diff --git a/cura/API/Account.py b/cura/API/Account.py index 4703e92e2f..41f2b20c86 100644 --- a/cura/API/Account.py +++ b/cura/API/Account.py @@ -35,6 +35,7 @@ class Account(QObject): isSyncingChanged = pyqtSignal(bool) manualSyncRequested = pyqtSignal() lastSyncDateTimeChanged = pyqtSignal() + syncStateChanged = pyqtSignal() def __init__(self, application: "CuraApplication", parent = None) -> None: super().__init__(parent) @@ -43,6 +44,7 @@ class Account(QObject): self._error_message = None # type: Optional[Message] self._logged_in = False + self._sync_state = "idle" self._last_sync_str = "-" self._callback_port = 32118 @@ -136,15 +138,24 @@ class Account(QObject): return user_profile.__dict__ def _onIsSyncingChanged(self, active: bool): - if not active: + if active: + self._sync_state = "syncing" + else: # finished + self._sync_state = "success" self._last_sync_str = datetime.now().strftime("%d/%m/%Y %H:%M") self.lastSyncDateTimeChanged.emit() + self.syncStateChanged.emit() + @pyqtProperty(str, notify=lastSyncDateTimeChanged) def lastSyncDateTime(self) -> str: return self._last_sync_str + @pyqtProperty(str, notify=syncStateChanged) + def syncState(self) -> str: + return self._sync_state + @pyqtSlot() def sync(self) -> None: """Checks for new cloud printers""" diff --git a/resources/qml/Account/SyncStateError.qml b/resources/qml/Account/SyncStateError.qml new file mode 100644 index 0000000000..ad8e3dfe2d --- /dev/null +++ b/resources/qml/Account/SyncStateError.qml @@ -0,0 +1,38 @@ +import QtQuick 2.10 +import QtQuick.Controls 2.3 + +import UM 1.4 as UM +import Cura 1.1 as Cura + +Row // sync state icon + message +{ + width: childrenRect.width + height: childrenRect.height + anchors.horizontalCenter: parent.horizontalCenter + spacing: UM.Theme.getSize("narrow_margin").height + + + + UM.RecolorImage + { + id: updateImage + width: 20 * screenScaleFactor + height: width + + source: UM.Theme.getIcon("warning_light") + color: palette.text + + signal syncingChanged(bool newSyncing) + property double animationDuration: 1500 + + } + + Label + { + id: syncStateSuccessLabel + text: catalog.i18nc("@info", "Something went wrong...\nPlease try again later.") + color: UM.Theme.getColor("text") + font: UM.Theme.getFont("medium") + renderType: Text.NativeRendering + } +} \ No newline at end of file diff --git a/resources/qml/Account/SyncStateIdle.qml b/resources/qml/Account/SyncStateIdle.qml new file mode 100644 index 0000000000..d08bcc7bad --- /dev/null +++ b/resources/qml/Account/SyncStateIdle.qml @@ -0,0 +1,44 @@ +import QtQuick 2.10 +import QtQuick.Controls 2.3 + +import UM 1.4 as UM +import Cura 1.1 as Cura + +Row // sync state icon + message +{ + width: childrenRect.width + height: childrenRect.height + anchors.horizontalCenter: parent.horizontalCenter + spacing: UM.Theme.getSize("narrow_margin").height + + + + UM.RecolorImage + { + id: updateImage + width: 20 * screenScaleFactor + height: width + + source: UM.Theme.getIcon("update") + color: palette.text + + } + + Label + { + id: accountSyncButton + text: catalog.i18nc("@button", "Check for account updates") + color: UM.Theme.getColor("secondary_button_text") + font: UM.Theme.getFont("medium") + renderType: Text.NativeRendering + + MouseArea + { + anchors.fill: parent + onClicked: Cura.API.account.sync() + hoverEnabled: true + onEntered: accountSyncButton.font.underline = true + onExited: accountSyncButton.font.underline = false + } + } +} \ No newline at end of file diff --git a/resources/qml/Account/SyncStateSuccess.qml b/resources/qml/Account/SyncStateSuccess.qml new file mode 100644 index 0000000000..fa6051a71b --- /dev/null +++ b/resources/qml/Account/SyncStateSuccess.qml @@ -0,0 +1,32 @@ +import QtQuick 2.10 +import QtQuick.Controls 2.3 + +import UM 1.4 as UM +import Cura 1.1 as Cura + +Row // sync state icon + message +{ + width: childrenRect.width + height: childrenRect.height + anchors.horizontalCenter: parent.horizontalCenter + spacing: UM.Theme.getSize("narrow_margin").height + + UM.RecolorImage + { + id: updateImage + width: 20 * screenScaleFactor + height: width + + source: UM.Theme.getIcon("checked") + color: palette.text + } + + Label + { + id: syncStateSuccessLabel + text: catalog.i18nc("@info", "You are up to date") + color: UM.Theme.getColor("text") + font: UM.Theme.getFont("medium") + renderType: Text.NativeRendering + } +} \ No newline at end of file diff --git a/resources/qml/Account/SyncStateSyncing.qml b/resources/qml/Account/SyncStateSyncing.qml new file mode 100644 index 0000000000..1dd5101254 --- /dev/null +++ b/resources/qml/Account/SyncStateSyncing.qml @@ -0,0 +1,43 @@ +import QtQuick 2.10 +import QtQuick.Controls 2.3 + +import UM 1.4 as UM +import Cura 1.1 as Cura + +Row // sync state icon + message +{ + width: childrenRect.width + height: childrenRect.height + anchors.horizontalCenter: parent.horizontalCenter + spacing: UM.Theme.getSize("narrow_margin").height + + UM.RecolorImage + { + id: updateImage + width: 20 * screenScaleFactor + height: width + + source: UM.Theme.getIcon("update") + color: palette.text + + RotationAnimator + { + id: updateAnimator + target: updateImage + from: 0 + to: 360 + duration: 1000 + loops: Animation.Infinite + running: true + } + } + + Label + { + id: accountSyncButton + text: catalog.i18nc("@button", "Checking...") + color: UM.Theme.getColor("text") + font: UM.Theme.getFont("medium") + renderType: Text.NativeRendering + } +} \ No newline at end of file diff --git a/resources/qml/Account/UserOperations.qml b/resources/qml/Account/UserOperations.qml index 188f1d56ea..da4d4dabbe 100644 --- a/resources/qml/Account/UserOperations.qml +++ b/resources/qml/Account/UserOperations.qml @@ -29,79 +29,23 @@ Column color: UM.Theme.getColor("text") } - Row - { - width: childrenRect.width - height: childrenRect.height - anchors.horizontalCenter: parent.horizontalCenter - spacing: UM.Theme.getSize("narrow_margin").height - - - - UM.RecolorImage - { - id: updateImage - width: 20 * screenScaleFactor - height: width - - source: UM.Theme.getIcon("update") - color: palette.text - - signal syncingChanged(bool newSyncing) - property double animationDuration: 1500 - - - RotationAnimator - { - id: updateAnimator - target: updateImage - to: 360; - } - - onSyncingChanged: - { - if(newSyncing) - { - // start infinite rotation loop - updateAnimator.from = 0 - updateAnimator.duration = animationDuration - updateAnimator.loops = Animation.Infinite - updateAnimator.start() - } else { - // complete current rotation - updateAnimator.stop() - updateAnimator.from = updateImage.rotation - updateAnimator.duration = ((360 - updateImage.rotation) / 360) * animationDuration - updateAnimator.loops = 1 - updateAnimator.start() - } - } - - Component.onCompleted: Cura.API.account.isSyncingChanged.connect(syncingChanged) //todo connect to pyqtsignal or a pyqtproperty? - - - } - - Label - { - id: accountSyncButton - text: catalog.i18nc("@button", "Check for account updates") - color: UM.Theme.getColor("secondary_button_text") - font: UM.Theme.getFont("medium") - renderType: Text.NativeRendering - - MouseArea - { - anchors.fill: parent - onClicked: Cura.API.account.sync() - hoverEnabled: true - onEntered: accountSyncButton.font.underline = true - onExited: accountSyncButton.font.underline = false - } - } + SyncStateIdle { + visible: Cura.API.account.syncState == "idle" } - Label + SyncStateSyncing { + visible: Cura.API.account.syncState == "syncing" + } + + SyncStateSuccess { + visible: Cura.API.account.syncState == "success" + } + + SyncStateError { + visible: Cura.API.account.syncState == "error" + } + + Label { id: lastSyncLabel anchors.horizontalCenter: parent.horizontalCenter