summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorTamaranch <138-Tamaranch@users.noreply.gitlab.xfce.org>2020-07-08 12:14:37 +0200
committerAlexander Schwinn <alexxcons@xfce.org>2020-07-21 22:27:40 +0200
commitee7a2461e21cef030d727e670802296a17f646a6 (patch)
tree9b4fa2eff619333e41500290762d00646841db8d /plugins
parentf7cb80ea92556caad148e1c4ca9e8346d4bb3fe9 (diff)
downloadthunar-ee7a2461e21cef030d727e670802296a17f646a6.tar.gz
Make use of shared field codes expansion of libxfce4util
Followup of https://gitlab.xfce.org/xfce/libxfce4util/-/merge_requests/2 Fixes !23
Diffstat (limited to 'plugins')
-rw-r--r--plugins/thunar-uca/thunar-uca-model.c100
1 files changed, 21 insertions, 79 deletions
diff --git a/plugins/thunar-uca/thunar-uca-model.c b/plugins/thunar-uca/thunar-uca-model.c
index 54f0dd12..5667b884 100644
--- a/plugins/thunar-uca/thunar-uca-model.c
+++ b/plugins/thunar-uca/thunar-uca-model.c
@@ -1529,10 +1529,11 @@ thunar_uca_model_parse_argv (ThunarUcaModel *uca_model,
const gchar *p;
GString *command_line = g_string_new (NULL);
GList *lp;
+ GSList *uri_list = NULL;
gchar *dirname;
- gchar *quoted;
gchar *path;
gchar *uri;
+ gchar *expanded;
GFile *location;
g_return_val_if_fail (THUNAR_UCA_IS_MODEL (uca_model), FALSE);
@@ -1547,75 +1548,13 @@ thunar_uca_model_parse_argv (ThunarUcaModel *uca_model,
goto error;
}
- /* generate the command line */
+ /* expand first the field codes that are deprecated in Freedesktop.org specification */
for (p = item->command; *p != '\0'; ++p)
{
- if (p[0] == '%' && p[1] != '\0')
+ if (G_UNLIKELY (p[0] == '%' && p[1] != '\0'))
{
switch (*++p)
{
- case 'f':
- if (G_LIKELY (file_infos != NULL))
- {
- location = thunarx_file_info_get_location (file_infos->data);
- path = g_file_get_path (location);
- g_object_unref (location);
-
- if (G_UNLIKELY (path == NULL))
- goto error;
-
- quoted = g_shell_quote (path);
- g_string_append (command_line, quoted);
- g_free (quoted);
- g_free (path);
- }
- break;
-
- case 'F':
- for (lp = file_infos; lp != NULL; lp = lp->next)
- {
- if (G_LIKELY (lp != file_infos))
- g_string_append_c (command_line, ' ');
-
- location = thunarx_file_info_get_location (lp->data);
- path = g_file_get_path (location);
- g_object_unref (location);
-
- if (G_UNLIKELY (path == NULL))
- goto error;
-
- quoted = g_shell_quote (path);
- g_string_append (command_line, quoted);
- g_free (quoted);
- g_free (path);
- }
- break;
-
- case 'u':
- if (G_LIKELY (file_infos != NULL))
- {
- uri = thunarx_file_info_get_uri (file_infos->data);
- quoted = g_shell_quote (uri);
- g_string_append (command_line, quoted);
- g_free (quoted);
- g_free (uri);
- }
- break;
-
- case 'U':
- for (lp = file_infos; lp != NULL; lp = lp->next)
- {
- if (G_LIKELY (lp != file_infos))
- g_string_append_c (command_line, ' ');
-
- uri = thunarx_file_info_get_uri (lp->data);
- quoted = g_shell_quote (uri);
- g_string_append (command_line, quoted);
- g_free (quoted);
- g_free (uri);
- }
- break;
-
case 'd':
if (G_LIKELY (file_infos != NULL))
{
@@ -1627,10 +1566,8 @@ thunar_uca_model_parse_argv (ThunarUcaModel *uca_model,
goto error;
dirname = g_path_get_dirname (path);
- quoted = g_shell_quote (dirname);
- g_string_append (command_line, quoted);
+ xfce_append_quoted (command_line, dirname);
g_free (dirname);
- g_free (quoted);
g_free (path);
}
break;
@@ -1649,10 +1586,8 @@ thunar_uca_model_parse_argv (ThunarUcaModel *uca_model,
goto error;
dirname = g_path_get_dirname (path);
- quoted = g_shell_quote (dirname);
- g_string_append (command_line, quoted);
+ xfce_append_quoted (command_line, dirname);
g_free (dirname);
- g_free (quoted);
g_free (path);
}
break;
@@ -1661,9 +1596,7 @@ thunar_uca_model_parse_argv (ThunarUcaModel *uca_model,
if (G_LIKELY (file_infos != NULL))
{
path = thunarx_file_info_get_name (file_infos->data);
- quoted = g_shell_quote (path);
- g_string_append (command_line, quoted);
- g_free (quoted);
+ xfce_append_quoted (command_line, path);
g_free (path);
}
break;
@@ -1675,15 +1608,14 @@ thunar_uca_model_parse_argv (ThunarUcaModel *uca_model,
g_string_append_c (command_line, ' ');
path = thunarx_file_info_get_name (lp->data);
- quoted = g_shell_quote (path);
- g_string_append (command_line, quoted);
- g_free (quoted);
+ xfce_append_quoted (command_line, path);
g_free (path);
}
break;
- case '%':
+ default:
g_string_append_c (command_line, '%');
+ g_string_append_c (command_line, *p);
break;
}
}
@@ -1693,6 +1625,16 @@ thunar_uca_model_parse_argv (ThunarUcaModel *uca_model,
}
}
+ /* expand the non deprecated field codes */
+ for (lp = file_infos; lp != NULL; lp = lp->next)
+ uri_list = g_slist_prepend (uri_list, thunarx_file_info_get_uri (lp->data));
+ uri_list = g_slist_reverse (uri_list);
+
+ expanded = xfce_expand_desktop_entry_field_codes (command_line->str, uri_list,
+ NULL, NULL, NULL, FALSE);
+ g_string_free (command_line, TRUE);
+ g_slist_free_full (uri_list, g_free);
+
/* we run the command using the bourne shell (or the systems
* replacement for the bourne shell), so environment variables
* and backticks can be used for the action commands.
@@ -1701,7 +1643,7 @@ thunar_uca_model_parse_argv (ThunarUcaModel *uca_model,
(*argvp) = g_new (gchar *, 4);
(*argvp)[0] = g_strdup (_PATH_BSHELL);
(*argvp)[1] = g_strdup ("-c");
- (*argvp)[2] = g_string_free (command_line, FALSE);
+ (*argvp)[2] = expanded;
(*argvp)[3] = NULL;
return TRUE;