[gtk/cherry-pick-4fe28ba0] Merge branch 'gtk-3-24' into 'gtk-3-24'



commit b1e9809f191e317e84293fe3d3699f26776d03b0
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jan 7 20:24:48 2019 +0000

    Merge branch 'gtk-3-24' into 'gtk-3-24'
    
    GtkSearchEngineQuartz Fixes
    
    See merge request GNOME/gtk!490
    
    (cherry picked from commit 4fe28ba02a297de6349e100daaf816fb9f9b170a)
    
    ae8be924 [GtkSearchEngineQuartz] Resolve the path to a GtkFile* for the hit list.
    ad9fd969 [GtkSearchEngineQuartz] Limit the returned hits.

 gtk/gtksearchenginequartz.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtksearchenginequartz.c b/gtk/gtksearchenginequartz.c
index da90c4d56b..95558a07f2 100644
--- a/gtk/gtksearchenginequartz.c
+++ b/gtk/gtksearchenginequartz.c
@@ -73,29 +73,37 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkSearchEngineQuartz, _gtk_search_engine_quartz, GT
 {
   int i;
   GList *hits = NULL;
+  /* The max was originally set to 1000 to mimic something called "the
+   * boogie backend".
+   */
+  const unsigned int max_hits = 1000;
+  const unsigned int max_iter = submitted_hits + [ns_query resultCount];
 
   /* Here we submit hits "submitted_hits" to "resultCount" */
-  for (i = submitted_hits; i < [ns_query resultCount]; i++)
+  for (i = submitted_hits; i < max_iter && i < max_hits; ++i)
     {
       id result = [ns_query resultAtIndex:i];
-      char *result_path;
+      const char *result_path;
+      GFile *file;
+      GtkSearchHit *hit;
+
+      result_path = [[result valueForAttribute:@"kMDItemPath"] UTF8String];
+      file = g_file_new_for_path (result_path);
+
+      hit = g_new (GtkSearchHit, 1);
+      hit->file = file;
+      hit->info = NULL;
 
-      result_path = g_strdup_printf ("file://%s", [[result valueForAttribute:@"kMDItemPath"] cString]);
-      hits = g_list_prepend (hits, result_path);
+      hits = g_list_prepend (hits, hit);
     }
 
   _gtk_search_engine_hits_added (engine, hits);
-  g_list_free (hits);
+  g_list_free_full (hits, (GDestroyNotify) _gtk_search_hit_free);
 
-  submitted_hits = [ns_query resultCount];
-
-  /* The beagle backend stops at 1000 hits, so guess we do so too here.
-   * It works pretty snappy on my MacBook, if we get rid of this limit
-   * we are almost definitely going to need some code to submit hits
-   * in batches.
-   */
-  if (submitted_hits > 1000)
+  if (max_iter >= max_hits)
     [ns_query stopQuery];
+
+  submitted_hits = max_iter;
 }
 
 - (void) queryUpdate:(id)sender


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