[gnome-control-center/gbsneto/panel-widget-in-sidebar: 3/14] window: Factor out function to find panel iter



commit 62743ab47e6de34d28061f384bdbbc87a4099da9
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Nov 12 00:30:55 2018 -0200

    window: Factor out function to find panel iter
    
    It will be used by the next commits to look for the panel
    name. That is because the panel name is what will be used
    as the first headerbar title of panels with a sidebar widget.

 shell/cc-window.c | 69 +++++++++++++++++++++++++++++++++----------------------
 1 file changed, 42 insertions(+), 27 deletions(-)
---
diff --git a/shell/cc-window.c b/shell/cc-window.c
index 3bda5456f..ea8d436aa 100644
--- a/shell/cc-window.c
+++ b/shell/cc-window.c
@@ -224,6 +224,37 @@ add_current_panel_to_history (CcShell    *shell,
   g_debug ("Added '%s' to the previous panels", self->current_panel_id);
 }
 
+static gboolean
+find_iter_for_panel_id (CcWindow    *self,
+                        const gchar *panel_id,
+                        GtkTreeIter *out_iter)
+{
+  GtkTreeIter iter;
+  gboolean valid;
+
+  valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->store), &iter);
+
+  while (valid)
+    {
+      g_autofree gchar *id = NULL;
+
+      gtk_tree_model_get (GTK_TREE_MODEL (self->store),
+                          &iter,
+                          COL_ID, &id,
+                          -1);
+
+      if (g_strcmp0 (id, panel_id) == 0)
+        break;
+
+      valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (self->store), &iter);
+    }
+
+  g_assert (out_iter != NULL);
+  *out_iter = iter;
+
+  return valid;
+}
+
 static void
 update_list_title (CcWindow *self)
 {
@@ -330,7 +361,6 @@ setup_model (CcWindow *shell)
   g_signal_connect_object (model, "row-changed", G_CALLBACK (on_row_changed_cb), shell, 0);
 }
 
-
 static gboolean
 set_active_panel_from_id (CcShell      *shell,
                           const gchar  *start_id,
@@ -344,8 +374,8 @@ set_active_panel_from_id (CcShell      *shell,
   GtkTreeIter iter;
   GtkWidget *old_panel;
   CcWindow *self;
-  gboolean iter_valid;
   gboolean activated;
+  gboolean found;
 
   self = CC_WINDOW (shell);
 
@@ -356,36 +386,21 @@ set_active_panel_from_id (CcShell      *shell,
       return TRUE;
     }
 
-  iter_valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->store), &iter);
-
-  /* find the details for this item */
-  while (iter_valid)
+  found = find_iter_for_panel_id (self, start_id, &iter);
+  if (!found)
     {
-      g_autofree gchar *id = NULL;
-
-      gtk_tree_model_get (GTK_TREE_MODEL (self->store), &iter,
-                          COL_NAME, &name,
-                          COL_GICON, &gicon,
-                          COL_ID, &id,
-                          COL_VISIBILITY, &visibility,
-                          -1);
-
-      if (id && strcmp (id, start_id) == 0)
-        break;
-
-      g_clear_pointer (&name, g_free);
-      g_clear_object (&gicon);
-
-      iter_valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (self->store), &iter);
+      g_warning ("Could not find settings panel \"%s\"", start_id);
+      return TRUE;
     }
 
   old_panel = self->current_panel;
 
-  if (!name)
-    {
-      g_warning ("Could not find settings panel \"%s\"", start_id);
-      return TRUE;
-    }
+  gtk_tree_model_get (GTK_TREE_MODEL (self->store),
+                      &iter,
+                      COL_NAME, &name,
+                      COL_GICON, &gicon,
+                      COL_VISIBILITY, &visibility,
+                      -1);
 
   /* Activate the panel */
   activated = activate_panel (CC_WINDOW (shell), start_id, parameters, name, gicon, visibility);


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