1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:57:35 +00:00

Calendar: Update month view on first_day_of_week setting change

Now when the user changes their preferred first day of the week in the
Calendar Settings, the Calendar application and applet views are update
accordingly without needing to restart them.
This commit is contained in:
Olivier De Cannière 2022-09-19 21:23:40 +02:00 committed by Tim Flynn
parent a1d98b825d
commit 6f69f4bb5e
4 changed files with 17 additions and 1 deletions

View file

@ -27,6 +27,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
Config::pledge_domain("Calendar");
Config::monitor_domain("Calendar");
TRY(Core::System::pledge("stdio recvfd sendfd rpath"));
TRY(Core::System::unveil("/etc/timezone", "r"));

View file

@ -754,4 +754,13 @@ size_t Calendar::day_of_week_index(String const& day_name)
auto const& day_names = AK::long_day_names;
return AK::find_index(day_names.begin(), day_names.end(), day_name);
}
void Calendar::config_string_did_change(String const& domain, String const& group, String const& key, String const& value)
{
VERIFY(domain == "Calendar");
if (group == "View" && key == "FirstDayOfWeek") {
m_first_day_of_week = static_cast<DayOfWeek>(day_of_week_index(value));
update_tiles(m_view_year, m_view_month);
}
}
}

View file

@ -8,13 +8,16 @@
#pragma once
#include <AK/String.h>
#include <LibConfig/Listener.h>
#include <LibCore/DateTime.h>
#include <LibGUI/Frame.h>
#include <LibGUI/Widget.h>
namespace GUI {
class Calendar final : public GUI::Frame {
class Calendar final
: public GUI::Frame
, public Config::Listener {
C_OBJECT(Calendar)
public:
@ -67,6 +70,8 @@ public:
m_unadjusted_tile_size.set_height(height);
}
virtual void config_string_did_change(String const&, String const&, String const&, String const&) override;
Function<void()> on_tile_click;
Function<void()> on_tile_doubleclick;
Function<void()> on_month_click;

View file

@ -50,6 +50,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
Config::pledge_domains({ "Taskbar", "Calendar" });
Config::monitor_domain("Taskbar");
Config::monitor_domain("Calendar");
app->event_loop().register_signal(SIGCHLD, [](int) {
// Wait all available children
while (waitpid(-1, nullptr, WNOHANG) > 0)