client: Port old HighlightRule to ExpressionMatch
[quassel.git] / src / qtui / statusnotifieritem.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This contains code from KStatusNotifierItem, part of the KDE libs     *
6  *   Copyright (C) 2009 Marco Martin <notmart@gmail.com>                   *
7  *                                                                         *
8  *   This file is free software; you can redistribute it and/or modify     *
9  *   it under the terms of the GNU Library General Public License (LGPL)   *
10  *   as published by the Free Software Foundation; either version 2 of the *
11  *   License, or (at your option) any later version.                       *
12  *                                                                         *
13  *   This program is distributed in the hope that it will be useful,       *
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16  *   GNU General Public License for more details.                          *
17  *                                                                         *
18  *   You should have received a copy of the GNU General Public License     *
19  *   along with this program; if not, write to the                         *
20  *   Free Software Foundation, Inc.,                                       *
21  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
22  ***************************************************************************/
23
24 #pragma once
25
26 #ifdef HAVE_DBUS
27
28 #include <QDBusError>
29 #include <QHash>
30 #include <QString>
31
32 #if QT_VERSION >= 0x050000
33 #  include <QTemporaryDir>
34 #endif
35
36 #include "notificationsclient.h"
37 #include "systemtray.h"
38 #include "statusnotifierwatcher.h"
39
40 #ifdef QT_NO_SYSTEMTRAYICON
41 #  define StatusNotifierItemParent SystemTray
42 #else
43 #  define StatusNotifierItemParent LegacySystemTray
44 #  include "legacysystemtray.h"
45 #endif
46
47 class StatusNotifierItemDBus;
48
49 class StatusNotifierItem : public StatusNotifierItemParent
50 {
51     Q_OBJECT
52
53 public:
54     explicit StatusNotifierItem(QWidget *parent);
55
56     bool isSystemTrayAvailable() const override;
57
58 public slots:
59     void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int msTimeout = 10000, uint notificationId = 0) override;
60     void closeMessage(uint notificationId) override;
61
62 protected:
63     QString title() const;
64     QString iconName() const;
65     QString attentionIconName() const;
66     QString toolTipIconName() const;
67     QString iconThemePath() const;
68     QString menuObjectPath() const;
69
70     bool eventFilter(QObject *watched, QEvent *event) override;
71
72 private slots:
73     void activated(const QPoint &pos);
74     void serviceChange(const QString &name, const QString &oldOwner, const QString &newOwner);
75     void checkForRegisteredHosts();
76     void onDBusError(const QDBusError &error);
77
78     void notificationClosed(uint id, uint reason);
79     void notificationInvoked(uint id, const QString &action);
80
81     void refreshIcons();
82
83     void onModeChanged(Mode mode);
84     void onStateChanged(State state);
85     void onVisibilityChanged(bool isVisible);
86
87 private:
88     void registerToWatcher();
89
90     StatusNotifierItemDBus *_statusNotifierItemDBus{nullptr};
91     org::kde::StatusNotifierWatcher *_statusNotifierWatcher{nullptr};
92     org::freedesktop::Notifications *_notificationsClient{nullptr};
93     bool _notificationsClientSupportsMarkup{false};
94     bool _notificationsClientSupportsActions{false};
95     quint32 _lastNotificationsDBusId{0};
96     QHash<uint, uint> _notificationsIdMap; ///< Maps our own notification ID to the D-Bus one
97
98     QString _iconThemePath;
99     QString _menuObjectPath;
100
101 #if QT_VERSION >= 0x050000
102     QTemporaryDir _iconThemeDir;
103 #endif
104
105     friend class StatusNotifierItemDBus;
106 };
107
108 #endif /* HAVE_DBUS */