[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
wilder-portage-prov
Kai Uwe Broulik 6 years ago
parent 9a4f259c48
commit 503bf4f3a5
  1. 10
      gmenu-dbusmenu-proxy/actions.cpp
  2. 2
      gmenu-dbusmenu-proxy/actions.h
  3. 11
      gmenu-dbusmenu-proxy/window.cpp
  4. 2
      gmenu-dbusmenu-proxy/window.h

@ -89,7 +89,7 @@ GMenuActionMap Actions::getAll() const
return m_actions; 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)) { if (!m_actions.contains(name)) {
qCWarning(DBUSMENUPROXY) << "Cannot invoke action" << name << "which doesn't exist"; qCWarning(DBUSMENUPROXY) << "Cannot invoke action" << name << "which doesn't exist";
@ -101,8 +101,12 @@ void Actions::trigger(const QString &name, uint timestamp)
s_orgGtkActions, s_orgGtkActions,
QStringLiteral("Activate")); QStringLiteral("Activate"));
msg << name; 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; QVariantMap platformData;

@ -38,7 +38,7 @@ public:
bool get(const QString &name, GMenuAction &action) const; bool get(const QString &name, GMenuAction &action) const;
GMenuActionMap getAll() 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" bool isValid() const; // basically "has actions"

@ -299,16 +299,15 @@ bool Window::getAction(const QString &name, GMenuAction &action) const
return actions->get(lookupName, action); 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; QString lookupName;
Actions *actions = getActionsForAction(name, lookupName); Actions *actions = getActionsForAction(name, lookupName);
if (!actions) { if (!actions) {
return; return;
} }
actions->trigger(lookupName, timestamp); actions->trigger(lookupName, target, timestamp);
} }
Actions *Window::getActionsForAction(const QString &name, QString &lookupName) const 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" // GMenu dbus doesn't have any "opened" or "closed" signals, we'll only handle "clicked"
if (eventId == QLatin1String("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()) { if (!action.isEmpty()) {
triggerAction(action, timestamp); triggerAction(action, target, timestamp);
} }
} }

@ -100,7 +100,7 @@ private:
void updateWindowProperties(); void updateWindowProperties();
bool getAction(const QString &name, GMenuAction &action) const; 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; Actions *getActionsForAction(const QString &name, QString &lookupName) const;
void menuChanged(const QVector<uint> &menuIds); void menuChanged(const QVector<uint> &menuIds);

Loading…
Cancel
Save