Merge lp:~pete-woods/indicator-network/sim-unlock-label-lp1449925 into lp:indicator-network/15.10

Proposed by Pete Woods
Status: Merged
Approved by: Pete Woods
Approved revision: 512
Merged at revision: 509
Proposed branch: lp:~pete-woods/indicator-network/sim-unlock-label-lp1449925
Merge into: lp:indicator-network/15.10
Diff against target: 2029 lines (+682/-363)
25 files modified
CMakeLists.txt (+0/-7)
debian/control (+0/-1)
src/indicator/CMakeLists.txt (+0/-1)
src/indicator/agent/PasswordMenu.cpp (+4/-1)
src/indicator/agent/SecretAgent.cpp (+8/-7)
src/indicator/agent/SecretAgent.h (+9/-4)
src/indicator/agent/SecretRequest.cpp (+15/-27)
src/indicator/agent/SecretRequest.h (+4/-3)
src/indicator/factory.cpp (+18/-2)
src/indicator/main.cpp (+8/-17)
src/indicator/nmofono/manager-impl.cpp (+3/-2)
src/indicator/nmofono/manager-impl.h (+6/-1)
src/indicator/sim-unlock-dialog.cpp (+7/-18)
src/indicator/sim-unlock-dialog.h (+2/-1)
src/notify-cpp/CMakeLists.txt (+4/-1)
src/notify-cpp/notification-manager.cpp (+76/-0)
src/notify-cpp/notification-manager.h (+67/-0)
src/notify-cpp/notification.cpp (+138/-61)
src/notify-cpp/notification.h (+43/-22)
src/notify-cpp/snapdecision/sim-unlock.cpp (+41/-29)
src/notify-cpp/snapdecision/sim-unlock.h (+4/-3)
src/qdbus-stubs/dbus-types.h (+6/-0)
tests/integration/indicator-network-test-base.h (+5/-1)
tests/integration/test-indicator.cpp (+210/-152)
tests/unit/secret-agent/test-secret-agent.cpp (+4/-2)
To merge this branch: bzr merge lp:~pete-woods/indicator-network/sim-unlock-label-lp1449925
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Indicator Applet Developers Pending
Review via email: mp+266725@code.launchpad.net

Commit message

* Fix SIM PIN unlock dialog mis-titled
* Move from libnotify to internal notify-cpp

Description of the change

* Fix SIM PIN unlock dialog mis-titled
* Move from libnotify to internal notify-cpp

To post a comment you must log in.
502. By Pete Woods

Sync GCC5 landing

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
503. By Pete Woods

Add hotspot management.
Approved by: PS Jenkins bot

504. By Pete Woods

Hold a wakelock when the hotspot is active. Fixes: #1458046
Approved by: PS Jenkins bot

505. By Pete Woods

Simplify wifi/flight toggles
Approved by: PS Jenkins bot

506. By Pete Woods

Don't show access points when hotspot is enabled Fixes: #1478160
Approved by: PS Jenkins bot

507. By Pete Woods

Seed the random number generator Fixes: #1478157

508. By CI Train Bot Account

