GamesSettings: Make CardSettingsWidget creation fallible

This commit is contained in:
Sam Atkins 2023-02-01 13:50:10 +00:00 committed by Andreas Kling
parent 66f2f4d647
commit d3953c6b73
Notes: sideshowbarker 2024-07-17 00:52:47 +09:00
2 changed files with 17 additions and 6 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -67,9 +67,16 @@ private:
}
};
CardSettingsWidget::CardSettingsWidget()
ErrorOr<NonnullRefPtr<CardSettingsWidget>> CardSettingsWidget::try_create()
{
load_from_gml(card_settings_widget_gml).release_value_but_fixme_should_propagate_errors();
auto card_settings_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) CardSettingsWidget));
TRY(card_settings_widget->initialize());
return card_settings_widget;
}
ErrorOr<void> CardSettingsWidget::initialize()
{
TRY(load_from_gml(card_settings_widget_gml));
auto background_color = Gfx::Color::from_string(Config::read_string("Games"sv, "Cards"sv, "BackgroundColor"sv)).value_or(Gfx::Color::from_rgb(0x008000));
@ -99,6 +106,8 @@ CardSettingsWidget::CardSettingsWidget()
};
m_last_selected_card_back = m_card_back_image_view->selection().first();
return {};
}
void CardSettingsWidget::apply_settings()

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -18,15 +18,17 @@ namespace GamesSettings {
class CardGamePreview;
class CardSettingsWidget final : public GUI::SettingsWindow::Tab {
C_OBJECT(CardSettingsWidget)
C_OBJECT_ABSTRACT(CardSettingsWidget)
public:
static ErrorOr<NonnullRefPtr<CardSettingsWidget>> try_create();
virtual ~CardSettingsWidget() override = default;
virtual void apply_settings() override;
virtual void reset_default_values() override;
private:
CardSettingsWidget();
CardSettingsWidget() = default;
ErrorOr<void> initialize();
bool set_card_back_image_path(DeprecatedString const&);
DeprecatedString card_back_image_path() const;