envmanager: Ensure that lnf is not constantly reapplied, overwriting user settings

This commit is contained in:
Devin Lin 2023-12-08 19:09:26 -08:00
parent cd055e8eca
commit 7056649bf4
2 changed files with 13 additions and 23 deletions

View file

@ -25,6 +25,8 @@ const QMap<QString, QMap<QString, QVariant>> APPLICATIONS_BLACKLIST_DEFAULT_SETT
// NOTE: we only write these entries if they are not already defined in the config // NOTE: we only write these entries if they are not already defined in the config
const QMap<QString, QMap<QString, QVariant>> KDEGLOBALS_DEFAULT_SETTINGS = {{"General", {{"BrowserApplication", "angelfish"}}}}; const QMap<QString, QMap<QString, QVariant>> KDEGLOBALS_DEFAULT_SETTINGS = {{"General", {{"BrowserApplication", "angelfish"}}}};
const QMap<QString, QMap<QString, QVariant>> KDEGLOBALS_SETTINGS = {{"KDE", {{"LookAndFeelPackage", "org.kde.breeze.mobile"}}}};
// kwinrc // kwinrc
QMap<QString, QMap<QString, QVariant>> getKwinrcSettings(KSharedConfig::Ptr m_mobileConfig) QMap<QString, QMap<QString, QVariant>> getKwinrcSettings(KSharedConfig::Ptr m_mobileConfig)
{ {

View file

@ -16,9 +16,6 @@
const QString CONFIG_FILE = QStringLiteral("plasmamobilerc"); const QString CONFIG_FILE = QStringLiteral("plasmamobilerc");
const QString SAVED_CONFIG_GROUP = QStringLiteral("SavedConfig"); const QString SAVED_CONFIG_GROUP = QStringLiteral("SavedConfig");
const QString MOBILE_LOOK_AND_FEEL = QStringLiteral("org.kde.breeze.mobile");
const QString LOOK_AND_FEEL_KEY = QStringLiteral("LookAndFeelPackage");
Settings::Settings(QObject *parent) Settings::Settings(QObject *parent)
: QObject{parent} : QObject{parent}
, m_isMobilePlatform{KRuntimePlatform::runtimePlatform().contains(QStringLiteral("phone"))} , m_isMobilePlatform{KRuntimePlatform::runtimePlatform().contains(QStringLiteral("phone"))}
@ -51,10 +48,6 @@ void Settings::applyConfiguration()
void Settings::loadSavedConfiguration() void Settings::loadSavedConfiguration()
{ {
// check look and feel
QString lnf = loadSavedConfigSetting(m_kdeglobalsConfig, QStringLiteral("kdeglobals"), QStringLiteral("KDE"), LOOK_AND_FEEL_KEY, false);
QProcess::execute("plasma-apply-lookandfeel", {"-a", lnf});
// kwinrc // kwinrc
loadKeys(QStringLiteral("kwinrc"), m_kwinrcConfig, getKwinrcSettings(m_mobileConfig)); loadKeys(QStringLiteral("kwinrc"), m_kwinrcConfig, getKwinrcSettings(m_mobileConfig));
m_kwinrcConfig->sync(); m_kwinrcConfig->sync();
@ -66,6 +59,7 @@ void Settings::loadSavedConfiguration()
// kdeglobals // kdeglobals
loadKeys(QStringLiteral("kdeglobals"), m_kdeglobalsConfig, KDEGLOBALS_DEFAULT_SETTINGS); loadKeys(QStringLiteral("kdeglobals"), m_kdeglobalsConfig, KDEGLOBALS_DEFAULT_SETTINGS);
loadKeys(QStringLiteral("kdeglobals"), m_kdeglobalsConfig, KDEGLOBALS_SETTINGS);
m_kdeglobalsConfig->sync(); m_kdeglobalsConfig->sync();
// save our changes // save our changes
@ -74,30 +68,24 @@ void Settings::loadSavedConfiguration()
void Settings::applyMobileConfiguration() void Settings::applyMobileConfiguration()
{ {
// check look and feel
KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
if (package.path() != MOBILE_LOOK_AND_FEEL) {
// save it to be loaded when back on desktop
saveConfigSetting(QStringLiteral("kdeglobals"), QStringLiteral("KDE"), LOOK_AND_FEEL_KEY, package.path());
// ensure correct look and feel is applied
QProcess::execute("plasma-apply-lookandfeel", {"-a", MOBILE_LOOK_AND_FEEL});
}
// kwinrc // kwinrc
writeKeys(QStringLiteral("kwinrc"), m_kwinrcConfig, getKwinrcSettings(m_mobileConfig), false); writeKeys(QStringLiteral("kwinrc"), m_kwinrcConfig, getKwinrcSettings(m_mobileConfig), false);
m_kwinrcConfig->sync(); m_kwinrcConfig->sync();
reloadKWinConfig(); reloadKWinConfig();
// applications-blacklistrc // applications-blacklistrc
// NOTE: we only write entries if they are not already defined in the config writeKeys(QStringLiteral("applications-blacklistrc"),
writeKeys(QStringLiteral("applications-blacklistrc"), m_appBlacklistConfig, APPLICATIONS_BLACKLIST_DEFAULT_SETTINGS, true); m_appBlacklistConfig,
APPLICATIONS_BLACKLIST_DEFAULT_SETTINGS,
true); // only write entries if they are not already defined in the config
m_appBlacklistConfig->sync(); m_appBlacklistConfig->sync();
// kdeglobals // kdeglobals
// NOTE: we only write entries if they are not already defined in the config writeKeys(QStringLiteral("kdeglobals"),
writeKeys(QStringLiteral("kdeglobals"), m_kdeglobalsConfig, KDEGLOBALS_DEFAULT_SETTINGS, true); m_kdeglobalsConfig,
KDEGLOBALS_DEFAULT_SETTINGS,
true); // only write entries if they are not already defined in the config
writeKeys(QStringLiteral("kdeglobals"), m_kdeglobalsConfig, KDEGLOBALS_SETTINGS, false);
m_kdeglobalsConfig->sync(); m_kdeglobalsConfig->sync();
// save our changes // save our changes
@ -140,7 +128,7 @@ void Settings::saveConfigSetting(const QString &fileName, const QString &group,
auto keyGroup = KConfigGroup{&fileGroup, group}; auto keyGroup = KConfigGroup{&fileGroup, group};
if (!keyGroup.hasKey(key)) { if (!keyGroup.hasKey(key)) {
qCDebug(LOGGING_CATEGORY) << "In" << fileName << "saved" << key << "to" << value; qCDebug(LOGGING_CATEGORY) << "In" << fileName << "saved" << key << "=" << value;
keyGroup.writeEntry(key, value); keyGroup.writeEntry(key, value);
} }
} }