cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / qtui / statusnotifieritemdbus.h
1 /***************************************************************************
2  *   The original file is part of the KDE libraries                        *
3  *   Copyright (C) 2009 by Marco Martin <notmart@gmail.com>                *
4  *   Quasselfied 2010 by Manuel Nickschas <sputnick@quassel-irc.org>       *
5  *                                                                         *
6  *   This file is free software; you can redistribute it and/or modify     *
7  *   it under the terms of the GNU Library General Public License (LGPL)   *
8  *   as published by the Free Software Foundation; either version 2 of the *
9  *   License, or (at your option) any later version.                       *
10  *                                                                         *
11  *   This program is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14  *   GNU General Public License for more details.                          *
15  *                                                                         *
16  *   You should have received a copy of the GNU General Public License     *
17  *   along with this program; if not, write to the                         *
18  *   Free Software Foundation, Inc.,                                       *
19  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
20  ***************************************************************************/
21
22 #ifndef STATUSNOTIFIERITEMDBUS_H_
23 #define STATUSNOTIFIERITEMDBUS_H_
24
25 #include <QDBusArgument>
26 #include <QDBusConnection>
27 #include <QObject>
28 #include <QPixmap>
29 #include <QString>
30
31 // Custom message type for DBus
32 struct DBusImageStruct
33 {
34     int width;
35     int height;
36     QByteArray data;
37 };
38
39 using DBusImageVector = QVector<DBusImageStruct>;
40
41 struct DBusToolTipStruct
42 {
43     QString icon;
44     DBusImageVector image;
45     QString title;
46     QString subTitle;
47 };
48
49 class StatusNotifierItem;
50
51 class StatusNotifierItemDBus : public QObject
52 {
53     Q_OBJECT
54
55     Q_PROPERTY(QString Category READ Category)
56     Q_PROPERTY(QString Id READ Id)
57     Q_PROPERTY(QString Title READ Title)
58     Q_PROPERTY(QString Status READ Status)
59     Q_PROPERTY(int WindowId READ WindowId)
60     Q_PROPERTY(QString IconName READ IconName)
61     Q_PROPERTY(DBusImageVector IconPixmap READ IconPixmap)
62     Q_PROPERTY(QString OverlayIconName READ OverlayIconName)
63     Q_PROPERTY(DBusImageVector OverlayIconPixmap READ OverlayIconPixmap)
64     Q_PROPERTY(QString AttentionIconName READ AttentionIconName)
65     Q_PROPERTY(DBusImageVector AttentionIconPixmap READ AttentionIconPixmap)
66     Q_PROPERTY(QString AttentionMovieName READ AttentionMovieName)
67     Q_PROPERTY(DBusToolTipStruct ToolTip READ ToolTip)
68     Q_PROPERTY(QString IconThemePath READ IconThemePath)
69     Q_PROPERTY(QDBusObjectPath Menu READ Menu)
70
71     friend class StatusNotifierItem;
72
73 public:
74     StatusNotifierItemDBus(StatusNotifierItem* parent);
75     ~StatusNotifierItemDBus() override;
76
77     /**
78      * @return the dbus connection used by this object
79      */
80     QDBusConnection dbusConnection() const;
81
82     /**
83      * Register the StatusNotifierItem to DBus
84      */
85     void registerTrayIcon();
86
87     /**
88      * Unregister the StatusNotifierItem from DBus
89      */
90     void unregisterTrayIcon();
91
92     /**
93      * @return the service this object is registered on the bus under
94      */
95     QString service() const;
96
97     /**
98      * @return the category of the application associated to this item
99      * @see Category
100      */
101     QString Category() const;
102
103     /**
104      * @return the id of this item
105      */
106     QString Id() const;
107
108     /**
109      * @return the title of this item
110      */
111     QString Title() const;
112
113     /**
114      * @return The status of this item
115      * @see Status
116      */
117     QString Status() const;
118
119     /**
120      * @return The id of the main window of the application that controls the item
121      */
122     int WindowId() const;
123
124     /**
125      * @return the name of the main icon to be displayed
126      * if image() is not empty this will always return an empty string
127      */
128     QString IconName() const;
129
130     /**
131      * @return a serialization of the icon data
132      */
133     DBusImageVector IconPixmap() const;
134
135     /**
136      * @return the name of the overlay of the main icon to be displayed
137      * if image() is not empty this will always return an empty string
138      */
139     QString OverlayIconName() const;
140
141     /**
142      * @return a serialization of the icon data
143      */
144     DBusImageVector OverlayIconPixmap() const;
145
146     /**
147      * @return the name of the icon to be displayed when the application
148      * is requesting the user's attention
149      * if attentionImage() is not empty this will always return an empty string
150      */
151     QString AttentionIconName() const;
152
153     /**
154      * @return a serialization of the requesting attention icon data
155      */
156     DBusImageVector AttentionIconPixmap() const;
157
158     /**
159      * @return the name of the attention movie
160      */
161     QString AttentionMovieName() const;
162
163     /**
164      * all the data needed for a tooltip
165      */
166     DBusToolTipStruct ToolTip() const;
167
168     /**
169      * @return path to extra icon theme, to load application specific icons
170      */
171     QString IconThemePath() const;
172
173     /**
174      * @return object path to the dbusmenu object
175      */
176     QDBusObjectPath Menu() const;
177
178 public slots:
179     // interaction
180     /**
181      * Shows the context menu associated to this item
182      * at the desired screen position
183      */
184     void ContextMenu(int x, int y);
185
186     /**
187      * Shows the main widget and try to position it on top
188      * of the other windows, if the widget is already visible, hide it.
189      */
190     void Activate(int x, int y);
191
192     /**
193      * The user activated the item in an alternate way (for instance with middle mouse button, this depends from the systray implementation)
194      */
195     void SecondaryActivate(int x, int y);
196
197     /**
198      * Inform this item that the mouse wheel was used on its representation
199      */
200     void Scroll(int delta, const QString& orientation);
201
202 signals:
203     /**
204      * Inform the systemtray that the own main icon has been changed,
205      * so should be reloaded
206      */
207     void NewIcon();
208
209     /**
210      * Inform the systemtray that there is a new icon to be used as overlay
211      */
212     void NewOverlayIcon();
213
214     /**
215      * Inform the systemtray that the requesting attention icon
216      * has been changed, so should be reloaded
217      */
218     void NewAttentionIcon();
219
220     /**
221      * Inform the systemtray that something in the tooltip has been changed
222      */
223     void NewToolTip();
224
225     /**
226      * Signal the new status when it has been changed
227      * @see Status
228      */
229     void NewStatus(const QString& status);
230
231 private:
232     StatusNotifierItem* m_statusNotifierItem;
233     QDBusConnection m_dbus;
234     static int s_serviceCount;
235 };
236
237 const QDBusArgument& operator<<(QDBusArgument& argument, const DBusImageStruct& icon);
238 const QDBusArgument& operator>>(const QDBusArgument& argument, DBusImageStruct& icon);
239
240 Q_DECLARE_METATYPE(DBusImageStruct)
241
242 const QDBusArgument& operator<<(QDBusArgument& argument, const DBusImageVector& iconVector);
243 const QDBusArgument& operator>>(const QDBusArgument& argument, DBusImageVector& iconVector);
244
245 Q_DECLARE_METATYPE(DBusImageVector)
246
247 const QDBusArgument& operator<<(QDBusArgument& argument, const DBusToolTipStruct& toolTip);
248 const QDBusArgument& operator>>(const QDBusArgument& argument, DBusToolTipStruct& toolTip);
249
250 Q_DECLARE_METATYPE(DBusToolTipStruct)
251
252 #endif