Skip to content

Commit

Permalink
D-Bus system tray: properly check whether StatusNotifierHost available
Browse files Browse the repository at this point in the history
"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>
  • Loading branch information
ec1oud committed Feb 20, 2015
1 parent 37ce38d commit 23e9b57
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/platformsupport/dbusmenu/qdbusmenuconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/platformsupport/dbusmenu/qdbusmenuconnection_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -80,7 +80,7 @@ private Q_SLOTS:
private:
QDBusConnection m_connection;
QDBusServiceWatcher *m_dbusWatcher;
bool m_watcherRegistered;
bool m_statusNotifierHostRegistered;
};

QT_END_NAMESPACE
Expand Down
7 changes: 2 additions & 5 deletions src/platformsupport/dbustray/qdbustrayicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 23e9b57

Please sign in to comment.