Performance tweak: rem. pointless recursive calls
[quassel.git] / src / qtui / statusnotifieritem.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2015 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 #ifndef STATUSNOTIFIERITEM_H_
25 #define STATUSNOTIFIERITEM_H_
26
27 #ifdef HAVE_DBUS
28
29 #include "notificationsclient.h"
30 #include "systemtray.h"
31 #include "statusnotifierwatcher.h"
32
33 #ifdef QT_NO_SYSTEMTRAYICON
34 #  define StatusNotifierItemParent SystemTray
35 #else
36 #  define StatusNotifierItemParent LegacySystemTray
37 #  include "legacysystemtray.h"
38 #endif
39
40 class StatusNotifierItemDBus;
41
42 class StatusNotifierItem : public StatusNotifierItemParent
43 {
44     Q_OBJECT
45
46 public:
47     explicit StatusNotifierItem(QWidget *parent);
48     virtual ~StatusNotifierItem();
49
50     virtual bool isSystemTrayAvailable() const;
51     virtual bool isVisible() const;
52
53 public slots:
54     virtual void setState(State state);
55     virtual void setVisible(bool visible);
56     virtual void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int msTimeout = 10000, uint notificationId = 0);
57     virtual void closeMessage(uint notificationId);
58
59 protected:
60     virtual void init();
61     virtual void setMode(Mode mode);
62
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     virtual bool eventFilter(QObject *watched, QEvent *event);
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
77     void notificationClosed(uint id, uint reason);
78     void notificationInvoked(uint id, const QString &action);
79
80 private:
81     void registerToDaemon();
82
83     static const int _protocolVersion;
84     static const QString _statusNotifierWatcherServiceName;
85     StatusNotifierItemDBus *_statusNotifierItemDBus;
86
87     org::kde::StatusNotifierWatcher *_statusNotifierWatcher;
88     org::freedesktop::Notifications *_notificationsClient;
89     bool _notificationsClientSupportsMarkup;
90     bool _notificationsClientSupportsActions;
91     quint32 _lastNotificationsDBusId;
92     QHash<uint, uint> _notificationsIdMap; ///< Maps our own notification ID to the D-Bus one
93
94     QString _iconThemePath;
95     QString _menuObjectPath;
96
97     friend class StatusNotifierItemDBus;
98 };
99
100
101 #endif /* HAVE_DBUS */
102 #endif /* STATUSNOTIFIERITEM_H_ */