From 0babb954fbe6c732aa896bcc2aa5316c1d4483ca Mon Sep 17 00:00:00 2001 From: MShrimp4 Date: Mon, 28 Feb 2022 21:32:19 +0900 Subject: [PATCH 1/5] Try to open Type=Link .desktop files Related: exo#69 --- exo-open/main.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/exo-open/main.c b/exo-open/main.c index a471c788..75ad9a7f 100644 --- a/exo-open/main.c +++ b/exo-open/main.c @@ -103,6 +103,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 +160,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 +178,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 +191,39 @@ 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, "Desktop Entry", "Type", NULL); + g_info ("Type: %s\n", type); + if (g_strcmp0 (type, "Link") == 0) + { + link = g_key_file_get_value (key_file, "Desktop Entry", "URL", NULL); + if (!exo_str_looks_like_an_uri (link)) + { + /* TODO: xfce_g_file_get_parent_path() */ + 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); + } + g_info ("URL: %s\n", link); + 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); -- GitLab From 3ed7e5595eea5d9b6d2923b19c8d5c9abfd76640 Mon Sep 17 00:00:00 2001 From: MShrimp4 Date: Mon, 28 Feb 2022 21:49:48 +0900 Subject: [PATCH 2/5] Use xfce_g_string_append_quoted () --- exo-open/main.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/exo-open/main.c b/exo-open/main.c index 75ad9a7f..6b36ae02 100644 --- a/exo-open/main.c +++ b/exo-open/main.c @@ -512,7 +512,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; @@ -567,15 +567,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); } -- GitLab From 5ec4fa481df1c07b669c70bbd55cd3b09f63f6dc Mon Sep 17 00:00:00 2001 From: MShrimp4 Date: Mon, 28 Feb 2022 22:31:27 +0900 Subject: [PATCH 3/5] USE G_KEY_FILE_* where applicable --- exo-open/main.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/exo-open/main.c b/exo-open/main.c index 6b36ae02..45654b23 100644 --- a/exo-open/main.c +++ b/exo-open/main.c @@ -31,6 +31,7 @@ #endif #include +#include #include #ifdef HAVE_GIO_UNIX #include @@ -192,11 +193,17 @@ exo_open_launch_desktop_file (const gchar *arg) } /* try to launch link type .desktop file */ - type = g_key_file_get_value (key_file, "Desktop Entry", "Type", NULL); + type = g_key_file_get_value (key_file, + G_KEY_FILE_DESKTOP_GROUP, + G_KEY_FILE_DESKTOP_KEY_TYPE, + NULL); g_info ("Type: %s\n", type); - if (g_strcmp0 (type, "Link") == 0) + if (g_strcmp0 (type, G_KEY_FILE_DESKTOP_TYPE_LINK) == 0) { - link = g_key_file_get_value (key_file, "Desktop Entry", "URL", NULL); + 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)) { /* TODO: xfce_g_file_get_parent_path() */ -- GitLab From cbdaf4d865b79b269cf6ef1421e8ccde7865a4f3 Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Mon, 28 Feb 2022 23:45:12 +0000 Subject: [PATCH 4/5] Typo --- exo-open/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exo-open/main.c b/exo-open/main.c index 45654b23..e14e7075 100644 --- a/exo-open/main.c +++ b/exo-open/main.c @@ -213,7 +213,7 @@ exo_open_launch_desktop_file (const gchar *arg) abs_path = g_build_filename (file_dir, link, NULL); g_free (file_dir); g_free (link); - link = exo_open_find_scheme(abs_path); + link = exo_open_find_scheme (abs_path); g_free (abs_path); } g_info ("URL: %s\n", link); -- GitLab From aa204febb96db755a31e5b78bb3134a7a0791dc2 Mon Sep 17 00:00:00 2001 From: MShrimp4 Date: Tue, 1 Mar 2022 08:57:27 +0900 Subject: [PATCH 5/5] Remove test purpose code / comments --- exo-open/main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/exo-open/main.c b/exo-open/main.c index e14e7075..8ec347ea 100644 --- a/exo-open/main.c +++ b/exo-open/main.c @@ -39,6 +39,7 @@ #include + #define USERCHARS "-[:alnum:]" #define USERCHARS_CLASS "[" USERCHARS "]" #define PASSCHARS_CLASS "[-[:alnum:]\\Q,?;.:/!%$^*&~\"#'\\E]" @@ -192,12 +193,11 @@ exo_open_launch_desktop_file (const gchar *arg) return FALSE; } - /* try to launch link type .desktop file */ + /* 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); - g_info ("Type: %s\n", type); if (g_strcmp0 (type, G_KEY_FILE_DESKTOP_TYPE_LINK) == 0) { link = g_key_file_get_value (key_file, @@ -206,7 +206,6 @@ exo_open_launch_desktop_file (const gchar *arg) NULL); if (!exo_str_looks_like_an_uri (link)) { - /* TODO: xfce_g_file_get_parent_path() */ parent = g_file_get_parent (gfile); file_dir = g_file_get_path (parent); g_object_unref (parent); @@ -216,7 +215,6 @@ exo_open_launch_desktop_file (const gchar *arg) link = exo_open_find_scheme (abs_path); g_free (abs_path); } - g_info ("URL: %s\n", link); result = exo_open_uri (link, NULL); g_free (link); } -- GitLab