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