ソースを参照

LibGfx: Add list_installed_system_themes() to SystemTheme

Ben Maxwell 3 年 前
コミット
8fa0409ae1

+ 16 - 0
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;
+}
+
 }

+ 8 - 0
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;

+ 3 - 18
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();
 
     {