dbustray: Handle StatusNotifierWatcher appearing and disappearing

If the StatusNotifierWatcher disappears and then appears again, we need
to register our tray icon again with it.

To do this, split the “register with watcher” part into a separate
method, and call it when m_dbusWatcher emits its serviceRegistered()
signal.

Change-Id: Id5fc8ac81b5038a61b678514dabd3eb9c8f1c106
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Dmitry Shachnev 2016-11-05 20:44:36 +03:00
parent 5f6800c220
commit 9067a7f59c
4 changed files with 20 additions and 3 deletions

View File

@ -119,13 +119,16 @@ bool QDBusMenuConnection::registerTrayIcon(QDBusTrayIcon *item)
if (item->menu())
registerTrayIconMenu(item);
return registerTrayIconWithWatcher(item);
}
bool QDBusMenuConnection::registerTrayIconWithWatcher(QDBusTrayIcon *item)
{
QDBusMessage registerMethod = QDBusMessage::createMethodCall(
StatusNotifierWatcherService, StatusNotifierWatcherPath, StatusNotifierWatcherService,
QLatin1String("RegisterStatusNotifierItem"));
registerMethod.setArguments(QVariantList() << item->instanceId());
success = m_connection.callWithCallback(registerMethod, this, SIGNAL(trayIconRegistered()), SLOT(dbusError(QDBusError)));
return success;
return m_connection.callWithCallback(registerMethod, this, SIGNAL(trayIconRegistered()), SLOT(dbusError(QDBusError)));
}
bool QDBusMenuConnection::unregisterTrayIcon(QDBusTrayIcon *item)

View File

@ -69,11 +69,13 @@ class QDBusMenuConnection : public QObject
public:
QDBusMenuConnection(QObject *parent = 0, const QString &serviceName = QString());
QDBusConnection connection() const { return m_connection; }
QDBusServiceWatcher *dbusWatcher() const { return m_dbusWatcher; }
bool isStatusNotifierHostRegistered() const { return m_statusNotifierHostRegistered; }
#ifndef QT_NO_SYSTEMTRAYICON
bool registerTrayIconMenu(QDBusTrayIcon *item);
void unregisterTrayIconMenu(QDBusTrayIcon *item);
bool registerTrayIcon(QDBusTrayIcon *item);
bool registerTrayIconWithWatcher(QDBusTrayIcon *item);
bool unregisterTrayIcon(QDBusTrayIcon *item);
#endif // QT_NO_SYSTEMTRAYICON

View File

@ -116,6 +116,8 @@ void QDBusTrayIcon::init()
{
qCDebug(qLcTray) << "registering" << m_instanceId;
m_registered = dBusConnection()->registerTrayIcon(this);
QObject::connect(dBusConnection()->dbusWatcher(), &QDBusServiceWatcher::serviceRegistered,
this, &QDBusTrayIcon::watcherServiceRegistered);
}
void QDBusTrayIcon::cleanup()
@ -130,6 +132,15 @@ void QDBusTrayIcon::cleanup()
m_registered = false;
}
void QDBusTrayIcon::watcherServiceRegistered(const QString &serviceName)
{
Q_UNUSED(serviceName);
// We have the icon registered, but the watcher has restarted or
// changed, so we need to tell it about our icon again
if (m_registered)
dBusConnection()->registerTrayIconWithWatcher(this);
}
void QDBusTrayIcon::attentionTimerExpired()
{
m_messageTitle = QString();

View File

@ -133,6 +133,7 @@ private Q_SLOTS:
void attentionTimerExpired();
void actionInvoked(uint id, const QString &action);
void notificationClosed(uint id, uint reason);
void watcherServiceRegistered(const QString &serviceName);
private:
void setStatus(const QString &status);