[nautilus/wip/gbsneto/search-popover: 3/9] query: improve NautilusQuery code



commit bbf70a597bc750189ff28aac7a30ea241d777402
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Oct 5 21:01:35 2015 -0300

    query: improve NautilusQuery code
    
    NautilusQuery currently is designed much like an
    structure of data, making no use of all the object
    system that GLib provides.
    
    In order to prepare ground for the new search, make
    NautilusQuery work more like a real object than like
    a plain structure.

 libnautilus-private/Makefile.am                    |    5 +-
 libnautilus-private/nautilus-query.c               |  297 +++++++++++++++++++-
 libnautilus-private/nautilus-query.h               |   28 ++-
 libnautilus-private/nautilus-search-directory.c    |   22 +-
 .../nautilus-search-engine-simple.c                |    5 +-
 .../nautilus-search-engine-tracker.c               |    5 +-
 libnautilus-private/nautilus-search-hit.c          |    5 +-
 src/nautilus-list-view.c                           |    8 +-
 src/nautilus-query-editor.c                        |   29 +-
 src/nautilus-shell-search-provider.c               |    9 +-
 10 files changed, 360 insertions(+), 53 deletions(-)
---
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index 92c6014..fe6331c 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -31,7 +31,10 @@ BUILT_SOURCES =                                      \
        nautilus-private-enum-types.c                   \
        $(NULL)
 
-ENUM_TYPES = nautilus-search-provider.h
+ENUM_TYPES =                                           \
+       nautilus-query.h                                \
+       nautilus-search-provider.h
+
 
 nautilus-private-enum-types.h: nautilus-private-enum-types.h.template $(ENUM_TYPES) $(GLIB_MKENUMS)
        $(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template nautilus-private-enum-types.h.template 
$(ENUM_TYPES)) > $@
diff --git a/libnautilus-private/nautilus-query.c b/libnautilus-private/nautilus-query.c
index 285bbfe..7d87d28 100644
--- a/libnautilus-private/nautilus-query.c
+++ b/libnautilus-private/nautilus-query.c
@@ -28,12 +28,18 @@
 
 #include "nautilus-file-utilities.h"
 #include "nautilus-query.h"
+#include "nautilus-private-enum-types.h"
 
 struct _NautilusQuery {
+        GObject parent;
+
        char *text;
-       char *location_uri;
+       GFile *location;
        GList *mime_types;
        gboolean show_hidden;
+        GDateTime *datetime;
+        NautilusQuerySearchType search_type;
+        NautilusQuerySearchContent search_content;
 
        char **prepared_words;
 };
@@ -43,6 +49,17 @@ static void  nautilus_query_init             (NautilusQuery      *query);
 
 G_DEFINE_TYPE (NautilusQuery, nautilus_query, G_TYPE_OBJECT);
 
+enum {
+        PROP_0,
+        PROP_DATE,
+        PROP_LOCATION,
+        PROP_MIMETYPES,
+        PROP_SEARCH_TYPE,
+        PROP_SHOW_HIDDEN,
+        PROP_TEXT,
+        LAST_PROP
+};
+
 static void
 finalize (GObject *object)
 {
@@ -52,25 +69,190 @@ finalize (GObject *object)
 
         g_free (query->text);
         g_strfreev (query->prepared_words);
-        g_free (query->location_uri);
+        g_clear_object (&query->location);
+        g_clear_pointer (&query->datetime, g_date_time_unref);
 
        G_OBJECT_CLASS (nautilus_query_parent_class)->finalize (object);
 }
 
 static void
