From 503bf4f3a54267e22592c3e0ee246c20a2485a3d Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Mon, 9 Mar 2020 09:21:17 +0100 Subject: [PATCH] [gmenu-dbusmenu-proxy] Pass action "target" in invocation According to documentation [1] a menu item has a target attribute, which is "the parameter to pass when activating the action". Furthermore, the action "Activate" method specifies "If the action activation requires a parameter then this parameter must be given in the second parameter (av).". Also implements a TODO in the code. [1] https://wiki.gnome.org/Projects/GLib/GApplication/DBusAPI CCBUG: 418385 Differential Revision: https://phabricator.kde.org/D27884 --- gmenu-dbusmenu-proxy/actions.cpp | 10 +++++++--- gmenu-dbusmenu-proxy/actions.h | 2 +- gmenu-dbusmenu-proxy/window.cpp | 11 ++++++----- gmenu-dbusmenu-proxy/window.h | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/gmenu-dbusmenu-proxy/actions.cpp b/gmenu-dbusmenu-proxy/actions.cpp index 9709595a0..e2b6a0748 100644 --- a/gmenu-dbusmenu-proxy/actions.cpp +++ b/gmenu-dbusmenu-proxy/actions.cpp @@ -89,7 +89,7 @@ GMenuActionMap Actions::getAll() const return m_actions; } -void Actions::trigger(const QString &name, uint timestamp) +void Actions::trigger(const QString &name, const QVariant &target, uint timestamp) { if (!m_actions.contains(name)) { qCWarning(DBUSMENUPROXY) << "Cannot invoke action" << name << "which doesn't exist"; @@ -101,8 +101,12 @@ void Actions::trigger(const QString &name, uint timestamp) s_orgGtkActions, QStringLiteral("Activate")); msg << name; - // TODO use the arguments provided by "target" in the menu item - msg << QVariant::fromValue(QVariantList()); + + QVariantList args; + if (target.isValid()) { + args << target; + } + msg << QVariant::fromValue(args); QVariantMap platformData; diff --git a/gmenu-dbusmenu-proxy/actions.h b/gmenu-dbusmenu-proxy/actions.h index 78ca17a92..565bccbe7 100644 --- a/gmenu-dbusmenu-proxy/actions.h +++ b/gmenu-dbusmenu-proxy/actions.h @@ -38,7 +38,7 @@ public: bool get(const QString &name, GMenuAction &action) const; GMenuActionMap getAll() const; - void trigger(const QString &name, uint timestamp = 0); + void trigger(const QString &name, const QVariant &target, uint timestamp = 0); bool isValid() const; // basically "has actions" diff --git a/gmenu-dbusmenu-proxy/window.cpp b/gmenu-dbusmenu-proxy/window.cpp index 0aca30080..4d532e952 100644 --- a/gmenu-dbusmenu-proxy/window.cpp +++ b/gmenu-dbusmenu-proxy/window.cpp @@ -299,16 +299,15 @@ bool Window::getAction(const QString &name, GMenuAction &action) const return actions->get(lookupName, action); } -void Window::triggerAction(const QString &name, uint timestamp) +void Window::triggerAction(const QString &name, const QVariant &target, uint timestamp) { QString lookupName; Actions *actions = getActionsForAction(name, lookupName); - if (!actions) { return; } - actions->trigger(lookupName, timestamp); + actions->trigger(lookupName, target, timestamp); } Actions *Window::getActionsForAction(const QString &name, QString &lookupName) const @@ -409,9 +408,11 @@ void Window::Event(int id, const QString &eventId, const QDBusVariant &data, uin // GMenu dbus doesn't have any "opened" or "closed" signals, we'll only handle "clicked" if (eventId == QLatin1String("clicked")) { - const QString action = m_currentMenu->getItem(id).value(QStringLiteral("action")).toString(); + const QVariantMap item = m_currentMenu->getItem(id); + const QString action = item.value(QStringLiteral("action")).toString(); + const QVariant target = item.value(QStringLiteral("target")); if (!action.isEmpty()) { - triggerAction(action, timestamp); + triggerAction(action, target, timestamp); } } diff --git a/gmenu-dbusmenu-proxy/window.h b/gmenu-dbusmenu-proxy/window.h index 035ea6a00..a3025c955 100644 --- a/gmenu-dbusmenu-proxy/window.h +++ b/gmenu-dbusmenu-proxy/window.h @@ -100,7 +100,7 @@ private: void updateWindowProperties(); bool getAction(const QString &name, GMenuAction &action) const; - void triggerAction(const QString &name, uint timestamp = 0); + void triggerAction(const QString &name, const QVariant &target, uint timestamp = 0); Actions *getActionsForAction(const QString &name, QString &lookupName) const; void menuChanged(const QVector &menuIds);