[gnome-control-center/benzea/fix-ntp-update-loop] datetime: Improve NTP switch handling fixing update loop
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/benzea/fix-ntp-update-loop] datetime: Improve NTP switch handling fixing update loop
- Date: Fri, 19 Mar 2021 10:30:52 +0000 (UTC)
commit 1d26e31abc4d848659b5008ed4de2769f0b6c1c7
Author: Benjamin Berg <bberg redhat com>
Date: Fri Mar 19 11:22:42 2021 +0100
datetime: Improve NTP switch handling fixing update loop
We cannot simply set the state/active property of the switch without
also triggering the notify:: or state-set signals at the same time. As
such, we need to block the "set-state" handler when we update the
"state" of the switch.
Also, while at it, change the switch to react to "state-set" and only
update the "state" after we received the response from the system.
Fixes: #1299
panels/datetime/cc-datetime-panel.c | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/panels/datetime/cc-datetime-panel.c b/panels/datetime/cc-datetime-panel.c
index 33a975941..4e7b3ee00 100644
--- a/panels/datetime/cc-datetime-panel.c
+++ b/panels/datetime/cc-datetime-panel.c
@@ -626,11 +626,29 @@ on_clock_changed (CcDateTimePanel *panel,
update_timezone (panel);
}
-static void
-change_ntp (CcDateTimePanel *self,
- GParamSpec *pspec)
+static gboolean
+change_ntp (CcDateTimePanel *self)
{
queue_set_ntp (self);
+
+ /* The new state will be visible once we see the reply. */
+ return TRUE;
+}
+
+static void
+on_ntp_changed (CcDateTimePanel *self)
+{
+ gboolean ntp_on;
+
+ g_object_get (self->dtm, "ntp", &ntp_on, NULL);
+
+ g_signal_handlers_block_by_func (self->network_time_switch, change_ntp, self);
+
+ g_object_set (self->network_time_switch,
+ "state", ntp_on,
+ NULL);
+
+ g_signal_handlers_unblock_by_func (self->network_time_switch, change_ntp, self);
}
static gboolean
@@ -1105,11 +1123,11 @@ cc_date_time_panel_init (CcDateTimePanel *self)
bind_switch_to_row (self,
self->network_time_switch,
self->datetime_button);
- g_object_bind_property (self->dtm, "ntp",
- self->network_time_switch, "active",
- G_BINDING_SYNC_CREATE);
- g_signal_connect_object (self->network_time_switch, "notify::active",
+ g_signal_connect_object (self->dtm, "notify::ntp",
+ G_CALLBACK (on_ntp_changed), self, G_CONNECT_SWAPPED);
+ g_signal_connect_object (self->network_time_switch, "state-set",
G_CALLBACK (change_ntp), self, G_CONNECT_SWAPPED);
+ on_ntp_changed (self);
gtk_widget_set_visible (self->auto_datetime_row, is_ntp_available (self));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]