+nautilus_query_get_property (GObject    *object,
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
+{
+        NautilusQuery *self = NAUTILUS_QUERY (object);
+
+        switch (prop_id) {
+        case PROP_DATE:
+                g_value_set_boxed (value, self->datetime);
+                break;
+
+        case PROP_LOCATION:
+                g_value_set_object (value, self->location);
+                break;
+
+        case PROP_MIMETYPES:
+                g_value_set_pointer (value, self->mime_types);
+                break;
+
+        case PROP_SEARCH_TYPE:
+                g_value_set_enum (value, self->search_type);
+                break;
+
+        case PROP_SHOW_HIDDEN:
+                g_value_set_boolean (value, self->show_hidden);
+                break;
+
+        case PROP_TEXT:
+                g_value_set_string (value, self->text);
+                break;
+
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        }
+}
+
+static void
+nautilus_query_set_property (GObject      *object,
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
+{
+        NautilusQuery *self = NAUTILUS_QUERY (object);
+
+        switch (prop_id) {
+        case PROP_DATE:
+                nautilus_query_set_date (self, g_value_get_boxed (value));
+                break;
+
+        case PROP_LOCATION:
+                nautilus_query_set_location (self, g_value_get_object (value));
+                break;
+
+        case PROP_MIMETYPES:
+                nautilus_query_set_mime_types (self, g_value_get_pointer (value));
+                break;
+
+        case PROP_SEARCH_TYPE:
+                nautilus_query_set_search_type (self, g_value_get_enum (value));
+                break;
+
+        case PROP_SHOW_HIDDEN:
+                nautilus_query_set_show_hidden_files (self, g_value_get_boolean (value));
+                break;
+
+        case PROP_TEXT:
+                nautilus_query_set_text (self, g_value_get_string (value));
+                break;
+
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        }
+}
+
+static void
 nautilus_query_class_init (NautilusQueryClass *class)
 {
        GObjectClass *gobject_class;
 
        gobject_class = G_OBJECT_CLASS (class);
        gobject_class->finalize = finalize;
+        gobject_class->get_property = nautilus_query_get_property;
+        gobject_class->set_property = nautilus_query_set_property;
+
+        /**
+         * NautilusQuery::date:
+         *
+         * The initial date of the query.
+         *
+         */
+        g_object_class_install_property (gobject_class,
+                                         PROP_DATE,
+                                         g_param_spec_boxed ("date",
+                                                             "Date of the query",
+                                                             "The initial date of the query",
+                                                             G_TYPE_DATE_TIME,
+                                                             G_PARAM_READWRITE));
+
+        /**
+         * NautilusQuery::location:
+         *
+         * The location of the query.
+         *
+         */
+        g_object_class_install_property (gobject_class,
+                                         PROP_LOCATION,
+                                         g_param_spec_object ("location",
+                                                              "Location of the query",
+                                                              "The location of the query",
+                                                              G_TYPE_FILE,
+                                                              G_PARAM_READWRITE));
+
+        /**
+         * NautilusQuery::mimetypes:
+         *
+         * MIME types the query holds.
+         *
+         */
+        g_object_class_install_property (gobject_class,
+                                         PROP_MIMETYPES,
+                                         g_param_spec_pointer ("mimetypes",
+                                                               "MIME types of the query",
+                                                               "The MIME types of the query",
+                                                               G_PARAM_READWRITE));
+
+        /**
+         * NautilusQuery::search-type:
+         *
+         * The search type of the query.
+         *
+         */
+        g_object_class_install_property (gobject_class,
+                                         PROP_SEARCH_TYPE,
+                                         g_param_spec_enum ("search-type",
+                                                            "Type of the query",
+                                                            "The type of the query",
+                                                            NAUTILUS_TYPE_QUERY_SEARCH_TYPE,
+                                                            NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED,
+                                                            G_PARAM_READWRITE));
+
+        /**
+         * NautilusQuery::show-hidden:
+         *
+         * Whether the search should include hidden files.
+         *
+         */
+        g_object_class_install_property (gobject_class,
+                                         PROP_SHOW_HIDDEN,
+                                         g_param_spec_boolean ("show-hidden",
+                                                               "Show hidden files",
+                                                               "Whether the search should show hidden files",
+                                                               FALSE,
+                                                               G_PARAM_READWRITE));
+
+        /**
+         * NautilusQuery::text:
+         *
+         * The search string.
+         *
+         */
+        g_object_class_install_property (gobject_class,
+                                         PROP_TEXT,
+                                         g_param_spec_string ("text",
+                                                              "Text of the search",
+                                                              "The text string of the search",
+                                                              NULL,
+                                                              G_PARAM_READWRITE));
 }
 
 static void
 nautilus_query_init (NautilusQuery *query)
 {
         query->show_hidden = TRUE;
-        query->location_uri = nautilus_get_home_directory_uri ();
+        query->location = g_file_new_for_path (g_get_home_dir ());
+        query->search_type = NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED;
+        query->search_content = NAUTILUS_QUERY_SEARCH_CONTENT_SIMPLE;
 }
 
 static gchar *
@@ -139,61 +321,91 @@ nautilus_query_new (void)
 char *
 nautilus_query_get_text (NautilusQuery *query)
 {
+        g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NULL);
+
         return g_strdup (query->text);
 }
 
 void 
 nautilus_query_set_text (NautilusQuery *query, const char *text)
 {
+        g_return_if_fail (NAUTILUS_IS_QUERY (query));
+
         g_free (query->text);
         query->text = g_strstrip (g_strdup (text));
 
         g_strfreev (query->prepared_words);
         query->prepared_words = NULL;
+
+        g_object_notify (G_OBJECT (query), "text");
 }
 
-char *
+GFile*
 nautilus_query_get_location (NautilusQuery *query)
 {
-        return g_strdup (query->location_uri);
+        g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NULL);
+
+        return g_object_ref (query->location);
 }
