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:
parent
37ce38daec
commit
23e9b57e3d
@ -63,14 +63,14 @@ QDBusMenuConnection::QDBusMenuConnection(QObject *parent)
|
|||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_connection(QDBusConnection::sessionBus())
|
, m_connection(QDBusConnection::sessionBus())
|
||||||
, m_dbusWatcher(new QDBusServiceWatcher(StatusNotifierWatcherService, m_connection, QDBusServiceWatcher::WatchForRegistration, this))
|
, m_dbusWatcher(new QDBusServiceWatcher(StatusNotifierWatcherService, m_connection, QDBusServiceWatcher::WatchForRegistration, this))
|
||||||
, m_watcherRegistered(false)
|
, m_statusNotifierHostRegistered(false)
|
||||||
{
|
{
|
||||||
#ifndef QT_NO_SYSTEMTRAYICON
|
#ifndef QT_NO_SYSTEMTRAYICON
|
||||||
// Start monitoring if any known tray-related services are registered.
|
QDBusInterface systrayHost(StatusNotifierWatcherService, StatusNotifierWatcherPath, StatusNotifierWatcherService, m_connection);
|
||||||
if (m_connection.interface()->isServiceRegistered(StatusNotifierWatcherService))
|
if (systrayHost.isValid() && systrayHost.property("IsStatusNotifierHostRegistered").toBool())
|
||||||
m_watcherRegistered = true;
|
m_statusNotifierHostRegistered = true;
|
||||||
else
|
else
|
||||||
qCDebug(qLcMenu) << "failed to find service" << StatusNotifierWatcherService;
|
qCDebug(qLcMenu) << "StatusNotifierHost is not registered";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class QDBusMenuConnection : public QObject
|
|||||||
public:
|
public:
|
||||||
QDBusMenuConnection(QObject *parent = 0);
|
QDBusMenuConnection(QObject *parent = 0);
|
||||||
QDBusConnection connection() const { return m_connection; }
|
QDBusConnection connection() const { return m_connection; }
|
||||||
bool isWatcherRegistered() const { return m_watcherRegistered; }
|
bool isStatusNotifierHostRegistered() const { return m_statusNotifierHostRegistered; }
|
||||||
#ifndef QT_NO_SYSTEMTRAYICON
|
#ifndef QT_NO_SYSTEMTRAYICON
|
||||||
bool registerTrayIcon(QDBusTrayIcon *item);
|
bool registerTrayIcon(QDBusTrayIcon *item);
|
||||||
bool unregisterTrayIcon(QDBusTrayIcon *item);
|
bool unregisterTrayIcon(QDBusTrayIcon *item);
|
||||||
@ -80,7 +80,7 @@ private Q_SLOTS:
|
|||||||
private:
|
private:
|
||||||
QDBusConnection m_connection;
|
QDBusConnection m_connection;
|
||||||
QDBusServiceWatcher *m_dbusWatcher;
|
QDBusServiceWatcher *m_dbusWatcher;
|
||||||
bool m_watcherRegistered;
|
bool m_statusNotifierHostRegistered;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -281,11 +281,8 @@ void QDBusTrayIcon::notificationClosed(uint id, uint reason)
|
|||||||
bool QDBusTrayIcon::isSystemTrayAvailable() const
|
bool QDBusTrayIcon::isSystemTrayAvailable() const
|
||||||
{
|
{
|
||||||
QDBusMenuConnection * conn = const_cast<QDBusTrayIcon *>(this)->dBusConnection();
|
QDBusMenuConnection * conn = const_cast<QDBusTrayIcon *>(this)->dBusConnection();
|
||||||
|
qCDebug(qLcTray) << conn->isStatusNotifierHostRegistered();
|
||||||
// If the KDE watcher service is registered, we must be on a desktop
|
return conn->isStatusNotifierHostRegistered();
|
||||||
// where a StatusNotifier-conforming system tray exists.
|
|
||||||
qCDebug(qLcTray) << conn->isWatcherRegistered();
|
|
||||||
return conn->isWatcherRegistered();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -98,7 +98,7 @@ static bool isDBusTrayAvailable() {
|
|||||||
static bool dbusTrayAvailableKnown = false;
|
static bool dbusTrayAvailableKnown = false;
|
||||||
if (!dbusTrayAvailableKnown) {
|
if (!dbusTrayAvailableKnown) {
|
||||||
QDBusMenuConnection conn;
|
QDBusMenuConnection conn;
|
||||||
if (conn.isWatcherRegistered())
|
if (conn.isStatusNotifierHostRegistered())
|
||||||
dbusTrayAvailable = true;
|
dbusTrayAvailable = true;
|
||||||
dbusTrayAvailableKnown = true;
|
dbusTrayAvailableKnown = true;
|
||||||
qCDebug(qLcTray) << "D-Bus tray available:" << dbusTrayAvailable;
|
qCDebug(qLcTray) << "D-Bus tray available:" << dbusTrayAvailable;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user