mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Implement Adding, Editing and Removing manual printers
CURA-2384
This commit is contained in:
parent
eba49ee8c2
commit
578b4d3826
3 changed files with 42 additions and 8 deletions
|
@ -39,9 +39,9 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
|||
Application.getInstance().globalContainerStackChanged.connect(self.reCheckConnections)
|
||||
|
||||
# Get list of manual printers from preferences
|
||||
preferences = Preferences.getInstance()
|
||||
preferences.addPreference("um3networkprinting/manual_instances", "") # A comma-separated list of ip adresses or hostnames
|
||||
self._manual_instances = preferences.getValue("um3networkprinting/manual_instances").split(",")
|
||||
self._preferences = Preferences.getInstance()
|
||||
self._preferences.addPreference("um3networkprinting/manual_instances", "") # A comma-separated list of ip adresses or hostnames
|
||||
self._manual_instances = self._preferences.getValue("um3networkprinting/manual_instances").split(",")
|
||||
|
||||
addPrinterSignal = Signal()
|
||||
removePrinterSignal = Signal()
|
||||
|
@ -65,11 +65,17 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
|||
self.addManualPrinter(address)
|
||||
|
||||
def addManualPrinter(self, address):
|
||||
# Add a preliminary printer instance
|
||||
if address not in self._manual_instances:
|
||||
self._manual_instances.append(address)
|
||||
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances))
|
||||
|
||||
name = address
|
||||
instance_name = "manual:%s" % address
|
||||
properties = { b"name": name.encode("UTF-8") }
|
||||
self.addPrinter(instance_name, address, properties)
|
||||
|
||||
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
|
||||
|
@ -77,6 +83,16 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
|||
name_request = QNetworkRequest(url)
|
||||
self._network_manager.get(name_request)
|
||||
|
||||
def removeManualPrinter(self, key, address = None):
|
||||
if key in self._printers:
|
||||
if not address:
|
||||
address = self._printers[key].ipAddress
|
||||
self.removePrinter(key)
|
||||
|
||||
if address in self._manual_instances:
|
||||
self._manual_instances.remove(address)
|
||||
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances))
|
||||
|
||||
## Handler for all requests that have finished.
|
||||
def _onNetworkRequestFinished(self, reply):
|
||||
reply_url = reply.url().toString()
|
||||
|
@ -91,8 +107,10 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
|||
|
||||
instance_name = "manual:%s" % address
|
||||
properties = { b"name": name.encode("UTF-8") }
|
||||
self.removePrinter(instance_name)
|
||||
self.addPrinter(instance_name, address, properties)
|
||||
if instance_name in self._printers:
|
||||
# Only replace the printer if it is still in the list of (manual) printers
|
||||
self.removePrinter(instance_name)
|
||||
self.addPrinter(instance_name, address, properties)
|
||||
|
||||
## Stop looking for devices on network.
|
||||
def stop(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue