system, datetime: Don't set datetime when auto time sync is enabled

The timedate1_call will fail because network time synchronization is enabled:

GDBus.Error:org.freedesktop.timedate1.AutomaticTimeSyncEnabled: Automatic time synchronization is enabled

Let's not set_time when NTP is not available, neither set time by
accident at the widget construction stage. When widgets signals are connected
in the UI file their respective callback was getting called. By moving
the signal connection to callbacks to the widget's _init method we
avoid the unwanted callback call.

Fixes #2945
This commit is contained in:
Felipe Borges 2024-03-15 11:49:16 +01:00
parent 544c146ea8
commit 6127c08fa3
2 changed files with 9 additions and 4 deletions

View file

@ -304,6 +304,10 @@ queue_set_datetime (CcDateTimePage *self)
{
gint64 unixtime;
/* Don't set the time if we are using network time (NTP). */
if (gtk_switch_get_active (self->network_time_switch))
return;
/* timedated expects number of microseconds since 1 Jan 1970 UTC */
unixtime = g_date_time_to_unix (self->date);
@ -831,10 +835,8 @@ cc_date_time_page_class_init (CcDateTimePageClass *klass)
gtk_widget_class_bind_template_callback (widget_class, panel_tz_selection_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, list_box_row_activated);
gtk_widget_class_bind_template_callback (widget_class, time_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, change_clock_settings);
gtk_widget_class_bind_template_callback (widget_class, on_date_box_row_activated_cb);
gtk_widget_class_bind_template_callback (widget_class, on_month_selection_changed_cb);
bind_textdomain_codeset (GETTEXT_PACKAGE_TIMEZONES, "UTF-8");
}
@ -955,6 +957,11 @@ cc_date_time_page_init (CcDateTimePage *self)
* the model is filled up */
get_initial_timezone (self);
g_signal_connect_object (self->time_editor, "time-changed",
G_CALLBACK (time_changed_cb), self, G_CONNECT_SWAPPED);
g_signal_connect_object (self->month_model, "selection-changed",
G_CALLBACK (on_month_selection_changed_cb), self, G_CONNECT_SWAPPED);
/* Watch changes of timedated remote service properties */
g_signal_connect_object (self->dtm, "g-properties-changed",
G_CALLBACK (on_timedated_properties_changed), self, G_CONNECT_SWAPPED);

View file

@ -37,7 +37,6 @@
<child>
<object class="CcTimeEditor" id="time_editor">
<property name="halign">center</property>
<signal name="time-changed" handler="time_changed_cb" swapped="yes"/>
</object>
</child>
@ -264,7 +263,6 @@
<property name="model">
<object class="GtkSingleSelection" id="month_model">
<property name="autoselect">False</property>
<signal name="selection-changed" handler="on_month_selection_changed_cb" swapped="yes"/>
<property name="model">
<object class="GtkStringList">
<items>