mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 15:47:35 +00:00
LibGfx+Userland: Make Gfx::SystemTheme propagate errors
This patch introduces error propagation to Gfx::SystemTheme to remove instances of release_value_but_fixme_should_propagate_errors(). Userland applications that have been affected by this change have been updated to utilise this propagation and as a result 4 such instances of the aforementioned method have been removed.
This commit is contained in:
parent
bdd9bc16de
commit
806a55eda1
15 changed files with 64 additions and 39 deletions
|
@ -85,16 +85,16 @@ void AbstractThemePreview::set_theme(Core::AnonymousBuffer const& theme_buffer)
|
|||
set_preview_palette(m_preview_palette);
|
||||
}
|
||||
|
||||
void AbstractThemePreview::set_theme_from_file(Core::File& file)
|
||||
ErrorOr<void> AbstractThemePreview::set_theme_from_file(Core::File& file)
|
||||
{
|
||||
auto config_file = Core::ConfigFile::open(file.filename(), file.leak_fd()).release_value_but_fixme_should_propagate_errors();
|
||||
auto theme = Gfx::load_system_theme(config_file);
|
||||
VERIFY(theme.is_valid());
|
||||
auto config_file = TRY(Core::ConfigFile::open(file.filename(), file.leak_fd()));
|
||||
auto theme = TRY(Gfx::load_system_theme(config_file));
|
||||
|
||||
m_preview_palette = Gfx::Palette(Gfx::PaletteImpl::create_with_anonymous_buffer(theme));
|
||||
set_preview_palette(m_preview_palette);
|
||||
if (on_theme_load_from_file)
|
||||
on_theme_load_from_file(file.filename());
|
||||
return {};
|
||||
}
|
||||
|
||||
void AbstractThemePreview::paint_window(StringView title, Gfx::IntRect const& rect, Gfx::WindowTheme::WindowState state, Gfx::Bitmap const& icon, int button_count)
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
|
||||
Gfx::Palette const& preview_palette() const { return m_preview_palette; }
|
||||
void set_preview_palette(Gfx::Palette const&);
|
||||
void set_theme_from_file(Core::File&);
|
||||
ErrorOr<void> set_theme_from_file(Core::File&);
|
||||
void set_theme(Core::AnonymousBuffer const&);
|
||||
|
||||
void paint_window(StringView title, Gfx::IntRect const& rect, Gfx::WindowTheme::WindowState, Gfx::Bitmap const& icon, int button_count = 3);
|
||||
|
|
|
@ -31,9 +31,9 @@ void set_system_theme(Core::AnonymousBuffer buffer)
|
|||
theme_page = theme_buffer.data<SystemTheme>();
|
||||
}
|
||||
|
||||
Core::AnonymousBuffer load_system_theme(Core::ConfigFile const& file)
|
||||
ErrorOr<Core::AnonymousBuffer> load_system_theme(Core::ConfigFile const& file)
|
||||
{
|
||||
auto buffer = Core::AnonymousBuffer::create_with_size(sizeof(SystemTheme)).release_value();
|
||||
auto buffer = TRY(Core::AnonymousBuffer::create_with_size(sizeof(SystemTheme)));
|
||||
|
||||
auto* data = buffer.data<SystemTheme>();
|
||||
|
||||
|
@ -148,19 +148,20 @@ Core::AnonymousBuffer load_system_theme(Core::ConfigFile const& file)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
Core::AnonymousBuffer load_system_theme(DeprecatedString const& path)
|
||||
ErrorOr<Core::AnonymousBuffer> load_system_theme(DeprecatedString const& path)
|
||||
{
|
||||
return load_system_theme(Core::ConfigFile::open(path).release_value_but_fixme_should_propagate_errors());
|
||||
auto config_file = TRY(Core::ConfigFile::open(path));
|
||||
return TRY(load_system_theme(config_file));
|
||||
}
|
||||
|
||||
Vector<SystemThemeMetaData> list_installed_system_themes()
|
||||
ErrorOr<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 = DeprecatedString::formatted("/res/themes/{}", theme_name);
|
||||
system_themes.append({ LexicalPath::title(theme_name), theme_path });
|
||||
TRY(system_themes.try_append({ LexicalPath::title(theme_name), theme_path }));
|
||||
}
|
||||
quick_sort(system_themes, [](auto& a, auto& b) { return a.name < b.name; });
|
||||
return system_themes;
|
||||
|
|
|
@ -271,15 +271,15 @@ struct SystemTheme {
|
|||
|
||||
Core::AnonymousBuffer& current_system_theme_buffer();
|
||||
void set_system_theme(Core::AnonymousBuffer);
|
||||
Core::AnonymousBuffer load_system_theme(Core::ConfigFile const&);
|
||||
Core::AnonymousBuffer load_system_theme(DeprecatedString const& path);
|
||||
ErrorOr<Core::AnonymousBuffer> load_system_theme(Core::ConfigFile const&);
|
||||
ErrorOr<Core::AnonymousBuffer> load_system_theme(DeprecatedString const& path);
|
||||
|
||||
struct SystemThemeMetaData {
|
||||
DeprecatedString name;
|
||||
DeprecatedString path;
|
||||
};
|
||||
|
||||
Vector<SystemThemeMetaData> list_installed_system_themes();
|
||||
ErrorOr<Vector<SystemThemeMetaData>> list_installed_system_themes();
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue