diff --git a/src/xfce-appfinder-window.c b/src/xfce-appfinder-window.c index 6f5c1bd..c5962dc 100644 --- a/src/xfce-appfinder-window.c +++ b/src/xfce-appfinder-window.c @@ -695,8 +695,11 @@ _xfce_appfinder_window_execute (XfceAppfinderWindow *window) GtkTreeModel *model; GtkTreeIter iter; GdkScreen *screen; + gboolean startup_notification, terminal; GError *error = NULL; - gchar *command, *uri; + const gchar *icon_name, *name; + gchar *command, *p, *expanded_command; + GString *newstr; g_return_if_fail (XFCE_IS_APPFINDER_WINDOW (window)); @@ -710,13 +713,91 @@ _xfce_appfinder_window_execute (XfceAppfinderWindow *window) if (G_UNLIKELY (item == NULL)) return; - uri = garcon_menu_item_get_uri (item); - command = g_strconcat ("exo-open ", uri, NULL); - g_free (uri); + /* Get the command and expand the percent vars */ + command = g_strdup (garcon_menu_item_get_command (item)); + icon_name = garcon_menu_item_get_icon_name (item); + name = garcon_menu_item_get_name (item); + + if (G_UNLIKELY (command == NULL)) + return; + + newstr = g_string_sized_new (strlen (command) + 1); + + for (p = command; *p; ++p) + { + if ('%' == *p) + { + ++p; + switch (*p) + { + /* we don't care about these since we aren't passing filenames */ + case 'f': + case 'F': + case 'u': + case 'U': + /* these are all deprecated */ + case 'd': + case 'D': + case 'n': + case 'N': + case 'v': + case 'm': + break; + case 'i': + if (G_LIKELY (icon_name)) + { + gchar *str = g_shell_quote (icon_name); + g_string_append (newstr, "--icon "); + g_string_append (newstr, str); + g_free (str); + } + break; + case 'c': + if (G_LIKELY (name)) + { + gchar *name_locale, *str; + gsize bread = 0; + GError *error = NULL; + + name_locale = g_locale_from_utf8 (name, + -1, &bread, NULL, + &error); + + if (name_locale) + { + str = g_shell_quote (name_locale); + g_string_append (newstr, str); + g_free (str); + g_free (name_locale); + } + else + { + g_warning ("Invalid UTF-8 in Name at byte %u: %s", + (guint) bread, error->message); + } + } + break; + case '%': + g_string_append_c (newstr, '%'); + break; + default: + g_warning ("Invalid field code in Exec line: %%%c", *p); + break; + } + } + else + g_string_append_c (newstr, *p); + } + + expanded_command = newstr->str; + + /* Get the launch preferences */ + startup_notification = garcon_menu_item_supports_startup_notification (item); + terminal = garcon_menu_item_requires_terminal (item); screen = xfce_gdk_screen_get_active (NULL); - if (G_UNLIKELY (!xfce_spawn_command_line_on_screen (screen, command, FALSE, TRUE, &error))) + if (G_UNLIKELY (!xfce_spawn_command_line_on_screen (screen, expanded_command, terminal, startup_notification, &error))) { xfce_dialog_show_error (GTK_WINDOW (window), error, _("Could not execute application %s."), garcon_menu_element_get_name (GARCON_MENU_ELEMENT (item))); @@ -725,6 +806,8 @@ _xfce_appfinder_window_execute (XfceAppfinderWindow *window) g_error_free (error); } + g_string_free (newstr, FALSE); + g_free (expanded_command); g_free (command); if (G_LIKELY (xfconf_channel_get_bool (window->channel, "/close-after-execute", FALSE)))