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 ***************************************************************************/
22 #include "statusnotifieritemdbus.h"
24 #include <QApplication>
25 #include <QDBusConnection>
32 #include "statusnotifieritem.h"
33 #include "statusnotifieritemadaptor.h"
34 #include "statusnotifierwatcher.h"
37 __inline int toInt(WId wid)
39 return (int)((__int64)wid);
43 __inline int toInt(WId wid)
50 // Marshall the ImageStruct data into a D-BUS argument
51 const QDBusArgument& operator<<(QDBusArgument& argument, const DBusImageStruct& icon)
53 argument.beginStructure();
54 argument << icon.width;
55 argument << icon.height;
56 argument << icon.data;
57 argument.endStructure();
61 // Retrieve the ImageStruct data from the D-BUS argument
62 const QDBusArgument& operator>>(const QDBusArgument& argument, DBusImageStruct& icon)
68 argument.beginStructure();
72 argument.endStructure();
81 // Marshall the ImageVector data into a D-BUS argument
82 const QDBusArgument& operator<<(QDBusArgument& argument, const DBusImageVector& iconVector)
84 argument.beginArray(qMetaTypeId<DBusImageStruct>());
85 for (const auto& i : iconVector) {
92 // Retrieve the ImageVector data from the D-BUS argument
93 const QDBusArgument& operator>>(const QDBusArgument& argument, DBusImageVector& iconVector)
95 argument.beginArray();
98 while (!argument.atEnd()) {
99 DBusImageStruct element;
101 iconVector.append(element);
109 // Marshall the ToolTipStruct data into a D-BUS argument
110 const QDBusArgument& operator<<(QDBusArgument& argument, const DBusToolTipStruct& toolTip)
112 argument.beginStructure();
113 argument << toolTip.icon;
114 argument << toolTip.image;
115 argument << toolTip.title;
116 argument << toolTip.subTitle;
117 argument.endStructure();
121 // Retrieve the ToolTipStruct data from the D-BUS argument
122 const QDBusArgument& operator>>(const QDBusArgument& argument, DBusToolTipStruct& toolTip)
125 DBusImageVector image;
129 argument.beginStructure();
133 argument >> subTitle;
134 argument.endStructure();
137 toolTip.image = image;
138 toolTip.title = title;
139 toolTip.subTitle = subTitle;
144 int StatusNotifierItemDBus::s_serviceCount = 0;
146 StatusNotifierItemDBus::StatusNotifierItemDBus(StatusNotifierItem* parent)
148 , m_statusNotifierItem(parent)
150 QDBusConnection::connectToBus(QDBusConnection::SessionBus,
151 QString("org.kde.StatusNotifierItem-%1-%2").arg(QCoreApplication::applicationPid()).arg(++s_serviceCount)))
153 new StatusNotifierItemAdaptor(this);
156 StatusNotifierItemDBus::~StatusNotifierItemDBus()
158 unregisterTrayIcon();
161 QDBusConnection StatusNotifierItemDBus::dbusConnection() const
166 // FIXME: prevent double registrations, also test this on platforms != KDE
168 void StatusNotifierItemDBus::registerTrayIcon()
170 m_dbus.registerObject("/StatusNotifierItem", this);
174 void StatusNotifierItemDBus::unregisterTrayIcon()
176 if (m_dbus.isConnected()) {
177 m_dbus.unregisterObject("/StatusNotifierItem");
181 QString StatusNotifierItemDBus::service() const
183 return m_dbus.baseService();
187 // Values and calls have been adapted to Quassel
189 QString StatusNotifierItemDBus::Category() const
191 return QString("Communications"); // no need to make this configurable for Quassel
194 QString StatusNotifierItemDBus::Title() const
196 return m_statusNotifierItem->title();
199 QString StatusNotifierItemDBus::Id() const
201 return QString("QuasselIRC");
204 QString StatusNotifierItemDBus::Status() const
206 return m_statusNotifierItem->metaObject()
207 ->enumerator(m_statusNotifierItem->metaObject()->indexOfEnumerator("State"))
208 .valueToKey(m_statusNotifierItem->state());
211 int StatusNotifierItemDBus::WindowId() const
213 return toInt(QtUi::mainWindow()->winId());
217 // We don't need to support serialized icon data in Quassel
219 QString StatusNotifierItemDBus::IconName() const
221 return m_statusNotifierItem->iconName();
224 DBusImageVector StatusNotifierItemDBus::IconPixmap() const
226 return DBusImageVector();
229 QString StatusNotifierItemDBus::OverlayIconName() const
234 DBusImageVector StatusNotifierItemDBus::OverlayIconPixmap() const
236 return DBusImageVector();
239 // Requesting attention icon and movie
241 QString StatusNotifierItemDBus::AttentionIconName() const
243 return m_statusNotifierItem->attentionIconName();
246 DBusImageVector StatusNotifierItemDBus::AttentionIconPixmap() const
248 return DBusImageVector();
251 QString StatusNotifierItemDBus::AttentionMovieName() const
258 DBusToolTipStruct StatusNotifierItemDBus::ToolTip() const
260 DBusToolTipStruct toolTip;
261 toolTip.icon = m_statusNotifierItem->toolTipIconName();
262 toolTip.image = DBusImageVector();
263 toolTip.title = m_statusNotifierItem->toolTipTitle();
264 toolTip.subTitle = m_statusNotifierItem->toolTipSubTitle();
269 QString StatusNotifierItemDBus::IconThemePath() const
271 return m_statusNotifierItem->iconThemePath();
276 QDBusObjectPath StatusNotifierItemDBus::Menu() const
278 return QDBusObjectPath(m_statusNotifierItem->menuObjectPath());
283 void StatusNotifierItemDBus::ContextMenu(int x, int y)
285 if (!m_statusNotifierItem->trayMenu()) {
289 // TODO: nicer placement, possible?
290 if (!m_statusNotifierItem->trayMenu()->isVisible()) {
291 m_statusNotifierItem->trayMenu()->popup(QPoint(x, y));
294 m_statusNotifierItem->trayMenu()->hide();
298 void StatusNotifierItemDBus::Activate(int x, int y)
300 m_statusNotifierItem->activated(QPoint(x, y));
303 void StatusNotifierItemDBus::SecondaryActivate(int x, int y)
307 // emit m_statusNotifierItem->secondaryActivateRequested(QPoint(x,y));
310 void StatusNotifierItemDBus::Scroll(int delta, const QString& orientation)
313 Q_UNUSED(orientation)
314 // Qt::Orientation dir = (orientation.toLower() == "horizontal" ? Qt::Horizontal : Qt::Vertical);
315 // emit m_statusNotifierItem->scrollRequested(delta, dir);