From 3578482ea5fdb7109e5550097f826eb13c301483 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Tue, 30 Apr 2019 15:26:02 +0200 Subject: [PATCH] Fix connect via network dialog CURA-6483 - Do not add printers that have already been discovered - Add IP address validation check --- .../resources/qml/DiscoverUM3Action.qml | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/plugins/UM3NetworkPrinting/resources/qml/DiscoverUM3Action.qml b/plugins/UM3NetworkPrinting/resources/qml/DiscoverUM3Action.qml index 2788a35173..1e3da11e0a 100644 --- a/plugins/UM3NetworkPrinting/resources/qml/DiscoverUM3Action.qml +++ b/plugins/UM3NetworkPrinting/resources/qml/DiscoverUM3Action.qml @@ -1,8 +1,8 @@ -// Copyright (c) 2018 Ultimaker B.V. +// Copyright (c) 2019 Ultimaker B.V. // Cura is released under the terms of the LGPLv3 or higher. import UM 1.2 as UM -import Cura 1.0 as Cura +import Cura 1.5 as Cura import QtQuick 2.2 import QtQuick.Controls 1.1 @@ -14,9 +14,13 @@ Cura.MachineAction { id: base anchors.fill: parent; + property alias currentItemIndex: listview.currentIndex property var selectedDevice: null property bool completeProperties: true + // For validating IP addresses + property var networkingUtil: Cura.NetworkingUtil {} + function connectToPrinter() { if(base.selectedDevice && base.completeProperties) @@ -342,6 +346,17 @@ Cura.MachineAction } } + MessageDialog + { + id: invalidIPAddressMessageDialog + x: ((parent.width - width) / 2) | 0 + y: ((parent.height - height) / 2) | 0 + title: catalog.i18nc("@title:window", "Invalid IP address") + text: catalog.i18nc("@text", "Please enter a valid IP address.") + icon: StandardIcon.Warning + standardButtons: StandardButton.Ok + } + UM.Dialog { id: manualPrinterDialog @@ -404,6 +419,26 @@ Cura.MachineAction text: catalog.i18nc("@action:button", "OK") onClicked: { + // Validate the input first + if (!networkingUtil.isValidIP(manualPrinterDialog.addressText)) + { + invalidIPAddressMessageDialog.open() + return + } + + // if the entered IP address has already been discovered, switch the current item to that item + // and do nothing else. + for (var i = 0; i < manager.foundDevices.length; i++) + { + var device = manager.foundDevices[i] + if (device.address == manualPrinterDialog.addressText) + { + currentItemIndex = i + manualPrinterDialog.hide() + return + } + } + manager.setManualDevice(manualPrinterDialog.printerKey, manualPrinterDialog.addressText) manualPrinterDialog.hide() }