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.
This commit is contained in:
Sebastian Kügler 2014-01-31 01:06:43 +01:00
parent d2d7ae09d0
commit ffeb585003
4 changed files with 60 additions and 5 deletions

View File

@ -57,12 +57,13 @@ ThemePrivate::ThemePrivate(QObject *parent)
defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH), defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH),
defaultWallpaperHeight(DEFAULT_WALLPAPER_HEIGHT), defaultWallpaperHeight(DEFAULT_WALLPAPER_HEIGHT),
pixmapCache(0), pixmapCache(0),
configWatcher(0),
cacheSize(0), cacheSize(0),
cachesToDiscard(NoCache), cachesToDiscard(NoCache),
locolor(false), locolor(false),
compositingActive(KWindowSystem::self()->compositingActive()), compositingActive(KWindowSystem::self()->compositingActive()),
blurActive(false), blurActive(false),
isDefault(false), isDefault(true),
useGlobal(true), useGlobal(true),
hasWallpapers(false) hasWallpapers(false)
{ {
@ -90,6 +91,17 @@ ThemePrivate::ThemePrivate(QObject *parent)
#endif #endif
} }
installEventFilter(qApp); 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() ThemePrivate::~ThemePrivate()
@ -100,7 +112,7 @@ ThemePrivate::~ThemePrivate()
KConfigGroup &ThemePrivate::config() KConfigGroup &ThemePrivate::config()
{ {
if (!cfg.isValid()) { if (!cfg.isValid()) {
QString groupName = "Theme"; QString groupName = "Theme-plasma-shell";
if (!useGlobal) { if (!useGlobal) {
QString app = QCoreApplication::applicationName(); QString app = QCoreApplication::applicationName();
@ -109,16 +121,40 @@ KConfigGroup &ThemePrivate::config()
#ifndef NDEBUG #ifndef NDEBUG
// qDebug() << "using theme for app" << app; // qDebug() << "using theme for app" << app;
#endif #endif
qDebug() << "using theme for app" << app;
groupName.append("-").append(app); groupName.append("-").append(app);
} }
} }
qDebug() << "Opening " << themeRcFile << groupName;
cfg = KConfigGroup(KSharedConfig::openConfig(themeRcFile), groupName); cfg = KConfigGroup(KSharedConfig::openConfig(themeRcFile), groupName);
} }
return cfg; 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() bool ThemePrivate::useCache()
{ {
if (cacheTheme && !pixmapCache) { if (cacheTheme && !pixmapCache) {
@ -379,6 +415,7 @@ const QString ThemePrivate::svgStyleSheet()
void ThemePrivate::settingsFileChanged(const QString &file) void ThemePrivate::settingsFileChanged(const QString &file)
{ {
qDebug() << "settingsFile: " << file;
if (file.endsWith(themeRcFile)) { if (file.endsWith(themeRcFile)) {
config().config()->reparseConfiguration(); config().config()->reparseConfiguration();
settingsChanged(); settingsChanged();
@ -387,6 +424,7 @@ void ThemePrivate::settingsFileChanged(const QString &file)
void ThemePrivate::settingsChanged() void ThemePrivate::settingsChanged()
{ {
//qDebug() << "Settings Changed!";
KConfigGroup cg = config(); KConfigGroup cg = config();
setThemeName(cg.readEntry("name", ThemePrivate::defaultTheme), false); setThemeName(cg.readEntry("name", ThemePrivate::defaultTheme), false);
} }
@ -462,16 +500,18 @@ void ThemePrivate::processWallpaperSettings(KConfigBase *metadata)
void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings) void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings)
{ {
//qDebug() << tempThemeName;
QString theme = tempThemeName; QString theme = tempThemeName;
if (theme.isEmpty() || theme == themeName) { if (theme.isEmpty() || theme == themeName) {
//qDebug() << "eeuh";
// let's try and get the default theme at least // let's try and get the default theme at least
if (themeName.isEmpty()) { if (themeName.isEmpty()) {
theme = ThemePrivate::defaultTheme; theme = ThemePrivate::defaultTheme;
qDebug() << "eeuh" << theme;
} else { } else {
return; return;
} }
} }
qDebug() << tempThemeName;
// we have one special theme: essentially a dummy theme used to cache things with // we have one special theme: essentially a dummy theme used to cache things with
// the system colors. // the system colors.
@ -556,6 +596,7 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
const QString wallpaperPath = QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/wallpapers/"); const QString wallpaperPath = QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/wallpapers/");
hasWallpapers = !QStandardPaths::locate(QStandardPaths::GenericDataLocation, wallpaperPath, QStandardPaths::LocateDirectory).isEmpty(); hasWallpapers = !QStandardPaths::locate(QStandardPaths::GenericDataLocation, wallpaperPath, QStandardPaths::LocateDirectory).isEmpty();
qDebug() << "Writing Settings " << themeName << realTheme << isDefault << writeSettings;
if (realTheme && isDefault && writeSettings) { if (realTheme && isDefault && writeSettings) {
// we're the default theme, let's save our state // we're the default theme, let's save our state
KConfigGroup &cg = config(); KConfigGroup &cg = config();

View File

@ -37,6 +37,8 @@
#include "libplasma-theme-global.h" #include "libplasma-theme-global.h"
class KDirWatch;
namespace Plasma namespace Plasma
{ {
@ -92,6 +94,10 @@ public Q_SLOTS:
void notifyOfChanged(); void notifyOfChanged();
void settingsChanged(); void settingsChanged();
void configDirty(const QString &path);
void configCreated(const QString &path);
void configDeleted(const QString &path);
Q_SIGNALS: Q_SIGNALS:
void themeChanged(); void themeChanged();
void defaultFontChanged(); void defaultFontChanged();
@ -133,6 +139,7 @@ public:
QHash<QString, QString> discoveries; QHash<QString, QString> discoveries;
QTimer *saveTimer; QTimer *saveTimer;
QTimer *updateNotificationTimer; QTimer *updateNotificationTimer;
KDirWatch *configWatcher;
unsigned cacheSize; unsigned cacheSize;
CacheTypes cachesToDiscard; CacheTypes cachesToDiscard;

View File

@ -125,6 +125,7 @@ void Theme::setThemeName(const QString &themeName)
if (d->themeName == themeName) { if (d->themeName == themeName) {
return; return;
} }
qDebug() << "Set themeName: " << d->themeName << " to " << themeName;
if (d != ThemePrivate::globalTheme) { if (d != ThemePrivate::globalTheme) {
disconnect(QCoreApplication::instance(), 0, d, 0); disconnect(QCoreApplication::instance(), 0, d, 0);
@ -144,7 +145,7 @@ void Theme::setThemeName(const QString &themeName)
connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
d, SLOT(onAppExitCleanup())); d, SLOT(onAppExitCleanup()));
} }
connect(d, &ThemePrivate::themeChanged, this, &Theme::themeChanged); // connect(d, &ThemePrivate::themeChanged, this, &Theme::themeChanged);
} }
d->setThemeName(themeName, true); d->setThemeName(themeName, true);

View File

@ -98,6 +98,12 @@ ShellCorona::ShellCorona(QObject *parent)
{ {
d->desktopDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(package().filePath("defaults")), "Desktop"); 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, connect(this, &ShellCorona::containmentAdded,
this, &ShellCorona::handleContainmentAdded); this, &ShellCorona::handleContainmentAdded);