diff options
-rw-r--r-- | cura/Machines/Models/MaterialManagementModel.py | 9 | ||||
-rw-r--r-- | cura/PrinterOutput/UploadMaterialsJob.py | 25 | ||||
-rw-r--r-- | resources/qml/Preferences/Materials/MaterialsSyncDialog.qml | 1 |
3 files changed, 35 insertions, 0 deletions
diff --git a/cura/Machines/Models/MaterialManagementModel.py b/cura/Machines/Models/MaterialManagementModel.py index d5191988fa..617fc5be9e 100644 --- a/cura/Machines/Models/MaterialManagementModel.py +++ b/cura/Machines/Models/MaterialManagementModel.py @@ -16,6 +16,7 @@ from UM.Signal import postponeSignals, CompressTechnique import cura.CuraApplication # Imported like this to prevent circular imports. from cura.Machines.ContainerTree import ContainerTree +from cura.PrinterOutput.UploadMaterialsJob import UploadMaterialsJob # To export materials to the output printer. from cura.Settings.CuraContainerRegistry import CuraContainerRegistry # To find the sets of materials belonging to each other, and currently loaded extruder stacks. if TYPE_CHECKING: @@ -385,3 +386,11 @@ class MaterialManagementModel(QObject): archive.writestr(filename, material.serialize()) except OSError as e: Logger.log("e", f"An error has occurred while writing the material \'{metadata['id']}\' in the file \'{filename}\': {e}.") + + @pyqtSlot() + def exportUpload(self) -> None: + """ + Export all materials and upload them to the user's account. + """ + job = UploadMaterialsJob() + job.start() diff --git a/cura/PrinterOutput/UploadMaterialsJob.py b/cura/PrinterOutput/UploadMaterialsJob.py new file mode 100644 index 0000000000..42254d2475 --- /dev/null +++ b/cura/PrinterOutput/UploadMaterialsJob.py @@ -0,0 +1,25 @@ +# Copyright (c) 2021 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + +from PyQt5.QtCore import QUrl +import os # To delete the archive when we're done. +import tempfile # To create an archive before we upload it. + +import cura.CuraApplication # Imported like this to prevent circular imports. +from UM.Job import Job + + +class UploadMaterialsJob(Job): + """ + Job that uploads a set of materials to the Digital Factory. + """ + + def run(self): + archive_file = tempfile.NamedTemporaryFile("wb", delete = False) + archive_file.close() + + cura.CuraApplication.CuraApplication.getInstance().getMaterialManagementModel().exportAll(QUrl.fromLocalFile(archive_file.name)) + + print("Creating archive completed. Now we need to upload it.") # TODO: Upload that file. + + os.remove(archive_file.name) # Clean up.
\ No newline at end of file diff --git a/resources/qml/Preferences/Materials/MaterialsSyncDialog.qml b/resources/qml/Preferences/Materials/MaterialsSyncDialog.qml index 00e19ded9f..0bcafba8d2 100644 --- a/resources/qml/Preferences/Materials/MaterialsSyncDialog.qml +++ b/resources/qml/Preferences/Materials/MaterialsSyncDialog.qml @@ -354,6 +354,7 @@ Window { anchors.right: parent.right text: catalog.i18nc("@button", "Sync") + onClicked: materialManagementModel.exportUpload() } } } |