D-Bus system tray: properly check whether StatusNotifierHost available

"org.kde.StatusNotifierWatcher" is just a watcher/helper, whereas the
actual systray object is "org.kde.StatusNotifierHost-$PID".
The org.kde.StatusNotifierWatcher.IsStatusNotifierHostRegistered
property can tell us whether there is an actual system tray.
Also renamed the accessor to isStatusNotifierHostRegistered since we
are checking for the host, and also because it can be confusing
that it's a member of QDBusMenuConnection if the name isn't clear.
See also KDE bug 339707

Change-Id: I218c5357b9cc5a62e5cc07abe980893b826f98f4
Reviewed-by: Martin Klapetek <mklapetek@kde.org>
Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
Reviewed-by: Dmitry Shachnev <mitya57@gmail.com>
This commit is contained in:
Shawn Rutledge 2015-02-19 13:47:22 +01:00
parent 37ce38daec
commit 23e9b57e3d
4 changed files with 10 additions and 13 deletions

View File

@ -63,14 +63,14 @@ QDBusMenuConnection::QDBusMenuConnection(QObject *parent)
: QObject(parent)
, m_connection(QDBusConnection::sessionBus())
, m_dbusWatcher(new QDBusServiceWatcher(StatusNotifierWatcherService, m_connection, QDBusServiceWatcher::WatchForRegistration, this))
, m_watcherRegistered(false)
, m_statusNotifierHostRegistered(false)
{
#ifndef QT_NO_SYSTEMTRAYICON
// Start monitoring if any known tray-related services are registered.
if (m_connection.interface()->isServiceRegistered(StatusNotifierWatcherService))
m_watcherRegistered = true;
QDBusInterface systrayHost(StatusNotifierWatcherService, StatusNotifierWatcherPath, StatusNotifierWatcherService, m_connection);
if (systrayHost.isValid() && systrayHost.property("IsStatusNotifierHostRegistered").toBool())
m_statusNotifierHostRegistered = true;
else
qCDebug(qLcMenu) << "failed to find service" << StatusNotifierWatcherService;
qCDebug(qLcMenu) << "StatusNotifierHost is not registered";
#endif
}

View File

@ -63,7 +63,7 @@ class QDBusMenuConnection : public QObject
public:
QDBusMenuConnection(QObject *parent = 0);
QDBusConnection connection() const { return m_connection; }
bool isWatcherRegistered() const { return m_watcherRegistered; }
bool isStatusNotifierHostRegistered() const { return m_statusNotifierHostRegistered; }
#ifndef QT_NO_SYSTEMTRAYICON
bool registerTrayIcon(QDBusTrayIcon *item);
bool unregisterTrayIcon(QDBusTrayIcon *item);
@ -80,7 +80,7 @@ private Q_SLOTS:
private:
QDBusConnection m_connection;
QDBusServiceWatcher *m_dbusWatcher;
bool m_watcherRegistered;
bool m_statusNotifierHostRegistered;
};
QT_END_NAMESPACE

View File

@ -281,11 +281,8 @@ void QDBusTrayIcon::notificationClosed(uint id, uint reason)
bool QDBusTrayIcon::isSystemTrayAvailable() const
{
QDBusMenuConnection * conn = const_cast<QDBusTrayIcon *>(this)->dBusConnection();
// If the KDE watcher service is registered, we must be on a desktop
// where a StatusNotifier-conforming system tray exists.
qCDebug(qLcTray) << conn->isWatcherRegistered();
return conn->isWatcherRegistered();
qCDebug(qLcTray) << conn->isStatusNotifierHostRegistered();
return conn->isStatusNotifierHostRegistered();
}
QT_END_NAMESPACE

View File

@ -98,7 +98,7 @@ static bool isDBusTrayAvailable() {
static bool dbusTrayAvailableKnown = false;
if (!dbusTrayAvailableKnown) {
QDBusMenuConnection conn;
if (conn.isWatcherRegistered())
if (conn.isStatusNotifierHostRegistered())
dbusTrayAvailable = true;
dbusTrayAvailableKnown = true;
qCDebug(qLcTray) << "D-Bus tray available:" << dbusTrayAvailable;