mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-09 07:56: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)
|
loginStateChanged = pyqtSignal(bool)
|
||||||
accessTokenChanged = pyqtSignal()
|
accessTokenChanged = pyqtSignal()
|
||||||
cloudPrintersDetectedChanged = pyqtSignal(bool)
|
cloudPrintersDetectedChanged = pyqtSignal(bool)
|
||||||
isSyncingChanged = pyqtSignal(bool)
|
isSyncingChanged = pyqtSignal(str)
|
||||||
manualSyncRequested = pyqtSignal()
|
manualSyncRequested = pyqtSignal()
|
||||||
lastSyncDateTimeChanged = pyqtSignal()
|
lastSyncDateTimeChanged = pyqtSignal()
|
||||||
syncStateChanged = pyqtSignal()
|
syncStateChanged = pyqtSignal()
|
||||||
|
@ -137,15 +137,12 @@ class Account(QObject):
|
||||||
return None
|
return None
|
||||||
return user_profile.__dict__
|
return user_profile.__dict__
|
||||||
|
|
||||||
def _onIsSyncingChanged(self, active: bool):
|
def _onIsSyncingChanged(self, newState: str):
|
||||||
if active:
|
if newState == "success":
|
||||||
self._sync_state = "syncing"
|
|
||||||
else:
|
|
||||||
# finished
|
|
||||||
self._sync_state = "success"
|
|
||||||
self._last_sync_str = datetime.now().strftime("%d/%m/%Y %H:%M")
|
self._last_sync_str = datetime.now().strftime("%d/%m/%Y %H:%M")
|
||||||
self.lastSyncDateTimeChanged.emit()
|
self.lastSyncDateTimeChanged.emit()
|
||||||
|
|
||||||
|
self._sync_state = newState
|
||||||
self.syncStateChanged.emit()
|
self.syncStateChanged.emit()
|
||||||
|
|
||||||
@pyqtProperty(str, notify=lastSyncDateTimeChanged)
|
@pyqtProperty(str, notify=lastSyncDateTimeChanged)
|
||||||
|
|
|
@ -53,10 +53,10 @@ class CloudApiClient:
|
||||||
|
|
||||||
## Retrieves all the clusters for the user that is currently logged in.
|
## 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.
|
# \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)
|
url = "{}/clusters?status=active".format(self.CLUSTER_API_ROOT)
|
||||||
reply = self._manager.get(self._createEmptyRequest(url))
|
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.
|
## Retrieves the status of the given cluster.
|
||||||
# \param cluster_id: The ID of the cluster.
|
# \param cluster_id: The ID of the cluster.
|
||||||
|
@ -166,16 +166,24 @@ class CloudApiClient:
|
||||||
reply: QNetworkReply,
|
reply: QNetworkReply,
|
||||||
on_finished: Union[Callable[[CloudApiClientModel], Any],
|
on_finished: Union[Callable[[CloudApiClientModel], Any],
|
||||||
Callable[[List[CloudApiClientModel]], Any]],
|
Callable[[List[CloudApiClientModel]], Any]],
|
||||||
model: Type[CloudApiClientModel]) -> None:
|
model: Type[CloudApiClientModel],
|
||||||
|
on_error: Optional[Callable] = None) -> None:
|
||||||
def parse() -> None:
|
def parse() -> None:
|
||||||
self._anti_gc_callbacks.remove(parse)
|
self._anti_gc_callbacks.remove(parse)
|
||||||
|
|
||||||
# Don't try to parse the reply if we didn't get one
|
# Don't try to parse the reply if we didn't get one
|
||||||
if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) is None:
|
if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) is None:
|
||||||
|
if on_error is not None:
|
||||||
|
on_error()
|
||||||
return
|
return
|
||||||
|
|
||||||
status_code, response = self._parseReply(reply)
|
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._parseModels(response, on_finished, model)
|
||||||
|
|
||||||
self._anti_gc_callbacks.append(parse)
|
self._anti_gc_callbacks.append(parse)
|
||||||
reply.finished.connect(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._update_timer.stop()
|
||||||
|
|
||||||
self._syncing = True
|
self._syncing = True
|
||||||
self._account.isSyncingChanged.emit(True)
|
self._account.isSyncingChanged.emit("syncing")
|
||||||
self._api.getClusters(self._onGetRemoteClustersFinished)
|
self._api.getClusters(self._onGetRemoteClustersFinished, self._onGetRemoteClusterFailed)
|
||||||
|
|
||||||
def _onGetRemoteClustersFinished(self, clusters: List[CloudClusterResponse]) -> None:
|
def _onGetRemoteClustersFinished(self, clusters: List[CloudClusterResponse]) -> None:
|
||||||
"""Callback for when the request for getting the clusters is finished."""
|
"""Callback for when the request for getting the clusters is finished."""
|
||||||
|
@ -133,7 +133,13 @@ class CloudOutputDeviceManager:
|
||||||
self._connectToActiveMachine()
|
self._connectToActiveMachine()
|
||||||
|
|
||||||
self._syncing = False
|
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
|
# Schedule a new update
|
||||||
self._update_timer.start()
|
self._update_timer.start()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue