From: Hans-Peter D. <Han...@in...> - 2012-02-02 11:40:04
|
--- config.h | 2 ++ main.c | 25 ++++++++++++++++++++++++- vimprobable2.1 | 4 ++++ 3 files changed, 30 insertions(+), 1 deletions(-) diff --git a/config.h b/config.h index b2f8e78..c0c618b 100644 --- a/config.h +++ b/config.h @@ -120,6 +120,8 @@ Command commands[COMMANDSIZE] = { { "bma", bookmark, {0} }, { "bookmark", bookmark, {0} }, { "source", view_source, {0} }, + { "w", save_page, {0} }, + { "write", save_page, {0} }, { "set", browser_settings, {0} }, { "map", mappings, {0} }, { "jumpleft", scroll, {ScrollJumpTo | DirectionLeft} }, diff --git a/main.c b/main.c index f106245..99ccad7 100644 --- a/main.c +++ b/main.c @@ -77,6 +77,7 @@ static gboolean yank(const Arg *arg); static gboolean view_source(const Arg * arg); static gboolean zoom(const Arg *arg); static gboolean fake_key_event(const Arg *arg); +static gboolean save_page(const Arg *arg); static void update_url(const char *uri); static void setup_modkeys(void); @@ -280,7 +281,9 @@ webview_download_cb(WebKitWebView *webview, WebKitDownload *download, gpointer u WebKitDownloadStatus status; filename = webkit_download_get_suggested_filename(download); - if (filename == NULL || strlen(filename) == 0) { + if (user_data) { + filename = (const char*)user_data; + } else if (filename == NULL || strlen(filename) == 0) { filename = "vimprobable_download"; } path = g_build_filename(g_strdup_printf(DOWNLOADS_PATH), filename, NULL); @@ -1637,6 +1640,26 @@ fake_key_event(const Arg *a) { return TRUE; } +gboolean +save_page(const Arg *arg) { + WebKitNetworkRequest *request; + WebKitDownload *download; + const char *uri = webkit_web_view_get_uri(webview); + const char *destination = NULL; + + if (uri == NULL || *uri == '\0') { + set_error("No URI found to save."); + return FALSE; + } + + request = webkit_network_request_new(uri); + download = webkit_download_new(request); + if (arg->s && *arg->s) { + destination = arg->s; + } + webview_download_cb(webview, download, (gpointer *)destination); + return TRUE; +} gboolean commandhistoryfetch(const Arg *arg) { diff --git a/vimprobable2.1 b/vimprobable2.1 index a780e6a..0a8cb79 100644 --- a/vimprobable2.1 +++ b/vimprobable2.1 @@ -254,6 +254,10 @@ Shortcut: d Print the current URL +.IP ":w[rite] [filename]" + +Save the current document. + .SH MODES Vimprobable is a modal browser. By default, it is in command mode, meaning that -- 1.7.2.5 |
From: Hans-Peter D. <Han...@in...> - 2012-02-02 11:39:59
|
The suggested filename doesn't have to be the actual destination, e.g. for 'vimprobable_download' downloads or when the user gives a custom filename to :write. There is a downside though: webkit_download_get_destination_uri() returns an absolute path with 'file://' prefix, which is quite verbose. --- main.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 99ccad7..c377085 100644 --- a/main.c +++ b/main.c @@ -321,11 +321,11 @@ download_progress(WebKitDownload *d, GParamSpec *pspec) { if (status != WEBKIT_DOWNLOAD_STATUS_STARTED && status != WEBKIT_DOWNLOAD_STATUS_CREATED) { if (status != WEBKIT_DOWNLOAD_STATUS_FINISHED) { a.i = Error; - a.s = g_strdup_printf("Error while downloading %s", webkit_download_get_suggested_filename(d)); + a.s = g_strdup_printf("Error while downloading %s", webkit_download_get_destination_uri(d)); echo(&a); } else { a.i = Info; - a.s = g_strdup_printf("Download %s finished", webkit_download_get_suggested_filename(d)); + a.s = g_strdup_printf("Download %s finished", webkit_download_get_destination_uri(d)); echo(&a); } g_free(a.s); -- 1.7.2.5 |
From: Hans-Peter D. <Han...@in...> - 2012-02-02 11:40:03
|
--- vimprobable2.1 | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vimprobable2.1 b/vimprobable2.1 index 0a8cb79..b578447 100644 --- a/vimprobable2.1 +++ b/vimprobable2.1 @@ -174,10 +174,10 @@ Generate an :open command with the link's URL (like O) .I " " ;T or ;W Generate an :tabopen command with the link's URL (like T) -.I " " ;s +.I " " ;i Open image in current window -.I " " ;S +.I " " ;I Open image in new window .I " " gi -- 1.7.2.5 |
From: Hannes S. <ha...@yl...> - 2012-02-28 11:08:18
Attachments:
signature.asc
|
Merged this #3. #1 and #2 still seem to be subject to that bug which Daniel reported. |
From: Daniel C. <dan...@gm...> - 2012-02-04 10:58:16
Attachments:
signature.asc
|
Hi Hans-Peter, this is a feature I waited for a long time. But I found a small bug. If I save a page into a none existing path, vimprobable says 'Download file:///home/daniel/foo/foo.html finished' but the foo directory was not created and the file was not downloaded. I think we should test if the download was really done, if not echo a error message in vimprobable. Daniel |
From: Hans-Peter D. <hpd...@gm...> - 2012-02-04 21:44:44
|
Hi, Daniel Carl <dan...@gm...> writes: > this is a feature I waited for a long time. But I found a small bug. If I save > a page into a none existing path, vimprobable says 'Download > file:///home/daniel/foo/foo.html finished' but the foo directory was not > created and the file was not downloaded. I think we should test if the > download was really done, if not echo a error message in vimprobable. Well spotted! I think this is a bug in Webkit. We already check the status of the download in download_process() and print the "finished" message only if it is WEBKIT_DOWNLOAD_STATUS_FINISHED. I also get strange messages like (vimprobable2:5547): GLib-GIO-CRITICAL **: g_output_stream_write_all: assertion `G_IS_OUTPUT_STREAM (stream)' failed if I try to save a page to a nonexistent path. We could work around this by calling access(2) before starting the download. That's a little ugly, but I will prepare a new patch with it. HP |