open-download: don't crash on download cancel

Fixes #1728.
This commit is contained in:
Daniel Schadt 2016-08-02 01:10:40 +02:00
parent b187b680cb
commit 57ceaeeb55

View File

@ -954,12 +954,21 @@ class DownloadManager(QAbstractListModel):
message.error(self._win_id, msg) message.error(self._win_id, msg)
download.cancel() download.cancel()
return return
download.finished.connect(download.open_file) download.finished.connect(
functools.partial(self._open_download, download))
download.autoclose = True download.autoclose = True
download.set_fileobj(fobj) download.set_fileobj(fobj)
else: else:
log.downloads.error("Unknown download target: {}".format(target)) log.downloads.error("Unknown download target: {}".format(target))
def _open_download(self, download):
"""Open the given download but only if it was successful."""
if download.successful:
download.open_file()
else:
log.downloads.debug("{} finished but not successful, not opening!"
.format(download))
def raise_no_download(self, count): def raise_no_download(self, count):
"""Raise an exception that the download doesn't exist. """Raise an exception that the download doesn't exist.