[glib] desktopappinfo: add Exec to searchable keys
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] desktopappinfo: add Exec to searchable keys
- Date: Mon, 3 Mar 2014 21:01:36 +0000 (UTC)
commit 5d5ea495b5dca3965d60556300151c75a44c5653
Author: Ryan Lortie <desrt desrt ca>
Date: Sun Mar 2 09:38:51 2014 -0500
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
gio/gdesktopappinfo.c | 35 ++++++++++++++++----
gio/tests/desktop-app-info.c | 9 +++++
.../desktop-files/usr/applications/eog.desktop | 2 +-
3 files changed, 38 insertions(+), 8 deletions(-)
---
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index 91ebc77..0582b52 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 9f26e0e..3ad820f 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 7e0504a..9982842 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]