[nautilus] query: Add flags for recursive search types



commit 60f47ccaf15d7bd8f402a0058b387d105a31b964
Author: Marco Trevisan (Treviño) <mail 3v1n0 net>
Date:   Wed Jun 6 01:49:54 2018 +0200

    query: Add flags for recursive search types
    
    Use a list of cases to define when the recursive search should be done, instead
    of a simple true/false boolean.
    
    A part from the self-explanatory cases `ALWAYS` and `NEVER`, the `IF_INDEXED`
    option permits to any search engine that uses an indexed-search to return
    results from subfolders of the search location.
    
    One case we want to address, is the shell-search provider, that should not perform
    recursive searches, but it could return values from subfolders of the user home
    if the search is executed by search engines like tracker.

 src/nautilus-file-utilities.c | 29 +++++++++++++++++------------
 src/nautilus-file-utilities.h |  4 +++-
 src/nautilus-query-editor.c   | 10 +++++-----
 src/nautilus-query.c          | 28 ++++++++++++++--------------
 src/nautilus-query.h          | 15 ++++++++++-----
 src/nautilus-window-slot.c    |  4 ++--
 6 files changed, 51 insertions(+), 39 deletions(-)
---
diff --git a/src/nautilus-file-utilities.c b/src/nautilus-file-utilities.c
index 5f0f348f7..792f78a23 100644
--- a/src/nautilus-file-utilities.c
+++ b/src/nautilus-file-utilities.c
@@ -1392,28 +1392,33 @@ nautilus_uri_to_native_uri (const gchar *uri)
     return NULL;
 }
 
-gboolean
-location_settings_search_is_recursive (GFile *location)
+NautilusQueryRecursive
+location_settings_search_get_recursive (GFile *location)
 {
-    NautilusFile *file;
-    gboolean recursive;
+    g_autoptr (NautilusFile) file = NULL;
 
-    g_return_val_if_fail (location != NULL, TRUE);
+    g_return_val_if_fail (location, NAUTILUS_QUERY_RECURSIVE_ALWAYS);
 
-    file = nautilus_file_get (location);
+    file = nautilus_file_get_existing (location);
+
+    g_return_val_if_fail (file, NAUTILUS_QUERY_RECURSIVE_ALWAYS);
 
     if (nautilus_file_is_remote (file))
     {
-        recursive = g_settings_get_enum (nautilus_preferences, "recursive-search") == 
NAUTILUS_SPEED_TRADEOFF_ALWAYS;
+        if (g_settings_get_enum (nautilus_preferences, "recursive-search") == NAUTILUS_SPEED_TRADEOFF_ALWAYS)
+        {
+            return NAUTILUS_QUERY_RECURSIVE_ALWAYS;
+        }
     }
     else
     {
-        recursive = g_settings_get_enum (nautilus_preferences, "recursive-search") == 
NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY ||
-                    g_settings_get_enum (nautilus_preferences, "recursive-search") == 
NAUTILUS_SPEED_TRADEOFF_ALWAYS;
+        if (g_settings_get_enum (nautilus_preferences, "recursive-search") == 
NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY ||
+            g_settings_get_enum (nautilus_preferences, "recursive-search") == NAUTILUS_SPEED_TRADEOFF_ALWAYS)
+        {
+            return NAUTILUS_QUERY_RECURSIVE_ALWAYS;
+        }
     }
 
-    nautilus_file_unref (file);
-
-    return recursive;
+    return NAUTILUS_QUERY_RECURSIVE_NEVER;
 }
 
diff --git a/src/nautilus-file-utilities.h b/src/nautilus-file-utilities.h
index e02f2b0c6..c0bdcaabb 100644
--- a/src/nautilus-file-utilities.h
+++ b/src/nautilus-file-utilities.h
@@ -27,6 +27,8 @@
 
 #include <config.h>
 
