From e36e465b41a4495ab65aac3dd9e7271a240043be Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Tue, 9 May 2023 22:37:57 +0200 Subject: [PATCH] CalendarSettings: Propagate errors when creating CalendarSettingsWidget We need to add another pair of parenthesizes when propagating an initialization of ItemListModel, because a comma in a template argument would work as a separator of macro arguments, leading to a compile error. --- .../CalendarSettingsWidget.cpp | 18 +++++++++++++----- .../CalendarSettings/CalendarSettingsWidget.h | 7 +++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Userland/Applications/CalendarSettings/CalendarSettingsWidget.cpp b/Userland/Applications/CalendarSettings/CalendarSettingsWidget.cpp index 59004d87dd..ffb89956ae 100644 --- a/Userland/Applications/CalendarSettings/CalendarSettingsWidget.cpp +++ b/Userland/Applications/CalendarSettings/CalendarSettingsWidget.cpp @@ -29,14 +29,21 @@ void CalendarSettingsWidget::reset_default_values() m_default_view_combobox->set_text("Month"); } -CalendarSettingsWidget::CalendarSettingsWidget() +ErrorOr> CalendarSettingsWidget::try_create() { - load_from_gml(calendar_settings_widget_gml).release_value_but_fixme_should_propagate_errors(); + auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) CalendarSettingsWidget())); + TRY(widget->setup()); + return widget; +} + +ErrorOr CalendarSettingsWidget::setup() +{ + TRY(load_from_gml(calendar_settings_widget_gml)); m_first_day_of_week_combobox = *find_descendant_of_type_named("first_day_of_week"); m_first_day_of_week_combobox->set_text(Config::read_string("Calendar"sv, "View"sv, "FirstDayOfWeek"sv, "Sunday"sv)); m_first_day_of_week_combobox->set_only_allow_values_from_model(true); - m_first_day_of_week_combobox->set_model(*GUI::ItemListModel>::create(AK::long_day_names)); + m_first_day_of_week_combobox->set_model(*TRY((GUI::ItemListModel>::try_create(AK::long_day_names)))); m_first_day_of_week_combobox->on_change = [&](auto, auto) { set_modified(true); }; @@ -44,7 +51,7 @@ CalendarSettingsWidget::CalendarSettingsWidget() m_first_day_of_weekend_combobox = *find_descendant_of_type_named("first_day_of_weekend"); m_first_day_of_weekend_combobox->set_text(Config::read_string("Calendar"sv, "View"sv, "FirstDayOfWeekend"sv, "Saturday"sv)); m_first_day_of_weekend_combobox->set_only_allow_values_from_model(true); - m_first_day_of_weekend_combobox->set_model(*GUI::ItemListModel>::create(AK::long_day_names)); + m_first_day_of_weekend_combobox->set_model(*TRY((GUI::ItemListModel>::try_create(AK::long_day_names)))); m_first_day_of_weekend_combobox->on_change = [&](auto, auto) { set_modified(true); }; @@ -58,8 +65,9 @@ CalendarSettingsWidget::CalendarSettingsWidget() m_default_view_combobox = *find_descendant_of_type_named("default_view"); m_default_view_combobox->set_text(Config::read_string("Calendar"sv, "View"sv, "DefaultView"sv, "Month"sv)); m_default_view_combobox->set_only_allow_values_from_model(true); - m_default_view_combobox->set_model(*GUI::ItemListModel>::create(m_view_modes)); + m_default_view_combobox->set_model(*TRY((GUI::ItemListModel>::try_create(m_view_modes)))); m_default_view_combobox->on_change = [&](auto, auto) { set_modified(true); }; + return {}; } diff --git a/Userland/Applications/CalendarSettings/CalendarSettingsWidget.h b/Userland/Applications/CalendarSettings/CalendarSettingsWidget.h index d3215df51f..7c0f66574a 100644 --- a/Userland/Applications/CalendarSettings/CalendarSettingsWidget.h +++ b/Userland/Applications/CalendarSettings/CalendarSettingsWidget.h @@ -10,14 +10,17 @@ #include class CalendarSettingsWidget final : public GUI::SettingsWindow::Tab { - C_OBJECT(CalendarSettingsWidget) + C_OBJECT_ABSTRACT(CalendarSettingsWidget) public: + static ErrorOr> try_create(); + virtual void apply_settings() override; virtual void reset_default_values() override; private: - CalendarSettingsWidget(); + CalendarSettingsWidget() = default; + ErrorOr setup(); static constexpr Array const m_view_modes = { "Month"sv, "Year"sv }; RefPtr m_first_day_of_week_combobox;