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
This commit is contained in:
Benjamin Berg 2021-03-19 11:22:42 +01:00 committed by Robert Ancell
parent df8eb92efc
commit 3bf6ea7794

View file

@ -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));