[nautilus] shell: pass the full query to the slot to preserve all settings



commit 16d8b80cc482acb3d7bd725c4daf2a1b29ad6a3e
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Jul 17 04:15:11 2018 +0200

    shell: pass the full query to the slot to preserve all settings
    
    Instead of just opening a window with just the location and search terms,
    we should pass to the window slot the full nautilus query with all the
    shell search provider flags, so that they will be respected and that the
    results in the overview will respect the ones in nautilus

 src/nautilus-application.c           | 11 ++++------
 src/nautilus-application.h           |  3 +--
 src/nautilus-shell-search-provider.c | 41 +++++++++++++++++++-----------------
 src/nautilus-window-slot.c           | 19 +++++++----------
 src/nautilus-window-slot.h           |  2 +-
 src/nautilus-window.c                |  4 ++--
 src/nautilus-window.h                |  2 +-
 7 files changed, 39 insertions(+), 43 deletions(-)
---
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index c74d8b811..3199caa6c 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -1611,15 +1611,12 @@ nautilus_application_new (void)
 
 void
 nautilus_application_search (NautilusApplication *self,
-                             const gchar         *uri,
-                             const gchar         *text)
+                             NautilusQuery       *query)
 {
+    g_autoptr (GFile) location = NULL;
     NautilusWindow *window;
-    GFile *location;
 
-    location = g_file_new_for_uri (uri);
+    location = nautilus_query_get_location (query);
     window = open_window (self, location);
-    nautilus_window_search (window, text);
-
-    g_object_unref (location);
+    nautilus_window_search (window, query);
 }
diff --git a/src/nautilus-application.h b/src/nautilus-application.h
index 946c3eee1..f915b0d4d 100644
--- a/src/nautilus-application.h
+++ b/src/nautilus-application.h
@@ -84,7 +84,6 @@ GtkWidget * nautilus_application_connect_server (NautilusApplication *applicatio
                                                 NautilusWindow      *window);
 
 void nautilus_application_search (NautilusApplication *application,
-                                  const gchar         *uri,
-                                  const gchar         *text);
+                                  NautilusQuery       *query);
 void nautilus_application_startup_common (NautilusApplication *application);
 G_END_DECLS
diff --git a/src/nautilus-shell-search-provider.c b/src/nautilus-shell-search-provider.c
index bd97345d4..0789f0861 100644
--- a/src/nautilus-shell-search-provider.c
+++ b/src/nautilus-shell-search-provider.c
@@ -426,15 +426,32 @@ search_add_volumes_and_bookmarks (PendingSearch *search)
     g_object_unref (volume_monitor);
 }
 
+static NautilusQuery*
+shell_query_new (gchar **terms)
+{
+    NautilusQuery *query;
+    g_autoptr (GFile) home = NULL;
+    g_autofree gchar *terms_joined = NULL;
+
+    terms_joined = g_strjoinv (" ", terms);
+    home = g_file_new_for_path (g_get_home_dir ());
+
+    query = nautilus_query_new ();
+    nautilus_query_set_show_hidden_files (query, FALSE);
+    nautilus_query_set_recursive (query, NAUTILUS_QUERY_RECURSIVE_INDEXED_ONLY);
+    nautilus_query_set_text (query, terms_joined);
+    nautilus_query_set_location (query, home);
+
+    return query;
+}
+
 static void
 execute_search (NautilusShellSearchProvider  *self,
                 GDBusMethodInvocation        *invocation,
                 gchar                       **terms)
 {
-    gchar *terms_joined;
     NautilusQuery *query;
     PendingSearch *pending_search;
-    GFile *home;
 
     cancel_current_search (self);
 
@@ -446,14 +463,7 @@ execute_search (NautilusShellSearchProvider  *self,
         return;
     }
 
-    terms_joined = g_strjoinv (" ", terms);
-    home = g_file_new_for_path (g_get_home_dir ());
-
-    query = nautilus_query_new ();
-    nautilus_query_set_show_hidden_files (query, FALSE);
-    nautilus_query_set_recursive (query, NAUTILUS_QUERY_RECURSIVE_INDEXED_ONLY);
-    nautilus_query_set_text (query, terms_joined);
-    nautilus_query_set_location (query, home);
+    query = shell_query_new (terms);
 
     pending_search = g_slice_new0 (PendingSearch);
     pending_search->invocation = g_object_ref (invocation);
@@ -480,9 +490,6 @@ execute_search (NautilusShellSearchProvider  *self,
     nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (pending_search->engine),
                                         query);
     nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (pending_search->engine));
-
-    g_clear_object (&home);
-    g_free (terms_joined);
 }
 
 static gboolean
