[gnome-control-center/wip/hadess/power-saver-on-low-battery] power: Add UI for "power-saver profile when battery is low"




commit 3473040b596e85a6e0e198af4659baa7cc903b28
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Jul 21 12:29:55 2021 +0200

    power: Add UI for "power-saver profile when battery is low"
    
    See https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/merge_requests/247

 panels/power/cc-power-panel.c  | 29 +++++++++++++++++++++++++++++
 panels/power/cc-power-panel.ui | 15 +++++++++++++++
 2 files changed, 44 insertions(+)
---
diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c
index 740d52c64..061b7e75c 100644
--- a/panels/power/cc-power-panel.c
+++ b/panels/power/cc-power-panel.c
@@ -92,6 +92,8 @@ struct _CcPowerPanel
   GtkListBox        *power_profile_listbox;
   GtkListBox        *power_profile_info_listbox;
   HdyPreferencesGroup *power_profile_section;
+  HdyActionRow      *power_saver_low_battery_row;
+  GtkSwitch         *power_saver_low_battery_switch;
   GtkSizeGroup      *row_sizegroup;
   GtkComboBox       *suspend_on_battery_delay_combo;
   GtkLabel          *suspend_on_battery_delay_label;
@@ -256,6 +258,24 @@ empty_listbox (GtkListBox *listbox)
     gtk_container_remove (GTK_CONTAINER (listbox), l->data);
 }
 
+static void
+update_power_saver_low_battery_row_visibility (CcPowerPanel *self)
+{
+  g_autoptr(UpDevice) composite = NULL;
+  UpDeviceKind kind;
+
+  composite = up_client_get_display_device (self->up_client);
+  g_object_get (composite, "kind", &kind, NULL);
+  if (kind != UP_DEVICE_KIND_BATTERY ||
+      !self->power_profiles_proxy)
+    {
+      gtk_widget_hide (GTK_WIDGET (self->power_saver_low_battery_row));
+      return;
+    }
+
+  gtk_widget_show (GTK_WIDGET (self->power_saver_low_battery_row));
+}
+
 static void
 up_client_changed (CcPowerPanel *self)
 {
@@ -426,6 +446,8 @@ up_client_changed (CcPowerPanel *self)
           add_device (self, device);
         }
     }
+
+  update_power_saver_low_battery_row_visibility (self);
 }
 
 static void
@@ -1726,6 +1748,8 @@ setup_power_profiles (CcPowerPanel *self)
 
   if (self->has_performance_degraded)
     power_profile_update_info_boxes (self);
+
+  update_power_saver_low_battery_row_visibility (self);
 }
 
 static void
@@ -1838,6 +1862,8 @@ cc_power_panel_class_init (CcPowerPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_profile_listbox);
   gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_profile_info_listbox);
   gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_profile_section);
+  gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_saver_low_battery_row);
+  gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_saver_low_battery_switch);
   gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, row_sizegroup);
   gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, suspend_on_battery_delay_combo);
   gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, suspend_on_battery_delay_label);
@@ -1894,6 +1920,9 @@ cc_power_panel_init (CcPowerPanel *self)
   setup_power_profiles (self);
 
   setup_power_saving (self);
+  g_settings_bind (self->gsd_settings, "power-saver-profile-on-low-battery",
+                   self->power_saver_low_battery_switch, "active",
+                   G_SETTINGS_BIND_DEFAULT);
 
   setup_general_section (self);
 
diff --git a/panels/power/cc-power-panel.ui b/panels/power/cc-power-panel.ui
index d8283c556..4bde98ddf 100644
--- a/panels/power/cc-power-panel.ui
+++ b/panels/power/cc-power-panel.ui
@@ -222,6 +222,21 @@
                 </child>
               </object>
             </child>
+            <child>
+              <object class="HdyActionRow" id="power_saver_low_battery_row">
+                <property name="visible">False</property>
+                <property name="title" translatable="yes">_Power Saver on Low Battery</property>
+                <property name="subtitle" translatable="yes">When on low battery, the Power Saver profile 
will be automatically enabled.</property>
+                <property name="use_underline">True</property>
+                <property name="activatable_widget">power_saver_low_battery_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="power_saver_low_battery_switch">
+                    <property name="visible">True</property>
+                    <property name="valign">center</property>
+                  </object>
+                </child>
+              </object>
+            </child>
             <child>
               <object class="HdyActionRow" id="wifi_row">
                 <property name="visible">False</property>


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