diff options
author | Dmitry Shachnev <mitya57@gmail.com> | 2016-01-21 20:43:50 +0300 |
---|---|---|
committer | Dmitry Shachnev <mitya57@gmail.com> | 2016-02-08 10:43:06 +0000 |
commit | 9c7f37e648024a8c7129e332dfb12b3ebd1ebf25 (patch) | |
tree | 9ff22f3f7b67960bd110331147cd859e156593fb /src/platformsupport/dbusmenu/qdbusmenutypes.cpp | |
parent | 01859cc12126b7205f5b54d383a9aa88db756f21 (diff) |
dbusmenu: Refactor the code to allow dynamic updating of menus
* Transfer propertiesUpdated and updated signals from submenus to parent
menus. Without this, the adaptor only receives this signal from top-level
menu items, and doesn't receive it from items of submenus. Connect to
these signals when a menu item is added or synced, and disconnect when it
is removed.
* Make QDBusPlatformMenus use IDs of items containing them, not their own
IDs (own IDs do not make any sense since they are not exported over D-Bus).
* Store toplevel menus per-adaptor, to make it possible to export multiple
menus (for example a menubar and a tray icon menu).
* Adjust the QDBusMenuLayoutItem::populate methods to always get the menu
via its containing item and to populate the menus recursively.
* Map D-Bus menu AboutToShow method to platform menu aboutToShow method,
and map hovered and closed events to hovered and aboutToHide signals.
(QTBUG-46293)
* Always set the visible property on item. Otherwise, when an item becomes
visible, the D-Bus menu still thinks it's invisible because that property
was not changed back to true. (QTBUG-48647)
* Call emitUpdated from insertMenuItem and removeMenuItem methods, as they
really update layout. Do not call it from syncMenuItem, it changes only
properties but not the layout.
* Start revision numbering with 1, because libdbusmenu-based hosts ignore
updated signal with revision=1.
Task-number: QTBUG-46293
Task-number: QTBUG-48647
Change-Id: Icf713405db0443e25462c1a19046df7689fe5e78
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
Reviewed-by: Błażej Szczygieł <spaz16@wp.pl>
Diffstat (limited to 'src/platformsupport/dbusmenu/qdbusmenutypes.cpp')
-rw-r--r-- | src/platformsupport/dbusmenu/qdbusmenutypes.cpp | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/platformsupport/dbusmenu/qdbusmenutypes.cpp b/src/platformsupport/dbusmenu/qdbusmenutypes.cpp index 9f356bf281..b642038e7f 100644 --- a/src/platformsupport/dbusmenu/qdbusmenutypes.cpp +++ b/src/platformsupport/dbusmenu/qdbusmenutypes.cpp @@ -80,29 +80,27 @@ const QDBusArgument &operator>>(const QDBusArgument &arg, QDBusMenuItemKeys &key return arg; } -uint QDBusMenuLayoutItem::populate(int id, int depth, const QStringList &propertyNames) +uint QDBusMenuLayoutItem::populate(int id, int depth, const QStringList &propertyNames, const QDBusPlatformMenu *topLevelMenu) { qCDebug(qLcMenu) << id << "depth" << depth << propertyNames; m_id = id; if (id == 0) { m_properties.insert(QLatin1String("children-display"), QLatin1String("submenu")); - Q_FOREACH (const QDBusPlatformMenu *menu, QDBusPlatformMenu::topLevelMenus()) { - if (menu) - populate(menu, depth, propertyNames); - } + if (topLevelMenu) + populate(topLevelMenu, depth, propertyNames); return 1; // revision } - const QDBusPlatformMenu *menu = QDBusPlatformMenu::byId(id); - if (!menu) { - QDBusPlatformMenuItem *item = QDBusPlatformMenuItem::byId(id); - if (item) - menu = static_cast<const QDBusPlatformMenu *>(item->menu()); + QDBusPlatformMenuItem *item = QDBusPlatformMenuItem::byId(id); + if (item) { + const QDBusPlatformMenu *menu = static_cast<const QDBusPlatformMenu *>(item->menu()); + + if (menu) { + if (depth != 0) + populate(menu, depth, propertyNames); + return menu->revision(); + } } - if (depth != 0 && menu) - populate(menu, depth, propertyNames); - if (menu) - return menu->revision(); return 1; // revision } @@ -118,11 +116,13 @@ void QDBusMenuLayoutItem::populate(const QDBusPlatformMenu *menu, int depth, con void QDBusMenuLayoutItem::populate(const QDBusPlatformMenuItem *item, int depth, const QStringList &propertyNames) { - Q_UNUSED(depth) - Q_UNUSED(propertyNames) m_id = item->dbusID(); QDBusMenuItem proxy(item); m_properties = proxy.m_properties; + + const QDBusPlatformMenu *menu = static_cast<const QDBusPlatformMenu *>(item->menu()); + if (depth != 0 && menu) + populate(menu, depth, propertyNames); } const QDBusArgument &operator<<(QDBusArgument &arg, const QDBusMenuLayoutItem &item) @@ -199,8 +199,7 @@ QDBusMenuItem::QDBusMenuItem(const QDBusPlatformMenuItem *item) m_properties.insert(QLatin1String("icon-data"), buf.data()); } } - if (!item->isVisible()) - m_properties.insert(QLatin1String("visible"), false); + m_properties.insert(QLatin1String("visible"), item->isVisible()); } QDBusMenuItemList QDBusMenuItem::items(const QList<int> &ids, const QStringList &propertyNames) |