GHashTable *app_names;
GHashTable *mime_tweaks;
GHashTable *memory_index;
+ GHashTable *memory_implementations;
} DesktopFileDir;
static DesktopFileDir *desktop_file_dirs;
goto no_add;
/* Don't add duplicates already in the list */
- for (j = 0; strv[j]; j++)
+ for (j = 0; j < strv_len; j++)
if (g_str_equal (to_add[i], strv[j]))
goto no_add;
gpointer app, path;
dir->memory_index = memory_index_new ();
+ dir->memory_implementations = memory_index_new ();
/* Nothing to search? */
if (dir->app_names == NULL)
!g_key_file_get_boolean (key_file, "Desktop Entry", "Hidden", NULL))
{
/* Index the interesting keys... */
+ gchar **implements;
gint i;
for (i = 0; i < G_N_ELEMENTS (desktop_key_match_category); i++)
g_free (raw);
}
+
+ /* Make note of the Implements= line */
+ implements = g_key_file_get_string_list (key_file, "Desktop Entry", "Implements", NULL, NULL);
+ for (i = 0; implements && implements[i]; i++)
+ memory_index_add_token (dir->memory_implementations, implements[i], 0, app);
+ g_strfreev (implements);
}
g_key_file_free (key_file);
}
}
+static void
+desktop_file_dir_unindexed_get_implementations (DesktopFileDir *dir,
+ GList **results,
+ const gchar *interface)
+{
+ MemoryIndexEntry *mie;
+
+ if (!dir->memory_index)
+ desktop_file_dir_unindexed_setup_search (dir);
+
+ for (mie = g_hash_table_lookup (dir->memory_implementations, interface); mie; mie = mie->next)
+ *results = g_list_prepend (*results, g_strdup (mie->app_name));
+}
+
/* DesktopFileDir "API" {{{2 */
/*< internal >
dir->mime_tweaks = NULL;
}
+ if (dir->memory_implementations)
+ {
+ g_hash_table_unref (dir->memory_implementations);
+ dir->memory_implementations = NULL;
+ }
+
dir->is_setup = FALSE;
}
desktop_file_dir_unindexed_search (dir, search_token);
}
+static void
+desktop_file_dir_get_implementations (DesktopFileDir *dir,
+ GList **results,
+ const gchar *interface)
+{
+ desktop_file_dir_unindexed_get_implementations (dir, results, interface);
+}
+
/* Lock/unlock and global setup API {{{2 */
static void
/* "Get all" API {{{2 */
/**
+ * g_desktop_app_info_get_implementations:
+ * @interface: the name of the interface
+ *
+ * Gets all applications that implement @interface.
+ *
+ * An application implements an interface if that interface is listed in
+ * the Implements= line of the desktop file of the application.
+ *
+ * Since: 2.42
+ **/
+GList *
+g_desktop_app_info_get_implementations (const gchar *interface)
+{
+ GList *result = NULL;
+ GList **ptr;
+ gint i;
+
+ desktop_file_dirs_lock ();
+
+ for (i = 0; i < n_desktop_file_dirs; i++)
+ desktop_file_dir_get_implementations (&desktop_file_dirs[i], &result, interface);
+
+ desktop_file_dirs_unlock ();
+
+ ptr = &result;
+ while (*ptr)
+ {
+ gchar *name = (*ptr)->data;
+ GDesktopAppInfo *app;
+
+ app = g_desktop_app_info_new (name);
+ g_free (name);
+
+ if (app)
+ {
+ (*ptr)->data = app;
+ ptr = &(*ptr)->next;
+ }
+ else
+ *ptr = g_list_delete_link (*ptr, *ptr);
+ }
+
+ return result;
+}
+
+/**
* g_desktop_app_info_search:
* @search_string: the search string to use
*