diff --git a/cura/API/Account.py b/cura/API/Account.py index 7c81358379..84bbd566cf 100644 --- a/cura/API/Account.py +++ b/cura/API/Account.py @@ -1,5 +1,6 @@ # Copyright (c) 2018 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +from datetime import datetime from typing import Optional, Dict, TYPE_CHECKING from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot, pyqtProperty @@ -33,6 +34,7 @@ class Account(QObject): cloudPrintersDetectedChanged = pyqtSignal(bool) isSyncingChanged = pyqtSignal(bool) manualSyncRequested = pyqtSignal() + lastSyncDateTimeChanged = pyqtSignal() def __init__(self, application: "CuraApplication", parent = None) -> None: super().__init__(parent) @@ -41,6 +43,7 @@ class Account(QObject): self._error_message = None # type: Optional[Message] self._logged_in = False + self._last_sync_str = "-" self._callback_port = 32118 self._oauth_root = UltimakerCloudAuthentication.CuraCloudAccountAPIRoot @@ -66,6 +69,7 @@ class Account(QObject): self._authorization_service.onAuthenticationError.connect(self._onLoginStateChanged) self._authorization_service.accessTokenChanged.connect(self._onAccessTokenChanged) self._authorization_service.loadAuthDataFromPreferences() + self.isSyncingChanged.connect(self._onIsSyncingChanged) def _onAccessTokenChanged(self): self.accessTokenChanged.emit() @@ -131,6 +135,17 @@ class Account(QObject): return None return user_profile.__dict__ + def _onIsSyncingChanged(self, active: bool): + Logger.info("active: {}", active) + if not active: + # finished + self._last_sync_str = datetime.now().strftime("%d/%m/%Y %H:%M:%S") + self.lastSyncDateTimeChanged.emit() + + @pyqtProperty(str, notify=lastSyncDateTimeChanged) + def lastSyncDateTime(self) -> str: + return self._last_sync_str + @pyqtSlot() def sync(self) -> None: """Checks for new cloud printers""" diff --git a/resources/qml/Account/UserOperations.qml b/resources/qml/Account/UserOperations.qml index 08c3e0a61a..188f1d56ea 100644 --- a/resources/qml/Account/UserOperations.qml +++ b/resources/qml/Account/UserOperations.qml @@ -101,6 +101,17 @@ Column } } + Label + { + id: lastSyncLabel + anchors.horizontalCenter: parent.horizontalCenter + horizontalAlignment: Text.AlignHCenter + renderType: Text.NativeRendering + text: catalog.i18nc("@label The argument is a timestamp", "Last update: %1").arg(Cura.API.account.lastSyncDateTime) + font: UM.Theme.getFont("default") + color: UM.Theme.getColor("text_medium") + } + Cura.SecondaryButton { id: accountButton