diff options
author | Daniel Carl <danielcarl@gmx.de> | 2017-11-05 22:55:28 +0100 |
---|---|---|
committer | Daniel Carl <danielcarl@gmx.de> | 2017-11-05 22:55:28 +0100 |
commit | ee984e69e0eb0d0bb436043432d73536dc859f93 (patch) | |
tree | ebe1e031217034b51d6848fa91e36c45d59a11df /src | |
parent | f2d82ed0c22249b0cfeab8015ab44488d24986d6 (diff) |
Use suggested file name from uri on :save #449
Get some auto suggested download file name if a page is going to be
saved by :save command.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -20,6 +20,7 @@ #include <gdk/gdkx.h> #include <gtk/gtk.h> #include <gtk/gtkx.h> +#include <libsoup/soup.h> #include <limits.h> #include <stdlib.h> #include <string.h> @@ -113,12 +114,19 @@ struct Vimb vb; gboolean vb_download_set_destination(Client *c, WebKitDownload *download, char *suggested_filename, const char *path) { - char *download_path, *dir, *file, *uri; + char *download_path, *dir, *file, *uri, *basename = NULL, + *decoded_uri = NULL; + const char *download_uri; download_path = GET_CHAR(c, "download-path"); - /* For unnamed downloads set default filename. */ if (!suggested_filename || !*suggested_filename) { - suggested_filename = "vimb-download"; + /* Try to find a matching name if there is no suggested filename. */ + download_uri = webkit_uri_request_get_uri(webkit_download_get_request(download)); + decoded_uri = soup_uri_decode(download_uri); + basename = g_filename_display_basename(decoded_uri); + g_free(decoded_uri); + + suggested_filename = basename; } /* Prepare the path to save the download. */ @@ -135,6 +143,8 @@ gboolean vb_download_set_destination(Client *c, WebKitDownload *download, file = util_build_path(c, suggested_filename, download_path); } + g_free(basename); + if (!file) { return FALSE; } |