summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorKarol Kosek <krkk@krkk.ct8.pl>2021-08-25 22:22:07 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-12 11:49:52 +0200
commitf878e4464fba0d4e4ba4c9677316a62479866e21 (patch)
treeceb10da189ba87d365a87aaea25445383bf62d46 /Userland/Libraries
parent09314ad611786086679164658afa44c264c57dcf (diff)
downloadserenity-f878e4464fba0d4e4ba4c9677316a62479866e21.zip
LibGfx: Add SystemTheme::load_system_theme(Core::ConfigFile const&)
This makes loading system themes possible via FileSystemAccessClient (needed for the Theme Editor). :^)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGfx/SystemTheme.cpp14
-rw-r--r--Userland/Libraries/LibGfx/SystemTheme.h4
2 files changed, 12 insertions, 6 deletions
diff --git a/Userland/Libraries/LibGfx/SystemTheme.cpp b/Userland/Libraries/LibGfx/SystemTheme.cpp
index 268a2848e3..5bfac555e7 100644
--- a/Userland/Libraries/LibGfx/SystemTheme.cpp
+++ b/Userland/Libraries/LibGfx/SystemTheme.cpp
@@ -26,15 +26,14 @@ void set_system_theme(Core::AnonymousBuffer buffer)
theme_page = theme_buffer.data<SystemTheme>();
}
-Core::AnonymousBuffer load_system_theme(const String& path)
+Core::AnonymousBuffer load_system_theme(Core::ConfigFile const& file)
{
- auto file = Core::ConfigFile::open(path);
auto buffer = Core::AnonymousBuffer::create_with_size(sizeof(SystemTheme));
auto* data = buffer.data<SystemTheme>();
auto get_color = [&](auto& name) {
- auto color_string = file->read_entry("Colors", name);
+ auto color_string = file.read_entry("Colors", name);
auto color = Color::from_string(color_string);
if (!color.has_value())
return Color(Color::Black);
@@ -42,7 +41,7 @@ Core::AnonymousBuffer load_system_theme(const String& path)
};
auto get_metric = [&](auto& name, auto role) {
- int metric = file->read_num_entry("Metrics", name, -1);
+ int metric = file.read_num_entry("Metrics", name, -1);
if (metric == -1) {
switch (role) {
case (int)MetricRole::TitleHeight:
@@ -60,7 +59,7 @@ Core::AnonymousBuffer load_system_theme(const String& path)
};
auto get_path = [&](auto& name, auto role, bool allow_empty) {
- auto path = file->read_entry("Paths", name);
+ auto path = file.read_entry("Paths", name);
if (path.is_empty()) {
switch (role) {
case (int)PathRole::TitleButtonIcons:
@@ -102,4 +101,9 @@ Core::AnonymousBuffer load_system_theme(const String& path)
return buffer;
}
+Core::AnonymousBuffer load_system_theme(String const& path)
+{
+ return load_system_theme(Core::ConfigFile::open(path));
+}
+
}
diff --git a/Userland/Libraries/LibGfx/SystemTheme.h b/Userland/Libraries/LibGfx/SystemTheme.h
index 062722e90a..58dd20f775 100644
--- a/Userland/Libraries/LibGfx/SystemTheme.h
+++ b/Userland/Libraries/LibGfx/SystemTheme.h
@@ -10,6 +10,7 @@
#include <AK/String.h>
#include <AK/Types.h>
#include <LibCore/AnonymousBuffer.h>
+#include <LibCore/ConfigFile.h>
#include <LibGfx/Color.h>
namespace Gfx {
@@ -145,7 +146,8 @@ struct SystemTheme {
Core::AnonymousBuffer& current_system_theme_buffer();
void set_system_theme(Core::AnonymousBuffer);
-Core::AnonymousBuffer load_system_theme(const String& path);
+Core::AnonymousBuffer load_system_theme(Core::ConfigFile const&);
+Core::AnonymousBuffer load_system_theme(String const& path);
}