[gnome-control-center/benzea/fix-ntp-update-loop] datetime: Improve NTP switch handling fixing update loop




commit 9cfe7fa0a38387d17b49905e02c9d39652874991
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..d71dcb9c1 100644
--- a/panels/datetime/cc-datetime-panel.c
+++ b/panels/datetime/cc-datetime-panel.c
@@ -626,11 +626,30 @@ 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,
+                GParamSpec      *pspec)
+{
+  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,10 +1124,9 @@ 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);
 
   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]