displays: Use an AdwComboRow for the schedule type of the night light page

GtkComboBox is deprecated and not accessible, so this one is definitely better from this point of view.
This commit is contained in:
Lukáš Tyrychtr 2023-07-17 10:20:22 +02:00 committed by Felipe Borges
parent 32f2d9ea8d
commit ba79d849af
2 changed files with 16 additions and 21 deletions

View file

@ -44,7 +44,7 @@ struct _CcNightLightPage {
GtkWidget *infobar_disabled;
GtkWidget *scale_color_temperature;
GtkWidget *night_light_toggle_switch;
GtkComboBox *schedule_type_combo;
AdwComboRow *schedule_type_row;
GtkWidget *from_spinbuttons_box;
GtkSpinButton *spinbutton_from_hours;
GtkSpinButton *spinbutton_from_minutes;
@ -195,7 +195,7 @@ dialog_update_state (CcNightLightPage *self)
gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
gtk_combo_box_set_active_id (self->schedule_type_combo, automatic ? "automatic" : "manual");
adw_combo_row_set_selected (self->schedule_type_row, automatic ? 0 : 1);
/* set from */
if (automatic && self->proxy_color != NULL)
@ -284,22 +284,22 @@ build_schedule_combo_row (CcNightLightPage *self)
gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
gtk_combo_box_set_active_id (self->schedule_type_combo, automatic ? "automatic" : "manual");
adw_combo_row_set_selected (self->schedule_type_row, automatic ? 0 : 1);
self->ignore_value_changed = FALSE;
}
static void
on_schedule_type_combo_active_changed_cb (CcNightLightPage *self)
on_schedule_type_row_selected_changed_cb (CcNightLightPage *self)
{
const gchar *active_id;
guint selected;
gboolean automatic;
if (self->ignore_value_changed)
return;
active_id = gtk_combo_box_get_active_id (self->schedule_type_combo);
automatic = g_str_equal (active_id, "automatic");
selected = adw_combo_row_get_selected (self->schedule_type_row);
automatic = selected == 0;;
g_settings_set_boolean (self->settings_display, "night-light-schedule-automatic", automatic);
}
@ -680,7 +680,7 @@ cc_night_light_page_class_init (CcNightLightPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_unsupported_description);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_disabled);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_toggle_switch);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, schedule_type_combo);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, schedule_type_row);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, scale_color_temperature);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, from_spinbuttons_box);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, spinbutton_from_hours);
@ -702,7 +702,7 @@ cc_night_light_page_class_init (CcNightLightPageClass *klass)
gtk_widget_class_bind_template_callback (widget_class, dialog_time_to_value_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, dialog_color_temperature_value_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, dialog_undisable_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, on_schedule_type_combo_active_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, on_schedule_type_row_selected_changed_cb);
}

View file

@ -96,23 +96,18 @@
<!-- Schedule -->
<child>
<object class="AdwActionRow" id="schedule_row">
<object class="AdwComboRow" id="schedule_type_row">
<property name="title" translatable="yes">Schedule</property>
<property name="sensitive" bind-source="night_light_toggle_switch" bind-property="active" bind-flags="default|sync-create" />
<child>
<object class="GtkComboBoxText" id="schedule_type_combo">
<property name="valign">center</property>
<signal name="notify::active" handler="on_schedule_type_combo_active_changed_cb" object="CcNightLightPage" swapped="yes" />
<signal name="notify::selected" handler="on_schedule_type_row_selected_changed_cb" object="CcNightLightPage" swapped="yes" />
<property name="model">
<object class="GtkStringList">
<items>
<item translatable="yes" id="automatic">Sunset to Sunrise</item>
<item translatable="yes" id="manual">Manual Schedule</item>
<item translatable="yes">Sunset to Sunrise</item>
<item translatable="yes">Manual Schedule</item>
</items>
<accessibility>
<relation name="labelled-by">schedule_row</relation>
</accessibility>
</object>
</child>
</property>
</object>
</child>