~system-settings-touch/ubuntu-system-settings/15.04

« back to all changes in this revision

Viewing changes to plugins/hotspot/PageComponent.qml

merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * This file is part of system-settings
3
3
 *
4
 
 * Copyright (C) 2014 Canonical Ltd.
 
4
 * Copyright (C) 2014-2015 Canonical Ltd.
 
5
 *
 
6
 * Contact: Jonas G. Drange <jonas.drange@canonical.com>
5
7
 *
6
8
 * This program is free software: you can redistribute it and/or modify it
7
9
 * under the terms of the GNU General Public License version 3, as published
20
22
import SystemSettings 1.0
21
23
import Ubuntu.Components 0.1
22
24
import Ubuntu.Components.ListItems 0.1 as ListItem
23
 
import Ubuntu.SystemSettings.Cellular 1.0
 
25
import Ubuntu.Components.Popups 0.1
 
26
import Ubuntu.Connectivity 1.0
24
27
 
25
28
ItemPage {
26
29
 
27
 
    id: hotspot
28
 
 
29
 
    title: i18n.tr("Wi-Fi hotspot")
30
 
 
31
 
    HotspotManager {
32
 
        id: hotspotManager
 
30
    id: root
 
31
    objectName: "hotspotPage"
 
32
    title: i18n.tr("Hotspot")
 
33
 
 
34
    states: [
 
35
        State {
 
36
            name: "disabled"
 
37
            // Undefined WifiEnabled means Connectivity is unavailable.
 
38
            when: typeof Connectivity.wifiEnabled === "undefined" ||
 
39
                  Connectivity.FlightMode
 
40
            PropertyChanges {
 
41
                target: hotspotItem
 
42
                enabled: false
 
43
            }
 
44
            PropertyChanges {
 
45
                target: hotspotSetupButton
 
46
                enabled: false
 
47
            }
 
48
        },
 
49
        State {
 
50
            name: "nowifi"
 
51
            when: Connectivity.wifiEnabled === false
 
52
            PropertyChanges {
 
53
                target: hotspotSwitchWhenWifiDisabled
 
54
                visible: true
 
55
            }
 
56
        }
 
57
    ]
 
58
 
 
59
    Loader {
 
60
        id: setup
 
61
        asynchronous: false
33
62
    }
34
63
 
35
 
    Column {
 
64
    Flickable {
 
65
        id: flick
36
66
 
37
67
        anchors.fill: parent
38
 
 
39
 
        ListItem.Standard {
40
 
            text: i18n.tr("Hotspot")
41
 
            control: Switch {
42
 
                id: hotspotSwitch
43
 
                checked: hotspotManager.isHotspotActive()
44
 
                onTriggered: {
45
 
                    if(checked) {
46
 
                        hotspotManager.enableHotspot()
47
 
                    } else {
48
 
                        hotspotManager.disableHotspot()
 
68
        contentWidth: parent.width
 
69
        contentHeight: contentItem.childrenRect.height
 
70
        boundsBehavior: (contentHeight > root.height) ?
 
71
            Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
 
72
 
 
73
        Column {
 
74
            anchors {
 
75
                left: parent.left
 
76
                right: parent.right
 
77
            }
 
78
            spacing: units.gu(1)
 
79
 
 
80
            ListItem.Standard {
 
81
                id: hotspotItem
 
82
                text: i18n.tr("Hotspot")
 
83
                enabled: Connectivity.hotspotStored
 
84
                onClicked: hotspotSwitch.trigger()
 
85
                control: Switch {
 
86
                    id: hotspotSwitch
 
87
                    objectName: "hotspotSwitch"
 
88
                    enabled: parent.enabled
 
89
                    checked: Connectivity.hotspotEnabled
 
90
                    onTriggered: Connectivity.hotspotEnabled = checked
 
91
 
 
92
                    // Catch taps if Wi-Fi is disable and prompt user.
 
93
                    MouseArea {
 
94
                        id: hotspotSwitchWhenWifiDisabled
 
95
                        anchors.fill: parent
 
96
                        visible: false
 
97
                        onClicked: enableWifiAction.diag = PopupUtils.open(
 
98
                            enableWifiDialog
 
99
                        );
49
100
                    }
50
101
                }
51
102
            }
52
 
        }
53
 
 
54
 
        Label {
55
 
            width: parent.width
56
 
            wrapMode: Text.WordWrap
57
 
            anchors.leftMargin: units.gu(2)
58
 
            anchors.rightMargin: units.gu(2)
59
 
            text : hotspotSwitch.enabled ?
60
 
              i18n.tr("When hotspot is on, other devices can use your cellular data connection over Wi-Fi. Normal data charges apply.")
61
 
              : i18n.tr("Other devices can use your cellular data connection over the Wi-Fi network. Normal data charges apply.") 
62
 
        }
63
 
 
64
 
        Button {
65
 
            text: i18n.tr("Set up hotspot")
66
 
            anchors.left: parent.left
67
 
            anchors.right: parent.right
68
 
            anchors.leftMargin: units.gu(2)
69
 
            anchors.rightMargin: units.gu(2)
70
 
            onClicked: {
71
 
                pageStack.push(Qt.resolvedUrl("HotspotSetup.qml"), {hotspotManager: hotspotManager})
72
 
            }
73
 
        }
74
 
 
 
103
 
 
104
            ListItem.Caption {
 
105
                anchors {
 
106
                    left: parent.left
 
107
                    right: parent.right
 
108
                }
 
109
                text : Connectivity.hotspotStored ?
 
110
                  i18n.tr("When hotspot is on, other devices can use your cellular data connection over Wi-Fi. Normal data charges apply.")
 
111
                  : i18n.tr("Other devices can use your cellular data connection over the Wi-Fi network. Normal data charges apply.")
 
112
            }
 
113
 
 
114
            Button {
 
115
                id: hotspotSetupButton
 
116
                objectName: "hotspotSetupButton"
 
117
                anchors.horizontalCenter: parent.horizontalCenter
 
118
                width: parent.width - units.gu(4)
 
119
                text: Connectivity.hotspotStored ?
 
120
                    i18n.tr("Change Password/Setup…") : i18n.tr("Set Up Hotspot…")
 
121
                onClicked: {
 
122
                    setup.setSource(Qt.resolvedUrl("HotspotSetup.qml"));
 
123
                    PopupUtils.open(setup.item, root, {});
 
124
                }
 
125
            }
 
126
        }
 
127
    }
 
128
 
 
129
    Action {
 
130
        id: enableWifiAction
 
131
        property var diag
 
132
        onTriggered: {
 
133
            // As soon as Wi-Fi has been turned on, enable the hotspot.
 
134
            function wifiUpdated (updated) {
 
135
                Connectivity.wifiEnabledUpdated.disconnect(wifiUpdated);
 
136
                Connectivity.hotspotEnabled = true;
 
137
                PopupUtils.close(diag);
 
138
            }
 
139
 
 
140
            Connectivity.wifiEnabledUpdated.connect(wifiUpdated);
 
141
            hotspotSwitch.checked = true;
 
142
            Connectivity.wifiEnabled = true;
 
143
        }
 
144
    }
 
145
 
 
146
    Component {
 
147
        id: enableWifiDialog
 
148
        Dialog {
 
149
            id: dialogue
 
150
            objectName: "enableWifiDialog"
 
151
            title: i18n.tr("Wi-Fi is off")
 
152
            text: i18n.tr("In order to create a hotspot, you need to turn Wi-Fi on.")
 
153
 
 
154
            Button {
 
155
                text: i18n.tr("Cancel")
 
156
                onClicked: PopupUtils.close(dialogue)
 
157
            }
 
158
 
 
159
            Button {
 
160
                objectName: "confirmEnable"
 
161
                text: i18n.tr("Turn on Wi-Fi")
 
162
                onClicked: enableWifiAction.trigger()
 
163
            }
 
164
        }
 
165
    }
 
166
 
 
167
    Connections {
 
168
        target: Connectivity
 
169
        onHotspotEnabledUpdated: hotspotSwitch.checked = target.hotspotEnabled
75
170
    }
76
171
}