summaryrefslogtreecommitdiffstats
path: root/basicsuite/launchersettings/WifiGroupBox.qml
blob: 7f47e47ddd0db088d95ef84bf54d72a01488e1f1 (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
/******************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Enterprise Embedded.
**
** $QT_BEGIN_LICENSE:COMM$
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** $QT_END_LICENSE$
**
******************************************************************************/
import QtQuick 2.2
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.0
import B2Qt.Wifi 1.0

ColumnLayout {

    RowLayout {

        Label {
            text: qsTr("Wi-Fi")
            font.pixelSize: engine.titleFontSize() *.8
            Layout.leftMargin: 0
            Layout.preferredWidth: mainLayout.column1Width
        }

        Switch {
            id: wifiOnOffButton
            Layout.bottomMargin: 0

            onCheckedChanged: {
                if (checked && WifiManager.backendState === WifiManager.NotRunning) {
                    WifiManager.start()
                    return
                }

                if (!checked && WifiManager.backendState === WifiManager.Running) {
                    if (networkList.visible)
                        networkList.visible = false
                    WifiManager.stop()
                }
            }

            function updateButtonText(backendState)
            {
                if (backendState === WifiManager.Initializing) {
                    wifiOnOffText.text = qsTr("Initializing...")
                } else if (backendState === WifiManager.Terminating) {
                    wifiOnOffText.text = qsTr("Terminating...")
                } else if (backendState === WifiManager.NotRunning) {
                    wifiOnOffText.text = qsTr("Off")
                    wifiOnOffButton.checked = false
                } else if (backendState === WifiManager.Running) {
                    wifiOnOffText.text = qsTr("On")
                    wifiOnOffButton.checked = true
                }
            }

            Component.onCompleted: updateButtonText(WifiManager.backendState)

            Connections {
                target: WifiManager
                onBackendStateChanged: wifiOnOffButton.updateButtonText(backendState)
            }
        }

        Text {
            id: wifiOnOffText
            font.pixelSize: engine.smallFontSize()
            Layout.leftMargin: mainLayout.width * .05
        }
    }

    Binding {
        target: WifiManager
        property: "scanning"
        value: networkList.visible
    }

    Button {
        id: listNetworksButton
        Layout.leftMargin: mainLayout.column1Width
        Layout.topMargin: engine.mm(6)
        Layout.preferredWidth: mainLayout.width * .4
        visible: WifiManager.backendState === WifiManager.Running
        text: networkList.visible ? qsTr("Hide Wi-Fi networks")
                                  : qsTr("List available Wi-Fi networks")
        onClicked: networkList.visible = !networkList.visible
    }

    WifiNetworkList {
        id: networkList
        implicitHeight: engine.centimeter(7)
        Layout.fillWidth: true
        Layout.leftMargin: mainLayout.column1Width
        visible: false
        clip: true
    }
}