Updated message with message types

Contributes to CURA-8418
This commit is contained in:
Jelle Spijker 2021-07-28 08:45:42 +02:00
parent 900db57f0f
commit 2263969d5f
No known key found for this signature in database
GPG key ID: 6662DC033BE6B99A
26 changed files with 136 additions and 82 deletions

View file

@ -111,15 +111,15 @@ class Backup:
return archive
except (IOError, OSError, BadZipfile) as error:
Logger.log("e", "Could not create archive from user data directory: %s", error)
self._showMessage(
self.catalog.i18nc("@info:backup_failed",
"Could not create archive from user data directory: {}".format(error)))
self._showMessage(self.catalog.i18nc("@info:backup_failed",
"Could not create archive from user data directory: {}".format(error)),
message_type = Message.MessageType.ERROR)
return None
def _showMessage(self, message: str) -> None:
def _showMessage(self, message: str, message_type: Message.MessageType = Message.MessageType.NEUTRAL) -> None:
"""Show a UI message."""
Message(message, title=self.catalog.i18nc("@info:title", "Backup")).show()
Message(message, title=self.catalog.i18nc("@info:title", "Backup"), message_type = message_type).show()
def restore(self) -> bool:
"""Restore this back-up.
@ -130,9 +130,9 @@ class Backup:
if not self.zip_file or not self.meta_data or not self.meta_data.get("cura_release", None):
# We can restore without the minimum required information.
Logger.log("w", "Tried to restore a Cura backup without having proper data or meta data.")
self._showMessage(
self.catalog.i18nc("@info:backup_failed",
"Tried to restore a Cura backup without having proper data or meta data."))
self._showMessage(self.catalog.i18nc("@info:backup_failed",
"Tried to restore a Cura backup without having proper data or meta data."),
message_type = Message.MessageType.ERROR)
return False
current_version = Version(self._application.getVersion())
@ -141,9 +141,9 @@ class Backup:
if current_version < version_to_restore:
# Cannot restore version newer than current because settings might have changed.
Logger.log("d", "Tried to restore a Cura backup of version {version_to_restore} with cura version {current_version}".format(version_to_restore = version_to_restore, current_version = current_version))
self._showMessage(
self.catalog.i18nc("@info:backup_failed",
"Tried to restore a Cura backup that is higher than the current version."))
self._showMessage(self.catalog.i18nc("@info:backup_failed",
"Tried to restore a Cura backup that is higher than the current version."),
message_type = Message.MessageType.ERROR)
return False
# Get the current secrets and store since the back-up doesn't contain those
@ -154,7 +154,8 @@ class Backup:
archive = ZipFile(io.BytesIO(self.zip_file), "r")
except LookupError as e:
Logger.log("d", f"The following error occurred while trying to restore a Cura backup: {str(e)}")
Message(self.catalog.i18nc("@info:backup_failed", "The following error occurred while trying to restore a Cura backup:") + str(e),
Message(self.catalog.i18nc("@info:backup_failed",
"The following error occurred while trying to restore a Cura backup:") + str(e),
title = self.catalog.i18nc("@info:title", "Backup"),
message_type = Message.MessageType.ERROR).show()