diff options
author | Benjamin Berg <bberg@redhat.com> | 2021-03-19 11:22:42 +0100 |
---|---|---|
committer | Benjamin Berg <bberg@redhat.com> | 2021-03-19 11:29:50 +0100 |
commit | 1d26e31abc4d848659b5008ed4de2769f0b6c1c7 (patch) | |
tree | ac4440c3c5974492f918563f81e052cb5efe4416 | |
parent | 9d66021e135ec35860411ad2a9f4fb064abb86df (diff) | |
download | gnome-control-center-benzea/fix-ntp-update-loop.tar.gz |
datetime: Improve NTP switch handling fixing update loopbenzea/fix-ntp-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
-rw-r--r-- | panels/datetime/cc-datetime-panel.c | 32 |
1 files 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)); |