diff -r cfd0e44ef084 -r e91b276e0771 eric7/UI/UserInterface.py --- a/eric7/UI/UserInterface.py Sat Sep 04 16:51:35 2021 +0200 +++ b/eric7/UI/UserInterface.py Sat Sep 04 20:26:21 2021 +0200 @@ -58,6 +58,7 @@ from Tasks.TasksFile import TasksFile +from EricNetwork.EricNetworkIcon import EricNetworkIcon from EricNetwork.EricNetworkProxyFactory import ( EricNetworkProxyFactory, proxyAuthenticationRequired ) @@ -146,6 +147,8 @@ name of the menu and a reference to the menu are given. @signal masterPasswordChanged(str, str) emitted after the master password has been changed with the old and the new password + @signal onlineStateChanged(online) emitted to indicate a change of the + network state """ appendStderr = pyqtSignal(str) appendStdout = pyqtSignal(str) @@ -153,6 +156,7 @@ reloadAPIs = pyqtSignal() showMenu = pyqtSignal(str, QMenu) masterPasswordChanged = pyqtSignal(str, str) + onlineStateChanged = pyqtSignal(bool) maxFilePathLen = 100 maxMenuFilePathLen = 75 @@ -586,10 +590,8 @@ self.__initExternalToolsActions() # redirect handling of http and https URLs to ourselves - # TODO: enable this once PyQt 6.2.0/Qt 6.2.0 is released - if False: - QDesktopServices.setUrlHandler("http", self.handleUrl) - QDesktopServices.setUrlHandler("https", self.handleUrl) + QDesktopServices.setUrlHandler("http", self.handleUrl) + QDesktopServices.setUrlHandler("https", self.handleUrl) # register all relevant objects splash.showMessage(self.tr("Registering Objects...")) @@ -3606,6 +3608,11 @@ self.sbVcsMonitorLed = StatusMonitorLedWidget( self.project, self.__statusBar) self.__statusBar.addPermanentWidget(self.sbVcsMonitorLed) + + self.networkIcon = EricNetworkIcon(self.__statusBar) + self.__statusBar.addPermanentWidget(self.networkIcon) + self.networkIcon.onlineStateChanged.connect(self.onlineStateChanged) + self.networkIcon.onlineStateChanged.connect(self.__onlineStateChanged) def __initExternalToolsActions(self): """ @@ -6876,7 +6883,8 @@ """ Public method to check the availability of updates of plug-ins. """ - self.pluginManager.checkPluginUpdatesAvailable() + if self.isOnline(): + self.pluginManager.checkPluginUpdatesAvailable() ################################################################# ## Drag and Drop Support @@ -7036,6 +7044,25 @@ Preferences.syncPreferences() self.shutdownCalled = True return True + + def isOnline(self): + """ + Public method to get the online state. + + @return online state + @rtype bool + """ + return self.networkIcon.isOnline() + + def __onlineStateChanged(self, online): + """ + Private slot handling changes in online state. + + @param online flag indicating the online state + @type bool + """ + if online: + self.performVersionCheck(False) ############################################## ## Below are methods to check for new versions @@ -7057,54 +7084,65 @@ @param alternative index of server to download from (integer) @param showVersions flag indicating the show versions mode (boolean) """ - if not manual: - if VersionOnly.startswith("@@"): - return - else: - period = Preferences.getUI("PerformVersionCheck") - if period == 0: + if self.isOnline(): + if not manual: + if VersionOnly.startswith("@@"): return - elif period in [2, 3, 4]: - lastCheck = Preferences.Prefs.settings.value( - "Updates/LastCheckDate", QDate(1970, 1, 1)) - if lastCheck.isValid(): - now = QDate.currentDate() - if ( - (period == 2 and lastCheck.day() == now.day()) or - (period == 3 and lastCheck.daysTo(now) < 7) or - (period == 4 and (lastCheck.daysTo(now) < - lastCheck.daysInMonth())) - ): - # daily, weekly, monthly - return - - self.__inVersionCheck = True - self.manualUpdatesCheck = manual - self.showAvailableVersions = showVersions - self.httpAlternative = alternative - url = QUrl(self.__httpAlternatives[alternative]) - self.__versionCheckCanceled = False - if manual: - if self.__versionCheckProgress is None: - self.__versionCheckProgress = EricProgressDialog( - "", self.tr("&Cancel"), - 0, len(self.__httpAlternatives), - self.tr("%v/%m"), self) - self.__versionCheckProgress.setWindowTitle( - self.tr("Version Check")) - self.__versionCheckProgress.setMinimumDuration(0) - self.__versionCheckProgress.canceled.connect( - self.__versionsDownloadCanceled) - self.__versionCheckProgress.setLabelText( - self.tr("Trying host {0}").format(url.host())) - self.__versionCheckProgress.setValue(alternative) - request = QNetworkRequest(url) - request.setAttribute( - QNetworkRequest.Attribute.CacheLoadControlAttribute, - QNetworkRequest.CacheLoadControl.AlwaysNetwork) - reply = self.__networkManager.get(request) - reply.finished.connect(lambda: self.__versionsDownloadDone(reply)) - self.__replies.append(reply) + else: + period = Preferences.getUI("PerformVersionCheck") + if period == 0: + return + elif period in [2, 3, 4]: + lastCheck = Preferences.Prefs.settings.value( + "Updates/LastCheckDate", QDate(1970, 1, 1)) + if lastCheck.isValid(): + now = QDate.currentDate() + if ( + (period == 2 and + lastCheck.day() == now.day()) or + (period == 3 and lastCheck.daysTo(now) < 7) or + (period == 4 and (lastCheck.daysTo(now) < + lastCheck.daysInMonth())) + ): + # daily, weekly, monthly + return + + self.__inVersionCheck = True + self.manualUpdatesCheck = manual + self.showAvailableVersions = showVersions + self.httpAlternative = alternative + url = QUrl(self.__httpAlternatives[alternative]) + self.__versionCheckCanceled = False + if manual: + if self.__versionCheckProgress is None: + self.__versionCheckProgress = EricProgressDialog( + "", self.tr("&Cancel"), + 0, len(self.__httpAlternatives), + self.tr("%v/%m"), self) + self.__versionCheckProgress.setWindowTitle( + self.tr("Version Check")) + self.__versionCheckProgress.setMinimumDuration(0) + self.__versionCheckProgress.canceled.connect( + self.__versionsDownloadCanceled) + self.__versionCheckProgress.setLabelText( + self.tr("Trying host {0}").format(url.host())) + self.__versionCheckProgress.setValue(alternative) + request = QNetworkRequest(url) + request.setAttribute( + QNetworkRequest.Attribute.CacheLoadControlAttribute, + QNetworkRequest.CacheLoadControl.AlwaysNetwork) + reply = self.__networkManager.get(request) + reply.finished.connect(lambda: self.__versionsDownloadDone(reply)) + self.__replies.append(reply) + else: + if manual: + EricMessageBox.warning( + self, + self.tr("Error getting versions information"), + self.tr("The versions information cannot not be" + " downloaded because the Internet is" + " <b>not reachable</b>. Please try again later.") + ) @pyqtSlot() def __versionsDownloadDone(self, reply):