From 25ee48d28baba052e4e0ecae3d506b7f132fd1ef Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 14 Mar 2016 19:05:15 +0100 Subject: [PATCH] Add an --all flag to :download-cancel --- CHANGELOG.asciidoc | 1 + doc/help/commands.asciidoc | 5 +++++ qutebrowser/browser/downloads.py | 30 +++++++++++++++++++----------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 6b52eba9b..9d59e5368 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -28,6 +28,7 @@ Added clipboard. - New mode `word` for `hints -> mode` which uses a dictionary and link-texts for hints instead of single characters. +- New `--all` argument for `:download-cancel` to cancel all running downloads. Changed ~~~~~~~ diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 81daecb79..395e3d6e4 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -161,8 +161,13 @@ The form `:download [url] [dest]` is deprecated, use `:download --dest [dest] [u [[download-cancel]] === download-cancel +Syntax: +:download-cancel [*--all*]+ + Cancel the last/[count]th download. +==== optional arguments +* +*-a*+, +*--all*+: Cancel all running downloads + ==== count The index of the download to cancel. diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index c3c6203d9..73a7f0dc0 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -948,22 +948,30 @@ class DownloadManager(QAbstractListModel): @cmdutils.register(instance='download-manager', scope='window', count='count') - def download_cancel(self, count=0): + def download_cancel(self, all_=False, count=0): """Cancel the last/[count]th download. Args: + all_: Cancel all running downloads count: The index of the download to cancel. """ - try: - download = self.downloads[count - 1] - except IndexError: - self.raise_no_download(count) - if download.done: - if not count: - count = len(self.downloads) - raise cmdexc.CommandError("Download {} is already done!" - .format(count)) - download.cancel() + if all_: + # We need to make a copy as we're indirectly mutating + # self.downloads here + for download in self.downloads[:]: + if not download.done: + download.cancel() + else: + try: + download = self.downloads[count - 1] + except IndexError: + self.raise_no_download(count) + if download.done: + if not count: + count = len(self.downloads) + raise cmdexc.CommandError("Download {} is already done!" + .format(count)) + download.cancel() @cmdutils.register(instance='download-manager', scope='window', count='count')