diff options
-rw-r--r-- | README | 23 | ||||
-rw-r--r-- | examples/config/config | 4 | ||||
-rwxr-xr-x | examples/data/scripts/download.sh | 14 | ||||
-rwxr-xr-x | examples/data/scripts/insert_temp.sh | 7 | ||||
-rwxr-xr-x | examples/data/scripts/load_url_from_temps.sh | 22 | ||||
-rw-r--r-- | examples/data/scripts/util/dmenu.sh | 7 | ||||
-rw-r--r-- | examples/data/scripts/util/uzbl-dir.sh | 1 | ||||
-rw-r--r-- | src/callbacks.c | 8 | ||||
-rw-r--r-- | src/uzbl-core.c | 25 | ||||
-rw-r--r-- | src/uzbl-core.h | 1 |
10 files changed, 101 insertions, 11 deletions
@@ -257,11 +257,14 @@ The following commands are recognized: - Show the WebInspector * `add_cookie <domain> <path> <name> <value> <scheme> <expires>` - Adds a new cookie to the cookie jar -* 'delete_cookie <domain> <path> <name> <value> [<scheme> <expires>]` - - Deletes a matching cookie from the cookie jar. scheme and expire time - is currently not considered when matching. -* 'clear_cookies` - - Clears all cookies from the cookie jar +* `delete_cookie <domain> <path> <name> <value> [<scheme> <expires>]` + - Deletes a matching cookie from the cookie jar. scheme and expire time + is currently not considered when matching. +* `clear_cookies` + - Clears all cookies from the cookie jar +* `download <uri> [<destination path>]` + - Starts a download using the given uri. A destination file path can be given + to specify where the download should be written to. ### VARIABLES AND CONSTANTS @@ -506,9 +509,15 @@ Handler scripts (`download_handler`, `cookie_handler`, `scheme_handler` and * download handler - `$1 url`: The URL of the item to be downloaded. - - `$2 suggested_filename`: A filename suggested by the server or based on the URL. + - `$2 suggested_filename`: A filename suggested by the server or based on the + URL. - `$3 content_type`: The mimetype of the file to be downloaded. - - `$4 total_size`: The size of the file to be downloaded in bytes. This may be inaccurate. + - `$4 total_size`: The size of the file to be downloaded in bytes. This may be + inaccurate. + - `$5 destination_path`: This is only present if the download was started + explicitly using the `download` command. If it is present, this is the path + that the file should be saved to. A download handler using WebKit's internal + downloader can just echo this path and exit when this argument is present. * cookie handler diff --git a/examples/config/config b/examples/config/config index 7efbb22..a690aec 100644 --- a/examples/config/config +++ b/examples/config/config @@ -337,6 +337,10 @@ set ebind = @mode_bind global,-insert @cbind U = spawn @scripts_dir/load_url_from_history.sh @cbind u = spawn @scripts_dir/load_url_from_bookmarks.sh +# Temporary bookmarks +@cbind <Ctrl>d = spawn @scripts_dir/insert_temp.sh +@cbind D = spawn @scripts_dir/load_url_from_temps.sh + # Link following (similar to vimperator and konqueror) # Set custom keys you wish to use for navigation. Some common examples: set follow_hint_keys = 0123456789 diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index fe566ed..dbc9caf 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -1,9 +1,17 @@ #!/bin/sh # uzbl's example configuration sets this script up as its download_handler. -# when uzbl starts a download it runs this script. +# this script is run when uzbl encounters a URL that it can't display, and when +# a download is requested using the 'download' command. +# # if the script prints a file path to stdout, uzbl will save the download to -# that path. -# if nothing is printed to stdout, the download will be cancelled. +# that path using it's internal downloader. +# +# if nothing is printed to stdout, the internal download will be cancelled. +# you could do your own download handling in your script that way. + +# if $5 is set, it is the path that was passed to uzbl's "download" command. +# we want to use that if it's available. +[ -n "$5" ] && echo "$5" && exit . "$UZBL_UTIL_DIR/uzbl-dir.sh" diff --git a/examples/data/scripts/insert_temp.sh b/examples/data/scripts/insert_temp.sh new file mode 100755 index 0000000..7ed8d22 --- /dev/null +++ b/examples/data/scripts/insert_temp.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +. "$UZBL_UTIL_DIR/uzbl-dir.sh" + +>> "$UZBL_TEMPS_FILE" || exit 1 + +echo "$UZBL_URI $UZBL_TITLE" >> "$UZBL_TEMPS_FILE" diff --git a/examples/data/scripts/load_url_from_temps.sh b/examples/data/scripts/load_url_from_temps.sh new file mode 100755 index 0000000..b46687b --- /dev/null +++ b/examples/data/scripts/load_url_from_temps.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +DMENU_SCHEME="temps" +DMENU_OPTIONS="xmms vertical resize" + +. "$UZBL_UTIL_DIR/dmenu.sh" +. "$UZBL_UTIL_DIR/uzbl-dir.sh" + +[ -r "$UZBL_TEMPS_FILE" ] || exit 1 + +if [ -z "$DMENU_HAS_VERTICAL" ]; then + # because they are all after each other, just show the url, not their titles. + goto=$( awk '{ print $1 }' "$UZBL_TEMPS_FILE" | $DMENU ) +else + # show titles + goto=$( $DMENU < "$UZBL_TEMPS_FILE" | cut -d ' ' -f 1 ) +fi + +sed -i -e "\<^$goto <d" $UZBL_TEMPS_FILE + +[ -n "$goto" ] && echo "uri $goto" > "$UZBL_FIFO" +#[ -n "$goto" ] && echo "uri $goto" | socat - "unix-connect:$UZBL_SOCKET" diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index f0d1651..0b7272e 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -30,6 +30,13 @@ case "$DMENU_SCHEME" in SB="#ccffaa" SF="#303030" ;; + # Temps + "temps" ) + NB="#303030" + NF="khaki" + SB="#ccffaa" + SF="#303030" + ;; # Default * ) NB="#303030" diff --git a/examples/data/scripts/util/uzbl-dir.sh b/examples/data/scripts/util/uzbl-dir.sh index 3d28151..82510d8 100644 --- a/examples/data/scripts/util/uzbl-dir.sh +++ b/examples/data/scripts/util/uzbl-dir.sh @@ -15,5 +15,6 @@ UZBL_FORMS_DIR="$UZBL_DATA_DIR/dforms" UZBL_CONFIG_FILE="$UZBL_CONFIG_DIR/config" UZBL_COOKIE_FILE="$UZBL_DATA_DIR/cookies.txt" UZBL_BOOKMARKS_FILE="$UZBL_DATA_DIR/bookmarks" +UZBL_TEMPS_FILE="$UZBL_DATA_DIR/temps" UZBL_HISTORY_FILE="$UZBL_DATA_DIR/history" UZBL_SESSION_FILE="$UZBL_DATA_DIR/browser-session" diff --git a/src/callbacks.c b/src/callbacks.c index 360b0c4..703107b 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -837,6 +837,11 @@ download_cb(WebKitWebView *web_view, WebKitDownload *download, gpointer user_dat /* get the URI being downloaded */ const gchar *uri = webkit_download_get_uri(download); + /* get the destination path, if specified. + * this is only intended to be set when this function is trigger by an + * explicit download using uzbl's 'download' action. */ + const gchar *destination = user_data; + if (uzbl.state.verbose) printf("Download requested -> %s\n", uri); @@ -883,6 +888,9 @@ download_cb(WebKitWebView *web_view, WebKitDownload *download, gpointer user_dat gchar *total_size_s = g_strdup_printf("%d", total_size); g_array_append_val(a, total_size_s); + if(destination) + g_array_append_val(a, destination); + GString *result = g_string_new (""); run_parsed_command(c, a, result); diff --git a/src/uzbl-core.c b/src/uzbl-core.c index e498762..204c89c 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -552,7 +552,8 @@ CommandInfo cmdlist[] = { "show_inspector", show_inspector, 0 }, { "add_cookie", add_cookie, 0 }, { "delete_cookie", delete_cookie, 0 }, - { "clear_cookies", clear_cookies, 0 } + { "clear_cookies", clear_cookies, 0 }, + { "download", download, 0 } }; void @@ -741,6 +742,28 @@ clear_cookies(WebKitWebView *page, GArray *argv, GString *result) { } void +download(WebKitWebView *web_view, GArray *argv, GString *result) { + (void) result; + + const gchar *uri = argv_idx(argv, 0); + const gchar *destination = NULL; + if(argv->len > 1) + destination = argv_idx(argv, 1); + + WebKitNetworkRequest *req = webkit_network_request_new(uri); + WebKitDownload *download = webkit_download_new(req); + + download_cb(web_view, download, destination); + + if(webkit_download_get_destination_uri(download)) + webkit_download_start(download); + else + g_object_unref(download); + + g_object_unref(req); +} + +void act_dump_config() { dump_config(); } diff --git a/src/uzbl-core.h b/src/uzbl-core.h index affd334..be8fccd 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -325,6 +325,7 @@ void show_inspector(WebKitWebView *page, GArray *argv, GString *result); void add_cookie(WebKitWebView *page, GArray *argv, GString *result); void delete_cookie(WebKitWebView *page, GArray *argv, GString *result); void clear_cookies(WebKitWebView *pag, GArray *argv, GString *result); +void download(WebKitWebView *pag, GArray *argv, GString *result); void builtins(); typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result); |