From 3526cadcca178ce85cab011d1f9cd6ebd62ef324 Mon Sep 17 00:00:00 2001 From: Victoria Lacroix Date: Tue, 13 Jun 2023 11:14:49 -0400 Subject: [PATCH] gcal-window: datetime settings shortcut MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shortcut is added so that time-related system settings can be easily accessed. See #1023 The code is largely just a copy-paste of the code that opens the "Online Accounts…" menu. Fixes #1023 --- src/gui/gcal-window.c | 11 +++++++++ src/gui/gcal-window.ui | 4 ++++ src/utils/gcal-utils.c | 52 ++++++++++++++++++++++++++++++++++++++++++ src/utils/gcal-utils.h | 4 ++++ 4 files changed, 71 insertions(+) diff --git a/src/gui/gcal-window.c b/src/gui/gcal-window.c index cc0a7331..e0b7d2f8 100644 --- a/src/gui/gcal-window.c +++ b/src/gui/gcal-window.c @@ -425,6 +425,16 @@ on_window_new_event_cb (GSimpleAction *action, gtk_widget_set_visible (GTK_WIDGET (self->event_editor), TRUE); } +static void +on_window_open_date_time_settings_cb (GSimpleAction *action, + GVariant *param, + gpointer user_data) +{ + GApplication *application = g_application_get_default (); + + gcal_utils_launch_date_time_settings_panel (g_application_get_dbus_connection (application), NULL, NULL); +} + static void on_window_open_online_accounts_cb (GSimpleAction *action, GVariant *param, @@ -1095,6 +1105,7 @@ gcal_window_init (GcalWindow *self) {"change-view", on_view_action_activated, "i" }, {"next-date", on_window_next_date_activated_cb }, {"new-event", on_window_new_event_cb }, + {"open-date-time-settings", on_window_open_date_time_settings_cb }, {"open-online-accounts", on_window_open_online_accounts_cb }, {"previous-date", on_window_previous_date_activated_cb }, {"show-calendars", on_show_calendars_action_activated }, diff --git a/src/gui/gcal-window.ui b/src/gui/gcal-window.ui index 19fdbc30..9c907e06 100644 --- a/src/gui/gcal-window.ui +++ b/src/gui/gcal-window.ui @@ -302,6 +302,10 @@
+ + _Date & Time Settings… + win.open-date-time-settings + _Online Accounts… win.open-online-accounts diff --git a/src/utils/gcal-utils.c b/src/utils/gcal-utils.c index 5b6a5449..28f98110 100644 --- a/src/utils/gcal-utils.c +++ b/src/utils/gcal-utils.c @@ -1123,6 +1123,58 @@ create_dbus_proxy (GDBusConnection *connection, NULL); } +void +gcal_utils_launch_date_time_settings_panel (GDBusConnection *connection, + const gchar *action, + const gchar *arg) +{ + g_autoptr (GDBusProxy) proxy = NULL; + GVariantBuilder builder; + GVariant *params[3]; + GVariant *array[1]; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("av")); + + if (!action && !arg) + { + g_variant_builder_add (&builder, "v", g_variant_new_string ("")); + } + else + { + if (action) + g_variant_builder_add (&builder, "v", g_variant_new_string (action)); + + if (arg) + g_variant_builder_add (&builder, "v", g_variant_new_string (arg)); + } + + array[0] = g_variant_new ("v", g_variant_new ("(sav)", "datetime", &builder)); + + params[0] = g_variant_new_string ("launch-panel"); + params[1] = g_variant_new_array (G_VARIANT_TYPE ("v"), array, 1); + params[2] = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); + + proxy = create_dbus_proxy (connection, "org.gnome.Settings", "/org/gnome/Settings"); + + /* Fallback for old GNOME versions */ + if (!proxy) + proxy = create_dbus_proxy (connection, "org.gnome.ControlCenter", "/org/gnome/ControlCenter"); + + if (!proxy) + { + g_warning ("Couldn't open Date & Time panel"); + return; + } + + g_dbus_proxy_call_sync (proxy, + "Activate", + g_variant_new_tuple (params, 3), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL); +} + void gcal_utils_launch_online_accounts_panel (GDBusConnection *connection, const gchar *action, diff --git a/src/utils/gcal-utils.h b/src/utils/gcal-utils.h index e80624aa..245a77f6 100644 --- a/src/utils/gcal-utils.h +++ b/src/utils/gcal-utils.h @@ -120,6 +120,10 @@ GList* filter_children_by_uid_and_modtype (GtkWidget GcalRecurrenceModType mod, const gchar *uid); +void gcal_utils_launch_date_time_settings_panel (GDBusConnection *connection, + const gchar *action, + const gchar *arg); + void gcal_utils_launch_online_accounts_panel (GDBusConnection *connection, const gchar *action, const gchar *arg);