:download-open and :download-remove now complains if you try to execute on a download that is not done.

This commit is contained in:
Joel Torstensson 2015-02-12 21:05:53 +01:00
parent 91f7056649
commit 1f39200b28

View File

@ -767,11 +767,12 @@ class DownloadManager(QAbstractListModel):
Args: Args:
count: The index of the download to cancel. count: The index of the download to cancel.
""" """
finished_items = [d for d in self.downloads if d.done and d.successful]
try: try:
download = finished_items[count - 1] download = self.downloads[count - 1]
except IndexError: except IndexError:
raise cmdexc.CommandError("There's no download {}!".format(count)) 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() download.open_file()
@pyqtSlot(QNetworkRequest, QNetworkReply) @pyqtSlot(QNetworkRequest, QNetworkReply)
@ -841,11 +842,17 @@ class DownloadManager(QAbstractListModel):
all_: If given removes all finished downloads. all_: If given removes all finished downloads.
count: The index of the download to cancel. count: The index of the download to cancel.
""" """
finished_items = [d for d in self.downloads if d.done]
if all_: if all_:
finished_items = [d for d in self.downloads if d.done]
self.remove_items(finished_items) self.remove_items(finished_items)
else: 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): def last_index(self):
"""Get the last index in the model. """Get the last index in the model.