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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
// Copyright (c) 2019 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import UM 1.3 as UM
import Cura 1.5 as Cura
//
// This component contains the content for the 'by IP' page of the "Add New Printer" flow of the on-boarding process.
//
Item
{
UM.I18nCatalog { id: catalog; name: "cura" }
id: addPrinterByIpScreen
// If there's a manual address resolve request in progress.
property bool hasRequestInProgress: CuraApplication.getDiscoveredPrintersModel().hasManualDeviceRequestInProgress
// Indicates if a request has finished.
property bool hasRequestFinished: false
property string currentRequestAddress: ""
property var discoveredPrinter: null
property bool isPrinterDiscovered: discoveredPrinter != null
// A printer can only be added if it doesn't have an unknown type and it's the host of a group.
property bool canAddPrinter: isPrinterDiscovered && !discoveredPrinter.isUnknownMachineType && discoveredPrinter.isHostOfGroup
// For validating IP address
property var networkingUtil: Cura.NetworkingUtil {}
// CURA-6483
// For a manually added UM printer, the UM3OutputDevicePlugin will first create a LegacyUM device for it. Later,
// when it gets more info from the printer, it will first REMOVE the LegacyUM device and then add a ClusterUM device.
// The Add-by-IP page needs to make sure that the user do not add an unknown printer or a printer that's not the
// host of a group. Because of the device list change, this page needs to react upon DiscoveredPrintersChanged so
// it has the correct information.
Connections
{
target: CuraApplication.getDiscoveredPrintersModel()
function onDiscoveredPrintersChanged()
{
if (hasRequestFinished && currentRequestAddress)
{
var printer = CuraApplication.getDiscoveredPrintersModel().discoveredPrintersByAddress[currentRequestAddress]
printer = printer ? printer : null
discoveredPrinter = printer
}
}
}
// Make sure to cancel the current request when this page closes.
onVisibleChanged:
{
if (!visible)
{
CuraApplication.getDiscoveredPrintersModel().cancelCurrentManualDeviceRequest()
}
}
Label
{
id: titleLabel
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignHCenter
text: catalog.i18nc("@label", "Add printer by IP address")
color: UM.Theme.getColor("primary_button")
font: UM.Theme.getFont("huge")
renderType: Text.NativeRendering
}
Item
{
anchors.top: titleLabel.bottom
anchors.bottom: connectButton.top
anchors.topMargin: UM.Theme.getSize("default_margin").height
anchors.bottomMargin: UM.Theme.getSize("default_margin").height
anchors.left: parent.left
anchors.right: parent.right
Item
{
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: UM.Theme.getSize("default_margin").width
Label
{
id: explainLabel
height: contentHeight
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
text: catalog.i18nc("@label", "Enter the IP address of your printer on the network.")
}
Item
{
id: userInputFields
height: childrenRect.height
anchors.left: parent.left
anchors.right: parent.right
anchors.top: explainLabel.bottom
anchors.topMargin: UM.Theme.getSize("default_margin").width
Cura.TextField
{
id: hostnameField
width: (parent.width / 2) | 0
height: addPrinterButton.height
anchors.verticalCenter: addPrinterButton.verticalCenter
anchors.left: parent.left
signal invalidInputDetected()
onInvalidInputDetected: invalidInputLabel.visible = true
validator: RegExpValidator
{
regExp: /([a-fA-F0-9.:]+)?/
}
onTextEdited: invalidInputLabel.visible = false
placeholderText: catalog.i18nc("@text", "Enter your printer's IP address.")
enabled: { ! (addPrinterByIpScreen.hasRequestInProgress || addPrinterByIpScreen.isPrinterDiscovered) }
onAccepted: addPrinterButton.clicked()
}
Label
{
id: invalidInputLabel
anchors.top: hostnameField.bottom
anchors.topMargin: UM.Theme.getSize("default_margin").height
anchors.left: parent.left
visible: false
text: catalog.i18nc("@text", "Please enter a valid IP address.")
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
}
Cura.SecondaryButton
{
id: addPrinterButton
anchors.top: parent.top
anchors.left: hostnameField.right
anchors.leftMargin: UM.Theme.getSize("default_margin").width
text: catalog.i18nc("@button", "Add")
enabled: !addPrinterByIpScreen.hasRequestInProgress && !addPrinterByIpScreen.isPrinterDiscovered && (hostnameField.state != "invalid" && hostnameField.text != "")
onClicked:
{
addPrinterByIpScreen.hasRequestFinished = false //In case it's pressed multiple times.
const address = hostnameField.text
if (!networkingUtil.isValidIP(address))
{
hostnameField.invalidInputDetected()
return
}
// This address is already in the discovered printer model, no need to add a manual discovery.
if (CuraApplication.getDiscoveredPrintersModel().discoveredPrintersByAddress[address])
{
addPrinterByIpScreen.discoveredPrinter = CuraApplication.getDiscoveredPrintersModel().discoveredPrintersByAddress[address]
addPrinterByIpScreen.hasRequestFinished = true
return
}
addPrinterByIpScreen.currentRequestAddress = address
CuraApplication.getDiscoveredPrintersModel().checkManualDevice(address)
}
busy: addPrinterByIpScreen.hasRequestInProgress
}
}
Item
{
width: parent.width
anchors.top: userInputFields.bottom
anchors.margins: UM.Theme.getSize("default_margin").width
Label
{
id: waitResponseLabel
anchors.top: parent.top
anchors.margins: UM.Theme.getSize("default_margin").width
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
visible: addPrinterByIpScreen.hasRequestInProgress || (addPrinterByIpScreen.hasRequestFinished && !addPrinterByIpScreen.isPrinterDiscovered)
textFormat: Text.RichText
text:
{
if (addPrinterByIpScreen.hasRequestFinished)
{
return catalog.i18nc("@label", "Could not connect to device.") + "<br /><br /><a href=\"https://ultimaker.com/in/cura/troubleshooting/network?utm_source=cura&utm_medium=software&utm_campaign=add-network-printer-error\">"
+ catalog.i18nc("@label", "Can't connect to your Ultimaker printer?") + "</a>";
}
else
{
return catalog.i18nc("@label", "The printer at this address has not responded yet.") + "<br /><br /><a href=\"https://ultimaker.com/in/cura/troubleshooting/network?utm_source=cura&utm_medium=software&utm_campaign=add-network-printer-error\">"
+ catalog.i18nc("@label", "Can't connect to your Ultimaker printer?") + "</a>";
}
}
onLinkActivated: Qt.openUrlExternally(link)
}
Item
{
id: printerInfoLabels
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: UM.Theme.getSize("default_margin").width
visible: addPrinterByIpScreen.isPrinterDiscovered
Label
{
id: printerNameLabel
anchors.top: parent.top
font: UM.Theme.getFont("large")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
text: !addPrinterByIpScreen.isPrinterDiscovered ? "???" : addPrinterByIpScreen.discoveredPrinter.name
}
Label
{
id: printerCannotBeAddedLabel
width: parent.width
anchors.top: printerNameLabel.bottom
anchors.topMargin: UM.Theme.getSize("default_margin").height
text: catalog.i18nc("@label", "This printer cannot be added because it's an unknown printer or it's not the host of a group.")
visible: addPrinterByIpScreen.hasRequestFinished && !addPrinterByIpScreen.canAddPrinter
font: UM.Theme.getFont("default_bold")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
wrapMode: Text.WordWrap
}
GridLayout
{
id: printerInfoGrid
anchors.top: printerCannotBeAddedLabel ? printerCannotBeAddedLabel.bottom : printerNameLabel.bottom
anchors.margins: UM.Theme.getSize("default_margin").width
columns: 2
columnSpacing: UM.Theme.getSize("default_margin").width
Label
{
text: catalog.i18nc("@label", "Type")
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
}
Label
{
id: typeText
text: !addPrinterByIpScreen.isPrinterDiscovered ? "?" : addPrinterByIpScreen.discoveredPrinter.readableMachineType
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
}
Label
{
text: catalog.i18nc("@label", "Firmware version")
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
}
Label
{
id: firmwareText
text: !addPrinterByIpScreen.isPrinterDiscovered ? "0.0.0.0" : addPrinterByIpScreen.discoveredPrinter.device.getProperty("firmware_version")
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
}
Label
{
text: catalog.i18nc("@label", "Address")
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
}
Label
{
id: addressText
text: !addPrinterByIpScreen.isPrinterDiscovered ? "0.0.0.0" : addPrinterByIpScreen.discoveredPrinter.address
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
}
}
Connections
{
target: CuraApplication.getDiscoveredPrintersModel()
function onManualDeviceRequestFinished(success)
{
var discovered_printers_model = CuraApplication.getDiscoveredPrintersModel()
var printer = discovered_printers_model.discoveredPrintersByAddress[hostnameField.text]
if (printer)
{
addPrinterByIpScreen.discoveredPrinter = printer
}
addPrinterByIpScreen.hasRequestFinished = true
}
}
}
}
}
}
Cura.SecondaryButton
{
id: backButton
anchors.left: parent.left
anchors.bottom: parent.bottom
text: catalog.i18nc("@button", "Back")
onClicked:
{
CuraApplication.getDiscoveredPrintersModel().cancelCurrentManualDeviceRequest()
base.showPreviousPage()
}
}
Cura.PrimaryButton
{
id: connectButton
anchors.right: parent.right
anchors.bottom: parent.bottom
text: catalog.i18nc("@button", "Connect")
onClicked:
{
CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinter(discoveredPrinter)
base.showNextPage()
}
enabled: addPrinterByIpScreen.canAddPrinter
}
}
|