~ralsina/ubuntu-system-settings/notification-plugin

« back to all changes in this revision

Viewing changes to plugins/cellular/PageChooseCarrier.qml

  • Committer: Roberto Alsina
  • Date: 2014-07-31 18:32:54 UTC
  • mfrom: (779.1.70 ubuntu-system-settings)
  • Revision ID: roberto.alsina@canonical.com-20140731183254-0dgi0dfspshtolbb
merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import SystemSettings 1.0
23
23
import Ubuntu.Components 0.1
24
24
import Ubuntu.Components.ListItems 0.1 as ListItem
25
 
 
 
25
import MeeGo.QOfono 0.2
26
26
 
27
27
ItemPage {
28
 
    title: i18n.tr("Carrier")
 
28
    title: title
29
29
    objectName: "chooseCarrierPage"
30
30
 
31
31
    property var netReg
32
 
    property variant operators: netReg.operators
33
 
    property bool scanning: netReg.scanning
 
32
    property var operators: []
 
33
    property bool scanning: false
34
34
    property variant operatorNames
35
35
    property variant operatorStatus
36
36
    property int curOp
 
37
    Component.onCompleted: buildLists();
37
38
 
38
 
    onOperatorsChanged: {
39
 
        buildLists();
 
39
    Connections {
 
40
        target: netReg
 
41
        onStatusChanged: {
 
42
            if (netReg.status === "registered")
 
43
                buildLists();
 
44
        }
 
45
        onNetworkOperatorsChanged: buildLists();
 
46
        onScanFinished: scanning = false;
 
47
        onScanError: {
 
48
            scanning = false;
 
49
            console.warn ("onScanError: " + message);
 
50
        }
40
51
    }
41
52
 
42
53
    function buildLists()
43
54
    {
 
55
        var ops = [];
44
56
        var oN = new Array();
45
57
        var oS = new Array();
46
 
        for (var i in operators)
47
 
        {
48
 
            if (operators[i].status == "forbidden")
 
58
        for (var i = 0; i < netReg.networkOperators.length; i++) {
 
59
            var tempOp = netOp.createObject(parent, {"operatorPath": netReg.networkOperators[i]});
 
60
            if (tempOp.status === "forbidden")
49
61
                continue
50
 
            oN.push(operators[i].name);
51
 
            oS.push(operators[i].status);
 
62
            oN.push(tempOp.name);
 
63
            oS.push(tempOp.status);
 
64
            ops.push(tempOp)
52
65
        }
53
66
        curOp = oS.indexOf("current");
54
67
        operatorNames = oN;
55
68
        operatorStatus = oS;
56
 
    }
57
 
 
58
 
   ListItem.ItemSelector {
59
 
        id: carrierSelector
60
 
        objectName: "carrierSelector"
61
 
        expanded: true
62
 
        /* FIXME: This is disabled since it is currently a
63
 
         * read-only setting
64
 
         * enabled: cellularDataControl.checked
65
 
         */
66
 
        enabled: true
67
 
        model: operatorNames
68
 
        selectedIndex: curOp
69
 
        onSelectedIndexChanged: {
70
 
            operators[selectedIndex].registerOp();
71
 
        }
72
 
    }
73
 
 
74
 
    ListItem.SingleControl {
75
 
        anchors.bottom: parent.bottom
76
 
        control: Button {
77
 
            objectName: "refreshButton"
78
 
            width: parent.width - units.gu(4)
79
 
            text: i18n.tr("Refresh")
80
 
            onTriggered: netReg.scan()
81
 
        }
82
 
    }
83
 
 
84
 
    ActivityIndicator {
85
 
        id: activityIndicator
86
 
        anchors.centerIn: parent
87
 
        running: scanning
88
 
    }
89
 
 
90
 
    Label {
91
 
        anchors {
92
 
            top: activityIndicator.bottom
93
 
            topMargin: units.gu(2)
94
 
            horizontalCenter: activityIndicator.horizontalCenter
95
 
        }
96
 
        text: i18n.tr("Searching")
97
 
        visible: activityIndicator.running
 
69
        operators = ops;
 
70
        carrierSelector.selectedIndex = curOp;
 
71
    }
 
72
 
 
73
    Component {
 
74
        id: netOp
 
75
        OfonoNetworkOperator {
 
76
            onRegisterComplete: {
 
77
                if (error === OfonoNetworkOperator.InProgressError) {
 
78
                    console.warn("registerComplete failed with error: " + errorString);
 
79
                } else if (error !== OfonoNetworkOperator.NoError) {
 
80
                    console.warn("registerComplete failed with error: " + errorString + " Falling back to default");
 
81
                    netReg.registration();
 
82
                }
 
83
            }
 
84
        }
 
85
    }
 
86
 
 
87
    Flickable {
 
88
        anchors.fill: parent
 
89
        contentWidth: parent.width
 
90
        contentHeight: parent.height
 
91
        boundsBehavior: (contentHeight > parent.height) ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
 
92
 
 
93
        Column {
 
94
            anchors.left: parent.left
 
95
            anchors.right: parent.right
 
96
 
 
97
            ListItem.ItemSelector {
 
98
                id: chooseCarrier
 
99
                objectName: "autoChooseCarrierSelector"
 
100
                expanded: true
 
101
                enabled: netReg.mode !== "auto-only"
 
102
                text: i18n.tr("Choose carrier:")
 
103
                model: [i18n.tr("Automatically"), i18n.tr("Manually")]
 
104
                selectedIndex: netReg.mode === "manual" ? 1 : 0
 
105
                onSelectedIndexChanged: {
 
106
                    if (selectedIndex === 0)
 
107
                        netReg.registration();
 
108
                }
 
109
            }
 
110
 
 
111
            ListItem.ItemSelector {
 
112
                id: carrierSelector
 
113
                objectName: "carrierSelector"
 
114
                expanded: enabled
 
115
                enabled: chooseCarrier.selectedIndex === 1
 
116
                model: operatorNames
 
117
                onSelectedIndexChanged: {
 
118
                    if ((selectedIndex !== curOp) && operators[selectedIndex]) {
 
119
                        operators[selectedIndex].registerOperator();
 
120
                    }
 
121
                }
 
122
            }
 
123
        }
 
124
 
 
125
        ListItem.SingleControl {
 
126
            anchors.bottom: parent.bottom
 
127
            control: Button {
 
128
                objectName: "refreshButton"
 
129
                width: parent.width - units.gu(4)
 
130
                text: i18n.tr("Refresh")
 
131
                enabled: (netReg.status !== "searching") && (netReg.status !== "denied")
 
132
                onTriggered: {
 
133
                    scanning = true;
 
134
                    netReg.scan();
 
135
                }
 
136
            }
 
137
        }
 
138
 
 
139
        ActivityIndicator {
 
140
            id: activityIndicator
 
141
            anchors.centerIn: parent
 
142
            running: scanning
 
143
        }
 
144
 
 
145
        Label {
 
146
            anchors {
 
147
                top: activityIndicator.bottom
 
148
                topMargin: units.gu(2)
 
149
                horizontalCenter: activityIndicator.horizontalCenter
 
150
            }
 
151
            text: i18n.tr("Searching")
 
152
            visible: activityIndicator.running
 
153
        }
98
154
    }
99
155
}