-       
+
 void
-nautilus_query_set_location (NautilusQuery *query, const char *uri)
+nautilus_query_set_location (NautilusQuery *query,
+                             GFile         *location)
 {
-        g_free (query->location_uri);
-        query->location_uri = g_strdup (uri);
+        g_return_if_fail (NAUTILUS_IS_QUERY (query));
+
+        if (g_set_object (&query->location, location)) {
+                g_object_notify (G_OBJECT (query), "location");
+        }
+
 }
 
 GList *
 nautilus_query_get_mime_types (NautilusQuery *query)
 {
+        g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NULL);
+
         return g_list_copy_deep (query->mime_types, (GCopyFunc) g_strdup, NULL);
 }
 
 void
 nautilus_query_set_mime_types (NautilusQuery *query, GList *mime_types)
 {
+        g_return_if_fail (NAUTILUS_IS_QUERY (query));
+
         g_list_free_full (query->mime_types, g_free);
         query->mime_types = g_list_copy_deep (mime_types, (GCopyFunc) g_strdup, NULL);
+
+        g_object_notify (G_OBJECT (query), "mimetypes");
 }
 
 void
 nautilus_query_add_mime_type (NautilusQuery *query, const char *mime_type)
 {
+        g_return_if_fail (NAUTILUS_IS_QUERY (query));
+
         query->mime_types = g_list_append (query->mime_types, g_strdup (mime_type));
+
+        g_object_notify (G_OBJECT (query), "mimetypes");
 }
 
 gboolean
 nautilus_query_get_show_hidden_files (NautilusQuery *query)
 {
+        g_return_val_if_fail (NAUTILUS_IS_QUERY (query), FALSE);
+
         return query->show_hidden;
 }
 
 void
 nautilus_query_set_show_hidden_files (NautilusQuery *query, gboolean show_hidden)
 {
-        query->show_hidden = show_hidden;
+        g_return_if_fail (NAUTILUS_IS_QUERY (query));
+
+        if (query->show_hidden != show_hidden) {
+                query->show_hidden = show_hidden;
+                g_object_notify (G_OBJECT (query), "show-hidden");
+        }
 }
 
 char *
