From 09715da168390f491d40a330c8199034bc4c50d4 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Mon, 15 Sep 2025 16:23:20 -0400 Subject: [PATCH] envmanager: Use config overlay for applications-blacklistrc Use a config overlay for applications-blacklistrc, so that new options that we add are updated in installs. This brings it inline with all of the other config files we manage, and so I also remove unused functionality that we used in the past to "save" and restore config files. --- envmanager/config.h | 2 +- envmanager/settings.cpp | 38 +++++--------------------------------- envmanager/settings.h | 6 ------ 3 files changed, 6 insertions(+), 40 deletions(-) diff --git a/envmanager/config.h b/envmanager/config.h index 5529a4b8..273ffc4c 100644 --- a/envmanager/config.h +++ b/envmanager/config.h @@ -13,7 +13,7 @@ #include #include -// .config/applications-blacklistrc +// .config/plasma-mobile/applications-blacklistrc // NOTE: we only write these entries if they are not already defined in the config const QMap> APPLICATIONS_BLACKLIST_DEFAULT_SETTINGS = { {"Applications", diff --git a/envmanager/settings.cpp b/envmanager/settings.cpp index 1d98d614..7defc867 100644 --- a/envmanager/settings.cpp +++ b/envmanager/settings.cpp @@ -22,12 +22,12 @@ const QString SAVED_CONFIG_GROUP = u"SavedConfig"_s; const QString MOBILE_KWINRC_FILE = u"plasma-mobile/kwinrc"_s; const QString MOBILE_KSMSERVERRC_FILE = u"plasma-mobile/ksmserverrc"_s; const QString MOBILE_KDEGLOBALS_FILE = u"plasma-mobile/kdeglobals"_s; +const QString MOBILE_APPLICATIONS_BLACKLIST_FILE = u"plasma-mobile/applications-blacklistrc"_s; Settings::Settings(QObject *parent) : QObject{parent} , m_isMobilePlatform{KRuntimePlatform::runtimePlatform().contains(u"phone"_s)} , m_mobileConfig{KSharedConfig::openConfig(CONFIG_FILE, KConfig::SimpleConfig)} - , m_appBlacklistConfig{KSharedConfig::openConfig(u"applications-blacklistrc"_s, KConfig::SimpleConfig)} { } @@ -41,7 +41,6 @@ void Settings::applyConfiguration() { if (!m_isMobilePlatform) { qCDebug(LOGGING_CATEGORY) << "Configuration will not be applied, as the session is not Plasma Mobile."; - qCDebug(LOGGING_CATEGORY) << "Restoring any previously saved configuration..."; loadSavedConfiguration(); return; } @@ -58,10 +57,6 @@ void Settings::loadSavedConfiguration() originalKwinrcConfig->sync(); reloadKWinConfig(); - // applications-blacklistrc - loadKeys(u"applications-blacklistrc"_s, m_appBlacklistConfig, APPLICATIONS_BLACKLIST_DEFAULT_SETTINGS); - m_appBlacklistConfig->sync(); - // kdeglobals (legacy, we only write in the plasma-mobile/kdeglobals file now) auto originalKdeglobalsConfig = KSharedConfig::openConfig(u"kdeglobals"_s, KConfig::SimpleConfig); loadKeys(u"kdeglobals"_s, originalKdeglobalsConfig, KDEGLOBALS_SETTINGS); @@ -89,11 +84,10 @@ void Settings::applyMobileConfiguration() // applications-blacklistrc { - writeKeysAndSave(u"applications-blacklistrc"_s, - m_appBlacklistConfig, - APPLICATIONS_BLACKLIST_DEFAULT_SETTINGS, - true); // only write entries if they are not already defined in the config - m_appBlacklistConfig->sync(); + // We don't set these options as immutable + auto appBlacklistConfig = KSharedConfig::openConfig(MOBILE_APPLICATIONS_BLACKLIST_FILE, KConfig::SimpleConfig); + writeKeys(MOBILE_APPLICATIONS_BLACKLIST_FILE, appBlacklistConfig, APPLICATIONS_BLACKLIST_DEFAULT_SETTINGS); + appBlacklistConfig->sync(); } // kdeglobals @@ -136,28 +130,6 @@ void Settings::writeKeys(const QString &fileName, KSharedConfig::Ptr &config, co } } -void Settings::writeKeysAndSave(const QString &fileName, - KSharedConfig::Ptr &config, - const QMap> &settings, - bool overwriteOnlyIfEmpty) -{ - const auto groupNames = settings.keys(); - for (const auto &groupName : groupNames) { - auto group = KConfigGroup{config, groupName}; - - const auto keys = settings[groupName].keys(); - for (const auto &key : keys) { - if (!group.hasKey(key) || !overwriteOnlyIfEmpty) { - // save key - saveConfigSetting(fileName, groupName, key, group.readEntry(key)); - - // overwrite with mobile setting - group.writeEntry(key, settings[groupName][key], KConfigGroup::Notify); - } - } - } -} - void Settings::loadKeys(const QString &fileName, KSharedConfig::Ptr &config, const QMap> &settings) { const auto groupNames = settings.keys(); diff --git a/envmanager/settings.h b/envmanager/settings.h index 3ebb9fac..29cc8c67 100644 --- a/envmanager/settings.h +++ b/envmanager/settings.h @@ -30,8 +30,6 @@ private: void writeKeys(const QString &fileName, KSharedConfig::Ptr &config, const QMap> &settings); - void - writeKeysAndSave(const QString &fileName, KSharedConfig::Ptr &config, const QMap> &settings, bool overwriteOnlyIfEmpty); void loadKeys(const QString &fileName, KSharedConfig::Ptr &config, const QMap> &settings); void saveConfigSetting(const QString &fileName, const QString &group, const QString &key, const QVariant value); const QString loadSavedConfigSetting(KSharedConfig::Ptr &config, const QString &fileName, const QString &group, const QString &key, bool write = true); @@ -43,10 +41,6 @@ private: bool m_isMobilePlatform; KSharedConfig::Ptr m_mobileConfig; - KSharedConfig::Ptr m_kwinrcConfig; // (~/.config/plasma-mobile/kwinrc) - KSharedConfig::Ptr m_appBlacklistConfig; - KSharedConfig::Ptr m_kdeglobalsConfig; // (~/.config/plasma-mobile/kdeglobals) - KSharedConfig::Ptr m_ksmServerConfig; // (~/.config/plamsma-mobile/ksmserverrc) // For legacy upgrade purposes KSharedConfig::Ptr m_originalKdeglobalsConfig; // (~/.config/kdeglobals)