D-Bus tray icons: try to use them with QGenericUnixTheme

Until now, only the Gnome and KDE themes have done this.  But
the gtk2 theme is not the same as the gnome theme. Further, Ubuntu sets
the environment variable QT_QPA_PLATFORMTHEME=appmenu-qt5 if that
plugin is installed on the system; and then with a custom build of Qt
which cannot load the module (e.g. a static build), it will again
fall back to QGenericUnixTheme instead of the gnome theme. In both
cases we want to still try to use D-Bus StatusNotifier protocol
instead of XEmbed. In general it should always be safe to check
whether or not that is possible, before falling back to the XEmbed
tray icon implementation.

Change-Id: I86d6c6f6ad410ea31770d39166d0a7e3330365a0
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
bb10
Shawn Rutledge 2015-02-04 15:13:25 +01:00
parent f8dd268e50
commit 69d46a3e20
2 changed files with 16 additions and 0 deletions

View File

@ -44,6 +44,7 @@
#include <QtCore/QFile>
#include <QtCore/QDebug>
#include <QtCore/QHash>
#include <QtCore/QLoggingCategory>
#include <QtCore/QSettings>
#include <QtCore/QVariant>
#include <QtCore/QStringList>
@ -60,6 +61,8 @@
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(qLcTray)
ResourceHelper::ResourceHelper()
{
std::fill(palettes, palettes + QPlatformTheme::NPalettes, static_cast<QPalette *>(0));
@ -98,6 +101,7 @@ static bool isDBusTrayAvailable() {
if (conn.isWatcherRegistered())
dbusTrayAvailable = true;
dbusTrayAvailableKnown = true;
qCDebug(qLcTray) << "D-Bus tray available:" << dbusTrayAvailable;
}
return dbusTrayAvailable;
}
@ -161,6 +165,15 @@ QStringList QGenericUnixTheme::xdgIconThemePaths()
return paths;
}
#if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON)
QPlatformSystemTrayIcon *QGenericUnixTheme::createPlatformSystemTrayIcon() const
{
if (isDBusTrayAvailable())
return new QDBusTrayIcon();
return Q_NULLPTR;
}
#endif
QVariant QGenericUnixTheme::themeHint(ThemeHint hint) const
{
switch (hint) {

View File

@ -79,6 +79,9 @@ public:
virtual QVariant themeHint(ThemeHint hint) const Q_DECL_OVERRIDE;
static QStringList xdgIconThemePaths();
#if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON)
QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const Q_DECL_OVERRIDE;
#endif
static const char *name;
};