Move RemovedprintersMessage to it's own class

The OutputDeviceManager is just too bloated to properly make sense of.
So I'm trying to move as much code out of it so I can start to make sense of it

CURA-8463
This commit is contained in:
Jaime van Kessel 2022-08-30 11:45:30 +02:00
parent 45e7d15c80
commit ce3ab62c91
No known key found for this signature in database
GPG key ID: C85F7A3AF1BAA7C4
2 changed files with 60 additions and 40 deletions

View file

@ -22,6 +22,7 @@ from cura.Settings.GlobalStack import GlobalStack
from cura.UltimakerCloud.UltimakerCloudConstants import META_CAPABILITIES, META_UM_LINKED_TO_ACCOUNT from cura.UltimakerCloud.UltimakerCloudConstants import META_CAPABILITIES, META_UM_LINKED_TO_ACCOUNT
from .CloudApiClient import CloudApiClient from .CloudApiClient import CloudApiClient
from .CloudOutputDevice import CloudOutputDevice from .CloudOutputDevice import CloudOutputDevice
from ..Messages.RemovedPrintersMessage import RemovedPrintersMessage
from ..Models.Http.CloudClusterResponse import CloudClusterResponse from ..Models.Http.CloudClusterResponse import CloudClusterResponse
from ..Messages.NewPrinterDetectedMessage import NewPrinterDetectedMessage from ..Messages.NewPrinterDetectedMessage import NewPrinterDetectedMessage
@ -303,52 +304,13 @@ class CloudOutputDeviceManager:
for device_id in removed_device_ids: for device_id in removed_device_ids:
if not parseBool(self._um_cloud_printers[device_id].getMetaDataEntry(META_UM_LINKED_TO_ACCOUNT, "true")): if not parseBool(self._um_cloud_printers[device_id].getMetaDataEntry(META_UM_LINKED_TO_ACCOUNT, "true")):
ignored_device_ids.add(device_id) ignored_device_ids.add(device_id)
# Keep the reported_device_ids list in a class variable, so that the message button actions can access it and # Keep the reported_device_ids list in a class variable, so that the message button actions can access it and
# take the necessary steps to fulfill their purpose. # take the necessary steps to fulfill their purpose.
self.reported_device_ids = removed_device_ids - ignored_device_ids self.reported_device_ids = removed_device_ids - ignored_device_ids
if not self.reported_device_ids: if not self.reported_device_ids:
return return
# Generate message
self._removed_printers_message = Message(
title = self.i18n_catalog.i18ncp(
"info:status",
"A cloud connection is not available for a printer",
"A cloud connection is not available for some printers",
len(self.reported_device_ids)
),
message_type = Message.MessageType.WARNING
)
device_names = "".join(["<li>{} ({})</li>".format(self._um_cloud_printers[device].name,
self._um_cloud_printers[device].definition.name) for device in self.reported_device_ids])
message_text = self.i18n_catalog.i18ncp(
"info:status",
"This printer is not linked to the Digital Factory:",
"These printers are not linked to the Digital Factory:",
len(self.reported_device_ids)
)
message_text += "<br/><ul>{}</ul><br/>".format(device_names)
digital_factory_string = self.i18n_catalog.i18nc("info:name", "Ultimaker Digital Factory")
website_link = f"<a href='https://digitalfactory.ultimaker.com?utm_source=cura&" \
f"utm_medium=software&utm_campaign=change-account-connect-printer'>{digital_factory_string}</a>."
message_text += self.i18n_catalog.i18nc(
"info:status",
f"To establish a connection, please visit the {website_link}"
)
self._removed_printers_message.setText(message_text)
self._removed_printers_message.addAction("keep_printer_configurations_action",
name = self.i18n_catalog.i18nc("@action:button", "Keep printer configurations"),
icon = "",
description = "Keep cloud printers in Ultimaker Cura when not connected to your account.",
button_align = Message.ActionButtonAlignment.ALIGN_RIGHT)
self._removed_printers_message.addAction("remove_printers_action",
name = self.i18n_catalog.i18nc("@action:button", "Remove printers"),
icon = "",
description = "Remove cloud printer(s) which aren't linked to your account.",
button_style = Message.ActionButtonStyle.SECONDARY,
button_align = Message.ActionButtonAlignment.ALIGN_LEFT)
self._removed_printers_message.actionTriggered.connect(self._onRemovedPrintersMessageActionTriggered)
output_device_manager = CuraApplication.getInstance().getOutputDeviceManager() output_device_manager = CuraApplication.getInstance().getOutputDeviceManager()
# Remove the output device from the printers # Remove the output device from the printers
@ -364,6 +326,12 @@ class CloudOutputDeviceManager:
# Update the printer's metadata to mark it as not linked to the account # Update the printer's metadata to mark it as not linked to the account
global_stack.setMetaDataEntry(META_UM_LINKED_TO_ACCOUNT, False) global_stack.setMetaDataEntry(META_UM_LINKED_TO_ACCOUNT, False)
# Generate message to show
device_names = "".join(["<li>{} ({})</li>".format(self._um_cloud_printers[device].name,
self._um_cloud_printers[device].definition.name) for device in
self.reported_device_ids])
self._removed_printers_message = RemovedPrintersMessage(self.reported_device_ids, device_names)
self._removed_printers_message.actionTriggered.connect(self._onRemovedPrintersMessageActionTriggered)
self._removed_printers_message.show() self._removed_printers_message.show()
def _onDiscoveredDeviceRemoved(self, device_id: str) -> None: def _onDiscoveredDeviceRemoved(self, device_id: str) -> None:

View file

@ -0,0 +1,52 @@
# Copyright (c) 2022 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from UM import i18nCatalog
from UM.Message import Message
from cura.CuraApplication import CuraApplication
class RemovedPrintersMessage(Message):
i18n_catalog = i18nCatalog("cura")
def __init__(self, removed_devices, device_names) -> None:
self._removed_devices = removed_devices
message_text = self.i18n_catalog.i18ncp(
"info:status",
"This printer is not linked to the Digital Factory:",
"These printers are not linked to the Digital Factory:",
len(self.removed_devices)
)
message_text += "<br/><ul>{}</ul><br/>".format(device_names)
digital_factory_string = self.i18n_catalog.i18nc("info:name", "Ultimaker Digital Factory")
website_link = f"<a href='https://digitalfactory.ultimaker.com?utm_source=cura&" \
f"utm_medium=software&utm_campaign=change-account-connect-printer'>{digital_factory_string}</a>."
message_text += self.i18n_catalog.i18nc(
"info:status",
f"To establish a connection, please visit the {website_link}"
)
super().__init__(title=self.i18n_catalog.i18ncp("info:status",
"A cloud connection is not available for a printer",
"A cloud connection is not available for some printers",
len(self.removed_devices)),
message_type=Message.MessageType.WARNING,
text = message_text)
self.addAction("keep_printer_configurations_action",
name=self.i18n_catalog.i18nc("@action:button",
"Keep printer configurations"),
icon="",
description="Keep cloud printers in Ultimaker Cura when not connected to your account.",
button_align=Message.ActionButtonAlignment.ALIGN_RIGHT)
self.addAction("remove_printers_action",
name=self.i18n_catalog.i18nc("@action:button", "Remove printers"),
icon="",
description="Remove cloud printer(s) which aren't linked to your account.",
button_style=Message.ActionButtonStyle.SECONDARY,
button_align=Message.ActionButtonAlignment.ALIGN_LEFT)