From 46cec6b8056f4e96756483cedc0b14b749ff7856 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Fri, 1 Mar 2013 17:44:38 -0500 Subject: Port to timedated instead of gnome-settings-daemon datetime mechanism --- src/datetime-prefs.c | 115 +++++++++++++++---------------------------------- src/datetime-service.c | 12 +++--- 2 files changed, 40 insertions(+), 87 deletions(-) (limited to 'src') diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 952dce1..196b95f 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -70,8 +70,6 @@ struct _IndicatorDatetimePanelPrivate gboolean changing_time; GtkWidget * loc_dlg; CcTimezoneCompletion * completion; - GCancellable * tz_query_cancel; - GCancellable * ntp_query_cancel; }; struct _IndicatorDatetimePanelClass @@ -193,7 +191,7 @@ dbus_set_answered (GObject *object, GAsyncResult *res, gpointer command) GVariant * answers = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), res, &error); if (error != NULL) { - g_warning("Could not set '%s' for SettingsDaemon: %s", (gchar *)command, error->message); + g_warning("Could not set '%s' using timedated: %s", (gchar *)command, error->message); g_error_free(error); return; } @@ -206,33 +204,8 @@ toggle_ntp (GtkWidget * radio, GParamSpec * pspec, IndicatorDatetimePanel * self { gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio)); - g_dbus_proxy_call (self->priv->proxy, "SetUsingNtp", g_variant_new ("(b)", active), - G_DBUS_CALL_FLAGS_NONE, -1, NULL, dbus_set_answered, "using_ntp"); -} - -static void -ntp_query_answered (GObject *object, GAsyncResult *res, IndicatorDatetimePanel * self) -{ - GError * error = NULL; - GVariant * answers = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), res, &error); - - g_clear_object (&self->priv->ntp_query_cancel); - - if (error != NULL) { - g_warning("Could not query DBus proxy for SettingsDaemon: %s", error->message); - g_error_free(error); - return; - } - - gboolean can_use_ntp, is_using_ntp; - g_variant_get (answers, "(bb)", &can_use_ntp, &is_using_ntp); - - gtk_widget_set_sensitive (GTK_WIDGET (self->priv->auto_radio), can_use_ntp); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->auto_radio), is_using_ntp); - - g_signal_connect (self->priv->auto_radio, "notify::active", G_CALLBACK (toggle_ntp), self); - - g_variant_unref (answers); + g_dbus_proxy_call (self->priv->proxy, "SetNTP", g_variant_new ("(bb)", active, TRUE), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, dbus_set_answered, "NTP"); } static void @@ -255,7 +228,7 @@ tz_changed (CcTimezoneMap * map, CcTimezoneLocation * location, IndicatorDatetim gchar * zone; g_object_get (location, "zone", &zone, NULL); - g_dbus_proxy_call (self->priv->proxy, "SetTimezone", g_variant_new ("(s)", zone), + g_dbus_proxy_call (self->priv->proxy, "SetTimezone", g_variant_new ("(sb)", zone, TRUE), G_DBUS_CALL_FLAGS_NONE, -1, NULL, dbus_set_answered, "timezone"); sync_entry (self, zone); @@ -263,56 +236,46 @@ tz_changed (CcTimezoneMap * map, CcTimezoneLocation * location, IndicatorDatetim g_free (zone); } -static void -tz_query_answered (GObject *object, GAsyncResult *res, IndicatorDatetimePanel * self) -{ - GError * error = NULL; - GVariant * answers = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), res, &error); - - g_clear_object (&self->priv->tz_query_cancel); - - if (error != NULL) { - g_warning("Could not query DBus proxy for SettingsDaemon: %s", error->message); - g_error_free(error); - return; - } - - const gchar * timezone; - g_variant_get (answers, "(&s)", &timezone); - - cc_timezone_map_set_timezone (self->priv->tzmap, timezone); - - sync_entry (self, timezone); - g_signal_connect (self->priv->tzmap, "location-changed", G_CALLBACK (tz_changed), self); - - g_variant_unref (answers); -} - static void proxy_ready (GObject *object, GAsyncResult *res, IndicatorDatetimePanel * self) { GError * error = NULL; IndicatorDatetimePanelPrivate * priv = self->priv; + GVariant *value; self->priv->proxy = g_dbus_proxy_new_for_bus_finish (res, &error); if (error != NULL) { - g_critical("Could not grab DBus proxy for SettingsDaemon: %s", error->message); + g_critical("Could not grab DBus proxy for timedated: %s", error->message); g_error_free(error); return; } /* And now, do initial proxy configuration */ - if (priv->ntp_query_cancel == NULL) { - priv->ntp_query_cancel = g_cancellable_new(); - g_dbus_proxy_call (priv->proxy, "GetUsingNtp", NULL, G_DBUS_CALL_FLAGS_NONE, -1, - priv->ntp_query_cancel, (GAsyncReadyCallback)ntp_query_answered, self); - } - if (priv->tz_query_cancel == NULL) { - priv->tz_query_cancel = g_cancellable_new(); - g_dbus_proxy_call (priv->proxy, "GetTimezone", NULL, G_DBUS_CALL_FLAGS_NONE, -1, - priv->tz_query_cancel, (GAsyncReadyCallback)tz_query_answered, self); - } + value = g_dbus_proxy_get_cached_property (priv->proxy, "NTP"); + if (value != NULL) + { + if (g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->auto_radio), g_variant_get_boolean (value)); + g_signal_connect (priv->auto_radio, "notify::active", G_CALLBACK (toggle_ntp), self); + } + g_variant_unref (value); + } + + value = g_dbus_proxy_get_cached_property (priv->proxy, "Timezone"); + if (value != NULL) + { + if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) + { + const gchar *timezone = g_variant_get_string (value, NULL); + + cc_timezone_map_set_timezone (priv->tzmap, timezone); + sync_entry (self, timezone); + g_signal_connect (priv->tzmap, "location-changed", G_CALLBACK (tz_changed), self); + } + g_variant_unref (value); + } } static void @@ -693,7 +656,7 @@ indicator_datetime_panel_init (IndicatorDatetimePanel * self) gtk_container_add (GTK_CONTAINER (alignment), polkit_button); gtk_box_pack_start (GTK_BOX (WIG ("timeDateBox")), alignment, FALSE, TRUE, 0); - const gchar * polkit_name = "org.gnome.settingsdaemon.datetimemechanism.configure"; + const gchar * polkit_name = "org.gnome.controlcenter.datetime.configure"; polkit_permission_new (polkit_name, NULL, NULL, polkit_perm_ready, polkit_button); /* Add map */ @@ -760,9 +723,9 @@ indicator_datetime_panel_init (IndicatorDatetimePanel * self) /* Grab proxy for settings daemon */ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, - "org.gnome.SettingsDaemon.DateTimeMechanism", - "/", - "org.gnome.SettingsDaemon.DateTimeMechanism", + "org.freedesktop.timedate1", + "/org/freedesktop/timedate1", + "org.freedesktop.timedate1", NULL, (GAsyncReadyCallback)proxy_ready, self); /* Grab proxy for datetime service, to see if it's running. It would @@ -792,16 +755,6 @@ indicator_datetime_panel_dispose (GObject * object) g_clear_object (&priv->builder); g_clear_object (&priv->proxy); - if (priv->tz_query_cancel != NULL) { - g_cancellable_cancel (priv->tz_query_cancel); - g_clear_object (&priv->tz_query_cancel); - } - - if (priv->ntp_query_cancel != NULL) { - g_cancellable_cancel (priv->ntp_query_cancel); - g_clear_object (&priv->ntp_query_cancel); - } - if (priv->loc_dlg) { gtk_widget_destroy (priv->loc_dlg); priv->loc_dlg = NULL; diff --git a/src/datetime-service.c b/src/datetime-service.c index 56ea51c..6f3cf7b 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -277,7 +277,7 @@ quick_set_tz_cb (GObject *object, GAsyncResult *res, gpointer data) GVariant * answers = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), res, &error); if (error != NULL) { - g_warning("Could not set timezone for SettingsDaemon: %s", error->message); + g_warning("Could not set timezone using timedated: %s", error->message); g_clear_error (&error); return; } @@ -293,13 +293,13 @@ quick_set_tz_proxy_cb (GObject *object, GAsyncResult *res, gpointer zone) GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish (res, &error); if (error != NULL) { - g_warning("Could not grab DBus proxy for SettingsDaemon: %s", error->message); + g_warning("Could not grab DBus proxy for timedated: %s", error->message); g_clear_error (&error); g_free (zone); return; } - g_dbus_proxy_call (proxy, "SetTimezone", g_variant_new ("(s)", zone), + g_dbus_proxy_call (proxy, "SetTimezone", g_variant_new ("(sb)", zone, TRUE), G_DBUS_CALL_FLAGS_NONE, -1, NULL, quick_set_tz_cb, NULL); g_free (zone); g_object_unref (proxy); @@ -323,9 +323,9 @@ quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, gpointer user_data) g_object_unref (conf); g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, - "org.gnome.SettingsDaemon.DateTimeMechanism", - "/", - "org.gnome.SettingsDaemon.DateTimeMechanism", + "org.freedesktop.timedate1", + "/org/freedesktop/timedate1", + "org.freedesktop.timedate1", NULL, quick_set_tz_proxy_cb, g_strdup (tz)); return; -- cgit v1.2.3 From 8b7e3b5283cc6bd28d023f4135f54656c6aca282 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Mon, 4 Mar 2013 16:18:10 -0500 Subject: Send proper arguments for SetTime call vs. the gnome-settings-daemon DateTimeMechanism, the systemd version adds an extra two boolean arguments and wants time in microseconds instead of seconds. Make sure we're doing that properly. --- src/datetime-prefs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 196b95f..2c6998a 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -322,7 +322,8 @@ save_time (IndicatorDatetimePanel * self) { if (self->priv->user_edited_time) { gdouble current_value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (self->priv->date_spin)); - g_dbus_proxy_call (self->priv->proxy, "SetTime", g_variant_new ("(x)", (guint64)current_value), + g_dbus_proxy_call (self->priv->proxy, "SetTime", + g_variant_new ("(xbb)", (gint64) (current_value * G_TIME_SPAN_SECOND), FALSE, TRUE), G_DBUS_CALL_FLAGS_NONE, -1, NULL, dbus_set_answered, "time"); } self->priv->user_edited_time = FALSE; -- cgit v1.2.3 From 028e652e4dc2e5ec602654faeba366b777935086 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Mon, 4 Mar 2013 17:43:08 -0500 Subject: preferences: Add CanNTP support If timedated has the CanNTP property then use it to set the sensitivity of the "Automatically from the internet" radio. This property is only available in new versions of systemd, so if the property is not set, leave the widget sensitive. --- src/datetime-prefs.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 2c6998a..13c0fc2 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -252,6 +252,17 @@ proxy_ready (GObject *object, GAsyncResult *res, IndicatorDatetimePanel * self) } /* And now, do initial proxy configuration */ + value = g_dbus_proxy_get_cached_property (priv->proxy, "CanNTP"); + if (value != NULL) + { + if (g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)) + { + gtk_widget_set_sensitive (priv->auto_radio, g_variant_get_boolean (value)); + g_signal_connect (priv->auto_radio, "notify::active", G_CALLBACK (toggle_ntp), self); + } + g_variant_unref (value); + } + value = g_dbus_proxy_get_cached_property (priv->proxy, "NTP"); if (value != NULL) { -- cgit v1.2.3 From 75073d4d01add8591336f9d16f8668f3d4807ca6 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Mon, 4 Mar 2013 18:00:13 -0500 Subject: prefs: remove second signal connection for toggle_ntp Copy/paste error. Thanks Charles. :) --- src/datetime-prefs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 13c0fc2..ddcc43f 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -256,10 +256,7 @@ proxy_ready (GObject *object, GAsyncResult *res, IndicatorDatetimePanel * self) if (value != NULL) { if (g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)) - { - gtk_widget_set_sensitive (priv->auto_radio, g_variant_get_boolean (value)); - g_signal_connect (priv->auto_radio, "notify::active", G_CALLBACK (toggle_ntp), self); - } + gtk_widget_set_sensitive (priv->auto_radio, g_variant_get_boolean (value)); g_variant_unref (value); } -- cgit v1.2.3