From eba49ee8c287c6b63fbe82859fbf83aacbf5afda Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Wed, 28 Sep 2016 23:08:23 +0200 Subject: [PATCH] Always show manual printer instances, even before they are validated CURA-2483 --- NetworkPrinterOutputDevicePlugin.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/NetworkPrinterOutputDevicePlugin.py b/NetworkPrinterOutputDevicePlugin.py index caf20c5629..f1d5acefef 100644 --- a/NetworkPrinterOutputDevicePlugin.py +++ b/NetworkPrinterOutputDevicePlugin.py @@ -62,10 +62,20 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): # Look for manual instances from preference for address in self._manual_instances: - url = QUrl("http://" + address + self._api_prefix + "system/name") + self.addManualPrinter(address) - name_request = QNetworkRequest(url) - self._network_manager.get(name_request) + def addManualPrinter(self, address): + # Add a preliminary printer instance + name = address + instance_name = "manual:%s" % address + properties = { b"name": name.encode("UTF-8") } + self.addPrinter(instance_name, address, properties) + + # Check if a printer exists at this address + # If a printer responds, it will replace the preliminary printer created above + url = QUrl("http://" + address + self._api_prefix + "system/name") + name_request = QNetworkRequest(url) + self._network_manager.get(name_request) ## Handler for all requests that have finished. def _onNetworkRequestFinished(self, reply): @@ -76,10 +86,12 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): if "system/name" in reply_url: # Name returned from printer. if status_code == 200: address = reply.url().host() - name = reply.readAll() + name = reply.readAll().data().decode() + name = ("%s (%s)" % (name, address)) instance_name = "manual:%s" % address - properties = { b"name": name.data() } + properties = { b"name": name.encode("UTF-8") } + self.removePrinter(instance_name) self.addPrinter(instance_name, address, properties) ## Stop looking for devices on network.