[Xfce4-commits] <midori:master> Implement FTP support in External Applications

Christian Dywan noreply at xfce.org
Thu May 13 01:10:03 CEST 2010


Updating branch refs/heads/master
         to 9241afa0dba654b19649a802e22ddc99ffb27656 (commit)
       from 969c225c3b7735f314ed675fc49019efe478a7c5 (commit)

commit 9241afa0dba654b19649a802e22ddc99ffb27656
Author: Christian Dywan <christian at twotoasts.de>
Date:   Wed May 12 23:54:24 2010 +0200

    Implement FTP support in External Applications
    
    For the moment 'gftp' is hardcoded for ftp://.

 extensions/external-applications.vala |   38 ++++++++++++++++++++++++++++++--
 midori/midori-view.c                  |    1 -
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/extensions/external-applications.vala b/extensions/external-applications.vala
index 692cd5c..8661286 100644
--- a/extensions/external-applications.vala
+++ b/extensions/external-applications.vala
@@ -10,12 +10,44 @@
 */
 
 using Gtk;
+using WebKit;
 using Midori;
 
 public class ExternalApplications : Midori.Extension {
     Dialog? dialog;
-    void tab_added (Widget tab) {
-        /* */
+    bool launch (string command, string uri) {
+        try {
+            var info = GLib.AppInfo.create_from_commandline (command, null, 0);
+            var uris = new List<string>();
+            uris.prepend (uri);
+            info.launch_uris (uris, null);
+            return true;
+        }
+        catch (GLib.Error error) {
+            var error_dialog = new Gtk.MessageDialog (null, 0,
+                Gtk.MessageType.ERROR, Gtk.ButtonsType.OK,
+                "Failed to launch external application.");
+            error_dialog.format_secondary_text (error.message);
+            error_dialog.response.connect ((dialog, response)
+                => { dialog.destroy (); });
+            error_dialog.show ();
+        }
+        return false;
+    }
+    bool navigating (WebFrame web_frame, NetworkRequest request,
+                     WebNavigationAction action, WebPolicyDecision decision) {
+        string uri = request.get_uri ();
+        if (uri.has_prefix ("ftp://")) {
+            if (launch ("gftp", uri)) {
+                decision.ignore ();
+                return true;
+            }
+        }
+        return false;
+    }
+    void tab_added (View tab) {
+        var web_view = tab.get_web_view ();
+        web_view.navigation_policy_decision_requested.connect (navigating);
     }
     void configure_external_applications () {
         if (dialog == null) {
@@ -68,7 +100,7 @@ public Midori.Extension extension_init () {
     extension.name = "External Applications";
     extension.description = "Lalala";
     extension.version = "0.1";
-    extension.authors = "nobody";
+    extension.authors = "Christian Dywan <christian at twotoasts.de>";
     return extension;
 }
 
diff --git a/midori/midori-view.c b/midori/midori-view.c
index bf6e1fc..ea23e8b 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -966,7 +966,6 @@ midori_view_web_view_navigation_decision_cb (WebKitWebView*             web_view
             return TRUE;
         }
     }
-    /* TODO: Handle more external protocols */
     view->special = FALSE;
     return FALSE;
 }



More information about the Xfce4-commits mailing list