[Xfce4-commits] <midori:master> Use GAppInfo to spawn programs and support tokens like %f or %u

Christian Dywan noreply at xfce.org
Mon Nov 2 22:08:02 CET 2009


Updating branch refs/heads/master
         to 4fbbc43e421d8f7649a3c9cab8d9c50cf8405e29 (commit)
       from e98298597666efab2a9d22f45681a53ea083e8ec (commit)

commit 4fbbc43e421d8f7649a3c9cab8d9c50cf8405e29
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Nov 2 22:00:30 2009 +0100

    Use GAppInfo to spawn programs and support tokens like %f or %u

 midori/sokoke.c |   32 +++++++++++++-------------------
 1 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/midori/sokoke.c b/midori/sokoke.c
index 94099d9..cc50277 100644
--- a/midori/sokoke.c
+++ b/midori/sokoke.c
@@ -147,41 +147,35 @@ sokoke_spawn_program (const gchar* command,
                       gboolean     quote)
 {
     gchar* argument_escaped;
-    gchar* command_ready;
-    gchar** argv;
+    GAppInfo* info;
+    GFile* file;
+    GList* files;
     GError* error;
 
     g_return_val_if_fail (command != NULL, FALSE);
     g_return_val_if_fail (argument != NULL, FALSE);
 
     argument_escaped = quote ? g_shell_quote (argument) : g_strdup (argument);
-    if (strstr (command, "%s"))
-        command_ready = g_strdup_printf (command, argument_escaped);
-    else
-        command_ready = g_strconcat (command, " ", argument_escaped, NULL);
+
+    info = g_app_info_create_from_commandline (command,
+        NULL, G_APP_INFO_CREATE_NONE, NULL);
+    file = g_file_new_for_commandline_arg (argument_escaped);
+    files = g_list_append (NULL, file);
 
     error = NULL;
-    if (!g_shell_parse_argv (command_ready, NULL, &argv, &error))
+    if (!g_app_info_launch (info, files, NULL, &error))
     {
         error_dialog (_("Could not run external program."), error->message);
         g_error_free (error);
-        g_free (command_ready);
         g_free (argument_escaped);
+        g_object_unref (file);
+        g_list_free (files);
         return FALSE;
     }
 
-    error = NULL;
-    if (!g_spawn_async (NULL, argv, NULL,
-        (GSpawnFlags)G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
-        NULL, NULL, NULL, &error))
-    {
-        error_dialog (_("Could not run external program."), error->message);
-        g_error_free (error);
-    }
-
-    g_strfreev (argv);
-    g_free (command_ready);
     g_free (argument_escaped);
+    g_object_unref (file);
+    g_list_free (files);
     return TRUE;
 }
 



More information about the Xfce4-commits mailing list