--- a/PluginManager/PluginRepositoryDialog.py Sat Feb 17 17:29:03 2018 +0100 +++ b/PluginManager/PluginRepositoryDialog.py Sat Feb 17 18:51:46 2018 +0100 @@ -135,8 +135,6 @@ self.__networkConfigurationManager = None self.__onlineStateChanged(True) - self.__doneMethod = None - self.__inDownload = False self.__pluginsToDownload = [] self.__pluginsDownloaded = [] self.__isDownloadInstall = False @@ -310,7 +308,7 @@ if self.__isDownloadInstall: self.__allDownloadedOk &= status - del self.__pluginsToDownload[0] + self.__pluginsToDownload.pop(0) if len(self.__pluginsToDownload): self.__downloadPlugin() else: @@ -350,7 +348,6 @@ self.__downloadButton.setEnabled(len(self.__selectedItems())) self.__downloadInstallButton.setEnabled(len(self.__selectedItems())) self.__installButton.setEnabled(True) - self.__doneMethod = None if not self.__external: ui = e5App().getObject("UserInterface") else: @@ -397,7 +394,6 @@ self.__updateRemoteItems = 0 self.downloadProgress.setValue(0) - self.__doneMethod = None if os.path.exists(self.pluginRepositoryFile): self.__repositoryMissing = False @@ -459,17 +455,12 @@ self.statusLabel.setText(url) - self.__doneMethod = doneMethod - self.__downloadURL = url - self.__downloadFileName = filename - self.__downloadIODevice = QFile(self.__downloadFileName + ".tmp") - self.__downloadCancelled = False - request = QNetworkRequest(QUrl(url)) request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, QNetworkRequest.AlwaysNetwork) reply = self.__networkManager.get(request) - reply.finished.connect(lambda: self.__downloadFileDone(reply)) + reply.finished.connect( + lambda: self.__downloadFileDone(reply, filename, doneMethod)) reply.downloadProgress.connect(self.__downloadProgress) self.__replies.append(reply) else: @@ -481,13 +472,17 @@ """ from {0}.</p><p>Error: {1}</p>""" ).format(url, self.tr("Computer is offline."))) - def __downloadFileDone(self, reply): + def __downloadFileDone(self, reply, fileName, doneMethod): """ Private method called, after the file has been downloaded from the Internet. @param reply reference to the reply object of the download @type QNetworkReply + @param fileName local name of the file + @type str + @param doneMethod method to be called when done + @type func """ self.__updateButton.setEnabled(True) self.__downloadCancelButton.setEnabled(False) @@ -498,19 +493,16 @@ self.__replies.remove(reply) if reply.error() != QNetworkReply.NoError: ok = False - if not self.__downloadCancelled: + if reply.error() != QNetworkReply.OperationCanceledError: E5MessageBox.warning( self, self.tr("Error downloading file"), self.tr( """<p>Could not download the requested file""" """ from {0}.</p><p>Error: {1}</p>""" - ).format(self.__downloadURL, reply.errorString()) + ).format(reply.url().toString(), reply.errorString()) ) self.downloadProgress.setValue(0) - self.__downloadURL = None - self.__downloadIODevice.remove() - self.__downloadIODevice = None if self.repositoryList.topLevelItemCount(): if self.repositoryList.currentItem() is None: self.repositoryList.setCurrentItem( @@ -523,33 +515,36 @@ reply.deleteLater() return - self.__downloadIODevice.open(QIODevice.WriteOnly) + downloadIODevice = QFile(fileName + ".tmp") + downloadIODevice.open(QIODevice.WriteOnly) # read data in chunks chunkSize = 64 * 1024 * 1024 while True: data = reply.read(chunkSize) if data is None or len(data) == 0: break - self.__downloadIODevice.write(data) - self.__downloadIODevice.close() - if QFile.exists(self.__downloadFileName): - QFile.remove(self.__downloadFileName) - self.__downloadIODevice.rename(self.__downloadFileName) - self.__downloadIODevice = None - self.__downloadURL = None + downloadIODevice.write(data) + downloadIODevice.close() + if QFile.exists(fileName): + QFile.remove(fileName) + downloadIODevice.rename(fileName) reply.deleteLater() - if self.__doneMethod is not None: - self.__doneMethod(ok, self.__downloadFileName) + if doneMethod is not None: + doneMethod(ok, fileName) - def __downloadCancel(self): + def __downloadCancel(self, reply=None): """ Private slot to cancel the current download. + + @param reply reference to the network reply + @type QNetworkReply """ - if self.__replies: - reply = self.__replies[0] - self.__downloadCancelled = True - self.__pluginsToDownload = [] + if reply is None: + if self.__replies: + reply = self.__replies[0] + self.__pluginsToDownload = [] + if reply is not None: reply.abort() def __downloadProgress(self, done, total): @@ -695,7 +690,7 @@ """ ignored = self.__sslErrorHandler.sslErrorsReply(reply, errors)[0] if ignored == E5SslErrorHandler.NotIgnored: - self.__downloadCancelled = True + self.__downloadCancel(reply) def getDownloadedPlugins(self): """