searchenginemodel: Use GListModel API to filter
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Sun, 9 Oct 2022 20:21:29 +0000 (17:21 -0300)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 21 Oct 2022 02:34:40 +0000 (22:34 -0400)
We now start a mini-series of commits that will ultimately remove
the GtkTreeModel implementation of GtkFileSystemModel.

As a first step, port GtkSearchEngineModel iter through the files
using GListModel API.

gtk/gtksearchenginemodel.c

index 3923ea68131500022e28f54fc8f9db8e3fbbbb5f..18fde279bc3631cc1c71a42448bdbe3b30f00c22 100644 (file)
@@ -81,37 +81,37 @@ static gboolean
 do_search (gpointer data)
 {
   GtkSearchEngineModel *model = data;
-  GtkTreeIter iter;
   GList *hits = NULL;
   gboolean got_results = FALSE;
 
-  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model->model), &iter))
+  for (guint i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (model->model)); i++)
     {
-      do
-        {
-          GFileInfo *info;
-
-          info = _gtk_file_system_model_get_info (model->model, &iter);
-          if (info_matches_query (model->query, info))
-            {
-              GFile *file;
-              GtkSearchHit *hit;
-
-              file = _gtk_file_system_model_get_file (model->model, &iter);
-              hit = g_new (GtkSearchHit, 1);
-              hit->file = g_object_ref (file);
-              hit->info = g_object_ref (info);
-              hits = g_list_prepend (hits, hit);
-            }
-        }
-      while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model->model), &iter));
+      GtkFileSystemItem *item;
+      GFileInfo *info;
 
-      if (hits)
+      item = g_list_model_get_item (G_LIST_MODEL (model->model), i);
+      info = _gtk_file_system_item_get_file_info (item);
+
+      if (info_matches_query (model->query, info))
         {
-          _gtk_search_engine_hits_added (GTK_SEARCH_ENGINE (model), hits);
-          g_list_free_full (hits, (GDestroyNotify)_gtk_search_hit_free);
-          got_results = TRUE;
+          GFile *file;
+          GtkSearchHit *hit;
+
+          file = _gtk_file_system_item_get_file (item);
+          hit = g_new (GtkSearchHit, 1);
+          hit->file = g_object_ref (file);
+          hit->info = g_object_ref (info);
+          hits = g_list_prepend (hits, hit);
         }
+
+      g_clear_object (&item);
+    }
+
+  if (hits)
+    {
+      _gtk_search_engine_hits_added (GTK_SEARCH_ENGINE (model), hits);
+      g_list_free_full (hits, (GDestroyNotify)_gtk_search_hit_free);
+      got_results = TRUE;
     }
 
   model->idle = 0;