From 9789d8b57ff21c2c53bf6e63c907c1ed96852cd9 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 17 Jul 2007 20:51:12 +0000 Subject: [PATCH] make it possible to set the theme per-application, allowing krunner to share plasma's theme by default but amarok to have their own Fun(tm) too svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=689180 --- theme.cpp | 45 ++++++++++++++++++++++++++++++++++----------- theme.h | 16 ++++++++++++++++ 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/theme.cpp b/theme.cpp index 46f7d24b8..e9db3d541 100644 --- a/theme.cpp +++ b/theme.cpp @@ -27,19 +27,20 @@ namespace Plasma class Theme::Private { - public: - Private() - : themeName( "default" ) - { - } +public: + Private() + : themeName( "default" ) + { + } - QString themeName; + QString themeName; + QString app; }; class ThemeSingleton { - public: - Theme self; +public: + Theme self; }; K_GLOBAL_STATIC( ThemeSingleton, privateSelf ) @@ -53,9 +54,7 @@ Theme::Theme(QObject* parent) : QObject(parent), d(new Private) { - KConfig config( "plasmarc" ); - KConfigGroup group( &config, "Theme" ); - d->themeName = group.readEntry( "name", d->themeName ); + settingsChanged(); } Theme::~Theme() @@ -63,6 +62,30 @@ Theme::~Theme() delete d; } +void Theme::setApplication(const QString &appname) +{ + if (d->app != appname) { + d->app = appname; + settingsChanged(); + } +} + +void Theme::settingsChanged() +{ + QString groupName = "Theme"; + if (!d->app.isEmpty() && d->app != "plasma") { + groupName.append("-").append(d->app); + } + + KSharedConfig::Ptr config = KSharedConfig::openConfig("plasmarc"); + KConfigGroup group(config, groupName); + QString themeName = group.readEntry("name", d->themeName); + if (themeName != d->themeName) { + d->themeName = themeName; + emit changed(); + } +} + QString Theme::themeName() const { return d->themeName; diff --git a/theme.h b/theme.h index 2a01b128e..96bfab9a5 100644 --- a/theme.h +++ b/theme.h @@ -57,6 +57,15 @@ class PLASMA_EXPORT Theme : public QObject explicit Theme( QObject* parent = 0 ); ~Theme(); + /** + * Sets the application the theme setting is associated with. This + * allows for individual applications that use libplasma to have the + * theme set independantly. + * + * @param appname name of the application + **/ + void setApplication(const QString &appname); + /** * @return the name of the theme. "default" is none set. */ @@ -78,6 +87,13 @@ class PLASMA_EXPORT Theme : public QObject */ void changed(); + public Q_SLOTS: + /** + * Notifies the Theme object that the theme settings have changed + * and should be read from the config file + **/ + void settingsChanged(); + private: class Private; Private* const d;