[gnome-control-center] night-light: Move Off to the schedule switcher row



commit 07c1de1893f59bccc4a5444966a29785130d8ebe
Author: Jeremy Bicha <jbicha ubuntu com>
Date:   Tue Dec 18 20:49:38 2018 -0500

    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

 panels/display/cc-night-light-dialog.c  | 49 +++++++++++++++---------------
 panels/display/cc-night-light-dialog.ui | 54 ++++++++++++++-------------------
 2 files changed, 47 insertions(+), 56 deletions(-)
---
diff --git a/panels/display/cc-night-light-dialog.c b/panels/display/cc-night-light-dialog.c
index abb26f07f..7a3b86f92 100644
--- a/panels/display/cc-night-light-dialog.c
+++ b/panels/display/cc-night-light-dialog.c
@@ -39,9 +39,9 @@ struct _CcNightLightDialog {
   GtkWidget           *spinbutton_to_minutes;
   GtkStack            *stack_from;
   GtkStack            *stack_to;
-  GtkWidget           *switch_enable;
   GtkWidget           *togglebutton_automatic;
   GtkWidget           *togglebutton_manual;
+  GtkWidget           *togglebutton_off;
 
   GtkAdjustment       *adjustment_from_hours;
   GtkAdjustment       *adjustment_from_minutes;
@@ -118,6 +118,7 @@ dialog_update_state (CcNightLightDialog *self)
   gboolean enabled;
   gdouble value = 0.f;
   g_autoptr(GDateTime) dt = g_date_time_new_now_local ();
+  GtkToggleButton *toggle_button;
 
   /* only show the infobar if we are disabled */
   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");
   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;
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->togglebutton_automatic), automatic);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->togglebutton_manual), !automatic);
+  if (!enabled)
+    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;
 
   gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
@@ -217,15 +220,23 @@ static void
 dialog_mode_changed_cb (GtkToggleButton    *togglebutton,
                         CcNightLightDialog *self)
 {
-  gboolean ret;
-
   if (self->ignore_value_changed)
     return;
-  if (!gtk_toggle_button_get_active (togglebutton))
-    return;
 
-  ret = g_settings_get_boolean (self->settings_display, "night-light-schedule-automatic");
-  g_settings_set_boolean (self->settings_display, "night-light-schedule-automatic", !ret);
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->togglebutton_automatic)))
+    {
+      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
@@ -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, stack_from);
   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_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_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);
 
-  /* 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 */
   provider = gtk_css_provider_new ();
   if (!gtk_css_provider_load_from_data (provider,
diff --git a/panels/display/cc-night-light-dialog.ui b/panels/display/cc-night-light-dialog.ui
index c61b3738b..c8fe485c9 100644
--- a/panels/display/cc-night-light-dialog.ui
+++ b/panels/display/cc-night-light-dialog.ui
@@ -118,23 +118,7 @@
                     <property name="can_focus">False</property>
                     <property name="hexpand">True</property>
                     <property name="row_spacing">22</property>
-                    <property name="column_spacing">60</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>
+                    <property name="column_spacing">40</property>
                     <child>
                       <object class="GtkLabel">
                         <property name="visible">True</property>
@@ -151,29 +135,18 @@
                         <property name="top_attach">1</property>
                       </packing>
                     </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>
                       <object class="GtkButtonBox">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="layout_style">end</property>
                         <child>
-                          <object class="GtkToggleButton" id="togglebutton_automatic">
+                          <object class="GtkRadioButton" id="togglebutton_automatic">
                             <property name="label" translatable="yes">Sunset to Sunrise</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="active">True</property>
                             <signal name="toggled" handler="dialog_mode_changed_cb" 
object="CcNightLightDialog" swapped="no" />
                           </object>
@@ -184,11 +157,13 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkToggleButton" id="togglebutton_manual">
+                          <object class="GtkRadioButton" id="togglebutton_manual">
                             <property name="label" translatable="yes">Manual</property>
                             <property name="visible">True</property>
                             <property name="can_focus">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" />
                           </object>
                           <packing>
@@ -197,6 +172,23 @@
                             <property name="position">1</property>
                           </packing>
                         </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>
                           <class name="linked"/>
                         </style>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]