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
This commit is contained in:
parent
0c19f71c96
commit
1d311e7916
@ -75,6 +75,7 @@ struct _ShellApp
|
|||||||
char *name_collation_key;
|
char *name_collation_key;
|
||||||
char *casefolded_description;
|
char *casefolded_description;
|
||||||
char *casefolded_exec;
|
char *casefolded_exec;
|
||||||
|
char **casefolded_keywords;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -1299,6 +1300,7 @@ shell_app_init_search_data (ShellApp *app)
|
|||||||
const char *name;
|
const char *name;
|
||||||
const char *exec;
|
const char *exec;
|
||||||
const char *comment;
|
const char *comment;
|
||||||
|
const char * const *keywords;
|
||||||
char *normalized_exec;
|
char *normalized_exec;
|
||||||
GDesktopAppInfo *appinfo;
|
GDesktopAppInfo *appinfo;
|
||||||
|
|
||||||
@ -1313,6 +1315,25 @@ shell_app_init_search_data (ShellApp *app)
|
|||||||
normalized_exec = shell_util_normalize_and_casefold (exec);
|
normalized_exec = shell_util_normalize_and_casefold (exec);
|
||||||
app->casefolded_exec = trim_exec_line (normalized_exec);
|
app->casefolded_exec = trim_exec_line (normalized_exec);
|
||||||
g_free (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;
|
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)
|
if (current_match == MATCH_NONE)
|
||||||
return current_match;
|
return current_match;
|
||||||
|
|
||||||
@ -1464,6 +1502,7 @@ shell_app_finalize (GObject *object)
|
|||||||
g_free (app->name_collation_key);
|
g_free (app->name_collation_key);
|
||||||
g_free (app->casefolded_description);
|
g_free (app->casefolded_description);
|
||||||
g_free (app->casefolded_exec);
|
g_free (app->casefolded_exec);
|
||||||
|
g_strfreev (app->casefolded_keywords);
|
||||||
|
|
||||||
G_OBJECT_CLASS(shell_app_parent_class)->finalize (object);
|
G_OBJECT_CLASS(shell_app_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user