Browse Source

Add Account sync last update datetime

CURA-7290
Nino van Hooff 4 years ago
parent
commit
acf36d1e42
2 changed files with 26 additions and 0 deletions
  1. 15 0
      cura/API/Account.py
  2. 11 0
      resources/qml/Account/UserOperations.qml

+ 15 - 0
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"""

+ 11 - 0
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