mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-11-05 16:04:31 +00:00
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.
This commit is contained in:
parent
b822c1e4e6
commit
60f47ccaf1
6 changed files with 51 additions and 39 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
gboolean nautilus_query_is_empty (NautilusQuery *query);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue