diff options
-rw-r--r-- | Userland/Applications/DisplaySettings/ThemePreviewWidget.cpp | 6 | ||||
-rw-r--r-- | Userland/Applications/DisplaySettings/ThemePreviewWidget.h | 2 | ||||
-rw-r--r-- | Userland/Applications/DisplaySettings/ThemesSettingsWidget.cpp | 13 | ||||
-rw-r--r-- | Userland/Applications/ThemeEditor/MainWidget.cpp | 13 | ||||
-rw-r--r-- | Userland/Applications/ThemeEditor/MainWidget.h | 2 | ||||
-rw-r--r-- | Userland/Applications/ThemeEditor/PreviewWidget.cpp | 5 | ||||
-rw-r--r-- | Userland/Applications/ThemeEditor/main.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/AbstractThemePreview.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/AbstractThemePreview.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/SystemTheme.cpp | 13 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/SystemTheme.h | 6 | ||||
-rw-r--r-- | Userland/Services/Taskbar/main.cpp | 2 | ||||
-rw-r--r-- | Userland/Services/WindowServer/WindowManager.cpp | 10 | ||||
-rw-r--r-- | Userland/Services/WindowServer/main.cpp | 3 | ||||
-rw-r--r-- | Userland/Utilities/headless-browser.cpp | 11 |
15 files changed, 64 insertions, 39 deletions
diff --git a/Userland/Applications/DisplaySettings/ThemePreviewWidget.cpp b/Userland/Applications/DisplaySettings/ThemePreviewWidget.cpp index 8635ba5de4..9f299729c9 100644 --- a/Userland/Applications/DisplaySettings/ThemePreviewWidget.cpp +++ b/Userland/Applications/DisplaySettings/ThemePreviewWidget.cpp @@ -19,9 +19,11 @@ ThemePreviewWidget::ThemePreviewWidget(Gfx::Palette const& palette) set_fixed_size(304, 201); } -void ThemePreviewWidget::set_theme(DeprecatedString path) +ErrorOr<void> ThemePreviewWidget::set_theme(DeprecatedString path) { - set_theme_from_file(*Core::File::open(path, Core::OpenMode::ReadOnly).release_value_but_fixme_should_propagate_errors()); + auto config_file = TRY(Core::File::open(path, Core::OpenMode::ReadOnly)); + TRY(set_theme_from_file(config_file)); + return {}; } void ThemePreviewWidget::paint_preview(GUI::PaintEvent&) diff --git a/Userland/Applications/DisplaySettings/ThemePreviewWidget.h b/Userland/Applications/DisplaySettings/ThemePreviewWidget.h index f4abd130bf..8c5207a31e 100644 --- a/Userland/Applications/DisplaySettings/ThemePreviewWidget.h +++ b/Userland/Applications/DisplaySettings/ThemePreviewWidget.h @@ -18,7 +18,7 @@ class ThemePreviewWidget final : public GUI::AbstractThemePreview { C_OBJECT(ThemePreviewWidget); public: - void set_theme(DeprecatedString path); + ErrorOr<void> set_theme(DeprecatedString path); private: explicit ThemePreviewWidget(Gfx::Palette const& palette); diff --git a/Userland/Applications/DisplaySettings/ThemesSettingsWidget.cpp b/Userland/Applications/DisplaySettings/ThemesSettingsWidget.cpp index 5f53b7d16c..20fb6f2df1 100644 --- a/Userland/Applications/DisplaySettings/ThemesSettingsWidget.cpp +++ b/Userland/Applications/DisplaySettings/ThemesSettingsWidget.cpp @@ -13,6 +13,7 @@ #include <LibGUI/Application.h> #include <LibGUI/ConnectionToWindowServer.h> #include <LibGUI/ItemListModel.h> +#include <LibGUI/MessageBox.h> #include <LibGUI/Process.h> namespace DisplaySettings { @@ -21,7 +22,7 @@ ThemesSettingsWidget::ThemesSettingsWidget(bool& background_settings_changed) : m_background_settings_changed { background_settings_changed } { load_from_gml(themes_settings_gml); - m_themes = Gfx::list_installed_system_themes(); + m_themes = MUST(Gfx::list_installed_system_themes()); size_t current_theme_index; auto current_theme_name = GUI::ConnectionToWindowServer::the().get_system_theme(); @@ -39,7 +40,10 @@ ThemesSettingsWidget::ThemesSettingsWidget(bool& background_settings_changed) m_themes_combo->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_theme_names)); m_themes_combo->on_change = [this](auto&, const GUI::ModelIndex& index) { m_selected_theme = &m_themes.at(index.row()); - m_theme_preview->set_theme(m_selected_theme->path); + auto set_theme_result = m_theme_preview->set_theme(m_selected_theme->path); + if (set_theme_result.is_error()) { + GUI::MessageBox::show_error(window(), DeprecatedString::formatted("There was an error generating the theme preview: {}", set_theme_result.error())); + } set_modified(true); }; m_themes_combo->set_selected_index(current_theme_index, GUI::AllowCallback::No); @@ -66,7 +70,10 @@ ThemesSettingsWidget::ThemesSettingsWidget(bool& background_settings_changed) if (current_theme_name == theme_meta.name) { m_themes_combo->set_selected_index(index, GUI::AllowCallback::No); m_selected_theme = &m_themes.at(index); - m_theme_preview->set_theme(m_selected_theme->path); + auto set_theme_result = m_theme_preview->set_theme(m_selected_theme->path); + if (set_theme_result.is_error()) { + GUI::MessageBox::show_error(window(), DeprecatedString::formatted("There was an error setting the new theme: {}", set_theme_result.error())); + } } ++index; } diff --git a/Userland/Applications/ThemeEditor/MainWidget.cpp b/Userland/Applications/ThemeEditor/MainWidget.cpp index 2ac9815f34..0c823b9b9a 100644 --- a/Userland/Applications/ThemeEditor/MainWidget.cpp +++ b/Userland/Applications/ThemeEditor/MainWidget.cpp @@ -208,7 +208,11 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) auto response = FileSystemAccessClient::Client::the().try_open_file(&window, "Select theme file", "/res/themes"sv); if (response.is_error()) return; - load_from_file(*response.value()); + auto load_from_file_result = load_from_file(*response.value()); + if (load_from_file_result.is_error()) { + GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Can't open file named {}: {}", response.value()->filename(), load_from_file_result.error())); + return; + } }))); m_save_action = GUI::CommonActions::make_save_action([&](auto&) { @@ -557,10 +561,10 @@ void MainWidget::show_path_picker_dialog(StringView property_display_name, GUI:: path_input.set_text(*result); } -void MainWidget::load_from_file(Core::File& file) +ErrorOr<void> MainWidget::load_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); + auto config_file = TRY(Core::ConfigFile::open(file.filename(), file.leak_fd())); + auto theme = TRY(Gfx::load_system_theme(config_file)); VERIFY(theme.is_valid()); auto new_palette = Gfx::Palette(Gfx::PaletteImpl::create_with_anonymous_buffer(theme)); @@ -599,6 +603,7 @@ void MainWidget::load_from_file(Core::File& file) m_last_modified_time = Time::now_monotonic(); window()->set_modified(false); + return {}; } } diff --git a/Userland/Applications/ThemeEditor/MainWidget.h b/Userland/Applications/ThemeEditor/MainWidget.h index 28befade58..f9bac73729 100644 --- a/Userland/Applications/ThemeEditor/MainWidget.h +++ b/Userland/Applications/ThemeEditor/MainWidget.h @@ -85,7 +85,7 @@ public: ErrorOr<void> initialize_menubar(GUI::Window&); GUI::Window::CloseRequestDecision request_close(); void update_title(); - void load_from_file(Core::File&); + ErrorOr<void> load_from_file(Core::File&); private: MainWidget(); diff --git a/Userland/Applications/ThemeEditor/PreviewWidget.cpp b/Userland/Applications/ThemeEditor/PreviewWidget.cpp index 9a80469735..45b19d45e2 100644 --- a/Userland/Applications/ThemeEditor/PreviewWidget.cpp +++ b/Userland/Applications/ThemeEditor/PreviewWidget.cpp @@ -160,7 +160,10 @@ void PreviewWidget::drop_event(GUI::DropEvent& event) auto response = FileSystemAccessClient::Client::the().try_request_file(window(), urls.first().path(), Core::OpenMode::ReadOnly); if (response.is_error()) return; - set_theme_from_file(*response.value()); + + auto set_theme_from_file_result = set_theme_from_file(response.release_value()); + if (set_theme_from_file_result.is_error()) + GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Setting theme from file has failed: {}", set_theme_from_file_result.error())); } } diff --git a/Userland/Applications/ThemeEditor/main.cpp b/Userland/Applications/ThemeEditor/main.cpp index 1e60a885c5..200e86cdfc 100644 --- a/Userland/Applications/ThemeEditor/main.cpp +++ b/Userland/Applications/ThemeEditor/main.cpp @@ -56,8 +56,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, path.value()); if (response.is_error()) GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error())); - else - main_widget->load_from_file(response.release_value()); + else { + auto load_from_file_result = main_widget->load_from_file(response.release_value()); + if (load_from_file_result.is_error()) + GUI::MessageBox::show_error(window, DeprecatedString::formatted("Loading theme from file has failed: {}", load_from_file_result.error())); + } }); } diff --git a/Userland/Libraries/LibGUI/AbstractThemePreview.cpp b/Userland/Libraries/LibGUI/AbstractThemePreview.cpp index 9ed8de1dd6..1cd8993fef 100644 --- a/Userland/Libraries/LibGUI/AbstractThemePreview.cpp +++ b/Userland/Libraries/LibGUI/AbstractThemePreview.cpp @@ -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) diff --git a/Userland/Libraries/LibGUI/AbstractThemePreview.h b/Userland/Libraries/LibGUI/AbstractThemePreview.h index a502a7c2d7..680dcbe541 100644 --- a/Userland/Libraries/LibGUI/AbstractThemePreview.h +++ b/Userland/Libraries/LibGUI/AbstractThemePreview.h @@ -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); diff --git a/Userland/Libraries/LibGfx/SystemTheme.cpp b/Userland/Libraries/LibGfx/SystemTheme.cpp index 45ab4a8f6a..5682fec877 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.cpp +++ b/Userland/Libraries/LibGfx/SystemTheme.cpp @@ -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; diff --git a/Userland/Libraries/LibGfx/SystemTheme.h b/Userland/Libraries/LibGfx/SystemTheme.h index f4f42a5194..19aef754f3 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.h +++ b/Userland/Libraries/LibGfx/SystemTheme.h @@ -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(); } diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp index 1dede77962..ed57f2ccc2 100644 --- a/Userland/Services/Taskbar/main.cpp +++ b/Userland/Services/Taskbar/main.cpp @@ -227,7 +227,7 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu(GUI::Window& window) g_themes_menu = &system_menu->add_submenu("&Themes"); g_themes_menu->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/themes.png"sv).release_value_but_fixme_should_propagate_errors()); - g_themes = Gfx::list_installed_system_themes(); + g_themes = TRY(Gfx::list_installed_system_themes()); auto current_theme_name = GUI::ConnectionToWindowServer::the().get_system_theme(); { diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index 128e8d0f98..95fd787e4e 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -2064,9 +2064,12 @@ void WindowManager::invalidate_after_theme_or_font_change() bool WindowManager::update_theme(DeprecatedString theme_path, DeprecatedString theme_name, bool keep_desktop_background) { - auto new_theme = Gfx::load_system_theme(theme_path); - if (!new_theme.is_valid()) + auto error_or_new_theme = Gfx::load_system_theme(theme_path); + if (error_or_new_theme.is_error()) { + dbgln("WindowManager: Updating theme failed, error {}", error_or_new_theme.error()); return false; + } + auto new_theme = error_or_new_theme.release_value(); m_theme_overridden = false; Gfx::set_system_theme(new_theme); m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(new_theme); @@ -2101,8 +2104,7 @@ void WindowManager::clear_theme_override() { m_theme_overridden = false; auto previous_theme_name = m_config->read_entry("Theme", "Name"); - auto previous_theme = Gfx::load_system_theme(DeprecatedString::formatted("/res/themes/{}.ini", previous_theme_name)); - VERIFY(previous_theme.is_valid()); + auto previous_theme = MUST(Gfx::load_system_theme(DeprecatedString::formatted("/res/themes/{}.ini", previous_theme_name))); Gfx::set_system_theme(previous_theme); m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(previous_theme); invalidate_after_theme_or_font_change(); diff --git a/Userland/Services/WindowServer/main.cpp b/Userland/Services/WindowServer/main.cpp index 06a9a9375a..2238e32ce8 100644 --- a/Userland/Services/WindowServer/main.cpp +++ b/Userland/Services/WindowServer/main.cpp @@ -44,8 +44,7 @@ ErrorOr<int> serenity_main(Main::Arguments) auto wm_config = TRY(Core::ConfigFile::open("/etc/WindowServer.ini")); auto theme_name = wm_config->read_entry("Theme", "Name", "Default"); - auto theme = Gfx::load_system_theme(DeprecatedString::formatted("/res/themes/{}.ini", theme_name)); - VERIFY(theme.is_valid()); + auto theme = TRY(Gfx::load_system_theme(DeprecatedString::formatted("/res/themes/{}.ini", theme_name))); Gfx::set_system_theme(theme); auto palette = Gfx::PaletteImpl::create_with_anonymous_buffer(theme); diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index c1aaa5c869..2e8d2df8a3 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -771,10 +771,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) auto page_client = HeadlessBrowserPageClient::create(); - if (!resources_folder.is_empty()) - page_client->setup_palette(Gfx::load_system_theme(LexicalPath::join(resources_folder, "themes/Default.ini"sv).string())); - else - page_client->setup_palette(Gfx::load_system_theme("/res/themes/Default.ini")); + if (!resources_folder.is_empty()) { + auto system_theme = TRY(Gfx::load_system_theme(LexicalPath::join(resources_folder, "themes/Default.ini"sv).string())); + page_client->setup_palette(system_theme); + } else { + auto system_theme = TRY(Gfx::load_system_theme("/res/themes/Default.ini")); + page_client->setup_palette(system_theme); + } dbgln("Loading {}", url); page_client->load(AK::URL(url)); |