@@ -205,3 +417,68 @@ nautilus_query_to_readable_string (NautilusQuery *query)
 
         return g_strdup_printf (_("Search for ā€œ%sā€"), query->text);
 }
+
+NautilusQuerySearchContent
+nautilus_query_get_search_content (NautilusQuery *query)
+{
+        g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NAUTILUS_QUERY_SEARCH_CONTENT_SIMPLE);
+
+        return query->search_content;
+}
+
+void
+nautilus_query_set_search_content (NautilusQuery              *query,
+                                   NautilusQuerySearchContent  content)
+{
+        g_return_if_fail (NAUTILUS_IS_QUERY (query));
+
+        if (query->search_content != content) {
+                query->search_content = content;
+                g_object_notify (G_OBJECT (query), "search-type");
+        }
+}
+
+NautilusQuerySearchType
+nautilus_query_get_search_type (NautilusQuery *query)
+{
+        g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED);
+
+        return query->search_type;
+}
+
+void
+nautilus_query_set_search_type (NautilusQuery           *query,
+                                NautilusQuerySearchType  type)
+{
+        g_return_if_fail (NAUTILUS_IS_QUERY (query));
+
+        if (query->search_type != type) {
+                query->search_type = type;
+                g_object_notify (G_OBJECT (query), "search-type");
+        }
+}
+
+GDateTime*
+nautilus_query_get_date (NautilusQuery *query)
+{
+        g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NULL);
+
+        return query->datetime;
+}
+
+void
+nautilus_query_set_date (NautilusQuery *query,
+                         GDateTime     *date)
+{
+        g_return_if_fail (NAUTILUS_IS_QUERY (query));
+
+        if (query->datetime != date) {
+                g_clear_pointer (&query->datetime, g_date_time_unref);
+                if (date) {
+                        /* Assign the new date */
+                        query->datetime = g_date_time_ref (date);
+                }
+
+                g_object_notify (G_OBJECT (query), "date");
+        }
+}
diff --git a/libnautilus-private/nautilus-query.h b/libnautilus-private/nautilus-query.h
index df3e473..71a9cdb 100644
--- a/libnautilus-private/nautilus-query.h
+++ b/libnautilus-private/nautilus-query.h
@@ -24,6 +24,17 @@
 #define NAUTILUS_QUERY_H
 
 #include <glib-object.h>
+#include <gio/gio.h>
+
+typedef enum {
+        NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS,
+        NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED
+} NautilusQuerySearchType;
+
+typedef enum {
+        NAUTILUS_QUERY_SEARCH_CONTENT_SIMPLE,
+        NAUTILUS_QUERY_SEARCH_CONTENT_FULL_TEXT,
+} NautilusQuerySearchContent;
 
 #define NAUTILUS_TYPE_QUERY            (nautilus_query_get_type ())
 
