appDisplay: Use the desktop file index for app searching
Rather than scanning all apps for searching, use Ryan's new desktop file index and the glib support APIs for app searching instead of our own system. https://bugzilla.gnome.org/show_bug.cgi?id=711631
This commit is contained in:
@ -348,143 +348,3 @@ shell_app_system_get_running (ShellAppSystem *self)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static gint
|
||||
compare_apps_by_usage (gconstpointer a,
|
||||
gconstpointer b,
|
||||
gpointer data)
|
||||
{
|
||||
ShellAppUsage *usage = shell_app_usage_get_default ();
|
||||
|
||||
ShellApp *app_a = (ShellApp*)a;
|
||||
ShellApp *app_b = (ShellApp*)b;
|
||||
|
||||
return shell_app_usage_compare (usage, "", app_a, app_b);
|
||||
}
|
||||
|
||||
static GSList *
|
||||
sort_and_concat_results (ShellAppSystem *system,
|
||||
GSList *prefix_matches,
|
||||
GSList *substring_matches)
|
||||
{
|
||||
GSList *matches = NULL;
|
||||
GSList *l;
|
||||
|
||||
prefix_matches = g_slist_sort_with_data (prefix_matches,
|
||||
compare_apps_by_usage,
|
||||
system);
|
||||
substring_matches = g_slist_sort_with_data (substring_matches,
|
||||
compare_apps_by_usage,
|
||||
system);
|
||||
|
||||
for (l = substring_matches; l != NULL; l = l->next)
|
||||
matches = g_slist_prepend (matches, (char *) shell_app_get_id (SHELL_APP (l->data)));
|
||||
for (l = prefix_matches; l != NULL; l = l->next)
|
||||
matches = g_slist_prepend (matches, (char *) shell_app_get_id (SHELL_APP (l->data)));
|
||||
|
||||
return g_slist_reverse (matches);
|
||||
}
|
||||
|
||||
/**
|
||||
* normalize_terms:
|
||||
* @terms: (element-type utf8): Input search terms
|
||||
*
|
||||
* Returns: (element-type utf8) (transfer full): Unicode-normalized and lowercased terms
|
||||
*/
|
||||
static GSList *
|
||||
normalize_terms (GSList *terms)
|
||||
{
|
||||
GSList *normalized_terms = NULL;
|
||||
GSList *iter;
|
||||
for (iter = terms; iter; iter = iter->next)
|
||||
{
|
||||
const char *term = iter->data;
|
||||
normalized_terms = g_slist_prepend (normalized_terms,
|
||||
shell_util_normalize_casefold_and_unaccent (term));
|
||||
}
|
||||
return normalized_terms;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
search_tree (ShellAppSystem *self,
|
||||
GSList *terms,
|
||||
GHashTable *apps)
|
||||
{
|
||||
GSList *prefix_results = NULL;
|
||||
GSList *substring_results = NULL;
|
||||
GSList *normalized_terms;
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
|
||||
normalized_terms = normalize_terms (terms);
|
||||
|
||||
g_hash_table_iter_init (&iter, apps);
|
||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||
{
|
||||
ShellApp *app = value;
|
||||
_shell_app_do_match (app, normalized_terms,
|
||||
&prefix_results,
|
||||
&substring_results);
|
||||
}
|
||||
g_slist_free_full (normalized_terms, g_free);
|
||||
|
||||
return sort_and_concat_results (self, prefix_results, substring_results);
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_app_system_initial_search:
|
||||
* @system: A #ShellAppSystem
|
||||
* @terms: (element-type utf8): List of terms, logical AND
|
||||
*
|
||||
* Search through applications for the given search terms.
|
||||
*
|
||||
* Returns: (transfer container) (element-type utf8): List of applications
|
||||
*/
|
||||
GSList *
|
||||
shell_app_system_initial_search (ShellAppSystem *self,
|
||||
GSList *terms)
|
||||
{
|
||||
return search_tree (self, terms, self->priv->id_to_app);
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_app_system_subsearch:
|
||||
* @system: A #ShellAppSystem
|
||||
* @previous_results: (element-type utf8): List of previous results
|
||||
* @terms: (element-type utf8): List of terms, logical AND
|
||||
*
|
||||
* Search through a previous result set; for more information, see
|
||||
* js/ui/search.js. Note that returned strings are only valid until
|
||||
* a return to the main loop.
|
||||
*
|
||||
* Returns: (transfer container) (element-type utf8): List of application identifiers
|
||||
*/
|
||||
GSList *
|
||||
shell_app_system_subsearch (ShellAppSystem *system,
|
||||
GSList *previous_results,
|
||||
GSList *terms)
|
||||
{
|
||||
GSList *iter;
|
||||
GSList *prefix_results = NULL;
|
||||
GSList *substring_results = NULL;
|
||||
GSList *normalized_terms = normalize_terms (terms);
|
||||
|
||||
previous_results = g_slist_reverse (previous_results);
|
||||
|
||||
for (iter = previous_results; iter; iter = iter->next)
|
||||
{
|
||||
ShellApp *app = shell_app_system_lookup_app (system, iter->data);
|
||||
|
||||
_shell_app_do_match (app, normalized_terms,
|
||||
&prefix_results,
|
||||
&substring_results);
|
||||
}
|
||||
g_slist_free_full (normalized_terms, g_free);
|
||||
|
||||
/* Note that a shorter term might have matched as a prefix, but
|
||||
when extended only as a substring, so we have to redo the
|
||||
sort rather than reusing the existing ordering */
|
||||
return sort_and_concat_results (system, prefix_results, substring_results);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user