diff --git a/kcms/lookandfeel/lookandfeelmanager.cpp b/kcms/lookandfeel/lookandfeelmanager.cpp index 8932dcf16..901f0a14c 100644 --- a/kcms/lookandfeel/lookandfeelmanager.cpp +++ b/kcms/lookandfeel/lookandfeelmanager.cpp @@ -222,6 +222,35 @@ KConfig LookAndFeelManager::configDefaults(const QString &filename) return KConfig(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1String("/kdedefaults/") + filename, KConfig::SimpleConfig); } +QString LookAndFeelManager::colorSchemeFile(const QString &schemeName) +{ + QString colorScheme(schemeName); + colorScheme.remove(QLatin1Char('\'')); // So Foo's does not become FooS + QRegExp fixer(QStringLiteral("[\\W,.-]+(.?)")); + int offset; + while ((offset = fixer.indexIn(colorScheme)) >= 0) { + colorScheme.replace(offset, fixer.matchedLength(), fixer.cap(1).toUpper()); + } + colorScheme.replace(0, 1, colorScheme.at(0).toUpper()); + + // NOTE: why this loop trough all the scheme files? + // the scheme theme name is an heuristic, there is no plugin metadata whatsoever. + // is based on the file name stripped from weird characters or the + // eventual id- prefix store.kde.org puts, so we can just find a + // theme that ends as the specified name + const QStringList schemeDirs = + QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("color-schemes"), QStandardPaths::LocateDirectory); + for (const QString &dir : schemeDirs) { + const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.colors")); + for (const QString &file : fileNames) { + if (file.endsWith(colorScheme + QStringLiteral(".colors"))) { + return dir + QLatin1Char('/') + file; + } + } + } + return QString(); +} + void LookAndFeelManager::save(const KPackage::Package &package, const KPackage::Package &previousPackage) { if (m_resetDefaultLayout && m_mode == Mode::Apply) { @@ -264,34 +293,9 @@ void LookAndFeelManager::save(const KPackage::Package &package, const KPackage:: setColors(package.metadata().name(), colorsFile); } } else if (!colorScheme.isEmpty()) { - colorScheme.remove(QLatin1Char('\'')); // So Foo's does not become FooS - QRegExp fixer(QStringLiteral("[\\W,.-]+(.?)")); - int offset; - while ((offset = fixer.indexIn(colorScheme)) >= 0) { - colorScheme.replace(offset, fixer.matchedLength(), fixer.cap(1).toUpper()); - } - colorScheme.replace(0, 1, colorScheme.at(0).toUpper()); - - // NOTE: why this loop trough all the scheme files? - // the scheme theme name is an heuristic, there is no plugin metadata whatsoever. - // is based on the file name stripped from weird characters or the - // eventual id- prefix store.kde.org puts, so we can just find a - // theme that ends as the specified name - bool schemeFound = false; - const QStringList schemeDirs = - QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("color-schemes"), QStandardPaths::LocateDirectory); - for (const QString &dir : schemeDirs) { - const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.colors")); - for (const QString &file : fileNames) { - if (file.endsWith(colorScheme + QStringLiteral(".colors"))) { - setColors(colorScheme, dir + QLatin1Char('/') + file); - schemeFound = true; - break; - } - } - if (schemeFound) { - break; - } + QString path = colorSchemeFile(colorScheme); + if (!path.isEmpty()) { + setColors(colorScheme, path); } } } diff --git a/kcms/lookandfeel/lookandfeelmanager.h b/kcms/lookandfeel/lookandfeelmanager.h index 1ff10155c..bc5f7219f 100644 --- a/kcms/lookandfeel/lookandfeelmanager.h +++ b/kcms/lookandfeel/lookandfeelmanager.h @@ -38,6 +38,8 @@ public: */ void save(const KPackage::Package &package, const KPackage::Package &oldPackage); + QString colorSchemeFile(const QString &schemeName); + bool resetDefaultLayout() const; void setResetDefaultLayout(bool reset); diff --git a/startkde/startplasma.cpp b/startkde/startplasma.cpp index 6994ba712..5521869f7 100644 --- a/startkde/startplasma.cpp +++ b/startkde/startplasma.cpp @@ -372,6 +372,24 @@ void setupPlasmaEnvironment() LookAndFeelManager lnfManager; lnfManager.setMode(LookAndFeelManager::Mode::Defaults); lnfManager.save(package, KPackage::Package()); + const QString colorScheme = KConfigGroup(&globals, QStringLiteral("General")).readEntry("ColorScheme", QStringLiteral("BreezeLight")); + } + // If no colors are saved, take them from the LNF and apply + if (!globals.hasGroup("Colors:Window") || !globals.hasGroup("Colors:View") || + !globals.hasGroup("Colors:Button") || !globals.hasGroup("Colors:Tooltip") || + !globals.hasGroup("Colors:Selection")) { + LookAndFeelManager lnfManager; + lnfManager.setMode(LookAndFeelManager::Mode::Apply); + const KConfig globals; // Reload the config + const QString colorScheme = KConfigGroup(&globals, QStringLiteral("General")).readEntry("ColorScheme", QStringLiteral("BreezeLight")); + QString path = lnfManager.colorSchemeFile(colorScheme); + if (!path.isEmpty()) { + lnfManager.setColors(colorScheme, path); + } + const QString svgCache = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1Char('/') + QStringLiteral("plasma-svgelements"); + if (!svgCache.isEmpty()) { + QFile::remove(svgCache); + } } }