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: Superseded
Proposed branch: lp:~jonas-drange/ubuntu-system-settings/no-empty-contexts-1433278-rtm
Merge into: lp:ubuntu-system-settings/rtm-14.09
Diff against target: 331 lines (+158/-54)
4 files modified
plugins/cellular/CMakeLists.txt (+1/-0)
plugins/cellular/CustomApnEditor.qml (+70/-10)
plugins/cellular/PageChooseApn.qml (+26/-44)
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
Ubuntu Touch System Settings Pending
Review via email: mp+254410@code.launchpad.net

This proposal has been superseded by 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.
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.
1007. By Jonas G. Drange

merge prerequisite

Unmerged revisions

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-27 15:30:10 +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-27 15:30:10 +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-02-16 13:45:07 +0000
141+++ plugins/cellular/PageChooseApn.qml 2015-03-27 15:30:10 +0000
142@@ -52,31 +52,6 @@
143 property bool __suppressActivation : true;
144 property bool __haveCustomContexts : false;
145
146- function isEmptyCustom (type, ctx)
147- {
148- /* OK, this sucks _hard_,
149- * QOfono does not return the added context, so instead we have to "figure it out"
150- * by looking for "contextAdded" for totally empty context with default Name values.
151- * LP(#1361864)
152- */
153-
154- var targetName = "";
155- var targetAccessPointName = "";
156- if (type === "internet") {
157- targetName = "Internet";
158- targetAccessPointName = "";
159- } else if (type == "mms") {
160- targetName = "MMS";
161- targetAccessPointName = "";
162- }
163-
164- if (ctx.type === type &&
165- ctx.name === targetName &&
166- ctx.accessPointName === targetAccessPointName)
167- return true;
168- return false;
169- }
170-
171 function updateContexts(contexts)
172 {
173 var tmp = contexts || sim.connMan.contexts.slice(0);
174@@ -113,7 +88,6 @@
175 if (mContexts[currentValue] !== undefined) {
176 throw "updateContexts: added is broken";
177 }
178-
179 var ctx = connCtx.createObject(parent,
180 {
181 "contextPath": currentValue
182@@ -138,15 +112,26 @@
183
184 // expects updateContexts() to have ran before executing.
185 function checkAndCreateCustomContexts() {
186+
187+ // When a context is added, we assume it is a custom one.
188+ function addedCustomContext (path) {
189+
190+ // We do not have a QML object representing this context,
191+ // so we ask updateContexts to create one.
192+ if (!d.mContexts[path]) {
193+ d.updateContexts();
194+ }
195+ d.mContexts[path].name = mCustomContextNameInternet;
196+ sim.connMan.contextAdded.disconnect(addedCustomContext);
197+ }
198+
199 var customInternet = Object.keys(mContexts).filter(function (i) {
200 var ctx = mContexts[i];
201- return ctx.name === mCustomContextNameInternet ||
202- isEmptyCustom("internet", ctx);
203+ return ctx.name === mCustomContextNameInternet;
204 });
205 var customMms = Object.keys(mContexts).filter(function (i) {
206 var ctx = mContexts[i];
207- return ctx.name === mCustomContextNameMms ||
208- isEmptyCustom("mms", ctx);
209+ return ctx.name === mCustomContextNameMms;
210 });
211
212 // make sure there is only one context per type
213@@ -165,8 +150,8 @@
214 });
215 }
216
217- if (customInternet.length === 0) {
218- sim.connMan.addContext("internet");
219+ if (customInternet.length !== 0) {
220+ d.__haveCustomContexts = true;
221 }
222
223 // @bug don't create the custom MMS context
224@@ -251,7 +236,8 @@
225 type: type,
226 contexts: {"internet": mCustomContextInternet,
227 "mms": mCustomContextMms},
228- activateCb: activateHelper
229+ activateCb: activateHelper,
230+ sim: sim
231 });
232 }
233
234@@ -304,9 +290,12 @@
235
236 onActiveChanged: if (type === "internet") internetApnSelector.updateSelectedIndex()
237 onNameChanged: {
238- if (name === "Internet") {
239- this.name = d.mCustomContextNameInternet;
240- } else if (name === "MMS") {
241+
242+ if (name === d.mCustomContextNameInternet) {
243+ d.__haveCustomContexts = true;
244+ }
245+
246+ if (name === "MMS") {
247 this.name = d.mCustomContextNameMms;
248 this.accessPointName = d.pendingCustomMmsData["accessPointName"];
249 this.username = d.pendingCustomMmsData["username"];
250@@ -433,14 +422,7 @@
251 objectName: "customApnEdit"
252 text: i18n.tr("Custom Internet APN…")
253 width: parent.width - units.gu(4)
254- onClicked: {
255- if (!d.__haveCustomContexts) {
256- d.checkAndCreateCustomContexts();
257- d.__haveCustomContexts = true;
258- }
259-
260- d.openApnEditor("internet")
261- }
262+ onClicked: d.openApnEditor("internet")
263 }
264
265 ListItem.ItemSelector {
266
267=== added file 'plugins/cellular/apn.js'
268--- plugins/cellular/apn.js 1970-01-01 00:00:00 +0000
269+++ plugins/cellular/apn.js 2015-03-27 15:30:10 +0000
270@@ -0,0 +1,61 @@
271+var _CUSTOM_INTERNET_CONTEXT_NAME = '___ubuntu_custom_apn_internet';
272+var _CUSTOM_MMS_CONTEXT_NAME = '___ubuntu_custom_apn_mms';
273+
274+/*
275+Updates a context with new values.
276+
277+@param {QOfonoConnectionContext} context
278+@param {Object} values dict with new values
279+*/
280+function updateContext (context, values) {
281+ var messageProxy;
282+ console.warn('updateContext', values.accessPointName, values.messageCenter,
283+ values.messageProxy, values.port, values.useraccessPointName,
284+ values.password, values.type);
285+ if (typeof values.accessPointName !== 'undefined') {
286+ context.accessPointName = values.accessPointName;
287+ }
288+ if (typeof values.messageCenter !== 'undefined') {
289+ context.messageCenter = values.messageCenter;
290+ }
291+ if (typeof values.messageProxy !== 'undefined') {
292+ messageProxy = values.messageProxy;
293+ if (messageProxy !== '') {
294+ messageProxy = messageProxy + ':' + values.port;
295+ }
296+ context.messageProxy = messageProxy;
297+ }
298+ if (typeof values.username !== 'undefined') {
299+ context.username = values.username;
300+ }
301+ if (typeof values.password !== 'undefined') {
302+ context.password = values.password;
303+ }
304+ if (typeof values.type !== 'undefined') {
305+ context.type = values.type;
306+ }
307+
308+ if (context.type === 'internet') {
309+ context.name = CUSTOM_INTERNET_CONTEXT_NAME();
310+ } else if (context.type === 'mms') {
311+ context.name = CUSTOM_MMS_CONTEXT_NAME();
312+ }
313+}
314+
315+/*
316+Exposes the custom internet context name to the world.
317+
318+@return {String} custom internet context name
319+*/
320+function CUSTOM_INTERNET_CONTEXT_NAME () {
321+ return _CUSTOM_INTERNET_CONTEXT_NAME;
322+}
323+
324+/*
325+Exposes the custom mms context name to the world.
326+
327+@return {String} custom mms context name
328+*/
329+function CUSTOM_MMS_CONTEXT_NAME () {
330+ return _CUSTOM_MMS_CONTEXT_NAME;
331+}

Subscribers

People subscribed via source and target branches