summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Soriano <csoriano@gnome.org>2016-01-15 17:31:30 +0100
committerCarlos Soriano <csoriano@gnome.org>2016-01-18 11:01:43 +0100
commitcacc1f2bc40df7e4fdd256c148e31188abd4751f (patch)
treef770bc19047586bb51540f3b1d793ddc9ac9de3e
parent45eebc268768e8f4a1b14a714a69056b16c6daa2 (diff)
downloadnautilus-cacc1f2bc40df7e4fdd256c148e31188abd4751f.tar.gz
files-view: make search robust
This is the last patch of a series of patches to fix all the related issues with search synchronization, robustness on search, etc. This patch orders fix when the view is requested to load a search directory. This is tricky because the views expect real locations, and when a caller sets the view to start searching the view expect to already have a real location loaded, so it can set the invented search directory with the model as a backing uri. In the case that window slot request a search directory, we are screwed, because either we load first the real backing uri, which will screw the window slot and all of the connected users of the view when the is-location signal is done, or we first set the query and then load the search directory, which will screw it anyway because the real location set up at that point in the view is not the one associated with the search directory. So we effectively need to do both at the same time. To do that, implement a set_search_query_internal which will allow us to pass a backing uri, so when the slot sets a location that is a search directory, instead of loading the directory itself, we only set the query indicating the real location behind, so it can set up everything in the search directory before loading it. This patch was done with a few things in mind, and it actually fixes few other issues. For example, now then we reuse the directory from the slot, we actually create a new search directory, so we actually don't reuse it. The point for this is because if we reuse the directory, any stop to the search directory will stop the future search that we just set. This happens when the slot stops the old view to load (which had the same search directory before this patch) after setting the new view to load. A better fix would be to get rid of the nautilus-search directory invention or to make it only internal, and make the window-slot be aware when a location was also searching (with a struct instead of using nautilus-bookmarks). https://bugzilla.gnome.org/show_bug.cgi?id=759717
-rw-r--r--src/nautilus-files-view.c68
1 files changed, 48 insertions, 20 deletions
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index a35a8215b..087faf608 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -321,6 +321,10 @@ static gboolean nautilus_files_view_is_searching (NautilusView
static void nautilus_files_view_iface_init (NautilusViewInterface *view);
+static void set_search_query_internal (NautilusFilesView *files_view,
+ NautilusQuery *query,
+ NautilusDirectory *base_model);
+
G_DEFINE_TYPE_WITH_CODE (NautilusFilesView,
nautilus_files_view,
GTK_TYPE_GRID,
@@ -3100,17 +3104,28 @@ nautilus_files_view_set_location (NautilusView *view,
GFile *location)
{
NautilusDirectory *directory;
+ NautilusFilesView *files_view;
nautilus_profile_start (NULL);
+ files_view = NAUTILUS_FILES_VIEW (view);
directory = nautilus_directory_get (location);
- load_directory (NAUTILUS_FILES_VIEW (view), directory);
- /* In case we want to load a previous search, sync the query */
+
+ nautilus_files_view_stop_loading (files_view);
+ /* In case we want to load a previous search we need to extract the real
+ * location and the search location, and load the directory when everything
+ * is ready. That's why we cannot use the nautilus_view_set_query, because
+ * to set a query we need a previous location loaded, but to load a search
+ * location we need to know the real location behind it. */
if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
NautilusQuery *previous_query;
+ NautilusDirectory *base_model;
+ base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (directory));
previous_query = nautilus_search_directory_get_query (NAUTILUS_SEARCH_DIRECTORY (directory));
- nautilus_view_set_search_query (view, previous_query);
+ set_search_query_internal (files_view, previous_query, base_model);
g_object_unref (previous_query);
+ } else {
+ load_directory (NAUTILUS_FILES_VIEW (view), directory);
}
nautilus_directory_unref (directory);
nautilus_profile_end (NULL);
@@ -7679,15 +7694,14 @@ nautilus_files_view_get_search_query (NautilusView *view)
}
static void
-nautilus_files_view_set_search_query (NautilusView *view,
- NautilusQuery *query)
+set_search_query_internal (NautilusFilesView *files_view,
+ NautilusQuery *query,
+ NautilusDirectory *base_model)
{
- NautilusFilesView *files_view;
GFile *location;
gchar *text;
gboolean valid_query = FALSE;
- files_view = NAUTILUS_FILES_VIEW (view);
location = NULL;
if (query) {
text = nautilus_query_get_text (query);
@@ -7697,11 +7711,11 @@ nautilus_files_view_set_search_query (NautilusView *view,
}
g_set_object (&files_view->details->search_query, query);
- g_object_notify (G_OBJECT (view), "search-query");
+ g_object_notify (G_OBJECT (files_view), "search-query");
if (valid_query) {
- if (nautilus_view_is_searching (view)) {
- location = nautilus_directory_get_location (files_view->details->model);
+ if (nautilus_view_is_searching (NAUTILUS_VIEW (files_view))) {
+ location = nautilus_directory_get_location (base_model);
/*
* Reuse the search directory and reload it.
@@ -7728,13 +7742,12 @@ nautilus_files_view_set_search_query (NautilusView *view,
directory = nautilus_directory_get (location);
g_assert (NAUTILUS_IS_SEARCH_DIRECTORY (directory));
-
- nautilus_search_directory_set_base_model (NAUTILUS_SEARCH_DIRECTORY (directory), files_view->details->model);
+ nautilus_search_directory_set_base_model (NAUTILUS_SEARCH_DIRECTORY (directory), base_model);
nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (directory), query);
- nautilus_view_set_location (view, location);
+ load_directory (files_view, directory);
- g_object_notify (G_OBJECT (view), "is-searching");
+ g_object_notify (G_OBJECT (files_view), "is-searching");
nautilus_directory_unref (directory);
nautilus_file_unref (file);
@@ -7742,19 +7755,34 @@ nautilus_files_view_set_search_query (NautilusView *view,
g_free (path);
}
} else {
- if (nautilus_view_is_searching (view)) {
- NautilusDirectory *base;
-
- base = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (files_view->details->model));
- location = nautilus_directory_get_location (base);
+ if (nautilus_view_is_searching (NAUTILUS_VIEW (files_view))) {
+ location = nautilus_directory_get_location (base_model);
- nautilus_view_set_location (view, location);
+ nautilus_view_set_location (NAUTILUS_VIEW (files_view), location);
}
}
check_remote_warning_bar (files_view);
g_clear_object (&location);
}
+static void
+nautilus_files_view_set_search_query (NautilusView *view,
+ NautilusQuery *query)
+{
+ NautilusDirectory *base_model;
+ NautilusFilesView *files_view;
+
+ files_view = NAUTILUS_FILES_VIEW (view);
+
+ if (nautilus_view_is_searching (view)) {
+ base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (files_view->details->model));
+ } else {
+ base_model = files_view->details->model;
+ }
+
+ set_search_query_internal (NAUTILUS_FILES_VIEW (view), query, base_model);
+}
+
static GFile*
nautilus_files_view_get_location (NautilusView *view)
{