summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2013-06-08 00:49:45 +0200
committerDaniel Carl <danielcarl@gmx.de>2013-06-08 00:55:25 +0200
commitbf6289b8d42dbc334ab91450eaa0896d629c5361 (patch)
tree1630d5f0159723af01b846f7d9cc4370fbe6b7ce /src
parenta010ec2eff63b399c917452c0b6379aa588b8373 (diff)
Added hinting mode to download links (#32).
There is now a new hinting mode and command :hint-save to download the hinted links into the configured download directory. This hinting is bound to the keybinding ';s'. Also the enums out of the command.c file where moved into the command.h file, because they would be possible needed from other components that call commands directly and not from their string representation.
Diffstat (limited to 'src')
-rw-r--r--src/command.c37
-rw-r--r--src/command.h24
-rw-r--r--src/config.h1
-rw-r--r--src/hints.c4
-rw-r--r--src/hints.h3
5 files changed, 46 insertions, 23 deletions
diff --git a/src/command.c b/src/command.c
index 9fb39c6..b22619a 100644
--- a/src/command.c
+++ b/src/command.c
@@ -29,25 +29,6 @@
#include "bookmark.h"
#include "dom.h"
-/*
-bitmap
-1: primary cliboard
-2: secondary cliboard
-3: yank uri
-4: yank selection
-*/
-enum {
- COMMAND_YANK_URI = (VB_CLIPBOARD_SECONDARY<<1),
- COMMAND_YANK_SELECTION = (VB_CLIPBOARD_SECONDARY<<2)
-};
-
-enum {
- COMMAND_ZOOM_OUT,
- COMMAND_ZOOM_IN,
- COMMAND_ZOOM_FULL = (1<<1),
- COMMAND_ZOOM_RESET = (1<<2)
-};
-
typedef struct {
char *file;
Element *element;
@@ -112,6 +93,7 @@ static CommandInfo cmd_list[] = {
{"hint-image-open", NULL, command_hints, {HINTS_TYPE_IMAGE | HINTS_PROCESS_OPEN, ";i"}},
{"hint-image-tabopen", NULL, command_hints, {HINTS_TYPE_IMAGE | HINTS_PROCESS_OPEN | HINTS_OPEN_NEW, ";I"}},
{"hint-editor", NULL, command_hints, {HINTS_TYPE_EDITABLE, ";e"}},
+ {"hint-save", NULL, command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS_SAVE, ";s"}},
{"yank-uri", "yu", command_yank, {VB_CLIPBOARD_PRIMARY | VB_CLIPBOARD_SECONDARY | COMMAND_YANK_URI}},
{"yank-selection", "ys", command_yank, {VB_CLIPBOARD_PRIMARY | VB_CLIPBOARD_SECONDARY | COMMAND_YANK_SELECTION}},
{"search-forward", NULL, command_search, {VB_SEARCH_FORWARD}},
@@ -134,7 +116,7 @@ static CommandInfo cmd_list[] = {
{"prev", "p", command_nextprev, {1}},
{"descent", NULL, command_descent, {0}},
{"descent!", NULL, command_descent, {1}},
- {"save", NULL, command_save, {0}},
+ {"save", NULL, command_save, {COMMAND_SAVE_CURRENT}},
};
static void editor_resume(GPid pid, int status, OpenEditorData *data);
@@ -745,14 +727,25 @@ gboolean command_descent(const Arg *arg)
gboolean command_save(const Arg *arg)
{
WebKitDownload *download;
- const char *uri = webkit_web_view_get_uri(vb.gui.webview);
+ const char *uri, *path = NULL;
+
+ vb_set_mode(VB_MODE_NORMAL, false);
+ if (arg->i == COMMAND_SAVE_CURRENT) {
+ uri = webkit_web_view_get_uri(vb.gui.webview);
+ /* given string is the path to save the download to */
+ if (arg->s && *(arg->s) != '\0') {
+ path = arg->s;
+ }
+ } else {
+ uri = arg->s;
+ }
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);
+ vb_download(vb.gui.webview, download, path);
return true;
}
diff --git a/src/command.h b/src/command.h
index ac41d21..326d5cb 100644
--- a/src/command.h
+++ b/src/command.h
@@ -20,6 +20,30 @@
#ifndef _COMMAND_H
#define _COMMAND_H
+/*
+bitmap
+1: primary cliboard
+2: secondary cliboard
+3: yank uri
+4: yank selection
+*/
+enum {
+ COMMAND_YANK_URI = (VB_CLIPBOARD_SECONDARY<<1),
+ COMMAND_YANK_SELECTION = (VB_CLIPBOARD_SECONDARY<<2)
+};
+
+enum {
+ COMMAND_ZOOM_OUT,
+ COMMAND_ZOOM_IN,
+ COMMAND_ZOOM_FULL = (1<<1),
+ COMMAND_ZOOM_RESET = (1<<2)
+};
+
+enum {
+ COMMAND_SAVE_CURRENT,
+ COMMAND_SAVE_URI
+};
+
void command_init(void);
GList *command_get_by_prefix(const char *prefix);
void command_cleanup(void);
diff --git a/src/config.h b/src/config.h
index 57b3ded..beb36bc 100644
--- a/src/config.h
+++ b/src/config.h
@@ -76,6 +76,7 @@ const char *default_config[] = {
"nmap ;i=hint-image-open",
"nmap ;I=hint-image-tabopen",
"nmap ;e=hint-editor",
+ "nmap ;s=hint-save",
"nmap y=yank-uri",
"nmap Y=yank-selection",
"nmap p=open-clipboard",
diff --git a/src/hints.c b/src/hints.c
index 2df9f17..0ebe2a7 100644
--- a/src/hints.c
+++ b/src/hints.c
@@ -164,6 +164,10 @@ static void run_script(char *js)
a.s = g_strconcat((mode & HINTS_OPEN_NEW) ? ":tabopen " : ":open ", v, NULL);
command_input(&a);
g_free(a.s);
+ } else if (mode & HINTS_PROCESS_SAVE) {
+ a.s = v;
+ a.i = COMMAND_SAVE_URI;
+ command_save(&a);
} else {
a.i = VB_CLIPBOARD_PRIMARY | VB_CLIPBOARD_SECONDARY;
a.s = v;
diff --git a/src/hints.h b/src/hints.h
index 5146036..52d4220 100644
--- a/src/hints.h
+++ b/src/hints.h
@@ -31,7 +31,8 @@ enum {
HINTS_PROCESS_INPUT = (1 << 2),
HINTS_PROCESS_YANK = (1 << 3),
HINTS_PROCESS_OPEN = (1 << 4),
- HINTS_OPEN_NEW = (1 << 5),
+ HINTS_PROCESS_SAVE = (1 << 5),
+ HINTS_OPEN_NEW = (1 << 6),
};
void hints_init(WebKitWebFrame *frame);