+#include "nautilus-query.h"
+
 #define NAUTILUS_DESKTOP_ID APPLICATION_ID ".desktop"
 
 /* These functions all return something something that needs to be
@@ -122,4 +124,4 @@ GList * nautilus_file_list_from_uri_list (GList *uris);
 
 gchar * nautilus_uri_to_native_uri (const gchar *uri);
 
-gboolean location_settings_search_is_recursive (GFile *location);
+NautilusQueryRecursive location_settings_search_get_recursive (GFile *location);
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index 3a56ceea0..03424fe0a 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -97,7 +97,7 @@ update_fts_sensitivity (NautilusQueryEditor *editor)
         fts_sensitive = !nautilus_file_is_other_locations (file) &&
                         !g_str_has_prefix (uri, "network://") &&
                         !(nautilus_file_is_remote (file) &&
-                          !location_settings_search_is_recursive (editor->location));
+                          location_settings_search_get_recursive (editor->location) == 
NAUTILUS_QUERY_RECURSIVE_NEVER);
         nautilus_search_popover_set_fts_sensitive (NAUTILUS_SEARCH_POPOVER (editor->popover),
                                                    fts_sensitive);
     }
@@ -108,14 +108,14 @@ recursive_search_preferences_changed (GSettings           *settings,
                                       gchar               *key,
                                       NautilusQueryEditor *editor)
 {
-    gboolean recursive;
+    NautilusQueryRecursive recursive;
 
     if (!editor->location || !editor->query)
     {
         return;
     }
 
-    recursive = location_settings_search_is_recursive (editor->location);
+    recursive = location_settings_search_get_recursive (editor->location);
     if (recursive != nautilus_query_get_recursive (editor->query))
     {
         nautilus_query_set_recursive (editor->query, recursive);
@@ -312,7 +312,7 @@ create_query (NautilusQueryEditor *editor)
 {
     NautilusQuery *query;
     g_autoptr (NautilusFile) file = NULL;
-    gboolean recursive;
+    NautilusQueryRecursive recursive;
     gboolean fts_enabled;
 
     g_return_if_fail (editor->query == NULL);
@@ -329,7 +329,7 @@ create_query (NautilusQueryEditor *editor)
 
     nautilus_query_set_search_content (query, fts_enabled);
 
-    recursive = location_settings_search_is_recursive (editor->location);
+    recursive = location_settings_search_get_recursive (editor->location);
 
     nautilus_query_set_text (query, gtk_entry_get_text (GTK_ENTRY (editor->entry)));
     nautilus_query_set_location (query, editor->location);
diff --git a/src/nautilus-query.c b/src/nautilus-query.c
index 05e29b90e..e6802c314 100644
--- a/src/nautilus-query.c
+++ b/src/nautilus-query.c
@@ -41,11 +41,11 @@ struct _NautilusQuery
     GList *mime_types;
     gboolean show_hidden;
     GPtrArray *date_range;
+    NautilusQueryRecursive recursive;
     NautilusQuerySearchType search_type;
     NautilusQuerySearchContent search_content;
 
     gboolean searching;
-    gboolean recursive;
     char **prepared_words;
     GMutex prepared_words_mutex;
 };
@@ -115,7 +115,7 @@ nautilus_query_get_property (GObject    *object,
 
         case PROP_RECURSIVE:
         {
-            g_value_set_boolean (value, self->recursive);
+            g_value_set_enum (value, self->recursive);
         }
         break;
 
@@ -178,7 +178,7 @@ nautilus_query_set_property (GObject      *object,
 
         case PROP_RECURSIVE:
         {
-            nautilus_query_set_recursive (self, g_value_get_boolean (value));
+            nautilus_query_set_recursive (self, g_value_get_enum (value));
         }
         break;
 
@@ -269,11 +269,12 @@ nautilus_query_class_init (NautilusQueryClass *class)
      */
     g_object_class_install_property (gobject_class,
                                      PROP_RECURSIVE,
-                                     g_param_spec_boolean ("recursive",
-                                                           "Whether the query is being performed on 
subdirectories",
-                                                           "Whether the query is being performed on 
subdirectories or not",
-                                                           FALSE,
-                                                           G_PARAM_READWRITE));
+                                     g_param_spec_enum ("recursive",
+                                                        "Whether the query is being performed on 
subdirectories",
+                                                        "Whether the query is being performed on 
subdirectories or not",
+                                                        NAUTILUS_TYPE_QUERY_RECURSIVE,
+                                                        NAUTILUS_QUERY_RECURSIVE_ALWAYS,
+                                                        G_PARAM_READWRITE));
 
     /**
      * NautilusQuery::search-type:
@@ -633,22 +634,21 @@ nautilus_query_set_searching (NautilusQuery *query,
     }
 }
 
-gboolean
+NautilusQueryRecursive
 nautilus_query_get_recursive (NautilusQuery *query)
 {
-    g_return_val_if_fail (NAUTILUS_IS_QUERY (query), FALSE);
+    g_return_val_if_fail (NAUTILUS_IS_QUERY (query),
+                          NAUTILUS_QUERY_RECURSIVE_ALWAYS);
 
     return query->recursive;
 }
 
 void
-nautilus_query_set_recursive (NautilusQuery *query,
-                              gboolean       recursive)
+nautilus_query_set_recursive (NautilusQuery          *query,
+                              NautilusQueryRecursive  recursive)
 {
     g_return_if_fail (NAUTILUS_IS_QUERY (query));
 
-    recursive = !!recursive;
-
     if (query->recursive != recursive)
     {
         query->recursive = recursive;
diff --git a/src/nautilus-query.h b/src/nautilus-query.h
index 1fda5e394..ad838c4fd 100644
--- a/src/nautilus-query.h
+++ b/src/nautilus-query.h
@@ -34,6 +34,12 @@ typedef enum {
         NAUTILUS_QUERY_SEARCH_CONTENT_FULL_TEXT,
 } NautilusQuerySearchContent;
 
+typedef enum {
+        NAUTILUS_QUERY_RECURSIVE_NEVER,
+        NAUTILUS_QUERY_RECURSIVE_ALWAYS,
+        NAUTILUS_QUERY_RECURSIVE_INDEXED_ONLY,
+} NautilusQueryRecursive;
+
 #define NAUTILUS_TYPE_QUERY            (nautilus_query_get_type ())
 
 G_DECLARE_FINAL_TYPE (NautilusQuery, nautilus_query, NAUTILUS, QUERY, GObject)
@@ -66,10 +72,9 @@ GPtrArray*     nautilus_query_get_date_range     (NautilusQuery *query);
 void           nautilus_query_set_date_range     (NautilusQuery *query,
                                                   GPtrArray     *date_range);
 
-gboolean       nautilus_query_get_recursive      (NautilusQuery *query);
-
-void           nautilus_query_set_recursive      (NautilusQuery *query,
-                                                  gboolean       recursive);
+NautilusQueryRecursive nautilus_query_get_recursive (NautilusQuery *query);
+void                   nautilus_query_set_recursive (NautilusQuery          *query,
+                                                     NautilusQueryRecursive  recursive);
 
 gboolean       nautilus_query_get_searching      (NautilusQuery *query);
 
@@ -80,4 +85,4 @@ gdouble        nautilus_query_matches_string     (NautilusQuery *query, const gc
 
 char *         nautilus_query_to_readable_string (NautilusQuery *query);
 
-gboolean       nautilus_query_is_empty           (NautilusQuery *query);
\ No newline at end of file
+gboolean       nautilus_query_is_empty           (NautilusQuery *query);
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index e56175b0c..3b5bbd597 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -1157,11 +1157,11 @@ update_search_information (NautilusWindowSlot *self)
             label = _("Searching network locations only");
         }
         else if (nautilus_file_is_remote (file) &&
-                 !location_settings_search_is_recursive (priv->location))
+                 location_settings_search_get_recursive (priv->location) == NAUTILUS_QUERY_RECURSIVE_NEVER)
         {
             label = _("Remote location — only searching the current folder");
         }
-        else if (!location_settings_search_is_recursive (priv->location))
+        else if (location_settings_search_get_recursive (priv->location) == NAUTILUS_QUERY_RECURSIVE_NEVER)
         {
             label = _("Only searching the current folder");
         }


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