[gnome-control-center/wip/hadess/degraded-power-profile: 4/6] power: Simplify emptying listbox




commit 0f86d4d754705b7fb64f326abdfc22685ceafc59
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jul 15 13:46:19 2021 +0200

    power: Simplify emptying listbox
    
    We do that in a few places.

 panels/power/cc-power-panel.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c
index d31d16d22..5d57afe59 100644
--- a/panels/power/cc-power-panel.c
+++ b/panels/power/cc-power-panel.c
@@ -242,25 +242,29 @@ add_device (CcPowerPanel *self, UpDevice *device)
 }
 
 static void
-up_client_changed (CcPowerPanel *self)
+empty_listbox (GtkListBox *listbox)
 {
-  g_autoptr(GList) battery_children = NULL;
-  g_autoptr(GList) device_children = NULL;
+  g_autoptr(GList) children = NULL;
   GList *l;
+
+  children = gtk_container_get_children (GTK_CONTAINER (listbox));
+  for (l = children; l != NULL; l = l->next)
+    gtk_container_remove (GTK_CONTAINER (listbox), l->data);
+}
+
+static void
+up_client_changed (CcPowerPanel *self)
+{
   gint i;
   UpDeviceKind kind;
   guint n_batteries;
   gboolean on_ups;
   g_autoptr(UpDevice) composite = NULL;
 
-  battery_children = gtk_container_get_children (GTK_CONTAINER (self->battery_listbox));
-  for (l = battery_children; l != NULL; l = l->next)
-    gtk_container_remove (GTK_CONTAINER (self->battery_listbox), l->data);
+  empty_listbox (self->battery_listbox);
   gtk_widget_hide (GTK_WIDGET (self->battery_section));
 
-  device_children = gtk_container_get_children (GTK_CONTAINER (self->device_listbox));
-  for (l = device_children; l != NULL; l = l->next)
-    gtk_container_remove (GTK_CONTAINER (self->device_listbox), l->data);
+  empty_listbox (self->device_listbox);
   gtk_widget_hide (GTK_WIDGET (self->device_section));
 
 #ifdef TEST_FAKE_DEVICES


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