summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2014-03-02 09:38:51 -0500
committerRyan Lortie <desrt@desrt.ca>2014-03-03 16:01:27 -0500
commit5d5ea495b5dca3965d60556300151c75a44c5653 (patch)
treead07585b152aa5bcd0ba956a5408fd60e92a94cd
parent9ecc859f95d3a2f3faf918c96ca21a447dd33b6a (diff)
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
-rw-r--r--gio/gdesktopappinfo.c35
-rw-r--r--gio/tests/desktop-app-info.c9
-rw-r--r--gio/tests/desktop-files/usr/applications/eog.desktop2
3 files changed, 38 insertions, 8 deletions
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index 91ebc77e4..0582b5211 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -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);
}
}
diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c
index 9f26e0ee8..3ad820fee 100644
--- a/gio/tests/desktop-app-info.c
+++ b/gio/tests/desktop-app-info.c
@@ -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"
*/
diff --git a/gio/tests/desktop-files/usr/applications/eog.desktop b/gio/tests/desktop-files/usr/applications/eog.desktop
index 7e0504a3e..998284266 100644
--- a/gio/tests/desktop-files/usr/applications/eog.desktop
+++ b/gio/tests/desktop-files/usr/applications/eog.desktop
@@ -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