[nautilus] search-engine: toggle recursive search with a gsetting



commit 70adcc4c07ccae7bbfd38e54fa50b0cfa6e9e75c
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue May 19 13:25:45 2015 -0300

    search-engine: toggle recursive search with a gsetting
    
    One of the features of the new search ui design is that it will have a
    switch allowing the search to be recursive or not. These changes make
    it possible to enable/disable the recursive search within a gsetting.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=749588

 libnautilus-private/nautilus-search-directory.c    |    6 ++++-
 .../nautilus-search-engine-tracker.c               |   22 +++++++++++++++----
 .../org.gnome.nautilus.gschema.xml.in              |    5 ++++
 3 files changed, 27 insertions(+), 6 deletions(-)
---
diff --git a/libnautilus-private/nautilus-search-directory.c b/libnautilus-private/nautilus-search-directory.c
index 788faaf..281694f 100644
--- a/libnautilus-private/nautilus-search-directory.c
+++ b/libnautilus-private/nautilus-search-directory.c
@@ -142,6 +142,8 @@ start_search (NautilusSearchDirectory *search)
 {
        NautilusSearchEngineModel *model_provider;
        NautilusSearchEngineSimple *simple_provider;
+       GSettings *nautilus_preferences;
+       gboolean recursive;
 
        if (!search->details->query) {
                return;
@@ -167,7 +169,9 @@ start_search (NautilusSearchDirectory *search)
        nautilus_search_engine_model_set_model (model_provider, search->details->base_model);
 
        simple_provider = nautilus_search_engine_get_simple_provider (search->details->engine);
-       g_object_set (simple_provider, "recursive", TRUE, NULL);
+       nautilus_preferences = g_settings_new ("org.gnome.nautilus.preferences");
+       recursive = g_settings_get_boolean (nautilus_preferences, "enable-recursive-search");
+       g_object_set (simple_provider, "recursive", recursive, NULL);
 
        reset_file_list (search);
 
diff --git a/libnautilus-private/nautilus-search-engine-tracker.c 
b/libnautilus-private/nautilus-search-engine-tracker.c
index c53810c..0244d3b 100644
--- a/libnautilus-private/nautilus-search-engine-tracker.c
+++ b/libnautilus-private/nautilus-search-engine-tracker.c
@@ -36,6 +36,8 @@ struct NautilusSearchEngineTrackerDetails {
        gboolean       query_pending;
        GQueue        *hits_pending;
 
+       gboolean       recursive;
+
        GCancellable  *cancellable;
 };
 
@@ -234,6 +236,8 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
        GString *sparql;
        GList *mimetypes, *l;
        gint mime_count;
+       GSettings *nautilus_preferences;
+       gboolean recursive;
 
        tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (provider);
 
@@ -249,6 +253,10 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
                return;
        }
 
+       nautilus_preferences = g_settings_new ("org.gnome.nautilus.preferences");
+       recursive = g_settings_get_boolean (nautilus_preferences, "enable-recursive-search");
+       tracker->details->recursive = recursive;
+
        query_text = nautilus_query_get_text (tracker->details->query);
        downcase = g_utf8_strdown (query_text, -1);
        search_text = tracker_sparql_escape_string (downcase);
@@ -269,11 +277,15 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
                g_string_append (sparql, "nie:mimeType ?mime ;");
        }
 
-       g_string_append_printf (sparql,
-                               " fts:match '\"%s*\"' . FILTER ("
-                               " tracker:uri-is-descendant('%s', nie:url(?urn)) &&"
-                               " fn:contains(fn:lower-case(nfo:fileName(?urn)), '%s')",
-                               search_text, location_uri, search_text);
+       g_string_append_printf (sparql, " fts:match '\"%s*\"' . FILTER ( ", search_text);
+
+       if (!tracker->details->recursive) {
+               g_string_append_printf (sparql, "tracker:uri-is-parent('%s', nie:url(?urn)) && ", 
location_uri);
+       } else {
+               g_string_append_printf (sparql, "tracker:uri-is-descendant('%s', nie:url(?urn)) && ", 
location_uri);
+       }
+
+       g_string_append_printf (sparql, "fn:contains(fn:lower-case(nfo:fileName(?urn)), '%s')", search_text);
 
        if (mime_count > 0) {
                g_string_append (sparql, " && (");
diff --git a/libnautilus-private/org.gnome.nautilus.gschema.xml.in 
b/libnautilus-private/org.gnome.nautilus.gschema.xml.in
index 701847d..6571904 100644
--- a/libnautilus-private/org.gnome.nautilus.gschema.xml.in
+++ b/libnautilus-private/org.gnome.nautilus.gschema.xml.in
@@ -70,6 +70,11 @@
       <_summary>Always use the location entry, instead of the pathbar</_summary>
       <_description>If set to true, then Nautilus browser windows will always use a textual input entry for 
the location toolbar, instead of the pathbar.</_description>
     </key>
+    <key name="enable-recursive-search" type="b">
+      <default>true</default>
+      <_summary>Whether to enable recursive search or not</_summary>
+      <_description>Enables or disables recursive search in Nautilus.</_description>
+    </key>
     <key name="confirm-trash" type="b">
       <default>true</default>
       <_summary>Whether to ask for confirmation when deleting files, or emptying Trash</_summary>


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