mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Only allow connecting if the printer has responded to API query
CURA-2483
This commit is contained in:
parent
a2722c7571
commit
ea9ba87fa4
2 changed files with 21 additions and 11 deletions
|
@ -11,6 +11,7 @@ Cura.MachineAction
|
||||||
id: base
|
id: base
|
||||||
anchors.fill: parent;
|
anchors.fill: parent;
|
||||||
property var selectedPrinter: null
|
property var selectedPrinter: null
|
||||||
|
property bool completeProperties: true
|
||||||
property var connectingToPrinter: null
|
property var connectingToPrinter: null
|
||||||
|
|
||||||
Connections
|
Connections
|
||||||
|
@ -84,7 +85,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
id: editButton
|
id: editButton
|
||||||
text: catalog.i18nc("@action:button", "Edit")
|
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:
|
onClicked:
|
||||||
{
|
{
|
||||||
manualPrinterDialog.showDialog(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress);
|
manualPrinterDialog.showDialog(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress);
|
||||||
|
@ -95,7 +96,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
id: removeButton
|
id: removeButton
|
||||||
text: catalog.i18nc("@action:button", "Remove")
|
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)
|
onClicked: manager.removeManualPrinter(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +151,12 @@ Cura.MachineAction
|
||||||
}
|
}
|
||||||
width: parent.width
|
width: parent.width
|
||||||
currentIndex: -1
|
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()
|
Component.onCompleted: manager.startDiscovery()
|
||||||
delegate: Rectangle
|
delegate: Rectangle
|
||||||
{
|
{
|
||||||
|
@ -252,7 +258,7 @@ Cura.MachineAction
|
||||||
Button
|
Button
|
||||||
{
|
{
|
||||||
text: catalog.i18nc("@action:button", "Connect")
|
text: catalog.i18nc("@action:button", "Connect")
|
||||||
enabled: base.selectedPrinter ? true : false
|
enabled: (base.selectedPrinter && base.completeProperties) ? true : false
|
||||||
onClicked: connectToPrinter()
|
onClicked: connectToPrinter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,8 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
||||||
|
|
||||||
# Look for manual instances from preference
|
# Look for manual instances from preference
|
||||||
for address in self._manual_instances:
|
for address in self._manual_instances:
|
||||||
self.addManualPrinter(address)
|
if address:
|
||||||
|
self.addManualPrinter(address)
|
||||||
|
|
||||||
def addManualPrinter(self, address):
|
def addManualPrinter(self, address):
|
||||||
if address not in self._manual_instances:
|
if address not in self._manual_instances:
|
||||||
|
@ -72,17 +73,13 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
||||||
|
|
||||||
name = address
|
name = address
|
||||||
instance_name = "manual:%s" % 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:
|
if instance_name not in self._printers:
|
||||||
# Add a preliminary printer instance
|
# Add a preliminary printer instance
|
||||||
self.addPrinter(instance_name, address, properties)
|
self.addPrinter(instance_name, address, properties)
|
||||||
|
|
||||||
# Check if a printer exists at this address
|
self.checkManualPrinter(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)
|
|
||||||
|
|
||||||
def removeManualPrinter(self, key, address = None):
|
def removeManualPrinter(self, key, address = None):
|
||||||
if key in self._printers:
|
if key in self._printers:
|
||||||
|
@ -94,6 +91,13 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
||||||
self._manual_instances.remove(address)
|
self._manual_instances.remove(address)
|
||||||
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances))
|
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.
|
## Handler for all requests that have finished.
|
||||||
def _onNetworkRequestFinished(self, reply):
|
def _onNetworkRequestFinished(self, reply):
|
||||||
reply_url = reply.url().toString()
|
reply_url = reply.url().toString()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue