From 9241afa0dba654b19649a802e22ddc99ffb27656 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 12 May 2010 23:54:24 +0200 Subject: [PATCH] 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 692cd5c1..86612863 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(); + 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 "; return extension; } diff --git a/midori/midori-view.c b/midori/midori-view.c index bf6e1fc2..ea23e8b5 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; } -- 2.39.5