From 1f39200b2810f0e97bbc1501211ce96e46b958f3 Mon Sep 17 00:00:00 2001 From: Joel Torstensson Date: Thu, 12 Feb 2015 21:05:53 +0100 Subject: [PATCH] :download-open and :download-remove now complains if you try to execute on a download that is not done. --- qutebrowser/browser/downloads.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 814c7c8f9..ed3eb8be1 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -767,11 +767,12 @@ class DownloadManager(QAbstractListModel): Args: count: The index of the download to cancel. """ - finished_items = [d for d in self.downloads if d.done and d.successful] try: - download = finished_items[count - 1] + download = self.downloads[count - 1] except IndexError: raise cmdexc.CommandError("There's no download {}!".format(count)) + if not download.done and not download.successful: + raise cmdexc.CommandError("Download {} is not done!".format(count)) download.open_file() @pyqtSlot(QNetworkRequest, QNetworkReply) @@ -841,11 +842,17 @@ class DownloadManager(QAbstractListModel): all_: If given removes all finished downloads. count: The index of the download to cancel. """ - finished_items = [d for d in self.downloads if d.done] if all_: + finished_items = [d for d in self.downloads if d.done] self.remove_items(finished_items) else: - self.remove_item(finished_items[count - 1]) + try: + download = self.downloads[count - 1] + except IndexError: + raise cmdexc.CommandError("There's no download {}!".format(count)) + if not download.done: + raise cmdexc.CommandError("Download {} is not done!".format(count)) + self.remove_item(download) def last_index(self): """Get the last index in the model.