From 0a8743843227d24875908fb5ffa18e95e3eff7be Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Sun, 9 Oct 2022 17:21:29 -0300 Subject: [PATCH] searchenginemodel: Use GListModel API to filter 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 | 46 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/gtk/gtksearchenginemodel.c b/gtk/gtksearchenginemodel.c index 3923ea6813..18fde279bc 100644 --- a/gtk/gtksearchenginemodel.c +++ b/gtk/gtksearchenginemodel.c @@ -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 + GtkFileSystemItem *item; + GFileInfo *info; + + 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)) { - GFileInfo *info; + GFile *file; + GtkSearchHit *hit; - 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); - } + 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); } - while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model->model), &iter)); - 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; - } + 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;