diff options
author | Nino van Hooff <ninovanhooff@gmail.com> | 2020-06-15 12:39:06 +0300 |
---|---|---|
committer | Nino van Hooff <ninovanhooff@gmail.com> | 2020-06-15 12:39:06 +0300 |
commit | 994f9fbde7230e90d557621533b21ccb50f2c278 (patch) | |
tree | 7beee1a0a1291aa5f7e9204c99b93aa16f86e578 /cura/API | |
parent | 9bf9bf9a3f87dbe09ac27e5c82f19bd70ef3039c (diff) |
Re-implement ConnectionStatus by adding a pyqtSignal to HttpRequestMgr
and using ConnectionStatus as proxy for it.
CURA-7492
Diffstat (limited to 'cura/API')
-rw-r--r-- | cura/API/ConnectionStatus.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/cura/API/ConnectionStatus.py b/cura/API/ConnectionStatus.py index 483284d1c7..36f804e3cf 100644 --- a/cura/API/ConnectionStatus.py +++ b/cura/API/ConnectionStatus.py @@ -2,11 +2,16 @@ from typing import Optional from PyQt5.QtCore import QObject, pyqtSignal, pyqtProperty -from UM.Logger import Logger +from UM.TaskManagement.HttpRequestManager import HttpRequestManager class ConnectionStatus(QObject): - """Status info for some web services""" + """Provides an estimation of whether internet is reachable + + Estimation is updated with every request through HttpRequestManager. + Acts as a proxy to HttpRequestManager.internetReachableChanged without + exposing the HttpRequestManager in its entirety. + """ __instance = None # type: Optional[ConnectionStatus] @@ -21,16 +26,16 @@ class ConnectionStatus(QObject): def __init__(self, parent: Optional["QObject"] = None) -> None: super().__init__(parent) - self._is_internet_reachable = True # type: bool + manager = HttpRequestManager.getInstance() + self._is_internet_reachable = manager.isInternetReachable # type: bool + manager.internetReachableChanged.connect(self._onInternetReachableChanged) @pyqtProperty(bool, notify = internetReachableChanged) def isInternetReachable(self) -> bool: return self._is_internet_reachable - def setOnlineStatus(self, new_status: bool) -> None: - old_status = self._is_internet_reachable - self._is_internet_reachable = new_status - if old_status != new_status: - Logger.debug( - "Connection status has been set to {}".format("online" if self._is_internet_reachable else "offline")) + def _onInternetReachableChanged(self, reachable: bool): + if reachable != self._is_internet_reachable: + self._is_internet_reachable = reachable self.internetReachableChanged.emit() + |