133 self.__onlineStateChanged) |
133 self.__onlineStateChanged) |
134 else: |
134 else: |
135 self.__networkConfigurationManager = None |
135 self.__networkConfigurationManager = None |
136 self.__onlineStateChanged(True) |
136 self.__onlineStateChanged(True) |
137 |
137 |
138 self.__doneMethod = None |
|
139 self.__inDownload = False |
|
140 self.__pluginsToDownload = [] |
138 self.__pluginsToDownload = [] |
141 self.__pluginsDownloaded = [] |
139 self.__pluginsDownloaded = [] |
142 self.__isDownloadInstall = False |
140 self.__isDownloadInstall = False |
143 self.__allDownloadedOk = False |
141 self.__allDownloadedOk = False |
144 |
142 |
308 if status: |
306 if status: |
309 self.__pluginsDownloaded.append(filename) |
307 self.__pluginsDownloaded.append(filename) |
310 if self.__isDownloadInstall: |
308 if self.__isDownloadInstall: |
311 self.__allDownloadedOk &= status |
309 self.__allDownloadedOk &= status |
312 |
310 |
313 del self.__pluginsToDownload[0] |
311 self.__pluginsToDownload.pop(0) |
314 if len(self.__pluginsToDownload): |
312 if len(self.__pluginsToDownload): |
315 self.__downloadPlugin() |
313 self.__downloadPlugin() |
316 else: |
314 else: |
317 self.__downloadPluginsDone() |
315 self.__downloadPluginsDone() |
318 |
316 |
348 Private method called, when the download of the plugins is finished. |
346 Private method called, when the download of the plugins is finished. |
349 """ |
347 """ |
350 self.__downloadButton.setEnabled(len(self.__selectedItems())) |
348 self.__downloadButton.setEnabled(len(self.__selectedItems())) |
351 self.__downloadInstallButton.setEnabled(len(self.__selectedItems())) |
349 self.__downloadInstallButton.setEnabled(len(self.__selectedItems())) |
352 self.__installButton.setEnabled(True) |
350 self.__installButton.setEnabled(True) |
353 self.__doneMethod = None |
|
354 if not self.__external: |
351 if not self.__external: |
355 ui = e5App().getObject("UserInterface") |
352 ui = e5App().getObject("UserInterface") |
356 else: |
353 else: |
357 ui = None |
354 ui = None |
358 if ui and ui.notificationsEnabled(): |
355 if ui and ui.notificationsEnabled(): |
395 self.__newItems = 0 |
392 self.__newItems = 0 |
396 self.__updateLocalItems = 0 |
393 self.__updateLocalItems = 0 |
397 self.__updateRemoteItems = 0 |
394 self.__updateRemoteItems = 0 |
398 |
395 |
399 self.downloadProgress.setValue(0) |
396 self.downloadProgress.setValue(0) |
400 self.__doneMethod = None |
|
401 |
397 |
402 if os.path.exists(self.pluginRepositoryFile): |
398 if os.path.exists(self.pluginRepositoryFile): |
403 self.__repositoryMissing = False |
399 self.__repositoryMissing = False |
404 f = QFile(self.pluginRepositoryFile) |
400 f = QFile(self.pluginRepositoryFile) |
405 if f.open(QIODevice.ReadOnly): |
401 if f.open(QIODevice.ReadOnly): |
457 self.__downloadInstallButton.setEnabled(False) |
453 self.__downloadInstallButton.setEnabled(False) |
458 self.__downloadCancelButton.setEnabled(True) |
454 self.__downloadCancelButton.setEnabled(True) |
459 |
455 |
460 self.statusLabel.setText(url) |
456 self.statusLabel.setText(url) |
461 |
457 |
462 self.__doneMethod = doneMethod |
|
463 self.__downloadURL = url |
|
464 self.__downloadFileName = filename |
|
465 self.__downloadIODevice = QFile(self.__downloadFileName + ".tmp") |
|
466 self.__downloadCancelled = False |
|
467 |
|
468 request = QNetworkRequest(QUrl(url)) |
458 request = QNetworkRequest(QUrl(url)) |
469 request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, |
459 request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, |
470 QNetworkRequest.AlwaysNetwork) |
460 QNetworkRequest.AlwaysNetwork) |
471 reply = self.__networkManager.get(request) |
461 reply = self.__networkManager.get(request) |
472 reply.finished.connect(lambda: self.__downloadFileDone(reply)) |
462 reply.finished.connect( |
|
463 lambda: self.__downloadFileDone(reply, filename, doneMethod)) |
473 reply.downloadProgress.connect(self.__downloadProgress) |
464 reply.downloadProgress.connect(self.__downloadProgress) |
474 self.__replies.append(reply) |
465 self.__replies.append(reply) |
475 else: |
466 else: |
476 E5MessageBox.warning( |
467 E5MessageBox.warning( |
477 self, |
468 self, |
479 self.tr( |
470 self.tr( |
480 """<p>Could not download the requested file""" |
471 """<p>Could not download the requested file""" |
481 """ from {0}.</p><p>Error: {1}</p>""" |
472 """ from {0}.</p><p>Error: {1}</p>""" |
482 ).format(url, self.tr("Computer is offline."))) |
473 ).format(url, self.tr("Computer is offline."))) |
483 |
474 |
484 def __downloadFileDone(self, reply): |
475 def __downloadFileDone(self, reply, fileName, doneMethod): |
485 """ |
476 """ |
486 Private method called, after the file has been downloaded |
477 Private method called, after the file has been downloaded |
487 from the Internet. |
478 from the Internet. |
488 |
479 |
489 @param reply reference to the reply object of the download |
480 @param reply reference to the reply object of the download |
490 @type QNetworkReply |
481 @type QNetworkReply |
|
482 @param fileName local name of the file |
|
483 @type str |
|
484 @param doneMethod method to be called when done |
|
485 @type func |
491 """ |
486 """ |
492 self.__updateButton.setEnabled(True) |
487 self.__updateButton.setEnabled(True) |
493 self.__downloadCancelButton.setEnabled(False) |
488 self.__downloadCancelButton.setEnabled(False) |
494 self.__onlineStateChanged(self.__isOnline()) |
489 self.__onlineStateChanged(self.__isOnline()) |
495 |
490 |
496 ok = True |
491 ok = True |
497 if reply in self.__replies: |
492 if reply in self.__replies: |
498 self.__replies.remove(reply) |
493 self.__replies.remove(reply) |
499 if reply.error() != QNetworkReply.NoError: |
494 if reply.error() != QNetworkReply.NoError: |
500 ok = False |
495 ok = False |
501 if not self.__downloadCancelled: |
496 if reply.error() != QNetworkReply.OperationCanceledError: |
502 E5MessageBox.warning( |
497 E5MessageBox.warning( |
503 self, |
498 self, |
504 self.tr("Error downloading file"), |
499 self.tr("Error downloading file"), |
505 self.tr( |
500 self.tr( |
506 """<p>Could not download the requested file""" |
501 """<p>Could not download the requested file""" |
507 """ from {0}.</p><p>Error: {1}</p>""" |
502 """ from {0}.</p><p>Error: {1}</p>""" |
508 ).format(self.__downloadURL, reply.errorString()) |
503 ).format(reply.url().toString(), reply.errorString()) |
509 ) |
504 ) |
510 self.downloadProgress.setValue(0) |
505 self.downloadProgress.setValue(0) |
511 self.__downloadURL = None |
|
512 self.__downloadIODevice.remove() |
|
513 self.__downloadIODevice = None |
|
514 if self.repositoryList.topLevelItemCount(): |
506 if self.repositoryList.topLevelItemCount(): |
515 if self.repositoryList.currentItem() is None: |
507 if self.repositoryList.currentItem() is None: |
516 self.repositoryList.setCurrentItem( |
508 self.repositoryList.setCurrentItem( |
517 self.repositoryList.topLevelItem(0)) |
509 self.repositoryList.topLevelItem(0)) |
518 else: |
510 else: |
521 self.__downloadInstallButton.setEnabled( |
513 self.__downloadInstallButton.setEnabled( |
522 len(self.__selectedItems())) |
514 len(self.__selectedItems())) |
523 reply.deleteLater() |
515 reply.deleteLater() |
524 return |
516 return |
525 |
517 |
526 self.__downloadIODevice.open(QIODevice.WriteOnly) |
518 downloadIODevice = QFile(fileName + ".tmp") |
|
519 downloadIODevice.open(QIODevice.WriteOnly) |
527 # read data in chunks |
520 # read data in chunks |
528 chunkSize = 64 * 1024 * 1024 |
521 chunkSize = 64 * 1024 * 1024 |
529 while True: |
522 while True: |
530 data = reply.read(chunkSize) |
523 data = reply.read(chunkSize) |
531 if data is None or len(data) == 0: |
524 if data is None or len(data) == 0: |
532 break |
525 break |
533 self.__downloadIODevice.write(data) |
526 downloadIODevice.write(data) |
534 self.__downloadIODevice.close() |
527 downloadIODevice.close() |
535 if QFile.exists(self.__downloadFileName): |
528 if QFile.exists(fileName): |
536 QFile.remove(self.__downloadFileName) |
529 QFile.remove(fileName) |
537 self.__downloadIODevice.rename(self.__downloadFileName) |
530 downloadIODevice.rename(fileName) |
538 self.__downloadIODevice = None |
|
539 self.__downloadURL = None |
|
540 reply.deleteLater() |
531 reply.deleteLater() |
541 |
532 |
542 if self.__doneMethod is not None: |
533 if doneMethod is not None: |
543 self.__doneMethod(ok, self.__downloadFileName) |
534 doneMethod(ok, fileName) |
544 |
535 |
545 def __downloadCancel(self): |
536 def __downloadCancel(self, reply=None): |
546 """ |
537 """ |
547 Private slot to cancel the current download. |
538 Private slot to cancel the current download. |
548 """ |
539 |
549 if self.__replies: |
540 @param reply reference to the network reply |
550 reply = self.__replies[0] |
541 @type QNetworkReply |
551 self.__downloadCancelled = True |
542 """ |
552 self.__pluginsToDownload = [] |
543 if reply is None: |
|
544 if self.__replies: |
|
545 reply = self.__replies[0] |
|
546 self.__pluginsToDownload = [] |
|
547 if reply is not None: |
553 reply.abort() |
548 reply.abort() |
554 |
549 |
555 def __downloadProgress(self, done, total): |
550 def __downloadProgress(self, done, total): |
556 """ |
551 """ |
557 Private slot to show the download progress. |
552 Private slot to show the download progress. |
693 @param reply reference to the reply object (QNetworkReply) |
688 @param reply reference to the reply object (QNetworkReply) |
694 @param errors list of SSL errors (list of QSslError) |
689 @param errors list of SSL errors (list of QSslError) |
695 """ |
690 """ |
696 ignored = self.__sslErrorHandler.sslErrorsReply(reply, errors)[0] |
691 ignored = self.__sslErrorHandler.sslErrorsReply(reply, errors)[0] |
697 if ignored == E5SslErrorHandler.NotIgnored: |
692 if ignored == E5SslErrorHandler.NotIgnored: |
698 self.__downloadCancelled = True |
693 self.__downloadCancel(reply) |
699 |
694 |
700 def getDownloadedPlugins(self): |
695 def getDownloadedPlugins(self): |
701 """ |
696 """ |
702 Public method to get the list of recently downloaded plugin files. |
697 Public method to get the list of recently downloaded plugin files. |
703 |
698 |