From 8fa0409ae145b0dcbe784679a43b70ec91de900e Mon Sep 17 00:00:00 2001 From: Ben Maxwell Date: Sat, 2 Apr 2022 18:27:22 +0100 Subject: [PATCH] LibGfx: Add list_installed_system_themes() to SystemTheme --- Userland/Libraries/LibGfx/SystemTheme.cpp | 16 ++++++++++++++++ Userland/Libraries/LibGfx/SystemTheme.h | 8 ++++++++ Userland/Services/Taskbar/main.cpp | 21 +++------------------ 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 +#include #include +#include #include #include @@ -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 list_installed_system_themes() +{ + Vector 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 #include #include +#include #include #include #include @@ -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 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 -#include #include #include #include -#include #include #include #include @@ -23,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -78,14 +77,9 @@ struct AppMetadata { }; Vector g_apps; -struct ThemeMetadata { - String name; - String path; -}; - Color g_menu_selection_color; -Vector g_themes; +Vector g_themes; RefPtr g_themes_menu; GUI::ActionGroup g_themes_group; @@ -214,16 +208,7 @@ ErrorOr> 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(); {