mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 23:46:22 -06:00
Implement printer cloud sync error state
CURA-7290
This commit is contained in:
parent
4e7f446fe1
commit
81d02d5d58
3 changed files with 25 additions and 14 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
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)
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue