2 * Copyright 2014 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Michael Zanetti <michael.zanetti@canonical.com>
20#include "dbusinterface.h"
21#include "launchermodel.h"
22#include "launcheritem.h"
24#include <QDBusArgument>
25#include <QDBusConnection>
26#include <QDBusMessage>
29DBusInterface::DBusInterface(LauncherModel *parent):
30 UnityDBusVirtualObject("/com/canonical/Unity/Launcher", "com.canonical.Unity.Launcher", true, parent),
31 m_launcherModel(parent)
35DBusInterface::~DBusInterface()
39QString DBusInterface::introspect(const QString &path) const
41 /* This case we should just list the nodes */
42 if (path == "/com/canonical/Unity/Launcher/" || path == "/com/canonical/Unity/Launcher") {
45 // Add Refresh to introspect
46 nodes = "<interface name=\"com.canonical.Unity.Launcher\">"
47 "<method name=\"Refresh\"/>"
50 // Add dynamic properties for launcher emblems
51 for (int i = 0; i < m_launcherModel->rowCount(); i++) {
52 nodes.append("<node name=\"");
53 nodes.append(encodeAppId(m_launcherModel->get(i)->appId()));
54 nodes.append("\"/>\n");
59 /* Should not happen, but let's handle it */
60 if (!path.startsWith("/com/canonical/Unity/Launcher")) {
64 /* Now we should be looking at a node */
66 "<interface name=\"com.canonical.Unity.Launcher.Item\">"
67 "<property name=\"count\" type=\"i\" access=\"readwrite\" />"
68 "<property name=\"countVisible\" type=\"b\" access=\"readwrite\" />"
69 "<method name=\"Alert\" />"
75QString DBusInterface::decodeAppId(const QString& path)
77 QByteArray bytes = path.toUtf8();
80 for (int i = 0; i < bytes.size(); ++i) {
81 char chr = bytes.at(i);
85 number.append(bytes.at(i+1));
86 number.append(bytes.at(i+2));
89 char newchar = number.toUInt(&okay, 16);
91 decoded.append(newchar);
99 return QString::fromUtf8(decoded);
102QString DBusInterface::encodeAppId(const QString& appId)
104 QByteArray bytes = appId.toUtf8();
107 for (int i = 0; i < bytes.size(); ++i) {
108 uchar chr = bytes.at(i);
110 if ((chr >= 'a' && chr <= 'z') ||
111 (chr >= 'A' && chr <= 'Z') ||
112 (chr >= '0' && chr <= '9'&& i != 0)) {
115 QString hexval = QString("_%1").arg(chr, 2, 16, QChar('0'));
116 encoded.append(hexval.toUpper());
123bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnection& connection)
125 /* Check to make sure we're getting properties on our interface */
126 if (message.type() != QDBusMessage::MessageType::MethodCallMessage) {
130 /* Break down the path to just the app id */
131 bool validpath = true;
132 QString pathtemp = message.path();
133 if (!pathtemp.startsWith("/com/canonical/Unity/Launcher/")) {
136 pathtemp.remove("/com/canonical/Unity/Launcher/");
137 if (pathtemp.indexOf('/') >= 0) {
141 /* Find ourselves an appid */
142 QString appid = decodeAppId(pathtemp);
144 // First handle methods of the Launcher interface
145 if (message.interface() == "com.canonical.Unity.Launcher") {
146 if (message.member() == "Refresh") {
147 QDBusMessage reply = message.createReply();
148 Q_EMIT refreshCalled();
149 return connection.send(reply);
151 } else if (message.interface() == "com.canonical.Unity.Launcher.Item") {
152 // Handle methods of the Launcher-Item interface
153 if (message.member() == "Alert" && validpath) {
154 QDBusMessage reply = message.createReply();
155 Q_EMIT alertCalled(appid);
156 return connection.send(reply);
160 // Now handle dynamic properties (for launcher emblems)
161 if (message.interface() != "org.freedesktop.DBus.Properties") {
165 if (message.member() != "GetAll" && message.arguments()[0].toString() != "com.canonical.Unity.Launcher.Item") {
173 int index = m_launcherModel->findApplication(appid);
174 LauncherItem *item = static_cast<LauncherItem*>(m_launcherModel->get(index));
177 if (message.member() == "Get") {
181 if (message.arguments()[1].toString() == "count") {
182 retval.append(QVariant::fromValue(QDBusVariant(item->count())));
183 } else if (message.arguments()[1].toString() == "countVisible") {
184 retval.append(QVariant::fromValue(QDBusVariant(item->countVisible())));
186 } else if (message.member() == "Set") {
187 if (message.arguments()[1].toString() == "count") {
188 int newCount = message.arguments()[2].value<QDBusVariant>().variant().toInt();
189 if (!item || newCount != item->count()) {
190 Q_EMIT countChanged(appid, newCount);
191 notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "count", QVariant(newCount));
193 } else if (message.arguments()[1].toString() == "countVisible") {
194 bool newVisible = message.arguments()[2].value<QDBusVariant>().variant().toBool();
195 if (!item || newVisible != item->countVisible()) {
196 Q_EMIT countVisibleChanged(appid, newVisible);
197 notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "countVisible", newVisible);
200 } else if (message.member() == "GetAll") {
203 all.insert("count", item->count());
204 all.insert("countVisible", item->countVisible());
211 QDBusMessage reply = message.createReply(retval);
212 return connection.send(reply);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list