Merge lp:~jonas-drange/ubuntu-system-settings/no-empty-contexts-1433278-rtm into lp:ubuntu-system-settings/rtm-14.09

Proposed by Jonas G. Drange
Status: Merged
Approved by: Ken VanDine
Approved revision: 1006
Merged at revision: 1007
Proposed branch: lp:~jonas-drange/ubuntu-system-settings/no-empty-contexts-1433278-rtm
Merge into: lp:ubuntu-system-settings/rtm-14.09
Prerequisite: lp:~jonas-drange/ubuntu-system-settings/apn-no-overwrite-1415495-rtm
Diff against target: 260 lines (+136/-38)
4 files modified
plugins/cellular/CMakeLists.txt (+1/-0)
plugins/cellular/CustomApnEditor.qml (+70/-10)
plugins/cellular/PageChooseApn.qml (+4/-28)
plugins/cellular/apn.js (+61/-0)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-system-settings/no-empty-contexts-1433278-rtm
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ken VanDine Approve
Review via email: mp+254412@code.launchpad.net

This proposal supersedes a proposal from 2015-03-27.

Commit message

[cellular/apn] no creation of custom contexts on editor exit

Description of the change

What changed:
I moved creation of a new, custom internet context to when the user presses "Activate".

Why did I add apn.js:
I want to move the tons of JavaScript code out of the QML and into a nice, documented collection of helper code.

How to test this:
1. $ /usr/share/ofono/scripts/remove-contexts # removes your contexts. Backup your gprs* files if you want to keep them.

Note: If you have not tweaked APNs, ofono should automatically restore your APNs after you remove them completely (and reboot/restart ofono).

2. Open up the APN editor and press "Custom Internet APN"
3. Immediately press Cancel or even "<"
4. Confirm no new contexts were created.

* /var/lib/ofono/<IMSI>/gprs

To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Clean backport, thanks

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1007. By Jonas G. Drange