@@ -37,13 +48,26 @@ void           nautilus_query_set_text           (NautilusQuery *query, const ch
 gboolean       nautilus_query_get_show_hidden_files (NautilusQuery *query);
 void           nautilus_query_set_show_hidden_files (NautilusQuery *query, gboolean show_hidden);
 
-char *         nautilus_query_get_location       (NautilusQuery *query);
-void           nautilus_query_set_location       (NautilusQuery *query, const char *uri);
+GFile*         nautilus_query_get_location       (NautilusQuery *query);
+void           nautilus_query_set_location       (NautilusQuery *query,
+                                                  GFile         *location);
 
 GList *        nautilus_query_get_mime_types     (NautilusQuery *query);
 void           nautilus_query_set_mime_types     (NautilusQuery *query, GList *mime_types);
 void           nautilus_query_add_mime_type      (NautilusQuery *query, const char *mime_type);
 
+NautilusQuerySearchContent nautilus_query_get_search_content (NautilusQuery *query);
+void                       nautilus_query_set_search_content (NautilusQuery              *query,
+                                                              NautilusQuerySearchContent  content);
+
+NautilusQuerySearchType nautilus_query_get_search_type (NautilusQuery *query);
+void                    nautilus_query_set_search_type (NautilusQuery           *query,
+                                                        NautilusQuerySearchType  type);
+
+GDateTime*     nautilus_query_get_date           (NautilusQuery *query);
+void           nautilus_query_set_date           (NautilusQuery *query,
+                                                  GDateTime     *date);
+
 gdouble        nautilus_query_matches_string     (NautilusQuery *query, const gchar *string);
 
 char *         nautilus_query_to_readable_string (NautilusQuery *query);
diff --git a/libnautilus-private/nautilus-search-directory.c b/libnautilus-private/nautilus-search-directory.c
index 5de492f..10b5525 100644
--- a/libnautilus-private/nautilus-search-directory.c
+++ b/libnautilus-private/nautilus-search-directory.c
@@ -871,19 +871,16 @@ nautilus_search_directory_set_base_model (NautilusSearchDirectory *search,
        }
 
        if (search->details->query != NULL) {
-               gchar *uri;
                GFile *query_location, *model_location;
                gboolean is_equal;
 
-               uri = nautilus_query_get_location (search->details->query);
-               query_location = g_file_new_for_uri (uri);
+                query_location = nautilus_query_get_location (search->details->query);
                model_location = nautilus_directory_get_location (base_model);
 
                is_equal = g_file_equal (model_location, query_location);
 
                g_object_unref (model_location);
                g_object_unref (query_location);
-               g_free (uri);
 
                if (!is_equal) {
                        return;
@@ -924,11 +921,20 @@ nautilus_search_directory_set_query (NautilusSearchDirectory *search,
                                     NautilusQuery *query)
 {
        NautilusFile *file;
+        NautilusQuery *old_query;
+
+        old_query = search->details->query;
+
+       if (g_set_object (&search->details->query, query)) {
+                /* Disconnect from the previous query changes */
+                if (old_query) {
+                        g_signal_handlers_disconnect_by_func (old_query, search_force_reload, search);
+                }
+
+                if (query) {
+                        g_signal_connect_swapped (query, "notify", G_CALLBACK (search_force_reload), search);
+                }
 
-       if (search->details->query != query) {
-               g_object_ref (query);
-               g_clear_object (&search->details->query);
-               search->details->query = query;
 
                g_object_notify_by_pspec (G_OBJECT (search), properties[PROP_QUERY]);
        }
diff --git a/libnautilus-private/nautilus-search-engine-simple.c 
b/libnautilus-private/nautilus-search-engine-simple.c
index 33180fb..f3557d6 100644
--- a/libnautilus-private/nautilus-search-engine-simple.c
+++ b/libnautilus-private/nautilus-search-engine-simple.c
@@ -93,7 +93,6 @@ search_thread_data_new (NautilusSearchEngineSimple *engine,
                        NautilusQuery *query)
 {
        SearchThreadData *data;
-       char *uri;
        GFile *location;
        
        data = g_new0 (SearchThreadData, 1);
@@ -103,9 +102,7 @@ search_thread_data_new (NautilusSearchEngineSimple *engine,
        data->visited = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
        data->query = g_object_ref (query);
 
-       uri = nautilus_query_get_location (query);
-       location = g_file_new_for_uri (uri);
-       g_free (uri);
+       location = nautilus_query_get_location (query);
 
        g_queue_push_tail (data->directories, location);
        data->mime_types = nautilus_query_get_mime_types (query);
diff --git a/libnautilus-private/nautilus-search-engine-tracker.c 
b/libnautilus-private/nautilus-search-engine-tracker.c
index 6120448..7b0f801 100644
--- a/libnautilus-private/nautilus-search-engine-tracker.c
+++ b/libnautilus-private/nautilus-search-engine-tracker.c
@@ -250,6 +250,7 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
 {
        NautilusSearchEngineTracker *tracker;
        gchar   *query_text, *search_text, *location_uri, *downcase;
+        GFile *location;
        GString *sparql;
        GList *mimetypes, *l;
        gint mime_count;
@@ -279,7 +280,8 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
        g_free (query_text);
        g_free (downcase);
 
-       location_uri = nautilus_query_get_location (tracker->details->query);
+        location = nautilus_query_get_location (tracker->details->query);
+       location_uri = location ? g_file_get_uri (location) : NULL;
        mimetypes = nautilus_query_get_mime_types (tracker->details->query);
 
        mime_count = g_list_length (mimetypes);
@@ -330,6 +332,7 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
        g_free (search_text);
        g_free (location_uri);
        g_list_free_full (mimetypes, g_free);
+        g_object_unref (location);
 }
 
 static void
diff --git a/libnautilus-private/nautilus-search-hit.c b/libnautilus-private/nautilus-search-hit.c
index a6dc16c..7870437 100644
--- a/libnautilus-private/nautilus-search-hit.c
+++ b/libnautilus-private/nautilus-search-hit.c
@@ -55,7 +55,6 @@ nautilus_search_hit_compute_scores (NautilusSearchHit *hit,
                                    NautilusQuery     *query)
 {
        GDateTime *now;
-       char *query_uri;
        GFile *query_location;
        GFile *hit_location;
        GTimeSpan m_diff = G_MAXINT64;
@@ -65,8 +64,7 @@ nautilus_search_hit_compute_scores (NautilusSearchHit *hit,
        gdouble proximity_bonus = 0.0;
        gdouble match_bonus = 0.0;
 
-       query_uri = nautilus_query_get_location (query);
-       query_location = g_file_new_for_uri (query_uri);
+       query_location = nautilus_query_get_location (query);
        hit_location = g_file_new_for_uri (hit->details->uri);
 
        if (g_file_has_prefix (hit_location, query_location)) {
@@ -122,7 +120,6 @@ nautilus_search_hit_compute_scores (NautilusSearchHit *hit,
               proximity_bonus, recent_bonus, match_bonus);
 
        g_date_time_unref (now);
-       g_free (query_uri);
        g_object_unref (query_location);
 }
 
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index a0377da..5a729be 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -1463,12 +1463,12 @@ location_cell_data_func (GtkTreeViewColumn *column,
                base_location = g_object_ref (home_location);
        } else {
                NautilusQuery *query;
-               gchar *base_uri;
                NautilusFile *base;
+                GFile *location;
 
                query = nautilus_search_directory_get_query (NAUTILUS_SEARCH_DIRECTORY (directory));
-               base_uri = nautilus_query_get_location (query);
-               base = nautilus_file_get_by_uri (base_uri);
+                location = nautilus_query_get_location (query);
+               base = nautilus_file_get (location);
 
                if (!nautilus_file_is_in_recent (base)) {
                        base_location = nautilus_file_get_location (base);
@@ -1477,7 +1477,7 @@ location_cell_data_func (GtkTreeViewColumn *column,
                }
 
                nautilus_file_unref (base);
-               g_free (base_uri);
+                g_object_unref (location);
                g_object_unref (query);
        }
 
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index c0e24b6..841e9da 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -64,7 +64,7 @@ struct NautilusQueryEditorDetails {
 
        GtkWidget *search_current_button;
        GtkWidget *search_all_button;
-       char *current_uri;
+        GFile *current_location;
 
        GList *rows;
 
@@ -243,8 +243,8 @@ GFile *
 nautilus_query_editor_get_location (NautilusQueryEditor *editor)
 {
        GFile *file = NULL;
-       if (editor->details->current_uri != NULL)
-               file = g_file_new_for_uri (editor->details->current_uri);
+        if (editor->details->current_location != NULL)
+                file = g_object_ref (editor->details->current_location);
        return file;
 }
 
@@ -1007,16 +1007,16 @@ static void
 add_location_to_query (NautilusQueryEditor *editor,
                       NautilusQuery       *query)
 {
-       char *uri;
+        GFile *location;
 
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->details->search_all_button))) {
-               uri = nautilus_get_home_directory_uri ();
+               location = g_file_new_for_uri (nautilus_get_home_directory_uri ());
        } else {
-               uri = g_strdup (editor->details->current_uri);
+                location = nautilus_query_editor_get_location (editor);
        }
 
-       nautilus_query_set_location (query, uri);
-       g_free (uri);
+       nautilus_query_set_location (query, location);
+       g_clear_object (&location);
 }
 
 NautilusQuery *
@@ -1064,7 +1064,7 @@ update_location (NautilusQueryEditor *editor)
        NautilusFile *file;
        GtkWidget *label;
 
-       file = nautilus_file_get_by_uri (editor->details->current_uri);
+        file = nautilus_file_get (editor->details->current_location);
 
        if (file != NULL) {
                char *name;
@@ -1092,7 +1092,7 @@ nautilus_query_editor_set_location (NautilusQueryEditor *editor,
         NautilusDirectory *directory;
         NautilusDirectory *base_model;
 
-       g_free (editor->details->current_uri);
+       g_clear_object (&editor->details->current_location);
 
         /* The client could set us a location that is actually a search directory,
          * like what happens with the slot when updating the query editor location.
@@ -1101,9 +1101,9 @@ nautilus_query_editor_set_location (NautilusQueryEditor *editor,
         directory = nautilus_directory_get (location);
         if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
                 base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY 
(directory));
-                editor->details->current_uri = nautilus_directory_get_uri (base_model);
+                editor->details->current_location = nautilus_directory_get_location (base_model);
         } else {
-                editor->details->current_uri = g_file_get_uri (location);
+                editor->details->current_location = g_object_ref (location);
         }
        update_location (editor);
 
@@ -1152,15 +1152,14 @@ nautilus_query_editor_set_query (NautilusQueryEditor    *editor,
        }
        g_free (current_text);
 
-       g_free (editor->details->current_uri);
-       editor->details->current_uri = NULL;
+        g_clear_object (&editor->details->current_location);
 
        update_rows (editor, query);
        g_clear_object (&editor->details->query);
 
        if (query != NULL) {
                editor->details->query = g_object_ref (query);
-               editor->details->current_uri = nautilus_query_get_location (query);
+               editor->details->current_location = nautilus_query_get_location (query);
                update_location (editor);
        }
 
diff --git a/src/nautilus-shell-search-provider.c b/src/nautilus-shell-search-provider.c
index a2b596d..b7aadd3 100644
--- a/src/nautilus-shell-search-provider.c
+++ b/src/nautilus-shell-search-provider.c
@@ -393,9 +393,10 @@ execute_search (NautilusShellSearchProvider *self,
                 GDBusMethodInvocation          *invocation,
                 gchar                         **terms)
 {
-  gchar *terms_joined, *home_uri;
+  gchar *terms_joined;
   NautilusQuery *query;
   PendingSearch *pending_search;
+  GFile *home;
 
   cancel_current_search (self);
 
@@ -407,12 +408,12 @@ execute_search (NautilusShellSearchProvider *self,
   }
 
   terms_joined = g_strjoinv (" ", terms);
-  home_uri = nautilus_get_home_directory_uri ();
+  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_text (query, terms_joined);
-  nautilus_query_set_location (query, home_uri);
+  nautilus_query_set_location (query, home);
 
   pending_search = g_slice_new0 (PendingSearch);
   pending_search->invocation = g_object_ref (invocation);
@@ -440,7 +441,7 @@ execute_search (NautilusShellSearchProvider *self,
                                       query);
   nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (pending_search->engine));
 
-  g_free (home_uri);
+  g_clear_object (&home);
   g_free (terms_joined);
 }
 


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