Fix handling of failed downloads with QtWebEngine

This commit is contained in:
Florian Bruhin 2017-03-20 09:44:07 +01:00
parent 3e2ba32240
commit 6888ac04e1

View File

@ -78,17 +78,16 @@ class DownloadItem(downloads.AbstractDownloadItem):
self.stats.finish() self.stats.finish()
elif state == QWebEngineDownloadItem.DownloadInterrupted: elif state == QWebEngineDownloadItem.DownloadInterrupted:
self.successful = False self.successful = False
self.done = True
# https://bugreports.qt.io/browse/QTBUG-56839 # https://bugreports.qt.io/browse/QTBUG-56839
self.error.emit("Download failed") self._die("Download failed")
self.stats.finish()
else: else:
raise ValueError("_on_state_changed was called with unknown state " raise ValueError("_on_state_changed was called with unknown state "
"{}".format(state_name)) "{}".format(state_name))
def _do_die(self): def _do_die(self):
self._qt_item.downloadProgress.disconnect() self._qt_item.downloadProgress.disconnect()
self._qt_item.cancel() if self._qt_item.state() != QWebEngineDownloadItem.DownloadInterrupted:
self._qt_item.cancel()
def _do_cancel(self): def _do_cancel(self):
self._qt_item.cancel() self._qt_item.cancel()