completion items, or to focus previous or next hints if hinting is active.
.TP
-.BI run " [COMMAND LIST]"
+.BI "run [" "COMMAND LIST" ]
Run is a command, that was introduced to have the ability to run multiple
other commands with a single call. Everything after the `run' is interpreted
as a `|' seperated list of commands and parameters. The run command allows to
.BI [ N "]search-forward, [" N "]search-backward"
Search in current page forward or backward.
.TP
+.BI "save [" PATH "]"
+Download current opened page into configured download directory. If \fIPATH\fP
+is given, download under this file name or path. Possible value for PATH are
+`page.html', `subdir/img1.png', `~/downlod.html' or absolute pathes
+`/tmp/file.html'.
+.TP
.B inspect
Toggles the webinspector for current page. This is only available if the config
"webinspector" is enabled.
{"prev", "p", command_nextprev, {1}},
{"descent", NULL, command_descent, {0}},
{"descent!", NULL, command_descent, {1}},
+ {"save", NULL, command_save, {0}},
};
static void editor_resume(GPid pid, int status, OpenEditorData *data);
return result;
}
+gboolean command_save(const Arg *arg)
+{
+ WebKitDownload *download;
+ const char *uri = webkit_web_view_get_uri(vb.gui.webview);
+
+ if (!uri || *uri == '\0') {
+ return false;
+ }
+
+ download = webkit_download_new(webkit_network_request_new(uri));
+ vb_download(vb.gui.webview, download, arg->s ? arg->s : NULL);
+
+ return true;
+}
+
gboolean command_editor(const Arg *arg)
{
char *file_path = NULL;
gboolean command_editor(const Arg *arg);
gboolean command_nextprev(const Arg *arg);
gboolean command_descent(const Arg *arg);
+gboolean command_save(const Arg *arg);
#endif /* end of include guard: _COMMAND_H */
static gboolean mimetype_decision_cb(WebKitWebView *webview,
WebKitWebFrame *frame, WebKitNetworkRequest *request, char*
mime_type, WebKitWebPolicyDecision *decision);
-static gboolean download_requested_cb(WebKitWebView *view, WebKitDownload *download);
static void download_progress_cp(WebKitDownload *download, GParamSpec *pspec);
static void request_start_cb(WebKitWebView *webview, WebKitWebFrame *frame,
WebKitWebResource *resource, WebKitNetworkRequest *request,
"signal::hovering-over-link", G_CALLBACK(hover_link_cb), NULL,
"signal::title-changed", G_CALLBACK(title_changed_cb), NULL,
"signal::mime-type-policy-decision-requested", G_CALLBACK(mimetype_decision_cb), NULL,
- "signal::download-requested", G_CALLBACK(download_requested_cb), NULL,
+ "signal::download-requested", G_CALLBACK(vb_download), NULL,
"signal::resource-request-starting", G_CALLBACK(request_start_cb), NULL,
"signal::should-show-delete-interface-for-element", G_CALLBACK(gtk_false), NULL,
NULL
return false;
}
-static gboolean download_requested_cb(WebKitWebView *view, WebKitDownload *download)
+gboolean vb_download(WebKitWebView *view, WebKitDownload *download, const char *path)
{
WebKitDownloadStatus status;
- char *uri = NULL;
+ char *uri, *file;
- const char *filename = webkit_download_get_suggested_filename(download);
- if (!filename) {
- filename = "vimb_donwload";
+ /* prepare the path to save the donwload */
+ if (path) {
+ file = util_buil_path(path, vb.config.download_dir);
+ } else {
+ path = webkit_download_get_suggested_filename(download);
+ if (!path) {
+ path = "vimb_donwload";
+ }
+ file = util_buil_path(path, vb.config.download_dir);
}
- /* prepare the download target path */
- uri = g_strdup_printf("file://%s%c%s", vb.config.download_dir, G_DIR_SEPARATOR, filename);
+ /* build the file uri from file path */
+ uri = g_filename_to_uri(file, NULL, NULL);
webkit_download_set_destination_uri(download, uri);
+ g_free(file);
g_free(uri);
guint64 size = webkit_download_get_total_size(download);
if (size > 0) {
- vb_echo(VB_MSG_NORMAL, false, "Download %s [~%uB] started ...", filename, size);
+ vb_echo(VB_MSG_NORMAL, false, "Download %s [~%uB] started ...", path, size);
} else {
- vb_echo(VB_MSG_NORMAL, false, "Download %s started ...", filename);
+ vb_echo(VB_MSG_NORMAL, false, "Download %s started ...", path);
}
status = webkit_download_get_status(download);
void vb_update_input_style(void);
void vb_update_urlbar(const char *uri);
VbInputType vb_get_input_parts(const char* input, const char **prefix, const char **clean);
+gboolean vb_download(WebKitWebView *view, WebKitDownload *download, const char *path);
#endif /* end of include guard: _MAIN_H */
return true;
}
+
+/**
+ * Build the absolute file path of given path and possible given directory.
+ * If the path is already absolute or uses ~/ for the home directory, the
+ * directory is ignored.
+ *
+ * Returned path must be freed.
+ */
+char *util_buil_path(const char *path, const char *dir)
+{
+ char *fullPath, *p;
+
+ /* creating directory */
+ if (path[0] == '/') {
+ fullPath = g_strdup(path);
+ } else if (path[0] == '~') {
+ if (path[1] == '/') {
+ fullPath = g_strconcat(g_get_home_dir(), &path[1], NULL);
+ } else {
+ fullPath = g_strconcat(g_get_home_dir(), "/", &path[1], NULL);
+ }
+ } else if (dir) {
+ fullPath = g_strconcat(dir, "/", path, NULL);
+ } else {
+ fullPath = g_strconcat(g_get_current_dir(), "/", path, NULL);
+ }
+
+ if ((p = strrchr(fullPath, '/'))) {
+ *p = '\0';
+ g_mkdir_with_parents(fullPath, 0700);
+ *p = '/';
+ }
+
+ return fullPath;
+}
gboolean util_string_contains_all_tags(char *src, char **query, unsigned int q);
char *util_str_replace(const char* search, const char* replace, const char* string);
gboolean util_create_tmp_file(const char *content, char **file);
+char *util_buil_path(const char *path, const char *dir);
#endif /* end of include guard: _UTIL_H */