diff options
author | Tamaranch <138-Tamaranch@users.noreply.gitlab.xfce.org> | 2020-07-08 12:14:37 +0200 |
---|---|---|
committer | Alexander Schwinn <alexxcons@xfce.org> | 2020-07-21 22:27:40 +0200 |
commit | ee7a2461e21cef030d727e670802296a17f646a6 (patch) | |
tree | 9b4fa2eff619333e41500290762d00646841db8d | |
parent | f7cb80ea92556caad148e1c4ca9e8346d4bb3fe9 (diff) | |
download | thunar-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
-rw-r--r-- | configure.ac.in | 2 | ||||
-rw-r--r-- | plugins/thunar-uca/thunar-uca-model.c | 100 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | thunar/Makefile.am | 2 | ||||
-rw-r--r-- | thunar/thunar-exec.c | 212 | ||||
-rw-r--r-- | thunar/thunar-exec.h | 41 | ||||
-rw-r--r-- | thunar/thunar-file.c | 19 |
7 files changed, 37 insertions, 340 deletions
diff --git a/configure.ac.in b/configure.ac.in index 6f4e0e7a..0659fc38 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -152,7 +152,7 @@ XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.42.0]) XDT_CHECK_PACKAGE([GMODULE], [gmodule-2.0], [2.42.0]) XDT_CHECK_PACKAGE([GTK], [gtk+-3.0], [3.22.0]) XDT_CHECK_PACKAGE([GDK_PIXBUF], [gdk-pixbuf-2.0], [2.14.0]) -XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.12.0]) +XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.15.2]) XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-2], [4.15.3]) XDT_CHECK_PACKAGE([LIBXFCE4KBD_PRIVATE], [libxfce4kbd-private-3], [4.12.0]) XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.12.0]) 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; diff --git a/po/POTFILES.in b/po/POTFILES.in index 148e70d4..f4f63073 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -20,7 +20,6 @@ thunar/thunar-dialogs.c thunar/thunar-dnd.c thunar/thunar-emblem-chooser.c thunar/thunar-enum-types.c -thunar/thunar-exec.c thunar/thunar-file.c thunar/thunar-file-monitor.c thunar/thunar-folder.c diff --git a/thunar/Makefile.am b/thunar/Makefile.am index dbbaffc9..c69d7cc0 100644 --- a/thunar/Makefile.am +++ b/thunar/Makefile.am @@ -83,8 +83,6 @@ thunar_SOURCES = \ thunar-emblem-chooser.h \ thunar-enum-types.c \ thunar-enum-types.h \ - thunar-exec.c \ - thunar-exec.h \ thunar-file.c \ thunar-file.h \ thunar-file-monitor.c \ diff --git a/thunar/thunar-exec.c b/thunar/thunar-exec.c deleted file mode 100644 index 685783c0..00000000 --- a/thunar/thunar-exec.c +++ /dev/null @@ -1,212 +0,0 @@ -/* vi:set et ai sw=2 sts=2 ts=2: */ -/*- - * Copyright (c) 2005-2007 Benedikt Meurer <benny@xfce.org> - * Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <gio/gio.h> - -#include <thunar/thunar-exec.h> -#include <thunar/thunar-private.h> - - - -static void te_string_append_quoted (GString *string, - const gchar *unquoted); -static gboolean te_string_append_quoted_file (GString *string, - GFile *file, - GError **error); -static void te_string_append_quoted_uri (GString *string, - GFile *file); - - - -static void -te_string_append_quoted (GString *string, - const gchar *unquoted) -{ - gchar *quoted; - - quoted = g_shell_quote (unquoted); - g_string_append (string, quoted); - g_free (quoted); -} - - - -static gboolean -te_string_append_quoted_file (GString *string, - GFile *file, - GError **error) -{ - gboolean success = FALSE; - gchar *path; - - /* append the absolute, local, quoted path to the string */ - path = g_file_get_path (file); - if (G_LIKELY (path != NULL)) - { - te_string_append_quoted (string, path); - success = TRUE; - g_free (path); - } - - return success; -} - - - -static void -te_string_append_quoted_uri (GString *string, - GFile *file) -{ - gchar *uri; - - /* append the quoted URI for the path */ - uri = g_file_get_uri (file); - te_string_append_quoted (string, uri); - g_free (uri); -} - - - -/** - * thunar_exec_parse: - * @exec : the value of the <literal>Exec</literal> field. - * @file_list : the list of #GFile<!---->s. - * @icon : value of the <literal>Icon</literal> field or %NULL. - * @name : translated value for the <literal>Name</literal> field or %NULL. - * @path : full path to the desktop file or %NULL. - * @terminal : whether to execute the command in a terminal. - * @argc : return location for the number of items placed into @argv. - * @argv : return location for the argument vector. - * @error : return location for errors or %NULL. - * - * Substitutes <literal>Exec</literal> parameter variables according - * to the <ulink href="https://freedesktop.org/wiki/Specifications/desktop-entry-spec" - * type="http">Desktop Entry Specification</ulink> and returns the - * parsed argument vector (in @argv) and the number of items placed - * into @argv (in @argc). - * - * The @icon, @name and @path fields are optional and may be %NULL - * if you don't know their values. The @icon parameter should be - * the value of the <literal>Icon</literal> field from the desktop - * file, the @name parameter should be the translated <literal>Name</literal> - * value, while the @path parameter should refer to the full path - * to the desktop file, whose <literal>Exec</literal> field is - * being parsed here. - * - * Return value: %TRUE on success, else %FALSE. - **/ -gboolean -thunar_exec_parse (const gchar *exec, - GList *file_list, - const gchar *icon, - const gchar *name, - const gchar *uri, - gboolean terminal, - gint *argc, - gchar ***argv, - GError **error) -{ - const gchar *p; - gboolean result = FALSE; - GString *command_line = g_string_new (NULL); - GList *lp; - - /* prepend terminal command if required */ - if (G_UNLIKELY (terminal)) - g_string_append (command_line, "exo-open --launch TerminalEmulator "); - - for (p = exec; *p != '\0'; ++p) - { - if (p[0] == '%' && p[1] != '\0') - { - switch (*++p) - { - case 'f': - /* append the absolute local path of the first path object */ - if (file_list != NULL && !te_string_append_quoted_file (command_line, file_list->data, error)) - goto done; - break; - - case 'F': - for (lp = file_list; lp != NULL; lp = lp->next) - { - if (G_LIKELY (lp != file_list)) - g_string_append_c (command_line, ' '); - if (!te_string_append_quoted_file (command_line, lp->data, error)) - goto done; - } - break; - - case 'u': - if (G_LIKELY (file_list != NULL)) - te_string_append_quoted_uri (command_line, file_list->data); - break; - - case 'U': - for (lp = file_list; lp != NULL; lp = lp->next) - { - if (G_LIKELY (lp != file_list)) - g_string_append_c (command_line, ' '); - te_string_append_quoted_uri (command_line, lp->data); - } - break; - - case 'i': - if (G_LIKELY (icon != NULL)) - { - g_string_append (command_line, "--icon "); - te_string_append_quoted (command_line, icon); - } - break; - - case 'c': - if (G_LIKELY (name != NULL)) - te_string_append_quoted (command_line, name); - break; - - case 'k': - if (G_LIKELY (uri != NULL)) - te_string_append_quoted (command_line, uri); - break; - - case '%': - g_string_append_c (command_line, '%'); - break; - } - } - else - { - g_string_append_c (command_line, *p); - } - } - - result = g_shell_parse_argv (command_line->str, argc, argv, error); - -done: - g_string_free (command_line, TRUE); - return result; -} diff --git a/thunar/thunar-exec.h b/thunar/thunar-exec.h deleted file mode 100644 index 449d6286..00000000 --- a/thunar/thunar-exec.h +++ /dev/null @@ -1,41 +0,0 @@ -/* vi:set et ai sw=2 sts=2 ts=2: */ -/*- - * Copyright (c) 2005-2007 Benedikt Meurer <benny@xfce.org> - * Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __THUNAR_EXEC_H__ -#define __THUNAR_EXEC_H__ - -#include <gdk/gdk.h> - -G_BEGIN_DECLS; - -gboolean thunar_exec_parse (const gchar *exec, - GList *path_list, - const gchar *icon, - const gchar *name, - const gchar *path, - gboolean terminal, - gint *argc, - gchar ***argv, - GError **error); - -G_END_DECLS; - -#endif /* !__THUNAR_EXEC_H__ */ diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 8def7dcc..279e8918 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -57,7 +57,6 @@ #include <thunar/thunar-application.h> #include <thunar/thunar-chooser-dialog.h> -#include <thunar/thunar-exec.h> #include <thunar/thunar-file.h> #include <thunar/thunar-file-monitor.h> #include <thunar/thunar-gio-extensions.h> @@ -1591,6 +1590,8 @@ thunar_file_execute (ThunarFile *file, GKeyFile *key_file; GError *err = NULL; GFile *file_parent; + GList *li; + GSList *uri_list = NULL; gchar *icon_name = NULL; gchar *name; gchar *type; @@ -1599,6 +1600,7 @@ thunar_file_execute (ThunarFile *file, gchar *escaped_location; gchar **argv = NULL; gchar *exec; + gchar *command; gchar *directory = NULL; gboolean is_secure = FALSE; guint32 stimestamp = 0; @@ -1607,6 +1609,9 @@ thunar_file_execute (ThunarFile *file, _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE); location = thunar_g_file_get_location (file->gfile); + for (li = file_list; li != NULL; li = li->next) + uri_list = g_slist_prepend (uri_list, g_file_get_uri (li->data)); + uri_list = g_slist_reverse (uri_list); if (thunar_file_is_desktop_file (file, &is_secure)) { @@ -1636,9 +1641,12 @@ thunar_file_execute (ThunarFile *file, terminal = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL); snotify = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY, NULL); - result = thunar_exec_parse (exec, file_list, icon_name, name, location, terminal, NULL, &argv, error); - + /* expand the field codes and parse the execute command */ + command = xfce_expand_desktop_entry_field_codes (exec, uri_list, icon_name, + name, location, terminal); g_free (name); + result = g_shell_parse_argv (command, NULL, &argv, error); + g_free (command); } else { @@ -1693,9 +1701,11 @@ thunar_file_execute (ThunarFile *file, /* fake the Exec line */ escaped_location = g_shell_quote (location); exec = g_strconcat (escaped_location, " %F", NULL); - result = thunar_exec_parse (exec, file_list, NULL, NULL, NULL, FALSE, NULL, &argv, error); + command = xfce_expand_desktop_entry_field_codes (exec, uri_list, NULL, NULL, NULL, FALSE); + result = g_shell_parse_argv (command, NULL, &argv, error); g_free (escaped_location); g_free (exec); + g_free (command); } if (G_LIKELY (result && argv != NULL)) @@ -1756,6 +1766,7 @@ thunar_file_execute (ThunarFile *file, } /* clean up */ + g_slist_free_full (uri_list, g_free); g_strfreev (argv); g_free (location); g_free (directory); |