on xenial help sign in
DBus, lots of DBus
commitc8082f9c93ced0e20ed25fcb781fb218e64b6f98 authorTed Gould <ted@gould.cx> dateTue 8 Apr 2014, 16:48 (13 years ago) parentf313567
2 files changed+86−4
plugins/Unity/Launcher/backend/launcherbackend.cpp+83−4 plugins/Unity/Launcher/backend/launcherbackend.h+3
plugins/Unity/Launcher/backend/launcherbackend.cpp+83−4
@@ -358,9 +358,40 @@ bool LauncherBackend::isDefaultsItem(const QList<QVariantMap> &apps) const
358358
359359bool LauncherBackend::handleMessage(const QDBusMessage& message, const QDBusConnection& connection)
360360{
361− Q_UNUSED(message)
362− Q_UNUSED(connection)
363− return false;
361+ /* Check to make sure we're getting properties on our interface */
362+ if (message.type() != QDBusMessage::MessageType::MethodCallMessage)
363+ return false;
364+ if (message.interface() != "org.freedesktop.DBus.Properties")
365+ return false;
366+ if (message.arguments()[0].toString() != "com.canonical.unity.Launcher.Item")
367+ return false;
368+
369+ /* Break down the path to just the app id */
370+ QString pathtemp = message.path();
371+ if (!pathtemp.startsWith("/com/canonical/unity/launcher/"))
372+ return false;
373+ pathtemp.remove("/com/canonical/unity/launcher/");
374+ if (pathtemp.indexOf('/') >= 0)
375+ return false;
376+
377+ /* Find ourselves an appid */
378+ QString appid = decodeAppId(pathtemp);
379+ QVariant retval;
380+
381+ if (message.member() == "Get") {
382+ if (message.arguments()[1].toString() == "count")
383+ retval = this->count(appid);
384+ } else if (message.member() == "Set") {
385+ //if (message.arguments()[1].toString() == "count")
386+ /* TODO: setCount */
387+ } else if (message.member() == "GetAll") {
388+ retval = this->itemToVariant(appid);
389+ } else {
390+ return false;
391+ }
392+
393+ QDBusMessage reply = message.createReply(retval);
394+ return connection.send(reply);
364395}
365396
366397QString LauncherBackend::introspect (const QString &path) const
@@ -371,7 +402,7 @@ QString LauncherBackend::introspect (const QString &path) const
371402
372403 Q_FOREACH(const QString &appId, m_storedApps) {
373404 nodes.append("<node name=\"");
374− nodes.append(appId);
405+ nodes.append(encodeAppId(appId));
375406 nodes.append("\"/>\n");
376407 }
377408
@@ -391,3 +422,51 @@ QString LauncherBackend::introspect (const QString &path) const
391422 "</interface>";
392423 return nodeiface;
393424}
425+
426+QString LauncherBackend::decodeAppId (const QString& path) const
427+{
428+ QByteArray bytes = path.toUtf8();
429+ QByteArray decoded;
430+
431+ for (int i = 0; i < bytes.size(); ++i) {
432+ char chr = bytes.at(i);
433+
434+ if (chr == '_') {
435+ QString number;
436+ number.append(bytes.at(i+1));
437+ number.append(bytes.at(i+2));
438+
439+ bool okay;
440+ char newchar = number.toUInt(&okay, 16);
441+ if (okay)
442+ decoded.append(newchar);
443+
444+ i += 2;
445+ } else {
446+ decoded.append(chr);
447+ }
448+ }
449+
450+ return decoded;
451+}
452+
453+QString LauncherBackend::encodeAppId (const QString& appId) const
454+{
455+ QByteArray bytes = appId.toUtf8();
456+ QString encoded;
457+
458+ for (int i = 0; i < bytes.size(); ++i) {
459+ char chr = bytes.at(i);
460+
461+ if ((chr >= 'a' && chr <= 'z') ||
462+ (chr >= 'A' && chr <= 'Z') ||
463+ (chr >= '0' && chr <= '9'&& i != 0)) {
464+ encoded.append(chr);
465+ } else {
466+ encoded.append('_');
467+ encoded.arg((ushort)chr, 2, 16, QChar('0'));
468+ }
469+ }
470+
471+ return encoded;
472+}
plugins/Unity/Launcher/backend/launcherbackend.h+3
@@ -159,6 +159,9 @@ private:
159159
160160 AccountsServiceDBusAdaptor *m_accounts;
161161 QString m_user;
162+
163+ QString decodeAppId (const QString& path) const;
164+ QString encodeAppId (const QString& appId) const;
162165};
163166
164167#endif // LAUNCHERBACKEND_H