Merge lp:~unity-api-team/indicator-network/dual_sim_pin_unlock into lp:indicator-network/14.10

Proposed by Antti Kaijanmäki
Status: Merged
Approved by: Jussi Pakkanen
Approved revision: 425
Merged at revision: 437
Proposed branch: lp:~unity-api-team/indicator-network/dual_sim_pin_unlock
Merge into: lp:indicator-network/14.10
Diff against target: 899 lines (+329/-183)
9 files modified
po/indicator-network.pot (+116/-76)
src/indicator/modem-manager.cpp (+3/-4)
src/indicator/modem.cpp (+2/-2)
src/indicator/sim-unlock-dialog.cpp (+139/-71)
src/indicator/sim-unlock-dialog.h (+1/-0)
src/menumodel-cpp/gio-helpers/variant.h (+28/-0)
src/notify-cpp/snapdecision/sim-unlock.cpp (+38/-28)
src/notify-cpp/snapdecision/sim-unlock.h (+1/-1)
tests/autopilot/indicator_network/data/pin-unlock.xml (+1/-1)
To merge this branch: bzr merge lp:~unity-api-team/indicator-network/dual_sim_pin_unlock
Reviewer Review Type Date Requested Status
Olga Kemmet (community) design Approve
Michael Zanetti (community) Abstain
PS Jenkins bot (community) continuous-integration Approve
Charles Kerr (community) Approve
Review via email: mp+237386@code.launchpad.net

Commit message

Finish the dual sim unlocking.

