[gnome-control-center] night-light: Update UI when gsettings schemas are nonwritable



commit a5f902c1242e74b250eb1cbe7adb7ddd28a9d512
Author: Jeremy Bicha <jbicha ubuntu com>
Date:   Wed Dec 19 13:39:00 2018 -0500

    night-light: Update UI when gsettings schemas are nonwritable
    
    Presumably, they are nonwritable because a system administrator has locked
    these settings down.
    
    https://help.gnome.org/admin/system-admin-guide/stable/dconf-lockdown.html
    
    If Night Light is locked on, don't show the Off button.
    
    If Night Light is locked off, don't show the Manual or "Sunset to Sunrise" buttons.
    
    If Manual is force-enabled, don't show "Sunset to Sunrise" or the other way around.

 panels/display/cc-night-light-dialog.c  | 42 +++++++++++++++++++++++++++++++++
 panels/display/cc-night-light-dialog.ui |  2 +-
 2 files changed, 43 insertions(+), 1 deletion(-)
---
diff --git a/panels/display/cc-night-light-dialog.c b/panels/display/cc-night-light-dialog.c
index 7a3b86f92..9f458df22 100644
--- a/panels/display/cc-night-light-dialog.c
+++ b/panels/display/cc-night-light-dialog.c
@@ -39,6 +39,7 @@ struct _CcNightLightDialog {
   GtkWidget           *spinbutton_to_minutes;
   GtkStack            *stack_from;
   GtkStack            *stack_to;
+  GtkWidget           *togglebutton_box;
   GtkWidget           *togglebutton_automatic;
   GtkWidget           *togglebutton_manual;
   GtkWidget           *togglebutton_off;
@@ -147,6 +148,33 @@ dialog_update_state (CcNightLightDialog *self)
 
   gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
 
+  /* Don't show the off button if it can't be turned off */
+  /* Don't allow choosing Manual or "Sunset to Sunrise" if it can't be turned on */
+  if (!g_settings_is_writable (self->settings_display, "night-light-enabled"))
+    {
+        gtk_widget_set_visible (self->togglebutton_off, !enabled);
+        gtk_widget_set_sensitive (self->togglebutton_box, enabled);
+    }
+  else
+    {
+        gtk_widget_set_visible (self->togglebutton_off, TRUE);
+        gtk_widget_set_sensitive (self->togglebutton_box, TRUE);
+    }
+
+  /* Don't show the Manual buttons if Manual can't be enabled. Same for "Sunset to Sunrise". */
+  if (!g_settings_is_writable (self->settings_display, "night-light-schedule-automatic"))
+    {
+        gtk_widget_set_visible (self->togglebutton_automatic, automatic);
+        gtk_widget_set_visible (self->togglebutton_manual, !automatic);
+        gtk_widget_set_visible (self->box_manual, !automatic);
+    }
+  else
+    {
+        gtk_widget_set_visible (self->togglebutton_automatic, TRUE);
+        gtk_widget_set_visible (self->togglebutton_manual, TRUE);
+        gtk_widget_set_visible (self->box_manual, TRUE);
+    }
+
   /* set from */
   if (automatic && self->proxy_color != NULL)
     {
@@ -551,6 +579,7 @@ 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, togglebutton_box);
   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);
@@ -580,6 +609,19 @@ cc_night_light_dialog_init (CcNightLightDialog *self)
 
   g_signal_connect (self->settings_display, "changed", G_CALLBACK (dialog_settings_changed_cb), self);
 
+  g_settings_bind_writable (self->settings_display, "night-light-schedule-from",
+                            self->spinbutton_from_hours, "sensitive",
+                            FALSE);
+  g_settings_bind_writable (self->settings_display, "night-light-schedule-from",
+                            self->spinbutton_from_minutes, "sensitive",
+                            FALSE);
+  g_settings_bind_writable (self->settings_display, "night-light-schedule-to",
+                            self->spinbutton_to_minutes, "sensitive",
+                            FALSE);
+  g_settings_bind_writable (self->settings_display, "night-light-schedule-to",
+                            self->spinbutton_to_minutes, "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 c8fe485c9..2ff3e0a4c 100644
--- a/panels/display/cc-night-light-dialog.ui
+++ b/panels/display/cc-night-light-dialog.ui
@@ -136,7 +136,7 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkButtonBox">
+                      <object class="GtkButtonBox" id="togglebutton_box">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="layout_style">end</property>


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