diff --git a/cura/API/Account.py b/cura/API/Account.py index 872fe815da..3463fe6951 100644 --- a/cura/API/Account.py +++ b/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 + @pyqtProperty(bool, notify=manualSyncEnabledChanged) + def manualSyncEnabled(self) -> bool: + return self._manual_sync_enabled + @pyqtSlot() - def sync(self) -> None: - """Signals all sync services to start syncing + @pyqtSlot(bool) + def sync(self, user_initiated=False): + if user_initiated: + self._manual_sync_enabled = False + self.manualSyncEnabledChanged.emit(self._manual_sync_enabled) - This can be considered a forced sync: even when a - sync is currently running, a sync will be requested. - """ + self._sync() - 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 popupClosed(self): + self._manual_sync_enabled = True + self.manualSyncEnabledChanged.emit(self._manual_sync_enabled) @pyqtSlot() def logout(self) -> None: diff --git a/resources/qml/Account/AccountWidget.qml b/resources/qml/Account/AccountWidget.qml index 26b491ce15..00ac954f22 100644 --- a/resources/qml/Account/AccountWidget.qml +++ b/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 diff --git a/resources/qml/Account/SyncState.qml b/resources/qml/Account/SyncState.qml index 3f96ddad1f..b419f150f9 100644 --- a/resources/qml/Account/SyncState.qml +++ b/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 } }