@@ -714,13 +721,9 @@ handle_launch_search (NautilusShellSearchProvider2  *skeleton,
                       gpointer                       user_data)
 {
     GApplication *app = g_application_get_default ();
-    gchar *string = g_strjoinv (" ", terms);
-    gchar *uri = nautilus_get_home_directory_uri ();
-
-    nautilus_application_search (NAUTILUS_APPLICATION (app), uri, string);
+    g_autoptr (NautilusQuery) query = shell_query_new (terms);
 
-    g_free (string);
-    g_free (uri);
+    nautilus_application_search (NAUTILUS_APPLICATION (app), query);
 
     nautilus_shell_search_provider2_complete_launch_search (skeleton, invocation);
     return TRUE;
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index f3e596445..90069cbde 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -98,6 +98,7 @@ typedef struct
 
     /* Query editor */
     NautilusQueryEditor *query_editor;
+    NautilusQuery *pending_search_query;
     gulong qe_changed_id;
     gulong qe_cancel_id;
     gulong qe_activated_id;
@@ -111,7 +112,6 @@ typedef struct
      * finish. Used for showing a spinner to provide feedback to the user. */
     gboolean allow_stop;
     gboolean needs_reload;
-    gchar *pending_search_text;
 
     /* New location. */
     GFile *pending_location;
@@ -376,9 +376,9 @@ update_search_visible (NautilusWindowSlot *self)
         }
     }
 
-    if (priv->pending_search_text)
+    if (priv->pending_search_query)
     {
-        nautilus_window_slot_search (self, g_strdup (priv->pending_search_text));
+        nautilus_window_slot_search (self, g_object_ref (priv->pending_search_query));
     }
 }
 
@@ -599,17 +599,13 @@ nautilus_window_slot_get_search_visible (NautilusWindowSlot *self)
 
 void
 nautilus_window_slot_search (NautilusWindowSlot *self,
-                             const gchar        *text)
+                             NautilusQuery      *query)
 {
     NautilusWindowSlotPrivate *priv;
     NautilusView *view;
 
     priv = nautilus_window_slot_get_instance_private (self);
-    if (priv->pending_search_text)
-    {
-        g_free (priv->pending_search_text);
-        priv->pending_search_text = NULL;
-    }
+    g_clear_object (&priv->pending_search_query);
 
     view = nautilus_window_slot_get_current_view (self);
     /* We could call this when the location is still being checked in the
@@ -618,11 +614,11 @@ nautilus_window_slot_search (NautilusWindowSlot *self,
     if (view)
     {
         nautilus_window_slot_set_search_visible (self, TRUE);
-        nautilus_query_editor_set_text (priv->query_editor, text);
+        nautilus_query_editor_set_query (priv->query_editor, query);
     }
     else
     {
-        priv->pending_search_text = g_strdup (text);
+        priv->pending_search_query = g_object_ref (query);
     }
 }
 
@@ -3087,6 +3083,7 @@ nautilus_window_slot_dispose (GObject *object)
     g_clear_object (&priv->current_location_bookmark);
     g_clear_object (&priv->last_location_bookmark);
     g_clear_object (&priv->slot_action_group);
+    g_clear_object (&priv->pending_search_query);
 
     g_clear_pointer (&priv->find_mount_cancellable, g_cancellable_cancel);
 
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index 6c6e46bda..e2e0d7592 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -115,7 +115,7 @@ gboolean nautilus_window_slot_get_searching                (NautilusWindowSlot *
 GList* nautilus_window_slot_get_selection                  (NautilusWindowSlot *slot);
 
 void     nautilus_window_slot_search                       (NautilusWindowSlot *slot,
-                                                            const gchar        *text);
+                                                            NautilusQuery      *query);
 
 gboolean nautilus_window_slot_handles_location (NautilusWindowSlot *self,
                                                 GFile              *location);
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index d655769d2..45999afb6 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -2884,14 +2884,14 @@ nautilus_window_show_about_dialog (NautilusWindow *window)
 
 void
 nautilus_window_search (NautilusWindow *window,
-                        const gchar    *text)
+                        NautilusQuery  *query)
 {
     NautilusWindowSlot *active_slot;
 
     active_slot = nautilus_window_get_active_slot (window);
     if (active_slot)
     {
-        nautilus_window_slot_search (active_slot, text);
+        nautilus_window_slot_search (active_slot, query);
     }
     else
     {
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index 8ac0d942d..15dc62993 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -103,7 +103,7 @@ void nautilus_window_end_dnd (NautilusWindow *window,
                               GdkDragContext *context);
 
 void nautilus_window_search (NautilusWindow *window,
-                             const gchar    *text);
+                             NautilusQuery  *query);
 
 void nautilus_window_initialize_slot (NautilusWindow          *window,
                                       NautilusWindowSlot      *slot,


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