Fix retrying of downloads after the tab is closed.
This commit is contained in:
parent
cd39be62ee
commit
6576796718
@ -165,13 +165,13 @@ class DownloadItem(QObject):
|
|||||||
done.
|
done.
|
||||||
fileobj: The file object to download the file to.
|
fileobj: The file object to download the file to.
|
||||||
reply: The QNetworkReply associated with this download.
|
reply: The QNetworkReply associated with this download.
|
||||||
|
retry_info: A RetryInfo instance.
|
||||||
_filename: The filename of the download.
|
_filename: The filename of the download.
|
||||||
_redirects: How many time we were redirected already.
|
_redirects: How many time we were redirected already.
|
||||||
_buffer: A BytesIO object to buffer incoming data until we know the
|
_buffer: A BytesIO object to buffer incoming data until we know the
|
||||||
target file.
|
target file.
|
||||||
_read_timer: A QTimer which reads the QNetworkReply into self._buffer
|
_read_timer: A QTimer which reads the QNetworkReply into self._buffer
|
||||||
periodically.
|
periodically.
|
||||||
_retry_info: A RetryInfo instance.
|
|
||||||
_win_id: The window ID the DownloadItem runs in.
|
_win_id: The window ID the DownloadItem runs in.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
@ -202,7 +202,7 @@ class DownloadItem(QObject):
|
|||||||
reply: The QNetworkReply to download.
|
reply: The QNetworkReply to download.
|
||||||
"""
|
"""
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._retry_info = None
|
self.retry_info = None
|
||||||
self.done = False
|
self.done = False
|
||||||
self.stats = DownloadItemStats(self)
|
self.stats = DownloadItemStats(self)
|
||||||
self.stats.updated.connect(self.data_changed)
|
self.stats.updated.connect(self.data_changed)
|
||||||
@ -311,8 +311,8 @@ class DownloadItem(QObject):
|
|||||||
reply.finished.connect(self.on_reply_finished)
|
reply.finished.connect(self.on_reply_finished)
|
||||||
reply.error.connect(self.on_reply_error)
|
reply.error.connect(self.on_reply_error)
|
||||||
reply.readyRead.connect(self.on_ready_read)
|
reply.readyRead.connect(self.on_ready_read)
|
||||||
self._retry_info = RetryInfo(request=reply.request(),
|
self.retry_info = RetryInfo(request=reply.request(),
|
||||||
manager=reply.manager())
|
manager=reply.manager())
|
||||||
if not self.fileobj:
|
if not self.fileobj:
|
||||||
self._read_timer.start()
|
self._read_timer.start()
|
||||||
# We could have got signals before we connected slots to them.
|
# We could have got signals before we connected slots to them.
|
||||||
@ -365,7 +365,7 @@ class DownloadItem(QObject):
|
|||||||
def retry(self):
|
def retry(self):
|
||||||
"""Retry a failed download."""
|
"""Retry a failed download."""
|
||||||
self.cancel()
|
self.cancel()
|
||||||
new_reply = self._retry_info.manager.get(self._retry_info.request)
|
new_reply = self.retry_info.manager.get(self.retry_info.request)
|
||||||
self.do_retry.emit(new_reply)
|
self.do_retry.emit(new_reply)
|
||||||
|
|
||||||
def open_file(self):
|
def open_file(self):
|
||||||
@ -800,6 +800,10 @@ class DownloadManager(QAbstractListModel):
|
|||||||
for download in self.downloads:
|
for download in self.downloads:
|
||||||
if download.reply is not None and download.reply.manager() is nam:
|
if download.reply is not None and download.reply.manager() is nam:
|
||||||
return True
|
return True
|
||||||
|
if (download.done and (not download.successful) and
|
||||||
|
download.retry_info.manager is nam):
|
||||||
|
# user could request retry after tab is closed.
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def can_clear(self):
|
def can_clear(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user