Commit f1e986a4 authored by Ahmad Samir's avatar Ahmad Samir Committed by Tomaz Canabrava
Browse files

Add new config entry to control migrating old config keys

This way we don't run the same migration stuff at every start.

This also fixes an issue with the widget colorscheme config entry; if the
old WindowColorScheme key isn't found an empty string is used to write the
new UiSettings/ColorScheme key.

Inspired by similar code in KIO (SystemBookMarks related code) and Dolphin.
parent 37b9f9e3
Pipeline #188796 passed with stage
in 2 minutes and 39 seconds
......@@ -77,39 +77,47 @@ public:
}
};
// Used to control migrating config entries.
// Increment when there are new keys to migrate.
static int CurrentConfigVersion = 1;
static void migrateRenamedConfigKeys()
{
struct KeyInfo {
const char *groupName;
const char *oldKeyName;
const char *newKeyName;
};
static const KeyInfo keys[] = {{"KonsoleWindow", "SaveGeometryOnExit", "RememberWindowSize"}};
KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig(QStringLiteral("konsolerc"));
// Migrate renamed config keys
for (const auto &[group, oldName, newName] : keys) {
KConfigGroup cg = konsoleConfig->group(group);
if (cg.exists() && cg.hasKey(oldName)) {
const bool value = cg.readEntry(oldName, false);
cg.deleteEntry(oldName);
cg.writeEntry(newName, value);
KConfigGroup verGroup = konsoleConfig->group("General");
const int savedVersion = verGroup.readEntry<int>("ConfigVersion", 0);
if (savedVersion < CurrentConfigVersion) {
struct KeyInfo {
const char *groupName;
const char *oldKeyName;
const char *newKeyName;
};
static const KeyInfo keys[] = {{"KonsoleWindow", "SaveGeometryOnExit", "RememberWindowSize"}};
// Migrate renamed config keys
for (const auto &[group, oldName, newName] : keys) {
KConfigGroup cg = konsoleConfig->group(group);
if (cg.exists() && cg.hasKey(oldName)) {
const bool value = cg.readEntry(oldName, false);
cg.deleteEntry(oldName);
cg.writeEntry(newName, value);
}
}
}
// With 5.93 KColorSchemeManager from KConfigWidgets, handles the loading
// and saving of the widget color scheme, and uses "ColorScheme" as the
// entry name, so clean-up here
// With 5.93 KColorSchemeManager from KConfigWidgets, handles the loading
// and saving of the widget color scheme, and uses "ColorScheme" as the
// entry name, so clean-up here
#if KCONFIGWIDGETS_VERSION >= QT_VERSION_CHECK(5, 93, 0)
KConfigGroup cg(konsoleConfig, "UiSettings");
const QString schemeName = cg.readEntry("WindowColorScheme");
cg.deleteEntry("WindowColorScheme");
cg.writeEntry("ColorScheme", schemeName);
KConfigGroup cg(konsoleConfig, "UiSettings");
const QString schemeName = cg.readEntry("WindowColorScheme");
cg.deleteEntry("WindowColorScheme");
cg.writeEntry("ColorScheme", schemeName);
#endif
konsoleConfig->sync();
verGroup.writeEntry("ConfigVersion", CurrentConfigVersion);
konsoleConfig->sync();
}
}
// ***
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment