dbustray: Support late registering of tray icon menu
If a menu is added to the tray icon after the icon itself has been registered, we need to register the menu properly. Change-Id: I19a6d78848142d66c2cd882746d8d55c0b9a2818 Reviewed-by: Błażej Szczygieł <spaz16@wp.pl> Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
This commit is contained in:
parent
7ad930987d
commit
a4fac65938
@ -80,6 +80,14 @@ void QDBusMenuConnection::dbusError(const QDBusError &error)
|
||||
}
|
||||
|
||||
#ifndef QT_NO_SYSTEMTRAYICON
|
||||
bool QDBusMenuConnection::registerTrayIconMenu(QDBusTrayIcon *item)
|
||||
{
|
||||
bool success = connection().registerObject(MenuBarPath, item->menu());
|
||||
if (!success) // success == false is normal, because the object may be already registered
|
||||
qCDebug(qLcMenu) << "failed to register" << item->instanceId() << MenuBarPath;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool QDBusMenuConnection::registerTrayIcon(QDBusTrayIcon *item)
|
||||
{
|
||||
bool success = connection().registerService(item->instanceId());
|
||||
@ -95,14 +103,8 @@ bool QDBusMenuConnection::registerTrayIcon(QDBusTrayIcon *item)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (item->menu()) {
|
||||
success = connection().registerObject(MenuBarPath, item->menu());
|
||||
if (!success) {
|
||||
unregisterTrayIcon(item);
|
||||
qWarning() << "failed to register" << item->instanceId() << MenuBarPath;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (item->menu())
|
||||
registerTrayIconMenu(item);
|
||||
|
||||
QDBusMessage registerMethod = QDBusMessage::createMethodCall(
|
||||
StatusNotifierWatcherService, StatusNotifierWatcherPath, StatusNotifierWatcherService,
|
||||
|
@ -65,6 +65,7 @@ public:
|
||||
QDBusConnection connection() const { return m_connection; }
|
||||
bool isStatusNotifierHostRegistered() const { return m_statusNotifierHostRegistered; }
|
||||
#ifndef QT_NO_SYSTEMTRAYICON
|
||||
bool registerTrayIconMenu(QDBusTrayIcon *item);
|
||||
bool registerTrayIcon(QDBusTrayIcon *item);
|
||||
bool unregisterTrayIcon(QDBusTrayIcon *item);
|
||||
#endif // QT_NO_SYSTEMTRAYICON
|
||||
|
@ -190,6 +190,7 @@ 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) {
|
||||
@ -201,6 +202,8 @@ void QDBusTrayIcon::updateMenu(QPlatformMenu * menu)
|
||||
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…
x
Reference in New Issue
Block a user