1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:37:35 +00:00

ClockSettings: Convert ClockSettingsWidget to a failable factory

This commit is contained in:
Karol Kosek 2023-05-09 22:40:48 +02:00 committed by Andreas Kling
parent e36e465b41
commit ab8be9aed5
2 changed files with 19 additions and 6 deletions

View file

@ -19,9 +19,16 @@ constexpr auto time_format_12h_seconds = "%r"sv;
constexpr auto time_format_24h = "%R"sv; constexpr auto time_format_24h = "%R"sv;
constexpr auto time_format_24h_seconds = "%T"sv; constexpr auto time_format_24h_seconds = "%T"sv;
ClockSettingsWidget::ClockSettingsWidget() ErrorOr<NonnullRefPtr<ClockSettingsWidget>> ClockSettingsWidget::try_create()
{ {
load_from_gml(clock_settings_widget_gml).release_value_but_fixme_should_propagate_errors(); auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ClockSettingsWidget()));
TRY(widget->setup());
return widget;
}
ErrorOr<void> ClockSettingsWidget::setup()
{
TRY(load_from_gml(clock_settings_widget_gml));
m_24_hour_radio = *find_descendant_of_type_named<GUI::RadioButton>("24hour_radio"); m_24_hour_radio = *find_descendant_of_type_named<GUI::RadioButton>("24hour_radio");
auto& twelve_hour_radio = *find_descendant_of_type_named<GUI::RadioButton>("12hour_radio"); auto& twelve_hour_radio = *find_descendant_of_type_named<GUI::RadioButton>("12hour_radio");
@ -87,11 +94,13 @@ ClockSettingsWidget::ClockSettingsWidget()
set_modified(true); set_modified(true);
}; };
m_clock_preview_update_timer = Core::Timer::create_repeating(1000, [&]() { m_clock_preview_update_timer = TRY(Core::Timer::create_repeating(1000, [&]() {
update_clock_preview(); update_clock_preview();
}).release_value_but_fixme_should_propagate_errors(); }));
m_clock_preview_update_timer->start(); m_clock_preview_update_timer->start();
update_clock_preview(); update_clock_preview();
return {};
} }
void ClockSettingsWidget::apply_settings() void ClockSettingsWidget::apply_settings()

View file

@ -10,10 +10,14 @@
#include <LibGUI/SettingsWindow.h> #include <LibGUI/SettingsWindow.h>
class ClockSettingsWidget final : public GUI::SettingsWindow::Tab { class ClockSettingsWidget final : public GUI::SettingsWindow::Tab {
C_OBJECT(ClockSettingsWidget) C_OBJECT_ABSTRACT(ClockSettingsWidget)
public:
static ErrorOr<NonnullRefPtr<ClockSettingsWidget>> try_create();
private: private:
ClockSettingsWidget(); ClockSettingsWidget() = default;
ErrorOr<void> setup();
virtual void apply_settings() override; virtual void apply_settings() override;
virtual void reset_default_values() override; virtual void reset_default_values() override;