Releasing 0.5.2+15.10.20150810.1-0ubuntu1

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-06-22 08:25:05 +0000
3+++ CMakeLists.txt 2015-08-12 13:44:19 +0000
4@@ -60,13 +60,6 @@
5 )
6 include_directories(${OFONO_INCLUDE_DIRS})
7
8-set(NOTIFY_REQUIRED_VERSION 0.7.5)
9-pkg_check_modules(
10- NOTIFY REQUIRED
11- libnotify>=${NOTIFY_REQUIRED_VERSION}
12-)
13-include_directories(${NOTIFY_INCLUDE_DIRS})
14-
15 find_package(Qt5Core REQUIRED)
16 include_directories(${Qt5Core_INCLUDE_DIRS})
17
18
19=== modified file 'debian/control'
20--- debian/control 2015-07-20 18:48:44 +0000
21+++ debian/control 2015-08-12 13:44:19 +0000
22@@ -12,7 +12,6 @@
23 graphviz,
24 intltool,
25 libglib2.0-dev,
26- libnotify-dev,
27 #///! TODO: The next line should be removed once all dependancy on qmenumodel is removed
28 libqmenumodel-dev,
29 libqofono-dev,
30
31=== modified file 'src/indicator/CMakeLists.txt'
32--- src/indicator/CMakeLists.txt 2015-07-28 08:27:11 +0000
33+++ src/indicator/CMakeLists.txt 2015-08-12 13:44:19 +0000
34@@ -101,7 +101,6 @@
35 qpowerd
36 ${DBUSCPP_LIBRARIES}
37 ${GLIB_LIBRARIES}
38- ${NOTIFY_LIBRARIES}
39 ${QOFONO_LIBRARIES}
40 )
41
42
43=== modified file 'src/indicator/agent/PasswordMenu.cpp'
44--- src/indicator/agent/PasswordMenu.cpp 2015-04-15 15:04:51 +0000
45+++ src/indicator/agent/PasswordMenu.cpp 2015-08-12 13:44:19 +0000
46@@ -19,9 +19,12 @@
47 #include <agent/PasswordMenu.h>
48 #include <gio/gio.h>
49
50+#include <iostream>
51 #include <QString>
52 #include <QDebug>
53
54+using namespace std;
55+
56 namespace agent
57 {
58 namespace
59@@ -51,7 +54,7 @@
60 void passwordChanged(GVariant *variant) {
61 m_password = QString::fromUtf8(g_variant_get_string(variant, 0));
62 if (qEnvironmentVariableIsSet("SECRET_AGENT_DEBUG_PASSWORD")) {
63- qDebug() << "Password received";
64+ cout << "Password received" << endl;
65 }
66 }
67
68
69=== modified file 'src/indicator/agent/SecretAgent.cpp'
70--- src/indicator/agent/SecretAgent.cpp 2015-04-21 10:59:52 +0000
71+++ src/indicator/agent/SecretAgent.cpp 2015-08-12 13:44:19 +0000
72@@ -19,7 +19,7 @@
73 #include <agent/SecretAgent.h>
74 #include <agent/SecretRequest.h>
75 #include <AgentManagerInterface.h>
76-#include <NotificationsInterface.h>
77+#include <notify-cpp/notification-manager.h>
78 #include <SecretAgentAdaptor.h>
79
80 #include <NetworkManager.h>
81@@ -34,13 +34,13 @@
82 Q_OBJECT
83
84 public:
85- Priv(const QDBusConnection &systemConnection,
86+ Priv(notify::NotificationManager::SPtr notificationManager, const QDBusConnection &systemConnection,
87 const QDBusConnection &sessionConnection) :
88 m_systemConnection(systemConnection),
89 m_sessionConnection(sessionConnection),
90 m_managerWatcher(NM_DBUS_SERVICE, m_systemConnection),
91 m_agentManager(NM_DBUS_SERVICE, NM_DBUS_PATH_AGENT_MANAGER, m_systemConnection),
92- m_notifications("org.freedesktop.Notifications", "/org/freedesktop/Notifications", m_sessionConnection),
93+ m_notifications(notificationManager),
94 m_request(nullptr) {
95 }
96
97@@ -64,14 +64,15 @@
98
99 OrgFreedesktopNetworkManagerAgentManagerInterface m_agentManager;
100
101- OrgFreedesktopNotificationsInterface m_notifications;
102+ notify::NotificationManager::SPtr m_notifications;
103
104 std::shared_ptr<SecretRequest> m_request;
105 };
106
107-SecretAgent::SecretAgent(const QDBusConnection &systemConnection,
108+SecretAgent::SecretAgent(notify::NotificationManager::SPtr notificationManager,
109+ const QDBusConnection &systemConnection,
110 const QDBusConnection &sessionConnection, QObject *parent) :
111- QObject(parent), d(new Priv(systemConnection, sessionConnection))
112+ QObject(parent), d(new Priv(notificationManager, systemConnection, sessionConnection))
113 {
114 // Memory managed by Qt
115 new SecretAgentAdaptor(this);
116@@ -182,7 +183,7 @@
117 Q_UNUSED(connectionPath);
118 }
119
120-OrgFreedesktopNotificationsInterface & SecretAgent::notifications() {
121+notify::NotificationManager::SPtr SecretAgent::notifications() {
122 return d->m_notifications;
123 }
124
125
126=== modified file 'src/indicator/agent/SecretAgent.h'
127--- src/indicator/agent/SecretAgent.h 2015-04-21 10:59:52 +0000
128+++ src/indicator/agent/SecretAgent.h 2015-08-12 13:44:19 +0000
129@@ -26,9 +26,13 @@
130 #include <QDBusContext>
131 #include <QMap>
132
133-class OrgFreedesktopNotificationsInterface;
134 class SecretAgentAdaptor;
135
136+namespace notify
137+{
138+class NotificationManager;
139+}
140+
141 namespace agent
142 {
143
144@@ -58,8 +62,9 @@
145 static constexpr char const* KEY_MGMT_WPA_PSK = "wpa-psk";
146 static constexpr char const* KEY_MGMT_NONE = "none";
147
148- explicit SecretAgent(const QDBusConnection &systemConnection,
149- const QDBusConnection &sessionConnection, QObject *parent = 0);
150+ explicit SecretAgent(std::shared_ptr<notify::NotificationManager> notificationManager,
151+ const QDBusConnection &systemConnection,
152+ const QDBusConnection &sessionConnection, QObject *parent = 0);
153
154 virtual ~SecretAgent();
155
156@@ -79,7 +84,7 @@
157 void SaveSecrets(const QVariantDictMap &connection,
158 const QDBusObjectPath &connectionPath);
159
160- OrgFreedesktopNotificationsInterface & notifications();
161+ std::shared_ptr<notify::NotificationManager> notifications();
162
163 protected:
164 class Priv;
165
166=== modified file 'src/indicator/agent/SecretRequest.cpp'
167--- src/indicator/agent/SecretRequest.cpp 2015-04-21 10:59:52 +0000
168+++ src/indicator/agent/SecretRequest.cpp 2015-08-12 13:44:19 +0000
169@@ -20,7 +20,7 @@
170 #include <agent/SecretAgent.h>
171 #include <util/localisation.h>
172
173-#include <NotificationsInterface.h>
174+#include <notify-cpp/notification-manager.h>
175
176 namespace agent
177 {
178@@ -35,12 +35,6 @@
179 settingName), m_hints(hints), m_flags(flags), m_message(
180 message), m_menu() {
181
182- connect(&m_secretAgent.notifications(),
183- SIGNAL(ActionInvoked(uint, const QString &)), this,
184- SLOT(actionInvoked(uint, const QString &)));
185-
186- connect(&m_secretAgent.notifications(), SIGNAL(NotificationClosed(uint, uint)), this, SLOT(notificationClosed(uint, uint)));
187-
188 // indicate to the notification-daemon, that we want to use snap-decisions
189 QVariantMap notificationHints;
190 notificationHints["x-canonical-snap-decisions"] = "true";
191@@ -74,29 +68,28 @@
192 subject = _("WEP");
193 }
194
195- m_notificationId = m_secretAgent.notifications().Notify("indicator-network",
196- 0, "wifi-full-secure",
197+ m_notification = m_secretAgent.notifications()->notify(
198 title.arg(conn[SecretAgent::CONNECTION_ID].toString()), subject,
199+ "wifi-full-secure",
200 QStringList() << "connect_id" << _("Connect") << "cancel_id"
201 << _("Cancel"), notificationHints, 0);
202+
203+ connect(m_notification.get(), &notify::Notification::actionInvoked, this,
204+ &SecretRequest::actionInvoked);
205+
206+ connect(m_notification.get(), &notify::Notification::closed, this,
207+ &SecretRequest::notificationClosed);
208+
209+ m_notification->show();
210 }
211
212 SecretRequest::~SecretRequest() {
213- /* Close the notification if it's open */
214- if (m_notificationId != 0) {
215- m_secretAgent.notifications().CloseNotification(m_notificationId).waitForFinished();
216- m_notificationId = 0;
217- }
218 }
219
220 /* Called when the user submits a password */
221-void SecretRequest::actionInvoked(uint id, const QString &actionKey) {
222- // Ignore other requests' notifications
223- if (id != m_notificationId) {
224- return;
225- }
226+void SecretRequest::actionInvoked(const QString &actionKey) {
227
228- m_notificationId = 0;
229+ m_notification.reset();
230
231 if (actionKey != "connect_id") {
232 m_secretAgent.FinishGetSecrets(*this, true);
233@@ -121,15 +114,10 @@
234 }
235
236 /* Called when the user closes the dialog */
237-void SecretRequest::notificationClosed(uint id, uint reason) {
238+void SecretRequest::notificationClosed(uint reason) {
239 Q_UNUSED(reason);
240
241- // Ignore other requests' notifications
242- if (id != m_notificationId) {
243- return;
244- }
245-
246- m_notificationId = 0;
247+ m_notification.reset();
248
249 m_secretAgent.FinishGetSecrets(*this, true);
250 }
251
252=== modified file 'src/indicator/agent/SecretRequest.h'
253--- src/indicator/agent/SecretRequest.h 2015-04-21 10:59:52 +0000
254+++ src/indicator/agent/SecretRequest.h 2015-08-12 13:44:19 +0000
255@@ -20,6 +20,7 @@
256
257 #include <dbus-types.h>
258 #include <agent/PasswordMenu.h>
259+#include <notify-cpp/notification.h>
260
261 #include <QDBusMessage>
262 #include <QDBusObjectPath>
263@@ -42,8 +43,8 @@
264 virtual ~SecretRequest();
265
266 public Q_SLOTS:
267- void actionInvoked(uint id, const QString &actionKey);
268- void notificationClosed(uint id, uint reason);
269+ void actionInvoked(const QString &actionKey);
270+ void notificationClosed(uint reason);
271
272 public:
273 const QVariantDictMap & connection() const;
274@@ -51,7 +52,7 @@
275 const QDBusMessage & message() const;
276
277 protected:
278- unsigned int m_notificationId;
279+ notify::Notification::UPtr m_notification;
280
281 SecretAgent &m_secretAgent;
282
283
284=== modified file 'src/indicator/factory.cpp'
285--- src/indicator/factory.cpp 2015-04-15 15:04:51 +0000
286+++ src/indicator/factory.cpp 2015-08-12 13:44:19 +0000
287@@ -17,9 +17,11 @@
288 * Pete Woods <pete.woods@canonical.com>
289 */
290
291+#include <config.h>
292 #include <factory.h>
293
294 #include <nmofono/manager-impl.h>
295+#include <notify-cpp/notification-manager.h>
296
297 using namespace std;
298
299@@ -29,6 +31,17 @@
300
301 SessionBus::Ptr m_sessionBus;
302
303+ notify::NotificationManager::SPtr m_notificationManager;
304+
305+ notify::NotificationManager::SPtr singletonNotificationManager()
306+ {
307+ if (!m_notificationManager)
308+ {
309+ m_notificationManager = make_shared<notify::NotificationManager>(GETTEXT_PACKAGE);
310+ }
311+ return m_notificationManager;
312+ }
313+
314 SessionBus::Ptr singletonSessionBus()
315 {
316 if (!m_sessionBus)
317@@ -42,7 +55,9 @@
318 {
319 if (!m_nmofono)
320 {
321- m_nmofono = make_shared<nmofono::ManagerImpl>(QDBusConnection::systemBus());
322+ m_nmofono = make_shared<nmofono::ManagerImpl>(
323+ singletonNotificationManager(),
324+ QDBusConnection::systemBus());
325 }
326 return m_nmofono;
327 }
328@@ -117,7 +132,8 @@
329
330 agent::SecretAgent::UPtr Factory::newSecretAgent()
331 {
332- return make_unique<agent::SecretAgent>(QDBusConnection::systemBus(),
333+ return make_unique<agent::SecretAgent>(d->singletonNotificationManager(),
334+ QDBusConnection::systemBus(),
335 QDBusConnection::sessionBus());
336 }
337
338
339=== modified file 'src/indicator/main.cpp'
340--- src/indicator/main.cpp 2015-08-10 09:30:04 +0000
341+++ src/indicator/main.cpp 2015-08-12 13:44:19 +0000
342@@ -28,7 +28,6 @@
343 #include <ctime>
344
345 #include <glib.h>
346-#include <libnotify/notify.h>
347
348 #include <config.h>
349
350@@ -53,25 +52,17 @@
351 bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
352 textdomain(GETTEXT_PACKAGE);
353
354- notify_init(GETTEXT_PACKAGE);
355-
356 if (argc == 2 && QString("--print-address") == argv[1])
357 {
358 qDebug() << QDBusConnection::systemBus().baseService();
359 }
360
361- int result = 0;
362- {
363- Factory factory;
364- auto menu = factory.newMenuBuilder();
365- auto secretAgent = factory.newSecretAgent();
366- auto connectivityService = factory.newConnectivityService();
367-
368- QObject::connect(connectivityService.get(), &ConnectivityService::unlockAllModems, menu.get(), &MenuBuilder::unlockAllModems);
369- QObject::connect(connectivityService.get(), &ConnectivityService::unlockModem, menu.get(), &MenuBuilder::unlockModem);
370- result = app.exec();
371- }
372- notify_uninit();
373-
374- return result;
375+ Factory factory;
376+ auto menu = factory.newMenuBuilder();
377+ auto secretAgent = factory.newSecretAgent();
378+ auto connectivityService = factory.newConnectivityService();
379+
380+ QObject::connect(connectivityService.get(), &ConnectivityService::unlockAllModems, menu.get(), &MenuBuilder::unlockAllModems);
381+ QObject::connect(connectivityService.get(), &ConnectivityService::unlockModem, menu.get(), &MenuBuilder::unlockModem);
382+ return app.exec();
383 }
384
385=== modified file 'src/indicator/nmofono/manager-impl.cpp'
386--- src/indicator/nmofono/manager-impl.cpp 2015-08-07 08:55:50 +0000
387+++ src/indicator/nmofono/manager-impl.cpp 2015-08-12 13:44:19 +0000
388@@ -31,6 +31,7 @@
389 #include <qofono-qt5/qofonomodem.h>
390 #undef slots
391
392+#include <notify-cpp/notification-manager.h>
393 #include <notify-cpp/snapdecision/sim-unlock.h>
394 #include <sim-unlock-dialog.h>
395 #include <util/qhash-sharedptr.h>
396@@ -224,11 +225,11 @@
397 Q_EMIT statusUpdated(d->m_status);
398 }
399
400-ManagerImpl::ManagerImpl(const QDBusConnection& systemConnection) : d(new ManagerImpl::Private(*this))
401+ManagerImpl::ManagerImpl(notify::NotificationManager::SPtr notificationManager, const QDBusConnection& systemConnection) : d(new ManagerImpl::Private(*this))
402 {
403 d->nm = make_shared<OrgFreedesktopNetworkManagerInterface>(NM_DBUS_SERVICE, NM_DBUS_PATH, systemConnection);
404
405- d->m_unlockDialog = make_shared<SimUnlockDialog>();
406+ d->m_unlockDialog = make_shared<SimUnlockDialog>(notificationManager);
407 connect(d->m_unlockDialog.get(), &SimUnlockDialog::ready, d.get(), &Private::sim_unlock_ready);
408
409 d->m_ofono = make_shared<QOfonoManager>();
410
411=== modified file 'src/indicator/nmofono/manager-impl.h'
412--- src/indicator/nmofono/manager-impl.h 2015-08-05 15:14:28 +0000
413+++ src/indicator/nmofono/manager-impl.h 2015-08-12 13:44:19 +0000
414@@ -25,6 +25,11 @@
415 #include <QDBusObjectPath>
416 #include <QVariantMap>
417
418+namespace notify
419+{
420+class NotificationManager;
421+}
422+
423 namespace nmofono {
424 class Manager;
425
426@@ -40,7 +45,7 @@
427 public:
428 typedef std::shared_ptr<ManagerImpl> Ptr;
429
430- ManagerImpl(const QDBusConnection& systemBus);
431+ ManagerImpl(std::shared_ptr<notify::NotificationManager> notificationManager, const QDBusConnection& systemBus);
432
433 // Public API
434 void setFlightMode(bool) override;
435
436=== modified file 'src/indicator/sim-unlock-dialog.cpp'
437--- src/indicator/sim-unlock-dialog.cpp 2015-06-18 12:30:09 +0000
438+++ src/indicator/sim-unlock-dialog.cpp 2015-08-12 13:44:19 +0000
439@@ -19,7 +19,7 @@
440
441 #include "sim-unlock-dialog.h"
442
443-#include <notify-cpp/notification.h>
444+#include <notify-cpp/notification-manager.h>
445 #include <notify-cpp/snapdecision/sim-unlock.h>
446 #include <util/localisation.h>
447
448@@ -196,7 +196,7 @@
449 m_sd->showPopup(output.str(), closed);
450 }
451
452- Private(SimUnlockDialog& parent);
453+ Private(SimUnlockDialog& parent, notify::NotificationManager::SPtr);
454
455 public Q_SLOTS:
456 void update();
457@@ -205,8 +205,6 @@
458
459 void pinEntered(const QString& pin);
460
461- void closed();
462-
463 void reset();
464
465 void pinSuccess()
466@@ -244,13 +242,12 @@
467 }
468 };
469
470-SimUnlockDialog::Private::Private(SimUnlockDialog& parent)
471+SimUnlockDialog::Private::Private(SimUnlockDialog& parent, notify::NotificationManager::SPtr notificationManager)
472 : p(parent), m_doCleanUp{true}
473 {
474- m_sd = std::make_shared<notify::snapdecision::SimUnlock>();
475+ m_sd = make_shared<notify::snapdecision::SimUnlock>(notificationManager);
476 connect(m_sd.get(), &notify::snapdecision::SimUnlock::cancelled, this, &Private::cancelled);
477 connect(m_sd.get(), &notify::snapdecision::SimUnlock::pinEntered, this, &Private::pinEntered);
478- connect(m_sd.get(), &notify::snapdecision::SimUnlock::closed, this, &Private::closed);
479
480 reset();
481 }
482@@ -310,6 +307,7 @@
483 break;
484 }
485
486+
487 m_sd->setPinMinMax(lengths[type]);
488
489 std::string attempts;
490@@ -386,12 +384,6 @@
491 void
492 SimUnlockDialog::Private::cancelled()
493 {
494- m_sd->close();
495-}
496-
497-void
498-SimUnlockDialog::Private::closed()
499-{
500 reset();
501 }
502
503@@ -421,8 +413,8 @@
504 m_doCleanUp = true;
505 }
506
507-SimUnlockDialog::SimUnlockDialog() :
508- d(new Private(*this))
509+SimUnlockDialog::SimUnlockDialog(notify::NotificationManager::SPtr notificationManager) :
510+ d(new Private(*this, notificationManager))
511 {
512 }
513
514@@ -475,9 +467,6 @@
515 pukRetries = retries[wwan::Modem::PinType::puk];
516 }
517
518- qDebug() << __PRETTY_FUNCTION__ << modem->name() << "pinRetries ="
519- << pinRetries << "pukRetries =" << pukRetries;
520-
521 // remind the user
522 if (type == wwan::Modem::PinType::pin && pinRetries == 1)
523 {
524
525=== modified file 'src/indicator/sim-unlock-dialog.h'
526--- src/indicator/sim-unlock-dialog.h 2015-04-24 08:47:08 +0000
527+++ src/indicator/sim-unlock-dialog.h 2015-08-12 13:44:19 +0000
528@@ -20,6 +20,7 @@
529 #pragma once
530
531 #include <nmofono/wwan/modem.h>
532+#include <notify-cpp/notification-manager.h>
533
534 #include <memory>
535 #include <QObject>
536@@ -42,7 +43,7 @@
537 };
538
539 typedef std::shared_ptr<SimUnlockDialog> Ptr;
540- SimUnlockDialog();
541+ SimUnlockDialog(notify::NotificationManager::SPtr notificationManager);
542 ~SimUnlockDialog();
543
544 void unlock(nmofono::wwan::Modem::Ptr modem);
545
546=== modified file 'src/notify-cpp/CMakeLists.txt'
547--- src/notify-cpp/CMakeLists.txt 2015-05-12 09:07:46 +0000
548+++ src/notify-cpp/CMakeLists.txt 2015-08-12 13:44:19 +0000
549@@ -1,12 +1,15 @@
550 include_directories("${CMAKE_SOURCE_DIR}/src/")
551+include_directories("${CMAKE_BINARY_DIR}/src/qdbus-stubs")
552+include_directories("${CMAKE_SOURCE_DIR}/src/qdbus-stubs")
553
554 set(NOTIFY_CPP_SOURCES
555 notification.cpp
556+ notification-manager.cpp
557 snapdecision/sim-unlock.cpp
558 )
559
560 add_library(notify_cpp STATIC ${NOTIFY_CPP_SOURCES})
561 target_link_libraries(
562 notify_cpp
563- ${GLIB_LIBRARIES}
564+ qdbus-stubs
565 )
566
567=== added file 'src/notify-cpp/notification-manager.cpp'
568--- src/notify-cpp/notification-manager.cpp 1970-01-01 00:00:00 +0000
569+++ src/notify-cpp/notification-manager.cpp 2015-08-12 13:44:19 +0000
570@@ -0,0 +1,76 @@
571+/*
572+ * Copyright © 2015 Canonical Ltd.
573+ *
574+ * This program is free software: you can redistribute it and/or modify it
575+ * under the terms of the GNU Lesser General Public License version 3,
576+ * as published by the Free Software Foundation.
577+ *
578+ * This program is distributed in the hope that it will be useful,
579+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
580+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
581+ * GNU Lesser General Public License for more details.
582+ *
583+ * You should have received a copy of the GNU Lesser General Public License
584+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
585+ *
586+ * Authors:
587+ * Pete Woods <pete.woods@canonical.com>
588+ */
589+
590+#include <notification-manager.h>
591+#include <NotificationsInterface.h>
592+#include <QDebug>
593+
594+using namespace std;
595+
596+namespace notify
597+{
598+
599+class NotificationManager::Priv
600+{
601+public:
602+ QString m_appName;
603+
604+ shared_ptr<OrgFreedesktopNotificationsInterface> m_notificationInterface;
605+};
606+
607+NotificationManager::NotificationManager(const QString &appName,
608+ const QDBusConnection& sessionConnection) :
609+ d(new Priv)
610+{
611+ d->m_appName = appName;
612+ d->m_notificationInterface = make_shared<
613+ OrgFreedesktopNotificationsInterface>(DBusTypes::NOTIFY_DBUS_NAME,
614+ DBusTypes::NOTIFY_DBUS_PATH,
615+ sessionConnection);
616+
617+ d->m_notificationInterface->GetServerInformation();
618+
619+ connect(d->m_notificationInterface.get(),
620+ &OrgFreedesktopNotificationsInterface::ActionInvoked, this,
621+ &NotificationManager::actionInvoked);
622+
623+ connect(d->m_notificationInterface.get(),
624+ &OrgFreedesktopNotificationsInterface::NotificationClosed, this,
625+ &NotificationManager::notificationClosed);
626+
627+ connect(d->m_notificationInterface.get(),
628+ &OrgFreedesktopNotificationsInterface::dataChanged, this,
629+ &NotificationManager::dataChanged);
630+}
631+
632+NotificationManager::~NotificationManager()
633+{
634+}
635+
636+Notification::UPtr
637+NotificationManager::notify(const QString &summary, const QString &body,
638+ const QString &icon, const QStringList &actions,
639+ const QVariantMap &hints, int expireTimeout)
640+{
641+ return make_unique<Notification>(d->m_appName, summary, body, icon, actions,
642+ hints, expireTimeout,
643+ d->m_notificationInterface);
644+}
645+
646+}
647
648=== added file 'src/notify-cpp/notification-manager.h'
649--- src/notify-cpp/notification-manager.h 1970-01-01 00:00:00 +0000
650+++ src/notify-cpp/notification-manager.h 2015-08-12 13:44:19 +0000
651@@ -0,0 +1,67 @@
652+/*
653+ * Copyright © 2015 Canonical Ltd.
654+ *
655+ * This program is free software: you can redistribute it and/or modify it
656+ * under the terms of the GNU Lesser General Public License version 3,
657+ * as published by the Free Software Foundation.
658+ *
659+ * This program is distributed in the hope that it will be useful,
660+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
661+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
662+ * GNU Lesser General Public License for more details.
663+ *
664+ * You should have received a copy of the GNU Lesser General Public License
665+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
666+ *
667+ * Authors:
668+ * Pete Woods <pete.woods@canonical.com>
669+ */
670+
671+#pragma once
672+
673+#include <memory>
674+#include <QDBusConnection>
675+#include <QObject>
676+#include <QString>
677+#include <QStringList>
678+#include <QVariantMap>
679+
680+#include <notify-cpp/notification.h>
681+
682+namespace notify
683+{
684+
685+class NotificationManager: public QObject
686+{
687+ Q_OBJECT
688+
689+public:
690+ typedef std::unique_ptr<NotificationManager> UPtr;
691+ typedef std::shared_ptr<NotificationManager> SPtr;
692+
693+ NotificationManager(const QString &appName,
694+ const QDBusConnection& sessionConnection = QDBusConnection::sessionBus());
695+
696+ ~NotificationManager();
697+
698+ Notification::UPtr notify(
699+ const QString &summary,
700+ const QString &body,
701+ const QString &icon,
702+ const QStringList &actions,
703+ const QVariantMap &hints,
704+ int expireTimeout = -1);
705+
706+Q_SIGNALS:
707+ void actionInvoked(uint id, const QString &action_key);
708+
709+ void notificationClosed(uint id, uint reason);
710+
711+ void dataChanged(uint id);
712+
713+protected:
714+ class Priv;
715+ std::shared_ptr<Priv> d;
716+};
717+
718+}
719
720=== modified file 'src/notify-cpp/notification.cpp'
721--- src/notify-cpp/notification.cpp 2015-05-12 09:03:23 +0000
722+++ src/notify-cpp/notification.cpp 2015-08-12 13:44:19 +0000
723@@ -18,14 +18,17 @@
724 */
725
726 #include "notification.h"
727+#include <NotificationsInterface.h>
728
729-#include <libnotify/notify.h>
730 #include <QDebug>
731
732 using namespace notify;
733+using namespace std;
734
735-class notify::Notification::Private
736+class notify::Notification::Private: public QObject
737 {
738+ Q_OBJECT
739+
740 public:
741 Private(Notification& parent) :
742 p(parent)
743@@ -34,76 +37,135 @@
744
745 Notification& p;
746
747+ QString m_appName;
748 QString m_summary;
749 QString m_body;
750 QString m_icon;
751-
752- std::unique_ptr<NotifyNotification, GObjectDeleter> m_notification;
753-
754- static void closed_cb(NotifyNotification *,
755- gpointer user_data)
756- {
757- Private *that = static_cast<Private *>(user_data);
758- Q_EMIT that->p.closed();
759- }
760-
761- gulong disconnectId = 0;
762+ QStringList m_actions;
763+ QVariantMap m_hints;
764+ int m_expireTimeout = 0;
765+ uint m_id = 0;
766+
767+ shared_ptr<OrgFreedesktopNotificationsInterface> m_notificationsInterface;
768+
769+ bool m_open = false;
770+ bool m_dirty = false;
771+
772+public Q_SLOTS:
773+ void notificationClosed(uint id, uint reason)
774+ {
775+ if (id == m_id)
776+ {
777+ m_open = false;
778+ Q_EMIT p.closed(reason);
779+ }
780+ }
781+
782+ void actionInvoked(uint id, const QString& name)
783+ {
784+ if (id == m_id)
785+ {
786+ Q_EMIT p.actionInvoked(name);
787+ }
788+ }
789 };
790
791-Notification::Notification(const QString &summary,
792- const QString &body,
793- const QString &icon)
794+Notification::Notification(
795+ const QString& appName, const QString &summary, const QString &body,
796+ const QString &icon, const QStringList &actions,
797+ const QVariantMap &hints, int expireTimeout,
798+ shared_ptr<OrgFreedesktopNotificationsInterface> notificationsInterface)
799 {
800 d.reset(new Private(*this));
801+ d->m_appName = appName;
802 d->m_summary = summary;
803 d->m_body = body;
804 d->m_icon = icon;
805-
806- d->m_notification.reset(notify_notification_new(summary.toUtf8().constData(), body.toUtf8().constData(), icon.toUtf8().constData()));
807- d->disconnectId = g_signal_connect(d->m_notification.get(), "closed", G_CALLBACK(Private::closed_cb), d.get());
808+ d->m_actions = actions;
809+ d->m_hints = hints;
810+ d->m_expireTimeout = expireTimeout;
811+ d->m_notificationsInterface = notificationsInterface;
812+
813+ connect(d->m_notificationsInterface.get(), &OrgFreedesktopNotificationsInterface::NotificationClosed, d.get(), &Private::notificationClosed);
814+
815+ connect(d->m_notificationsInterface.get(), &OrgFreedesktopNotificationsInterface::ActionInvoked, d.get(), &Private::actionInvoked);
816 }
817
818 Notification::~Notification()
819 {
820- g_signal_handler_disconnect(d->m_notification.get(), d->disconnectId);
821-
822-// TODO Uncomment this when the notification service is more robust
823-// GError* error = nullptr;
824-// if (notify_notification_close(d->m_notification.get(), &error) == FALSE)
825-// {
826-// qWarning() << __PRETTY_FUNCTION__ << error->message;
827-// g_error_free(error);
828-// }
829+ if (d->m_id > 0 && d->m_open)
830+ {
831+ auto reply = d->m_notificationsInterface->CloseNotification(d->m_id);
832+ reply.waitForFinished();
833+ if (reply.isError())
834+ {
835+ qCritical() << __PRETTY_FUNCTION__ << reply.error().message();
836+ }
837+ }
838 }
839
840 QString
841-Notification::summary()
842+Notification::summary() const
843 {
844 return d->m_summary;
845 }
846
847 QString
848-Notification::body()
849+Notification::body() const
850 {
851 return d->m_body;
852 }
853
854 QString
855-Notification::icon()
856+Notification::icon() const
857 {
858 return d->m_icon;
859 }
860
861-void
862-Notification::setHint(const QString &key, Variant value)
863-{
864- notify_notification_set_hint(d->m_notification.get(), key.toUtf8().constData(), value);
865-}
866-
867-void
868-Notification::setHintString(const QString &key, const QString &value)
869-{
870- notify_notification_set_hint_string(d->m_notification.get(), key.toUtf8().constData(), value.toUtf8().constData());
871+QStringList
872+Notification::actions() const
873+{
874+ return d->m_actions;
875+}
876+
877+QVariantMap
878+Notification::hints() const
879+{
880+ return d->m_hints;
881+}
882+
883+void
884+Notification::addHint(const QString &key, const QVariant& value)
885+{
886+ d->m_hints[key] = value;
887+ d->m_dirty = true;
888+ Q_EMIT hintsUpdated(d->m_hints);
889+}
890+
891+void
892+Notification::setHints(const QVariantMap& hints)
893+{
894+ if (d->m_hints == hints)
895+ {
896+ return;
897+ }
898+
899+ d->m_hints = hints;
900+ d->m_dirty = true;
901+ Q_EMIT hintsUpdated(d->m_hints);
902+}
903+
904+void
905+Notification::setActions(const QStringList& actions)
906+{
907+ if (d->m_actions == actions)
908+ {
909+ return;
910+ }
911+
912+ d->m_actions = actions;
913+ d->m_dirty = true;
914+ Q_EMIT actionsUpdated(d->m_actions);
915 }
916
917 void
918@@ -115,7 +177,7 @@
919 }
920
921 d->m_summary = summary;
922- g_object_set(d->m_notification.get(), "summary", d->m_summary.toUtf8().constData(), nullptr);
923+ d->m_dirty = true;
924 Q_EMIT summaryUpdated(d->m_summary);
925 }
926
927@@ -128,7 +190,7 @@
928 }
929
930 d->m_body = body;
931- g_object_set(d->m_notification.get(), "body", d->m_body.toUtf8().constData(), nullptr);
932+ d->m_dirty = true;
933 Q_EMIT bodyUpdated(d->m_body);
934 }
935
936@@ -141,35 +203,50 @@
937 }
938
939 d->m_icon = icon;
940- g_object_set(d->m_notification.get(), "icon", d->m_icon.toUtf8().constData(), nullptr);
941+ d->m_dirty = true;
942 Q_EMIT iconUpdated(d->m_icon);
943 }
944
945 void
946-Notification::update()
947-{
948- notify_notification_update(d->m_notification.get(), d->m_summary.toUtf8().constData(),
949- d->m_body.toUtf8().constData(), d->m_icon.toUtf8().constData());
950-}
951-
952-void
953 Notification::show()
954 {
955- GError *error = nullptr;
956- notify_notification_show(d->m_notification.get(), &error);
957- if (error) {
958- qCritical() << __PRETTY_FUNCTION__ << error->message;
959- g_error_free(error);
960+ if (d->m_dirty || !d->m_open)
961+ {
962+ auto reply = d->m_notificationsInterface->Notify(d->m_appName, d->m_id,
963+ d->m_icon, d->m_summary,
964+ d->m_body, d->m_actions,
965+ d->m_hints,
966+ d->m_expireTimeout);
967+ reply.waitForFinished();
968+ if (reply.isError())
969+ {
970+ qCritical() << __PRETTY_FUNCTION__ << reply.error().message();
971+ }
972+ else
973+ {
974+ d->m_id = reply;
975+ d->m_dirty = false;
976+ d->m_open = true;
977+ }
978 }
979 }
980
981 void
982 Notification::close()
983 {
984- GError *error = nullptr;
985- notify_notification_close(d->m_notification.get(), &error);
986- if (error) {
987- qCritical() << __PRETTY_FUNCTION__ << error->message;
988- g_error_free(error);
989+ if (d->m_id > 0)
990+ {
991+ auto reply = d->m_notificationsInterface->CloseNotification(d->m_id);
992+ reply.waitForFinished();
993+ if (reply.isError())
994+ {
995+ qCritical() << __PRETTY_FUNCTION__ << reply.error().message();
996+ }
997+ else
998+ {
999+ d->m_open = false;
1000+ }
1001 }
1002 }
1003+
1004+#include "notification.moc"
1005
1006=== modified file 'src/notify-cpp/notification.h'
1007--- src/notify-cpp/notification.h 2015-04-24 08:47:08 +0000
1008+++ src/notify-cpp/notification.h 2015-08-12 13:44:19 +0000
1009@@ -25,7 +25,12 @@
1010
1011 #include <QObject>
1012
1013-namespace notify {
1014+class OrgFreedesktopNotificationsInterface;
1015+
1016+namespace notify
1017+{
1018+
1019+class NotificationManager;
1020
1021 class Notification: public QObject
1022 {
1023@@ -36,35 +41,38 @@
1024
1025 public:
1026
1027- typedef std::shared_ptr<Notification> Ptr;
1028+ typedef std::unique_ptr<Notification> UPtr;
1029+ typedef std::shared_ptr<Notification> SPtr;
1030
1031- Notification() = delete;
1032- Notification(const QString &summary,
1033- const QString &body,
1034- const QString &icon);
1035 virtual ~Notification();
1036
1037 /// @todo remember show() after set().
1038- Q_PROPERTY(QString summary READ summary NOTIFY summaryUpdated)
1039- QString summary();
1040-
1041- /// @todo remember show() after set().
1042- Q_PROPERTY(QString body READ body NOTIFY bodyUpdated)
1043- QString body();
1044-
1045- /// @todo remember show() after set().
1046- Q_PROPERTY(QString icon READ icon NOTIFY iconUpdated)
1047- QString icon();
1048-
1049- void update();
1050+ Q_PROPERTY(QString summary READ summary WRITE setSummary NOTIFY summaryUpdated)
1051+ QString summary() const;
1052+
1053+ /// @todo remember show() after set().
1054+ Q_PROPERTY(QString body READ body WRITE setBody NOTIFY bodyUpdated)
1055+ QString body() const;
1056+
1057+ /// @todo remember show() after set().
1058+ Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconUpdated)
1059+ QString icon() const;
1060+
1061+ Q_PROPERTY(QStringList actions READ actions WRITE setActions NOTIFY actionsUpdated)
1062+ QStringList actions() const;
1063+
1064+ Q_PROPERTY(QVariantMap hints READ hints WRITE setHints NOTIFY hintsUpdated)
1065+ QVariantMap hints() const;
1066
1067 void show();
1068 void close();
1069
1070 public Q_SLOTS:
1071- void setHint(const QString &key, Variant value);
1072-
1073- void setHintString(const QString &key, const QString &value);
1074+ void setActions(const QStringList& actions);
1075+
1076+ void setHints(const QVariantMap& hints);
1077+
1078+ void addHint(const QString &key, const QVariant& value);
1079
1080 void setSummary(const QString& summary);
1081
1082@@ -73,12 +81,25 @@
1083 void setIcon(const QString& icon);
1084
1085 Q_SIGNALS:
1086- void closed();
1087+ void closed(uint reason);
1088+
1089+ void hintsUpdated(const QVariantMap&);
1090+
1091+ void actionsUpdated(const QStringList&);
1092
1093 void summaryUpdated(const QString&);
1094
1095 void bodyUpdated(const QString&);
1096
1097 void iconUpdated(const QString&);
1098+
1099+ void actionInvoked(const QString& name);
1100+
1101+public:
1102+ Notification(const QString& appName,
1103+ const QString &summary, const QString &body,
1104+ const QString &icon, const QStringList &actions,
1105+ const QVariantMap &hints, int expireTimeout,
1106+ std::shared_ptr<OrgFreedesktopNotificationsInterface> notificationsInterface);
1107 };
1108 }
1109
1110=== modified file 'src/notify-cpp/snapdecision/sim-unlock.cpp'
1111--- src/notify-cpp/snapdecision/sim-unlock.cpp 2015-05-12 09:02:50 +0000
1112+++ src/notify-cpp/snapdecision/sim-unlock.cpp 2015-08-12 13:44:19 +0000
1113@@ -18,7 +18,6 @@
1114 */
1115
1116 #include "sim-unlock.h"
1117-#include <notify-cpp/notification.h>
1118
1119 #include "menumodel-cpp/menu.h"
1120 #include "menumodel-cpp/menu-exporter.h"
1121@@ -31,6 +30,7 @@
1122 #include <QDebug>
1123
1124 using namespace notify::snapdecision;
1125+using namespace std;
1126
1127 class SimUnlock::Private: public QObject
1128 {
1129@@ -39,8 +39,8 @@
1130 public:
1131 SimUnlock& p;
1132
1133- Notification::Ptr m_notification;
1134- Notification::Ptr m_pending;
1135+ NotificationManager::SPtr m_notificationManager;
1136+ Notification::UPtr m_notification;
1137
1138 QString m_title;
1139 QString m_body;
1140@@ -48,7 +48,7 @@
1141
1142 std::shared_ptr<SessionBus> m_sessionBus;
1143
1144- std::map<std::string, Variant> m_modelPaths;
1145+ QVariantMap m_modelPaths;
1146
1147 Action::Ptr m_notifyAction;
1148 Action::Ptr m_pinMinMaxAction;
1149@@ -65,11 +65,6 @@
1150 std::function<void()> m_pendingPopupClosed;
1151
1152 public Q_SLOTS:
1153- void notificationClosed()
1154- {
1155- resetNotification(m_title, m_body);
1156- Q_EMIT p.closed();
1157- }
1158
1159 void resetActionStates()
1160 {
1161@@ -90,16 +85,31 @@
1162 }
1163 }
1164
1165- void resetNotification(const QString &title,
1166- const QString &body)
1167+ void resetNotification()
1168 {
1169- m_pending = m_notification;
1170- m_notification = std::make_shared<notify::Notification>(title, body, "");
1171- m_notification->setHintString("x-canonical-snap-decisions", "true");
1172- m_notification->setHint("x-canonical-snap-decisions-timeout", TypedVariant<std::int32_t>(std::numeric_limits<std::int32_t>::max()));
1173- m_notification->setHint("x-canonical-private-menu-model", TypedVariant<std::map<std::string, Variant>>(m_modelPaths));
1174+ QVariantMap hints({
1175+ { "x-canonical-snap-decisions", "true" },
1176+ { "x-canonical-snap-decisions-timeout", numeric_limits<int32_t>::max() },
1177+ { "x-canonical-private-menu-model", m_modelPaths }
1178+ });
1179+
1180+ if (m_notification)
1181+ {
1182+ m_notification->setSummary(m_title);
1183+ m_notification->setBody(m_body);
1184+ m_notification->setIcon("");
1185+ m_notification->setActions(QStringList());
1186+ m_notification->setHints(hints);
1187+ }
1188+ else
1189+ {
1190+ m_notification = m_notificationManager->notify(
1191+ m_title, m_body, "", QStringList(), hints);
1192+
1193+ connect(&p, &SimUnlock::titleUpdated, m_notification.get(), &Notification::setSummary);
1194+ connect(&p, &SimUnlock::bodyUpdated, m_notification.get(), &Notification::setBody);
1195+ }
1196 resetActionStates();
1197- connect(m_notification.get(), &Notification::closed, this, &Private::notificationClosed);
1198 }
1199
1200 void pinEntered(const Variant& state)
1201@@ -111,6 +121,7 @@
1202 {
1203 if (!parameter.as<bool>())
1204 {
1205+ p.close();
1206 Q_EMIT p.cancelled();
1207 }
1208 }
1209@@ -145,11 +156,13 @@
1210
1211 public:
1212 Private(SimUnlock& parent,
1213+ NotificationManager::SPtr notificationManager,
1214 const QString &title,
1215 const QString &body,
1216 std::pair<std::uint8_t, std::uint8_t> pinMinMax)
1217 : p(parent)
1218 {
1219+ m_notificationManager = notificationManager;
1220 m_title = title;
1221 m_body = body;
1222 m_pinMinMax = pinMinMax;
1223@@ -162,12 +175,12 @@
1224 std::string menuPath = "/com/canonical/indicator/network/unlocksim" + std::to_string(exportId);
1225 ++exportId;
1226
1227- std::map<std::string, Variant> modelActions;
1228- modelActions["notifications"] = TypedVariant<std::string>(actionPath);
1229+ QVariantMap modelActions;
1230+ modelActions["notifications"] = QString::fromStdString(actionPath);
1231
1232- m_modelPaths["busName"] = TypedVariant<std::string>(m_sessionBus->address());
1233- m_modelPaths["menuPath"] = TypedVariant<std::string>(menuPath);
1234- m_modelPaths["actions"] = TypedVariant<std::map<std::string, Variant>>(modelActions);
1235+ m_modelPaths["busName"] = QString::fromStdString(m_sessionBus->address());
1236+ m_modelPaths["menuPath"] = QString::fromStdString(menuPath);
1237+ m_modelPaths["actions"] = modelActions;
1238
1239 m_menu = std::make_shared<Menu>();
1240 m_menuItem = std::make_shared<MenuItem>("", "notifications.simunlock");
1241@@ -205,19 +218,18 @@
1242 m_menuExporter = std::make_shared<MenuExporter>(m_sessionBus, menuPath, m_menu);
1243 m_actionGroupExporter = std::make_shared<ActionGroupExporter>(m_sessionBus, m_actionGroup, actionPath);
1244
1245- resetNotification(title, body);
1246+ resetNotification();
1247
1248- connect(&p, &SimUnlock::titleUpdated, m_notification.get(), &Notification::setSummary);
1249- connect(&p, &SimUnlock::bodyUpdated, m_notification.get(), &Notification::setBody);
1250 connect(&p, &SimUnlock::pinMinMaxUpdated, this, &Private::pinMinMaxChanged);
1251 }
1252 };
1253
1254-SimUnlock::SimUnlock(const QString &title,
1255- const QString &body,
1256- std::pair<std::uint8_t, std::uint8_t> pinMinMax)
1257+SimUnlock::SimUnlock(NotificationManager::SPtr notificationManager,
1258+ const QString &title,
1259+ const QString &body,
1260+ std::pair<std::uint8_t, std::uint8_t> pinMinMax)
1261 {
1262- d.reset(new Private(*this, title, body, pinMinMax));
1263+ d.reset(new Private(*this, notificationManager, title, body, pinMinMax));
1264 }
1265
1266 SimUnlock::~SimUnlock()
1267
1268=== modified file 'src/notify-cpp/snapdecision/sim-unlock.h'
1269--- src/notify-cpp/snapdecision/sim-unlock.h 2015-05-13 15:46:54 +0000
1270+++ src/notify-cpp/snapdecision/sim-unlock.h 2015-08-12 13:44:19 +0000
1271@@ -24,6 +24,8 @@
1272 #include <QObject>
1273 #include <QString>
1274
1275+#include <notify-cpp/notification-manager.h>
1276+
1277 namespace notify {
1278 namespace snapdecision {
1279
1280@@ -38,7 +40,8 @@
1281
1282 typedef std::shared_ptr<SimUnlock> Ptr;
1283
1284- explicit SimUnlock(const QString &title = "",
1285+ explicit SimUnlock(NotificationManager::SPtr notificationManager,
1286+ const QString &title = "",
1287 const QString &body = "",
1288 std::pair<std::uint8_t, std::uint8_t> pinMinMax = {0, 0});
1289 ~SimUnlock();
1290@@ -84,8 +87,6 @@
1291
1292 void cancelled();
1293
1294- void closed();
1295-
1296 void titleUpdated(const QString&);
1297
1298 void bodyUpdated(const QString&);
1299
1300=== modified file 'src/qdbus-stubs/dbus-types.h'
1301--- src/qdbus-stubs/dbus-types.h 2015-08-10 16:49:01 +0000
1302+++ src/qdbus-stubs/dbus-types.h 2015-08-12 13:44:19 +0000
1303@@ -56,4 +56,10 @@
1304 static constexpr char const* URFKILL_OBJ_PATH = "/org/freedesktop/URfkill";
1305
1306 static constexpr char const* URFKILL_WIFI_OBJ_PATH = "/org/freedesktop/URfkill/WLAN";
1307+ static constexpr char const* NOTIFY_DBUS_NAME = "org.freedesktop.Notifications";
1308+
1309+ static constexpr char const* NOTIFY_DBUS_INTERFACE = "org.freedesktop.Notifications";
1310+
1311+ static constexpr char const* NOTIFY_DBUS_PATH = "/org/freedesktop/Notifications";
1312+
1313 }
1314
1315=== modified file 'tests/integration/indicator-network-test-base.h'
1316--- tests/integration/indicator-network-test-base.h 2015-07-07 08:29:34 +0000
1317+++ tests/integration/indicator-network-test-base.h 2015-08-12 13:44:19 +0000
1318@@ -30,7 +30,11 @@
1319 #include <gtest/gtest.h>
1320
1321 inline void PrintTo(const QVariant& variant, std::ostream* os) {
1322- *os << "QVariant(" << variant.toString().toStdString() << ")";
1323+ QString output;
1324+ QDebug dbg(&output);
1325+ dbg << variant;
1326+
1327+ *os << "QVariant(" << output.toStdString() << ")";
1328 }
1329
1330 #define WAIT_FOR_SIGNALS(signalSpy, signalsExpected)\
1331
1332=== modified file 'tests/integration/test-indicator.cpp'
1333--- tests/integration/test-indicator.cpp 2015-07-08 08:49:30 +0000
1334+++ tests/integration/test-indicator.cpp 2015-08-12 13:44:19 +0000
1335@@ -2077,12 +2077,12 @@
1336 // set sim locked
1337 setSimManagerProperty(firstModem(), "PinRequired", "pin");
1338
1339+ QSignalSpy notificationsSpy(&notificationsMockInterface(),
1340+ SIGNAL(MethodCalled(const QString &, const QVariantList &)));
1341+
1342 // start the indicator
1343 ASSERT_NO_THROW(startIndicator());
1344
1345- QSignalSpy notificationsSpy(&notificationsMockInterface(),
1346- SIGNAL(MethodCalled(const QString &, const QVariantList &)));
1347-
1348 // check indicator is a locked sim card and a 0-bar wifi icon.
1349 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.
1350 // check that the “Unlock SIM” button has the correct action name.
1351@@ -2100,10 +2100,9 @@
1352 ).match());
1353
1354 // check that the "GetServerInformation" method was called
1355- // check that the "Notify" method was called twice
1356 // check method arguments are correct
1357- std::string busName;
1358- WAIT_FOR_SIGNALS(notificationsSpy, 3);
1359+ string busName;
1360+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1361 {
1362 QVariantList const& call(notificationsSpy.at(0));
1363 EXPECT_EQ("GetServerInformation", call.at(0));
1364@@ -2147,45 +2146,9 @@
1365 ASSERT_TRUE(actions.contains("notifications"));
1366 EXPECT_EQ("/com/canonical/indicator/network/unlocksim0", actions["notifications"]);
1367 }
1368- {
1369- QVariantList const& call(notificationsSpy.at(2));
1370- EXPECT_EQ("Notify", call.at(0));
1371- QVariantList const& args(call.at(1).toList());
1372- ASSERT_EQ(8, args.size());
1373- EXPECT_EQ("indicator-network", args.at(0));
1374- EXPECT_EQ(1, args.at(1));
1375- EXPECT_EQ("", args.at(2));
1376- EXPECT_EQ("Enter SIM PIN", args.at(3));
1377- EXPECT_EQ("3 attempts remaining", args.at(4));
1378- EXPECT_EQ(QStringList(), args.at(5));
1379- EXPECT_EQ(-1, args.at(7));
1380-
1381- QVariantMap hints;
1382- ASSERT_TRUE(qDBusArgumentToMap(args.at(6), hints));
1383- ASSERT_EQ(3, hints.size());
1384- ASSERT_TRUE(hints.contains("x-canonical-private-menu-model"));
1385- ASSERT_TRUE(hints.contains("x-canonical-snap-decisions"));
1386- ASSERT_TRUE(hints.contains("x-canonical-snap-decisions-timeout"));
1387- EXPECT_EQ(true, hints["x-canonical-snap-decisions"]);
1388- EXPECT_EQ(numeric_limits<int32_t>::max(), hints["x-canonical-snap-decisions-timeout"]);
1389-
1390- QVariantMap menuInfo;
1391- ASSERT_TRUE(qDBusArgumentToMap(hints["x-canonical-private-menu-model"], menuInfo));
1392- ASSERT_EQ(3, menuInfo.size());
1393- ASSERT_TRUE(menuInfo.contains("actions"));
1394- ASSERT_TRUE(menuInfo.contains("busName"));
1395- ASSERT_TRUE(menuInfo.contains("menuPath"));
1396- EXPECT_EQ(busName, menuInfo["busName"].toString().toStdString());
1397- EXPECT_EQ("/com/canonical/indicator/network/unlocksim0", menuInfo["menuPath"]);
1398-
1399- QVariantMap actions;
1400- ASSERT_TRUE(qDBusArgumentToMap(menuInfo["actions"], actions));
1401- ASSERT_EQ(1, actions.size());
1402- ASSERT_TRUE(actions.contains("notifications"));
1403- EXPECT_EQ("/com/canonical/indicator/network/unlocksim0", actions["notifications"]);
1404- }
1405 notificationsSpy.clear();
1406
1407+ ASSERT_FALSE(busName.empty());
1408 // check contents of x-canonical-private-menu-model
1409 EXPECT_MATCHRESULT(mh::MenuMatcher(unlockSimParameters(busName, 0))
1410 .item(mh::MenuItemMatcher()
1411@@ -2205,12 +2168,12 @@
1412 // set sim locked
1413 setSimManagerProperty(firstModem(), "PinRequired", "pin");
1414
1415+ QSignalSpy notificationsSpy(&notificationsMockInterface(),
1416+ SIGNAL(MethodCalled(const QString &, const QVariantList &)));
1417+
1418 // start the indicator
1419 ASSERT_NO_THROW(startIndicator());
1420
1421- QSignalSpy notificationsSpy(&notificationsMockInterface(),
1422- SIGNAL(MethodCalled(const QString &, const QVariantList &)));
1423-
1424 // check indicator is a locked sim card and a 0-bar wifi icon.
1425 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.
1426 // check that the “Unlock SIM” button has the correct action name.
1427@@ -2228,15 +2191,13 @@
1428 ).match());
1429
1430 // check that the "GetServerInformation" method was called
1431- // check that the "Notify" method was called twice
1432 // check method arguments are correct
1433 std::string busName;
1434- WAIT_FOR_SIGNALS(notificationsSpy, 3);
1435+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1436 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);
1437 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});
1438- CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});
1439 {
1440- QVariantList const& call(notificationsSpy.at(2));
1441+ QVariantList const& call(notificationsSpy.at(1));
1442 QVariantList const& args(call.at(1).toList());
1443 QVariantMap hints;
1444 QVariantMap menuInfo;
1445@@ -2284,11 +2245,10 @@
1446 )
1447 ).match());
1448
1449- // check that the "Notify" method was called twice
1450- // check method arguments are correct (new notification index should be 2)
1451- WAIT_FOR_SIGNALS(notificationsSpy, 2);
1452- CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 0});
1453- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 2});
1454+ // check that the "Notify" method was called
1455+ // check method arguments are correct (we re-use the same notification and reopen it)
1456+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1457+ CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1});
1458 notificationsSpy.clear();
1459
1460 // cancel the notification again
1461@@ -2302,15 +2262,144 @@
1462 .activate(shared_ptr<GVariant>(g_variant_new_boolean(false), &mh::gvariant_deleter))
1463 ).match());
1464
1465- // check that the "NotificationClosed" signal was emitted (new notification index should be 2)
1466- WAIT_FOR_SIGNALS(notificationClosedSpy, 1);
1467- EXPECT_EQ(notificationClosedSpy.first(), QVariantList() << QVariant(2) << QVariant(1));
1468- notificationClosedSpy.clear();
1469-
1470- // check that the "CloseNotification" method was called
1471- // check method arguments are correct (new notification index should be 2)
1472- WAIT_FOR_SIGNALS(notificationsSpy, 1);
1473- CHECK_METHOD_CALL(notificationsSpy, 0, "CloseNotification", {0, "2"});
1474+ // check that the "NotificationClosed" signal was emitted (new notification index should be 1)
1475+ WAIT_FOR_SIGNALS(notificationClosedSpy, 1);
1476+ EXPECT_EQ(notificationClosedSpy.first(), QVariantList() << QVariant(1) << QVariant(1));
1477+ notificationClosedSpy.clear();
1478+
1479+ // check that the "CloseNotification" method was called
1480+ // check method arguments are correct (still using the same notification: 1)
1481+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1482+ CHECK_METHOD_CALL(notificationsSpy, 0, "CloseNotification", {0, "1"});
1483+ notificationsSpy.clear();
1484+}
1485+
1486+TEST_F(TestIndicator, UnlockSIM_CancelFirstUnlockSecond)
1487+{
1488+ // set flight mode off, wifi off, and cell data off, and sim in
1489+ setGlobalConnectedState(NM_STATE_DISCONNECTED);
1490+
1491+ // set sim locked
1492+ setSimManagerProperty(firstModem(), "PinRequired", "pin");
1493+
1494+ // Create a second locked modem
1495+ auto secondModem = createModem("ril_1");
1496+ setSimManagerProperty(secondModem, "PinRequired", "pin");
1497+
1498+ QSignalSpy notificationsSpy(&notificationsMockInterface(),
1499+ SIGNAL(MethodCalled(const QString &, const QVariantList &)));
1500+
1501+ QSignalSpy secondModemMockInterfaceSpy(&modemMockInterface(secondModem),
1502+ SIGNAL(MethodCalled(const QString &, const QVariantList &)));
1503+
1504+ // start the indicator
1505+ ASSERT_NO_THROW(startIndicator());
1506+
1507+ // check indicator is a locked sim card and a 0-bar wifi icon.
1508+ // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.
1509+ // check that the “Unlock SIM” button has the correct action name.
1510+ // unlock first SIM
1511+ EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters())
1512+ .item(mh::MenuItemMatcher()
1513+ .mode(mh::MenuItemMatcher::Mode::starts_with)
1514+ .item(flightModeSwitch())
1515+ .item(mh::MenuItemMatcher()
1516+ .item(modemInfo("SIM 1", "SIM Locked", "simcard-locked", true)
1517+ .pass_through_activate("x-canonical-modem-locked-action")
1518+ )
1519+ .item(modemInfo("SIM 2", "SIM Locked", "simcard-locked", true))
1520+ .item(cellularSettings())
1521+ )
1522+ ).match());
1523+
1524+ // check that the "GetServerInformation" method was called
1525+ // check method arguments are correct
1526+ std::string busName;
1527+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1528+ CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);
1529+ CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM 1 PIN"}, {4, "3 attempts remaining"});
1530+ {
1531+ QVariantList const& call(notificationsSpy.at(1));
1532+ QVariantList const& args(call.at(1).toList());
1533+ QVariantMap hints;
1534+ QVariantMap menuInfo;
1535+ ASSERT_TRUE(qDBusArgumentToMap(args.at(6), hints));
1536+ ASSERT_TRUE(qDBusArgumentToMap(hints["x-canonical-private-menu-model"], menuInfo));
1537+ busName = menuInfo["busName"].toString().toStdString();
1538+ }
1539+ notificationsSpy.clear();
1540+
1541+ // cancel the notification
1542+ QSignalSpy notificationClosedSpy(&dbusMock.notificationDaemonInterface(),
1543+ SIGNAL(NotificationClosed(uint, uint)));
1544+
1545+ EXPECT_MATCHRESULT(mh::MenuMatcher(unlockSimParameters(busName, 0))
1546+ .item(mh::MenuItemMatcher()
1547+ .action("notifications.simunlock")
1548+ .string_attribute("x-canonical-type", "com.canonical.snapdecision.pinlock")
1549+ .string_attribute("x-canonical-pin-min-max", "notifications.pinMinMax")
1550+ .string_attribute("x-canonical-pin-popup", "notifications.popup")
1551+ .string_attribute("x-canonical-pin-error", "notifications.error")
1552+ .activate(shared_ptr<GVariant>(g_variant_new_boolean(false), &mh::gvariant_deleter))
1553+ ).match());
1554+
1555+ // check that the "NotificationClosed" signal was emitted
1556+ WAIT_FOR_SIGNALS(notificationClosedSpy, 1);
1557+ EXPECT_EQ(notificationClosedSpy.first(), QVariantList() << QVariant(1) << QVariant(1));
1558+ notificationClosedSpy.clear();
1559+
1560+ // check that the "CloseNotification" method was called
1561+ // check method arguments are correct
1562+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1563+ CHECK_METHOD_CALL(notificationsSpy, 0, "CloseNotification", {0, "1"});
1564+ notificationsSpy.clear();
1565+
1566+ // Activate the second SIM unlock
1567+ EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters())
1568+ .item(mh::MenuItemMatcher()
1569+ .mode(mh::MenuItemMatcher::Mode::starts_with)
1570+ .item(flightModeSwitch())
1571+ .item(mh::MenuItemMatcher()
1572+ .item(modemInfo("SIM 1", "SIM Locked", "simcard-locked", true))
1573+ .item(modemInfo("SIM 2", "SIM Locked", "simcard-locked", true)
1574+ .pass_through_activate("x-canonical-modem-locked-action")
1575+ )
1576+ .item(cellularSettings())
1577+ )
1578+ ).match());
1579+
1580+ // check that the "Notify" method was called
1581+ // check method arguments are correct (we re-use the same notification and reopen it)
1582+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1583+ CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"});
1584+ notificationsSpy.clear();
1585+
1586+ secondModemMockInterfaceSpy.clear();
1587+
1588+ // enter the PIN
1589+ EXPECT_MATCHRESULT(mh::MenuMatcher(unlockSimParameters(busName, 0))
1590+ .item(mh::MenuItemMatcher()
1591+ .action("notifications.simunlock")
1592+ .string_attribute("x-canonical-type", "com.canonical.snapdecision.pinlock")
1593+ .string_attribute("x-canonical-pin-min-max", "notifications.pinMinMax")
1594+ .string_attribute("x-canonical-pin-popup", "notifications.popup")
1595+ .string_attribute("x-canonical-pin-error", "notifications.error")
1596+ .set_action_state(shared_ptr<GVariant>(g_variant_new_string("1234"), &mh::gvariant_deleter))
1597+ ).match());
1598+
1599+ // Check the PIN was sent to Ofono
1600+ WAIT_FOR_SIGNALS(secondModemMockInterfaceSpy, 1);
1601+ CHECK_METHOD_CALL(secondModemMockInterfaceSpy, 0, "EnterPin", {0, "pin"}, {1, "1234"});
1602+
1603+ // check that the "NotificationClosed" signal was emitted (new notification index should be 1)
1604+ WAIT_FOR_SIGNALS(notificationClosedSpy, 1);
1605+ EXPECT_EQ(notificationClosedSpy.first(), QVariantList() << QVariant(1) << QVariant(1));
1606+ notificationClosedSpy.clear();
1607+
1608+ // check that the "CloseNotification" method was called
1609+ // check method arguments are correct (still using the same notification: 1)
1610+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1611+ CHECK_METHOD_CALL(notificationsSpy, 0, "CloseNotification", {0, "1"});
1612 notificationsSpy.clear();
1613 }
1614
1615@@ -2322,12 +2411,12 @@
1616 // set sim locked
1617 setSimManagerProperty(firstModem(), "PinRequired", "pin");
1618
1619+ QSignalSpy notificationsSpy(&notificationsMockInterface(),
1620+ SIGNAL(MethodCalled(const QString &, const QVariantList &)));
1621+
1622 // start the indicator
1623 ASSERT_NO_THROW(startIndicator());
1624
1625- QSignalSpy notificationsSpy(&notificationsMockInterface(),
1626- SIGNAL(MethodCalled(const QString &, const QVariantList &)));
1627-
1628 // check indicator is a locked sim card and a 0-bar wifi icon.
1629 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.
1630 // check that the “Unlock SIM” button has the correct action name.
1631@@ -2348,12 +2437,11 @@
1632 // check that the "Notify" method was called twice
1633 // check method arguments are correct
1634 std::string busName;
1635- WAIT_FOR_SIGNALS(notificationsSpy, 3);
1636+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1637 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);
1638 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});
1639- CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});
1640 {
1641- QVariantList const& call(notificationsSpy.at(2));
1642+ QVariantList const& call(notificationsSpy.at(1));
1643 QVariantList const& args(call.at(1).toList());
1644 QVariantMap hints;
1645 QVariantMap menuInfo;
1646@@ -2406,12 +2494,12 @@
1647 // set sim locked
1648 setSimManagerProperty(firstModem(), "PinRequired", "pin");
1649
1650+ QSignalSpy notificationsSpy(&notificationsMockInterface(),
1651+ SIGNAL(MethodCalled(const QString &, const QVariantList &)));
1652+
1653 // start the indicator
1654 ASSERT_NO_THROW(startIndicator());
1655
1656- QSignalSpy notificationsSpy(&notificationsMockInterface(),
1657- SIGNAL(MethodCalled(const QString &, const QVariantList &)));
1658-
1659 // check indicator is a locked sim card and a 0-bar wifi icon.
1660 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.
1661 // check that the “Unlock SIM” button has the correct action name.
1662@@ -2432,12 +2520,11 @@
1663 // check that the "Notify" method was called twice
1664 // check method arguments are correct
1665 std::string busName;
1666- WAIT_FOR_SIGNALS(notificationsSpy, 3);
1667+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1668 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);
1669 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});
1670- CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});
1671 {
1672- QVariantList const& call(notificationsSpy.at(2));
1673+ QVariantList const& call(notificationsSpy.at(1));
1674 QVariantList const& args(call.at(1).toList());
1675 QVariantMap hints;
1676 QVariantMap menuInfo;
1677@@ -2464,13 +2551,11 @@
1678 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});
1679 modemSpy.clear();
1680
1681- // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin
1682+ // check that the "Notify" method was called when retries changes, then again for incorrect pin
1683 // check method arguments are correct (notification index should still be 1)
1684- WAIT_FOR_SIGNALS(notificationsSpy, 4);
1685+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1686 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "2 attempts remaining"});
1687 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "2 attempts remaining"});
1688- CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "2 attempts remaining"});
1689- CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "2 attempts remaining"});
1690 notificationsSpy.clear();
1691
1692 // check that the notification is displaying the appropriate error message
1693@@ -2498,13 +2583,11 @@
1694 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});
1695 modemSpy.clear();
1696
1697- // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin
1698+ // check that the "Notify" method was called when retries changes, then again for incorrect pin
1699 // check method arguments are correct (notification index should still be 1)
1700- WAIT_FOR_SIGNALS(notificationsSpy, 4);
1701+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1702 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "1 attempt remaining"});
1703 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "1 attempt remaining"});
1704- CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "1 attempt remaining"});
1705- CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "1 attempt remaining"});
1706 notificationsSpy.clear();
1707
1708 // check that the error message and last attempt popup are displayed
1709@@ -2537,13 +2620,11 @@
1710 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});
1711 modemSpy.clear();
1712
1713- // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin
1714+ // check that the "Notify" method was called when retries changes, then again for incorrect pin
1715 // check method arguments are correct (notification index should still be 1)
1716- WAIT_FOR_SIGNALS(notificationsSpy, 4);
1717+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1718 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "0 attempts remaining"});
1719 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "0 attempts remaining"});
1720- CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "0 attempts remaining"});
1721- CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "0 attempts remaining"});
1722 notificationsSpy.clear();
1723
1724 // set sim blocked
1725@@ -2553,11 +2634,10 @@
1726 WAIT_FOR_SIGNALS(modemSpy, 1);
1727 modemSpy.clear();
1728
1729- // check that the "Notify" method was called twice
1730+ // check that the "Notify" method was called
1731 // check method arguments are correct (notification index should still be 1)
1732- WAIT_FOR_SIGNALS(notificationsSpy, 2);
1733+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1734 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter PUK code"}, {4, "10 attempts remaining"});
1735- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter PUK code"}, {4, "10 attempts remaining"});
1736 notificationsSpy.clear();
1737
1738 // check that the error message and last attempt popup are displayed
1739@@ -2585,11 +2665,10 @@
1740 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("87654321"), &mh::gvariant_deleter))
1741 ).match());
1742
1743- // check that the "Notify" method was called twice
1744+ // check that the "Notify" method was called
1745 // check method arguments are correct (notification index should still be 1)
1746- WAIT_FOR_SIGNALS(notificationsSpy, 2);
1747+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1748 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter new SIM PIN"}, {4, "Create new PIN"});
1749- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter new SIM PIN"}, {4, "Create new PIN"});
1750 notificationsSpy.clear();
1751
1752 // enter new pin
1753@@ -2598,11 +2677,10 @@
1754 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("4321"), &mh::gvariant_deleter))
1755 ).match());
1756
1757- // check that the "Notify" method was called twice
1758+ // check that the "Notify" method was called
1759 // check method arguments are correct (notification index should still be 1)
1760- WAIT_FOR_SIGNALS(notificationsSpy, 2);
1761+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1762 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
1763- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
1764 notificationsSpy.clear();
1765
1766 // enter new pin again
1767@@ -2617,13 +2695,11 @@
1768 CHECK_METHOD_CALL(modemSpy, 0, "ResetPin", {0, "puk"}, {1, "87654321"}, {2, "4321"});
1769 modemSpy.clear();
1770
1771- // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin
1772+ // check that the "Notify" method was called when retries changes, then again for incorrect pin
1773 // check method arguments are correct (notification index should still be 1)
1774- WAIT_FOR_SIGNALS(notificationsSpy, 4);
1775+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1776 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
1777- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
1778- CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter PUK code"}, {4, "9 attempts remaining"});
1779- CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter PUK code"}, {4, "9 attempts remaining"});
1780+ CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter PUK code"}, {4, "9 attempts remaining"});
1781 notificationsSpy.clear();
1782
1783 // check that the notification is displaying the appropriate error message
1784@@ -2649,10 +2725,9 @@
1785 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("12345678"), &mh::gvariant_deleter))
1786 ).match());
1787
1788- // check that the "Notify" method was called twice
1789- WAIT_FOR_SIGNALS(notificationsSpy, 2);
1790+ // check that the "Notify" method was called
1791+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1792 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter new SIM PIN"}, {4, "Create new PIN"});
1793- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter new SIM PIN"}, {4, "Create new PIN"});
1794 notificationsSpy.clear();
1795
1796 // enter new pin
1797@@ -2661,10 +2736,9 @@
1798 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("4321"), &mh::gvariant_deleter))
1799 ).match());
1800
1801- // check that the "Notify" method was called twice
1802- WAIT_FOR_SIGNALS(notificationsSpy, 2);
1803+ // check that the "Notify" method was called
1804+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1805 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
1806- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
1807 notificationsSpy.clear();
1808
1809 // enter new pin again
1810@@ -2687,10 +2761,9 @@
1811 // check that the "Notify" method was called twice when retries changes
1812 // check that the "CloseNotification" method was called
1813 // check method arguments are correct
1814- WAIT_FOR_SIGNALS(notificationsSpy, 3);
1815+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1816 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
1817- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
1818- CHECK_METHOD_CALL(notificationsSpy, 2, "CloseNotification", {0, "1"});
1819+ CHECK_METHOD_CALL(notificationsSpy, 1, "CloseNotification", {0, "1"});
1820 notificationsSpy.clear();
1821 }
1822
1823@@ -2703,12 +2776,12 @@
1824 auto secondModem = createModem("ril_1");
1825 setSimManagerProperty(secondModem, "PinRequired", "pin");
1826
1827+ QSignalSpy notificationsSpy(&notificationsMockInterface(),
1828+ SIGNAL(MethodCalled(const QString &, const QVariantList &)));
1829+
1830 // start the indicator
1831 ASSERT_NO_THROW(startIndicator());
1832
1833- QSignalSpy notificationsSpy(&notificationsMockInterface(),
1834- SIGNAL(MethodCalled(const QString &, const QVariantList &)));
1835-
1836 // check indicator is a locked sim card and a 0-bar wifi icon.
1837 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.
1838 // check that the “Unlock SIM” button has the correct action name.
1839@@ -2730,12 +2803,11 @@
1840 // check that the "Notify" method was called twice
1841 // check method arguments are correct
1842 std::string busName;
1843- WAIT_FOR_SIGNALS(notificationsSpy, 3);
1844+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1845 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);
1846 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM 2 PIN"}, {4, "3 attempts remaining"});
1847- CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "3 attempts remaining"});
1848 {
1849- QVariantList const& call(notificationsSpy.at(2));
1850+ QVariantList const& call(notificationsSpy.at(1));
1851 QVariantList const& args(call.at(1).toList());
1852 QVariantMap hints;
1853 QVariantMap menuInfo;
1854@@ -2762,13 +2834,11 @@
1855 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});
1856 modemSpy.clear();
1857
1858- // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin
1859+ // check that the "Notify" method was called when retries changes, then again for incorrect pin
1860 // check method arguments are correct (notification index should still be 1)
1861- WAIT_FOR_SIGNALS(notificationsSpy, 4);
1862+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1863 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "2 attempts remaining"});
1864 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "2 attempts remaining"});
1865- CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "2 attempts remaining"});
1866- CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "2 attempts remaining"});
1867 notificationsSpy.clear();
1868
1869 // check that the notification is displaying the appropriate error message
1870@@ -2796,13 +2866,11 @@
1871 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});
1872 modemSpy.clear();
1873
1874- // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin
1875+ // check that the "Notify" method was called when retries changes, then again for incorrect pin
1876 // check method arguments are correct (notification index should still be 1)
1877- WAIT_FOR_SIGNALS(notificationsSpy, 4);
1878+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1879 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "1 attempt remaining"});
1880 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "1 attempt remaining"});
1881- CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "1 attempt remaining"});
1882- CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "1 attempt remaining"});
1883 notificationsSpy.clear();
1884
1885 // check that the error message and last attempt popup are displayed
1886@@ -2835,13 +2903,11 @@
1887 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});
1888 modemSpy.clear();
1889
1890- // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin
1891+ // check that the "Notify" method was called when retries changes, then again for incorrect pin
1892 // check method arguments are correct (notification index should still be 1)
1893- WAIT_FOR_SIGNALS(notificationsSpy, 4);
1894+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1895 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "0 attempts remaining"});
1896 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "0 attempts remaining"});
1897- CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "0 attempts remaining"});
1898- CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "0 attempts remaining"});
1899 notificationsSpy.clear();
1900
1901 // set sim blocked
1902@@ -2851,11 +2917,10 @@
1903 WAIT_FOR_SIGNALS(modemSpy, 1);
1904 modemSpy.clear();
1905
1906- // check that the "Notify" method was called twice
1907+ // check that the "Notify" method was called
1908 // check method arguments are correct (notification index should still be 1)
1909- WAIT_FOR_SIGNALS(notificationsSpy, 2);
1910+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1911 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter PUK code for SIM 2"}, {4, "10 attempts remaining"});
1912- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter PUK code for SIM 2"}, {4, "10 attempts remaining"});
1913 notificationsSpy.clear();
1914
1915 // check that the error message and last attempt popup are displayed
1916@@ -2883,11 +2948,10 @@
1917 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("87654321"), &mh::gvariant_deleter))
1918 ).match());
1919
1920- // check that the "Notify" method was called twice
1921+ // check that the "Notify" method was called
1922 // check method arguments are correct (notification index should still be 1)
1923- WAIT_FOR_SIGNALS(notificationsSpy, 2);
1924+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1925 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter new SIM 2 PIN"}, {4, "Create new PIN"});
1926- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter new SIM 2 PIN"}, {4, "Create new PIN"});
1927 notificationsSpy.clear();
1928
1929 // enter new pin
1930@@ -2896,11 +2960,10 @@
1931 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("4321"), &mh::gvariant_deleter))
1932 ).match());
1933
1934- // check that the "Notify" method was called twice
1935+ // check that the "Notify" method was called
1936 // check method arguments are correct (notification index should still be 1)
1937- WAIT_FOR_SIGNALS(notificationsSpy, 2);
1938+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1939 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
1940- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
1941 notificationsSpy.clear();
1942
1943 // enter new pin again
1944@@ -2915,13 +2978,11 @@
1945 CHECK_METHOD_CALL(modemSpy, 0, "ResetPin", {0, "puk"}, {1, "87654321"}, {2, "4321"});
1946 modemSpy.clear();
1947
1948- // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin
1949+ // check that the "Notify" method was called when retries changes, then again for incorrect pin
1950 // check method arguments are correct (notification index should still be 1)
1951- WAIT_FOR_SIGNALS(notificationsSpy, 4);
1952+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1953 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
1954- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
1955- CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter PUK code for SIM 2"}, {4, "9 attempts remaining"});
1956- CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter PUK code for SIM 2"}, {4, "9 attempts remaining"});
1957+ CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter PUK code for SIM 2"}, {4, "9 attempts remaining"});
1958 notificationsSpy.clear();
1959
1960 // check that the notification is displaying the appropriate error message
1961@@ -2947,10 +3008,9 @@
1962 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("12345678"), &mh::gvariant_deleter))
1963 ).match());
1964
1965- // check that the "Notify" method was called twice
1966- WAIT_FOR_SIGNALS(notificationsSpy, 2);
1967+ // check that the "Notify" method was called
1968+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1969 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter new SIM 2 PIN"}, {4, "Create new PIN"});
1970- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter new SIM 2 PIN"}, {4, "Create new PIN"});
1971 notificationsSpy.clear();
1972
1973 // enter new pin
1974@@ -2959,10 +3019,9 @@
1975 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("4321"), &mh::gvariant_deleter))
1976 ).match());
1977
1978- // check that the "Notify" method was called twice
1979- WAIT_FOR_SIGNALS(notificationsSpy, 2);
1980+ // check that the "Notify" method was called
1981+ WAIT_FOR_SIGNALS(notificationsSpy, 1);
1982 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
1983- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
1984 notificationsSpy.clear();
1985
1986 // enter new pin again
1987@@ -2985,10 +3044,9 @@
1988 // check that the "Notify" method was called twice when retries changes
1989 // check that the "CloseNotification" method was called
1990 // check method arguments are correct
1991- WAIT_FOR_SIGNALS(notificationsSpy, 3);
1992+ WAIT_FOR_SIGNALS(notificationsSpy, 2);
1993 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
1994- CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
1995- CHECK_METHOD_CALL(notificationsSpy, 2, "CloseNotification", {0, "1"});
1996+ CHECK_METHOD_CALL(notificationsSpy, 1, "CloseNotification", {0, "1"});
1997 notificationsSpy.clear();
1998 }
1999
2000
2001=== modified file 'tests/unit/secret-agent/test-secret-agent.cpp'
2002--- tests/unit/secret-agent/test-secret-agent.cpp 2015-04-23 12:04:27 +0000
2003+++ tests/unit/secret-agent/test-secret-agent.cpp 2015-08-12 13:44:19 +0000
2004@@ -50,7 +50,8 @@
2005 QProcessEnvironment env(QProcessEnvironment::systemEnvironment());
2006 env.insert("SECRET_AGENT_DEBUG_PASSWORD", "1");
2007 secretAgent.setProcessEnvironment(env);
2008- secretAgent.setProcessChannelMode(QProcess::MergedChannels);
2009+ secretAgent.setReadChannel(QProcess::StandardOutput);
2010+ secretAgent.setProcessChannelMode(QProcess::ForwardedErrorChannel);
2011 secretAgent.start(SECRET_AGENT_BIN, QStringList() << "--print-address");
2012 secretAgent.waitForStarted();
2013 secretAgent.waitForReadyRead();
2014@@ -260,13 +261,14 @@
2015 /* Tests that if we request secrets and then cancel the request
2016 that we close the notification */
2017 TEST_F(TestSecretAgent, CancelGetSecrets) {
2018+ QSignalSpy notificationSpy(notificationsInterface.data(), SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2019+
2020 agentInterface->GetSecrets(
2021 connection(SecretAgent::KEY_MGMT_WPA_PSK),
2022 QDBusObjectPath("/connection/foo"),
2023 SecretAgent::WIRELESS_SECURITY_SETTING_NAME, QStringList(),
2024 5);
2025
2026- QSignalSpy notificationSpy(notificationsInterface.data(), SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2027 notificationSpy.wait();
2028
2029 ASSERT_EQ(1, notificationSpy.size());

Subscribers

People subscribed via source and target branches