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
=== modified file 'plugins/cellular/CMakeLists.txt'
--- plugins/cellular/CMakeLists.txt 2015-02-05 19:11:36 +0000
+++ plugins/cellular/CMakeLists.txt 2015-03-30 13:23:54 +0000
@@ -4,6 +4,7 @@
4install(FILES settings-cellular.svg DESTINATION ${PLUGIN_MANIFEST_DIR}/icons)4install(FILES settings-cellular.svg DESTINATION ${PLUGIN_MANIFEST_DIR}/icons)
55
6set(QML_SOURCES6set(QML_SOURCES
7 apn.js
7 carriers.js8 carriers.js
8 CustomApnEditor.qml9 CustomApnEditor.qml
9 PageChooseApn.qml10 PageChooseApn.qml
1011
=== modified file 'plugins/cellular/CustomApnEditor.qml'
--- plugins/cellular/CustomApnEditor.qml 2015-02-16 13:45:07 +0000
+++ plugins/cellular/CustomApnEditor.qml 2015-03-30 13:23:54 +0000
@@ -23,6 +23,7 @@
23import SystemSettings 1.023import SystemSettings 1.0
24import Ubuntu.Components 1.124import Ubuntu.Components 1.1
25import Ubuntu.Components.ListItems 1.0 as ListItem25import Ubuntu.Components.ListItems 1.0 as ListItem
26import "apn.js" as APN
2627
27ItemPage {28ItemPage {
28 objectName: "customapnPage"29 objectName: "customapnPage"
@@ -37,6 +38,9 @@
37 /// work around LP(#1361919)38 /// work around LP(#1361919)
38 property var activateCb;39 property var activateCb;
3940
41 // Sim qml object
42 property var sim
43
40 QtObject {44 QtObject {
41 id: d45 id: d
42 property var typeText : type === "internet" ? i18n.tr("Internet") : i18n.tr("MMS")46 property var typeText : type === "internet" ? i18n.tr("Internet") : i18n.tr("MMS")
@@ -83,6 +87,12 @@
83 ctx = contexts["internet"]87 ctx = contexts["internet"]
84 }88 }
8589
90 // We do not have any context yet, we will create one, but not now.
91 // We create it once the user presses 'Activate'.
92 if (!ctx) {
93 return;
94 }
95
86 apnName.text = ctx.accessPointName;96 apnName.text = ctx.accessPointName;
87 userName.text = ctx.username;97 userName.text = ctx.username;
88 pword.text = ctx.password;98 pword.text = ctx.password;
@@ -277,6 +287,8 @@
277287
278 onClicked: {288 onClicked: {
279 var ctx;289 var ctx;
290 var values;
291
280 if (d.isMms)292 if (d.isMms)
281 ctx = contexts["mms"];293 ctx = contexts["mms"];
282 else294 else
@@ -300,23 +312,71 @@
300 pageStack.pop();312 pageStack.pop();
301 return;313 return;
302 }314 }
303 ctx.accessPointName = apnName.text;315
304 ctx.username = userName.text;316 values = {
305 ctx.password = pword.text;317 'accessPointName': apnName.text,
318 'username': userName.text,
319 'password': pword.text
320 };
321
306 if (d.isMms) {322 if (d.isMms) {
307 ctx.messageCenter = mmsc.text;323 values['messageCenter'] = mmsc.text;
308 var proxyValue = "";324 var proxyValue = "";
309 if (proxy.text !== "") {325 if (proxy.text !== "") {
310 proxyValue = proxy.text;326 proxyValue = proxy.text;
311 if (port.text !== "")327 if (port.text !== "")
312 proxyValue = proxyValue + ":" + port.text;328 proxyValue = proxyValue + ":" + port.text;
313 }329 }
314 ctx.messageProxy = proxyValue330 values['messageProxy'] = proxyValue;
315 }331 }
316 /// @todo map protocol values332
317333 // If we are editing an existing context, update
318 activateCb(ctx.type, ctx.contextPath);334 // its values, activate and exit.
319 pageStack.pop();335 if (ctx) {
336 APN.updateContext(ctx, values);
337 activateCb(ctx.type, ctx.contextPath);
338 pageStack.pop();
339 } else {
340 // If we do not have a context, create one and defer
341 // editing it to when it has been created—and we
342 // will also wait until Ofono has given it a name.
343 // This is all very async, so we will use connect()
344 // and dynamic QML.
345
346 function addedCustomContext (path) {
347 // This is a handler for when we add a context
348 // in the custom apn editor.
349 // We create a temporary QML object for the
350 // context like this, until we get the APN
351 // editor refactored.
352 // TODO(jgdx): create some kind of libqofono
353 // objects framework in apn.js
354 var newCtx = Qt.createQmlObject(
355 'import MeeGo.QOfono 0.2;'+
356 'OfonoContextConnection {'+
357 'contextPath: "'+path+'" }',
358 root, "apn.js");
359
360 // Ofono sets a default name (Internet or MMS).
361 // We are going to change it to our default name.
362 newCtx.nameChanged.connect(function (name) {
363 if (name === "Internet") {
364 newCtx.name = APN.CUSTOM_INTERNET_CONTEXT_NAME();
365 APN.updateContext(newCtx, values);
366 } else if (name === "MMS") {
367 newCtx.name = APN.CUSTOM_MMS_CONTEXT_NAME();
368 APN.updateContext(newCtx, values);
369 } else {
370 newCtx.destroy(100);
371 activateCb(newCtx.type, newCtx.contextPath);
372 pageStack.pop();
373 }
374 });
375 }
376
377 sim.connMan.addContext(root.type);
378 sim.connMan.contextAdded.connect(addedCustomContext);
379 }
320 }380 }
321 }381 }
322 } // item for buttons382 } // item for buttons
323383
=== modified file 'plugins/cellular/PageChooseApn.qml'
--- plugins/cellular/PageChooseApn.qml 2015-03-30 13:23:54 +0000
+++ plugins/cellular/PageChooseApn.qml 2015-03-30 13:23:54 +0000
@@ -150,10 +150,7 @@
150 });150 });
151 }151 }
152152
153 if (customInternet.length === 0) {153 if (customInternet.length !== 0) {
154 sim.connMan.addContext("internet");
155 sim.connMan.contextAdded.connect(addedCustomContext);
156 } else {
157 d.__haveCustomContexts = true;154 d.__haveCustomContexts = true;
158 }155 }
159156
@@ -239,7 +236,8 @@
239 type: type,236 type: type,
240 contexts: {"internet": mCustomContextInternet,237 contexts: {"internet": mCustomContextInternet,
241 "mms": mCustomContextMms},238 "mms": mCustomContextMms},
242 activateCb: activateHelper239 activateCb: activateHelper,
240 sim: sim
243 });241 });
244 }242 }
245243
@@ -424,29 +422,7 @@
424 objectName: "customApnEdit"422 objectName: "customApnEdit"
425 text: i18n.tr("Custom Internet APN…")423 text: i18n.tr("Custom Internet APN…")
426 width: parent.width - units.gu(4)424 width: parent.width - units.gu(4)
427 onClicked: {425 onClicked: d.openApnEditor("internet")
428
429 function contextAdded (path) {
430 d.updateContexts();
431
432 if (d.mContexts[path]) {
433 d.mCustomContextInternet = d.mContexts[path];
434 }
435 d.openApnEditor("internet")
436 d.contextsChanged.disconnect(contextAdded);
437 }
438
439 if (d.__haveCustomContexts) {
440 d.openApnEditor("internet")
441 } else {
442 d.checkAndCreateCustomContexts();
443 d.__haveCustomContexts = true;
444
445 // We defer opening the editor until we have
446 // added the custom context to mContexts
447 sim.connMan.contextAdded.connect(contextAdded);
448 }
449 }
450 }426 }
451427
452 ListItem.ItemSelector {428 ListItem.ItemSelector {
453429
=== added file 'plugins/cellular/apn.js'
--- plugins/cellular/apn.js 1970-01-01 00:00:00 +0000
+++ plugins/cellular/apn.js 2015-03-30 13:23:54 +0000
@@ -0,0 +1,61 @@
1var _CUSTOM_INTERNET_CONTEXT_NAME = '___ubuntu_custom_apn_internet';
2var _CUSTOM_MMS_CONTEXT_NAME = '___ubuntu_custom_apn_mms';
3
4/*
5Updates a context with new values.
6
7@param {QOfonoConnectionContext} context
8@param {Object} values dict with new values
9*/
10function updateContext (context, values) {
11 var messageProxy;
12 console.warn('updateContext', values.accessPointName, values.messageCenter,
13 values.messageProxy, values.port, values.useraccessPointName,
14 values.password, values.type);
15 if (typeof values.accessPointName !== 'undefined') {
16 context.accessPointName = values.accessPointName;
17 }
18 if (typeof values.messageCenter !== 'undefined') {
19 context.messageCenter = values.messageCenter;
20 }
21 if (typeof values.messageProxy !== 'undefined') {
22 messageProxy = values.messageProxy;
23 if (messageProxy !== '') {
24 messageProxy = messageProxy + ':' + values.port;
25 }
26 context.messageProxy = messageProxy;
27 }
28 if (typeof values.username !== 'undefined') {
29 context.username = values.username;
30 }
31 if (typeof values.password !== 'undefined') {
32 context.password = values.password;
33 }
34 if (typeof values.type !== 'undefined') {
35 context.type = values.type;
36 }
37
38 if (context.type === 'internet') {
39 context.name = CUSTOM_INTERNET_CONTEXT_NAME();
40 } else if (context.type === 'mms') {
41 context.name = CUSTOM_MMS_CONTEXT_NAME();
42 }
43}
44
45/*
46Exposes the custom internet context name to the world.
47
48@return {String} custom internet context name
49*/
50function CUSTOM_INTERNET_CONTEXT_NAME () {
51 return _CUSTOM_INTERNET_CONTEXT_NAME;
52}
53
54/*
55Exposes the custom mms context name to the world.
56
57@return {String} custom mms context name
58*/
59function CUSTOM_MMS_CONTEXT_NAME () {
60 return _CUSTOM_MMS_CONTEXT_NAME;
61}

Subscribers

People subscribed via source and target branches