Browse Source

Only show the manual sync button after the account popup was closed

CURA-7290
Nino van Hooff 4 years ago
parent
commit
f78fa884c1
3 changed files with 42 additions and 16 deletions
  1. 31 12
      cura/API/Account.py
  2. 9 1
      resources/qml/Account/AccountWidget.qml
  3. 2 3
      resources/qml/Account/SyncState.qml

+ 31 - 12
cura/API/Account.py

@@ -50,6 +50,7 @@ class Account(QObject):
     """
     lastSyncDateTimeChanged = pyqtSignal()
     syncStateChanged = pyqtSignal(int)  # because SyncState is an int Enum
+    manualSyncEnabledChanged = pyqtSignal(bool)
 
     def __init__(self, application: "CuraApplication", parent = None) -> None:
         super().__init__(parent)
@@ -59,6 +60,7 @@ class Account(QObject):
         self._error_message = None  # type: Optional[Message]
         self._logged_in = False
         self._sync_state = SyncState.SUCCESS
+        self._manual_sync_enabled = False
         self._last_sync_str = "-"
 
         self._callback_port = 32118
@@ -157,11 +159,25 @@ class Account(QObject):
             self._logged_in = logged_in
             self.loginStateChanged.emit(logged_in)
             if logged_in:
-                self.sync()
+                self._sync()
             else:
                 if self._update_timer.isActive():
                     self._update_timer.stop()
 
+    def _sync(self) -> None:
+        """Signals all sync services to start syncing
+
+        This can be considered a forced sync: even when a
+        sync is currently running, a sync will be requested.
+        """
+
+        if self._update_timer.isActive():
+            self._update_timer.stop()
+        elif self._sync_state == SyncState.SYNCING:
+            Logger.warning("Starting a new sync while previous sync was not completed\n{}", str(self._sync_services))
+
+        self.syncRequested.emit()
+
     @pyqtSlot()
     def login(self) -> None:
         if self._logged_in:
@@ -200,20 +216,23 @@ class Account(QObject):
     def lastSyncDateTime(self) -> str:
         return self._last_sync_str
 
-    @pyqtSlot()
-    def sync(self) -> None:
-        """Signals all sync services to start syncing
+    @pyqtProperty(bool, notify=manualSyncEnabledChanged)
+    def manualSyncEnabled(self) -> bool:
+        return self._manual_sync_enabled
 
-        This can be considered a forced sync: even when a
-        sync is currently running, a sync will be requested.
-        """
+    @pyqtSlot()
+    @pyqtSlot(bool)
+    def sync(self, user_initiated=False):
+        if user_initiated:
+            self._manual_sync_enabled = False
+            self.manualSyncEnabledChanged.emit(self._manual_sync_enabled)
 
-        if self._update_timer.isActive():
-            self._update_timer.stop()
-        elif self._sync_state == SyncState.SYNCING:
-            Logger.warning("Starting a new sync while previous sync was not completed\n{}", str(self._sync_services))
+        self._sync()
 
-        self.syncRequested.emit()
+    @pyqtSlot()
+    def popupClosed(self):
+        self._manual_sync_enabled = True
+        self.manualSyncEnabledChanged.emit(self._manual_sync_enabled)
 
     @pyqtSlot()
     def logout(self) -> None:

+ 9 - 1
resources/qml/Account/AccountWidget.qml

@@ -108,7 +108,15 @@ Item
             }
         }
 
-        onClicked: popup.opened ? popup.close() : popup.open()
+        onClicked: {
+            if (popup.opened)
+            {
+                popup.close()
+                Cura.API.account.popupClosed()
+            } else {
+                popup.open()
+            }
+        }
     }
 
     Popup

+ 2 - 3
resources/qml/Account/SyncState.qml

@@ -63,11 +63,12 @@ Row // sync state icon + message
             color: UM.Theme.getColor("secondary_button_text")
             font: UM.Theme.getFont("medium")
             renderType: Text.NativeRendering
+            visible: Cura.API.account.manualSyncEnabled
 
             MouseArea
             {
                 anchors.fill: parent
-                onClicked: Cura.API.account.sync()
+                onClicked: Cura.API.account.sync(true)
                 hoverEnabled: true
                 onEntered: accountSyncButton.font.underline = true
                 onExited: accountSyncButton.font.underline = false
@@ -93,10 +94,8 @@ Row // sync state icon + message
 
         if(newState == Cura.AccountSyncState.SYNCING){
             updateAnimator.running = true
-            accountSyncButton.visible = false
         } else {
             updateAnimator.running = false
-            accountSyncButton.visible = true
         }
     }