diff --git a/cura/API/Account.py b/cura/API/Account.py index 41f2b20c86..ebab9c6677 100644 --- a/cura/API/Account.py +++ b/cura/API/Account.py @@ -32,7 +32,7 @@ class Account(QObject): loginStateChanged = pyqtSignal(bool) accessTokenChanged = pyqtSignal() cloudPrintersDetectedChanged = pyqtSignal(bool) - isSyncingChanged = pyqtSignal(bool) + isSyncingChanged = pyqtSignal(str) manualSyncRequested = pyqtSignal() lastSyncDateTimeChanged = pyqtSignal() syncStateChanged = pyqtSignal() @@ -137,15 +137,12 @@ class Account(QObject): return None return user_profile.__dict__ - def _onIsSyncingChanged(self, active: bool): - if active: - self._sync_state = "syncing" - else: - # finished - self._sync_state = "success" + def _onIsSyncingChanged(self, newState: str): + if newState == "success": self._last_sync_str = datetime.now().strftime("%d/%m/%Y %H:%M") self.lastSyncDateTimeChanged.emit() + self._sync_state = newState self.syncStateChanged.emit() @pyqtProperty(str, notify=lastSyncDateTimeChanged) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py index 6fec436843..1c9670d87f 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py @@ -53,10 +53,10 @@ class CloudApiClient: ## Retrieves all the clusters for the user that is currently logged in. # \param on_finished: The function to be called after the result is parsed. - def getClusters(self, on_finished: Callable[[List[CloudClusterResponse]], Any]) -> None: + def getClusters(self, on_finished: Callable[[List[CloudClusterResponse]], Any], failed: Callable) -> None: url = "{}/clusters?status=active".format(self.CLUSTER_API_ROOT) reply = self._manager.get(self._createEmptyRequest(url)) - self._addCallback(reply, on_finished, CloudClusterResponse) + self._addCallback(reply, on_finished, CloudClusterResponse, failed) ## Retrieves the status of the given cluster. # \param cluster_id: The ID of the cluster. @@ -166,16 +166,24 @@ class CloudApiClient: reply: QNetworkReply, on_finished: Union[Callable[[CloudApiClientModel], Any], Callable[[List[CloudApiClientModel]], Any]], - model: Type[CloudApiClientModel]) -> None: + model: Type[CloudApiClientModel], + on_error: Optional[Callable] = None) -> None: def parse() -> None: self._anti_gc_callbacks.remove(parse) # Don't try to parse the reply if we didn't get one if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) is None: + if on_error is not None: + on_error() return status_code, response = self._parseReply(reply) - self._parseModels(response, on_finished, model) + if status_code >= 300 and on_error is not None: + on_error() + else: + self._parseModels(response, on_finished, model) self._anti_gc_callbacks.append(parse) reply.finished.connect(parse) + if on_error is not None: + reply.error.connect(on_error) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index ef478f338a..c95d94f0fd 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -103,8 +103,8 @@ class CloudOutputDeviceManager: self._update_timer.stop() self._syncing = True - self._account.isSyncingChanged.emit(True) - self._api.getClusters(self._onGetRemoteClustersFinished) + self._account.isSyncingChanged.emit("syncing") + self._api.getClusters(self._onGetRemoteClustersFinished, self._onGetRemoteClusterFailed) def _onGetRemoteClustersFinished(self, clusters: List[CloudClusterResponse]) -> None: """Callback for when the request for getting the clusters is finished.""" @@ -133,7 +133,13 @@ class CloudOutputDeviceManager: self._connectToActiveMachine() self._syncing = False - self._account.isSyncingChanged.emit(False) + self._account.isSyncingChanged.emit("success") + # Schedule a new update + self._update_timer.start() + + def _onGetRemoteClusterFailed(self): + self._syncing = False + self._account.isSyncingChanged.emit("error") # Schedule a new update self._update_timer.start()