summaryrefslogtreecommitdiffstats
path: root/app/wired/ConfigDialog.qml
blob: 4d8632f61bbb29dedee8f8fad8cf53998622965e (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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/*
 * Copyright (C) 2016 The Qt Company Ltd.
 * Copyright (C) 2019 Konsulko Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
import AGL.Demo.Controls 1.0


Dialog {
    id: root
    property string serviceName: undefined
    property alias xpos: root.x
    property alias ypos: root.y
    property alias maxpwidth: root.width
    property alias maxpheight: root.height
    property alias customAddress: m_customAddress.text
    property alias customNetmask: m_customNetmask.text
    property alias customGateway: m_customGateway.text
    property alias customNSlist: m_customNSlist.text

    property string activeAddress: undefined
    property string activeNetmask: undefined
    property string activeGateway: undefined
    property string activeNSList: undefined

    property bool activeStatic: undefined
    property bool activeManualNS: undefined

    property bool isIPv4: true
    property bool isStatic: activeStatic
    property bool isManualDNS: activeManualNS

    signal finished(string svc, var newaa, var newna)

    visible: false
    z: 1
    focus: true
    modal: true
    footer: DialogButtonBox {
        Button { text: "APPLY"
                 DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
        }
        Button { text: "CLOSE"
                 DialogButtonBox.buttonRole: DialogButtonBox.RejectRole
        }
        Button { text: "RESET"
                 DialogButtonBox.buttonRole: DialogButtonBox.ResetRole
        }
        background: Rectangle {
            border.color : '#00ADDC'
            color: '#848286'
        }
    }

    background: Rectangle {
        border.color : '#00ADDC'
        color: 'transparent'
    }

    function setDefaultValues() {
        isIPv4 = true
        isStatic = false
        isManualDNS = false
        m_customAddress.clear()
        m_customNetmask.clear()
        m_customGateway.clear()
        m_customNSlist.clear()
    }

    onIsIPv4Changed: {
        verSwitch.checked = isIPv4
    }

    onIsStaticChanged: {
        modeSwitch.checked = isStatic
    }

    onIsManualDNSChanged: {
        dnsSwitch.checked = isManualDNS
    }

    onAccepted: readInputValues()
    function readInputValues() {
        if (isIPv4 === false) {
            console.log("IPv6 not supported by settings application")
            setDefaultValues()
        } else {
            var aa = [];
            isStatic? aa.push("manual") : aa.push("dhcp");
            aa.push(customAddress);
            aa.push(customNetmask);
            aa.push(customGateway);
            var na = [];
            isManualDNS? na.push("manual"): na.push("auto");
            isManualDNS? na.push(customNSlist) : na.push("");
            root.finished(serviceName, aa, na);
        }
    }

    onReset: {
        setDefaultValues()
    }

    onRejected: {
        isIPv4 = true
        isStatic = activeStatic
        isManualDNS = activeManualNS
        customAddress.clear()
        customNetmask.clear()
        customGateway.clear()
        customNSlist.clear()
    }

    Item {
        id: container
        anchors.centerIn: parent
        anchors.fill: parent
        ColumnLayout {
            anchors.fill: parent
            RowLayout {
                Layout.fillHeight: true
                Layout.fillWidth: true
                Layout.alignment: Qt.AlignLeft
                spacing: 8
                visible: true
                Label {
                    id: nwLabel
                    font.pixelSize: 28
                    color: '#080C0F'
                    text: "Network:"
                    Layout.preferredWidth: 200
                }
                Label {
                    id: svcLabel
                    font.pixelSize: 28
                    color: '#66FF99'
                    text: serviceName
                }
            }
            RowLayout {
                Layout.fillHeight: true
                Layout.fillWidth: true
                Layout.alignment: Qt.AlignLeft
                spacing: 8
                visible: true
                Label {
                    id: ipvlabel
                    font.pixelSize: 28
                    color: '#080C0F'
                    text: "IP version:"
                    Layout.preferredWidth: 200
                }
                Label {
                    id: ipv6label
                    font.pixelSize: 28
                    color: root.isIPv4? '#848286':'#0DF9FF'
                    text: "IPv6"
                    Layout.preferredWidth: 80
                }
                Switch {
                    id: verSwitch
                    scale: 0.5
                    checked : root.isIPv4
                    onCheckedChanged: { root.isIPv4 =  checked }
                }
                Label {
                    id: ipv4label
                    font.pixelSize: 28
                    color: root.isIPv4? '#0DF9FF':'#848286'
                    text: "IPv4"
                }
            }
            RowLayout {
                Layout.fillHeight: true
                Layout.fillWidth: true
                Layout.alignment: Qt.AlignHCenter
                spacing: 8
                visible: root.isIPv4? false : true
                Label {
                    font.pixelSize: 28
                    color: 'white'
                    text: "IPv6 not supported by Settings application"
                }
            }
            RowLayout {
                Layout.fillHeight: true
                Layout.fillWidth: true
                Layout.alignment: Qt.AlignLeft
                spacing: 8
                visible: root.isIPv4? true : false
                Label {
                    id: modelabel
                    font.pixelSize: 28
                    color: '#080C0F'
                    text: "Addressing:"
                    Layout.preferredWidth: 200
                }
                Label {
                    id: dhcplabel
                    font.pixelSize: 28
                    color: root.isStatic? '#848286':'#0DF9FF'
                    text: "DHCP"
                    Layout.preferredWidth: 80
                }
                Switch {
                    id: modeSwitch
                    scale: 0.5
                    checked : root.isStatic
                    onCheckedChanged: { root.isStatic = checked }
                }
                Label {
                    id: staticlabel
                    font.pixelSize: 28
                    color: root.isStatic? '#0DF9FF':'#848286'
                    text: "Static"
                }
            }
            RowLayout {
                Layout.fillHeight: true
                Layout.fillWidth: true
                Layout.alignment: Qt.AlignHCenter
                spacing: 16
                visible: (root.isStatic && root.isIPv4)? true : false
                ColumnLayout {
                    Layout.fillWidth: true
                    Label {
                        id: address
                        font.pixelSize: 28
                        color: '#080C0F'
                        text: "address:"
                    }
                    TextArea {
                        id: m_customAddress
                        font.pixelSize: 28
                        Layout.fillWidth: true
                        Layout.alignment: Qt.AlignLeft
                        placeholderText: activeAddress
                    }
                }
                ColumnLayout {
                    Layout.fillWidth: true
                    Label {
                        id: netmask
                        font.pixelSize: 28
                        color: '#080C0F'
                        text: "netmask:"
                    }
                    TextArea {
                        id: m_customNetmask
                        font.pixelSize: 28
                        Layout.fillWidth: true
                        Layout.alignment: Qt.AlignLeft
                        placeholderText: activeNetmask
                    }
                }
                ColumnLayout {
                    Layout.fillWidth: true
                    Label {
                        id: gateway
                        font.pixelSize: 28
                        color: '#080C0F'
                        text: "gateway:"
                    }
                    TextArea {
                        id: m_customGateway
                        font.pixelSize: 28
                        Layout.fillWidth: true
                        Layout.alignment: Qt.AlignLeft
                        placeholderText: activeGateway
                    }
                }
            }
            RowLayout {
                Layout.fillHeight: true
                Layout.fillWidth: true
                Layout.alignment: Qt.AlignLeft
                spacing: 8
                visible: root.isIPv4? true : false
                Label {
                    id: dnslabel
                    font.pixelSize: 28
                    color: '#080C0F'
                    text: "DNS address:"
                    Layout.preferredWidth: 200
                }
                Label {
                    id: customdnslabel
                    font.pixelSize: 28
                    color: root.isManualDNS? '#848286':'#0DF9FF'
                    text: "Auto"
                    Layout.preferredWidth: 80
                }
                Switch {
                    id: dnsSwitch
                    scale: 0.5
                    checked : root.isManualDNS
                    onCheckedChanged: { root.isManualDNS = checked }
                }
                Label {
                    id: autodnslabel
                    font.pixelSize: 28
                    color: root.isManualDNS? '#0DF9FF':'#848286'
                    text: "Manual"
                }
            }
            RowLayout {
                Layout.fillHeight: true
                Layout.fillWidth: true
                Layout.alignment: Qt.AlignHCenter
                spacing: 16
                visible: (root.isManualDNS && root.isIPv4)? true : false
                ColumnLayout {
                    Layout.fillWidth: true
                    Label {
                        id: dnsList
                        font.pixelSize: 28
                        color: '#080C0F'
                        text: "DNS list:"
                    }
                    TextArea {
                        id: m_customNSlist
                        font.pixelSize: 28
                        Layout.fillWidth: true
                        Layout.alignment: Qt.AlignLeft
                        placeholderText: activeNSList
                    }
                }
            }

            Keyboard {
                id: keyboard
                Layout.fillWidth: true
                Layout.fillHeight: true
                Layout.preferredHeight: 1
                target: activeFocusControl
            }
        }
    }
}