[gtk/wip/carlosg/tracker3: 1/5] gtksearchengine: Add "got_results" argument to ::finished



commit b890e878185a0bffe2669a210e1eddbfc9485dec
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun May 17 00:00:22 2020 +0200

    gtksearchengine: Add "got_results" argument to ::finished
    
    The filechooser tries to figure out whether it got results by poking
    the model, but all files might go through the async GFileInfo querying
    state.
    
    Make all search engines (and the composite one) just notify about this
    fact, so the file chooser can behave appropriately without waiting for
    the async operations to finish.

 gtk/gtkfilechooserwidget.c   |  3 ++-
 gtk/gtksearchengine.c        | 14 ++++++++++----
 gtk/gtksearchengine.h        |  3 ++-
 gtk/gtksearchenginequartz.c  |  2 +-
 gtk/gtksearchenginetracker.c |  4 ++--
 5 files changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index ba4961c280..17ffea9429 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -6535,6 +6535,7 @@ search_engine_hits_added_cb (GtkSearchEngine      *engine,
 /* Callback used from GtkSearchEngine when the query is done running */
 static void
 search_engine_finished_cb (GtkSearchEngine *engine,
+                           gboolean         got_results,
                            gpointer         data)
 {
   GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (data);
@@ -6548,7 +6549,7 @@ search_engine_finished_cb (GtkSearchEngine *engine,
       impl->show_progress_timeout = 0;
     }
 
-  if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (impl->search_model), NULL) == 0)
+  if (!got_results)
     {
       gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_files_stack), "empty");
       gtk_widget_grab_focus (impl->search_entry);
diff --git a/gtk/gtksearchengine.c b/gtk/gtksearchengine.c
index 3f7ba58a3a..8c69b47832 100644
--- a/gtk/gtksearchengine.c
+++ b/gtk/gtksearchengine.c
@@ -35,6 +35,7 @@
 struct _GtkSearchEnginePrivate {
   GtkSearchEngine *native;
   gboolean native_running;
+  gboolean got_results;
   gchar *native_error;
 
   GtkSearchEngine *model;
@@ -161,7 +162,7 @@ _gtk_search_engine_class_init (GtkSearchEngineClass *class)
                   G_STRUCT_OFFSET (GtkSearchEngineClass, finished),
                   NULL, NULL,
                   NULL,
-                  G_TYPE_NONE, 0);
+                  G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
 
   signals[ERROR] =
     g_signal_new (I_("error"),
@@ -230,13 +231,16 @@ update_status (GtkSearchEngine *engine)
           else if (engine->priv->model_error)
             _gtk_search_engine_error (engine, engine->priv->model_error);
           else
-            _gtk_search_engine_finished (engine);
+            _gtk_search_engine_finished (engine, engine->priv->got_results);
+
+          engine->priv->got_results = FALSE;
         }
     }
 }
 
 static void
 finished (GtkSearchEngine *engine,
+          gboolean         got_results,
           gpointer         data)
 {
   GtkSearchEngine *composite = GTK_SEARCH_ENGINE (data);
@@ -246,6 +250,7 @@ finished (GtkSearchEngine *engine,
   else if (engine == composite->priv->model)
     composite->priv->model_running = FALSE;
 
+  composite->priv->got_results |= got_results;
   update_status (composite);
 }
 
@@ -391,11 +396,12 @@ _gtk_search_engine_hits_added (GtkSearchEngine *engine,
 }
 
 void
-_gtk_search_engine_finished (GtkSearchEngine *engine)
+_gtk_search_engine_finished (GtkSearchEngine *engine,
+                             gboolean         got_results)
 {
   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
 
-  g_signal_emit (engine, signals[FINISHED], 0);
+  g_signal_emit (engine, signals[FINISHED], 0, got_results);
 }
 
 void
diff --git a/gtk/gtksearchengine.h b/gtk/gtksearchengine.h
index c3d181274d..0c11324d04 100644
--- a/gtk/gtksearchengine.h
+++ b/gtk/gtksearchengine.h
@@ -82,7 +82,8 @@ void           _gtk_search_engine_stop            (GtkSearchEngine *engine);
 
 void            _gtk_search_engine_hits_added      (GtkSearchEngine *engine, 
                                                     GList           *hits);
-void            _gtk_search_engine_finished        (GtkSearchEngine *engine);
+void             _gtk_search_engine_finished        (GtkSearchEngine *engine,
+                                                     gboolean         got_results);
 void            _gtk_search_engine_error           (GtkSearchEngine *engine, 
                                                     const gchar     *error_message);
 void             _gtk_search_engine_set_recursive   (GtkSearchEngine *engine,
diff --git a/gtk/gtksearchenginequartz.c b/gtk/gtksearchenginequartz.c
index 7e9d5dd721..d10cdf5987 100644
--- a/gtk/gtksearchenginequartz.c
+++ b/gtk/gtksearchenginequartz.c
@@ -124,7 +124,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkSearchEngineQuartz, _gtk_search_engine_quartz, GT
 
   [self submitHits:ns_query];
 
-  _gtk_search_engine_finished (engine);
+  _gtk_search_engine_finished (engine, submitted_hits > 0);
   submitted_hits = 0;
 }
 
diff --git a/gtk/gtksearchenginetracker.c b/gtk/gtksearchenginetracker.c
index 4a8188d488..7350d5e354 100644
--- a/gtk/gtksearchenginetracker.c
+++ b/gtk/gtksearchenginetracker.c
@@ -291,7 +291,7 @@ query_callback (GObject      *object,
 
   if (!reply)
     {
-      _gtk_search_engine_finished (GTK_SEARCH_ENGINE (tracker));
+      _gtk_search_engine_finished (GTK_SEARCH_ENGINE (tracker), FALSE);
       g_object_unref (tracker);
       return;
     }
@@ -315,7 +315,7 @@ query_callback (GObject      *object,
     }
 
   _gtk_search_engine_hits_added (GTK_SEARCH_ENGINE (tracker), hits);
-  _gtk_search_engine_finished (GTK_SEARCH_ENGINE (tracker));
+  _gtk_search_engine_finished (GTK_SEARCH_ENGINE (tracker), i > 0);
 
   g_list_free (hits);
   for (i = 0; i < n; i++)


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