From 7dadd97f017f0c8455c707dc2b46f6d46042acd2 Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Tue, 3 Nov 2015 20:27:02 +0200 Subject: [PATCH 1/3] Implement :download-clear command. Fixes #1013. --- doc/help/commands.asciidoc | 5 +++++ qutebrowser/browser/downloads.py | 9 +++++++-- qutebrowser/config/configdata.py | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index e21eecaf7..7848b91b8 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -14,6 +14,7 @@ |<>|Close the current window. |<>|Download a given URL, or current page if no URL given. |<>|Cancel the last/[count]th download. +|<>|Remove all finished downloads from the list. |<>|Delete the last/[count]th download from disk. |<>|Open the last/[count]th download. |<>|Remove the last/[count]th download from the list. @@ -158,6 +159,10 @@ Cancel the last/[count]th download. ==== count The index of the download to cancel. +[[download-clear]] +=== download-clear +Remove all finished downloads from the list. + [[download-delete]] === download-delete Delete the last/[count]th download from disk. diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 187e23e1c..d72d027d9 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -964,6 +964,12 @@ class DownloadManager(QAbstractListModel): """Check if there are finished downloads to clear.""" return any(download.done for download in self.downloads) + @cmdutils.register(instance='download-manager', scope='window') + def download_clear(self): + """Remove all finished downloads from the list.""" + finished_items = [d for d in self.downloads if d.done] + self.remove_items(finished_items) + @cmdutils.register(instance='download-manager', scope='window', count='count') def download_remove(self, all_=False, count=0): @@ -974,8 +980,7 @@ class DownloadManager(QAbstractListModel): count: The index of the download to cancel. """ if all_: - finished_items = [d for d in self.downloads if d.done] - self.remove_items(finished_items) + self.download_clear() else: try: download = self.downloads[count - 1] diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index a5d4c00b8..e32460186 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -1373,7 +1373,7 @@ KEY_DATA = collections.OrderedDict([ ('inspector', ['wi']), ('download', ['gd']), ('download-cancel', ['ad']), - ('download-remove --all', ['cd']), + ('download-clear', ['cd']), ('view-source', ['gf']), ('tab-focus last', ['']), ('enter-mode passthrough', ['']), From dc06787f83a86218fb25ea6a42b7cd2bac12d0be Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Wed, 4 Nov 2015 01:01:27 +0200 Subject: [PATCH 2/3] Make key config migration for clearing downloads. --- qutebrowser/config/configdata.py | 2 ++ tests/unit/config/test_config.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index e32460186..6f9d7c82d 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -1497,4 +1497,6 @@ CHANGED_KEY_COMMANDS = [ (re.compile(r'^search *;; *clear-keychain$'), r'clear-keychain ;; search'), (re.compile(r'^leave-mode$'), r'clear-keychain ;; leave-mode'), + + (re.compile(r'^download-remove --all$'), r'download-clear'), ] diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index de19e0fdf..4910e2ad2 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -251,6 +251,8 @@ class TestKeyConfigParser: ('search;;foo', None), ('leave-mode', 'clear-keychain ;; leave-mode'), ('leave-mode ;; foo', None), + + ('download-remove --all', 'download-clear'), ] ) def test_migrations(self, old, new_expected): From 782f09488a3f9941571b4041347a139f15ced5c6 Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Wed, 4 Nov 2015 01:03:38 +0200 Subject: [PATCH 3/3] Deprecate :download-remove --all. :download-clear should be used instead. --- qutebrowser/browser/downloads.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index d72d027d9..c8f434072 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -976,10 +976,12 @@ class DownloadManager(QAbstractListModel): """Remove the last/[count]th download from the list. Args: - all_: If given removes all finished downloads. + all_: Deprecated argument for removing all finished downloads. count: The index of the download to cancel. """ if all_: + message.warning(self._win_id, ":download-remove --all is " + "deprecated - use :download-clear instead!") self.download_clear() else: try: