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> *
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. *
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. *
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 ***************************************************************************/
24 #include "statusnotifieritemdbus.h"
25 #include "statusnotifieritem.h"
27 #include <QApplication>
28 #include <QDBusConnection>
33 #include "statusnotifierwatcher.h"
34 #include "statusnotifieritemadaptor.h"
37 __inline int toInt(WId wid)
39 return (int)((__int64)wid);
43 __inline int toInt(WId wid)
51 // Marshall the ImageStruct data into a D-BUS argument
52 const QDBusArgument &operator<<(QDBusArgument &argument, const DBusImageStruct &icon)
54 argument.beginStructure();
55 argument << icon.width;
56 argument << icon.height;
57 argument << icon.data;
58 argument.endStructure();
63 // Retrieve the ImageStruct data from the D-BUS argument
64 const QDBusArgument &operator>>(const QDBusArgument &argument, DBusImageStruct &icon)
70 argument.beginStructure();
74 argument.endStructure();
84 // Marshall the ImageVector data into a D-BUS argument
85 const QDBusArgument &operator<<(QDBusArgument &argument, const DBusImageVector &iconVector)
87 argument.beginArray(qMetaTypeId<DBusImageStruct>());
88 for (const auto &i : iconVector) {
96 // Retrieve the ImageVector data from the D-BUS argument
97 const QDBusArgument &operator>>(const QDBusArgument &argument, DBusImageVector &iconVector)
99 argument.beginArray();
102 while (!argument.atEnd()) {
103 DBusImageStruct element;
105 iconVector.append(element);
114 // Marshall the ToolTipStruct data into a D-BUS argument
115 const QDBusArgument &operator<<(QDBusArgument &argument, const DBusToolTipStruct &toolTip)
117 argument.beginStructure();
118 argument << toolTip.icon;
119 argument << toolTip.image;
120 argument << toolTip.title;
121 argument << toolTip.subTitle;
122 argument.endStructure();
127 // Retrieve the ToolTipStruct data from the D-BUS argument
128 const QDBusArgument &operator>>(const QDBusArgument &argument, DBusToolTipStruct &toolTip)
131 DBusImageVector image;
135 argument.beginStructure();
139 argument >> subTitle;
140 argument.endStructure();
143 toolTip.image = image;
144 toolTip.title = title;
145 toolTip.subTitle = subTitle;
151 int StatusNotifierItemDBus::s_serviceCount = 0;
153 StatusNotifierItemDBus::StatusNotifierItemDBus(StatusNotifierItem *parent)
155 m_statusNotifierItem(parent),
156 m_dbus(QDBusConnection::connectToBus(QDBusConnection::SessionBus,
157 QString("org.kde.StatusNotifierItem-%1-%2").arg(QCoreApplication::applicationPid()).arg(++s_serviceCount)))
159 new StatusNotifierItemAdaptor(this);
163 StatusNotifierItemDBus::~StatusNotifierItemDBus()
165 unregisterTrayIcon();
169 QDBusConnection StatusNotifierItemDBus::dbusConnection() const
175 // FIXME: prevent double registrations, also test this on platforms != KDE
177 void StatusNotifierItemDBus::registerTrayIcon()
179 m_dbus.registerObject("/StatusNotifierItem", this);
184 void StatusNotifierItemDBus::unregisterTrayIcon()
186 if (m_dbus.isConnected()) {
187 m_dbus.unregisterObject("/StatusNotifierItem");
192 QString StatusNotifierItemDBus::service() const
194 return m_dbus.baseService();
199 //Values and calls have been adapted to Quassel
201 QString StatusNotifierItemDBus::Category() const
203 return QString("Communications"); // no need to make this configurable for Quassel
207 QString StatusNotifierItemDBus::Title() const
209 return m_statusNotifierItem->title();
213 QString StatusNotifierItemDBus::Id() const
215 return QString("QuasselIRC");
219 QString StatusNotifierItemDBus::Status() const
221 return m_statusNotifierItem->metaObject()->enumerator(m_statusNotifierItem->metaObject()->indexOfEnumerator("State")).valueToKey(m_statusNotifierItem->state());
225 int StatusNotifierItemDBus::WindowId() const
227 return toInt(QtUi::mainWindow()->winId());
232 //We don't need to support serialized icon data in Quassel
234 QString StatusNotifierItemDBus::IconName() const
236 return m_statusNotifierItem->iconName();
240 DBusImageVector StatusNotifierItemDBus::IconPixmap() const
242 return DBusImageVector();
246 QString StatusNotifierItemDBus::OverlayIconName() const
252 DBusImageVector StatusNotifierItemDBus::OverlayIconPixmap() const
254 return DBusImageVector();
258 //Requesting attention icon and movie
260 QString StatusNotifierItemDBus::AttentionIconName() const
262 return m_statusNotifierItem->attentionIconName();
266 DBusImageVector StatusNotifierItemDBus::AttentionIconPixmap() const
268 return DBusImageVector();
272 QString StatusNotifierItemDBus::AttentionMovieName() const
280 DBusToolTipStruct StatusNotifierItemDBus::ToolTip() const
282 DBusToolTipStruct toolTip;
283 toolTip.icon = m_statusNotifierItem->toolTipIconName();
284 toolTip.image = DBusImageVector();
285 toolTip.title = m_statusNotifierItem->toolTipTitle();
286 toolTip.subTitle = m_statusNotifierItem->toolTipSubTitle();
292 QString StatusNotifierItemDBus::IconThemePath() const
294 return m_statusNotifierItem->iconThemePath();
300 QDBusObjectPath StatusNotifierItemDBus::Menu() const
302 return QDBusObjectPath(m_statusNotifierItem->menuObjectPath());
308 void StatusNotifierItemDBus::ContextMenu(int x, int y)
310 if (!m_statusNotifierItem->trayMenu()) {
314 //TODO: nicer placement, possible?
315 if (!m_statusNotifierItem->trayMenu()->isVisible()) {
316 m_statusNotifierItem->trayMenu()->popup(QPoint(x, y));
319 m_statusNotifierItem->trayMenu()->hide();
324 void StatusNotifierItemDBus::Activate(int x, int y)
326 m_statusNotifierItem->activated(QPoint(x, y));
330 void StatusNotifierItemDBus::SecondaryActivate(int x, int y)
334 // emit m_statusNotifierItem->secondaryActivateRequested(QPoint(x,y));
338 void StatusNotifierItemDBus::Scroll(int delta, const QString &orientation)
341 Q_UNUSED(orientation)
342 // Qt::Orientation dir = (orientation.toLower() == "horizontal" ? Qt::Horizontal : Qt::Vertical);
343 // emit m_statusNotifierItem->scrollRequested(delta, dir);