diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2012-03-14 13:50:14 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-15 00:50:47 +0100 |
commit | f7957f39937c42aadecc6ad2b73d006559514e00 (patch) | |
tree | 05dd38f103090dcc7eb5d5fc9f8f6446ebef1e6f /src/platformsupport | |
parent | d295b9b9cfc8bde021bf07ea997d8cd0d14cffb8 (diff) |
Refactor theme plugin loading.
In the old implementation, the QPlatformIntegration was asked
for the theme first, so there was no way of overriding that
by a custom plugin. Also, there was a memory leak in case
the platform theme was actually created by a plugin.
QGuiApplication now asks the QPlatformIntegration for a list
of potential theme names first, tries to load them using
the plugin loader and finally invokes a factory method of
QPlatformIntegration in case that fails. The theme is now
owned by QGuiApplication.
In the XCB plugin, the environment variable DESKTOP_SESSION
is queried and appended to the list of themes, making it possible
to load plugins for other session types.
Change-Id: I1a4b4e061815bca16c65b23e591bb7563a3e44e2
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src/platformsupport')
-rw-r--r-- | src/platformsupport/themes/genericunix/qgenericunixthemes.cpp | 39 | ||||
-rw-r--r-- | src/platformsupport/themes/genericunix/qgenericunixthemes_p.h | 9 |
2 files changed, 38 insertions, 10 deletions
diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index 602dd6264a..597dbde74f 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -77,6 +77,8 @@ void ResourceHelper::clear() \ingroup qpa */ +const char *QGenericUnixTheme::name = "generic"; + // Helper to return the icon theme paths from XDG. QStringList QGenericUnixTheme::xdgIconThemePaths() { @@ -159,6 +161,8 @@ static inline bool readKdeSystemPalette(const QSettings &kdeSettings, QPalette * \ingroup qpa */ +const char *QKdeTheme::name = "kde"; + QKdeTheme::QKdeTheme(const QString &kdeHome, int kdeVersion) : m_kdeHome(kdeHome), m_kdeVersion(kdeVersion), m_toolButtonStyle(Qt::ToolButtonTextBesideIcon), m_toolBarIconSize(0) @@ -329,6 +333,8 @@ QPlatformTheme *QKdeTheme::createKdeTheme() \ingroup qpa */ +const char *QGnomeTheme::name = "gnome"; + QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const { switch (hint) { @@ -358,23 +364,38 @@ QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const \brief Creates a UNIX theme according to the detected desktop environment. */ -QPlatformTheme *QGenericUnixTheme::createUnixTheme() +QPlatformTheme *QGenericUnixTheme::createUnixTheme(const QString &name) +{ + if (name == QLatin1String(QGenericUnixTheme::name)) + return new QGenericUnixTheme; + if (name == QLatin1String(QKdeTheme::name)) + if (QPlatformTheme *kdeTheme = QKdeTheme::createKdeTheme()) + return kdeTheme; + if (name == QLatin1String(QGnomeTheme::name)) + return new QGnomeTheme; + return new QGenericUnixTheme; +} + +QStringList QGenericUnixTheme::themeNames() { - QPlatformTheme *result = 0; + QStringList result; if (QGuiApplication::desktopSettingsAware()) { switch (QGenericUnixServices::desktopEnvironment()) { - case QGenericUnixServices::DE_UNKNOWN: - break; case QGenericUnixServices::DE_KDE: - result = QKdeTheme::createKdeTheme(); + result.push_back(QLatin1String(QKdeTheme::name)); break; case QGenericUnixServices::DE_GNOME: - result = new QGnomeTheme; + result.push_back(QLatin1String(QGnomeTheme::name)); + break; + case QGenericUnixServices::DE_UNKNOWN: break; } - } - if (!result) - result = new QGenericUnixTheme; + const QByteArray session = qgetenv("DESKTOP_SESSION"); + if (!session.isEmpty() && session != "default") + result.push_back(QString::fromLocal8Bit(session)); + } // desktopSettingsAware + if (result.isEmpty()) + result.push_back(QLatin1String(QGenericUnixTheme::name)); return result; } diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h index a9db29e8cd..cabffc0212 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h @@ -67,11 +67,14 @@ class QGenericUnixTheme : public QPlatformTheme public: QGenericUnixTheme() {} - static QPlatformTheme *createUnixTheme(); + static QPlatformTheme *createUnixTheme(const QString &name); + static QStringList themeNames(); virtual QVariant themeHint(ThemeHint hint) const; static QStringList xdgIconThemePaths(); + + static const char *name; }; class QKdeTheme : public QPlatformTheme @@ -88,6 +91,8 @@ public: virtual const QFont *font(Font type) const { return m_resources.fonts[type]; } + static const char *name; + private: QString globalSettingsFile() const; void refresh(); @@ -109,6 +114,8 @@ public: QGnomeTheme() {} virtual QVariant themeHint(ThemeHint hint) const; + static const char *name; + private: }; |