From 7c72e842150dc99c534b95731ecb6b67fd96ae09 Mon Sep 17 00:00:00 2001 From: Konstantinos Karmas Date: Tue, 22 Jun 2021 15:16:13 +0200 Subject: [PATCH 1/6] Read preferences from new restored configs Before calling the illuminate, we need to make sure that the previous cached Preferences have been overridden by the newly restored preferences from the backup. Otherwise, the `illuminate()` function will bring back the cached preferences and the new ones from the backup will be lost. CURA-8313 --- cura/Backups/Backup.py | 3 +++ plugins/CuraDrive/src/DriveApiService.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cura/Backups/Backup.py b/cura/Backups/Backup.py index 5fad2ccf19..74ef43f5b2 100644 --- a/cura/Backups/Backup.py +++ b/cura/Backups/Backup.py @@ -166,6 +166,9 @@ class Backup: Logger.log("d", "Moving preferences file from %s to %s", backup_preferences_file, preferences_file) shutil.move(backup_preferences_file, preferences_file) + # Read the preferences from the newly restored configuration (or else the cached Preferences will override the restored ones) + self._application.readPreferencesFromConfiguration() + # Restore the obfuscated settings self._illuminate(**secrets) diff --git a/plugins/CuraDrive/src/DriveApiService.py b/plugins/CuraDrive/src/DriveApiService.py index 754069dc9b..6dd6f02b97 100644 --- a/plugins/CuraDrive/src/DriveApiService.py +++ b/plugins/CuraDrive/src/DriveApiService.py @@ -93,7 +93,7 @@ class DriveApiService: def _onRestoreFinished(self, job: "RestoreBackupJob") -> None: if job.restore_backup_error_message != "": # If the job contains an error message we pass it along so the UI can display it. - self.restoringStateChanged.emit(is_restoring=False) + self.restoringStateChanged.emit(is_restoring = False) else: self.restoringStateChanged.emit(is_restoring = False, error_message = job.restore_backup_error_message) From 32eac869994ec1e84a81c6247b59c982f6619152 Mon Sep 17 00:00:00 2001 From: Konstantinos Karmas Date: Tue, 22 Jun 2021 16:24:43 +0200 Subject: [PATCH 2/6] Hide the backup window when the application is shutting down CURA-8313 --- plugins/CuraDrive/src/qml/components/BackupListItem.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/CuraDrive/src/qml/components/BackupListItem.qml b/plugins/CuraDrive/src/qml/components/BackupListItem.qml index 5cdb500b4e..7b539b03b9 100644 --- a/plugins/CuraDrive/src/qml/components/BackupListItem.qml +++ b/plugins/CuraDrive/src/qml/components/BackupListItem.qml @@ -71,6 +71,7 @@ Item text: catalog.i18nc("@button", "Restore") enabled: !CuraDrive.isCreatingBackup && !CuraDrive.isRestoringBackup onClicked: confirmRestoreDialog.visible = true + busy: CuraDrive.backupIdBeingRestored == modelData.backup_id && CuraDrive.isRestoringBackup } UM.SimpleButton From b1ee6d3d22e68ff79d4d3e10357043632b50391e Mon Sep 17 00:00:00 2001 From: Konstantinos Karmas Date: Tue, 22 Jun 2021 16:29:52 +0200 Subject: [PATCH 3/6] Revert "Hide the backup window when the application is shutting down" This reverts commit 32eac869994ec1e84a81c6247b59c982f6619152. --- plugins/CuraDrive/src/qml/components/BackupListItem.qml | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/CuraDrive/src/qml/components/BackupListItem.qml b/plugins/CuraDrive/src/qml/components/BackupListItem.qml index 7b539b03b9..5cdb500b4e 100644 --- a/plugins/CuraDrive/src/qml/components/BackupListItem.qml +++ b/plugins/CuraDrive/src/qml/components/BackupListItem.qml @@ -71,7 +71,6 @@ Item text: catalog.i18nc("@button", "Restore") enabled: !CuraDrive.isCreatingBackup && !CuraDrive.isRestoringBackup onClicked: confirmRestoreDialog.visible = true - busy: CuraDrive.backupIdBeingRestored == modelData.backup_id && CuraDrive.isRestoringBackup } UM.SimpleButton From 51de50cd057936a3a6001d53d6edbad2dae48d5a Mon Sep 17 00:00:00 2001 From: Konstantinos Karmas Date: Tue, 22 Jun 2021 16:31:37 +0200 Subject: [PATCH 4/6] Hide the backup window when the application is shutting down CURA-8313 --- plugins/CuraDrive/src/DrivePluginExtension.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/CuraDrive/src/DrivePluginExtension.py b/plugins/CuraDrive/src/DrivePluginExtension.py index 8de4876f52..587856ae41 100644 --- a/plugins/CuraDrive/src/DrivePluginExtension.py +++ b/plugins/CuraDrive/src/DrivePluginExtension.py @@ -52,6 +52,7 @@ class DrivePluginExtension(QObject, Extension): # Attach signals. CuraApplication.getInstance().getCuraAPI().account.loginStateChanged.connect(self._onLoginStateChanged) + CuraApplication.getInstance().applicationShuttingDown.connect(self._onApplicationShuttingDown) self._drive_api_service.restoringStateChanged.connect(self._onRestoringStateChanged) self._drive_api_service.creatingStateChanged.connect(self._onCreatingStateChanged) @@ -75,6 +76,9 @@ class DrivePluginExtension(QObject, Extension): if self._drive_window: self._drive_window.show() + def _onApplicationShuttingDown(self): + self._drive_window.hide() + def _autoBackup(self) -> None: preferences = CuraApplication.getInstance().getPreferences() if preferences.getValue(Settings.AUTO_BACKUP_ENABLED_PREFERENCE_KEY) and self._isLastBackupTooLongAgo(): From 4f5e055cd8f62b2b3b8c88c1c1316e74dd2fcc38 Mon Sep 17 00:00:00 2001 From: Konstantinos Karmas Date: Tue, 22 Jun 2021 16:33:32 +0200 Subject: [PATCH 5/6] Show the backup item as busy while it is being restored Previously, after pressing the "Restore" button of a backup, there was no indication about it being restored. This commit changes that by making the "Restore" button of that backup display the busy rotating wheel. CURA-8313 --- plugins/CuraDrive/src/DrivePluginExtension.py | 17 ++++++++++++++++- .../src/qml/components/BackupListItem.qml | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/CuraDrive/src/DrivePluginExtension.py b/plugins/CuraDrive/src/DrivePluginExtension.py index 587856ae41..6fd55d172e 100644 --- a/plugins/CuraDrive/src/DrivePluginExtension.py +++ b/plugins/CuraDrive/src/DrivePluginExtension.py @@ -34,6 +34,9 @@ class DrivePluginExtension(QObject, Extension): # Signal emitted when preferences changed (like auto-backup). preferencesChanged = pyqtSignal() + # Signal emitted when the id of the backup-to-be-restored is changed + backupIdBeingRestoredChanged = pyqtSignal(arguments = ["backup_id_being_restored"]) + DATE_FORMAT = "%d/%m/%Y %H:%M:%S" def __init__(self) -> None: @@ -45,6 +48,7 @@ class DrivePluginExtension(QObject, Extension): self._backups = [] # type: List[Dict[str, Any]] self._is_restoring_backup = False self._is_creating_backup = False + self._backup_id_being_restored = "" # Initialize services. preferences = CuraApplication.getInstance().getPreferences() @@ -104,10 +108,11 @@ class DrivePluginExtension(QObject, Extension): if logged_in: self.refreshBackups() - def _onRestoringStateChanged(self, is_restoring: bool = False, error_message: str = None) -> None: + def _onRestoringStateChanged(self, is_restoring: bool = False, error_message: Optional[str] = None) -> None: self._is_restoring_backup = is_restoring self.restoringStateChanged.emit() if error_message: + self.backupIdBeingRestored = "" Message(error_message, title = catalog.i18nc("@info:title", "Backup")).show() def _onCreatingStateChanged(self, is_creating: bool = False, error_message: str = None) -> None: @@ -156,6 +161,7 @@ class DrivePluginExtension(QObject, Extension): for backup in self._backups: if backup.get("backup_id") == backup_id: self._drive_api_service.restoreBackup(backup) + self.setBackupIdBeingRestored(backup_id) return Logger.log("w", "Unable to find backup with the ID %s", backup_id) @@ -170,3 +176,12 @@ class DrivePluginExtension(QObject, Extension): def _backupDeletedCallback(self, success: bool): if success: self.refreshBackups() + + def setBackupIdBeingRestored(self, backup_id_being_restored: str) -> None: + if backup_id_being_restored != self._backup_id_being_restored: + self._backup_id_being_restored = backup_id_being_restored + self.backupIdBeingRestoredChanged.emit() + + @pyqtProperty(str, fset = setBackupIdBeingRestored, notify = backupIdBeingRestoredChanged) + def backupIdBeingRestored(self) -> str: + return self._backup_id_being_restored diff --git a/plugins/CuraDrive/src/qml/components/BackupListItem.qml b/plugins/CuraDrive/src/qml/components/BackupListItem.qml index 5cdb500b4e..7b539b03b9 100644 --- a/plugins/CuraDrive/src/qml/components/BackupListItem.qml +++ b/plugins/CuraDrive/src/qml/components/BackupListItem.qml @@ -71,6 +71,7 @@ Item text: catalog.i18nc("@button", "Restore") enabled: !CuraDrive.isCreatingBackup && !CuraDrive.isRestoringBackup onClicked: confirmRestoreDialog.visible = true + busy: CuraDrive.backupIdBeingRestored == modelData.backup_id && CuraDrive.isRestoringBackup } UM.SimpleButton From bcd44b8b6fa9151625257d1af3e6b1e6af879712 Mon Sep 17 00:00:00 2001 From: Konstantinos Karmas Date: Tue, 22 Jun 2021 17:01:36 +0200 Subject: [PATCH 6/6] Process events while extracting the downloaded backup To prevent the UI from being frozen. This way, the user knows that something is happening in the background and Cura didn't just stop working. CURA-8313 --- cura/Backups/Backup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cura/Backups/Backup.py b/cura/Backups/Backup.py index 74ef43f5b2..6128dac320 100644 --- a/cura/Backups/Backup.py +++ b/cura/Backups/Backup.py @@ -194,7 +194,10 @@ class Backup: Resources.factoryReset() Logger.log("d", "Extracting backup to location: %s", target_path) try: - archive.extractall(target_path) + name_list = archive.namelist() + for archive_filename in name_list: + archive.extract(archive_filename, target_path) + CuraApplication.getInstance().processEvents() except (PermissionError, EnvironmentError): Logger.logException("e", "Unable to extract the backup due to permission or file system errors.") return False