From 59adc0787f7b77922c671964e471d0fd2dd7fc90 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Fri, 3 Dec 2010 13:47:09 -0700 Subject: let webkit handle downloads (breaks backward compatibility) --- examples/config/config | 1 + 1 file changed, 1 insertion(+) (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index 855f7c2..64e1c94 100644 --- a/examples/config/config +++ b/examples/config/config @@ -43,6 +43,7 @@ set scripts_dir = $XDG_DATA_HOME/uzbl:@prefix/share/uzbl/examples/data:scri set cookie_handler = talk_to_socket $XDG_CACHE_HOME/uzbl/cookie_daemon_socket set scheme_handler = sync_spawn @scripts_dir/scheme.py set authentication_handler = sync_spawn @scripts_dir/auth.py +set download_handler = sync_spawn @scripts_dir/download.sh # === Dynamic event handlers ================================================= -- cgit v1.2.3 From 5ab073d90e3c66a53e116c78299c657a13847d5c Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Fri, 3 Dec 2010 14:55:47 -0700 Subject: display active downloads in the status bar --- examples/config/config | 4 ++- examples/data/plugins/downloads.py | 69 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 examples/data/plugins/downloads.py (limited to 'examples/config') diff --git a/examples/config/config b/examples/config/config index 64e1c94..a8547d2 100644 --- a/examples/config/config +++ b/examples/config/config @@ -105,7 +105,9 @@ set name_section = \@[\@NAME]\@ set status_section = \@status_message set selected_section = \@[\@SELECTED_URI]\@ -set status_format = @mode_section @keycmd_section @progress_section @uri_section @name_section @status_section @scroll_section @selected_section +set download_section = \@downloads + +set status_format = @mode_section @keycmd_section @progress_section @uri_section @name_section @status_section @scroll_section @selected_section @download_section set title_format_long = \@keycmd_prompt \@raw_modcmd \@raw_keycmd \@TITLE - Uzbl browser <\@NAME> \@SELECTED_URI diff --git a/examples/data/plugins/downloads.py b/examples/data/plugins/downloads.py new file mode 100644 index 0000000..7bf32d7 --- /dev/null +++ b/examples/data/plugins/downloads.py @@ -0,0 +1,69 @@ +# this plugin does a very simple display of download progress. to use it, add +# @downloads to your status_format. + +import os +ACTIVE_DOWNLOADS = {} + +# after a download's status has changed this is called to update the status bar +def update_download_section(uzbl): + global ACTIVE_DOWNLOADS + + if len(ACTIVE_DOWNLOADS): + # add a newline before we list downloads + result = ' downloads:' + for path in ACTIVE_DOWNLOADS: + # add each download + fn = os.path.basename(path) + progress, = ACTIVE_DOWNLOADS[path] + + dl = " %s (%d%%)" % (fn, progress * 100) + + # replace entities to make sure we don't break our markup + # (this could be done with an @[]@ expansion in uzbl, but then we + # can't use the above to make a new line) + dl = dl.replace("&", "&").replace("<", "<") + result += dl + else: + result = '' + + # and the result gets saved to an uzbl variable that can be used in + # status_format + if uzbl.config.get('downloads', '') != result: + uzbl.config['downloads'] = result + +def download_started(uzbl, destination_path): + # add to the list of active downloads + global ACTIVE_DOWNLOADS + ACTIVE_DOWNLOADS[destination_path] = (0.0,) + + # update the progress + update_download_section(uzbl) + +def download_progress(uzbl, args): + # parse the arguments + s = args.rindex(' ') + destination_path = args[:s] + progress = float(args[s+1:]) + + # update the progress + global ACTIVE_DOWNLOADS + ACTIVE_DOWNLOADS[destination_path] = (progress,) + + # update the status bar variable + update_download_section(uzbl) + +def download_complete(uzbl, destination_path): + # remove from the list of active downloads + global ACTIVE_DOWNLOADS + del ACTIVE_DOWNLOADS[destination_path] + + # update the status bar variable + update_download_section(uzbl) + +# plugin init hook +def init(uzbl): + connect_dict(uzbl, { + 'DOWNLOAD_STARTED': download_started, + 'DOWNLOAD_PROGRESS': download_progress, + 'DOWNLOAD_COMPLETE': download_complete, + }) -- cgit v1.2.3