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):
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!
# 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]

View file

@ -113,6 +113,12 @@ Item
! addPrinterByIpScreen.haveConnection
}
}
Connections
{
target: UM.OutputDeviceManager
onManualDeviceChanged: { addPrinterButton.enabled = ! UM.OutputDeviceManager.hasManualDevice }
}
}
}
@ -171,11 +177,20 @@ Item
{
target: UM.OutputDeviceManager
onManualDeviceChanged:
{
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 = ""
}
}
}
}
@ -183,10 +198,19 @@ Item
{
target: UM.OutputDeviceManager
onManualDeviceChanged:
{
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
}
}
}
}
}