9a805be5b25ef70337c01a3d36777dd8e5098e5b
[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 <QtGlobal>
29
30 #if QT_VERSION >= 0x050000
31 #  include <QTemporaryDir>
32 #endif
33
34 #include "notificationsclient.h"
35 #include "systemtray.h"
36 #include "statusnotifierwatcher.h"
37
38 #ifdef QT_NO_SYSTEMTRAYICON
39 #  define StatusNotifierItemParent SystemTray
40 #else
41 #  define StatusNotifierItemParent LegacySystemTray
42 #  include "legacysystemtray.h"
43 #endif
44
45 class StatusNotifierItemDBus;
46
47 class StatusNotifierItem : public StatusNotifierItemParent
48 {
49     Q_OBJECT
50
51 public:
52     explicit StatusNotifierItem(QWidget *parent);
53     ~StatusNotifierItem() override;
54
55     bool isSystemTrayAvailable() const override;
56     bool isVisible() const override;
57
58 public slots:
59     void setState(State state) override;
60     void setVisible(bool visible) override;
61     void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int msTimeout = 10000, uint notificationId = 0) override;
62     void closeMessage(uint notificationId) override;
63
64 protected:
65     void init() override;
66     void setMode(Mode mode) override;
67
68     QString title() const;
69     QString iconName() const;
70     QString attentionIconName() const;
71     QString toolTipIconName() const;
72     QString iconThemePath() const;
73     QString menuObjectPath() const;
74
75     bool eventFilter(QObject *watched, QEvent *event) override;
76
77 private slots:
78     void activated(const QPoint &pos);
79     void serviceChange(const QString &name, const QString &oldOwner, const QString &newOwner);
80     void checkForRegisteredHosts();
81
82     void notificationClosed(uint id, uint reason);
83     void notificationInvoked(uint id, const QString &action);
84
85     void refreshIcons();
86
87 private:
88     void registerToDaemon();
89
90     static const int _protocolVersion;
91     static const QString _statusNotifierWatcherServiceName;
92     StatusNotifierItemDBus *_statusNotifierItemDBus{nullptr};
93
94     org::kde::StatusNotifierWatcher *_statusNotifierWatcher{nullptr};
95     org::freedesktop::Notifications *_notificationsClient{nullptr};
96     bool _notificationsClientSupportsMarkup{false};
97     bool _notificationsClientSupportsActions{false};
98     quint32 _lastNotificationsDBusId{0};
99     QHash<uint, uint> _notificationsIdMap; ///< Maps our own notification ID to the D-Bus one
100
101     QString _iconThemePath;
102     QString _menuObjectPath;
103
104 #if QT_VERSION >= 0x050000
105     QTemporaryDir _iconThemeDir;
106 #endif
107
108     friend class StatusNotifierItemDBus;
109 };
110
111 #endif /* HAVE_DBUS */