LibGfx: Add list_installed_system_themes() to SystemTheme

This commit is contained in:
Ben Maxwell 2022-04-02 18:27:22 +01:00 committed by Andreas Kling
parent 3fbefb82ac
commit 8fa0409ae1
Notes: sideshowbarker 2024-07-17 16:18:27 +09:00
3 changed files with 27 additions and 18 deletions

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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();
{