Skip to content

Commit 5e4e84b

Browse files
committed
nemo-search-engine-advanced.c: Support wildcard mimetypes.
This allows a search helper to process multiple types of the same family, such as 'image/*'. Note that for now, a more specific search helper will be used over a wildcard helper, regardless of priority. If a helper handles 'image/jpeg', it will be used exclusively, *not* the 'image/*' helper.
1 parent f13caea commit 5e4e84b

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

libnemo-private/nemo-search-engine-advanced.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,15 @@ should_skip_child (SearchThreadData *data, GFileInfo *info, GFile *file, gboolea
918918
return TRUE;
919919
}
920920

921+
static gboolean
922+
find_wildcard_mime_type (gpointer key, gpointer value, gpointer user_data)
923+
{
924+
const gchar *helper_mime_type = key;
925+
const gchar *file_content_type = user_data;
926+
927+
return g_content_type_is_mime_type (file_content_type, helper_mime_type);
928+
}
929+
921930
static void
922931
visit_directory (GFile *dir, SearchThreadData *data)
923932
{
@@ -1009,14 +1018,16 @@ visit_directory (GFile *dir, SearchThreadData *data)
10091018
skip_child = should_skip_child (data, info, child, is_dir);
10101019

10111020
if (hit) {
1012-
const gchar *mime_type;
1021+
const gchar *content_type;
10131022

1014-
mime_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1023+
content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
10151024

1016-
if (mime_type == NULL) {
1017-
mime_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
1025+
if (content_type == NULL) {
1026+
content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
10181027
}
10191028

1029+
g_autofree gchar *mime_type = g_content_type_get_mime_type (content_type);
1030+
10201031
// Our helpers don't currently support uris, so we shouldn't at all -
10211032
// probably best, as search would transfer the contents of every file
10221033
// to our machines.
@@ -1025,8 +1036,11 @@ visit_directory (GFile *dir, SearchThreadData *data)
10251036
SearchHelper *helper = NULL;
10261037

10271038
helper = g_hash_table_lookup (search_helpers, mime_type);
1039+
if (helper == NULL) {
1040+
helper = g_hash_table_find (search_helpers, find_wildcard_mime_type, (gpointer) content_type);
1041+
}
10281042

1029-
if (helper != NULL || g_content_type_is_a (mime_type, "text/plain")) {
1043+
if (helper != NULL || g_content_type_is_a (content_type, "text/plain")) {
10301044
if (DEBUGGING) {
10311045
g_message ("Evaluating '%s'", g_file_peek_path (child));
10321046
}

0 commit comments

Comments
 (0)