Only allow connecting if the printer has responded to API query

CURA-2483
This commit is contained in:
fieldOfView 2016-09-29 14:29:33 +02:00
parent a2722c7571
commit ea9ba87fa4
2 changed files with 21 additions and 11 deletions

View file

@ -11,6 +11,7 @@ Cura.MachineAction
id: base
anchors.fill: parent;
property var selectedPrinter: null
property bool completeProperties: true
property var connectingToPrinter: null
Connections
@ -84,7 +85,7 @@ Cura.MachineAction
{
id: editButton
text: catalog.i18nc("@action:button", "Edit")
enabled: base.selectedPrinter && base.selectedPrinter.getKey().substr(0,7) =="manual:"
enabled: base.selectedPrinter != null && (base.selectedPrinter.getKey().substr(0,7) =="manual:")
onClicked:
{
manualPrinterDialog.showDialog(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress);
@ -95,7 +96,7 @@ Cura.MachineAction
{
id: removeButton
text: catalog.i18nc("@action:button", "Remove")
enabled: base.selectedPrinter && base.selectedPrinter.getKey().substr(0,7) =="manual:"
enabled: base.selectedPrinter != null && (base.selectedPrinter.getKey().substr(0,7) =="manual:")
onClicked: manager.removeManualPrinter(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress)
}
@ -150,7 +151,12 @@ Cura.MachineAction
}
width: parent.width
currentIndex: -1
onCurrentIndexChanged: base.selectedPrinter = listview.model[currentIndex]
onCurrentIndexChanged:
{
base.selectedPrinter = listview.model[currentIndex];
// Only allow connecting if the printer has responded to API query since the last refresh
base.completeProperties = base.selectedPrinter != null && (base.selectedPrinter.firmwareVersion != "");
}
Component.onCompleted: manager.startDiscovery()
delegate: Rectangle
{
@ -252,7 +258,7 @@ Cura.MachineAction
Button
{
text: catalog.i18nc("@action:button", "Connect")
enabled: base.selectedPrinter ? true : false
enabled: (base.selectedPrinter && base.completeProperties) ? true : false
onClicked: connectToPrinter()
}
}

View file

@ -63,6 +63,7 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
# Look for manual instances from preference
for address in self._manual_instances:
if address:
self.addManualPrinter(address)
def addManualPrinter(self, address):
@ -72,17 +73,13 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
name = address
instance_name = "manual:%s" % address
properties = { b"name": name.encode("UTF-8") }
properties = { b"name": name.encode("UTF-8"), b"incomplete": True }
if instance_name not in self._printers:
# Add a preliminary printer instance
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_request = QNetworkRequest(url)
self._network_manager.get(name_request)
self.checkManualPrinter(address)
def removeManualPrinter(self, key, address = None):
if key in self._printers:
@ -94,6 +91,13 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
self._manual_instances.remove(address)
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances))
def checkManualPrinter(self, address):
# 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_request = QNetworkRequest(url)
self._network_manager.get(name_request)
## Handler for all requests that have finished.
def _onNetworkRequestFinished(self, reply):
reply_url = reply.url().toString()