mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 18:45:55 +08:00
Merge branch 'CURA-8313_Restore_backup_messes_configurations' of github.com:Ultimaker/Cura into 4.10
This commit is contained in:
commit
c7ce0f2236
@ -166,6 +166,9 @@ class Backup:
|
|||||||
Logger.log("d", "Moving preferences file from %s to %s", backup_preferences_file, preferences_file)
|
Logger.log("d", "Moving preferences file from %s to %s", backup_preferences_file, preferences_file)
|
||||||
shutil.move(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
|
# Restore the obfuscated settings
|
||||||
self._illuminate(**secrets)
|
self._illuminate(**secrets)
|
||||||
|
|
||||||
@ -191,7 +194,10 @@ class Backup:
|
|||||||
Resources.factoryReset()
|
Resources.factoryReset()
|
||||||
Logger.log("d", "Extracting backup to location: %s", target_path)
|
Logger.log("d", "Extracting backup to location: %s", target_path)
|
||||||
try:
|
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):
|
except (PermissionError, EnvironmentError):
|
||||||
Logger.logException("e", "Unable to extract the backup due to permission or file system errors.")
|
Logger.logException("e", "Unable to extract the backup due to permission or file system errors.")
|
||||||
return False
|
return False
|
||||||
|
@ -93,7 +93,7 @@ class DriveApiService:
|
|||||||
def _onRestoreFinished(self, job: "RestoreBackupJob") -> None:
|
def _onRestoreFinished(self, job: "RestoreBackupJob") -> None:
|
||||||
if job.restore_backup_error_message != "":
|
if job.restore_backup_error_message != "":
|
||||||
# If the job contains an error message we pass it along so the UI can display it.
|
# 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:
|
else:
|
||||||
self.restoringStateChanged.emit(is_restoring = False, error_message = job.restore_backup_error_message)
|
self.restoringStateChanged.emit(is_restoring = False, error_message = job.restore_backup_error_message)
|
||||||
|
|
||||||
|
@ -34,6 +34,9 @@ class DrivePluginExtension(QObject, Extension):
|
|||||||
# Signal emitted when preferences changed (like auto-backup).
|
# Signal emitted when preferences changed (like auto-backup).
|
||||||
preferencesChanged = pyqtSignal()
|
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"
|
DATE_FORMAT = "%d/%m/%Y %H:%M:%S"
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
@ -45,6 +48,7 @@ class DrivePluginExtension(QObject, Extension):
|
|||||||
self._backups = [] # type: List[Dict[str, Any]]
|
self._backups = [] # type: List[Dict[str, Any]]
|
||||||
self._is_restoring_backup = False
|
self._is_restoring_backup = False
|
||||||
self._is_creating_backup = False
|
self._is_creating_backup = False
|
||||||
|
self._backup_id_being_restored = ""
|
||||||
|
|
||||||
# Initialize services.
|
# Initialize services.
|
||||||
preferences = CuraApplication.getInstance().getPreferences()
|
preferences = CuraApplication.getInstance().getPreferences()
|
||||||
@ -52,6 +56,7 @@ class DrivePluginExtension(QObject, Extension):
|
|||||||
|
|
||||||
# Attach signals.
|
# Attach signals.
|
||||||
CuraApplication.getInstance().getCuraAPI().account.loginStateChanged.connect(self._onLoginStateChanged)
|
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.restoringStateChanged.connect(self._onRestoringStateChanged)
|
||||||
self._drive_api_service.creatingStateChanged.connect(self._onCreatingStateChanged)
|
self._drive_api_service.creatingStateChanged.connect(self._onCreatingStateChanged)
|
||||||
|
|
||||||
@ -75,6 +80,9 @@ class DrivePluginExtension(QObject, Extension):
|
|||||||
if self._drive_window:
|
if self._drive_window:
|
||||||
self._drive_window.show()
|
self._drive_window.show()
|
||||||
|
|
||||||
|
def _onApplicationShuttingDown(self):
|
||||||
|
self._drive_window.hide()
|
||||||
|
|
||||||
def _autoBackup(self) -> None:
|
def _autoBackup(self) -> None:
|
||||||
preferences = CuraApplication.getInstance().getPreferences()
|
preferences = CuraApplication.getInstance().getPreferences()
|
||||||
if preferences.getValue(Settings.AUTO_BACKUP_ENABLED_PREFERENCE_KEY) and self._isLastBackupTooLongAgo():
|
if preferences.getValue(Settings.AUTO_BACKUP_ENABLED_PREFERENCE_KEY) and self._isLastBackupTooLongAgo():
|
||||||
@ -100,10 +108,11 @@ class DrivePluginExtension(QObject, Extension):
|
|||||||
if logged_in:
|
if logged_in:
|
||||||
self.refreshBackups()
|
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._is_restoring_backup = is_restoring
|
||||||
self.restoringStateChanged.emit()
|
self.restoringStateChanged.emit()
|
||||||
if error_message:
|
if error_message:
|
||||||
|
self.backupIdBeingRestored = ""
|
||||||
Message(error_message, title = catalog.i18nc("@info:title", "Backup")).show()
|
Message(error_message, title = catalog.i18nc("@info:title", "Backup")).show()
|
||||||
|
|
||||||
def _onCreatingStateChanged(self, is_creating: bool = False, error_message: str = None) -> None:
|
def _onCreatingStateChanged(self, is_creating: bool = False, error_message: str = None) -> None:
|
||||||
@ -152,6 +161,7 @@ class DrivePluginExtension(QObject, Extension):
|
|||||||
for backup in self._backups:
|
for backup in self._backups:
|
||||||
if backup.get("backup_id") == backup_id:
|
if backup.get("backup_id") == backup_id:
|
||||||
self._drive_api_service.restoreBackup(backup)
|
self._drive_api_service.restoreBackup(backup)
|
||||||
|
self.setBackupIdBeingRestored(backup_id)
|
||||||
return
|
return
|
||||||
Logger.log("w", "Unable to find backup with the ID %s", backup_id)
|
Logger.log("w", "Unable to find backup with the ID %s", backup_id)
|
||||||
|
|
||||||
@ -166,3 +176,12 @@ class DrivePluginExtension(QObject, Extension):
|
|||||||
def _backupDeletedCallback(self, success: bool):
|
def _backupDeletedCallback(self, success: bool):
|
||||||
if success:
|
if success:
|
||||||
self.refreshBackups()
|
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
|
||||||
|
@ -71,6 +71,7 @@ Item
|
|||||||
text: catalog.i18nc("@button", "Restore")
|
text: catalog.i18nc("@button", "Restore")
|
||||||
enabled: !CuraDrive.isCreatingBackup && !CuraDrive.isRestoringBackup
|
enabled: !CuraDrive.isCreatingBackup && !CuraDrive.isRestoringBackup
|
||||||
onClicked: confirmRestoreDialog.visible = true
|
onClicked: confirmRestoreDialog.visible = true
|
||||||
|
busy: CuraDrive.backupIdBeingRestored == modelData.backup_id && CuraDrive.isRestoringBackup
|
||||||
}
|
}
|
||||||
|
|
||||||
UM.SimpleButton
|
UM.SimpleButton
|
||||||
|
Loading…
x
Reference in New Issue
Block a user