Made a start with the notification system. However need to figure out
how i want to handle multithreading and screen updates.
This commit is contained in:
parent
5494e5076b
commit
7f09d5fe07
7 changed files with 216 additions and 0 deletions
64
pglab/NotificationService.h
Normal file
64
pglab/NotificationService.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#ifndef NOTIFICATIONSERVICE_H
|
||||
#define NOTIFICATIONSERVICE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <memory>
|
||||
#include <shared_mutex>
|
||||
|
||||
enum NotificationSeverity {
|
||||
Informational, ///< Use for notifications of succesful completion and other things the user likely does not need to be bothered with
|
||||
Warning, ///<
|
||||
Error, ///< Use for failures like not being able to save the users data
|
||||
Critical ///< Don't think you should ever need this in a correct program....
|
||||
};
|
||||
|
||||
class Notification: public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Notification(int64_t id, NotificationSeverity severity, const QString &msg, const QString &detail = {});
|
||||
|
||||
int64_t id() const { return m_id; }
|
||||
NotificationSeverity severity() const { return m_severity; }
|
||||
QString shortMessage() const { return m_shortMessage; }
|
||||
QString detailMessage() const { return m_detailMessage; }
|
||||
|
||||
private:
|
||||
int64_t m_id;
|
||||
NotificationSeverity m_severity;
|
||||
QString m_shortMessage;
|
||||
QString m_detailMessage;
|
||||
|
||||
};
|
||||
|
||||
class NotificationService {
|
||||
public:
|
||||
static std::shared_ptr<NotificationService> instance();
|
||||
|
||||
NotificationService();
|
||||
|
||||
void addInformational(const QString &msg, const QString &detail = {});
|
||||
void addWarning(const QString &msg, const QString &detail = {});
|
||||
void addError(const QString &msg, const QString &detail = {});
|
||||
void add(NotificationSeverity severity, const QString &msg, const QString &detail = {});
|
||||
|
||||
/// Returns the number of notifications
|
||||
int count() const;
|
||||
const Notification& notification(int index);
|
||||
|
||||
signals:
|
||||
void onNewNotification(const Notification ¬ification);
|
||||
private:
|
||||
static std::shared_ptr<NotificationService> s_instance;
|
||||
|
||||
using NotificationContainer = QVector<Notification>;
|
||||
|
||||
std::shared_mutex m_nofiticationsMutex;
|
||||
NotificationContainer m_notifications;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(NotificationSeverity)
|
||||
Q_DECLARE_METATYPE(Notification)
|
||||
|
||||
#endif // NOTIFICATIONSERVICE_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue