summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Maxwell <macdue@dueutil.tech>2022-04-02 18:27:22 +0100
committerAndreas Kling <kling@serenityos.org>2022-04-02 21:50:41 +0200
commit8fa0409ae145b0dcbe784679a43b70ec91de900e (patch)
tree86a6e7453f0b055914f9c2e5e74e84f56a1448bf
parent3fbefb82ac87d60a4122cc2fc871682f03f445de (diff)
downloadserenity-8fa0409ae145b0dcbe784679a43b70ec91de900e.zip
LibGfx: Add list_installed_system_themes() to SystemTheme
-rw-r--r--Userland/Libraries/LibGfx/SystemTheme.cpp16
-rw-r--r--Userland/Libraries/LibGfx/SystemTheme.h8
-rw-r--r--Userland/Services/Taskbar/main.cpp21
3 files changed, 27 insertions, 18 deletions
diff --git a/Userland/Libraries/LibGfx/SystemTheme.cpp b/Userland/Libraries/LibGfx/SystemTheme.cpp
index 815d0a62cc..5a018500a7 100644
--- a/Userland/Libraries/LibGfx/SystemTheme.cpp
+++ b/Userland/Libraries/LibGfx/SystemTheme.cpp
@@ -6,7 +6,10 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/LexicalPath.h>
+#include <AK/QuickSort.h>
#include <LibCore/ConfigFile.h>
+#include <LibCore/DirIterator.h>
#include <LibGfx/SystemTheme.h>
#include <string.h>
@@ -150,4 +153,17 @@ Core::AnonymousBuffer load_system_theme(String const& path)
return load_system_theme(Core::ConfigFile::open(path).release_value_but_fixme_should_propagate_errors());
}
+Vector<SystemThemeMetaData> list_installed_system_themes()
+{
+ Vector<SystemThemeMetaData> system_themes;
+ Core::DirIterator dt("/res/themes", Core::DirIterator::SkipDots);
+ while (dt.has_next()) {
+ auto theme_name = dt.next_path();
+ auto theme_path = String::formatted("/res/themes/{}", theme_name);
+ system_themes.append({ LexicalPath::title(theme_name), theme_path });
+ }
+ quick_sort(system_themes, [](auto& a, auto& b) { return a.name < b.name; });
+ return system_themes;
+}
+
}
diff --git a/Userland/Libraries/LibGfx/SystemTheme.h b/Userland/Libraries/LibGfx/SystemTheme.h
index bc712ca7eb..646b792382 100644
--- a/Userland/Libraries/LibGfx/SystemTheme.h
+++ b/Userland/Libraries/LibGfx/SystemTheme.h
@@ -11,6 +11,7 @@
#include <AK/Forward.h>
#include <AK/String.h>
#include <AK/Types.h>
+#include <AK/Vector.h>
#include <LibCore/AnonymousBuffer.h>
#include <LibCore/ConfigFile.h>
#include <LibGfx/Color.h>
@@ -272,6 +273,13 @@ void set_system_theme(Core::AnonymousBuffer);
Core::AnonymousBuffer load_system_theme(Core::ConfigFile const&);
Core::AnonymousBuffer load_system_theme(String const& path);
+struct SystemThemeMetaData {
+ String name;
+ String path;
+};
+
+Vector<SystemThemeMetaData> list_installed_system_themes();
+
}
using Gfx::ColorRole;
diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp
index 29b3eb5453..5d3f66376a 100644
--- a/Userland/Services/Taskbar/main.cpp
+++ b/Userland/Services/Taskbar/main.cpp
@@ -7,11 +7,9 @@
#include "ShutdownDialog.h"
#include "TaskbarWindow.h"
#include <AK/Debug.h>
-#include <AK/LexicalPath.h>
#include <AK/QuickSort.h>
#include <LibConfig/Client.h>
#include <LibCore/ConfigFile.h>
-#include <LibCore/DirIterator.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Process.h>
#include <LibCore/StandardPaths.h>
@@ -23,6 +21,7 @@
#include <LibGUI/ConnectionToWindowMangerServer.h>
#include <LibGUI/ConnectionToWindowServer.h>
#include <LibGUI/Menu.h>
+#include <LibGfx/SystemTheme.h>
#include <LibMain/Main.h>
#include <WindowServer/Window.h>
#include <serenity.h>
@@ -78,14 +77,9 @@ struct AppMetadata {
};
Vector<AppMetadata> g_apps;
-struct ThemeMetadata {
- String name;
- String path;
-};
-
Color g_menu_selection_color;
-Vector<ThemeMetadata> g_themes;
+Vector<Gfx::SystemThemeMetaData> g_themes;
RefPtr<GUI::Menu> g_themes_menu;
GUI::ActionGroup g_themes_group;
@@ -214,16 +208,7 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu()
g_themes_menu = &system_menu->add_submenu("&Themes");
g_themes_menu->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/themes.png").release_value_but_fixme_should_propagate_errors());
- {
- Core::DirIterator dt("/res/themes", Core::DirIterator::SkipDots);
- while (dt.has_next()) {
- auto theme_name = dt.next_path();
- auto theme_path = String::formatted("/res/themes/{}", theme_name);
- g_themes.append({ LexicalPath::title(theme_name), theme_path });
- }
- quick_sort(g_themes, [](auto& a, auto& b) { return a.name < b.name; });
- }
-
+ g_themes = Gfx::list_installed_system_themes();
auto current_theme_name = GUI::ConnectionToWindowServer::the().get_system_theme();
{