From ffeb585003a2e6b19f66eae504121f6dbfba0948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Fri, 31 Jan 2014 01:06:43 +0100 Subject: [PATCH] Rough version in which theme switching works This aligns the config files and groups, and adds a KDirWatch in the shared Plasma::Theme private object in order to nofity when the configured theme changes. It's a bit rough, doesn't cover all corner cases and needs polishing. --- src/plasma/private/theme_p.cpp | 49 +++++++++++++++++++++++++++++++--- src/plasma/private/theme_p.h | 7 +++++ src/plasma/theme.cpp | 3 ++- src/shell/shellcorona.cpp | 6 +++++ 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/plasma/private/theme_p.cpp b/src/plasma/private/theme_p.cpp index 91d32c0ff..c44944799 100644 --- a/src/plasma/private/theme_p.cpp +++ b/src/plasma/private/theme_p.cpp @@ -57,12 +57,13 @@ ThemePrivate::ThemePrivate(QObject *parent) defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH), defaultWallpaperHeight(DEFAULT_WALLPAPER_HEIGHT), pixmapCache(0), + configWatcher(0), cacheSize(0), cachesToDiscard(NoCache), locolor(false), compositingActive(KWindowSystem::self()->compositingActive()), blurActive(false), - isDefault(false), + isDefault(true), useGlobal(true), hasWallpapers(false) { @@ -90,6 +91,17 @@ ThemePrivate::ThemePrivate(QObject *parent) #endif } installEventFilter(qApp); + + configWatcher = new KDirWatch(this); + const QString configLocation = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/plasmarc"); + configWatcher->addFile(configLocation); + + //connect(configWatcher, &KDirWatch::dirty, this, &ThemePrivate::configDirty); + connect(configWatcher, &KDirWatch::created, this, &ThemePrivate::settingsFileChanged); + //connect(configWatcher, &KDirWatch::deleted, this, &ThemePrivate::configDeleted); + + qDebug() << "Theme ctor " << themeName << QCoreApplication::applicationName(); + qDebug() << "configfile: " << configLocation; } ThemePrivate::~ThemePrivate() @@ -100,7 +112,7 @@ ThemePrivate::~ThemePrivate() KConfigGroup &ThemePrivate::config() { if (!cfg.isValid()) { - QString groupName = "Theme"; + QString groupName = "Theme-plasma-shell"; if (!useGlobal) { QString app = QCoreApplication::applicationName(); @@ -109,16 +121,40 @@ KConfigGroup &ThemePrivate::config() #ifndef NDEBUG // qDebug() << "using theme for app" << app; #endif + qDebug() << "using theme for app" << app; groupName.append("-").append(app); } } - + qDebug() << "Opening " << themeRcFile << groupName; cfg = KConfigGroup(KSharedConfig::openConfig(themeRcFile), groupName); } return cfg; } + +void ThemePrivate::configDirty(const QString &path) +{ + qDebug() << "config dirty: " << path; + //config()->reparseConfiguration(); + settingsChanged(); +} + +void ThemePrivate::configCreated(const QString& path) +{ + qDebug() << "config created: " << path; + settingsChanged(); + emit themeChanged(); +} + +void ThemePrivate::configDeleted(const QString& path) +{ + qDebug() << "config deleted: " << path; + //settingsChanged(); + +} + + bool ThemePrivate::useCache() { if (cacheTheme && !pixmapCache) { @@ -379,6 +415,7 @@ const QString ThemePrivate::svgStyleSheet() void ThemePrivate::settingsFileChanged(const QString &file) { + qDebug() << "settingsFile: " << file; if (file.endsWith(themeRcFile)) { config().config()->reparseConfiguration(); settingsChanged(); @@ -387,6 +424,7 @@ void ThemePrivate::settingsFileChanged(const QString &file) void ThemePrivate::settingsChanged() { + //qDebug() << "Settings Changed!"; KConfigGroup cg = config(); setThemeName(cg.readEntry("name", ThemePrivate::defaultTheme), false); } @@ -462,16 +500,18 @@ void ThemePrivate::processWallpaperSettings(KConfigBase *metadata) void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings) { - //qDebug() << tempThemeName; QString theme = tempThemeName; if (theme.isEmpty() || theme == themeName) { + //qDebug() << "eeuh"; // let's try and get the default theme at least if (themeName.isEmpty()) { theme = ThemePrivate::defaultTheme; + qDebug() << "eeuh" << theme; } else { return; } } + qDebug() << tempThemeName; // we have one special theme: essentially a dummy theme used to cache things with // the system colors. @@ -556,6 +596,7 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings const QString wallpaperPath = QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/wallpapers/"); hasWallpapers = !QStandardPaths::locate(QStandardPaths::GenericDataLocation, wallpaperPath, QStandardPaths::LocateDirectory).isEmpty(); + qDebug() << "Writing Settings " << themeName << realTheme << isDefault << writeSettings; if (realTheme && isDefault && writeSettings) { // we're the default theme, let's save our state KConfigGroup &cg = config(); diff --git a/src/plasma/private/theme_p.h b/src/plasma/private/theme_p.h index 3dcd14044..6dcb620d0 100644 --- a/src/plasma/private/theme_p.h +++ b/src/plasma/private/theme_p.h @@ -37,6 +37,8 @@ #include "libplasma-theme-global.h" +class KDirWatch; + namespace Plasma { @@ -92,6 +94,10 @@ public Q_SLOTS: void notifyOfChanged(); void settingsChanged(); + void configDirty(const QString &path); + void configCreated(const QString &path); + void configDeleted(const QString &path); + Q_SIGNALS: void themeChanged(); void defaultFontChanged(); @@ -133,6 +139,7 @@ public: QHash discoveries; QTimer *saveTimer; QTimer *updateNotificationTimer; + KDirWatch *configWatcher; unsigned cacheSize; CacheTypes cachesToDiscard; diff --git a/src/plasma/theme.cpp b/src/plasma/theme.cpp index a0ff7c4ef..863deda59 100644 --- a/src/plasma/theme.cpp +++ b/src/plasma/theme.cpp @@ -125,6 +125,7 @@ void Theme::setThemeName(const QString &themeName) if (d->themeName == themeName) { return; } + qDebug() << "Set themeName: " << d->themeName << " to " << themeName; if (d != ThemePrivate::globalTheme) { disconnect(QCoreApplication::instance(), 0, d, 0); @@ -144,7 +145,7 @@ void Theme::setThemeName(const QString &themeName) connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), d, SLOT(onAppExitCleanup())); } - connect(d, &ThemePrivate::themeChanged, this, &Theme::themeChanged); +// connect(d, &ThemePrivate::themeChanged, this, &Theme::themeChanged); } d->setThemeName(themeName, true); diff --git a/src/shell/shellcorona.cpp b/src/shell/shellcorona.cpp index 92307268b..e258dd950 100644 --- a/src/shell/shellcorona.cpp +++ b/src/shell/shellcorona.cpp @@ -98,6 +98,12 @@ ShellCorona::ShellCorona(QObject *parent) { d->desktopDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(package().filePath("defaults")), "Desktop"); + // FIXME: read from config,if emptry from package + Plasma::Theme *t = new Plasma::Theme(this); + //t->setThemeName("oxygen"); + KConfigGroup cg(KSharedConfig::openConfig("plasmarc"), "Theme-plasma-shell"); + t->setThemeName(cg.readEntry("name", "default")); + connect(this, &ShellCorona::containmentAdded, this, &ShellCorona::handleContainmentAdded);