Commit 5d5ea495 authored by Allison Karlitskaya's avatar Allison Karlitskaya

desktopappinfo: add Exec to searchable keys

Add the basename from the first component of the Exec line to the list of
strings to search for via g_desktop_app_info_search().

We treat Exec as a fairly strong match -- just below the visible name.

Add a testcase to make sure everything is working OK.

https://bugzilla.gnome.org/show_bug.cgi?id=725023
parent 9ecc859f
......@@ -247,6 +247,7 @@ add_to_table_if_appropriate (GHashTable *apps,
enum
{
DESKTOP_KEY_Comment,
DESKTOP_KEY_Exec,
DESKTOP_KEY_GenericName,
DESKTOP_KEY_Keywords,
DESKTOP_KEY_Name,
......@@ -262,10 +263,11 @@ const gchar desktop_key_match_category[N_DESKTOP_KEYS] = {
* use the same number for the two different keys.
*/
[DESKTOP_KEY_Name] = 1,
[DESKTOP_KEY_Keywords] = 2,
[DESKTOP_KEY_GenericName] = 3,
[DESKTOP_KEY_X_GNOME_FullName] = 4,
[DESKTOP_KEY_Comment] = 5
[DESKTOP_KEY_Exec] = 2,
[DESKTOP_KEY_Keywords] = 3,
[DESKTOP_KEY_GenericName] = 4,
[DESKTOP_KEY_X_GNOME_FullName] = 5,
[DESKTOP_KEY_Comment] = 6
};
static gchar *
......@@ -275,6 +277,8 @@ desktop_key_get_name (guint key_id)
{
case DESKTOP_KEY_Comment:
return "Comment";
case DESKTOP_KEY_Exec:
return "Exec";
case DESKTOP_KEY_GenericName:
return "GenericName";
case DESKTOP_KEY_Keywords:
......@@ -708,17 +712,34 @@ desktop_file_dir_unindexed_setup_search (DesktopFileDir *dir)
for (i = 0; i < G_N_ELEMENTS (desktop_key_match_category); i++)
{
gchar *value;
const gchar *value;
gchar *raw;
if (!desktop_key_match_category[i])
continue;
value = g_key_file_get_locale_string (key_file, "Desktop Entry", desktop_key_get_name (i), NULL, NULL);
raw = g_key_file_get_locale_string (key_file, "Desktop Entry", desktop_key_get_name (i), NULL, NULL);
value = raw;
if (i == DESKTOP_KEY_Exec && raw != NULL)
{
/* Special handling: only match basename of first field */
gchar *space;
gchar *slash;
/* Remove extra arguments, if any */
space = raw + strcspn (raw, " \t\n"); /* IFS */
*space = '\0';
/* Skip the pathname, if any */
if ((slash = strrchr (raw, '/')))
value = slash + 1;
}
if (value)
memory_index_add_string (dir->memory_index, value, desktop_key_match_category[i], app);
g_free (value);
g_free (raw);
}
}
......
......@@ -654,6 +654,15 @@ test_search (void)
"gnome-clocks.desktop\n"
"yelp.desktop gnome-contacts.desktop\n", TRUE, TRUE, NULL, NULL);
/* eog has exec name 'false' in usr only */
assert_search ("false", "eog.desktop\n", TRUE, FALSE, NULL, NULL);
assert_search ("false", "", FALSE, TRUE, NULL, NULL);
assert_search ("false", "", TRUE, TRUE, NULL, NULL);
assert_search ("false", "", FALSE, FALSE, NULL, NULL);
/* make sure we only search the first component */
assert_search ("nonsearchable", "", TRUE, FALSE, NULL, NULL);
/* "gnome con" will match only gnome contacts; via the name for
* "contacts" and the comment for "gnome"
*/
......
......@@ -21,7 +21,7 @@ Comment[en_GB]=Browse and rotate images
Comment[eo]=Foliumi kaj turni bildojn
Comment[pt]=Navegue e rode imagens
Comment[pt_BR]=Navegue e gire imagens
Exec=true %U
Exec=false --nonsearchable %U
Icon=eog
StartupNotify=true
Terminal=false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment