summaryrefslogtreecommitdiff
path: root/raveos-calamares-module/wifi/ui/wifi.qml
blob: e3b0b0ceba8905cc595d7a748840782160957a9b (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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import RaveOS 1.0
import "." as WifiModule

Rectangle {
    id: root
    color: Stilus.hatter

    readonly property var t: WifiModule.Translations
    property var kivalasztott: null
    property bool rejtett: false
    property bool csatlakozik: false
    property bool sikertelen: false
    property bool jelszoLatszik: false

    readonly property string ssid: rejtett ? ssidMezo.text : (kivalasztott ? kivalasztott.ssid : "")
    readonly property bool jelszoKell: rejtett || (kivalasztott !== null && kivalasztott.secured)

    function updateLanguage() {
        WifiModule.Translations.setLanguage(systemLocale)
    }

    function savok(erosseg) {
        if (erosseg >= 75) return 4
        if (erosseg >= 50) return 3
        if (erosseg >= 25) return 2
        return 1
    }

    function allapotSzoveg() {
        if (nm.connected) return t.statusConnected
        if (csatlakozik) return t.statusConnecting
        if (sikertelen) return t.statusFailed
        return t.statusDisconnected
    }

    Component.onCompleted: WifiModule.Translations.setLanguage(systemLocale)

    Connections {
        target: nm
        function onConnectionChanged() {
            if (nm.connected)
                root.csatlakozik = false
        }
        function onConnectionFailed(error) {
            root.csatlakozik = false
            root.sikertelen = true
        }
    }

    Timer {
        interval: 30000
        running: root.csatlakozik
        onTriggered: {
            if (!nm.connected) {
                root.csatlakozik = false
                root.sikertelen = true
            }
        }
    }

    component SzovegLink: Text {
        signal kattint()
        color: linkHover.hovered ? Stilus.zoldHover : Stilus.zold
        font.family: Stilus.font
        font.pixelSize: 13
        font.weight: Font.DemiBold

        HoverHandler {
            id: linkHover
            cursorShape: Qt.PointingHandCursor
        }

        TapHandler {
            onTapped: parent.kattint()
        }
    }

    ColumnLayout {
        anchors.fill: parent
        anchors.topMargin: 40
        anchors.bottomMargin: 32
        anchors.leftMargin: 56
        anchors.rightMargin: 56
        spacing: 20

        ColumnLayout {
            Layout.fillWidth: true
            spacing: 10

            Fejlec {
                Layout.fillWidth: true
                felirat: root.t.eyebrow
                cim: root.t.title
            }

            Text {
                Layout.fillWidth: true
                text: root.t.subtitle
                wrapMode: Text.WordWrap
                color: Stilus.szovegMasodlagos
                font.family: Stilus.font
                font.pixelSize: 14
            }
        }

        RowLayout {
            Layout.fillWidth: true
            Layout.fillHeight: true
            spacing: 24

            ColumnLayout {
                Layout.fillWidth: true
                Layout.fillHeight: true
                spacing: 8

                RowLayout {
                    Layout.fillWidth: true

                    Text {
                        Layout.fillWidth: true
                        text: root.t.availableNetworks
                        color: Stilus.szovegHalvany
                        font.family: Stilus.font
                        font.pixelSize: 12
                        font.weight: Font.Medium
                        font.letterSpacing: 1
                        font.capitalization: Font.AllUppercase
                    }

                    SzovegLink {
                        text: root.t.refresh
                        onKattint: nm.scan()
                    }
                }

                Rectangle {
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    color: Stilus.felulet
                    border.width: 1
                    border.color: Stilus.keret

                    ListView {
                        id: lista
                        anchors.fill: parent
                        anchors.margins: 1
                        clip: true
                        model: nm.accessPoints
                        boundsBehavior: Flickable.StopAtBounds
                        ScrollBar.vertical: Gorgeto {}

                        delegate: Rectangle {
                            id: sor
                            readonly property bool kijelolt: !root.rejtett && root.kivalasztott !== null && root.kivalasztott.ssid === modelData.ssid
                            width: lista.width
                            height: 48
                            color: kijelolt ? Stilus.aktiv : (sorHover.hovered ? Stilus.aktiv : "transparent")

                            Rectangle {
                                anchors.left: parent.left
                                anchors.right: parent.right
                                anchors.bottom: parent.bottom
                                height: 1
                                color: Stilus.aktiv
                            }

                            Rectangle {
                                visible: sor.kijelolt
                                anchors.left: parent.left
                                anchors.top: parent.top
                                anchors.bottom: parent.bottom
                                width: 2
                                color: Stilus.zold
                            }

                            RowLayout {
                                anchors.fill: parent
                                anchors.leftMargin: 14
                                anchors.rightMargin: 14
                                spacing: 12

                                Row {
                                    Layout.alignment: Qt.AlignVCenter
                                    spacing: 2
                                    height: 14

                                    Repeater {
                                        model: 4
                                        Rectangle {
                                            anchors.bottom: parent.bottom
                                            width: 3
                                            height: 4 + index * 3.3
                                            color: index < root.savok(modelData.strength)
                                                ? (sor.kijelolt ? Stilus.zold : Stilus.szoveg)
                                                : Stilus.keretErosebb
                                        }
                                    }
                                }

                                Text {
                                    Layout.fillWidth: true
                                    text: modelData.ssid
                                    elide: Text.ElideRight
                                    color: Stilus.szoveg
                                    font.family: Stilus.font
                                    font.pixelSize: 14
                                    font.weight: sor.kijelolt ? Font.DemiBold : Font.Normal
                                }

                                Canvas {
                                    visible: modelData.secured
                                    Layout.preferredWidth: 14
                                    Layout.preferredHeight: 14
                                    Accessible.name: root.t.secured
                                    onPaint: {
                                        var c = getContext("2d")
                                        c.reset()
                                        c.strokeStyle = Stilus.szovegHalvany
                                        c.lineWidth = 1.5
                                        c.strokeRect(3, 6.5, 8, 6)
                                        c.beginPath()
                                        c.moveTo(4.5, 6.5)
                                        c.lineTo(4.5, 4.5)
                                        c.arc(7, 4.5, 2.5, Math.PI, 0)
                                        c.lineTo(9.5, 6.5)
                                        c.stroke()
                                    }
                                }

                                Text {
                                    Layout.preferredWidth: 52
                                    horizontalAlignment: Text.AlignRight
                                    text: modelData.band
                                    color: Stilus.szovegHalvany
                                    font.family: Stilus.mono
                                    font.pixelSize: 11
                                }
                            }

                            HoverHandler { id: sorHover }

                            TapHandler {
                                onTapped: {
                                    root.rejtett = false
                                    root.sikertelen = false
                                    root.kivalasztott = modelData
                                    jelszoMezo.text = ""
                                }
                            }
                        }

                        Text {
                            anchors.centerIn: parent
                            width: parent.width - 40
                            visible: lista.count === 0
                            text: root.t.noNetworks
                            horizontalAlignment: Text.AlignHCenter
                            wrapMode: Text.WordWrap
                            color: Stilus.szovegHalvany
                            font.family: Stilus.font
                            font.pixelSize: 13
                        }
                    }
                }

                SzovegLink {
                    text: root.t.hiddenNetwork
                    onKattint: {
                        root.rejtett = true
                        root.kivalasztott = null
                        root.sikertelen = false
                    }
                }
            }

            Rectangle {
                Layout.preferredWidth: 300
                Layout.alignment: Qt.AlignTop
                implicitHeight: panel.implicitHeight + 36
                color: Stilus.felulet
                border.width: 1
                border.color: Stilus.keret

                ColumnLayout {
                    id: panel
                    x: 18
                    y: 18
                    width: parent.width - 36
                    spacing: 14

                    Text {
                        text: root.t.selected
                        color: Stilus.szovegHalvany
                        font.family: Stilus.font
                        font.pixelSize: 12
                        font.letterSpacing: 1
                        font.capitalization: Font.AllUppercase
                    }

                    Text {
                        visible: !root.rejtett
                        Layout.fillWidth: true
                        text: root.kivalasztott ? root.kivalasztott.ssid : root.t.noSelection
                        elide: Text.ElideRight
                        color: root.kivalasztott ? Stilus.szoveg : Stilus.szovegHalvany
                        font.family: Stilus.font
                        font.pixelSize: root.kivalasztott ? 16 : 13
                        font.weight: root.kivalasztott ? Font.DemiBold : Font.Normal
                    }

                    ColumnLayout {
                        visible: root.rejtett
                        Layout.fillWidth: true
                        spacing: 6

                        Text {
                            text: root.t.ssidLabel
                            color: Stilus.szovegHalvany
                            font.family: Stilus.font
                            font.pixelSize: 12
                        }

                        TextField {
                            id: ssidMezo
                            Layout.fillWidth: true
                            implicitHeight: 44
                            leftPadding: 12
                            color: Stilus.szoveg
                            font.family: Stilus.font
                            font.pixelSize: 14
                            background: Rectangle {
                                color: Stilus.hatter
                                border.width: 1
                                border.color: ssidMezo.activeFocus ? Stilus.zold : Stilus.keretErosebb
                            }
                        }
                    }

                    ColumnLayout {
                        visible: root.jelszoKell
                        Layout.fillWidth: true
                        spacing: 6

                        Text {
                            text: root.t.password
                            color: Stilus.szovegHalvany
                            font.family: Stilus.font
                            font.pixelSize: 12
                        }

                        JelszoMezo {
                            id: jelszoMezo
                            Layout.fillWidth: true
                            reveal: root.jelszoLatszik
                            revealName: root.t.showPassword
                            onRevealClicked: root.jelszoLatszik = !root.jelszoLatszik
                            onAccepted: csatlakozGomb.clicked()
                        }
                    }

                    Button {
                        id: csatlakozGomb
                        Layout.fillWidth: true
                        implicitHeight: 44
                        text: root.t.connect
                        enabled: root.ssid !== "" && (!root.jelszoKell || jelszoMezo.text !== "") && !root.csatlakozik
                        onClicked: {
                            if (!enabled)
                                return
                            root.sikertelen = false
                            root.csatlakozik = true
                            nm.connectTo(root.ssid, root.jelszoKell ? jelszoMezo.text : "")
                        }
                        background: Rectangle {
                            color: !csatlakozGomb.enabled ? "transparent" : (csatlakozGomb.hovered ? Stilus.zoldHover : Stilus.zold)
                            border.width: csatlakozGomb.enabled ? 0 : 1
                            border.color: Stilus.keret
                        }
                        contentItem: Text {
                            text: csatlakozGomb.text
                            color: csatlakozGomb.enabled ? Stilus.zoldonSzoveg : Stilus.szovegHalvany
                            font.family: Stilus.font
                            font.pixelSize: 14
                            font.weight: Font.DemiBold
                            horizontalAlignment: Text.AlignHCenter
                            verticalAlignment: Text.AlignVCenter
                        }
                    }

                    Text {
                        Layout.fillWidth: true
                        text: root.t.statusLabel + ": " + root.allapotSzoveg()
                        wrapMode: Text.WordWrap
                        color: nm.connected ? Stilus.zold : (root.sikertelen ? Stilus.sarga : Stilus.szovegHalvany)
                        font.family: Stilus.mono
                        font.pixelSize: 12
                    }
                }
            }
        }
    }
}