Browse Source

(WIP) Connect manual-device-added signals to AddPrinterByIP-page. [CURA-6294]

Remco Burema 6 years ago
parent
commit
bb17ab14da

+ 13 - 0
plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py

@@ -34,6 +34,8 @@ i18n_catalog = i18nCatalog("cura")
 #       If we discover a printer that has the same key as the active machine instance a connection is made.
 @signalemitter
 class UM3OutputDevicePlugin(OutputDevicePlugin):
+    addDeviceSignal = Signal()
+    removeDeviceSignal = Signal()
     discoveredDevicesChanged = Signal()
     cloudFlowIsPossible = Signal()
 
@@ -173,6 +175,8 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
                 self.checkCloudFlowIsPossible()
         else:
             self.getOutputDeviceManager().removeOutputDevice(key)
+            if key.startswith("manual:"):
+                self.removeManualDeviceSignal.emit(self.getPluginId(), key, self._discovered_devices[key].address())  # TODO?
 
     def stop(self):
         if self._zero_conf is not None:
@@ -195,6 +199,8 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
             self._manual_instances.remove(address)
             self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances))
 
+        self.removeManualDeviceSignal.emit(self.getPluginId(), key, address)  # TODO?
+
     def addManualDevice(self, address):
         if address not in self._manual_instances:
             self._manual_instances.append(address)
@@ -232,6 +238,10 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
     def _onNetworkRequestFinished(self, reply):
         reply_url = reply.url().toString()
 
+        address = ""
+        device = None
+        properties = {}  # type: Dict[bytes, bytes]
+
         if "system" in reply_url:
             if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200:
                 # Something went wrong with checking the firmware version!
@@ -291,6 +301,9 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
                 self._onRemoveDevice(instance_name)
                 self._onAddDevice(instance_name, address, properties)
 
+        if device:
+            self.addManualDeviceSignal.emit(self.getPluginId(), device.getId(), address, properties)
+
     def _onRemoveDevice(self, device_id):
         device = self._discovered_devices.pop(device_id, None)
         if device:

+ 30 - 9
resources/qml/WelcomePages/AddPrinterByIpContent.qml

@@ -70,7 +70,7 @@ Item
         anchors.topMargin: 40
         anchors.horizontalCenter: parent.horizontalCenter
         horizontalAlignment: Text.AlignHCenter
-        text: catalog.i18nc("@label", "Add printer by IP adress")
+        text: catalog.i18nc("@label", "Add printer by IP address")
         color: UM.Theme.getColor("primary_button")
         font: UM.Theme.getFont("large_bold")
         renderType: Text.NativeRendering
@@ -193,23 +193,44 @@ Item
                         anchors.top: parent.top
                         font: UM.Theme.getFont("large")
 
-                        text: "Davids-desktop"  // TODO: placeholder, alter after interface review.
+                        text: "???"
                     }
 
                     GridLayout
                     {
+                        id: printerInfoGrid
                         anchors.top: printerNameLabel.bottom
                         columns: 2
                         columnSpacing: 20
 
-                        Text { font: UM.Theme.getFont("default"); text: "Type" }
-                        Text { font: UM.Theme.getFont("default"); text: "Ultimaker S5" }  // TODO: placeholder, alter after interface review.
+                        Text { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Type") }
+                        Label { id: typeText; font: UM.Theme.getFont("default"); text: "?" }
 
-                        Text { font: UM.Theme.getFont("default"); text: "Firmware version" }
-                        Text { font: UM.Theme.getFont("default"); text: "4.3.3.20180529" }  // TODO: placeholder, alter after interface review.
+                        Text { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Firmware version") }
+                        Label { id: firmwareText; font: UM.Theme.getFont("default"); text: "0.0.0.0" }
 
-                        Text { font: UM.Theme.getFont("default"); text: "Address" }
-                        Text { font: UM.Theme.getFont("default"); text: "10.183.1.115" }  // TODO: placeholder, alter after interface review.
+                        Text { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Address") }
+                        Label { id: addressText; font: UM.Theme.getFont("default"); text: "0.0.0.0" }
+
+                        Connections
+                        {
+                            target: UM.OutputDeviceManager
+                            onManualDeviceChanged:
+                            {
+                                typeText.text = UM.OutputDeviceManager.manualDeviceProperty("printer_type")
+                                firmwareText.text = UM.OutputDeviceManager.manualDeviceProperty("firmware_version")
+                                addressText.text = UM.OutputDeviceManager.manualDeviceProperty("address")
+                            }
+                        }
+                    }
+
+                    Connections
+                    {
+                        target: UM.OutputDeviceManager
+                        onManualDeviceChanged:
+                        {
+                            printerNameLabel.text = UM.OutputDeviceManager.manualDeviceProperty("name")
+                        }
                     }
                 }
             }
@@ -222,7 +243,7 @@ Item
         anchors.left: parent.left
         anchors.bottom: parent.bottom
         anchors.margins: 40
-        text: catalog.i18nc("@button", "Back")
+        text: catalog.i18nc("@button", "Cancel")
         width: 140
         fixedWidthMode: true
         onClicked: base.showPreviousPage()