~jonas-drange/ubuntu-system-settings/hotspots

« back to all changes in this revision

Viewing changes to plugins/cellular/Hotspot.qml

  • Committer: jonas-drange
  • Date: 2015-07-31 15:03:10 UTC
  • mfrom: (1312.3.75 hotspots-binding)
  • Revision ID: jonas.drange@canonical.com-20150731150310-21t62nsd2zhd62jm
bzr merge lp:~jonas-drange/ubuntu-system-settings/hotspots-binding

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import SystemSettings 1.0
21
21
import Ubuntu.Components 0.1
22
22
import Ubuntu.Components.ListItems 0.1 as ListItem
 
23
import Ubuntu.Components.Popups 0.1
 
24
import Ubuntu.Settings.Components 0.1 as USC
23
25
import Ubuntu.SystemSettings.Cellular 1.0
24
26
 
25
27
ItemPage {
26
28
 
27
29
    id: hotspot
 
30
    objectName: "hotspotPage"
28
31
 
29
32
    title: i18n.tr("Wi-Fi hotspot")
30
33
 
 
34
    // We disable the back action while a hotspot is in the process of either
 
35
    // being enabled or disabled.
 
36
    head.backAction: Action {
 
37
        iconName: "back"
 
38
        enabled: hotspotSwitch.enabled
 
39
        onTriggered: {
 
40
            pageStack.pop();
 
41
        }
 
42
    }
 
43
 
31
44
    HotspotManager {
32
45
        id: hotspotManager
33
46
    }
34
47
 
 
48
    Loader {
 
49
        id: setup
 
50
        asynchronous: false
 
51
    }
 
52
 
35
53
    Column {
36
54
 
37
55
        anchors.fill: parent
 
56
        spacing: units.gu(2)
38
57
 
39
58
        ListItem.Standard {
40
59
            text: i18n.tr("Hotspot")
 
60
            enabled: hotspotManager.stored
41
61
            control: Switch {
42
62
                id: hotspotSwitch
43
 
                checked: hotspotManager.isHotspotActive()
44
 
                onTriggered: {
45
 
                    if(checked) {
46
 
                        hotspotManager.enableHotspot()
47
 
                    } else {
48
 
                        hotspotManager.disableHotspot()
 
63
                objectName: "hotspotSwitch"
 
64
                enabled: !switchSync.syncWaiting
 
65
 
 
66
                USC.ServerPropertySynchroniser {
 
67
                    id: switchSync
 
68
                    userTarget: hotspotSwitch
 
69
                    userProperty: "checked"
 
70
                    serverTarget: hotspotManager
 
71
                    serverProperty: "enabled"
 
72
                    useWaitBuffer: true
 
73
 
 
74
                    // Since this blocks the UI thread, we wait until
 
75
                    // the UI has completed the checkbox animation before we
 
76
                    // ask the server to uipdate.
 
77
                    onSyncTriggered: {
 
78
                        triggerTimer.value = value;
 
79
                        triggerTimer.start();
49
80
                    }
50
81
                }
 
82
 
 
83
                Timer {
 
84
                    id: triggerTimer
 
85
                    property bool value
 
86
                    interval: 250; repeat: false
 
87
                    onTriggered: hotspotManager.enabled = value
 
88
                }
51
89
            }
52
90
        }
53
91
 
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 ?
 
92
        ListItem.Caption {
 
93
            anchors {
 
94
                left: parent.left
 
95
                right: parent.right
 
96
                leftMargin: units.gu(2)
 
97
                rightMargin: units.gu(2)
 
98
            }
 
99
            text : hotspotSwitch.stored ?
60
100
              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.") 
 
101
              : i18n.tr("Other devices can use your cellular data connection over the Wi-Fi network. Normal data charges apply.")
62
102
        }
63
103
 
64
104
        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)
 
105
            objectName: "hotspotSetupEntry"
 
106
            anchors.horizontalCenter: parent.horizontalCenter
 
107
            width: parent.width - units.gu(4)
 
108
            text: hotspotManager.stored ?
 
109
                i18n.tr("Change password/setup…") : i18n.tr("Set up hotspot…")
 
110
 
70
111
            onClicked: {
71
 
                pageStack.push(Qt.resolvedUrl("HotspotSetup.qml"), {hotspotManager: hotspotManager})
 
112
                setup.setSource(Qt.resolvedUrl("HotspotSetup.qml"));
 
113
                PopupUtils.open(setup.item, hotspot, {
 
114
                    hotspotManager: hotspotManager
 
115
                });
72
116
            }
73
117
        }
74
 
 
75
118
    }
76
119
}