Move code and status related to uploading materials to separate class

There's quite a lot of status to track, errors and progress. It's better kept separate.

Contributes to issue CURA-8609.
This commit is contained in:
Ghostkeeper 2021-10-12 09:43:21 +02:00
parent c3d392c5cf
commit 4661b02e4c
No known key found for this signature in database
GPG key ID: 68F39EA88EEED5FF
4 changed files with 176 additions and 152 deletions

View file

@ -18,6 +18,7 @@ from UM.TaskManagement.HttpRequestScope import JsonDecoratorScope
from typing import Optional, TYPE_CHECKING
if TYPE_CHECKING:
from PyQt5.QtNetwork import QNetworkReply
from cura.UltimakerCloud.CloudMaterialSync import CloudMaterialSync
class UploadMaterialsJob(Job):
"""
@ -30,8 +31,9 @@ class UploadMaterialsJob(Job):
SUCCCESS = 0
FAILED = 1
def __init__(self):
def __init__(self, material_sync: "CloudMaterialSync"):
super().__init__()
self._material_sync = material_sync
self._scope = JsonDecoratorScope(UltimakerCloudScope(cura.CuraApplication.CuraApplication.getInstance())) # type: JsonDecoratorScope
uploadCompleted = Signal()
@ -40,7 +42,7 @@ class UploadMaterialsJob(Job):
archive_file = tempfile.NamedTemporaryFile("wb", delete = False)
archive_file.close()
cura.CuraApplication.CuraApplication.getInstance().getMaterialManagementModel().exportAll(QUrl.fromLocalFile(archive_file.name))
self._material_sync.exportAll(QUrl.fromLocalFile(archive_file.name))
http = HttpRequestManager.getInstance()
http.get(