summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Edmundson <[email protected]>2017-01-17 14:34:48 +0000
committerDavid Edmundson <[email protected]>2017-01-17 17:08:31 +0000
commit9d58703d37257e363ca27282b56caef3092ec5d0 (patch)
treecd51488499ac61c23e03baac6e77210e919386d7
parent6ed2c4a32b61bc890ca82a8f97d42d2bf7d127af (diff)
Generate DBusMenu Interface for libdbusmenuqt
Summary: This not only makes the code cleaner but more importantly avoids plasma making a blocking DBus call to a client in the QDBusInterface constructor which does a blocking call to Introspect Test Plan: Ran my test app with the dynamic menu. Everything was still fine Reviewers: #plasma Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D4172
-rw-r--r--libdbusmenuqt/CMakeLists.txt8
-rw-r--r--libdbusmenuqt/com.canonical.dbusmenu.xml49
-rw-r--r--libdbusmenuqt/dbusmenuimporter.cpp25
-rw-r--r--libdbusmenuqt/dbusmenuimporter.h1
4 files changed, 68 insertions, 15 deletions
diff --git a/libdbusmenuqt/CMakeLists.txt b/libdbusmenuqt/CMakeLists.txt
index 6c13e47..49d3420 100644
--- a/libdbusmenuqt/CMakeLists.txt
+++ b/libdbusmenuqt/CMakeLists.txt
@@ -5,6 +5,14 @@ dbusmenutypes_p.cpp
utils.cpp
)
+set_source_files_properties(com.canonical.dbusmenu.xml PROPERTIES
+ NO_NAMESPACE true
+ INCLUDE "dbusmenutypes_p.h"
+ CLASSNAME DBusMenuInterface
+)
+qt5_add_dbus_interface(libdbusmenu_SRCS com.canonical.dbusmenu.xml dbusmenu_interface)
+
+
add_library(dbusmenuqt STATIC ${libdbusmenu_SRCS})
target_link_libraries(dbusmenuqt
Qt5::DBus
diff --git a/libdbusmenuqt/com.canonical.dbusmenu.xml b/libdbusmenuqt/com.canonical.dbusmenu.xml
new file mode 100644
index 0000000..a5118c3
--- /dev/null
+++ b/libdbusmenuqt/com.canonical.dbusmenu.xml
@@ -0,0 +1,49 @@
+<interface name="com.canonical.dbusmenu">
+ <property name="Version" type="u" access="read"/>
+ <property name="Status" type="s" access="read"/>
+ <signal name="ItemsPropertiesUpdated">
+ <arg type="a(ia{sv})" direction="out"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="DBusMenuItemList"/>
+ <arg type="a(ias)" direction="out"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="DBusMenuItemKeysList"/>
+ </signal>
+ <signal name="LayoutUpdated">
+ <arg name="revision" type="u" direction="out"/>
+ <arg name="parentId" type="i" direction="out"/>
+ </signal>
+ <signal name="ItemActivationRequested">
+ <arg name="id" type="i" direction="out"/>
+ <arg name="timeStamp" type="u" direction="out"/>
+ </signal>
+ <method name="Event">
+ <arg name="id" type="i" direction="in"/>
+ <arg name="eventId" type="s" direction="in"/>
+ <arg name="data" type="v" direction="in"/>
+ <arg name="timestamp" type="u" direction="in"/>
+ <annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
+ </method>
+ <method name="GetProperty">
+ <arg type="v" direction="out"/>
+ <arg name="id" type="i" direction="in"/>
+ <arg name="property" type="s" direction="in"/>
+ </method>
+ <method name="GetLayout">
+ <arg type="u" direction="out"/>
+ <arg name="parentId" type="i" direction="in"/>
+ <arg name="recursionDepth" type="i" direction="in"/>
+ <arg name="propertyNames" type="as" direction="in"/>
+ <arg name="item" type="(ia{sv}av)" direction="out"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="DBusMenuLayoutItem"/>
+ </method>
+ <method name="GetGroupProperties">
+ <arg type="a(ia{sv})" direction="out"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="DBusMenuItemList"/>
+ <arg name="ids" type="ai" direction="in"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QList&lt;int&gt;"/>
+ <arg name="propertyNames" type="as" direction="in"/>
+ </method>
+ <method name="AboutToShow">
+ <arg type="b" direction="out"/>
+ <arg name="id" type="i" direction="in"/>
+ </method>
+</interface>
diff --git a/libdbusmenuqt/dbusmenuimporter.cpp b/libdbusmenuqt/dbusmenuimporter.cpp
index 8737fb2..07f62ac 100644
--- a/libdbusmenuqt/dbusmenuimporter.cpp
+++ b/libdbusmenuqt/dbusmenuimporter.cpp
@@ -41,6 +41,9 @@
#include "dbusmenushortcut_p.h"
#include "utils_p.h"
+// Generated
+#include "dbusmenu_interface.h"
+
//#define BENCHMARK
#ifdef BENCHMARK
#include <QTime>
@@ -52,8 +55,6 @@ static QTime sChrono;
return; \
}
-static const char *DBUSMENU_INTERFACE = "com.canonical.dbusmenu";
-
static const char *DBUSMENU_PROPERTY_ID = "_dbusmenu_id";
static const char *DBUSMENU_PROPERTY_ICON_NAME = "_dbusmenu_icon_name";
static const char *DBUSMENU_PROPERTY_ICON_DATA_HASH = "_dbusmenu_icon_data_hash";
@@ -79,7 +80,7 @@ class DBusMenuImporterPrivate
public:
DBusMenuImporter *q;
- QDBusAbstractInterface *m_interface;
+ DBusMenuInterface *m_interface;
QMenu *m_menu;
using ActionForId = QMap<int, QAction* >;
ActionForId m_actionForId;
@@ -90,7 +91,7 @@ public:
QDBusPendingCallWatcher *refresh(int id)
{
- QDBusPendingCall call = m_interface->asyncCall(QStringLiteral("GetLayout"), id, 1, QStringList());
+ auto call = m_interface->GetLayout(id, 1, QStringList());
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, q);
watcher->setProperty(DBUSMENU_PROPERTY_ID, id);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
@@ -266,8 +267,7 @@ public:
void sendEvent(int id, const QString &eventId)
{
- QVariant empty = QVariant::fromValue(QDBusVariant(QString()));
- m_interface->asyncCall(QStringLiteral("Event"), id, eventId, empty, 0u);
+ m_interface->Event(id, eventId, QDBusVariant(QString()), 0u);
}
};
@@ -278,19 +278,16 @@ DBusMenuImporter::DBusMenuImporter(const QString &service, const QString &path,
DBusMenuTypes_register();
d->q = this;
- d->m_interface = new QDBusInterface(service, path, DBUSMENU_INTERFACE, QDBusConnection::sessionBus(), this);
+ d->m_interface = new DBusMenuInterface(service, path, QDBusConnection::sessionBus(), this);
d->m_menu = 0;
d->m_pendingLayoutUpdateTimer = new QTimer(this);
d->m_pendingLayoutUpdateTimer->setSingleShot(true);
connect(d->m_pendingLayoutUpdateTimer, &QTimer::timeout, this, &DBusMenuImporter::processPendingLayoutUpdates);
- QDBusConnection::sessionBus().connect(service, path, DBUSMENU_INTERFACE, QStringLiteral("LayoutUpdated"), QStringLiteral("ui"),
- this, SLOT(slotLayoutUpdated(uint, int)));
- QDBusConnection::sessionBus().connect(service, path, DBUSMENU_INTERFACE, QStringLiteral("ItemsPropertiesUpdated"), QStringLiteral("a(ia{sv})a(ias)"),
- this, SLOT(slotItemsPropertiesUpdated(DBusMenuItemList, DBusMenuItemKeysList)));
- QDBusConnection::sessionBus().connect(service, path, DBUSMENU_INTERFACE, QStringLiteral("ItemActivationRequested"), QStringLiteral("iu"),
- this, SLOT(slotItemActivationRequested(int, uint)));
+ connect(d->m_interface, &DBusMenuInterface::LayoutUpdated, this, &DBusMenuImporter::slotLayoutUpdated);
+ connect(d->m_interface, &DBusMenuInterface::ItemActivationRequested, this, &DBusMenuImporter::slotItemActivationRequested);
+ connect(d->m_interface, &DBusMenuInterface::ItemsPropertiesUpdated, this, std::bind(&DBusMenuImporterPrivate::slotItemsPropertiesUpdated, d, std::placeholders::_1, std::placeholders::_2));
d->refresh(0);
}
@@ -467,7 +464,7 @@ void DBusMenuImporter::updateMenu(QMenu * menu)
int id = action->property(DBUSMENU_PROPERTY_ID).toInt();
- QDBusPendingCall call = d->m_interface->asyncCall(QStringLiteral("AboutToShow"), id);
+ auto call = d->m_interface->AboutToShow(id);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
watcher->setProperty(DBUSMENU_PROPERTY_ID, id);
connect(watcher, &QDBusPendingCallWatcher::finished, this,
diff --git a/libdbusmenuqt/dbusmenuimporter.h b/libdbusmenuqt/dbusmenuimporter.h
index 5c4d7c4..6d3fd4f 100644
--- a/libdbusmenuqt/dbusmenuimporter.h
+++ b/libdbusmenuqt/dbusmenuimporter.h
@@ -25,7 +25,6 @@
#include <QtCore/QObject>
class QAction;
-class QDBusAbstractInterface;
class QDBusPendingCallWatcher;
class QDBusVariant;
class QIcon;