CURA-5035 Better download resets

This commit is contained in:
Ian Paschal 2018-05-01 09:02:24 +02:00
parent 2d54251be0
commit bb7f9feb5e

View file

@ -294,7 +294,6 @@ class Toolbox(QObject, Extension):
request = QNetworkRequest(self._request_urls[type]) request = QNetworkRequest(self._request_urls[type])
request.setRawHeader(*self._request_header) request.setRawHeader(*self._request_header)
self._network_manager.get(request) self._network_manager.get(request)
# TODO: Request authors and request material showcase
@pyqtSlot(str) @pyqtSlot(str)
def startDownload(self, url: str): def startDownload(self, url: str):
@ -311,6 +310,10 @@ class Toolbox(QObject, Extension):
@pyqtSlot() @pyqtSlot()
def cancelDownload(self): def cancelDownload(self):
Logger.log("i", "Toolbox: User cancelled the download of a plugin.") Logger.log("i", "Toolbox: User cancelled the download of a plugin.")
self.resetDownload();
return
def resetDownload(self):
self._download_reply.abort() self._download_reply.abort()
self._download_reply.downloadProgress.disconnect(self._onDownloadProgress) self._download_reply.downloadProgress.disconnect(self._onDownloadProgress)
self._download_reply = None self._download_reply = None
@ -324,24 +327,13 @@ class Toolbox(QObject, Extension):
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
def _onNetworkAccessibleChanged(self, accessible: int): def _onNetworkAccessibleChanged(self, accessible: int):
if accessible == 0: if accessible == 0:
self.setDownloadProgress(0) self.resetDownload()
self.setIsDownloading(False)
if self._download_reply:
self._download_reply.downloadProgress.disconnect(self._onDownloadProgress)
self._download_reply.abort()
self._download_reply = None
def _onRequestFinished(self, reply: QNetworkReply): def _onRequestFinished(self, reply: QNetworkReply):
if reply.error() == QNetworkReply.TimeoutError: if reply.error() == QNetworkReply.TimeoutError:
Logger.log("w", "Got a timeout.") Logger.log("w", "Got a timeout.")
# Reset everything. self.resetDownload()
self.setDownloadProgress(0)
self.setIsDownloading(False)
if self._download_plugin_reply:
self._download_plugin_reply.downloadProgress.disconnect(self._onDownloadProgress)
self._download_plugin_reply.abort()
self._download_plugin_reply = None
return return
if reply.error() == QNetworkReply.HostNotFoundError: if reply.error() == QNetworkReply.HostNotFoundError: