Skip to content

Commit

Permalink
dbustray: Support replacing menu on QDBusTrayIcon
Browse files Browse the repository at this point in the history
If a new menu is set via the updateMenu() method, properly unregister
the old menu and register the new one.

Task-number: QTBUG-53676
Change-Id: I8c1ea2d171caec01488f0fe8a565bc9b2f7e431e
Reviewed-by: Shawn Rutledge <[email protected]>
  • Loading branch information
mitya57 committed Oct 7, 2016
1 parent 5cc0d92 commit 75b49a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/platformsupport/dbusmenu/qdbusmenuconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ bool QDBusMenuConnection::registerTrayIconMenu(QDBusTrayIcon *item)
return success;
}

void QDBusMenuConnection::unregisterTrayIconMenu(QDBusTrayIcon *item)
{
if (item->menu())
connection().unregisterObject(MenuBarPath);
}

bool QDBusMenuConnection::registerTrayIcon(QDBusTrayIcon *item)
{
bool success = connection().registerService(item->instanceId());
Expand Down Expand Up @@ -118,7 +124,7 @@ bool QDBusMenuConnection::registerTrayIcon(QDBusTrayIcon *item)

bool QDBusMenuConnection::unregisterTrayIcon(QDBusTrayIcon *item)
{
connection().unregisterObject(MenuBarPath);
unregisterTrayIconMenu(item);
connection().unregisterObject(StatusNotifierItemPath);
bool success = connection().unregisterService(item->instanceId());
if (!success)
Expand Down
1 change: 1 addition & 0 deletions src/platformsupport/dbusmenu/qdbusmenuconnection_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class QDBusMenuConnection : public QObject
bool isStatusNotifierHostRegistered() const { return m_statusNotifierHostRegistered; }
#ifndef QT_NO_SYSTEMTRAYICON
bool registerTrayIconMenu(QDBusTrayIcon *item);
void unregisterTrayIconMenu(QDBusTrayIcon *item);
bool registerTrayIcon(QDBusTrayIcon *item);
bool unregisterTrayIcon(QDBusTrayIcon *item);
#endif // QT_NO_SYSTEMTRAYICON
Expand Down
15 changes: 8 additions & 7 deletions src/platformsupport/dbustray/qdbustrayicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,21 @@ QPlatformMenu *QDBusTrayIcon::createMenu() const
void QDBusTrayIcon::updateMenu(QPlatformMenu * menu)
{
qCDebug(qLcTray) << menu;
bool needsRegistering = !m_menu;
if (!m_menu)
m_menu = qobject_cast<QDBusPlatformMenu *>(menu);
if (!m_menuAdaptor) {
QDBusPlatformMenu *newMenu = qobject_cast<QDBusPlatformMenu *>(menu);
if (m_menu != newMenu) {
if (m_menu) {
dBusConnection()->unregisterTrayIconMenu(this);
delete m_menuAdaptor;
}
m_menu = newMenu;
m_menuAdaptor = new QDBusMenuAdaptor(m_menu);
// TODO connect(m_menu, , m_menuAdaptor, SIGNAL(ItemActivationRequested(int,uint)));
connect(m_menu, SIGNAL(propertiesUpdated(QDBusMenuItemList,QDBusMenuItemKeysList)),
m_menuAdaptor, SIGNAL(ItemsPropertiesUpdated(QDBusMenuItemList,QDBusMenuItemKeysList)));
connect(m_menu, SIGNAL(updated(uint,int)),
m_menuAdaptor, SIGNAL(LayoutUpdated(uint,int)));
}
m_menu->emitUpdated();
if (needsRegistering)
dBusConnection()->registerTrayIconMenu(this);
}
}

void QDBusTrayIcon::showMessage(const QString &title, const QString &msg, const QIcon &icon,
Expand Down

0 comments on commit 75b49a5

Please sign in to comment.