(LP: #1267135)
(LP: #1302050)
(LP: #1303633)
(LP: #1303635)
(LP: #1303680)
(LP: #1315451)
(LP: #1336675)
(LP: #1357000)
(LP: #1359226)
(LP: #1359276)
(LP: #1359280)
(LP: #1360343)
(LP: #1361074)

Description of the change

finish the dual sim unlocking.

needs to land together with:
https://code.launchpad.net/~unity-api-team/unity8/dual_sim_pin_unlock/+merge/232672

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
419. By Antti Kaijanmäki

whoops..

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michael Zanetti (mzanetti) wrote :

* There seems to be an issue with the parameters somewhere: I got this after opening the SIM unlock screen: http://i.imgur.com/2IgtkJs.png

* The joining of strings doesn't seem to work properly: http://imgur.com/IQfD4gg
IIRC the first sentence should be in the title, and the others need to be joined adding a whitespace.

* I locked my SIM, then I entered the PUK, it asked me for my new PIN, I entered that. The card however is still blocked and still asks for the PUK.

* indicator-network crashes randomly. Sometimes when I entered the puk, sometimes when clicking the unlock sim card button in the indicator dropdown.

* Entering the PUK, it keeps on saying "10 retries left", never decreases the 10. Might be related to it crashing and not really trying to set the puk.

I'm not able to unlock a PUK-locked sim card.

review: Needs Fixing
Revision history for this message
Michael Zanetti (mzanetti) wrote :

Is the PUK defined to always be 8 characters? Can it be longer?

Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

> Is the PUK defined to always be 8 characters? Can it be longer?

it's _always_ 8 by international specs.

420. By Antti Kaijanmäki

add spaces between dialog sentences.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
421. By Antti Kaijanmäki

Fix enter pin string.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
422. By Antti Kaijanmäki

fix pin reset with puk code and random crash with the ubuntu:i18n.

Revision history for this message
Michael Zanetti (mzanetti) wrote :

Working well now for me. But I only tested it, no code review.

review: Approve (manual test)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Mostly looks good, some questions inline

review: Needs Information
Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

answers inline.

423. By Antti Kaijanmäki

don't call closed() on a unlock dialog popup too early.

Revision history for this message
Charles Kerr (charlesk) :
review: Approve
424. By Antti Kaijanmäki

fix popups for puk.

425. By Antti Kaijanmäki

update pot again.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michael Zanetti (mzanetti) wrote :

Hmm... The UnlockAllModems D-Bus call doesn't seem to work properly any more... It does open the dialog once, but entering the PIN there doesn't actually unlock the modem. All subsequent calls of this method time out.

review: Needs Fixing
Revision history for this message
Michael Zanetti (mzanetti) wrote :

> Hmm... The UnlockAllModems D-Bus call doesn't seem to work properly any
> more... It does open the dialog once, but entering the PIN there doesn't
> actually unlock the modem. All subsequent calls of this method time out.

Seems this is out of scope of this branch...

review: Abstain
Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

> > Hmm... The UnlockAllModems D-Bus call doesn't seem to work properly any
> > more... It does open the dialog once, but entering the PIN there doesn't
> > actually unlock the modem. All subsequent calls of this method time out.
>
> Seems this is out of scope of this branch...

Fixing UnlockAllModems is not part of this MP anymore.
Separately tracked in:
https://bugs.launchpad.net/ubuntu-rtm/+source/indicator-network/+bug/1333121

Revision history for this message
Olga Kemmet (olga-kemmet) wrote :

Works as intended.

review: Approve (design)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'po/indicator-network.pot'
2--- po/indicator-network.pot 2014-08-08 12:36:47 +0000
3+++ po/indicator-network.pot 2014-10-07 17:43:18 +0000
4@@ -8,7 +8,7 @@
5 msgstr ""
6 "Project-Id-Version: indicator-network\n"
7 "Report-Msgid-Bugs-To: \n"
8-"POT-Creation-Date: 2014-08-08 15:33+0300\n"
9+"POT-Creation-Date: 2014-10-07 20:43+0300\n"
10 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
12 "Language-Team: LANGUAGE <LL@li.org>\n"
13@@ -16,153 +16,193 @@
14 "MIME-Version: 1.0\n"
15 "Content-Type: text/plain; charset=UTF-8\n"
16 "Content-Transfer-Encoding: 8bit\n"
17+"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
18
19-#: network/quick-access-section.cpp:48
20+#: src/indicator/quick-access-section.cpp:48
21 msgid "Flight Mode"
22 msgstr ""
23
24 #. TRANSLATORS: this is the indicator title shown on the top header of the indicator area
25-#: network/root-state.cpp:307
26+#: src/indicator/root-state.cpp:296
27 msgid "Network"
28 msgstr ""
29
30-#. TRANSLATORS: this string is not currently being shown on the screen. This message might be subject to change.
31-#: network/sim-unlock-dialog.cpp:85
32-msgid ""
33-"This will be the last attempt.<br><br>If the SIM PIN is entered incorrectly, "
34-"your SIM will be blocked and would require the PUK Code to unlock."
35-msgstr ""
36-
37-#. TRANSLATORS: this string is not currently being shown on the screen. This message might be subject to change.
38-#: network/sim-unlock-dialog.cpp:95
39-msgid ""
40-"Your SIM is now blocked.<br><br>Enter the PUK Code to unlock.<br><br>You may "
41-"contact your network provider for PUK Code."
42-msgstr ""
43-
44-#. TRANSLATORS: this string is not currently being shown on the screen. This message might be subject to change.
45-#: network/sim-unlock-dialog.cpp:106
46-msgid ""
47-"This will be the last attempt.<br><br>If the PUK code is entered "
48-"incorrectly, your SIM will need to be replaced.<br><br>Please contact your "
49-"network provider."
50-msgstr ""
51-
52-#. TRANSLATORS: this string is not currently being shown on the screen. This message might be subject to change.
53-#: network/sim-unlock-dialog.cpp:117
54-msgid ""
55-"Your SIM is now permanently blocked and needs to be replaced.<br><br>Please "
56-"contact your network provider."
57-msgstr ""
58-
59-#: network/sim-unlock-dialog.cpp:183 network/sim-unlock-dialog.cpp:414
60-#: network/sim-unlock-dialog.cpp:442
61-msgid "Enter SIM PIN"
62-msgstr ""
63-
64-#: network/sim-unlock-dialog.cpp:187
65+#: src/indicator/sim-unlock-dialog.cpp:115
66+msgid "Sorry, incorrect PIN"
67+msgstr ""
68+
69+#: src/indicator/sim-unlock-dialog.cpp:136
70+msgid "Sorry, incorrect PUK"
71+msgstr ""
72+
73+#: src/indicator/sim-unlock-dialog.cpp:151
74+msgid "Sorry, incorrect %{1} PIN."
75+msgstr ""
76+
77+#: src/indicator/sim-unlock-dialog.cpp:156
78+#: src/indicator/sim-unlock-dialog.cpp:185
79+msgid "This will be your last attempt."
80+msgstr ""
81+
82+#: src/indicator/sim-unlock-dialog.cpp:158
83+msgid ""
84+"If %{1} PIN is entered incorrectly you will require your PUK code to unlock."
85+msgstr ""
86+
87+#: src/indicator/sim-unlock-dialog.cpp:168
88+msgid "Sorry, your %{1} is now blocked."
89+msgstr ""
90+
91+#: src/indicator/sim-unlock-dialog.cpp:173
92+msgid "Please enter your PUK code to unblock SIM card."
93+msgstr ""
94+
95+#: src/indicator/sim-unlock-dialog.cpp:175
96+msgid "You may need to contact your network provider for PUK code."
97+msgstr ""
98+
99+#: src/indicator/sim-unlock-dialog.cpp:183
100+#: src/indicator/sim-unlock-dialog.cpp:197
101+msgid "Sorry, incorrect PUK."
102+msgstr ""
103+
104+#: src/indicator/sim-unlock-dialog.cpp:187
105+msgid ""
106+"If PUK code is entered incorrectly, your SIM card will be blocked and needs "
107+"replacement."
108+msgstr ""
109+
110+#: src/indicator/sim-unlock-dialog.cpp:189
111+msgid "Please contact your network provider."
112+msgstr ""
113+
114+#: src/indicator/sim-unlock-dialog.cpp:199
115+msgid "Your SIM card is now permanently blocked and needs replacement."
116+msgstr ""
117+
118+#: src/indicator/sim-unlock-dialog.cpp:201
119+msgid "Please contact your service provider."
120+msgstr ""
121+
122+#: src/indicator/sim-unlock-dialog.cpp:265
123+msgid "Enter %{1} PIN"
124+msgstr ""
125+
126+#: src/indicator/sim-unlock-dialog.cpp:272
127 msgid "Enter PUK code"
128 msgstr ""
129
130-#: network/sim-unlock-dialog.cpp:195
131+#: src/indicator/sim-unlock-dialog.cpp:274
132+msgid "Enter PUK code for %{1}"
133+msgstr ""
134+
135+#: src/indicator/sim-unlock-dialog.cpp:282
136 #, c-format
137-msgid "Attempt %d of %d"
138-msgstr ""
139-
140-#: network/sim-unlock-dialog.cpp:210 network/sim-unlock-dialog.cpp:425
141-#: network/sim-unlock-dialog.cpp:435
142+msgid "1 attempt remaining"
143+msgid_plural "%d attempts remaining"
144+msgstr[0] ""
145+msgstr[1] ""
146+
147+#: src/indicator/sim-unlock-dialog.cpp:293
148+msgid "Enter new %{1} PIN"
149+msgstr ""
150+
151+#: src/indicator/sim-unlock-dialog.cpp:301
152+msgid "Confirm new %{1} PIN"
153+msgstr ""
154+
155+#: src/indicator/sim-unlock-dialog.cpp:340
156+#: src/indicator/sim-unlock-dialog.cpp:515
157+msgid "PIN codes did not match."
158+msgstr ""
159+
160+#: src/indicator/sim-unlock-dialog.cpp:495
161+#: src/indicator/sim-unlock-dialog.cpp:523
162+msgid "Enter SIM PIN"
163+msgstr ""
164+
165+#: src/indicator/sim-unlock-dialog.cpp:506
166+#: src/indicator/sim-unlock-dialog.cpp:516
167 msgid "Enter new PIN code"
168 msgstr ""
169
170-#: network/sim-unlock-dialog.cpp:213 network/sim-unlock-dialog.cpp:429
171+#: src/indicator/sim-unlock-dialog.cpp:510
172 msgid "Confirm new PIN code"
173 msgstr ""
174
175-#: network/sim-unlock-dialog.cpp:236
176-msgid "Oops!<br>Incorrect PIN entered."
177-msgstr ""
178-
179-#: network/sim-unlock-dialog.cpp:254 network/sim-unlock-dialog.cpp:434
180-msgid "PIN codes did not match."
181-msgstr ""
182-
183-#: network/sim-unlock-dialog.cpp:259
184-msgid "Oops!<br>Incorrect PUK entered."
185-msgstr ""
186-
187-#: network/sim-unlock-dialog.cpp:441
188+#: src/indicator/sim-unlock-dialog.cpp:522
189 msgid "Failed to change PIN."
190 msgstr ""
191
192-#: network/wifi-link-item.h:87
193+#: src/indicator/wifi-link-item.h:88
194 msgid "Wi-Fi"
195 msgstr ""
196
197-#: network/wifi-link-item.h:151
198+#: src/indicator/wifi-link-item.h:152
199 msgid "Other network…"
200 msgstr ""
201
202-#: network/wifi-section.cpp:60
203+#: src/indicator/wifi-section.cpp:60
204 msgid "Wi-Fi settings…"
205 msgstr ""
206
207-#: network/wwan-link-item.cpp:87
208+#: src/indicator/wwan-link-item.cpp:87
209 msgid "No SIM"
210 msgstr ""
211
212-#: network/wwan-link-item.cpp:93
213+#: src/indicator/wwan-link-item.cpp:93
214 msgid "SIM Error"
215 msgstr ""
216
217-#: network/wwan-link-item.cpp:100
218+#: src/indicator/wwan-link-item.cpp:100
219 msgid "SIM Locked"
220 msgstr ""
221
222-#: network/wwan-link-item.cpp:112
223+#: src/indicator/wwan-link-item.cpp:112
224 msgid "Unregistered"
225 msgstr ""
226
227-#: network/wwan-link-item.cpp:116
228+#: src/indicator/wwan-link-item.cpp:116
229 msgid "Unknown"
230 msgstr ""
231
232-#: network/wwan-link-item.cpp:120
233+#: src/indicator/wwan-link-item.cpp:120
234 msgid "Denied"
235 msgstr ""
236
237-#: network/wwan-link-item.cpp:124
238+#: src/indicator/wwan-link-item.cpp:124
239 msgid "Searching"
240 msgstr ""
241
242-#: network/wwan-link-item.cpp:135
243+#: src/indicator/wwan-link-item.cpp:135
244 msgid "No Signal"
245 msgstr ""
246
247-#: network/wwan-link-item.cpp:141
248+#: src/indicator/wwan-link-item.cpp:141
249 msgid "Offline"
250 msgstr ""
251
252-#: network/wwan-section.cpp:79
253+#: src/indicator/wwan-section.cpp:79
254 msgid "Cellular settings…"
255 msgstr ""
256
257-#: secret-agent/SecretRequest.cpp:62
258+#: src/secret-agent/SecretRequest.cpp:62
259 #, qt-format
260 msgid "Connect to “%1”"
261 msgstr ""
262
263-#: secret-agent/SecretRequest.cpp:67
264+#: src/secret-agent/SecretRequest.cpp:67
265 msgid "WPA"
266 msgstr ""
267
268-#: secret-agent/SecretRequest.cpp:69
269+#: src/secret-agent/SecretRequest.cpp:69
270 msgid "WEP"
271 msgstr ""
272
273-#: secret-agent/SecretRequest.cpp:75
274+#: src/secret-agent/SecretRequest.cpp:75
275 msgid "Connect"
276 msgstr ""
277
278-#: secret-agent/SecretRequest.cpp:76
279+#: src/secret-agent/SecretRequest.cpp:76
280 msgid "Cancel"
281 msgstr ""
282
283=== modified file 'src/indicator/modem-manager.cpp'
284--- src/indicator/modem-manager.cpp 2014-08-28 12:13:29 +0000
285+++ src/indicator/modem-manager.cpp 2014-10-07 17:43:18 +0000
286@@ -160,6 +160,8 @@
287 currentModems.insert(std::make_shared<Modem>(ofonoModem));
288 }
289
290+
291+ m_unlockDialog->showSimIdentifiers().set(currentModems.size() > 1);
292 m_modems.set(currentModems);
293 }
294
295@@ -177,14 +179,11 @@
296
297 ModemManager::ModemManager()
298 {
299- std::cout << __PRETTY_FUNCTION__ << std::endl;
300 d.reset(new Private);
301 }
302
303 ModemManager::~ModemManager()
304-{
305- std::cout << __PRETTY_FUNCTION__ << std::endl;
306-}
307+{}
308
309 void
310 ModemManager::unlockModem(Modem::Ptr modem)
311
312=== modified file 'src/indicator/modem.cpp'
313--- src/indicator/modem.cpp 2014-10-06 07:52:34 +0000
314+++ src/indicator/modem.cpp 2014-10-07 17:43:18 +0000
315@@ -211,8 +211,8 @@
316 switch(type) {
317 case PinType::none:
318 return true;
319- case PinType::pin:
320- return d->m_ofonoModem->simManager.get()->resetPin(org::ofono::Interface::SimManager::PinType::pin,
321+ case PinType::puk:
322+ return d->m_ofonoModem->simManager.get()->resetPin(org::ofono::Interface::SimManager::PinType::puk,
323 puk,
324 pin);
325 default:
326
327=== modified file 'src/indicator/sim-unlock-dialog.cpp'
328--- src/indicator/sim-unlock-dialog.cpp 2014-08-14 23:23:06 +0000
329+++ src/indicator/sim-unlock-dialog.cpp 2014-10-07 17:43:18 +0000
330@@ -24,6 +24,46 @@
331
332 #include <functional>
333
334+namespace ubuntu {
335+namespace i18n{
336+
337+std::string __argumentSubstitute(int /*depth*/, const std::string &format) // base function
338+{
339+ return format;
340+}
341+
342+template<typename T, typename... Targs>
343+std::string __argumentSubstitute(int depth, const std::string &format, T value, Targs... Fargs)
344+{
345+ std::string tmp = __argumentSubstitute(depth+1, format, Fargs...);
346+ std::string subs = "%{" + std::to_string(depth) + "}";
347+
348+ const std::string val {value};
349+ for (auto it = std::search(tmp.begin(), tmp.end(), subs.begin(), subs.end());
350+ it != tmp.end();
351+ it = std::search(tmp.begin(), tmp.end(), subs.begin(), subs.end()))
352+ {
353+ auto pos = it;
354+ pos = tmp.erase(pos, pos+subs.length());
355+ tmp.insert(pos, val.begin(), val.end());
356+ }
357+ return tmp;
358+}
359+
360+/// substitute variables in strings by index
361+/// only accepts std::string as input for now
362+/// argumentSubstitute("First: %{1}, Second %{2}", std::string{"foo"}, std::string{"bar"});
363+/// --> "First: foo, Second bar"
364+/// argumentSubstitute("First: %{2}, Second %{1}", std::string{"foo"}, std::string{"bar"});
365+/// --> "First: bar, Second: foor"
366+template<typename... Targs>
367+std::string argumentSubstitute(const std::string &format, Targs... Fargs)
368+{
369+ return __argumentSubstitute(1, format, Fargs...);
370+}
371+}
372+}
373+
374 class SimUnlockDialog::Private
375 {
376 public:
377@@ -58,7 +98,9 @@
378
379 std::vector<core::Connection> m_connections;
380
381- void sendEnterPin(std::string pin)
382+ core::Property<bool> m_showSimIdentifiers;
383+
384+ bool sendEnterPin(std::string pin)
385 {
386 int retries = -1;
387 auto retriesMap = m_modem->retries().get();
388@@ -67,17 +109,21 @@
389 retries = retriesMap[Modem::PinType::pin];
390 }
391
392- if (!m_modem->enterPin(Modem::PinType::pin, pin)) {
393- --retries;
394- if (retries == 1) {
395- showLastPinAttemptPopup();
396- } else if (retries == 0) {
397- showPinBlockedPopup();
398- }
399+ if (m_modem->enterPin(Modem::PinType::pin, pin))
400+ return true;
401+
402+ m_sd->showError(_("Sorry, incorrect PIN"));
403+ --retries;
404+ if (retries == 1) {
405+ showLastPinAttemptPopup();
406+ } else if (retries == 0) {
407+ showPinBlockedPopup();
408 }
409+
410+ return false;
411 }
412
413- void sendResetPin(std::string puk, std::string newPin)
414+ bool sendResetPin(std::string puk, std::string newPin)
415 {
416 int retries = -1;
417 auto retriesMap = m_modem->retries().get();
418@@ -86,56 +132,75 @@
419 retries = retriesMap[Modem::PinType::puk];
420 }
421
422- if (!m_modem->resetPin(Modem::PinType::pin, puk, newPin)) {
423+ if (!m_modem->resetPin(Modem::PinType::puk, puk, newPin)) {
424+ m_sd->showError(_("Sorry, incorrect PUK"));
425 --retries;
426 if (retries == 1) {
427- showLastPinAttemptPopup();
428+ showLastPukAttemptPopup();
429 } else if (retries == 0) {
430- showPinBlockedPopup([this](){ m_sd->close(); });
431+ showSimPermanentlyBlockedPopup([this](){ m_sd->close(); });
432 }
433+ return false;
434 }
435+ return true;
436 }
437
438-
439 void showLastPinAttemptPopup(std::function<void()> closed = std::function<void()>())
440 {
441- // TRANSLATORS: this string is not currently being shown on the screen. This message might be subject to change.
442- m_sd->showPopup(_("This will be the last attempt.<br>"
443- "<br>"
444- "If the SIM PIN is entered incorrectly, your SIM "
445- "will be blocked and would require the PUK Code to unlock."),
446- closed);
447+ std::stringstream output;
448+ output << ubuntu::i18n::argumentSubstitute(_("Sorry, incorrect %{1} PIN."),
449+ m_showSimIdentifiers.get() ?
450+ m_modem->simIdentifier().get()
451+ : "SIM");
452+ output << " ";
453+ output << _("This will be your last attempt.");
454+ output << " ";
455+ output << ubuntu::i18n::argumentSubstitute(_("If %{1} PIN is entered incorrectly you will require your PUK code to unlock."),
456+ m_showSimIdentifiers.get() ?
457+ m_modem->simIdentifier().get()
458+ : "SIM");
459+ m_sd->showPopup(output.str(), closed);
460 }
461
462 void showPinBlockedPopup(std::function<void()> closed = std::function<void()>())
463 {
464- // TRANSLATORS: this string is not currently being shown on the screen. This message might be subject to change.
465- m_sd->showPopup(_("Your SIM is now blocked.<br>"
466- "<br>"
467- "Enter the PUK Code to unlock.<br>"
468- "<br>"
469- "You may contact your network provider for PUK Code."),
470- closed);
471+ std::stringstream output;
472+ output << ubuntu::i18n::argumentSubstitute(std::string{_("Sorry, your %{1} is now blocked.")},
473+ m_showSimIdentifiers.get() ?
474+ m_modem->simIdentifier().get()
475+ : "SIM");
476+ output << " ";
477+ output << _("Please enter your PUK code to unblock SIM card.");
478+ output << " ";
479+ output << _("You may need to contact your network provider for PUK code.");
480+
481+ m_sd->showPopup(output.str(), closed);
482 }
483
484 void showLastPukAttemptPopup(std::function<void()> closed = std::function<void()>())
485 {
486- // TRANSLATORS: this string is not currently being shown on the screen. This message might be subject to change.
487- m_sd->showPopup(_("This will be the last attempt.<br>"
488- "<br>"
489- "If the PUK code is entered incorrectly, your SIM will need to be replaced.<br>"
490- "<br>"
491- "Please contact your network provider."),
492- closed);
493+ std::stringstream output;
494+ output << _("Sorry, incorrect PUK.");
495+ output << " ";
496+ output << _("This will be your last attempt.");
497+ output << " ";
498+ output << _("If PUK code is entered incorrectly, your SIM card will be blocked and needs replacement.");
499+ output << " ";
500+ output << _("Please contact your network provider.");
501+
502+ m_sd->showPopup(output.str(), closed);
503 }
504
505 void showSimPermanentlyBlockedPopup(std::function<void()> closed = std::function<void()>())
506 {
507- // TRANSLATORS: this string is not currently being shown on the screen. This message might be subject to change.
508- m_sd->showPopup(_("Your SIM is now permanently blocked and needs to be replaced.<br>"
509- "<br>"
510- "Please contact your network provider."),
511- closed);
512+ std::stringstream output;
513+ output << _("Sorry, incorrect PUK.");
514+ output << " ";
515+ output << _("Your SIM card is now permanently blocked and needs replacement.");
516+ output << " ";
517+ output << _("Please contact your service provider.");
518+
519+ m_sd->showPopup(output.str(), closed);
520 }
521
522 Private();
523@@ -153,13 +218,13 @@
524 SimUnlockDialog::Private::Private()
525 {
526 m_sd = std::make_shared<notify::snapdecision::SimUnlock>();
527+ m_showSimIdentifiers.set(false);
528 reset();
529 }
530
531 void
532 SimUnlockDialog::Private::update()
533 {
534- std::cout << __PRETTY_FUNCTION__ << std::endl;
535 std::lock_guard<std::recursive_mutex> lock(m_updateMutex);
536
537 if (!m_modem || !m_sd)
538@@ -197,43 +262,51 @@
539 // we are done.
540 return;
541 case Modem::PinType::pin:
542- /// @todo add SIM identifier
543- title = _("Enter SIM PIN");
544+ title = ubuntu::i18n::argumentSubstitute(_("Enter %{1} PIN"),
545+ m_showSimIdentifiers.get() ?
546+ m_modem->simIdentifier().get()
547+ : "SIM");
548 break;
549 case Modem::PinType::puk:
550- /// @todo add SIM identifier
551- title = _("Enter PUK code");
552+ if (!m_showSimIdentifiers.get())
553+ title = _("Enter PUK code");
554+ else
555+ title = ubuntu::i18n::argumentSubstitute(_("Enter PUK code for %{1}"),
556+ m_modem->simIdentifier().get());
557 break;
558 }
559 m_sd->pinMinMax().set(lengths[type]);
560
561 std::string attempts;
562 if (retries.find(type) != retries.end()) {
563- auto attempt = maxRetries[type] - retries[type] + 1;
564- gchar *tmp = g_strdup_printf(_("Attempt %d of %d"), attempt, maxRetries[type]);
565+ gchar *tmp = g_strdup_printf(ngettext("1 attempt remaining", "%d attempts remaining", retries[type]), retries[type]);
566 attempts = {tmp};
567 g_free(tmp);
568 }
569
570- /// @todo get a proper unlock dialog API..
571- if (attempts.empty()) {
572- m_sd->title().set(title);
573- } else {
574- m_sd->title().set("<b>" + title + "</b><br>" + attempts);
575- }
576- std::cout << m_sd->title().get() << std::endl;
577+ m_sd->title().set(title);
578+ m_sd->body().set(attempts);
579 break;
580 }
581 case EnterPinStates::enterNewPin:
582- m_sd->title().set(_("Enter new PIN code"));
583+ m_sd->body().set("Create new PIN");
584+ m_sd->title().set(ubuntu::i18n::argumentSubstitute(_("Enter new %{1} PIN"),
585+ m_showSimIdentifiers.get() ?
586+ m_modem->simIdentifier().get()
587+ : "SIM"));
588+ m_sd->pinMinMax().set(lengths[Modem::PinType::pin]);
589 break;
590 case EnterPinStates::confirmNewPin:
591- m_sd->title().set(_("Confirm new PIN code"));
592+ m_sd->body().set("Create new PIN");
593+ m_sd->title().set(ubuntu::i18n::argumentSubstitute(_("Confirm new %{1} PIN"),
594+ m_showSimIdentifiers.get() ?
595+ m_modem->simIdentifier().get()
596+ : "SIM"));
597+ m_sd->pinMinMax().set(lengths[Modem::PinType::pin]);
598 break;
599 }
600
601 /// @todo should be able to see cleartext puk and pin when entering puk or changing pin.
602- /// @todo add phone number or IMSI or something to the body
603 m_sd->update();
604 m_sd->show();
605 }
606@@ -241,8 +314,6 @@
607 void
608 SimUnlockDialog::Private::pinEntered(std::string pin)
609 {
610- std::cout << __PRETTY_FUNCTION__ << std::endl;
611-
612 std::lock_guard<std::recursive_mutex> lock(m_updateMutex);
613 switch (m_enterPinState) {
614 case EnterPinStates::initial:
615@@ -250,10 +321,7 @@
616 assert(0);
617 return;
618 case EnterPinStates::enterPin:
619- if (!m_modem->enterPin(Modem::PinType::pin, pin)) {
620- m_sd->showError(_("Oops!<br>Incorrect PIN entered."));
621- } else {
622- std::cout << "Correct PIN entered." << std::endl;
623+ if (sendEnterPin(pin)) {
624 m_sd->close();
625 reset();
626 return;
627@@ -273,17 +341,14 @@
628 m_enterPinState = EnterPinStates::enterNewPin;
629 m_newPin.clear();
630 } else {
631- if (!m_modem->resetPin(Modem::PinType::pin, m_pukCode, pin)) {
632- m_sd->showError(_("Oops!<br>Incorrect PUK entered."));
633- m_enterPinState = EnterPinStates::enterPuk;
634- m_pukCode.clear();
635- m_newPin.clear();
636- } else {
637- std::cout << "ResetPin succesfull." << std::endl;
638+ if (sendResetPin(m_pukCode, pin)) {
639 m_sd->close();
640 reset();
641 return;
642 }
643+ m_enterPinState = EnterPinStates::enterPuk;
644+ m_pukCode.clear();
645+ m_newPin.clear();
646 }
647 break;
648 }
649@@ -293,21 +358,18 @@
650 void
651 SimUnlockDialog::Private::cancelled()
652 {
653- std::cout << "SIM notification cancelled" << std::endl;
654 m_sd->close();
655 }
656
657 void
658 SimUnlockDialog::Private::closed()
659 {
660- std::cout << __PRETTY_FUNCTION__ << std::endl;
661 reset();
662 }
663
664 void
665 SimUnlockDialog::Private::reset()
666 {
667- std::cout << __PRETTY_FUNCTION__ << std::endl;
668 /** @todo
669 * bug in dbus-cpp :/
670 * can't disconnect here as the reset() is called from pinEnterer() and
671@@ -410,6 +472,7 @@
672 void
673 SimUnlockDialog::changePin(Modem::Ptr modem)
674 {
675+ /// @todo do we need this?
676 if (d->m_modem)
677 throw std::logic_error("Unlocking already in progress.");
678
679@@ -485,3 +548,8 @@
680 return d->m_state;
681 }
682
683+core::Property<bool> &
684+SimUnlockDialog::showSimIdentifiers()
685+{
686+ return d->m_showSimIdentifiers;
687+}
688
689=== modified file 'src/indicator/sim-unlock-dialog.h'
690--- src/indicator/sim-unlock-dialog.h 2014-04-23 13:18:25 +0000
691+++ src/indicator/sim-unlock-dialog.h 2014-10-07 17:43:18 +0000
692@@ -55,6 +55,7 @@
693 Modem::Ptr modem();
694
695 core::Property<State> &state();
696+ core::Property<bool> &showSimIdentifiers();
697 };
698
699 #endif
700
701=== modified file 'src/menumodel-cpp/gio-helpers/variant.h'
702--- src/menumodel-cpp/gio-helpers/variant.h 2014-08-15 11:59:20 +0000
703+++ src/menumodel-cpp/gio-helpers/variant.h 2014-10-07 17:43:18 +0000
704@@ -206,6 +206,34 @@
705 };
706
707 template<>
708+struct Codec<std::vector<std::int32_t>>
709+{
710+ inline static GVariant *encode_argument(const std::vector<std::int32_t> &values)
711+ {
712+ GVariantBuilder builder;
713+ g_variant_builder_init(&builder, G_VARIANT_TYPE("ai"));
714+ for (auto value : values) {
715+ std::int32_t tmp = value;
716+ g_variant_builder_add(&builder,
717+ "i",
718+ tmp);
719+ }
720+ return g_variant_builder_end(&builder);
721+ }
722+ inline static void decode_argument(const Variant &variant, std::vector<std::int32_t> &values)
723+ {
724+ assert(variant);
725+ assert(g_variant_is_of_type(variant, G_VARIANT_TYPE("ai")));
726+ GVariantIter iter;
727+ std::int32_t *val = 0;
728+ g_variant_iter_init (&iter, variant);
729+ while (g_variant_iter_loop (&iter, "i", &val)) {
730+ values.push_back(*val);
731+ }
732+ }
733+};
734+
735+template<>
736 struct Codec<std::vector<Variant>>
737 {
738 inline static GVariant *encode_argument(const std::vector<Variant> &values)
739
740=== modified file 'src/notify-cpp/snapdecision/sim-unlock.cpp'
741--- src/notify-cpp/snapdecision/sim-unlock.cpp 2014-08-14 23:23:06 +0000
742+++ src/notify-cpp/snapdecision/sim-unlock.cpp 2014-10-07 17:43:18 +0000
743@@ -47,6 +47,7 @@
744
745 Action::Ptr m_notifyAction;
746 Action::Ptr m_pinMinMaxAction;
747+ Action::Ptr m_popupAction;
748 Action::Ptr m_errorAction;
749 ActionGroup::Ptr m_actionGroup;
750 ActionGroupExporter::Ptr m_actionGroupExporter;
751@@ -55,6 +56,9 @@
752 MenuItem::Ptr m_menuItem;
753 MenuExporter::Ptr m_menuExporter;
754
755+ std::function<void()> m_pendingErrorClosed;
756+ std::function<void()> m_pendingPopupClosed;
757+
758 Private(const std::string &title,
759 const std::string &body,
760 std::pair<std::uint8_t, std::uint8_t> pinMinMax)
761@@ -75,8 +79,6 @@
762 modelActions["notifications"] = TypedVariant<std::string>(actionPath);
763
764 std::map<std::string, Variant> modelPaths;
765- /// @todo hack!
766- // modelPaths["busName"] = TypedVariant<std::string>("com.canonical.indicator.network");
767 modelPaths["busName"] = TypedVariant<std::string>(m_sessionBus->address());
768 modelPaths["menuPath"] = TypedVariant<std::string>(menuPath);
769 modelPaths["actions"] = TypedVariant<std::map<std::string, Variant>>(modelActions);
770@@ -84,9 +86,8 @@
771 m_menu = std::make_shared<Menu>();
772 m_menuItem = std::make_shared<MenuItem>("", "notifications.simunlock");
773 m_menuItem->setAttribute("x-canonical-type", TypedVariant<std::string>("com.canonical.snapdecision.pinlock"));
774- /// @todo we need both min and max.
775- m_menuItem->setAttribute("x-canonical-pin-length", TypedVariant<std::int32_t>(pinMinMax.first));
776 m_menuItem->setAttribute("x-canonical-pin-min-max", TypedVariant<std::string>("notifications.pinMinMax"));
777+ m_menuItem->setAttribute("x-canonical-pin-popup", TypedVariant<std::string>("notifications.popup"));
778 m_menuItem->setAttribute("x-canonical-pin-error", TypedVariant<std::string>("notifications.error"));
779 m_menu->append(m_menuItem);
780
781@@ -104,26 +105,36 @@
782 });
783 m_actionGroup->add(m_notifyAction);
784
785-#if 0
786 m_pinMinMaxAction = std::make_shared<Action>("pinMinMax",
787 nullptr,
788- TypedVariant<std::vector<std::int32_t>>(m_pinMinMax),
789- [this](Variant state)
790- {
791+ TypedVariant<std::vector<std::int32_t>>({m_pinMinMax.get().first, m_pinMinMax.get().second}),
792+ [this](Variant)
793+ {});
794+ m_actionGroup->add(m_pinMinMaxAction);
795+
796+ m_popupAction = std::make_shared<Action>("popup",
797+ nullptr,
798+ TypedVariant<std::string>(""),
799+ [this](Variant)
800+ {});
801+ m_popupAction->activated().connect([this](Variant){
802+ m_popupAction->setState(TypedVariant<std::string>(""));
803+ if (m_pendingPopupClosed)
804+ m_pendingPopupClosed();
805+ m_pendingPopupClosed = std::function<void()>();
806 });
807- m_actionGroup->add(m_pinMinMaxrAction);
808-#endif
809+ m_actionGroup->add(m_popupAction);
810+
811 m_errorAction = std::make_shared<Action>("error",
812 nullptr,
813 TypedVariant<std::string>(""),
814- [this](Variant state)
815- {
816- auto tmp = state.as<std::string>();
817- if (tmp.empty()) {
818- // ack from the dialog side.
819- // find the error and call the cb
820- } else {
821- }
822+ [this](Variant)
823+ {});
824+ m_errorAction->activated().connect([this](Variant){
825+ m_errorAction->setState(TypedVariant<std::string>(""));
826+ if (m_pendingErrorClosed)
827+ m_pendingErrorClosed();
828+ m_pendingErrorClosed = std::function<void()>();
829 });
830 m_actionGroup->add(m_errorAction);
831
832@@ -137,16 +148,13 @@
833 m_notification->closed().connect([this](){ m_closed(); });
834
835 m_title.changed().connect([this](const std::string &value){
836- /// @todo we need both min and max.
837 m_notification->summary().set(value);
838 });
839 m_body.changed().connect([this](const std::string &value){
840 m_notification->body().set(value);
841 });
842 m_pinMinMax.changed().connect([this](std::pair<std::uint8_t, uint8_t> value) {
843- /// @todo assert min <= max, also upon construction
844- m_menuItem->setAttribute("x-canonical-pin-length",
845- TypedVariant<std::int32_t>(value.first));
846+ m_pinMinMaxAction->setState(TypedVariant<std::vector<std::int32_t>>({value.first, value.second}));
847 });
848 }
849 };
850@@ -220,15 +228,17 @@
851 void
852 SimUnlock::showError(std::string message, std::function<void()> closed)
853 {
854- std::cerr << __PRETTY_FUNCTION__ << ": " << message << std::endl;
855- if (closed)
856- closed();
857+ d->m_errorAction->setState(TypedVariant<std::string>(message));
858+ if (d->m_pendingErrorClosed)
859+ d->m_pendingErrorClosed();
860+ d->m_pendingErrorClosed = closed;
861 }
862
863 void
864 SimUnlock::showPopup(std::string message, std::function<void()> closed)
865 {
866- std::cerr << __PRETTY_FUNCTION__ << ": " << message << std::endl;
867- if (closed)
868- closed();
869+ d->m_popupAction->setState(TypedVariant<std::string>(message));
870+ if (d->m_pendingPopupClosed)
871+ d->m_pendingPopupClosed();
872+ d->m_pendingPopupClosed = closed;
873 }
874
875=== modified file 'src/notify-cpp/snapdecision/sim-unlock.h'
876--- src/notify-cpp/snapdecision/sim-unlock.h 2014-08-15 11:59:20 +0000
877+++ src/notify-cpp/snapdecision/sim-unlock.h 2014-10-07 17:43:18 +0000
878@@ -38,7 +38,7 @@
879
880 explicit SimUnlock(const std::string &title = "",
881 const std::string &body = "",
882- std::pair<std::uint8_t, std::uint8_t> pinMinMax = {0, -0});
883+ std::pair<std::uint8_t, std::uint8_t> pinMinMax = {0, 0});
884 ~SimUnlock();
885
886 core::Signal<std::string> &pinEntered();
887
888=== modified file 'tests/autopilot/indicator_network/data/pin-unlock.xml'
889--- tests/autopilot/indicator_network/data/pin-unlock.xml 2014-05-02 01:40:42 +0000
890+++ tests/autopilot/indicator_network/data/pin-unlock.xml 2014-10-07 17:43:18 +0000
891@@ -242,7 +242,7 @@
892 <set name="PIN2VALUE" value="5678"/>
893
894 <!-- Value of the PUK that is required -->
895- <set name="PUKVALUE" value="1234567890"/>
896+ <set name="PUKVALUE" value="12345678"/>
897
898 <!-- Value of the PUK2 that is required -->
899 <set name="PUK2VALUE" value="01010101"/>

Subscribers

People subscribed via source and target branches