summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorOlivier De Cannière <olivier.decanniere96@gmail.com>2022-09-19 22:50:01 +0200
committerTim Flynn <trflynn89@pm.me>2022-09-20 13:12:00 -0400
commita1d98b825d0255d4d35f435d8381d541fc56f48b (patch)
tree8faa615da650c3e629d9c3fe82ab8d958b585fc9 /Userland
parent0eceed4fd72697a4e9bebf23c06b300637296361 (diff)
downloadserenity-a1d98b825d0255d4d35f435d8381d541fc56f48b.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Calendar/main.cpp3
-rw-r--r--Userland/Applications/CalendarSettings/CalendarSettingsWidget.cpp11
-rw-r--r--Userland/Applications/CalendarSettings/CalendarSettingsWidget.gml37
-rw-r--r--Userland/Applications/CalendarSettings/CalendarSettingsWidget.h2
-rw-r--r--Userland/Libraries/LibGUI/Calendar.cpp8
5 files changed, 58 insertions, 3 deletions
diff --git a/Userland/Applications/Calendar/main.cpp b/Userland/Applications/Calendar/main.cpp
index b1c7d7223b..54f0e56042 100644
--- a/Userland/Applications/Calendar/main.cpp
+++ b/Userland/Applications/Calendar/main.cpp
@@ -99,6 +99,9 @@ ErrorOr<int> 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 72d4976f86..d354a9ba7f 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<GUI::ComboBox>("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<GUI::ComboBox>("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<StringView, Array<StringView, 2>>::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 8403a640e5..f619bec9c5 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 b033537472..494597100a 100644
--- a/Userland/Applications/CalendarSettings/CalendarSettingsWidget.h
+++ b/Userland/Applications/CalendarSettings/CalendarSettingsWidget.h
@@ -18,6 +18,8 @@ public:
private:
CalendarSettingsWidget();
+ static constexpr Array<StringView, 2> const m_view_modes = { "Month"sv, "Year"sv };
RefPtr<GUI::ComboBox> m_first_day_of_week_combobox;
+ RefPtr<GUI::ComboBox> m_default_view_combobox;
};
diff --git a/Userland/Libraries/LibGUI/Calendar.cpp b/Userland/Libraries/LibGUI/Calendar.cpp
index 2de848fa4b..a9be42687f 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());
}