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),
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();

View File

@ -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<QString, QString> discoveries;
QTimer *saveTimer;
QTimer *updateNotificationTimer;
KDirWatch *configWatcher;
unsigned cacheSize;
CacheTypes cachesToDiscard;

View File

@ -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);

View File

@ -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);