[gnome-shell] shell-app: Make use of Keywords in search
- From: Florian MÃllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] shell-app: Make use of Keywords in search
- Date: Wed, 25 Jan 2012 19:32:40 +0000 (UTC)
commit 1d311e79167441362849657224197819e05678df
Author: Florian MÃllner <fmuellner gnome org>
Date: Thu Oct 13 22:03:50 2011 +0200
shell-app: Make use of Keywords in search
.desktop files have been designed for browsing, so the existing
fields often produce insufficient results when used for search.
gnome-control-center used X-GNOME-Keywords for that purpose, which
has now been standardized as Keywords. It makes sense for us to
support it in gnome-shell as well (and encourage its use outside
of settings panels).
https://bugzilla.gnome.org/show_bug.cgi?id=609702
src/shell-app.c | 39 +++++++++++++++++++++++++++++++++++++++
1 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/src/shell-app.c b/src/shell-app.c
index cc86091..ec9529d 100644
--- a/src/shell-app.c
+++ b/src/shell-app.c
@@ -75,6 +75,7 @@ struct _ShellApp
char *name_collation_key;
char *casefolded_description;
char *casefolded_exec;
+ char **casefolded_keywords;
};
enum {
@@ -1299,6 +1300,7 @@ shell_app_init_search_data (ShellApp *app)
const char *name;
const char *exec;
const char *comment;
+ const char * const *keywords;
char *normalized_exec;
GDesktopAppInfo *appinfo;
@@ -1313,6 +1315,25 @@ shell_app_init_search_data (ShellApp *app)
normalized_exec = shell_util_normalize_and_casefold (exec);
app->casefolded_exec = trim_exec_line (normalized_exec);
g_free (normalized_exec);
+
+ keywords = g_desktop_app_info_get_keywords (appinfo);
+
+ if (keywords)
+ {
+ int i;
+
+ app->casefolded_keywords = g_new0 (char*, g_strv_length (keywords) + 1);
+
+ i = 0;
+ while (keywords[i])
+ {
+ app->casefolded_keywords[i] = shell_util_normalize_and_casefold (keywords[i]);
+ ++i;
+ }
+ app->casefolded_keywords[i] = NULL;
+ }
+ else
+ app->casefolded_keywords = NULL;
}
/**
@@ -1381,6 +1402,23 @@ _shell_app_match_search_terms (ShellApp *app,
current_match = MATCH_SUBSTRING;
}
+ if (app->casefolded_keywords)
+ {
+ int i = 0;
+ while (app->casefolded_keywords[i] && current_match < MATCH_PREFIX)
+ {
+ p = strstr (app->casefolded_keywords[i], term);
+ if (p != NULL)
+ {
+ if (p == app->casefolded_keywords[i])
+ current_match = MATCH_PREFIX;
+ else
+ current_match = MATCH_SUBSTRING;
+ }
+ ++i;
+ }
+ }
+
if (current_match == MATCH_NONE)
return current_match;
@@ -1464,6 +1502,7 @@ shell_app_finalize (GObject *object)
g_free (app->name_collation_key);
g_free (app->casefolded_description);
g_free (app->casefolded_exec);
+ g_strfreev (app->casefolded_keywords);
G_OBJECT_CLASS(shell_app_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]