diff options
author | Yongha Hwang <mshrimp@sogang.ac.kr> | 2022-03-02 02:25:59 +0000 |
---|---|---|
committer | Yongha Hwang <mshrimp@sogang.ac.kr> | 2022-03-02 02:25:59 +0000 |
commit | f88ad83278d02b5ad5f21b80a4da558a7f410324 (patch) | |
tree | a7534daf0e46c15938ef40c17a9b534e928935b8 | |
parent | d788acc0610b098c60bcee43d0355fd0de0a9aa1 (diff) | |
download | exo-f88ad83278d02b5ad5f21b80a4da558a7f410324.tar.gz |
MR !50
Related: #69
Type=Link should be treated as exo-open (URL entry). Relative links are
resolved with respect to a directory where the .desktop is located.
-rw-r--r-- | exo-open/main.c | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/exo-open/main.c b/exo-open/main.c index a471c78..8ec347e 100644 --- a/exo-open/main.c +++ b/exo-open/main.c @@ -31,6 +31,7 @@ #endif #include <glib/gstdio.h> +#include <glib.h> #include <gio/gio.h> #ifdef HAVE_GIO_UNIX #include <gio/gdesktopappinfo.h> @@ -38,6 +39,7 @@ #include <exo/exo.h> + #define USERCHARS "-[:alnum:]" #define USERCHARS_CLASS "[" USERCHARS "]" #define PASSCHARS_CLASS "[-[:alnum:]\\Q,?;.:/!%$^*&~\"#'\\E]" @@ -103,6 +105,21 @@ static KnownSchemes known_schemes[] = +/* Prototypes */ +static void usage (void); +static gboolean exo_open_launch_desktop_file (const gchar *arg); +static gchar *exo_open_get_path (const gchar *string); +static gchar *exo_open_find_scheme (const gchar *string); +static gboolean exo_open_launch_category (const gchar *category, + const gchar *parameters); +static gboolean exo_open_uri_known_category (const gchar *uri, + const gchar *scheme, + gboolean *succeed); +static gboolean exo_open_uri (const gchar *uri, + GError **error); + + + static void usage (void) { @@ -145,6 +162,11 @@ exo_open_launch_desktop_file (const gchar *arg) { #ifdef HAVE_GIO_UNIX GFile *gfile; + GFile *parent; + gchar *type; + gchar *link; + gchar *abs_path; + gchar *file_dir; gchar *contents; gsize length; gboolean result; @@ -158,7 +180,6 @@ exo_open_launch_desktop_file (const gchar *arg) /* load the contents of the file */ result = g_file_load_contents (gfile, NULL, &contents, &length, NULL, NULL); - g_object_unref (G_OBJECT (gfile)); if (G_UNLIKELY (!result || length == 0)) return FALSE; @@ -172,6 +193,42 @@ exo_open_launch_desktop_file (const gchar *arg) return FALSE; } + /* try to launch "Link" type .desktop file */ + type = g_key_file_get_value (key_file, + G_KEY_FILE_DESKTOP_GROUP, + G_KEY_FILE_DESKTOP_KEY_TYPE, + NULL); + if (g_strcmp0 (type, G_KEY_FILE_DESKTOP_TYPE_LINK) == 0) + { + link = g_key_file_get_value (key_file, + G_KEY_FILE_DESKTOP_GROUP, + G_KEY_FILE_DESKTOP_KEY_URL, + NULL); + if (!exo_str_looks_like_an_uri (link)) + { + parent = g_file_get_parent (gfile); + file_dir = g_file_get_path (parent); + g_object_unref (parent); + abs_path = g_build_filename (file_dir, link, NULL); + g_free (file_dir); + g_free (link); + link = exo_open_find_scheme (abs_path); + g_free (abs_path); + } + result = exo_open_uri (link, NULL); + g_free (link); + } + else + result = FALSE; + g_free (type); + g_object_unref (G_OBJECT (gfile)); + + if (result) + { + g_key_file_free (key_file); + return TRUE; + } + /* create the appinfo */ appinfo = g_desktop_app_info_new_from_keyfile (key_file); g_key_file_free (key_file); @@ -460,7 +517,7 @@ main (gint argc, gchar **argv) GtkWidget *message_area; GtkWidget *label; GError *err = NULL; - gchar *parameter, *quoted; + gchar *parameter; gint result = EXIT_SUCCESS; GString *join; guint i; @@ -515,15 +572,9 @@ main (gint argc, gchar **argv) * arguments to be merged, this is a bit of magic to make * common cares work property, see sample above with xfrun4 */ if (argc > 2 && strchr (argv[i], ' ') != NULL) - { - quoted = g_shell_quote (argv[i]); - join = g_string_append (join, quoted); - g_free (quoted); - } + xfce_g_string_append_quoted (join, argv[i]); else - { - join = g_string_append (join, argv[i]); - } + g_string_append (join, argv[i]); } parameter = g_string_free (join, FALSE); } |