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 <QDBusConnection>
30 #include <QApplication>
35 # include <KWindowInfo>
36 # include <KWindowSystem>
39 #include "statusnotifierwatcher.h"
40 #include "statusnotifieritemadaptor.h"
43 __inline int toInt(WId wid)
45 return (int)((__int64)wid);
50 __inline int toInt(WId wid)
58 // Marshall the ImageStruct data into a D-BUS argument
59 const QDBusArgument &operator<<(QDBusArgument &argument, const DBusImageStruct &icon)
61 argument.beginStructure();
62 argument << icon.width;
63 argument << icon.height;
64 argument << icon.data;
65 argument.endStructure();
70 // Retrieve the ImageStruct data from the D-BUS argument
71 const QDBusArgument &operator>>(const QDBusArgument &argument, DBusImageStruct &icon)
77 argument.beginStructure();
81 argument.endStructure();
91 // Marshall the ImageVector data into a D-BUS argument
92 const QDBusArgument &operator<<(QDBusArgument &argument, const DBusImageVector &iconVector)
94 argument.beginArray(qMetaTypeId<DBusImageStruct>());
95 for (int i = 0; i < iconVector.size(); ++i) {
96 argument << iconVector[i];
103 // Retrieve the ImageVector data from the D-BUS argument
104 const QDBusArgument &operator>>(const QDBusArgument &argument, DBusImageVector &iconVector)
106 argument.beginArray();
109 while (!argument.atEnd()) {
110 DBusImageStruct element;
112 iconVector.append(element);
121 // Marshall the ToolTipStruct data into a D-BUS argument
122 const QDBusArgument &operator<<(QDBusArgument &argument, const DBusToolTipStruct &toolTip)
124 argument.beginStructure();
125 argument << toolTip.icon;
126 argument << toolTip.image;
127 argument << toolTip.title;
128 argument << toolTip.subTitle;
129 argument.endStructure();
134 // Retrieve the ToolTipStruct data from the D-BUS argument
135 const QDBusArgument &operator>>(const QDBusArgument &argument, DBusToolTipStruct &toolTip)
138 DBusImageVector image;
142 argument.beginStructure();
146 argument >> subTitle;
147 argument.endStructure();
150 toolTip.image = image;
151 toolTip.title = title;
152 toolTip.subTitle = subTitle;
158 int StatusNotifierItemDBus::s_serviceCount = 0;
160 StatusNotifierItemDBus::StatusNotifierItemDBus(StatusNotifierItem *parent)
162 m_statusNotifierItem(parent),
163 m_dbus(QDBusConnection::connectToBus(QDBusConnection::SessionBus,
164 QString("org.kde.StatusNotifierItem-%1-%2").arg(QCoreApplication::applicationPid()).arg(++s_serviceCount)))
166 new StatusNotifierItemAdaptor(this);
170 StatusNotifierItemDBus::~StatusNotifierItemDBus()
172 unregisterTrayIcon();
176 QDBusConnection StatusNotifierItemDBus::dbusConnection() const
182 // FIXME: prevent double registrations, also test this on platforms != KDE
184 void StatusNotifierItemDBus::registerTrayIcon()
186 m_dbus.registerObject("/StatusNotifierItem", this);
191 void StatusNotifierItemDBus::unregisterTrayIcon()
193 if (m_dbus.isConnected()) {
194 m_dbus.unregisterObject("/StatusNotifierItem");
199 QString StatusNotifierItemDBus::service() const
201 return m_dbus.baseService();
206 //Values and calls have been adapted to Quassel
208 QString StatusNotifierItemDBus::Category() const
210 return QString("Communications"); // no need to make this configurable for Quassel
214 QString StatusNotifierItemDBus::Title() const
216 return m_statusNotifierItem->title();
220 QString StatusNotifierItemDBus::Id() const
222 return QString("QuasselIRC");
226 QString StatusNotifierItemDBus::Status() const
228 return m_statusNotifierItem->metaObject()->enumerator(m_statusNotifierItem->metaObject()->indexOfEnumerator("State")).valueToKey(m_statusNotifierItem->state());
232 int StatusNotifierItemDBus::WindowId() const
234 return toInt(QtUi::mainWindow()->winId());
239 //We don't need to support serialized icon data in Quassel
241 QString StatusNotifierItemDBus::IconName() const
243 return m_statusNotifierItem->iconName();
247 DBusImageVector StatusNotifierItemDBus::IconPixmap() const
249 return DBusImageVector();
253 QString StatusNotifierItemDBus::OverlayIconName() const
259 DBusImageVector StatusNotifierItemDBus::OverlayIconPixmap() const
261 return DBusImageVector();
265 //Requesting attention icon and movie
267 QString StatusNotifierItemDBus::AttentionIconName() const
269 return m_statusNotifierItem->attentionIconName();
273 DBusImageVector StatusNotifierItemDBus::AttentionIconPixmap() const
275 return DBusImageVector();
279 QString StatusNotifierItemDBus::AttentionMovieName() const
287 DBusToolTipStruct StatusNotifierItemDBus::ToolTip() const
289 DBusToolTipStruct toolTip;
290 toolTip.icon = m_statusNotifierItem->toolTipIconName();
291 toolTip.image = DBusImageVector();
292 toolTip.title = m_statusNotifierItem->toolTipTitle();
293 toolTip.subTitle = m_statusNotifierItem->toolTipSubTitle();
299 QString StatusNotifierItemDBus::IconThemePath() const
301 return m_statusNotifierItem->iconThemePath();
307 QDBusObjectPath StatusNotifierItemDBus::Menu() const
309 return QDBusObjectPath(m_statusNotifierItem->menuObjectPath());
315 void StatusNotifierItemDBus::ContextMenu(int x, int y)
317 if (!m_statusNotifierItem->trayMenu()) {
321 //TODO: nicer placement, possible?
322 if (!m_statusNotifierItem->trayMenu()->isVisible()) {
324 m_statusNotifierItem->trayMenu()->setWindowFlags(Qt::Window|Qt::FramelessWindowHint);
326 m_statusNotifierItem->trayMenu()->popup(QPoint(x, y));
328 KWindowSystem::setState(m_statusNotifierItem->trayMenu()->winId(), NET::SkipTaskbar|NET::SkipPager|NET::KeepAbove);
329 KWindowSystem::setType(m_statusNotifierItem->trayMenu()->winId(), NET::PopupMenu);
330 KWindowSystem::forceActiveWindow(m_statusNotifierItem->trayMenu()->winId());
334 m_statusNotifierItem->trayMenu()->hide();
339 void StatusNotifierItemDBus::Activate(int x, int y)
341 m_statusNotifierItem->activated(QPoint(x, y));
345 void StatusNotifierItemDBus::SecondaryActivate(int x, int y)
349 // emit m_statusNotifierItem->secondaryActivateRequested(QPoint(x,y));
353 void StatusNotifierItemDBus::Scroll(int delta, const QString &orientation)
356 Q_UNUSED(orientation)
357 // Qt::Orientation dir = (orientation.toLower() == "horizontal" ? Qt::Horizontal : Qt::Vertical);
358 // emit m_statusNotifierItem->scrollRequested(delta, dir);