From d1f8d29c20ee2a5a113e850f5195d558235dd024 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 7 Oct 2015 23:22:21 +0200 Subject: [PATCH] Add --mhtml flag to :download And remove :download-whole command. --- doc/help/commands.asciidoc | 13 ++----------- qutebrowser/browser/commands.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index dcc90af65..22219a994 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -19,7 +19,6 @@ |<>|Open the last/[count]th download. |<>|Remove the last/[count]th download from the list. |<>|Retry the first failed/[count]th download. -|<>|Download the current page as a MHTML file, including all assets. |<>|Go forward in the history of the current tab. |<>|Toggle fullscreen mode. |<>|Show help about a command or setting. @@ -146,7 +145,7 @@ Close the current window. [[download]] === download -Syntax: +:download [*--dest* 'DEST'] ['url'] ['dest-old']+ +Syntax: +:download [*--mhtml*] [*--dest* 'DEST'] ['url'] ['dest-old']+ Download a given URL, or current page if no URL given. @@ -157,6 +156,7 @@ The form `:download [url] [dest]` is deprecated, use `:download --dest [dest] [u * +'dest-old'+: (deprecated) Same as dest. ==== optional arguments +* +*-m*+, +*--mhtml*+: Download the current page and all assets as mhtml file. * +*-d*+, +*--dest*+: The file path to write the download to, or not given to ask. [[download-cancel]] @@ -203,15 +203,6 @@ Retry the first failed/[count]th download. ==== count The index of the download to cancel. -[[download-whole]] -=== download-whole -Syntax: +:download-whole ['dest']+ - -Download the current page as a MHTML file, including all assets. - -==== positional arguments -* +'dest'+: The file path to write the download to. - [[forward]] === forward Syntax: +:forward [*--tab*] [*--bg*] [*--window*]+ diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 633285727..aa9dd2e4d 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1140,7 +1140,7 @@ class CommandDispatcher: cur.inspector.show() @cmdutils.register(instance='command-dispatcher', scope='window') - def download(self, url=None, dest_old=None, *, dest=None): + def download(self, url=None, dest_old=None, *, mhtml=False, dest=None): """Download a given URL, or current page if no URL given. The form `:download [url] [dest]` is deprecated, use `:download --dest @@ -1150,6 +1150,7 @@ class CommandDispatcher: url: The URL to download. If not given, download the current page. dest_old: (deprecated) Same as dest. dest: The file path to write the download to, or None to ask. + mhtml: Download the current page and all assets as mhtml file. """ if dest_old is not None: message.warning('current', ":download [url] [dest] is deprecated -" @@ -1162,15 +1163,20 @@ class CommandDispatcher: download_manager = objreg.get('download-manager', scope='window', window=self._win_id) if url: + if mhtml: + raise cmdexc.CommandError("Can only download the current page" + " as mhtml.") url = urlutils.qurl_from_user_input(url) urlutils.raise_cmdexc_if_invalid(url) download_manager.get(url, filename=dest) else: - page = self._current_widget().page() - download_manager.get(self._current_url(), page=page, filename=dest) + if mhtml: + self._download_mhtml(dest) + else: + page = self._current_widget().page() + download_manager.get(self._current_url(), page=page, filename=dest) - @cmdutils.register(instance='command-dispatcher', scope='window') - def download_whole(self, dest=None): + def _download_mhtml(self, dest=None): """Download the current page as a MHTML file, including all assets. Args: