From 8250c91fc428ec5421e7f924b165ac4fac3744c7 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 21 Mar 2019 18:45:57 +0100 Subject: [PATCH] Make remove manual device (also) work (as failure-state of add manual device). [CURA-6294] --- .../src/UM3OutputDevicePlugin.py | 20 +++++------ .../WelcomePages/AddPrinterByIpContent.qml | 34 ++++++++++++++++--- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py b/plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py index 9bcbf38b77..9f1684f624 100644 --- a/plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py +++ b/plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py @@ -258,22 +258,26 @@ class UM3OutputDevicePlugin(OutputDevicePlugin): def _onNetworkRequestFinished(self, reply): reply_url = reply.url().toString() - address = "" + address = reply.url().host() device = None properties = {} # type: Dict[bytes, bytes] - if "system" in reply_url: - if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200: - # Something went wrong with checking the firmware version! - return + if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200: + # Either: + # - Something went wrong with checking the firmware version! + # - Something went wrong with checking the amount of printers the cluster has! + # - Couldn't find printer at the address when trying to add it manually. + if address in self._manual_instances: + self.removeManualDeviceSignal.emit(self.getPluginId(), "", address) + return + if "system" in reply_url: try: system_info = json.loads(bytes(reply.readAll()).decode("utf-8")) except: Logger.log("e", "Something went wrong converting the JSON.") return - address = reply.url().host() has_cluster_capable_firmware = Version(system_info["firmware"]) > self._min_cluster_version instance_name = "manual:%s" % address properties = { @@ -301,16 +305,12 @@ class UM3OutputDevicePlugin(OutputDevicePlugin): self._network_manager.get(cluster_request) elif "printers" in reply_url: - if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200: - # Something went wrong with checking the amount of printers the cluster has! - return # So we confirmed that the device is in fact a cluster printer, and we should now know how big it is. try: cluster_printers_list = json.loads(bytes(reply.readAll()).decode("utf-8")) except: Logger.log("e", "Something went wrong converting the JSON.") return - address = reply.url().host() instance_name = "manual:%s" % address if instance_name in self._discovered_devices: device = self._discovered_devices[instance_name] diff --git a/resources/qml/WelcomePages/AddPrinterByIpContent.qml b/resources/qml/WelcomePages/AddPrinterByIpContent.qml index f3ed58200b..c67e93c9a7 100644 --- a/resources/qml/WelcomePages/AddPrinterByIpContent.qml +++ b/resources/qml/WelcomePages/AddPrinterByIpContent.qml @@ -113,6 +113,12 @@ Item ! addPrinterByIpScreen.haveConnection } } + + Connections + { + target: UM.OutputDeviceManager + onManualDeviceChanged: { addPrinterButton.enabled = ! UM.OutputDeviceManager.hasManualDevice } + } } } @@ -172,9 +178,18 @@ Item target: UM.OutputDeviceManager onManualDeviceChanged: { - typeText.text = UM.OutputDeviceManager.manualDeviceProperty("printer_type") - firmwareText.text = UM.OutputDeviceManager.manualDeviceProperty("firmware_version") - addressText.text = UM.OutputDeviceManager.manualDeviceProperty("address") + if (UM.OutputDeviceManager.hasManualDevice) + { + typeText.text = UM.OutputDeviceManager.manualDeviceProperty("printer_type") + firmwareText.text = UM.OutputDeviceManager.manualDeviceProperty("firmware_version") + addressText.text = UM.OutputDeviceManager.manualDeviceProperty("address") + } + else + { + typeText.text = "" + firmwareText.text = "" + addressText.text = "" + } } } } @@ -184,8 +199,17 @@ Item target: UM.OutputDeviceManager onManualDeviceChanged: { - printerNameLabel.text = UM.OutputDeviceManager.manualDeviceProperty("name") - addPrinterByIpScreen.haveConnection = true + if (UM.OutputDeviceManager.hasManualDevice) + { + printerNameLabel.text = UM.OutputDeviceManager.manualDeviceProperty("name") + addPrinterByIpScreen.haveConnection = true + } + else + { + printerNameLabel.text = catalog.i18nc("@label", "Could not connect to device.") + addPrinterByIpScreen.hasSentRequest = false + addPrinterByIpScreen.haveConnection = false + } } } }