[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;
}
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;

@ -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"

@ -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);
}
}

@ -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<uint> &menuIds);

Loading…
Cancel
Save