From a0a6ae2a2c5574088caca5c4aa16dcddbe93219e Mon Sep 17 00:00:00 2001 From: mindonwarp Date: Sun, 30 Aug 2026 08:58:20 +0200 Subject: [PATCH] core/utils: Find the actual 'default' locale start of week day Use the gcal-utils to find the actual day in case the desktop setting for start of week is set to 'default'. After this commit, all usages of that function have to be changed to use the GcalContext instead. Part-of: --- src/core/gcal-context.c | 14 +++++-- src/utils/gcal-utils.c | 86 ----------------------------------------- 2 files changed, 11 insertions(+), 89 deletions(-) diff --git a/src/core/gcal-context.c b/src/core/gcal-context.c index f20821b4..9c450240 100644 --- a/src/core/gcal-context.c +++ b/src/core/gcal-context.c @@ -26,6 +26,8 @@ #include #include "gdesktop-enum-types.h" +#include "gcal-utils.h" + #define DESKTOP_SETTINGS_INTERFACE_NAMESPACE "org.gnome.desktop.interface" #define DESKTOP_SETTINGS_CALENDAR_NAMESPACE "org.gnome.desktop.calendar" #define CLOCK_FORMAT_KEY "clock-format" @@ -110,7 +112,13 @@ set_week_start_day_from_variant (GcalContext *self, weekday_nick = g_variant_get_string (variant, NULL); weekday = g_enum_get_value_by_nick (g_type_class_get (G_DESKTOP_TYPE_WEEKDAY), weekday_nick); - if (!weekday || self->week_start_day == weekday->value) + g_assert (weekday != NULL); + + /* find the actual 'default' from locale */ + if (weekday->value == G_DESKTOP_WEEKDAY_DEFAULT) + weekday = g_enum_get_value (g_type_class_get (G_DESKTOP_TYPE_WEEKDAY), gcal_util_get_first_weekday ()); + + if (self->week_start_day == weekday->value) return; self->week_start_day = weekday->value; @@ -383,7 +391,7 @@ gcal_context_class_init (GcalContextClass *klass) properties[PROP_WEEK_START_DAY] = g_param_spec_enum ("week-start-day", NULL, NULL, - G_DESKTOP_TYPE_WEEKDAY, get_first_weekday_iso (), + G_DESKTOP_TYPE_WEEKDAY, gcal_util_get_first_weekday (), G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, N_PROPS, properties); @@ -527,7 +535,7 @@ gcal_context_get_time_format (GcalContext *self) GDesktopWeekday gcal_context_get_week_start_day (GcalContext *self) { - g_return_val_if_fail (GCAL_IS_CONTEXT (self), get_first_weekday ()); + g_return_val_if_fail (GCAL_IS_CONTEXT (self), gcal_util_get_first_weekday ()); return self->week_start_day; } diff --git a/src/utils/gcal-utils.c b/src/utils/gcal-utils.c index 48b59650..7410317c 100644 --- a/src/utils/gcal-utils.c +++ b/src/utils/gcal-utils.c @@ -210,89 +210,6 @@ gcal_util_get_desc_from_component (ECalComponent *component, return desc != NULL ? g_strstrip (desc) : NULL; } -static gboolean -read_first_weekday_from_portal (gint *out_first_weekday) -{ - static gsize first_weekday_init = FALSE; - static gsize first_weekday = G_MAXSIZE; - - if (g_once_init_enter (&first_weekday_init)) - { - g_autoptr (GDBusProxy) settings_portal = NULL; - g_autoptr (GVariant) result = NULL; - g_autoptr (GVariant) aux2 = NULL; - g_autoptr (GVariant) aux = NULL; - g_autoptr (GError) error = NULL; - const gchar *day; - - /* - * If the value is not "default" then there is a user preference - * override, in that case skip the autodetection dance. - */ - static const gchar *portal_weekdays[] = { - "sunday", - "monday", - "tuesday", - "wednesday", - "thursday", - "friday", - "saturday", - }; - - settings_portal = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_NONE, - NULL, - "org.freedesktop.portal.Desktop", - "/org/freedesktop/portal/desktop", - "org.freedesktop.portal.Settings", - NULL, - &error); - - if (error) - { - g_warning ("Failed to load portals: %s. Aborting...", error->message); - goto out; - } - - result = g_dbus_proxy_call_sync (settings_portal, - "ReadOne", - g_variant_new ("(ss)", "org.gnome.desktop.calendar", "week-start-day"), - G_DBUS_CALL_FLAGS_NONE, - G_MAXINT, - NULL, - &error); - - if (error) - { - g_warning ("Failed to load first weekday settings: %s", error->message); - goto out; - } - - aux = g_variant_get_child_value (result, 0); - aux2 = g_variant_get_variant (aux); - day = g_variant_get_string (aux2, NULL); - - g_debug ("Setting 'week-start-day' is currently: %s", day); - - for (int i = 0; i < G_N_ELEMENTS (portal_weekdays); i++) - { - if (g_strcmp0 (day, portal_weekdays[i]) == 0) - { - first_weekday = i; - break; - } - } - -out: - g_once_init_leave (&first_weekday_init, TRUE); - } - - if (first_weekday != G_MAXSIZE && out_first_weekday) - *out_first_weekday = first_weekday; - - return first_weekday != G_MAXSIZE; -} - /** * gcal_util_get_first_weekday: * @@ -306,9 +223,6 @@ gcal_util_get_first_weekday (void) { gint week_start; - if (read_first_weekday_from_portal (&week_start)) - return week_start; - #ifdef HAVE__NL_TIME_FIRST_WEEKDAY union { unsigned int word; char *string; } langinfo;