Changed :downloads-clear to :download-remove.

This commit is contained in:
Joel Torstensson 2015-02-09 17:17:34 +01:00
parent e9da7b5391
commit 55193803a1
2 changed files with 17 additions and 10 deletions

View File

@ -825,16 +825,22 @@ class DownloadManager(QAbstractListModel):
def can_clear(self):
"""Check if there are finished downloads to clear."""
if self.downloads:
return any(download.done for download in self.downloads)
else:
return False
return any(download.done for download in self.downloads)
@cmdutils.register(instance='download-manager', name='downloads-clear',
scope='window')
def clear(self):
"""Remove all finished downloads."""
self.remove_items(d for d in self.downloads if d.done)
@cmdutils.register(instance='download-manager', scope='window')
def download_remove(self, all_: {'name': 'all'}=False,
count: {'special': 'count'}=0):
"""Remove the last/[count]th finished download.
Args:
all: Whether to remove all finished downloads.
count: The index of the download to cancel.
"""
finished_items = [d for d in self.downloads if d.done]
if all_:
self.remove_items(finished_items)
else:
self.remove_item(finished_items[count - 1])
def last_index(self):
"""Get the last index in the model.

View File

@ -142,7 +142,8 @@ class DownloadView(QListView):
actions.append(("Cancel", item.cancel))
if self.model().can_clear():
actions.append((None, None))
actions.append(("Remove all finished", self.model().clear))
actions.append(("Remove all finished", functools.partial(
self.model().download_remove, True)))
return actions
@pyqtSlot('QPoint')