[gnome-shell/wip/desktop-file-index: 17/20] appDisplay: Use the desktop file index for app searching
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/desktop-file-index: 17/20] appDisplay: Use the desktop file index for app searching
- Date: Wed, 2 Oct 2013 14:00:30 +0000 (UTC)
commit 9c5c0f37c25b719155d389c87f721c4ee0e9301c
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Thu Sep 19 13:42:58 2013 -0400
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.
js/ui/appDisplay.js | 11 +++-
src/shell-app-system.c | 141 ------------------------------------------------
src/shell-app-system.h | 6 --
src/shell-app-usage.c | 18 +++---
src/shell-app-usage.h | 4 +-
5 files changed, 20 insertions(+), 160 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 8f5dfcd..d5fd487 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -875,12 +875,19 @@ const AppSearchProvider = new Lang.Class({
callback(metas);
},
+ _compareResults: function(a, b) {
+ let usage = Shell.AppUsage.get_default();
+ return usage.compare('', a, b);
+ },
+
getInitialResultSet: function(terms) {
- this.searchSystem.setResults(this, this._appSys.initial_search(terms));
+ let query = terms.join(' ');
+ let results = Gio.DesktopAppInfo.search(query, Lang.bind(this, this._compareResults), MAX_COLUMNS);
+ this.searchSystem.setResults(this, results);
},
getSubsearchResultSet: function(previousResults, terms) {
- this.searchSystem.setResults(this, this._appSys.subsearch(previousResults, terms));
+ this.getInitialResultSet(terms);
},
activateResult: function(result) {
diff --git a/src/shell-app-system.c b/src/shell-app-system.c
index 0b36318..cf566f1 100644
--- a/src/shell-app-system.c
+++ b/src/shell-app-system.c
@@ -312,144 +312,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 the value of @prefs must be
- * the same as passed to shell_app_system_initial_search(). 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);
-}
-
diff --git a/src/shell-app-system.h b/src/shell-app-system.h
index 6f93449..c0c501a 100644
--- a/src/shell-app-system.h
+++ b/src/shell-app-system.h
@@ -49,10 +49,4 @@ ShellApp *shell_app_system_lookup_desktop_wmclass (ShellAppSystem *s
GSList *shell_app_system_get_running (ShellAppSystem *self);
-GSList *shell_app_system_initial_search (ShellAppSystem *system,
- GSList *terms);
-GSList *shell_app_system_subsearch (ShellAppSystem *system,
- GSList *previous_results,
- GSList *terms);
-
#endif /* __SHELL_APP_SYSTEM_H__ */
diff --git a/src/shell-app-usage.c b/src/shell-app-usage.c
index 31e7f85..c733ce4 100644
--- a/src/shell-app-usage.c
+++ b/src/shell-app-usage.c
@@ -527,19 +527,19 @@ shell_app_usage_get_most_used (ShellAppUsage *self,
* shell_app_usage_compare:
* @self: the usage instance to request
* @context: Activity identifier
- * @app_a: First app
- * @app_b: Second app
+ * @id_a: ID of first app
+ * @id_b: ID of second app
*
- * Compare @app_a and @app_b based on frequency of use.
+ * Compare @id_a and @id_b based on frequency of use.
*
- * Returns: -1 if @app_a ranks higher than @app_b, 1 if @app_b ranks higher
- * than @app_a, and 0 if both rank equally.
+ * Returns: -1 if @id_a ranks higher than @id_b, 1 if @id_b ranks higher
+ * than @id_a, and 0 if both rank equally.
*/
int
shell_app_usage_compare (ShellAppUsage *self,
const char *context,
- ShellApp *app_a,
- ShellApp *app_b)
+ const char *id_a,
+ const char *id_b)
{
GHashTable *usages;
UsageData *usage_a, *usage_b;
@@ -548,8 +548,8 @@ shell_app_usage_compare (ShellAppUsage *self,
if (usages == NULL)
return 0;
- usage_a = g_hash_table_lookup (usages, shell_app_get_id (app_a));
- usage_b = g_hash_table_lookup (usages, shell_app_get_id (app_b));
+ usage_a = g_hash_table_lookup (usages, id_a);
+ usage_b = g_hash_table_lookup (usages, id_b);
if (usage_a == NULL && usage_b == NULL)
return 0;
diff --git a/src/shell-app-usage.h b/src/shell-app-usage.h
index 4016b58..4afdbb3 100644
--- a/src/shell-app-usage.h
+++ b/src/shell-app-usage.h
@@ -31,8 +31,8 @@ GSList *shell_app_usage_get_most_used (ShellAppUsage *usage,
const char *context);
int shell_app_usage_compare (ShellAppUsage *self,
const char *context,
- ShellApp *app_a,
- ShellApp *app_b);
+ const char *id_a,
+ const char *id_b);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]