@@ -96,13 +96,21 @@ G_DEFINE_TYPE (NemoSearchEngineAdvanced, nemo_search_engine_advanced,
9696static GHashTable * search_helpers = NULL ;
9797
9898static void
99- search_helper_free (SearchHelper * helper )
99+ search_helper_free (gpointer data )
100100{
101+ SearchHelper * helper = (SearchHelper * ) data ;
101102 g_free (helper -> def_path );
102103 g_free (helper -> exec_format );
104+ g_free (helper -> filename );
103105 g_free (helper );
104106}
105107
108+ static void
109+ search_helper_list_free (GList * helper_list )
110+ {
111+ g_list_free_full (helper_list , (GDestroyNotify ) search_helper_free );
112+ }
113+
106114static GList *
107115get_cat_helper_directories (void )
108116{
@@ -144,7 +152,6 @@ process_search_helper_file (const gchar *path)
144152 gchar * * try_exec_list = NULL ;
145153 gchar * abs_try_path = NULL ;
146154 gchar * * mime_types = NULL ;
147- gint priority = 100 ;
148155 gsize n_types ;
149156 gint i ;
150157
@@ -203,39 +210,28 @@ process_search_helper_file (const gchar *path)
203210 goto done ;
204211 }
205212
206- if (g_key_file_has_key (key_file , SEARCH_HELPER_GROUP , "Priority" , NULL )) {
207- priority = g_key_file_get_integer (key_file , SEARCH_HELPER_GROUP , "Priority" , NULL );
208-
209- // Failure sets the return to 0, make it 100 for the default when there's no key.
210- if (priority == 0 ) {
211- priority = 100 ;
212- }
213- }
214-
215213 /* The helper table is keyed to mimetype strings, which will point to the same value */
216214
217215 for (i = 0 ; i < n_types ; i ++ ) {
218- SearchHelper * helper , * existing ;
216+ SearchHelper * helper ;
217+ GList * existing ;
219218 const gchar * mime_type ;
220219
221220 mime_type = mime_types [i ];
222221
223- existing = g_hash_table_lookup (search_helpers , mime_type );
224- if (existing && existing -> priority > priority ) {
225- DEBUG ("Existing nemo search_helper for '%s' (%s) has higher priority than a new one (%s), ignoring the new one." ,
226- mime_type , existing -> def_path , path );
227- continue ;
228- } else if (existing ) {
229- DEBUG ("Replacing existing nemo search_helper for '%s' (%s) with %s based on priority." ,
230- mime_type , existing -> def_path , path );
231- }
232-
233222 helper = g_new0 (SearchHelper , 1 );
223+ helper -> filename = g_path_get_basename (path );
234224 helper -> def_path = g_strdup (path );
235225 helper -> exec_format = g_strdup (exec_format );
236- helper -> priority = priority ;
237226
238- g_hash_table_replace (search_helpers , g_strdup (mime_type ), helper );
227+ existing = g_hash_table_lookup (search_helpers , mime_type );
228+
229+ if (!existing ) {
230+ existing = g_list_append (NULL , helper );
231+ g_hash_table_replace (search_helpers , g_strdup (mime_type ), existing );
232+ } else {
233+ existing = g_list_append (existing , helper );
234+ }
239235 }
240236
241237done :
@@ -253,7 +249,7 @@ initialize_search_helpers (NemoSearchEngineAdvanced *engine)
253249 GList * dir_list , * d_iter ;
254250
255251 search_helpers = g_hash_table_new_full (g_str_hash , g_str_equal ,
256- g_free , (GDestroyNotify ) search_helper_free );
252+ g_free , (GDestroyNotify ) search_helper_list_free );
257253
258254 dir_list = get_cat_helper_directories ();
259255
@@ -918,13 +914,41 @@ should_skip_child (SearchThreadData *data, GFileInfo *info, GFile *file, gboolea
918914 return TRUE;
919915}
920916
921- static gboolean
922- find_wildcard_mime_type (gpointer key , gpointer value , gpointer user_data )
917+ typedef struct
923918{
919+ GList * helpers ;
920+ const gchar * content_type ;
921+ } SearchHelperFindData ;
922+
923+ static void
924+ find_matching_helper (gpointer key ,
925+ gpointer value ,
926+ gpointer user_data )
927+ {
928+ SearchHelperFindData * data = user_data ;
929+
930+ const gchar * file_content_type = data -> content_type ;
924931 const gchar * helper_mime_type = key ;
925- const gchar * file_content_type = user_data ;
932+ if (g_content_type_is_mime_type (file_content_type , helper_mime_type )) {
933+ GList * i ;
934+ GList * helper_list = value ;
935+
936+ for (i = helper_list ; i != NULL ; i = i -> next ) {
937+ data -> helpers = g_list_prepend (data -> helpers , i -> data );
938+ }
939+ }
940+ }
926941
927- return g_content_type_is_mime_type (file_content_type , helper_mime_type );
942+ static GList *
943+ lookup_helpers_for_content_type (const gchar * content_type )
944+ {
945+ SearchHelperFindData find_data = { NULL , content_type };
946+
947+ g_hash_table_foreach (search_helpers ,
948+ (GHFunc ) find_matching_helper ,
949+ (gpointer ) & find_data );
950+
951+ return find_data .helpers ;
928952}
929953
930954static void
@@ -1026,25 +1050,26 @@ visit_directory (GFile *dir, SearchThreadData *data)
10261050 content_type = g_file_info_get_attribute_string (info , G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE );
10271051 }
10281052
1029- g_autofree gchar * mime_type = g_content_type_get_mime_type (content_type );
1030-
1031- // Our helpers don't currently support uris, so we shouldn't at all -
1032- // probably best, as search would transfer the contents of every file
1033- // to our machines.
10341053 if (data -> content_re && data -> location_supports_content_search ) {
10351054 if (!skip_child ) {
1036- SearchHelper * helper = NULL ;
1037-
1038- 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 );
1055+ if (DEBUGGING ) {
1056+ g_message ("Evaluating '%s'" , g_file_peek_path (child ));
10411057 }
10421058
1043- if (helper != NULL || g_content_type_is_a (content_type , "text/plain" )) {
1044- if (DEBUGGING ) {
1045- g_message ("Evaluating '%s'" , g_file_peek_path (child ));
1059+ if (g_content_type_is_a (content_type , "text/plain" )) {
1060+ search_for_content_hits (data , child , NULL );
1061+ } else {
1062+ GList * helpers = lookup_helpers_for_content_type (content_type );
1063+ if (helpers != NULL ) {
1064+ GList * i ;
1065+
1066+ for (i = helpers ; i != NULL ; i = i -> next ) {
1067+ SearchHelper * helper = i -> data ;
1068+ search_for_content_hits (data , child , helper );
1069+ }
1070+
1071+ g_list_free (helpers );
10461072 }
1047- search_for_content_hits (data , child , helper );
10481073 }
10491074 }
10501075 } else {
0 commit comments