Implement ServiceStateChange.Removed (bonjour undiscovery)

Contributes to CURA-1851
This commit is contained in:
fieldOfView 2016-07-27 16:41:06 +02:00
parent 050e81053f
commit 136755758e
3 changed files with 23 additions and 9 deletions

View File

@ -14,19 +14,20 @@ class DiscoverUM3Action(MachineAction):
self._network_plugin = None
printerDetected = pyqtSignal()
printersChanged = pyqtSignal()
@pyqtSlot()
def startDiscovery(self):
if not self._network_plugin:
self._network_plugin = Application.getInstance().getOutputDeviceManager().getOutputDevicePlugin("JediWifiPrintingPlugin")
self._network_plugin.addPrinterSignal.connect(self._onPrinterAdded)
self.printerDetected.emit()
self._network_plugin.addPrinterSignal.connect(self._onPrinterDiscoveryChanged)
self._network_plugin.removePrinterSignal.connect(self._onPrinterDiscoveryChanged)
self.printersChanged.emit()
def _onPrinterAdded(self, *args):
self.printerDetected.emit()
def _onPrinterDiscoveryChanged(self, *args):
self.printersChanged.emit()
@pyqtProperty("QVariantList", notify = printerDetected)
@pyqtProperty("QVariantList", notify = printersChanged)
def foundDevices(self):
if self._network_plugin:
printers = self._network_plugin.getPrinters()

View File

@ -233,6 +233,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
self._updateHeadPosition(head_x, head_y, head_z)
def close(self):
self._updateJobState("")
self.setConnectionState(ConnectionState.closed)
if self._progress_message:
self._progress_message.hide()
@ -279,6 +280,11 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
self._update_timer.start()
self._camera_timer.start()
## Stop requesting data from printer
def disconnect(self):
Logger.log("d", "Connection with printer %s with ip %s stopped", self._key, self._address)
self.close()
newImage = pyqtSignal()
@pyqtProperty(QUrl, notify = newImage)

View File

@ -19,9 +19,11 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
# Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
self.addPrinterSignal.connect(self.addPrinter)
self.removePrinterSignal.connect(self.removePrinter)
Application.getInstance().globalContainerStackChanged.connect(self.reCheckConnections)
addPrinterSignal = Signal()
removePrinterSignal = Signal()
## Start looking for devices on network.
def start(self):
@ -56,6 +58,13 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
self._printers[printer.getKey()].connect()
printer.connectionStateChanged.connect(self._onPrinterConnectionStateChanged)
def removePrinter(self, name):
printer = self._printers.pop(name, None)
if printer:
if printer.isConnected():
printer.connectionStateChanged.disconnect(self._onPrinterConnectionStateChanged)
printer.disconnect()
## Handler for when the connection state of one of the detected printers changes
def _onPrinterConnectionStateChanged(self, key):
if self._printers[key].isConnected():
@ -73,6 +82,4 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
self.addPrinterSignal.emit(str(name), address, info.properties)
elif state_change == ServiceStateChange.Removed:
pass
# TODO; This isn't testable right now. We need to also decide how to handle
#
self.removePrinterSignal.emit(str(name))