dbustray: Support replacing menu on QDBusTrayIcon
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 <shawn.rutledge@qt.io>
This commit is contained in:
parent
5cc0d92c24
commit
75b49a59db
@ -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());
|
||||
@ -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)
|
||||
|
@ -66,6 +66,7 @@ public:
|
||||
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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user