From a1d98b825d0255d4d35f435d8381d541fc56f48b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20De=20Canni=C3=A8re?= Date: Mon, 19 Sep 2022 22:50:01 +0200 Subject: [PATCH] Calendar: Add setting to choose default view This commit adds an entry to the Calendar Settings to allow the user to select between the month and year views as the startup default. --- Userland/Applications/Calendar/main.cpp | 3 ++ .../CalendarSettingsWidget.cpp | 11 ++++++ .../CalendarSettingsWidget.gml | 37 +++++++++++++++++-- .../CalendarSettings/CalendarSettingsWidget.h | 2 + Userland/Libraries/LibGUI/Calendar.cpp | 8 ++++ 5 files changed, 58 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/Calendar/main.cpp b/Userland/Applications/Calendar/main.cpp index b1c7d7223b8..54f0e56042d 100644 --- a/Userland/Applications/Calendar/main.cpp +++ b/Userland/Applications/Calendar/main.cpp @@ -99,6 +99,9 @@ ErrorOr serenity_main(Main::Arguments arguments) view_type_action_group->set_exclusive(true); view_type_action_group->add_action(*view_month_action); view_type_action_group->add_action(*view_year_action); + auto default_view = Config::read_string("Calendar"sv, "View"sv, "DefaultView"sv, "Month"sv); + if (default_view == "Year") + view_year_action->set_checked(true); (void)TRY(toolbar->try_add_action(prev_date_action)); (void)TRY(toolbar->try_add_action(next_date_action)); diff --git a/Userland/Applications/CalendarSettings/CalendarSettingsWidget.cpp b/Userland/Applications/CalendarSettings/CalendarSettingsWidget.cpp index 72d4976f86e..d354a9ba7f9 100644 --- a/Userland/Applications/CalendarSettings/CalendarSettingsWidget.cpp +++ b/Userland/Applications/CalendarSettings/CalendarSettingsWidget.cpp @@ -13,16 +13,19 @@ void CalendarSettingsWidget::apply_settings() { Config::write_string("Calendar"sv, "View"sv, "FirstDayOfWeek"sv, m_first_day_of_week_combobox->text()); + Config::write_string("Calendar"sv, "View"sv, "DefaultView"sv, m_default_view_combobox->text()); } void CalendarSettingsWidget::reset_default_values() { m_first_day_of_week_combobox->set_text("Sunday"); + m_default_view_combobox->set_text("Month"); } CalendarSettingsWidget::CalendarSettingsWidget() { 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); @@ -30,4 +33,12 @@ CalendarSettingsWidget::CalendarSettingsWidget() m_first_day_of_week_combobox->on_change = [&](auto, auto) { set_modified(true); }; + + 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->on_change = [&](auto, auto) { + set_modified(true); + }; } diff --git a/Userland/Applications/CalendarSettings/CalendarSettingsWidget.gml b/Userland/Applications/CalendarSettings/CalendarSettingsWidget.gml index 8403a640e56..f619bec9c57 100644 --- a/Userland/Applications/CalendarSettings/CalendarSettingsWidget.gml +++ b/Userland/Applications/CalendarSettings/CalendarSettingsWidget.gml @@ -30,9 +30,40 @@ fixed_width: 70 } - @GUI::ComboBox { - name: "first_day_of_week" - } + @GUI::ComboBox { + name: "first_day_of_week" + } + } + } + + @GUI::GroupBox { + title: "Default view" + fixed_height: 72 + layout: @GUI::VerticalBoxLayout { + margins: [6] + spacing: 2 + } + + @GUI::Label { + text: "Show the month or the year view when Calendar is started." + word_wrap: true + text_alignment: "CenterLeft" + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 16 + } + + @GUI::Label { + text: "Default view:" + text_alignment: "CenterLeft" + fixed_width: 70 + } + + @GUI::ComboBox { + name: "default_view" + } } } } diff --git a/Userland/Applications/CalendarSettings/CalendarSettingsWidget.h b/Userland/Applications/CalendarSettings/CalendarSettingsWidget.h index b0335374729..494597100a1 100644 --- a/Userland/Applications/CalendarSettings/CalendarSettingsWidget.h +++ b/Userland/Applications/CalendarSettings/CalendarSettingsWidget.h @@ -18,6 +18,8 @@ public: private: CalendarSettingsWidget(); + static constexpr Array const m_view_modes = { "Month"sv, "Year"sv }; RefPtr m_first_day_of_week_combobox; + RefPtr m_default_view_combobox; }; diff --git a/Userland/Libraries/LibGUI/Calendar.cpp b/Userland/Libraries/LibGUI/Calendar.cpp index 2de848fa4b3..a9be42687fe 100644 --- a/Userland/Libraries/LibGUI/Calendar.cpp +++ b/Userland/Libraries/LibGUI/Calendar.cpp @@ -45,6 +45,14 @@ Calendar::Calendar(Core::DateTime date_time, Mode mode) } } + auto default_view = Config::read_string("Calendar"sv, "View"sv, "DefaultView"sv, "Month"sv); + if (default_view == "Year") { + m_mode = Year; + m_show_days = false; + m_show_year = true; + m_show_month_year = true; + } + update_tiles(m_selected_date.year(), m_selected_date.month()); }