18 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QFile, QIODevice, QUrl, \ |
18 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QFile, QIODevice, QUrl, \ |
19 QProcess, QPoint |
19 QProcess, QPoint |
20 from PyQt5.QtWidgets import QWidget, QDialogButtonBox, QAbstractButton, \ |
20 from PyQt5.QtWidgets import QWidget, QDialogButtonBox, QAbstractButton, \ |
21 QTreeWidgetItem, QDialog, QVBoxLayout, QMenu |
21 QTreeWidgetItem, QDialog, QVBoxLayout, QMenu |
22 from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, \ |
22 from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, \ |
23 QNetworkReply |
23 QNetworkReply, QNetworkConfigurationManager |
24 |
24 |
25 from .Ui_PluginRepositoryDialog import Ui_PluginRepositoryDialog |
25 from .Ui_PluginRepositoryDialog import Ui_PluginRepositoryDialog |
26 |
26 |
27 from E5Gui import E5MessageBox |
27 from E5Gui import E5MessageBox |
28 from E5Gui.E5MainWindow import E5MainWindow |
28 from E5Gui.E5MainWindow import E5MainWindow |
121 if SSL_AVAILABLE: |
121 if SSL_AVAILABLE: |
122 self.__sslErrorHandler = E5SslErrorHandler(self) |
122 self.__sslErrorHandler = E5SslErrorHandler(self) |
123 self.__networkManager.sslErrors.connect(self.__sslErrors) |
123 self.__networkManager.sslErrors.connect(self.__sslErrors) |
124 self.__replies = [] |
124 self.__replies = [] |
125 |
125 |
|
126 self.__networkConfigurationManager = QNetworkConfigurationManager(self) |
|
127 self.__onlineStateChanged( |
|
128 self.__networkConfigurationManager.isOnline()) |
|
129 |
|
130 self.__networkConfigurationManager.onlineStateChanged.connect( |
|
131 self.__onlineStateChanged) |
|
132 |
126 self.__doneMethod = None |
133 self.__doneMethod = None |
127 self.__inDownload = False |
134 self.__inDownload = False |
128 self.__pluginsToDownload = [] |
135 self.__pluginsToDownload = [] |
129 self.__pluginsDownloaded = [] |
136 self.__pluginsDownloaded = [] |
130 self.__isDownloadInstall = False |
137 self.__isDownloadInstall = False |
131 self.__allDownloadedOk = False |
138 self.__allDownloadedOk = False |
132 |
139 |
133 self.__hiddenPlugins = Preferences.getPluginManager("HiddenPlugins") |
140 self.__hiddenPlugins = Preferences.getPluginManager("HiddenPlugins") |
134 |
141 |
135 self.__populateList() |
142 self.__populateList() |
|
143 |
|
144 @pyqtSlot(bool) |
|
145 def __onlineStateChanged(self, online): |
|
146 """ |
|
147 Private slot handling online state changes. |
|
148 |
|
149 @param online flag indicating the online status |
|
150 @type bool |
|
151 """ |
|
152 self.__updateButton.setEnabled(online) |
|
153 self.on_repositoryList_itemSelectionChanged() |
|
154 if online: |
|
155 msg = self.tr("Network Status: online") |
|
156 else: |
|
157 msg = self.tr("Network Status: offline") |
|
158 self.statusLabel.setText(msg) |
136 |
159 |
137 @pyqtSlot(QAbstractButton) |
160 @pyqtSlot(QAbstractButton) |
138 def on_buttonBox_clicked(self, button): |
161 def on_buttonBox_clicked(self, button): |
139 """ |
162 """ |
140 Private slot to handle the click of a button of the button box. |
163 Private slot to handle the click of a button of the button box. |
230 @pyqtSlot() |
253 @pyqtSlot() |
231 def on_repositoryList_itemSelectionChanged(self): |
254 def on_repositoryList_itemSelectionChanged(self): |
232 """ |
255 """ |
233 Private slot to handle a change of the selection. |
256 Private slot to handle a change of the selection. |
234 """ |
257 """ |
235 self.__downloadButton.setEnabled(len(self.__selectedItems())) |
258 self.__downloadButton.setEnabled( |
236 self.__downloadInstallButton.setEnabled(len(self.__selectedItems())) |
259 len(self.__selectedItems()) and |
|
260 self.__networkConfigurationManager.isOnline()) |
|
261 self.__downloadInstallButton.setEnabled( |
|
262 len(self.__selectedItems()) and |
|
263 self.__networkConfigurationManager.isOnline()) |
237 self.__installButton.setEnabled(len(self.__selectedItems())) |
264 self.__installButton.setEnabled(len(self.__selectedItems())) |
238 |
265 |
239 def __updateList(self): |
266 def __updateList(self): |
240 """ |
267 """ |
241 Private slot to download a new list and display the contents. |
268 Private slot to download a new list and display the contents. |
393 |
420 |
394 @param url URL for the download (string) |
421 @param url URL for the download (string) |
395 @param filename local name of the file (string) |
422 @param filename local name of the file (string) |
396 @param doneMethod method to be called when done |
423 @param doneMethod method to be called when done |
397 """ |
424 """ |
398 self.__updateButton.setEnabled(False) |
425 if self.__networkConfigurationManager.isOnline(): |
399 self.__downloadButton.setEnabled(False) |
426 self.__updateButton.setEnabled(False) |
400 self.__downloadInstallButton.setEnabled(False) |
427 self.__downloadButton.setEnabled(False) |
401 self.__downloadCancelButton.setEnabled(True) |
428 self.__downloadInstallButton.setEnabled(False) |
402 |
429 self.__downloadCancelButton.setEnabled(True) |
403 self.statusLabel.setText(url) |
430 |
404 |
431 self.statusLabel.setText(url) |
405 self.__doneMethod = doneMethod |
432 |
406 self.__downloadURL = url |
433 self.__doneMethod = doneMethod |
407 self.__downloadFileName = filename |
434 self.__downloadURL = url |
408 self.__downloadIODevice = QFile(self.__downloadFileName + ".tmp") |
435 self.__downloadFileName = filename |
409 self.__downloadCancelled = False |
436 self.__downloadIODevice = QFile(self.__downloadFileName + ".tmp") |
410 |
437 self.__downloadCancelled = False |
411 request = QNetworkRequest(QUrl(url)) |
438 |
412 request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, |
439 request = QNetworkRequest(QUrl(url)) |
413 QNetworkRequest.AlwaysNetwork) |
440 request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, |
414 reply = self.__networkManager.get(request) |
441 QNetworkRequest.AlwaysNetwork) |
415 reply.finished.connect(self.__downloadFileDone) |
442 reply = self.__networkManager.get(request) |
416 reply.downloadProgress.connect(self.__downloadProgress) |
443 reply.finished.connect(self.__downloadFileDone) |
417 self.__replies.append(reply) |
444 reply.downloadProgress.connect(self.__downloadProgress) |
|
445 self.__replies.append(reply) |
|
446 else: |
|
447 E5MessageBox.warning( |
|
448 self, |
|
449 self.tr("Error downloading file"), |
|
450 self.tr( |
|
451 """<p>Could not download the requested file""" |
|
452 """ from {0}.</p><p>Error: {1}</p>""" |
|
453 ).format(url, self.tr("Computer is offline."))) |
418 |
454 |
419 def __downloadFileDone(self): |
455 def __downloadFileDone(self): |
420 """ |
456 """ |
421 Private method called, after the file has been downloaded |
457 Private method called, after the file has been downloaded |
422 from the internet. |
458 from the internet. |
423 """ |
459 """ |
424 self.__updateButton.setEnabled(True) |
460 self.__updateButton.setEnabled(True) |
425 self.__downloadCancelButton.setEnabled(False) |
461 self.__downloadCancelButton.setEnabled(False) |
426 self.statusLabel.setText(" ") |
462 self.__onlineStateChanged( |
|
463 self.__networkConfigurationManager.isOnline()) |
427 |
464 |
428 ok = True |
465 ok = True |
429 reply = self.sender() |
466 reply = self.sender() |
430 if reply in self.__replies: |
467 if reply in self.__replies: |
431 self.__replies.remove(reply) |
468 self.__replies.remove(reply) |