mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:37:34 +00:00
LibGfx: Add list_installed_system_themes() to SystemTheme
This commit is contained in:
parent
3fbefb82ac
commit
8fa0409ae1
3 changed files with 27 additions and 18 deletions
|
@ -6,7 +6,10 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/LexicalPath.h>
|
||||||
|
#include <AK/QuickSort.h>
|
||||||
#include <LibCore/ConfigFile.h>
|
#include <LibCore/ConfigFile.h>
|
||||||
|
#include <LibCore/DirIterator.h>
|
||||||
#include <LibGfx/SystemTheme.h>
|
#include <LibGfx/SystemTheme.h>
|
||||||
#include <string.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());
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
#include <AK/Vector.h>
|
||||||
#include <LibCore/AnonymousBuffer.h>
|
#include <LibCore/AnonymousBuffer.h>
|
||||||
#include <LibCore/ConfigFile.h>
|
#include <LibCore/ConfigFile.h>
|
||||||
#include <LibGfx/Color.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(Core::ConfigFile const&);
|
||||||
Core::AnonymousBuffer load_system_theme(String const& path);
|
Core::AnonymousBuffer load_system_theme(String const& path);
|
||||||
|
|
||||||
|
struct SystemThemeMetaData {
|
||||||
|
String name;
|
||||||
|
String path;
|
||||||
|
};
|
||||||
|
|
||||||
|
Vector<SystemThemeMetaData> list_installed_system_themes();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using Gfx::ColorRole;
|
using Gfx::ColorRole;
|
||||||
|
|
|
@ -7,11 +7,9 @@
|
||||||
#include "ShutdownDialog.h"
|
#include "ShutdownDialog.h"
|
||||||
#include "TaskbarWindow.h"
|
#include "TaskbarWindow.h"
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <AK/LexicalPath.h>
|
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <LibConfig/Client.h>
|
#include <LibConfig/Client.h>
|
||||||
#include <LibCore/ConfigFile.h>
|
#include <LibCore/ConfigFile.h>
|
||||||
#include <LibCore/DirIterator.h>
|
|
||||||
#include <LibCore/EventLoop.h>
|
#include <LibCore/EventLoop.h>
|
||||||
#include <LibCore/Process.h>
|
#include <LibCore/Process.h>
|
||||||
#include <LibCore/StandardPaths.h>
|
#include <LibCore/StandardPaths.h>
|
||||||
|
@ -23,6 +21,7 @@
|
||||||
#include <LibGUI/ConnectionToWindowMangerServer.h>
|
#include <LibGUI/ConnectionToWindowMangerServer.h>
|
||||||
#include <LibGUI/ConnectionToWindowServer.h>
|
#include <LibGUI/ConnectionToWindowServer.h>
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
|
#include <LibGfx/SystemTheme.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <WindowServer/Window.h>
|
#include <WindowServer/Window.h>
|
||||||
#include <serenity.h>
|
#include <serenity.h>
|
||||||
|
@ -78,14 +77,9 @@ struct AppMetadata {
|
||||||
};
|
};
|
||||||
Vector<AppMetadata> g_apps;
|
Vector<AppMetadata> g_apps;
|
||||||
|
|
||||||
struct ThemeMetadata {
|
|
||||||
String name;
|
|
||||||
String path;
|
|
||||||
};
|
|
||||||
|
|
||||||
Color g_menu_selection_color;
|
Color g_menu_selection_color;
|
||||||
|
|
||||||
Vector<ThemeMetadata> g_themes;
|
Vector<Gfx::SystemThemeMetaData> g_themes;
|
||||||
RefPtr<GUI::Menu> g_themes_menu;
|
RefPtr<GUI::Menu> g_themes_menu;
|
||||||
GUI::ActionGroup g_themes_group;
|
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 = &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());
|
g_themes_menu->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/themes.png").release_value_but_fixme_should_propagate_errors());
|
||||||
|
|
||||||
{
|
g_themes = Gfx::list_installed_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);
|
|
||||||
g_themes.append({ LexicalPath::title(theme_name), theme_path });
|
|
||||||
}
|
|
||||||
quick_sort(g_themes, [](auto& a, auto& b) { return a.name < b.name; });
|
|
||||||
}
|
|
||||||
|
|
||||||
auto current_theme_name = GUI::ConnectionToWindowServer::the().get_system_theme();
|
auto current_theme_name = GUI::ConnectionToWindowServer::the().get_system_theme();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue