[Xfce4-commits] <midori:master> Support x-scheme-handler with GLib < 2.28

Christian Dywan noreply at xfce.org
Sat Mar 5 03:40:02 CET 2011


Updating branch refs/heads/master
         to d903505ee652dc4002014479963f9353a8ebf79e (commit)
       from fc8d0a1179a23a6da28e04626a51c8d7a5a43100 (commit)

commit d903505ee652dc4002014479963f9353a8ebf79e
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sat Mar 5 03:38:17 2011 +0100

    Support x-scheme-handler with GLib < 2.28
    
    So for example x-scheme-handler/magnet=transmission-gtk.desktop
    in the file ~/.local/share/applications/mimeapps.list allows
    opening of magnet links with Transmission.

 midori/sokoke.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 53 insertions(+), 7 deletions(-)

diff --git a/midori/sokoke.c b/midori/sokoke.c
index 3eb5932..219fc8f 100644
--- a/midori/sokoke.c
+++ b/midori/sokoke.c
@@ -271,6 +271,34 @@ sokoke_open_with_response_cb (GtkWidget* dialog,
     gtk_widget_destroy (dialog);
 }
 
+static GAppInfo*
+sokoke_default_for_uri (const gchar* uri,
+                        gchar**      scheme_ptr)
+{
+    gchar* scheme;
+    GAppInfo* info;
+
+    scheme = g_uri_parse_scheme (uri);
+    if (scheme_ptr != NULL)
+        *scheme_ptr = scheme;
+    if (!scheme)
+        return NULL;
+
+    info = g_app_info_get_default_for_uri_scheme (scheme);
+    #if !GLIB_CHECK_VERSION (2, 28, 0)
+    if (!info)
+    {
+        gchar* type = g_strdup_printf ("x-scheme-handler/%s", scheme);
+        info = g_app_info_get_default_for_type (type, FALSE);
+        g_free (type);
+    }
+    #endif
+    if (info != NULL && scheme_ptr != NULL)
+        g_free (scheme);
+    return info;
+
+}
+
 /**
  * sokoke_show_uri:
  * @screen: a #GdkScreen, or %NULL
@@ -281,6 +309,7 @@ sokoke_open_with_response_cb (GtkWidget* dialog,
  * Shows the specified URI with an appropriate application. This
  * supports xdg-open, exo-open and gnome-open as fallbacks if
  * GIO doesn't do the trick.
+ * x-scheme-handler is supported for GLib < 2.28 as of 0.3.3.
  *
  * On Maemo, hildon_uri_open() is used.
  *
@@ -364,6 +393,10 @@ sokoke_show_uri (GdkScreen*   screen,
 
     #else
 
+    #if !GLIB_CHECK_VERSION (2, 28, 0)
+    GAppInfo* info;
+    gchar* scheme;
+    #endif
     const gchar* fallbacks [] = { "xdg-open", "exo-open", "gnome-open" };
     gsize i;
     GtkWidget* dialog;
@@ -386,6 +419,25 @@ sokoke_show_uri (GdkScreen*   screen,
         return TRUE;
     #endif
 
+    #if !GLIB_CHECK_VERSION (2, 28, 0)
+    info = sokoke_default_for_uri (uri, &scheme);
+    if (info)
+    {
+        gchar* argument = g_strdup (&uri[scheme - uri]);
+        GList* uris = g_list_prepend (NULL, argument);
+        if (g_app_info_launch_uris (info, uris, NULL, NULL))
+        {
+            g_list_free (uris);
+            g_free (scheme);
+            g_object_unref (info);
+            return TRUE;
+        }
+        g_list_free (uris);
+        g_free (scheme);
+        g_object_unref (info);
+    }
+    #endif
+
     for (i = 0; i < G_N_ELEMENTS (fallbacks); i++)
     {
         gchar* command = g_strconcat (fallbacks[i], " ", uri, NULL);
@@ -756,7 +808,6 @@ sokoke_resolve_hostname (const gchar* hostname)
 gboolean
 sokoke_external_uri (const gchar* uri)
 {
-    gchar* scheme;
     GAppInfo* info;
 
     if (!uri || !strncmp (uri, "http", 4)
@@ -764,12 +815,7 @@ sokoke_external_uri (const gchar* uri)
              || !strncmp (uri, "about:", 6))
         return FALSE;
 
-    scheme = g_uri_parse_scheme (uri);
-    if (!scheme)
-        return FALSE;
-
-    info = g_app_info_get_default_for_uri_scheme (scheme);
-    g_free (scheme);
+    info = sokoke_default_for_uri (uri, NULL);
     if (info)
         g_object_unref (info);
     return info != NULL;



More information about the Xfce4-commits mailing list