summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2015-10-02 21:45:08 -0300
committerCarlos Soriano <csoriano@gnome.org>2016-02-02 20:43:04 +0100
commit2e72a3a0f3de75f2df5943133e8d70a4ba0aa3fa (patch)
tree16144a5d311758e69718f2795195d5ec84d5a0dc
parent80f8cba48921f7fbed5979c610a85fed2457a74b (diff)
downloadnautilus-2e72a3a0f3de75f2df5943133e8d70a4ba0aa3fa.tar.gz
query: make NautilusQuery a final class
NautilusQuery handle all the necessary data to perform searches throughout directories. Currently, there is no NautilusQuery subclass in Nautilus code, and - since it's inside libnautilus-private - there is no way to subclass it. This commit updates NautilusQuery code be a final class.
-rw-r--r--libnautilus-private/Makefile.am5
-rw-r--r--libnautilus-private/nautilus-query.c459
-rw-r--r--libnautilus-private/nautilus-query.h56
-rw-r--r--libnautilus-private/nautilus-search-directory.c22
-rw-r--r--libnautilus-private/nautilus-search-engine-simple.c5
-rw-r--r--libnautilus-private/nautilus-search-engine-tracker.c5
-rw-r--r--libnautilus-private/nautilus-search-hit.c5
-rw-r--r--src/nautilus-list-view.c8
-rw-r--r--src/nautilus-query-editor.c29
-rw-r--r--src/nautilus-shell-search-provider.c9
10 files changed, 506 insertions, 97 deletions
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index 166744df6..ea7315bd6 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 fb7bd487d..b95c631b0 100644
--- a/libnautilus-private/nautilus-query.c
+++ b/libnautilus-private/nautilus-query.c
@@ -28,13 +28,21 @@
#include "nautilus-file-utilities.h"
#include "nautilus-query.h"
+#include "nautilus-private-enum-types.h"
+
+struct _NautilusQuery {
+ GObject parent;
-struct NautilusQueryDetails {
char *text;
- char *location_uri;
+ GFile *location;
GList *mime_types;
gboolean show_hidden;
+ GDateTime *datetime;
+ NautilusQuerySearchType search_type;
+ NautilusQuerySearchContent search_content;
+ gboolean searching;
+ gboolean recursive;
char **prepared_words;
};
@@ -43,37 +51,255 @@ 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_RECURSIVE,
+ PROP_SEARCH_TYPE,
+ PROP_SEARCHING,
+ PROP_SHOW_HIDDEN,
+ PROP_TEXT,
+ LAST_PROP
+};
+
static void
finalize (GObject *object)
{
NautilusQuery *query;
query = NAUTILUS_QUERY (object);
- g_free (query->details->text);
- g_strfreev (query->details->prepared_words);
- g_free (query->details->location_uri);
+
+ g_free (query->text);
+ g_strfreev (query->prepared_words);
+ 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_RECURSIVE:
+ g_value_set_boolean (value, self->recursive);
+ break;
+
+ case PROP_SEARCH_TYPE:
+ g_value_set_enum (value, self->search_type);
+ break;
+
+ case PROP_SEARCHING:
+ g_value_set_boolean (value, self->searching);
+ 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_RECURSIVE:
+ nautilus_query_set_recursive (self, g_value_get_boolean (value));
+ break;
+
+ case PROP_SEARCH_TYPE:
+ nautilus_query_set_search_type (self, g_value_get_enum (value));
+ break;
+
+ case PROP_SEARCHING:
+ nautilus_query_set_searching (self, g_value_get_boolean (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;
-
- g_type_class_add_private (class, sizeof (NautilusQueryDetails));
+ 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::recursive:
+ *
+ * Whether the query is being performed on subdirectories or not.
+ *
+ */
+ 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));
+
+ /**
+ * 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::searching:
+ *
+ * Whether the query is being performed or not.
+ *
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_SEARCHING,
+ g_param_spec_boolean ("searching",
+ "Whether the query is being performed",
+ "Whether the query is being performed or not",
+ FALSE,
+ 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->details = G_TYPE_INSTANCE_GET_PRIVATE (query, NAUTILUS_TYPE_QUERY,
- NautilusQueryDetails);
- query->details->show_hidden = TRUE;
- query->details->location_uri = nautilus_get_home_directory_uri ();
+ query->show_hidden = TRUE;
+ 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 *
@@ -97,13 +323,13 @@ nautilus_query_matches_string (NautilusQuery *query,
gdouble retval;
gint idx, nonexact_malus;
- if (!query->details->text) {
+ if (!query->text) {
return -1;
}
- if (!query->details->prepared_words) {
- prepared_string = prepare_string_for_compare (query->details->text);
- query->details->prepared_words = g_strsplit (prepared_string, " ", -1);
+ if (!query->prepared_words) {
+ prepared_string = prepare_string_for_compare (query->text);
+ query->prepared_words = g_strsplit (prepared_string, " ", -1);
g_free (prepared_string);
}
@@ -112,13 +338,13 @@ nautilus_query_matches_string (NautilusQuery *query,
ptr = NULL;
nonexact_malus = 0;
- for (idx = 0; query->details->prepared_words[idx] != NULL; idx++) {
- if ((ptr = strstr (prepared_string, query->details->prepared_words[idx])) == NULL) {
+ for (idx = 0; query->prepared_words[idx] != NULL; idx++) {
+ if ((ptr = strstr (prepared_string, query->prepared_words[idx])) == NULL) {
found = FALSE;
break;
}
- nonexact_malus += strlen (ptr) - strlen (query->details->prepared_words[idx]);
+ nonexact_malus += strlen (ptr) - strlen (query->prepared_words[idx]);
}
if (!found) {
@@ -142,70 +368,227 @@ nautilus_query_new (void)
char *
nautilus_query_get_text (NautilusQuery *query)
{
- return g_strdup (query->details->text);
+ 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_free (query->details->text);
- query->details->text = g_strstrip (g_strdup (text));
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
+
+ g_free (query->text);
+ query->text = g_strstrip (g_strdup (text));
- g_strfreev (query->details->prepared_words);
- query->details->prepared_words = NULL;
+ 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->details->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->details->location_uri);
- query->details->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)
{
- return g_list_copy_deep (query->details->mime_types, (GCopyFunc) g_strdup, NULL);
+ 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_list_free_full (query->details->mime_types, g_free);
- query->details->mime_types = g_list_copy_deep (mime_types, (GCopyFunc) g_strdup, NULL);
+ 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)
{
- query->details->mime_types = g_list_append (query->details->mime_types,
- g_strdup (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)
{
- return query->details->show_hidden;
+ 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->details->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 *
nautilus_query_to_readable_string (NautilusQuery *query)
{
- if (!query || !query->details->text || query->details->text[0] == '\0') {
+ if (!query || !query->text || query->text[0] == '\0') {
return g_strdup (_("Search"));
}
- return g_strdup_printf (_("Search for ā€œ%sā€"), query->details->text);
+ 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");
+ }
+}
+
+gboolean
+nautilus_query_get_searching (NautilusQuery *query)
+{
+ g_return_val_if_fail (NAUTILUS_IS_QUERY (query), FALSE);
+
+ return query->searching;
+}
+
+void
+nautilus_query_set_searching (NautilusQuery *query,
+ gboolean searching)
+{
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
+
+ searching = !!searching;
+
+ if (query->searching != searching) {
+ query->searching = searching;
+
+ g_object_notify (G_OBJECT (query), "searching");
+ }
+}
+
+gboolean
+nautilus_query_get_recursive (NautilusQuery *query)
+{
+ g_return_val_if_fail (NAUTILUS_IS_QUERY (query), FALSE);
+
+ return query->recursive;
+}
+
+void
+nautilus_query_set_recursive (NautilusQuery *query,
+ gboolean recursive)
+{
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
+
+ recursive = !!recursive;
+
+ if (query->recursive != recursive) {
+ query->recursive = recursive;
+
+ g_object_notify (G_OBJECT (query), "recursive");
+ }
+}
+
+gboolean
+nautilus_query_is_empty (NautilusQuery *query)
+{
+ if (!query) {
+ return TRUE;
+ }
+
+ if (!query->datetime &&
+ (!query->text ||
+ (query->text && query->text[0] == '\0')) &&
+ !query->mime_types) {
+ return TRUE;
+ }
+
+ return FALSE;
}
diff --git a/libnautilus-private/nautilus-query.h b/libnautilus-private/nautilus-query.h
index 9ceffe839..b21d4926f 100644
--- a/libnautilus-private/nautilus-query.h
+++ b/libnautilus-private/nautilus-query.h
@@ -24,26 +24,21 @@
#define NAUTILUS_QUERY_H
#include <glib-object.h>
+#include <gio/gio.h>
-#define NAUTILUS_TYPE_QUERY (nautilus_query_get_type ())
-#define NAUTILUS_QUERY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_QUERY, NautilusQuery))
-#define NAUTILUS_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_QUERY, NautilusQueryClass))
-#define NAUTILUS_IS_QUERY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_QUERY))
-#define NAUTILUS_IS_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_QUERY))
-#define NAUTILUS_QUERY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_QUERY, NautilusQueryClass))
-
-typedef struct NautilusQueryDetails NautilusQueryDetails;
+typedef enum {
+ NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS,
+ NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED
+} NautilusQuerySearchType;
-typedef struct NautilusQuery {
- GObject parent;
- NautilusQueryDetails *details;
-} NautilusQuery;
+typedef enum {
+ NAUTILUS_QUERY_SEARCH_CONTENT_SIMPLE,
+ NAUTILUS_QUERY_SEARCH_CONTENT_FULL_TEXT,
+} NautilusQuerySearchContent;
-typedef struct {
- GObjectClass parent_class;
-} NautilusQueryClass;
+#define NAUTILUS_TYPE_QUERY (nautilus_query_get_type ())
-GType nautilus_query_get_type (void);
+G_DECLARE_FINAL_TYPE (NautilusQuery, nautilus_query, NAUTILUS, QUERY, GObject)
NautilusQuery* nautilus_query_new (void);
@@ -53,15 +48,40 @@ 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);
+
+gboolean nautilus_query_get_recursive (NautilusQuery *query);
+
+void nautilus_query_set_recursive (NautilusQuery *query,
+ gboolean recursive);
+
+gboolean nautilus_query_get_searching (NautilusQuery *query);
+
+void nautilus_query_set_searching (NautilusQuery *query,
+ gboolean searching);
+
gdouble nautilus_query_matches_string (NautilusQuery *query, const gchar *string);
char * nautilus_query_to_readable_string (NautilusQuery *query);
+gboolean nautilus_query_is_empty (NautilusQuery *query);
+
#endif /* NAUTILUS_QUERY_H */
diff --git a/libnautilus-private/nautilus-search-directory.c b/libnautilus-private/nautilus-search-directory.c
index 11ca054b6..9fca6a339 100644
--- a/libnautilus-private/nautilus-search-directory.c
+++ b/libnautilus-private/nautilus-search-directory.c
@@ -892,19 +892,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;
@@ -945,11 +942,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 33180fbf3..f3557d6b1 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 e8a6e2e8a..e49a63130 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 a6dc16cd5..78704377d 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 7b517adc9..3fde3f9f7 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 f2dfef64b..7ac85e084 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 2148e7a49..cec51c060 100644
--- a/src/nautilus-shell-search-provider.c
+++ b/src/nautilus-shell-search-provider.c
@@ -392,9 +392,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);
@@ -406,12 +407,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);
@@ -439,7 +440,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);
}