From 1da904bf3db627e7a289a0576a583dfe1eb54e54 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Fri, 30 Apr 2004 09:19:46 +0000 Subject: [PATCH] r3487: Added 'Download handler' to drag and drop options. This program is invoked when a URI is dragged to the filer (eg, from a web-browser). The default command runs wget to download the file (Andrew Flegg). --- ROX-Filer/Help/Changes | 6 ++++++ ROX-Filer/Options.xml | 5 +++++ ROX-Filer/src/dnd.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/ROX-Filer/Help/Changes b/ROX-Filer/Help/Changes index 95c6766b..cd560f5e 100644 --- a/ROX-Filer/Help/Changes +++ b/ROX-Filer/Help/Changes @@ -2,6 +2,12 @@ A RISC OS-like filer for X by Thomas Leonard +29-Apr-2004 +~~~~~~~~~~~ +Added 'Download handler' to drag and drop options. This program is invoked +when a URI is dragged to the filer (eg, from a web-browser). The default +command runs wget to download the file (Andrew Flegg). + 27-Apr-2004 ~~~~~~~~~~~ Bugfix: URIs received through drag-and-drop were unescaped twice, causing diff --git a/ROX-Filer/Options.xml b/ROX-Filer/Options.xml index f70265c7..1e010655 100644 --- a/ROX-Filer/Options.xml +++ b/ROX-Filer/Options.xml @@ -252,6 +252,11 @@ operation, such as copying or deleting some files. Note that you can still get the menu to appear, by dragging with the left button and holding down the Alt key. + + When you drag a file from a web browser or other remote source, this program will be run to download it. $1 is the URI +dragged to the filer, and the current directory is the destination. Eg: +xterm -e wget $1 +
diff --git a/ROX-Filer/src/dnd.c b/ROX-Filer/src/dnd.c index c45a3d73..578474cf 100644 --- a/ROX-Filer/src/dnd.c +++ b/ROX-Filer/src/dnd.c @@ -148,6 +148,7 @@ Option o_dnd_spring_open; static Option o_dnd_spring_delay; static Option o_dnd_middle_menu; Option o_dnd_left_menu; +static Option o_dnd_uri_handler; void dnd_init(void) { @@ -164,6 +165,9 @@ void dnd_init(void) option_add_int(&o_dnd_spring_delay, "dnd_spring_delay", 400); option_add_int(&o_dnd_left_menu, "dnd_left_menu", TRUE); option_add_int(&o_dnd_middle_menu, "dnd_middle_menu", TRUE); + + option_add_string(&o_dnd_uri_handler, "dnd_uri_handler", + "xterm -e wget $1"); } /* SUPPORT FUNCTIONS */ @@ -881,10 +885,32 @@ static gboolean uri_is_local(const char *uri) return TRUE; } +/* Run the shell command 'command', replacing $1 with 'arg' */ +static void run_with_argument(const char *dir, + const char *command, + const char *arg) +{ + GPtrArray *argv; + + argv = g_ptr_array_new(); + + g_ptr_array_add(argv, "sh"); + g_ptr_array_add(argv, "-c"); + g_ptr_array_add(argv, (char *) command); + g_ptr_array_add(argv, "sh"); + g_ptr_array_add(argv, (char *) arg); + g_ptr_array_add(argv, NULL); + + rox_spawn(dir, (const gchar **) argv->pdata); + + g_ptr_array_free(argv, TRUE); +} + /* We've got a list of URIs from somewhere (probably another filer window). * If the files are on the local machine then try to copy them ourselves, * otherwise, if there was only one file and application/octet-stream was * provided, get the data via the X server. + * For http:, https: or ftp: schemes, use the download handler. */ static void got_uri_list(GtkWidget *widget, GdkDragContext *context, @@ -939,7 +965,15 @@ static void got_uri_list(GtkWidget *widget, application_octet_stream, time); send_reply = FALSE; } - else + else if ((strncasecmp(uri_list->data, "http:", 5) == 0) || + (strncasecmp(uri_list->data, "https:", 6) == 0) || + (strncasecmp(uri_list->data, "ftp:", 4) == 0)) + { + run_with_argument(dest_path, + o_dnd_uri_handler.value, + uri_list->data); + } + else error = _("Can't get data from remote machine " "(application/octet-stream not provided)"); } -- 2.11.4.GIT