From 7f501d4d8a3cb35a24fd5412bc096a12385b4713 Mon Sep 17 00:00:00 2001 From: david072 Date: Sun, 5 Nov 2023 12:49:52 +0100 Subject: [PATCH] Taskbar/QuickLaunchWidget: Ensure config backwards compatibility The QuickLaunchWidget can now also parse the old config format, so that we stay compatible with the old format. After loading, it deletes the old config values and saves them in the new format. --- Userland/Services/Taskbar/QuickLaunchWidget.cpp | 15 +++++++++++++++ Userland/Services/Taskbar/QuickLaunchWidget.h | 1 + 2 files changed, 16 insertions(+) diff --git a/Userland/Services/Taskbar/QuickLaunchWidget.cpp b/Userland/Services/Taskbar/QuickLaunchWidget.cpp index 30d35b4023..c5400296e2 100644 --- a/Userland/Services/Taskbar/QuickLaunchWidget.cpp +++ b/Userland/Services/Taskbar/QuickLaunchWidget.cpp @@ -355,6 +355,21 @@ void QuickLaunchWidget::load_entries(bool save) entries.append(entry.release_nonnull()); } + // backwards compatibility since the group and value-format changed + auto old_keys = Config::list_keys(CONFIG_DOMAIN, OLD_CONFIG_GROUP_ENTRIES); + if (!old_keys.is_empty()) { + for (auto& name : old_keys) { + auto path = Config::read_string(CONFIG_DOMAIN, OLD_CONFIG_GROUP_ENTRIES, name); + auto entry = QuickLaunchEntry::create_from_path(path); + if (!entry) + continue; + + entries.append(entry.release_nonnull()); + } + + Config::remove_group(CONFIG_DOMAIN, OLD_CONFIG_GROUP_ENTRIES); + } + m_entries.clear(); add_entries(move(entries), save); } diff --git a/Userland/Services/Taskbar/QuickLaunchWidget.h b/Userland/Services/Taskbar/QuickLaunchWidget.h index 6eda66c2dd..b05e86bd92 100644 --- a/Userland/Services/Taskbar/QuickLaunchWidget.h +++ b/Userland/Services/Taskbar/QuickLaunchWidget.h @@ -123,6 +123,7 @@ protected: private: static constexpr StringView CONFIG_DOMAIN = "Taskbar"sv; static constexpr StringView CONFIG_GROUP_ENTRIES = "QuickLaunch_Entries"sv; + static constexpr StringView OLD_CONFIG_GROUP_ENTRIES = "QuickLaunch"sv; static constexpr int BUTTON_SIZE = 24; explicit QuickLaunchWidget();