summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-03-14 13:50:14 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-15 00:50:47 +0100
commitf7957f39937c42aadecc6ad2b73d006559514e00 (patch)
tree05dd38f103090dcc7eb5d5fc9f8f6446ebef1e6f /src/gui
parentd295b9b9cfc8bde021bf07ea997d8cd0d14cffb8 (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/gui')
-rw-r--r--src/gui/kernel/qguiapplication.cpp16
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.cpp11
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.h3
3 files changed, 24 insertions, 6 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 77b69af3eb..ca1ecbef2b 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -538,13 +538,22 @@ static void init_platform(const QString &pluginArgument, const QString &platform
}
// Create the platform theme:
- // 1) Ask the platform integration to create a platform theme
- QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->platformTheme();
+ // 1) Ask the platform integration for a list of names.
+ const QStringList themeNames = QGuiApplicationPrivate::platform_integration->themeNames();
+ foreach (const QString &themeName, themeNames) {
+ QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
+ if (QGuiApplicationPrivate::platform_theme)
+ break;
+ }
// 2) If none found, look for a theme plugin. Theme plugins are located in the
// same directory as platform plugins.
if (!QGuiApplicationPrivate::platform_theme) {
- QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(name, platformPluginPath);
+ foreach (const QString &themeName, themeNames) {
+ QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
+ if (QGuiApplicationPrivate::platform_theme)
+ break;
+ }
// No error message; not having a theme plugin is allowed.
}
@@ -748,6 +757,7 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate()
qt_cleanupFontDatabase();
+ delete platform_theme;
delete platform_integration;
platform_integration = 0;
}
diff --git a/src/gui/kernel/qplatformintegration_qpa.cpp b/src/gui/kernel/qplatformintegration_qpa.cpp
index e8721edce7..c9ccc27ad0 100644
--- a/src/gui/kernel/qplatformintegration_qpa.cpp
+++ b/src/gui/kernel/qplatformintegration_qpa.cpp
@@ -44,6 +44,7 @@
#include <QtGui/QPlatformFontDatabase>
#include <QtGui/QPlatformClipboard>
#include <QtGui/QPlatformAccessibility>
+#include <QtGui/QPlatformTheme>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/private/qpixmap_raster_p.h>
#include <QtGui/private/qplatformscreen_qpa_p.h>
@@ -315,9 +316,15 @@ void QPlatformIntegration::screenAdded(QPlatformScreen *ps)
emit qGuiApp->screenAdded(screen);
}
-class QPlatformTheme *QPlatformIntegration::platformTheme() const
+QStringList QPlatformIntegration::themeNames() const
{
- return 0;
+ return QStringList();
+}
+
+class QPlatformTheme *QPlatformIntegration::createPlatformTheme(const QString &name) const
+{
+ Q_UNUSED(name)
+ return new QPlatformTheme;
}
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformintegration_qpa.h b/src/gui/kernel/qplatformintegration_qpa.h
index 3f9de9df5e..d6f5b6658a 100644
--- a/src/gui/kernel/qplatformintegration_qpa.h
+++ b/src/gui/kernel/qplatformintegration_qpa.h
@@ -126,7 +126,8 @@ public:
virtual Qt::KeyboardModifiers queryKeyboardModifiers() const;
- virtual QPlatformTheme *platformTheme() const;
+ virtual QStringList themeNames() const;
+ virtual QPlatformTheme *createPlatformTheme(const QString &name) const;
protected:
void screenAdded(QPlatformScreen *screen);