20 from PyQt6.QtWidgets import ( |
20 from PyQt6.QtWidgets import ( |
21 QWidget, QDialogButtonBox, QAbstractButton, QTreeWidgetItem, QDialog, |
21 QWidget, QDialogButtonBox, QAbstractButton, QTreeWidgetItem, QDialog, |
22 QVBoxLayout, QMenu |
22 QVBoxLayout, QMenu |
23 ) |
23 ) |
24 from PyQt6.QtNetwork import ( |
24 from PyQt6.QtNetwork import ( |
25 QNetworkAccessManager, QNetworkRequest, QNetworkReply |
25 QNetworkAccessManager, QNetworkRequest, QNetworkReply, QNetworkInformation |
26 ) |
26 ) |
27 |
27 |
28 from .Ui_PluginRepositoryDialog import Ui_PluginRepositoryDialog |
28 from .Ui_PluginRepositoryDialog import Ui_PluginRepositoryDialog |
29 |
29 |
30 from EricWidgets import EricMessageBox |
30 from EricWidgets import EricMessageBox |
140 if SSL_AVAILABLE: |
140 if SSL_AVAILABLE: |
141 self.__sslErrorHandler = EricSslErrorHandler(self) |
141 self.__sslErrorHandler = EricSslErrorHandler(self) |
142 self.__networkManager.sslErrors.connect(self.__sslErrors) |
142 self.__networkManager.sslErrors.connect(self.__sslErrors) |
143 self.__replies = [] |
143 self.__replies = [] |
144 |
144 |
|
145 if ( |
|
146 Preferences.getUI("DynamicOnlineCheck") and |
|
147 QNetworkInformation.load(QNetworkInformation.Feature.Reachability) |
|
148 ): |
|
149 self.__reachabilityChanged( |
|
150 QNetworkInformation.instance().reachability()) |
|
151 # TODO: QNetworkInformation: re-enable once problem is clear |
|
152 ## QNetworkInformation.instance().reachabilityChanged.connect( |
|
153 ## self.__reachabilityChanged) |
|
154 else: |
|
155 # assume to be 'always online' if no backend could be loaded or |
|
156 # dynamic online check is switched of |
|
157 self.__reachabilityChanged(QNetworkInformation.Reachability.Online) |
|
158 |
145 self.__pluginsToDownload = [] |
159 self.__pluginsToDownload = [] |
146 self.__pluginsDownloaded = [] |
160 self.__pluginsDownloaded = [] |
147 self.__isDownloadInstall = False |
161 self.__isDownloadInstall = False |
148 self.__allDownloadedOk = False |
162 self.__allDownloadedOk = False |
149 |
163 |
150 self.__hiddenPlugins = Preferences.getPluginManager("HiddenPlugins") |
164 self.__hiddenPlugins = Preferences.getPluginManager("HiddenPlugins") |
151 |
165 |
152 self.__populateList() |
166 self.__populateList() |
|
167 |
|
168 @pyqtSlot(QNetworkInformation.Reachability) |
|
169 def __reachabilityChanged(self, reachability): |
|
170 """ |
|
171 Private slot handling reachability state changes. |
|
172 |
|
173 @param reachability new reachability state |
|
174 @type QNetworkInformation.Reachability |
|
175 """ |
|
176 online = reachability == QNetworkInformation.Reachability.Online |
|
177 self.__online = online |
|
178 |
|
179 self.__updateButton.setEnabled(online) |
|
180 self.on_repositoryList_itemSelectionChanged() |
|
181 |
|
182 msg = ( |
|
183 self.tr("Internet Reachability Status: Reachable") |
|
184 if online else |
|
185 self.tr("Internet Reachability Status: Not Reachable") |
|
186 ) |
|
187 self.statusLabel.setText(msg) |
153 |
188 |
154 @pyqtSlot(QAbstractButton) |
189 @pyqtSlot(QAbstractButton) |
155 def on_buttonBox_clicked(self, button): |
190 def on_buttonBox_clicked(self, button): |
156 """ |
191 """ |
157 Private slot to handle the click of a button of the button box. |
192 Private slot to handle the click of a button of the button box. |
264 def on_repositoryList_itemSelectionChanged(self): |
299 def on_repositoryList_itemSelectionChanged(self): |
265 """ |
300 """ |
266 Private slot to handle a change of the selection. |
301 Private slot to handle a change of the selection. |
267 """ |
302 """ |
268 enable = bool(self.__selectedItems()) |
303 enable = bool(self.__selectedItems()) |
269 self.__downloadButton.setEnabled(enable) |
304 self.__downloadButton.setEnabled(enable and self.__online) |
270 self.__downloadInstallButton.setEnabled(enable) |
305 self.__downloadInstallButton.setEnabled(enable and self.__online) |
271 self.__installButton.setEnabled(enable) |
306 self.__installButton.setEnabled(enable) |
272 |
307 |
273 def __updateList(self): |
308 def __updateList(self): |
274 """ |
309 """ |
275 Private slot to download a new list and display the contents. |
310 Private slot to download a new list and display the contents. |
442 |
477 |
443 @param url URL for the download (string) |
478 @param url URL for the download (string) |
444 @param filename local name of the file (string) |
479 @param filename local name of the file (string) |
445 @param doneMethod method to be called when done |
480 @param doneMethod method to be called when done |
446 """ |
481 """ |
447 self.__updateButton.setEnabled(False) |
482 if self.__online: |
448 self.__downloadButton.setEnabled(False) |
483 self.__updateButton.setEnabled(False) |
449 self.__downloadInstallButton.setEnabled(False) |
484 self.__downloadButton.setEnabled(False) |
450 self.__closeButton.setEnabled(False) |
485 self.__downloadInstallButton.setEnabled(False) |
451 self.__downloadCancelButton.setEnabled(True) |
486 self.__closeButton.setEnabled(False) |
452 |
487 self.__downloadCancelButton.setEnabled(True) |
453 self.statusLabel.setText(url) |
488 |
454 |
489 self.statusLabel.setText(url) |
455 request = QNetworkRequest(QUrl(url)) |
490 |
456 request.setAttribute( |
491 request = QNetworkRequest(QUrl(url)) |
457 QNetworkRequest.Attribute.CacheLoadControlAttribute, |
492 request.setAttribute( |
458 QNetworkRequest.CacheLoadControl.AlwaysNetwork) |
493 QNetworkRequest.Attribute.CacheLoadControlAttribute, |
459 reply = self.__networkManager.get(request) |
494 QNetworkRequest.CacheLoadControl.AlwaysNetwork) |
460 reply.finished.connect( |
495 reply = self.__networkManager.get(request) |
461 lambda: self.__downloadFileDone(reply, filename, doneMethod)) |
496 reply.finished.connect( |
462 reply.downloadProgress.connect(self.__downloadProgress) |
497 lambda: self.__downloadFileDone(reply, filename, doneMethod)) |
463 self.__replies.append(reply) |
498 reply.downloadProgress.connect(self.__downloadProgress) |
|
499 self.__replies.append(reply) |
|
500 else: |
|
501 EricMessageBox.warning( |
|
502 self, |
|
503 self.tr("Error downloading file"), |
|
504 self.tr( |
|
505 """<p>Could not download the requested file""" |
|
506 """ from {0}.</p><p>Error: {1}</p>""" |
|
507 ).format(url, self.tr("No connection to Internet."))) |
464 |
508 |
465 def __downloadFileDone(self, reply, fileName, doneMethod): |
509 def __downloadFileDone(self, reply, fileName, doneMethod): |
466 """ |
510 """ |
467 Private method called, after the file has been downloaded |
511 Private method called, after the file has been downloaded |
468 from the Internet. |
512 from the Internet. |