From b6a824d0a3b4fabd9c22fe4c954d50e8755fb509 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Fri, 15 Jan 2016 17:04:01 +0300 Subject: Add native support for D-Bus global menu The protocol was originally developed by Canonical, currently supported by Unity and Plasma. Adjust some tests to use the non-native menu bar when they require it. [ChangeLog][XCB / X11] QMenuBar uses the unified D-Bus AppMenu menubar when the desktop environment supports it. Change-Id: Iea74b40522573bcc4f70168fe7fa2a49b4f3fc21 Reviewed-by: Shawn Rutledge --- .../themes/genericunix/qgenericunixthemes.cpp | 68 +++++++++++++++++++++- .../themes/genericunix/qgenericunixthemes_p.h | 12 ++++ 2 files changed, 79 insertions(+), 1 deletion(-) (limited to 'src/platformsupport/themes') diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index 026ba11c3d..aee12eed76 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -59,9 +59,12 @@ #include #include #include +#ifndef QT_NO_DBUS +#include "QtPlatformSupport/private/qdbusplatformmenu_p.h" +#include "QtPlatformSupport/private/qdbusmenubar_p.h" +#endif #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) #include "QtPlatformSupport/private/qdbustrayicon_p.h" -#include "QtPlatformSupport/private/qdbusplatformmenu_p.h" #endif #include @@ -114,6 +117,21 @@ static bool isDBusTrayAvailable() { } #endif +#ifndef QT_NO_DBUS +static bool checkDBusGlobalMenuAvailable() +{ + QDBusConnection connection = QDBusConnection::sessionBus(); + QString registrarService = QStringLiteral("com.canonical.AppMenu.Registrar"); + return connection.interface()->isServiceRegistered(registrarService); +} + +static bool isDBusGlobalMenuAvailable() +{ + static bool dbusGlobalMenuAvailable = checkDBusGlobalMenuAvailable(); + return dbusGlobalMenuAvailable; +} +#endif + class QGenericUnixThemePrivate : public QPlatformThemePrivate { public: @@ -172,6 +190,22 @@ QStringList QGenericUnixTheme::xdgIconThemePaths() return paths; } +#ifndef QT_NO_DBUS +QPlatformMenu *QGenericUnixTheme::createPlatformMenu() const +{ + if (isDBusGlobalMenuAvailable()) + return new QDBusPlatformMenu(); + return nullptr; +} + +QPlatformMenuBar *QGenericUnixTheme::createPlatformMenuBar() const +{ + if (isDBusGlobalMenuAvailable()) + return new QDBusMenuBar(); + return nullptr; +} +#endif + #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) QPlatformSystemTrayIcon *QGenericUnixTheme::createPlatformSystemTrayIcon() const { @@ -559,6 +593,22 @@ QPlatformTheme *QKdeTheme::createKdeTheme() return new QKdeTheme(kdeDirs, kdeVersion); } +#ifndef QT_NO_DBUS +QPlatformMenu *QKdeTheme::createPlatformMenu() const +{ + if (isDBusGlobalMenuAvailable()) + return new QDBusPlatformMenu(); + return nullptr; +} + +QPlatformMenuBar *QKdeTheme::createPlatformMenuBar() const +{ + if (isDBusGlobalMenuAvailable()) + return new QDBusMenuBar(); + return nullptr; +} +#endif + #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) QPlatformSystemTrayIcon *QKdeTheme::createPlatformSystemTrayIcon() const { @@ -655,6 +705,22 @@ QString QGnomeTheme::gtkFontName() const return QStringLiteral("%1 %2").arg(QLatin1String(defaultSystemFontNameC)).arg(defaultSystemFontSize); } +#ifndef QT_NO_DBUS +QPlatformMenu *QGnomeTheme::createPlatformMenu() const +{ + if (isDBusGlobalMenuAvailable()) + return new QDBusPlatformMenu(); + return nullptr; +} + +QPlatformMenuBar *QGnomeTheme::createPlatformMenuBar() const +{ + if (isDBusGlobalMenuAvailable()) + return new QDBusMenuBar(); + return nullptr; +} +#endif + #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) QPlatformSystemTrayIcon *QGnomeTheme::createPlatformSystemTrayIcon() const { diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h index 2d46a4d95e..b7e0d53d6f 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h @@ -85,6 +85,10 @@ public: QVariant themeHint(ThemeHint hint) const Q_DECL_OVERRIDE; static QStringList xdgIconThemePaths(); +#ifndef QT_NO_DBUS + QPlatformMenu *createPlatformMenu() const Q_DECL_OVERRIDE; + QPlatformMenuBar *createPlatformMenuBar() const Q_DECL_OVERRIDE; +#endif #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const Q_DECL_OVERRIDE; #endif @@ -107,6 +111,10 @@ public: const QPalette *palette(Palette type = SystemPalette) const Q_DECL_OVERRIDE; const QFont *font(Font type) const Q_DECL_OVERRIDE; +#ifndef QT_NO_DBUS + QPlatformMenu *createPlatformMenu() const Q_DECL_OVERRIDE; + QPlatformMenuBar *createPlatformMenuBar() const Q_DECL_OVERRIDE; +#endif #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const Q_DECL_OVERRIDE; #endif @@ -127,6 +135,10 @@ public: QString standardButtonText(int button) const Q_DECL_OVERRIDE; virtual QString gtkFontName() const; +#ifndef QT_NO_DBUS + QPlatformMenu *createPlatformMenu() const Q_DECL_OVERRIDE; + QPlatformMenuBar *createPlatformMenuBar() const Q_DECL_OVERRIDE; +#endif #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const Q_DECL_OVERRIDE; #endif -- cgit v1.2.3