night-light: Move Off to the schedule switcher row

As recommended by the mockup:
https://gitlab.gnome.org/Teams/Design/settings-mockups/blob/master/displays/night-light.png
This commit is contained in:
Jeremy Bicha 2018-12-18 20:49:38 -05:00 committed by Georges Basile Stavracas Neto
parent e5d8b6275a
commit 07c1de1893
2 changed files with 47 additions and 56 deletions

View file

@ -39,9 +39,9 @@ struct _CcNightLightDialog {
GtkWidget *spinbutton_to_minutes; GtkWidget *spinbutton_to_minutes;
GtkStack *stack_from; GtkStack *stack_from;
GtkStack *stack_to; GtkStack *stack_to;
GtkWidget *switch_enable;
GtkWidget *togglebutton_automatic; GtkWidget *togglebutton_automatic;
GtkWidget *togglebutton_manual; GtkWidget *togglebutton_manual;
GtkWidget *togglebutton_off;
GtkAdjustment *adjustment_from_hours; GtkAdjustment *adjustment_from_hours;
GtkAdjustment *adjustment_from_minutes; GtkAdjustment *adjustment_from_minutes;
@ -118,6 +118,7 @@ dialog_update_state (CcNightLightDialog *self)
gboolean enabled; gboolean enabled;
gdouble value = 0.f; gdouble value = 0.f;
g_autoptr(GDateTime) dt = g_date_time_new_now_local (); g_autoptr(GDateTime) dt = g_date_time_new_now_local ();
GtkToggleButton *toggle_button;
/* only show the infobar if we are disabled */ /* only show the infobar if we are disabled */
if (self->proxy_color != NULL) if (self->proxy_color != NULL)
@ -134,12 +135,14 @@ dialog_update_state (CcNightLightDialog *self)
enabled = g_settings_get_boolean (self->settings_display, "night-light-enabled"); enabled = g_settings_get_boolean (self->settings_display, "night-light-enabled");
automatic = g_settings_get_boolean (self->settings_display, "night-light-schedule-automatic"); automatic = g_settings_get_boolean (self->settings_display, "night-light-schedule-automatic");
gtk_widget_set_sensitive (self->togglebutton_automatic, enabled);
gtk_widget_set_sensitive (self->togglebutton_manual, enabled);
self->ignore_value_changed = TRUE; self->ignore_value_changed = TRUE;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->togglebutton_automatic), automatic); if (!enabled)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->togglebutton_manual), !automatic); toggle_button = GTK_TOGGLE_BUTTON (self->togglebutton_off);
else if (automatic)
toggle_button = GTK_TOGGLE_BUTTON (self->togglebutton_automatic);
else
toggle_button = GTK_TOGGLE_BUTTON (self->togglebutton_manual);
gtk_toggle_button_set_active (toggle_button, TRUE);
self->ignore_value_changed = FALSE; self->ignore_value_changed = FALSE;
gtk_widget_set_sensitive (self->box_manual, enabled && !automatic); gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
@ -217,15 +220,23 @@ static void
dialog_mode_changed_cb (GtkToggleButton *togglebutton, dialog_mode_changed_cb (GtkToggleButton *togglebutton,
CcNightLightDialog *self) CcNightLightDialog *self)
{ {
gboolean ret;
if (self->ignore_value_changed) if (self->ignore_value_changed)
return; return;
if (!gtk_toggle_button_get_active (togglebutton))
return;
ret = g_settings_get_boolean (self->settings_display, "night-light-schedule-automatic"); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->togglebutton_automatic)))
g_settings_set_boolean (self->settings_display, "night-light-schedule-automatic", !ret); {
g_settings_set_boolean (self->settings_display, "night-light-enabled", TRUE);
g_settings_set_boolean (self->settings_display, "night-light-schedule-automatic", TRUE);
}
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->togglebutton_manual)))
{
g_settings_set_boolean (self->settings_display, "night-light-enabled", TRUE);
g_settings_set_boolean (self->settings_display, "night-light-schedule-automatic", FALSE);
}
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->togglebutton_off)))
{
g_settings_set_boolean (self->settings_display, "night-light-enabled", FALSE);
}
} }
static void static void
@ -540,9 +551,9 @@ cc_night_light_dialog_class_init (CcNightLightDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, spinbutton_to_minutes); gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, spinbutton_to_minutes);
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, stack_from); gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, stack_from);
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, stack_to); gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, stack_to);
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, switch_enable);
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, togglebutton_automatic); gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, togglebutton_automatic);
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, togglebutton_manual); gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, togglebutton_manual);
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, togglebutton_off);
gtk_widget_class_bind_template_callback (widget_class, dialog_am_pm_from_button_clicked_cb); gtk_widget_class_bind_template_callback (widget_class, dialog_am_pm_from_button_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, dialog_am_pm_to_button_clicked_cb); gtk_widget_class_bind_template_callback (widget_class, dialog_am_pm_to_button_clicked_cb);
@ -569,18 +580,6 @@ cc_night_light_dialog_init (CcNightLightDialog *self)
g_signal_connect (self->settings_display, "changed", G_CALLBACK (dialog_settings_changed_cb), self); g_signal_connect (self->settings_display, "changed", G_CALLBACK (dialog_settings_changed_cb), self);
/* connect widgets */
g_settings_bind (self->settings_display,
"night-light-enabled",
self->switch_enable,
"active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind_writable (self->settings_display, "night-light-enabled",
self->switch_enable, "sensitive",
FALSE);
/* use custom CSS */ /* use custom CSS */
provider = gtk_css_provider_new (); provider = gtk_css_provider_new ();
if (!gtk_css_provider_load_from_data (provider, if (!gtk_css_provider_load_from_data (provider,

View file

@ -118,23 +118,7 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="row_spacing">22</property> <property name="row_spacing">22</property>
<property name="column_spacing">60</property> <property name="column_spacing">40</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Night Light</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child> <child>
<object class="GtkLabel"> <object class="GtkLabel">
<property name="visible">True</property> <property name="visible">True</property>
@ -151,29 +135,18 @@
<property name="top_attach">1</property> <property name="top_attach">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkSwitch" id="switch_enable">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">start</property>
<signal name="notify::active" handler="dialog_enabled_notify_cb" object="CcNightLightDialog" swapped="no" />
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child> <child>
<object class="GtkButtonBox"> <object class="GtkButtonBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="layout_style">end</property> <property name="layout_style">end</property>
<child> <child>
<object class="GtkToggleButton" id="togglebutton_automatic"> <object class="GtkRadioButton" id="togglebutton_automatic">
<property name="label" translatable="yes">Sunset to Sunrise</property> <property name="label" translatable="yes">Sunset to Sunrise</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="draw_indicator">False</property>
<property name="active">True</property> <property name="active">True</property>
<signal name="toggled" handler="dialog_mode_changed_cb" object="CcNightLightDialog" swapped="no" /> <signal name="toggled" handler="dialog_mode_changed_cb" object="CcNightLightDialog" swapped="no" />
</object> </object>
@ -184,11 +157,13 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkToggleButton" id="togglebutton_manual"> <object class="GtkRadioButton" id="togglebutton_manual">
<property name="label" translatable="yes">Manual</property> <property name="label" translatable="yes">Manual</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="group">togglebutton_automatic</property>
<property name="draw_indicator">False</property>
<signal name="toggled" handler="dialog_mode_changed_cb" object="CcNightLightDialog" swapped="no" /> <signal name="toggled" handler="dialog_mode_changed_cb" object="CcNightLightDialog" swapped="no" />
</object> </object>
<packing> <packing>
@ -197,6 +172,23 @@
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkRadioButton" id="togglebutton_off">
<property name="label" translatable="yes">_Off</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="draw_indicator">False</property>
<property name="group">togglebutton_automatic</property>
<property name="use_underline">True</property>
<signal name="toggled" handler="dialog_mode_changed_cb" object="CcNightLightDialog" swapped="no" />
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<style> <style>
<class name="linked"/> <class name="linked"/>
</style> </style>