Make remove manual device (also) work (as failure-state of add manual device). [CURA-6294]

This commit is contained in:
Remco Burema 2019-03-21 18:45:57 +01:00
parent f13ceb2a4d
commit 8250c91fc4
2 changed files with 39 additions and 15 deletions

View file

@ -258,22 +258,26 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
def _onNetworkRequestFinished(self, reply): def _onNetworkRequestFinished(self, reply):
reply_url = reply.url().toString() reply_url = reply.url().toString()
address = "" address = reply.url().host()
device = None device = None
properties = {} # type: Dict[bytes, bytes] properties = {} # type: Dict[bytes, bytes]
if "system" in reply_url: if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200:
if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200: # Either:
# Something went wrong with checking the firmware version! # - Something went wrong with checking the firmware version!
return # - 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: try:
system_info = json.loads(bytes(reply.readAll()).decode("utf-8")) system_info = json.loads(bytes(reply.readAll()).decode("utf-8"))
except: except:
Logger.log("e", "Something went wrong converting the JSON.") Logger.log("e", "Something went wrong converting the JSON.")
return return
address = reply.url().host()
has_cluster_capable_firmware = Version(system_info["firmware"]) > self._min_cluster_version has_cluster_capable_firmware = Version(system_info["firmware"]) > self._min_cluster_version
instance_name = "manual:%s" % address instance_name = "manual:%s" % address
properties = { properties = {
@ -301,16 +305,12 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
self._network_manager.get(cluster_request) self._network_manager.get(cluster_request)
elif "printers" in reply_url: 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. # So we confirmed that the device is in fact a cluster printer, and we should now know how big it is.
try: try:
cluster_printers_list = json.loads(bytes(reply.readAll()).decode("utf-8")) cluster_printers_list = json.loads(bytes(reply.readAll()).decode("utf-8"))
except: except:
Logger.log("e", "Something went wrong converting the JSON.") Logger.log("e", "Something went wrong converting the JSON.")
return return
address = reply.url().host()
instance_name = "manual:%s" % address instance_name = "manual:%s" % address
if instance_name in self._discovered_devices: if instance_name in self._discovered_devices:
device = self._discovered_devices[instance_name] device = self._discovered_devices[instance_name]

View file

@ -113,6 +113,12 @@ Item
! addPrinterByIpScreen.haveConnection ! addPrinterByIpScreen.haveConnection
} }
} }
Connections
{
target: UM.OutputDeviceManager
onManualDeviceChanged: { addPrinterButton.enabled = ! UM.OutputDeviceManager.hasManualDevice }
}
} }
} }
@ -172,9 +178,18 @@ Item
target: UM.OutputDeviceManager target: UM.OutputDeviceManager
onManualDeviceChanged: onManualDeviceChanged:
{ {
typeText.text = UM.OutputDeviceManager.manualDeviceProperty("printer_type") if (UM.OutputDeviceManager.hasManualDevice)
firmwareText.text = UM.OutputDeviceManager.manualDeviceProperty("firmware_version") {
addressText.text = UM.OutputDeviceManager.manualDeviceProperty("address") 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 target: UM.OutputDeviceManager
onManualDeviceChanged: onManualDeviceChanged:
{ {
printerNameLabel.text = UM.OutputDeviceManager.manualDeviceProperty("name") if (UM.OutputDeviceManager.hasManualDevice)
addPrinterByIpScreen.haveConnection = true {
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
}
} }
} }
} }