diff options
author | John Ralls <jralls@ceridwen.us> | 2019-01-11 16:14:28 -0800 |
---|---|---|
committer | John Ralls <jralls@ceridwen.us> | 2019-03-11 17:58:38 -0700 |
commit | 75b8abbf24379f2a4bda274d550131b8de48aee3 (patch) | |
tree | 198ebe4a77955a22883d66bcb85377ff831a0c3a | |
parent | 0f5603e74f8c905a02f99187a086205bd2628a98 (diff) | |
download | gtk+-75b8abbf24379f2a4bda274d550131b8de48aee3.tar.gz |
[GtkSearchEngineQuartz] Limit the scope of the Spotlight search.
If the query has a non-null location, set the scope to that directory,
otherwise set it to the local computer.
There is unfortunately no way to get Spotlight to search
non-recursively, nor does NSFileManager offer a convenient search of
the contents of a directory's regular files.
-rw-r--r-- | gtk/gtksearchenginequartz.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/gtk/gtksearchenginequartz.c b/gtk/gtksearchenginequartz.c index f408c415a8..c260b51025 100644 --- a/gtk/gtksearchenginequartz.c +++ b/gtk/gtksearchenginequartz.c @@ -192,6 +192,8 @@ gtk_search_engine_quartz_set_query (GtkSearchEngine *engine, GtkQuery *query) { GtkSearchEngineQuartz *quartz; + const char* path = NULL; + GFile *location = NULL; QUARTZ_POOL_ALLOC; @@ -204,11 +206,28 @@ gtk_search_engine_quartz_set_query (GtkSearchEngine *engine, g_object_unref (quartz->priv->query); quartz->priv->query = query; + location = gtk_query_get_location (query); + + if (location) + path = g_file_peek_path (location); /* We create a query to look for ".*text.*" in the text contents of * all indexed files. (Should we also search for text in file and folder * names?). */ + + if (path) + { + NSString *ns_path = [[NSString string] initWithUTF8String:path]; + [quartz->priv->ns_query setSearchScopes:@[ns_path]]; + } + else + { + [quartz->priv->ns_query setSearchScopes:@[NSMetadataQueryLocalComputerScope]]; + } + + [quartz->priv->ns_query setSearchItems:@[(NSString*)kMDItemTextContent, + (NSString*)kMDItemFSName]]; [quartz->priv->ns_query setPredicate: [NSPredicate predicateWithFormat: [NSString stringWithFormat:@"(kMDItemTextContent LIKE[cd] \"*%s*\")", |