aboutsummaryrefslogtreecommitdiff
path: root/src/qt/notificator.h
blob: 13f6a908da736ab11b3ca6fe0705e6a000400501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef NOTIFICATOR_H
#define NOTIFICATOR_H

#include <QObject>
#include <QIcon>

QT_BEGIN_NAMESPACE
class QSystemTrayIcon;
#ifdef QT_DBUS
class QDBusInterface;
#endif
QT_END_NAMESPACE

// Cross-platform desktop notification client
class Notificator: public QObject
{
    Q_OBJECT
public:
    // Create a new notificator
    // Ownership of trayIcon is not transferred to this object
    Notificator(const QString &programName=QString(), QSystemTrayIcon *trayIcon=0, QWidget *parent=0);
    ~Notificator();

    // Message class
    enum Class
    {
        Information,
        Warning,
        Critical,
    };

public slots:

    /* Show notification message.
     *
     *  cls: general message class
     *  title: title shown with message
     *  text: message content
     *  icon: optional icon to show with message
     *  millisTimeout: notification timeout in milliseconds (default 10 seconds)
     */
    void notify(Class cls, const QString &title, const QString &text,
                const QIcon &icon = QIcon(), int millisTimeout = 10000);

private:
    QWidget *parent;
    enum Mode {
        None,
        Freedesktop, // Use DBus org.freedesktop.Notifications
        QSystemTray, // Use QSystemTray::showMessage
    };
    QString programName;
    Mode mode;
    QSystemTrayIcon *trayIcon;
#ifdef QT_DBUS
    QDBusInterface *interface;

    void notifyDBus(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout);
#endif
    void notifySystray(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout);
};

#endif // NOTIFICATOR_H