merge prerequisite

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/cellular/CMakeLists.txt'
2--- plugins/cellular/CMakeLists.txt 2015-02-05 19:11:36 +0000
3+++ plugins/cellular/CMakeLists.txt 2015-03-30 13:23:54 +0000
4@@ -4,6 +4,7 @@
5 install(FILES settings-cellular.svg DESTINATION ${PLUGIN_MANIFEST_DIR}/icons)
6
7 set(QML_SOURCES
8+ apn.js
9 carriers.js
10 CustomApnEditor.qml
11 PageChooseApn.qml
12
13=== modified file 'plugins/cellular/CustomApnEditor.qml'
14--- plugins/cellular/CustomApnEditor.qml 2015-02-16 13:45:07 +0000
15+++ plugins/cellular/CustomApnEditor.qml 2015-03-30 13:23:54 +0000
16@@ -23,6 +23,7 @@
17 import SystemSettings 1.0
18 import Ubuntu.Components 1.1
19 import Ubuntu.Components.ListItems 1.0 as ListItem
20+import "apn.js" as APN
21
22 ItemPage {
23 objectName: "customapnPage"
24@@ -37,6 +38,9 @@
25 /// work around LP(#1361919)
26 property var activateCb;
27
28+ // Sim qml object
29+ property var sim
30+
31 QtObject {
32 id: d
33 property var typeText : type === "internet" ? i18n.tr("Internet") : i18n.tr("MMS")
34@@ -83,6 +87,12 @@
35 ctx = contexts["internet"]
36 }
37
38+ // We do not have any context yet, we will create one, but not now.
39+ // We create it once the user presses 'Activate'.
40+ if (!ctx) {
41+ return;
42+ }
43+
44 apnName.text = ctx.accessPointName;
45 userName.text = ctx.username;
46 pword.text = ctx.password;
47@@ -277,6 +287,8 @@
48
49 onClicked: {
50 var ctx;
51+ var values;
52+
53 if (d.isMms)
54 ctx = contexts["mms"];
55 else
56@@ -300,23 +312,71 @@
57 pageStack.pop();
58 return;
59 }
60- ctx.accessPointName = apnName.text;
61- ctx.username = userName.text;
62- ctx.password = pword.text;
63+
64+ values = {
65+ 'accessPointName': apnName.text,
66+ 'username': userName.text,
67+ 'password': pword.text
68+ };
69+
70 if (d.isMms) {
71- ctx.messageCenter = mmsc.text;
72+ values['messageCenter'] = mmsc.text;
73 var proxyValue = "";
74 if (proxy.text !== "") {
75 proxyValue = proxy.text;
76 if (port.text !== "")
77 proxyValue = proxyValue + ":" + port.text;
78 }
79- ctx.messageProxy = proxyValue
80- }
81- /// @todo map protocol values
82-
83- activateCb(ctx.type, ctx.contextPath);
84- pageStack.pop();
85+ values['messageProxy'] = proxyValue;
86+ }
87+
88+ // If we are editing an existing context, update
89+ // its values, activate and exit.
90+ if (ctx) {
91+ APN.updateContext(ctx, values);
92+ activateCb(ctx.type, ctx.contextPath);
93+ pageStack.pop();
94+ } else {
95+ // If we do not have a context, create one and defer
96+ // editing it to when it has been created—and we
97+ // will also wait until Ofono has given it a name.
98+ // This is all very async, so we will use connect()
99+ // and dynamic QML.
100+
101+ function addedCustomContext (path) {
102+ // This is a handler for when we add a context
103+ // in the custom apn editor.
104+ // We create a temporary QML object for the
105+ // context like this, until we get the APN
106+ // editor refactored.
107+ // TODO(jgdx): create some kind of libqofono
108+ // objects framework in apn.js
109+ var newCtx = Qt.createQmlObject(
110+ 'import MeeGo.QOfono 0.2;'+
111+ 'OfonoContextConnection {'+
112+ 'contextPath: "'+path+'" }',
113+ root, "apn.js");
114+
115+ // Ofono sets a default name (Internet or MMS).
116+ // We are going to change it to our default name.
117+ newCtx.nameChanged.connect(function (name) {
118+ if (name === "Internet") {
119+ newCtx.name = APN.CUSTOM_INTERNET_CONTEXT_NAME();
120+ APN.updateContext(newCtx, values);
121+ } else if (name === "MMS") {
122+ newCtx.name = APN.CUSTOM_MMS_CONTEXT_NAME();
123+ APN.updateContext(newCtx, values);
124+ } else {
125+ newCtx.destroy(100);
126+ activateCb(newCtx.type, newCtx.contextPath);
127+ pageStack.pop();
128+ }
129+ });
130+ }
131+
132+ sim.connMan.addContext(root.type);
133+ sim.connMan.contextAdded.connect(addedCustomContext);
134+ }
135 }
136 }
137 } // item for buttons
138
139=== modified file 'plugins/cellular/PageChooseApn.qml'
140--- plugins/cellular/PageChooseApn.qml 2015-03-30 13:23:54 +0000
141+++ plugins/cellular/PageChooseApn.qml 2015-03-30 13:23:54 +0000
142@@ -150,10 +150,7 @@
143 });
144 }
145
146- if (customInternet.length === 0) {
147- sim.connMan.addContext("internet");
148- sim.connMan.contextAdded.connect(addedCustomContext);
149- } else {
150+ if (customInternet.length !== 0) {
151 d.__haveCustomContexts = true;
152 }
153
154@@ -239,7 +236,8 @@
155 type: type,
156 contexts: {"internet": mCustomContextInternet,
157 "mms": mCustomContextMms},
158- activateCb: activateHelper
159+ activateCb: activateHelper,
160+ sim: sim
161 });
162 }
163
164@@ -424,29 +422,7 @@
165 objectName: "customApnEdit"
166 text: i18n.tr("Custom Internet APN…")
167 width: parent.width - units.gu(4)
168- onClicked: {
169-
170- function contextAdded (path) {
171- d.updateContexts();
172-
173- if (d.mContexts[path]) {
174- d.mCustomContextInternet = d.mContexts[path];
175- }
176- d.openApnEditor("internet")
177- d.contextsChanged.disconnect(contextAdded);
178- }
179-
180- if (d.__haveCustomContexts) {
181- d.openApnEditor("internet")
182- } else {
183- d.checkAndCreateCustomContexts();
184- d.__haveCustomContexts = true;
185-
186- // We defer opening the editor until we have
187- // added the custom context to mContexts
188- sim.connMan.contextAdded.connect(contextAdded);
189- }
190- }
191+ onClicked: d.openApnEditor("internet")
192 }
193
194 ListItem.ItemSelector {
195
196=== added file 'plugins/cellular/apn.js'
197--- plugins/cellular/apn.js 1970-01-01 00:00:00 +0000
198+++ plugins/cellular/apn.js 2015-03-30 13:23:54 +0000
199@@ -0,0 +1,61 @@
200+var _CUSTOM_INTERNET_CONTEXT_NAME = '___ubuntu_custom_apn_internet';
201+var _CUSTOM_MMS_CONTEXT_NAME = '___ubuntu_custom_apn_mms';
202+
203+/*
204+Updates a context with new values.
205+
206+@param {QOfonoConnectionContext} context
207+@param {Object} values dict with new values
208+*/
209+function updateContext (context, values) {
210+ var messageProxy;
211+ console.warn('updateContext', values.accessPointName, values.messageCenter,
212+ values.messageProxy, values.port, values.useraccessPointName,
213+ values.password, values.type);
214+ if (typeof values.accessPointName !== 'undefined') {
215+ context.accessPointName = values.accessPointName;
216+ }
217+ if (typeof values.messageCenter !== 'undefined') {
218+ context.messageCenter = values.messageCenter;
219+ }
220+ if (typeof values.messageProxy !== 'undefined') {
221+ messageProxy = values.messageProxy;
222+ if (messageProxy !== '') {
223+ messageProxy = messageProxy + ':' + values.port;
224+ }
225+ context.messageProxy = messageProxy;
226+ }
227+ if (typeof values.username !== 'undefined') {
228+ context.username = values.username;
229+ }
230+ if (typeof values.password !== 'undefined') {
231+ context.password = values.password;
232+ }
233+ if (typeof values.type !== 'undefined') {
234+ context.type = values.type;
235+ }
236+
237+ if (context.type === 'internet') {
238+ context.name = CUSTOM_INTERNET_CONTEXT_NAME();
239+ } else if (context.type === 'mms') {
240+ context.name = CUSTOM_MMS_CONTEXT_NAME();
241+ }
242+}
243+
244+/*
245+Exposes the custom internet context name to the world.
246+
247+@return {String} custom internet context name
248+*/
249+function CUSTOM_INTERNET_CONTEXT_NAME () {
250+ return _CUSTOM_INTERNET_CONTEXT_NAME;
251+}
252+
253+/*
254+Exposes the custom mms context name to the world.
255+
256+@return {String} custom mms context name
257+*/
258+function CUSTOM_MMS_CONTEXT_NAME () {
259+ return _CUSTOM_MMS_CONTEXT_NAME;
260+}

Subscribers

People subscribed via source and target branches