~ken-vandine/ubuntu-system-settings/1_3_deprecations

« back to all changes in this revision

Viewing changes to plugins/hotspot/PageComponent.qml

  • Committer: Ken VanDine
  • Date: 2015-08-21 14:03:29 UTC
  • mfrom: (1496.3.4 ubuntu-system-settings)
  • Revision ID: ken.vandine@canonical.com-20150821140329-o0b6eco9cwe9zfio
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
22
24
import Ubuntu.Components.ListItems 1.3 as ListItem
23
25
import Ubuntu.Components.Popups 1.3
24
26
import Ubuntu.Connectivity 1.0
25
 
import Ubuntu.Settings.Components 0.1 as USC
26
 
import Ubuntu.SystemSettings.Cellular 1.0
 
27
 
 
28
/* This is a temporary solution to the issue of Hotspots failing on mako. If
 
29
the device is mako, we hide the hotspot entry. Will be removed once lp:1434591
 
30
has been resolved. */
 
31
import Ubuntu.SystemSettings.Update 1.0
27
32
 
28
33
ItemPage {
29
34
 
30
 
    id: hotspot
 
35
    id: root
31
36
    objectName: "hotspotPage"
32
 
 
33
 
    // TRANSLATORS: “Hotspot” is hidden.
34
 
    title: showAllUI ? i18n.tr("Hotspot") : i18n.tr("Wi-Fi hotspot")
35
 
 
36
 
    // We disable the back action while a hotspot is in the process of either
37
 
    // being enabled or disabled.
38
 
    head.backAction: Action {
39
 
        iconName: "back"
40
 
        enabled: !Connectivity.unstoppableOperationHappening
41
 
        onTriggered: {
42
 
            pageStack.pop();
 
37
    title: i18n.tr("Hotspot")
 
38
 
 
39
    states: [
 
40
        State {
 
41
            name: "disabled"
 
42
            // Undefined WifiEnabled means Connectivity is unavailable.
 
43
            // Disable for mako (see lp:1434591).
 
44
            when: (typeof Connectivity.wifiEnabled === "undefined" ||
 
45
                   UpdateManager.deviceName === "mako") ||
 
46
                   Connectivity.FlightMode
 
47
            PropertyChanges {
 
48
                target: hotspotItem
 
49
                enabled: false
 
50
            }
 
51
            PropertyChanges {
 
52
                target: hotspotSetupButton
 
53
                enabled: false
 
54
            }
 
55
        },
 
56
        State {
 
57
            name: "nowifi"
 
58
            when: Connectivity.wifiEnabled === false
 
59
            PropertyChanges {
 
60
                target: hotspotSwitchWhenWifiDisabled
 
61
                visible: true
 
62
            }
43
63
        }
44
 
    }
 
64
    ]
45
65
 
46
66
    Loader {
47
67
        id: setup
48
68
        asynchronous: false
49
69
    }
50
70
 
51
 
    Column {
 
71
    Flickable {
 
72
        id: flick
52
73
 
53
74
        anchors.fill: parent
54
 
        spacing: units.gu(2)
55
 
 
56
 
        ListItem.Standard {
57
 
            text: i18n.tr("Hotspot")
58
 
            enabled: Connectivity.hotspotStored
59
 
            control: Switch {
60
 
                id: hotspotSwitch
61
 
                objectName: "hotspotSwitch"
62
 
                enabled: !switchSync.syncWaiting
63
 
 
64
 
                USC.ServerPropertySynchroniser {
65
 
                    id: switchSync
66
 
                    userTarget: hotspotSwitch
67
 
                    userProperty: "checked"
68
 
                    serverTarget: Connectivity
69
 
                    serverProperty: "hotspotEnabled"
70
 
                    useWaitBuffer: true
71
 
 
72
 
                    // Since this blocks the UI thread, we wait until
73
 
                    // the UI has completed the checkbox animation before we
74
 
                    // ask the server to uipdate.
75
 
                    onSyncTriggered: {
76
 
                        triggerTimer.value = value;
77
 
                        triggerTimer.start();
78
 
                    }
79
 
                }
80
 
 
81
 
                Timer {
82
 
                    id: triggerTimer
83
 
                    property bool value
84
 
                    interval: 250; repeat: false
85
 
                    onTriggered: Connectivity.hotspotEnabled = value
86
 
                }
87
 
            }
88
 
        }
89
 
 
90
 
        ListItem.Caption {
 
75
        contentWidth: parent.width
 
76
        contentHeight: contentItem.childrenRect.height
 
77
        boundsBehavior: (contentHeight > root.height) ?
 
78
            Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
 
79
 
 
80
        Column {
91
81
            anchors {
92
82
                left: parent.left
93
83
                right: parent.right
94
 
                leftMargin: units.gu(2)
95
 
                rightMargin: units.gu(2)
96
 
            }
97
 
            text : hotspotSwitch.stored ?
98
 
              i18n.tr("When hotspot is on, other devices can use your cellular data connection over Wi-Fi. Normal data charges apply.")
99
 
              : i18n.tr("Other devices can use your cellular data connection over the Wi-Fi network. Normal data charges apply.")
 
84
            }
 
85
            spacing: units.gu(1)
 
86
 
 
87
            ListItem.Standard {
 
88
                id: hotspotItem
 
89
                text: i18n.tr("Hotspot")
 
90
                enabled: Connectivity.hotspotStored
 
91
                onClicked: hotspotSwitch.trigger()
 
92
                control: Switch {
 
93
                    id: hotspotSwitch
 
94
                    objectName: "hotspotSwitch"
 
95
                    enabled: parent.enabled
 
96
                    checked: Connectivity.hotspotEnabled
 
97
                    onTriggered: Connectivity.hotspotEnabled = checked
 
98
 
 
99
                    // Catch taps if Wi-Fi is disable and prompt user.
 
100
                    MouseArea {
 
101
                        id: hotspotSwitchWhenWifiDisabled
 
102
                        anchors.fill: parent
 
103
                        visible: false
 
104
                        onClicked: enableWifiAction.diag = PopupUtils.open(
 
105
                            enableWifiDialog
 
106
                        );
 
107
                    }
 
108
                }
 
109
            }
 
110
 
 
111
            ListItem.Caption {
 
112
                anchors {
 
113
                    left: parent.left
 
114
                    right: parent.right
 
115
                }
 
116
                text : Connectivity.hotspotStored ?
 
117
                  i18n.tr("When hotspot is on, other devices can use your cellular data connection over Wi-Fi. Normal data charges apply.")
 
118
                  : i18n.tr("Other devices can use your cellular data connection over the Wi-Fi network. Normal data charges apply.")
 
119
            }
 
120
 
 
121
            Button {
 
122
                id: hotspotSetupButton
 
123
                objectName: "hotspotSetupButton"
 
124
                anchors.horizontalCenter: parent.horizontalCenter
 
125
                width: parent.width - units.gu(4)
 
126
                text: Connectivity.hotspotStored ?
 
127
                    i18n.tr("Change password/setup…") : i18n.tr("Set up hotspot…")
 
128
                onClicked: {
 
129
                    setup.setSource(Qt.resolvedUrl("HotspotSetup.qml"));
 
130
                    PopupUtils.open(setup.item, root, {});
 
131
                }
 
132
            }
100
133
        }
101
 
 
102
 
        Button {
103
 
            objectName: "hotspotSetupEntry"
104
 
            anchors.horizontalCenter: parent.horizontalCenter
105
 
            width: parent.width - units.gu(4)
106
 
            text: Connectivity.hotspotStored ?
107
 
                i18n.tr("Change password/setup…") : i18n.tr("Set up hotspot…")
108
 
 
109
 
            onClicked: {
110
 
                setup.setSource(Qt.resolvedUrl("HotspotSetup.qml"));
111
 
                PopupUtils.open(setup.item, hotspot, {
112
 
                });
 
134
    }
 
135
 
 
136
    Action {
 
137
        id: enableWifiAction
 
138
        property var diag
 
139
        onTriggered: {
 
140
            // As soon as Wi-Fi has been turned on, enable the hotspot.
 
141
            function wifiUpdated (updated) {
 
142
                Connectivity.wifiEnabledUpdated.disconnect(wifiUpdated);
 
143
                Connectivity.hotspotEnabled = true;
 
144
                PopupUtils.close(diag);
113
145
            }
 
146
 
 
147
            Connectivity.wifiEnabledUpdated.connect(wifiUpdated);
 
148
            hotspotSwitch.checked = true;
 
149
            Connectivity.wifiEnabled = true;
114
150
        }
115
151
    }
116
152
 
119
155
        Dialog {
120
156
            id: dialogue
121
157
            objectName: "enableWifiDialog"
122
 
            // TRANSLATORS: This string is hidden.
123
158
            title: i18n.tr("Wi-Fi is off")
124
 
            // TRANSLATORS: This string is hidden.
125
159
            text: i18n.tr("In order to create a hotspot, you need to turn Wi-Fi on.")
126
 
            visible: showAllUI
127
160
 
128
161
            Button {
129
162
                text: i18n.tr("Cancel")
132
165
 
133
166
            Button {
134
167
                objectName: "confirmEnable"
135
 
                // TRANSLATORS: This string is hidden.
136
168
                text: i18n.tr("Turn on Wi-Fi")
 
169
                onClicked: enableWifiAction.trigger()
137
170
            }
138
171
        }
139
172
    }
 
173
 
 
174
    Connections {
 
175
        target: Connectivity
 
176
        onHotspotEnabledUpdated: hotspotSwitch.checked = target.hotspotEnabled
 
177
    }
140
178
}