Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DiscoverUM3Action.qml « qml « resources « UM3NetworkPrinting « plugins - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d34a182b3bf7957456c3a93b542c65715ac8d92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// Copyright (c) 2022 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.

import QtQuick 2.15
import QtQuick.Controls 2.9
import QtQuick.Layouts 1.1
import QtQuick.Window 2.1

import UM 1.5 as UM
import Cura 1.5 as Cura

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)
        {
            manager.associateActiveMachineWithPrinterDevice(base.selectedDevice)
            completed()
        }
    }

    Column
    {
        anchors.fill: parent;
        id: discoverUM3Action
        spacing: UM.Theme.getSize("default_margin").height

        UM.I18nCatalog { id: catalog; name:"cura" }

        UM.Label
        {
            id: pageTitle
            width: parent.width
            text: catalog.i18nc("@title:window", "Connect to Networked Printer")
        }

        UM.Label
        {
            id: pageDescription
            width: parent.width
            text: catalog.i18nc("@label", "To print directly to your printer over the network, please make sure your printer is connected to the network using a network cable or by connecting your printer to your WIFI network. If you don't connect Cura with your printer, you can still use a USB drive to transfer g-code files to your printer.") + "\n\n" + catalog.i18nc("@label", "Select your printer from the list below:")
        }

        Row
        {
            spacing: UM.Theme.getSize("thin_margin").width

            Cura.SecondaryButton
            {
                id: addButton
                text: catalog.i18nc("@action:button", "Add");
                onClicked:
                {
                    manualPrinterDialog.showDialog("", "");
                }
            }

            Cura.SecondaryButton
            {
                id: editButton
                text: catalog.i18nc("@action:button", "Edit")
                enabled: base.selectedDevice != null && base.selectedDevice.getProperty("manual") == "true"
                onClicked:
                {
                    manualPrinterDialog.showDialog(base.selectedDevice.key, base.selectedDevice.ipAddress);
                }
            }

            Cura.SecondaryButton
            {
                id: removeButton
                text: catalog.i18nc("@action:button", "Remove")
                enabled: base.selectedDevice != null && base.selectedDevice.getProperty("manual") == "true"
                onClicked: manager.removeManualDevice(base.selectedDevice.key, base.selectedDevice.ipAddress)
            }

            Cura.SecondaryButton
            {
                id: rediscoverButton
                text: catalog.i18nc("@action:button", "Refresh")
                onClicked: manager.restartDiscovery()
            }
        }

        Row
        {
            id: contentRow
            width: parent.width
            spacing: UM.Theme.getSize("default_margin").width

            Column
            {
                width: Math.round(parent.width * 0.5)
                spacing: UM.Theme.getSize("default_margin").height

                ListView
                {
                    id: listview

                    width: parent.width
                    height: base.height - contentRow.y - discoveryTip.height

                    ScrollBar.vertical: UM.ScrollBar {}
                    clip: true

                    model: manager.foundDevices
                    currentIndex: -1
                    onCurrentIndexChanged:
                    {
                        base.selectedDevice = listview.model[currentIndex];
                        // Only allow connecting if the printer has responded to API query since the last refresh
                        base.completeProperties = base.selectedDevice != null && base.selectedDevice.getProperty("incomplete") != "true";
                    }
                    Component.onCompleted: manager.startDiscovery()

                    delegate: UM.Label
                    {
                        id: printNameLabel
                        width: listview.width
                        height: contentHeight
                        anchors.left: parent.left
                        anchors.leftMargin: UM.Theme.getSize("default_margin").width

                        anchors.right: parent.right
                        text: listview.model[index].name
                        elide: Text.ElideRight

                        MouseArea
                        {
                            anchors.fill: parent;
                            onClicked:
                            {
                                if(!parent.ListView.isCurrentItem)
                                {
                                    parent.ListView.view.currentIndex = index;
                                }
                            }
                        }

                        background: Rectangle
                        {
                            color: parent.ListView.isCurrentItem ? UM.Theme.getColor("background_3") : "transparent"
                        }
                    }
                }
                UM.Label
                {
                    id: discoveryTip
                    anchors.left: parent.left
                    anchors.right: parent.right
                    text: catalog.i18nc("@label", "If your printer is not listed, read the <a href='%1'>network printing troubleshooting guide</a>").arg("https://ultimaker.com/en/cura/troubleshooting/network?utm_source=cura&utm_medium=software&utm_campaign=manage-network-printer");
                    onLinkActivated: Qt.openUrlExternally(link)
                }

            }
            Column
            {
                width: Math.round(parent.width * 0.5)
                visible: base.selectedDevice ? true : false
                spacing: UM.Theme.getSize("default_margin").height
                UM.Label
                {
                    width: parent.width
                    text: base.selectedDevice ? base.selectedDevice.name : ""
                    font: UM.Theme.getFont("large_bold")
                    elide: Text.ElideRight
                }
                GridLayout
                {
                    visible: base.completeProperties
                    width: parent.width
                    columns: 2
                    UM.Label
                    {
                        Layout.fillWidth: true
                        text: catalog.i18nc("@label", "Type")
                    }
                    UM.Label
                    {
                        Layout.fillWidth: true
                        text:
                        {
                            if (base.selectedDevice) {
                                return base.selectedDevice.printerTypeName
                            }
                            return ""
                        }
                    }
                    UM.Label
                    {
                        Layout.fillWidth: true
                        text: catalog.i18nc("@label", "Firmware version")
                    }
                    UM.Label
                    {
                        Layout.fillWidth: true
                        text: base.selectedDevice ? base.selectedDevice.firmwareVersion : ""
                    }
                    UM.Label
                    {
                        Layout.fillWidth: true
                        text: catalog.i18nc("@label", "Address")
                    }
                    UM.Label
                    {
                        Layout.fillWidth: true
                        text: base.selectedDevice ? base.selectedDevice.ipAddress : ""
                    }
                }

                UM.Label
                {
                    width: parent.width
                    text:{
                        // The property cluster size does not exist for older UM3 devices.
                        if(!base.selectedDevice || base.selectedDevice.clusterSize == null || base.selectedDevice.clusterSize == 1)
                        {
                            return "";
                        }
                        else if (base.selectedDevice.clusterSize === 0)
                        {
                            return catalog.i18nc("@label", "This printer is not set up to host a group of printers.");
                        }
                        else
                        {
                            return catalog.i18nc("@label", "This printer is the host for a group of %1 printers.".arg(base.selectedDevice.clusterSize));
                        }
                    }

                }
                UM.Label
                {
                    width: parent.width
                    visible: base.selectedDevice != null && !base.completeProperties
                    text: catalog.i18nc("@label", "The printer at this address has not yet responded." )
                }

                Cura.SecondaryButton
                {
                    text: catalog.i18nc("@action:button", "Connect")
                    enabled: (base.selectedDevice && base.completeProperties && base.selectedDevice.clusterSize > 0) ? true : false
                    onClicked: connectToPrinter()
                }
            }
        }
    }

    Cura.MessageDialog
    {
        id: invalidIPAddressMessageDialog
        title: catalog.i18nc("@title:window", "Invalid IP address")
        text: catalog.i18nc("@text", "Please enter a valid IP address.")
        standardButtons: Dialog.Ok
    }

    Cura.MessageDialog
    {
        id: manualPrinterDialog
        property string printerKey
        property alias addressText: addressField.text

        title: catalog.i18nc("@title:window", "Printer Address")

        width: UM.Theme.getSize("small_popup_dialog").width
        height: UM.Theme.getSize("small_popup_dialog").height

        anchors.centerIn: Overlay.overlay

        standardButtons: Dialog.Yes | Dialog.No

        signal showDialog(string key, string address)
        onShowDialog:
        {
            printerKey = key;
            addressText = address;
            manualPrinterDialog.open();
            addressField.selectAll();
            addressField.focus = true;
        }

        Column {
            anchors.fill: parent
            spacing: UM.Theme.getSize("default_margin").height

            UM.Label
            {
                text: catalog.i18nc("@label", "Enter the IP address of your printer on the network.")
                renderType: Text.NativeRendering
            }

            Cura.TextField
            {
                id: addressField
                width: parent.width
                validator: RegularExpressionValidator { regularExpression: /[a-zA-Z0-9\.\-\_]*/ }
            }
        }

        onAccepted:
        {
            // Validate the input first
            if (!networkingUtil.isValidIP(manualPrinterDialog.addressText))
            {
                // prefent closing of element, as we want to keep the dialog active after a wrongly entered IP adress
                manualPrinterDialog.open()
                // show invalid ip warning
                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;
                    return;
                }
            }

            manager.setManualDevice(manualPrinterDialog.printerKey, manualPrinterDialog.addressText);
        }
    }
}