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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2015-06-22 08:25:05 +0000
+++ CMakeLists.txt 2015-08-12 13:44:19 +0000
@@ -60,13 +60,6 @@
60)60)
61include_directories(${OFONO_INCLUDE_DIRS})61include_directories(${OFONO_INCLUDE_DIRS})
6262
63set(NOTIFY_REQUIRED_VERSION 0.7.5)
64pkg_check_modules(
65 NOTIFY REQUIRED
66 libnotify>=${NOTIFY_REQUIRED_VERSION}
67)
68include_directories(${NOTIFY_INCLUDE_DIRS})
69
70find_package(Qt5Core REQUIRED)63find_package(Qt5Core REQUIRED)
71include_directories(${Qt5Core_INCLUDE_DIRS})64include_directories(${Qt5Core_INCLUDE_DIRS})
7265
7366
=== modified file 'debian/control'
--- debian/control 2015-07-20 18:48:44 +0000
+++ debian/control 2015-08-12 13:44:19 +0000
@@ -12,7 +12,6 @@
12 graphviz,12 graphviz,
13 intltool,13 intltool,
14 libglib2.0-dev,14 libglib2.0-dev,
15 libnotify-dev,
16#///! TODO: The next line should be removed once all dependancy on qmenumodel is removed15#///! TODO: The next line should be removed once all dependancy on qmenumodel is removed
17 libqmenumodel-dev,16 libqmenumodel-dev,
18 libqofono-dev,17 libqofono-dev,
1918
=== modified file 'src/indicator/CMakeLists.txt'
--- src/indicator/CMakeLists.txt 2015-07-28 08:27:11 +0000
+++ src/indicator/CMakeLists.txt 2015-08-12 13:44:19 +0000
@@ -101,7 +101,6 @@
101 qpowerd101 qpowerd
102 ${DBUSCPP_LIBRARIES}102 ${DBUSCPP_LIBRARIES}
103 ${GLIB_LIBRARIES}103 ${GLIB_LIBRARIES}
104 ${NOTIFY_LIBRARIES}
105 ${QOFONO_LIBRARIES}104 ${QOFONO_LIBRARIES}
106)105)
107106
108107
=== modified file 'src/indicator/agent/PasswordMenu.cpp'
--- src/indicator/agent/PasswordMenu.cpp 2015-04-15 15:04:51 +0000
+++ src/indicator/agent/PasswordMenu.cpp 2015-08-12 13:44:19 +0000
@@ -19,9 +19,12 @@
19#include <agent/PasswordMenu.h>19#include <agent/PasswordMenu.h>
20#include <gio/gio.h>20#include <gio/gio.h>
2121
22#include <iostream>
22#include <QString>23#include <QString>
23#include <QDebug>24#include <QDebug>
2425
26using namespace std;
27
25namespace agent28namespace agent
26{29{
27namespace30namespace
@@ -51,7 +54,7 @@
51 void passwordChanged(GVariant *variant) {54 void passwordChanged(GVariant *variant) {
52 m_password = QString::fromUtf8(g_variant_get_string(variant, 0));55 m_password = QString::fromUtf8(g_variant_get_string(variant, 0));
53 if (qEnvironmentVariableIsSet("SECRET_AGENT_DEBUG_PASSWORD")) {56 if (qEnvironmentVariableIsSet("SECRET_AGENT_DEBUG_PASSWORD")) {
54 qDebug() << "Password received";57 cout << "Password received" << endl;
55 }58 }
56 }59 }
5760
5861
=== modified file 'src/indicator/agent/SecretAgent.cpp'
--- src/indicator/agent/SecretAgent.cpp 2015-04-21 10:59:52 +0000
+++ src/indicator/agent/SecretAgent.cpp 2015-08-12 13:44:19 +0000
@@ -19,7 +19,7 @@
19#include <agent/SecretAgent.h>19#include <agent/SecretAgent.h>
20#include <agent/SecretRequest.h>20#include <agent/SecretRequest.h>
21#include <AgentManagerInterface.h>21#include <AgentManagerInterface.h>
22#include <NotificationsInterface.h>22#include <notify-cpp/notification-manager.h>
23#include <SecretAgentAdaptor.h>23#include <SecretAgentAdaptor.h>
2424
25#include <NetworkManager.h>25#include <NetworkManager.h>
@@ -34,13 +34,13 @@
34 Q_OBJECT34 Q_OBJECT
3535
36public:36public:
37 Priv(const QDBusConnection &systemConnection,37 Priv(notify::NotificationManager::SPtr notificationManager, const QDBusConnection &systemConnection,
38 const QDBusConnection &sessionConnection) :38 const QDBusConnection &sessionConnection) :
39 m_systemConnection(systemConnection),39 m_systemConnection(systemConnection),
40 m_sessionConnection(sessionConnection),40 m_sessionConnection(sessionConnection),
41 m_managerWatcher(NM_DBUS_SERVICE, m_systemConnection),41 m_managerWatcher(NM_DBUS_SERVICE, m_systemConnection),
42 m_agentManager(NM_DBUS_SERVICE, NM_DBUS_PATH_AGENT_MANAGER, m_systemConnection),42 m_agentManager(NM_DBUS_SERVICE, NM_DBUS_PATH_AGENT_MANAGER, m_systemConnection),
43 m_notifications("org.freedesktop.Notifications", "/org/freedesktop/Notifications", m_sessionConnection),43 m_notifications(notificationManager),
44 m_request(nullptr) {44 m_request(nullptr) {
45 }45 }
4646
@@ -64,14 +64,15 @@
6464
65 OrgFreedesktopNetworkManagerAgentManagerInterface m_agentManager;65 OrgFreedesktopNetworkManagerAgentManagerInterface m_agentManager;
6666
67 OrgFreedesktopNotificationsInterface m_notifications;67 notify::NotificationManager::SPtr m_notifications;
6868
69 std::shared_ptr<SecretRequest> m_request;69 std::shared_ptr<SecretRequest> m_request;
70};70};
7171
72SecretAgent::SecretAgent(const QDBusConnection &systemConnection,72SecretAgent::SecretAgent(notify::NotificationManager::SPtr notificationManager,
73 const QDBusConnection &systemConnection,
73 const QDBusConnection &sessionConnection, QObject *parent) :74 const QDBusConnection &sessionConnection, QObject *parent) :
74 QObject(parent), d(new Priv(systemConnection, sessionConnection))75 QObject(parent), d(new Priv(notificationManager, systemConnection, sessionConnection))
75 {76 {
76 // Memory managed by Qt77 // Memory managed by Qt
77 new SecretAgentAdaptor(this);78 new SecretAgentAdaptor(this);
@@ -182,7 +183,7 @@
182 Q_UNUSED(connectionPath);183 Q_UNUSED(connectionPath);
183}184}
184185
185OrgFreedesktopNotificationsInterface & SecretAgent::notifications() {186notify::NotificationManager::SPtr SecretAgent::notifications() {
186 return d->m_notifications;187 return d->m_notifications;
187}188}
188189
189190
=== modified file 'src/indicator/agent/SecretAgent.h'
--- src/indicator/agent/SecretAgent.h 2015-04-21 10:59:52 +0000
+++ src/indicator/agent/SecretAgent.h 2015-08-12 13:44:19 +0000
@@ -26,9 +26,13 @@
26#include <QDBusContext>26#include <QDBusContext>
27#include <QMap>27#include <QMap>
2828
29class OrgFreedesktopNotificationsInterface;
30class SecretAgentAdaptor;29class SecretAgentAdaptor;
3130
31namespace notify
32{
33class NotificationManager;
34}
35
32namespace agent36namespace agent
33{37{
3438
@@ -58,8 +62,9 @@
58 static constexpr char const* KEY_MGMT_WPA_PSK = "wpa-psk";62 static constexpr char const* KEY_MGMT_WPA_PSK = "wpa-psk";
59 static constexpr char const* KEY_MGMT_NONE = "none";63 static constexpr char const* KEY_MGMT_NONE = "none";
6064
61 explicit SecretAgent(const QDBusConnection &systemConnection,65 explicit SecretAgent(std::shared_ptr<notify::NotificationManager> notificationManager,
62 const QDBusConnection &sessionConnection, QObject *parent = 0);66 const QDBusConnection &systemConnection,
67 const QDBusConnection &sessionConnection, QObject *parent = 0);
6368
64 virtual ~SecretAgent();69 virtual ~SecretAgent();
6570
@@ -79,7 +84,7 @@
79 void SaveSecrets(const QVariantDictMap &connection,84 void SaveSecrets(const QVariantDictMap &connection,
80 const QDBusObjectPath &connectionPath);85 const QDBusObjectPath &connectionPath);
8186
82 OrgFreedesktopNotificationsInterface & notifications();87 std::shared_ptr<notify::NotificationManager> notifications();
8388
84protected:89protected:
85 class Priv;90 class Priv;
8691
=== modified file 'src/indicator/agent/SecretRequest.cpp'
--- src/indicator/agent/SecretRequest.cpp 2015-04-21 10:59:52 +0000
+++ src/indicator/agent/SecretRequest.cpp 2015-08-12 13:44:19 +0000
@@ -20,7 +20,7 @@
20#include <agent/SecretAgent.h>20#include <agent/SecretAgent.h>
21#include <util/localisation.h>21#include <util/localisation.h>
2222
23#include <NotificationsInterface.h>23#include <notify-cpp/notification-manager.h>
2424
25namespace agent25namespace agent
26{26{
@@ -35,12 +35,6 @@
35 settingName), m_hints(hints), m_flags(flags), m_message(35 settingName), m_hints(hints), m_flags(flags), m_message(
36 message), m_menu() {36 message), m_menu() {
3737
38 connect(&m_secretAgent.notifications(),
39 SIGNAL(ActionInvoked(uint, const QString &)), this,
40 SLOT(actionInvoked(uint, const QString &)));
41
42 connect(&m_secretAgent.notifications(), SIGNAL(NotificationClosed(uint, uint)), this, SLOT(notificationClosed(uint, uint)));
43
44 // indicate to the notification-daemon, that we want to use snap-decisions38 // indicate to the notification-daemon, that we want to use snap-decisions
45 QVariantMap notificationHints;39 QVariantMap notificationHints;
46 notificationHints["x-canonical-snap-decisions"] = "true";40 notificationHints["x-canonical-snap-decisions"] = "true";
@@ -74,29 +68,28 @@
74 subject = _("WEP");68 subject = _("WEP");
75 }69 }
7670
77 m_notificationId = m_secretAgent.notifications().Notify("indicator-network",71 m_notification = m_secretAgent.notifications()->notify(
78 0, "wifi-full-secure",
79 title.arg(conn[SecretAgent::CONNECTION_ID].toString()), subject,72 title.arg(conn[SecretAgent::CONNECTION_ID].toString()), subject,
73 "wifi-full-secure",
80 QStringList() << "connect_id" << _("Connect") << "cancel_id"74 QStringList() << "connect_id" << _("Connect") << "cancel_id"
81 << _("Cancel"), notificationHints, 0);75 << _("Cancel"), notificationHints, 0);
76
77 connect(m_notification.get(), &notify::Notification::actionInvoked, this,
78 &SecretRequest::actionInvoked);
79
80 connect(m_notification.get(), &notify::Notification::closed, this,
81 &SecretRequest::notificationClosed);
82
83 m_notification->show();
82}84}
8385
84SecretRequest::~SecretRequest() {86SecretRequest::~SecretRequest() {
85 /* Close the notification if it's open */
86 if (m_notificationId != 0) {
87 m_secretAgent.notifications().CloseNotification(m_notificationId).waitForFinished();
88 m_notificationId = 0;
89 }
90}87}
9188
92/* Called when the user submits a password */89/* Called when the user submits a password */
93void SecretRequest::actionInvoked(uint id, const QString &actionKey) {90void SecretRequest::actionInvoked(const QString &actionKey) {
94 // Ignore other requests' notifications
95 if (id != m_notificationId) {
96 return;
97 }
9891
99 m_notificationId = 0;92 m_notification.reset();
10093
101 if (actionKey != "connect_id") {94 if (actionKey != "connect_id") {
102 m_secretAgent.FinishGetSecrets(*this, true);95 m_secretAgent.FinishGetSecrets(*this, true);
@@ -121,15 +114,10 @@
121}114}
122115
123/* Called when the user closes the dialog */116/* Called when the user closes the dialog */
124void SecretRequest::notificationClosed(uint id, uint reason) {117void SecretRequest::notificationClosed(uint reason) {
125 Q_UNUSED(reason);118 Q_UNUSED(reason);
126119
127 // Ignore other requests' notifications120 m_notification.reset();
128 if (id != m_notificationId) {
129 return;
130 }
131
132 m_notificationId = 0;
133121
134 m_secretAgent.FinishGetSecrets(*this, true);122 m_secretAgent.FinishGetSecrets(*this, true);
135}123}
136124
=== modified file 'src/indicator/agent/SecretRequest.h'
--- src/indicator/agent/SecretRequest.h 2015-04-21 10:59:52 +0000
+++ src/indicator/agent/SecretRequest.h 2015-08-12 13:44:19 +0000
@@ -20,6 +20,7 @@
2020
21#include <dbus-types.h>21#include <dbus-types.h>
22#include <agent/PasswordMenu.h>22#include <agent/PasswordMenu.h>
23#include <notify-cpp/notification.h>
2324
24#include <QDBusMessage>25#include <QDBusMessage>
25#include <QDBusObjectPath>26#include <QDBusObjectPath>
@@ -42,8 +43,8 @@
42 virtual ~SecretRequest();43 virtual ~SecretRequest();
4344
44public Q_SLOTS:45public Q_SLOTS:
45 void actionInvoked(uint id, const QString &actionKey);46 void actionInvoked(const QString &actionKey);
46 void notificationClosed(uint id, uint reason);47 void notificationClosed(uint reason);
4748
48public:49public:
49 const QVariantDictMap & connection() const;50 const QVariantDictMap & connection() const;
@@ -51,7 +52,7 @@
51 const QDBusMessage & message() const;52 const QDBusMessage & message() const;
5253
53protected:54protected:
54 unsigned int m_notificationId;55 notify::Notification::UPtr m_notification;
5556
56 SecretAgent &m_secretAgent;57 SecretAgent &m_secretAgent;
5758
5859
=== modified file 'src/indicator/factory.cpp'
--- src/indicator/factory.cpp 2015-04-15 15:04:51 +0000
+++ src/indicator/factory.cpp 2015-08-12 13:44:19 +0000
@@ -17,9 +17,11 @@
17 * Pete Woods <pete.woods@canonical.com>17 * Pete Woods <pete.woods@canonical.com>
18 */18 */
1919
20#include <config.h>
20#include <factory.h>21#include <factory.h>
2122
22#include <nmofono/manager-impl.h>23#include <nmofono/manager-impl.h>
24#include <notify-cpp/notification-manager.h>
2325
24using namespace std;26using namespace std;
2527
@@ -29,6 +31,17 @@
2931
30 SessionBus::Ptr m_sessionBus;32 SessionBus::Ptr m_sessionBus;
3133
34 notify::NotificationManager::SPtr m_notificationManager;
35
36 notify::NotificationManager::SPtr singletonNotificationManager()
37 {
38 if (!m_notificationManager)
39 {
40 m_notificationManager = make_shared<notify::NotificationManager>(GETTEXT_PACKAGE);
41 }
42 return m_notificationManager;
43 }
44
32 SessionBus::Ptr singletonSessionBus()45 SessionBus::Ptr singletonSessionBus()
33 {46 {
34 if (!m_sessionBus)47 if (!m_sessionBus)
@@ -42,7 +55,9 @@
42 {55 {
43 if (!m_nmofono)56 if (!m_nmofono)
44 {57 {
45 m_nmofono = make_shared<nmofono::ManagerImpl>(QDBusConnection::systemBus());58 m_nmofono = make_shared<nmofono::ManagerImpl>(
59 singletonNotificationManager(),
60 QDBusConnection::systemBus());
46 }61 }
47 return m_nmofono;62 return m_nmofono;
48 }63 }
@@ -117,7 +132,8 @@
117132
118agent::SecretAgent::UPtr Factory::newSecretAgent()133agent::SecretAgent::UPtr Factory::newSecretAgent()
119{134{
120 return make_unique<agent::SecretAgent>(QDBusConnection::systemBus(),135 return make_unique<agent::SecretAgent>(d->singletonNotificationManager(),
136 QDBusConnection::systemBus(),
121 QDBusConnection::sessionBus());137 QDBusConnection::sessionBus());
122}138}
123139
124140
=== modified file 'src/indicator/main.cpp'
--- src/indicator/main.cpp 2015-08-10 09:30:04 +0000
+++ src/indicator/main.cpp 2015-08-12 13:44:19 +0000
@@ -28,7 +28,6 @@
28#include <ctime>28#include <ctime>
2929
30#include <glib.h>30#include <glib.h>
31#include <libnotify/notify.h>
3231
33#include <config.h>32#include <config.h>
3433
@@ -53,25 +52,17 @@
53 bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);52 bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
54 textdomain(GETTEXT_PACKAGE);53 textdomain(GETTEXT_PACKAGE);
5554
56 notify_init(GETTEXT_PACKAGE);
57
58 if (argc == 2 && QString("--print-address") == argv[1])55 if (argc == 2 && QString("--print-address") == argv[1])
59 {56 {
60 qDebug() << QDBusConnection::systemBus().baseService();57 qDebug() << QDBusConnection::systemBus().baseService();
61 }58 }
6259
63 int result = 0;60 Factory factory;
64 {61 auto menu = factory.newMenuBuilder();
65 Factory factory;62 auto secretAgent = factory.newSecretAgent();
66 auto menu = factory.newMenuBuilder();63 auto connectivityService = factory.newConnectivityService();
67 auto secretAgent = factory.newSecretAgent();64
68 auto connectivityService = factory.newConnectivityService();65 QObject::connect(connectivityService.get(), &ConnectivityService::unlockAllModems, menu.get(), &MenuBuilder::unlockAllModems);
6966 QObject::connect(connectivityService.get(), &ConnectivityService::unlockModem, menu.get(), &MenuBuilder::unlockModem);
70 QObject::connect(connectivityService.get(), &ConnectivityService::unlockAllModems, menu.get(), &MenuBuilder::unlockAllModems);67 return app.exec();
71 QObject::connect(connectivityService.get(), &ConnectivityService::unlockModem, menu.get(), &MenuBuilder::unlockModem);
72 result = app.exec();
73 }
74 notify_uninit();
75
76 return result;
77}68}
7869
=== modified file 'src/indicator/nmofono/manager-impl.cpp'
--- src/indicator/nmofono/manager-impl.cpp 2015-08-07 08:55:50 +0000
+++ src/indicator/nmofono/manager-impl.cpp 2015-08-12 13:44:19 +0000
@@ -31,6 +31,7 @@
31#include <qofono-qt5/qofonomodem.h>31#include <qofono-qt5/qofonomodem.h>
32#undef slots32#undef slots
3333
34#include <notify-cpp/notification-manager.h>
34#include <notify-cpp/snapdecision/sim-unlock.h>35#include <notify-cpp/snapdecision/sim-unlock.h>
35#include <sim-unlock-dialog.h>36#include <sim-unlock-dialog.h>
36#include <util/qhash-sharedptr.h>37#include <util/qhash-sharedptr.h>
@@ -224,11 +225,11 @@
224 Q_EMIT statusUpdated(d->m_status);225 Q_EMIT statusUpdated(d->m_status);
225}226}
226227
227ManagerImpl::ManagerImpl(const QDBusConnection& systemConnection) : d(new ManagerImpl::Private(*this))228ManagerImpl::ManagerImpl(notify::NotificationManager::SPtr notificationManager, const QDBusConnection& systemConnection) : d(new ManagerImpl::Private(*this))
228{229{
229 d->nm = make_shared<OrgFreedesktopNetworkManagerInterface>(NM_DBUS_SERVICE, NM_DBUS_PATH, systemConnection);230 d->nm = make_shared<OrgFreedesktopNetworkManagerInterface>(NM_DBUS_SERVICE, NM_DBUS_PATH, systemConnection);
230231
231 d->m_unlockDialog = make_shared<SimUnlockDialog>();232 d->m_unlockDialog = make_shared<SimUnlockDialog>(notificationManager);
232 connect(d->m_unlockDialog.get(), &SimUnlockDialog::ready, d.get(), &Private::sim_unlock_ready);233 connect(d->m_unlockDialog.get(), &SimUnlockDialog::ready, d.get(), &Private::sim_unlock_ready);
233234
234 d->m_ofono = make_shared<QOfonoManager>();235 d->m_ofono = make_shared<QOfonoManager>();
235236
=== modified file 'src/indicator/nmofono/manager-impl.h'
--- src/indicator/nmofono/manager-impl.h 2015-08-05 15:14:28 +0000
+++ src/indicator/nmofono/manager-impl.h 2015-08-12 13:44:19 +0000
@@ -25,6 +25,11 @@
25#include <QDBusObjectPath>25#include <QDBusObjectPath>
26#include <QVariantMap>26#include <QVariantMap>
2727
28namespace notify
29{
30class NotificationManager;
31}
32
28namespace nmofono {33namespace nmofono {
29 class Manager;34 class Manager;
3035
@@ -40,7 +45,7 @@
40public:45public:
41 typedef std::shared_ptr<ManagerImpl> Ptr;46 typedef std::shared_ptr<ManagerImpl> Ptr;
4247
43 ManagerImpl(const QDBusConnection& systemBus);48 ManagerImpl(std::shared_ptr<notify::NotificationManager> notificationManager, const QDBusConnection& systemBus);
4449
45 // Public API50 // Public API
46 void setFlightMode(bool) override;51 void setFlightMode(bool) override;
4752
=== modified file 'src/indicator/sim-unlock-dialog.cpp'
--- src/indicator/sim-unlock-dialog.cpp 2015-06-18 12:30:09 +0000
+++ src/indicator/sim-unlock-dialog.cpp 2015-08-12 13:44:19 +0000
@@ -19,7 +19,7 @@
1919
20#include "sim-unlock-dialog.h"20#include "sim-unlock-dialog.h"
2121
22#include <notify-cpp/notification.h>22#include <notify-cpp/notification-manager.h>
23#include <notify-cpp/snapdecision/sim-unlock.h>23#include <notify-cpp/snapdecision/sim-unlock.h>
24#include <util/localisation.h>24#include <util/localisation.h>
2525
@@ -196,7 +196,7 @@
196 m_sd->showPopup(output.str(), closed);196 m_sd->showPopup(output.str(), closed);
197 }197 }
198198
199 Private(SimUnlockDialog& parent);199 Private(SimUnlockDialog& parent, notify::NotificationManager::SPtr);
200200
201public Q_SLOTS:201public Q_SLOTS:
202 void update();202 void update();
@@ -205,8 +205,6 @@
205205
206 void pinEntered(const QString& pin);206 void pinEntered(const QString& pin);
207207
208 void closed();
209
210 void reset();208 void reset();
211209
212 void pinSuccess()210 void pinSuccess()
@@ -244,13 +242,12 @@
244 }242 }
245};243};
246244
247SimUnlockDialog::Private::Private(SimUnlockDialog& parent)245SimUnlockDialog::Private::Private(SimUnlockDialog& parent, notify::NotificationManager::SPtr notificationManager)
248 : p(parent), m_doCleanUp{true}246 : p(parent), m_doCleanUp{true}
249{247{
250 m_sd = std::make_shared<notify::snapdecision::SimUnlock>();248 m_sd = make_shared<notify::snapdecision::SimUnlock>(notificationManager);
251 connect(m_sd.get(), &notify::snapdecision::SimUnlock::cancelled, this, &Private::cancelled);249 connect(m_sd.get(), &notify::snapdecision::SimUnlock::cancelled, this, &Private::cancelled);
252 connect(m_sd.get(), &notify::snapdecision::SimUnlock::pinEntered, this, &Private::pinEntered);250 connect(m_sd.get(), &notify::snapdecision::SimUnlock::pinEntered, this, &Private::pinEntered);
253 connect(m_sd.get(), &notify::snapdecision::SimUnlock::closed, this, &Private::closed);
254251
255 reset();252 reset();
256}253}
@@ -310,6 +307,7 @@
310 break;307 break;
311 }308 }
312309
310
313 m_sd->setPinMinMax(lengths[type]);311 m_sd->setPinMinMax(lengths[type]);
314312
315 std::string attempts;313 std::string attempts;
@@ -386,12 +384,6 @@
386void384void
387SimUnlockDialog::Private::cancelled()385SimUnlockDialog::Private::cancelled()
388{386{
389 m_sd->close();
390}
391
392void
393SimUnlockDialog::Private::closed()
394{
395 reset();387 reset();
396}388}
397389
@@ -421,8 +413,8 @@
421 m_doCleanUp = true;413 m_doCleanUp = true;
422}414}
423415
424SimUnlockDialog::SimUnlockDialog() :416SimUnlockDialog::SimUnlockDialog(notify::NotificationManager::SPtr notificationManager) :
425 d(new Private(*this))417 d(new Private(*this, notificationManager))
426{418{
427}419}
428420
@@ -475,9 +467,6 @@
475 pukRetries = retries[wwan::Modem::PinType::puk];467 pukRetries = retries[wwan::Modem::PinType::puk];
476 }468 }
477469
478 qDebug() << __PRETTY_FUNCTION__ << modem->name() << "pinRetries ="
479 << pinRetries << "pukRetries =" << pukRetries;
480
481 // remind the user470 // remind the user
482 if (type == wwan::Modem::PinType::pin && pinRetries == 1)471 if (type == wwan::Modem::PinType::pin && pinRetries == 1)
483 {472 {
484473
=== modified file 'src/indicator/sim-unlock-dialog.h'
--- src/indicator/sim-unlock-dialog.h 2015-04-24 08:47:08 +0000
+++ src/indicator/sim-unlock-dialog.h 2015-08-12 13:44:19 +0000
@@ -20,6 +20,7 @@
20#pragma once20#pragma once
2121
22#include <nmofono/wwan/modem.h>22#include <nmofono/wwan/modem.h>
23#include <notify-cpp/notification-manager.h>
2324
24#include <memory>25#include <memory>
25#include <QObject>26#include <QObject>
@@ -42,7 +43,7 @@
42 };43 };
4344
44 typedef std::shared_ptr<SimUnlockDialog> Ptr;45 typedef std::shared_ptr<SimUnlockDialog> Ptr;
45 SimUnlockDialog();46 SimUnlockDialog(notify::NotificationManager::SPtr notificationManager);
46 ~SimUnlockDialog();47 ~SimUnlockDialog();
4748
48 void unlock(nmofono::wwan::Modem::Ptr modem);49 void unlock(nmofono::wwan::Modem::Ptr modem);
4950
=== modified file 'src/notify-cpp/CMakeLists.txt'
--- src/notify-cpp/CMakeLists.txt 2015-05-12 09:07:46 +0000
+++ src/notify-cpp/CMakeLists.txt 2015-08-12 13:44:19 +0000
@@ -1,12 +1,15 @@
1include_directories("${CMAKE_SOURCE_DIR}/src/")1include_directories("${CMAKE_SOURCE_DIR}/src/")
2include_directories("${CMAKE_BINARY_DIR}/src/qdbus-stubs")
3include_directories("${CMAKE_SOURCE_DIR}/src/qdbus-stubs")
24
3set(NOTIFY_CPP_SOURCES5set(NOTIFY_CPP_SOURCES
4 notification.cpp6 notification.cpp
7 notification-manager.cpp
5 snapdecision/sim-unlock.cpp8 snapdecision/sim-unlock.cpp
6)9)
710
8add_library(notify_cpp STATIC ${NOTIFY_CPP_SOURCES})11add_library(notify_cpp STATIC ${NOTIFY_CPP_SOURCES})
9target_link_libraries(12target_link_libraries(
10 notify_cpp13 notify_cpp
11 ${GLIB_LIBRARIES}14 qdbus-stubs
12)15)
1316
=== added file 'src/notify-cpp/notification-manager.cpp'
--- src/notify-cpp/notification-manager.cpp 1970-01-01 00:00:00 +0000
+++ src/notify-cpp/notification-manager.cpp 2015-08-12 13:44:19 +0000
@@ -0,0 +1,76 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Pete Woods <pete.woods@canonical.com>
18 */
19
20#include <notification-manager.h>
21#include <NotificationsInterface.h>
22#include <QDebug>
23
24using namespace std;
25
26namespace notify
27{
28
29class NotificationManager::Priv
30{
31public:
32 QString m_appName;
33
34 shared_ptr<OrgFreedesktopNotificationsInterface> m_notificationInterface;
35};
36
37NotificationManager::NotificationManager(const QString &appName,
38 const QDBusConnection& sessionConnection) :
39 d(new Priv)
40{
41 d->m_appName = appName;
42 d->m_notificationInterface = make_shared<
43 OrgFreedesktopNotificationsInterface>(DBusTypes::NOTIFY_DBUS_NAME,
44 DBusTypes::NOTIFY_DBUS_PATH,
45 sessionConnection);
46
47 d->m_notificationInterface->GetServerInformation();
48
49 connect(d->m_notificationInterface.get(),
50 &OrgFreedesktopNotificationsInterface::ActionInvoked, this,
51 &NotificationManager::actionInvoked);
52
53 connect(d->m_notificationInterface.get(),
54 &OrgFreedesktopNotificationsInterface::NotificationClosed, this,
55 &NotificationManager::notificationClosed);
56
57 connect(d->m_notificationInterface.get(),
58 &OrgFreedesktopNotificationsInterface::dataChanged, this,
59 &NotificationManager::dataChanged);
60}
61
62NotificationManager::~NotificationManager()
63{
64}
65
66Notification::UPtr
67NotificationManager::notify(const QString &summary, const QString &body,
68 const QString &icon, const QStringList &actions,
69 const QVariantMap &hints, int expireTimeout)
70{
71 return make_unique<Notification>(d->m_appName, summary, body, icon, actions,
72 hints, expireTimeout,
73 d->m_notificationInterface);
74}
75
76}
077
=== added file 'src/notify-cpp/notification-manager.h'
--- src/notify-cpp/notification-manager.h 1970-01-01 00:00:00 +0000
+++ src/notify-cpp/notification-manager.h 2015-08-12 13:44:19 +0000
@@ -0,0 +1,67 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Pete Woods <pete.woods@canonical.com>
18 */
19
20#pragma once
21
22#include <memory>
23#include <QDBusConnection>
24#include <QObject>
25#include <QString>
26#include <QStringList>
27#include <QVariantMap>
28
29#include <notify-cpp/notification.h>
30
31namespace notify
32{
33
34class NotificationManager: public QObject
35{
36 Q_OBJECT
37
38public:
39 typedef std::unique_ptr<NotificationManager> UPtr;
40 typedef std::shared_ptr<NotificationManager> SPtr;
41
42 NotificationManager(const QString &appName,
43 const QDBusConnection& sessionConnection = QDBusConnection::sessionBus());
44
45 ~NotificationManager();
46
47 Notification::UPtr notify(
48 const QString &summary,
49 const QString &body,
50 const QString &icon,
51 const QStringList &actions,
52 const QVariantMap &hints,
53 int expireTimeout = -1);
54
55Q_SIGNALS:
56 void actionInvoked(uint id, const QString &action_key);
57
58 void notificationClosed(uint id, uint reason);
59
60 void dataChanged(uint id);
61
62protected:
63 class Priv;
64 std::shared_ptr<Priv> d;
65};
66
67}
068
=== modified file 'src/notify-cpp/notification.cpp'
--- src/notify-cpp/notification.cpp 2015-05-12 09:03:23 +0000
+++ src/notify-cpp/notification.cpp 2015-08-12 13:44:19 +0000
@@ -18,14 +18,17 @@
18 */18 */
1919
20#include "notification.h"20#include "notification.h"
21#include <NotificationsInterface.h>
2122
22#include <libnotify/notify.h>
23#include <QDebug>23#include <QDebug>
2424
25using namespace notify;25using namespace notify;
26using namespace std;
2627
27class notify::Notification::Private28class notify::Notification::Private: public QObject
28{29{
30 Q_OBJECT
31
29public:32public:
30 Private(Notification& parent) :33 Private(Notification& parent) :
31 p(parent)34 p(parent)
@@ -34,76 +37,135 @@
3437
35 Notification& p;38 Notification& p;
3639
40 QString m_appName;
37 QString m_summary;41 QString m_summary;
38 QString m_body;42 QString m_body;
39 QString m_icon;43 QString m_icon;
4044 QStringList m_actions;
41 std::unique_ptr<NotifyNotification, GObjectDeleter> m_notification;45 QVariantMap m_hints;
4246 int m_expireTimeout = 0;
43 static void closed_cb(NotifyNotification *,47 uint m_id = 0;
44 gpointer user_data)48
45 {49 shared_ptr<OrgFreedesktopNotificationsInterface> m_notificationsInterface;
46 Private *that = static_cast<Private *>(user_data);50
47 Q_EMIT that->p.closed();51 bool m_open = false;
48 }52 bool m_dirty = false;
4953
50 gulong disconnectId = 0;54public Q_SLOTS:
55 void notificationClosed(uint id, uint reason)
56 {
57 if (id == m_id)
58 {
59 m_open = false;
60 Q_EMIT p.closed(reason);
61 }
62 }
63
64 void actionInvoked(uint id, const QString& name)
65 {
66 if (id == m_id)
67 {
68 Q_EMIT p.actionInvoked(name);
69 }
70 }
51};71};
5272
53Notification::Notification(const QString &summary,73Notification::Notification(
54 const QString &body,74 const QString& appName, const QString &summary, const QString &body,
55 const QString &icon)75 const QString &icon, const QStringList &actions,
76 const QVariantMap &hints, int expireTimeout,
77 shared_ptr<OrgFreedesktopNotificationsInterface> notificationsInterface)
56{78{
57 d.reset(new Private(*this));79 d.reset(new Private(*this));
80 d->m_appName = appName;
58 d->m_summary = summary;81 d->m_summary = summary;
59 d->m_body = body;82 d->m_body = body;
60 d->m_icon = icon;83 d->m_icon = icon;
6184 d->m_actions = actions;
62 d->m_notification.reset(notify_notification_new(summary.toUtf8().constData(), body.toUtf8().constData(), icon.toUtf8().constData()));85 d->m_hints = hints;
63 d->disconnectId = g_signal_connect(d->m_notification.get(), "closed", G_CALLBACK(Private::closed_cb), d.get());86 d->m_expireTimeout = expireTimeout;
87 d->m_notificationsInterface = notificationsInterface;
88
89 connect(d->m_notificationsInterface.get(), &OrgFreedesktopNotificationsInterface::NotificationClosed, d.get(), &Private::notificationClosed);
90
91 connect(d->m_notificationsInterface.get(), &OrgFreedesktopNotificationsInterface::ActionInvoked, d.get(), &Private::actionInvoked);
64}92}
6593
66Notification::~Notification()94Notification::~Notification()
67{95{
68 g_signal_handler_disconnect(d->m_notification.get(), d->disconnectId);96 if (d->m_id > 0 && d->m_open)
6997 {
70// TODO Uncomment this when the notification service is more robust98 auto reply = d->m_notificationsInterface->CloseNotification(d->m_id);
71// GError* error = nullptr;99 reply.waitForFinished();
72// if (notify_notification_close(d->m_notification.get(), &error) == FALSE)100 if (reply.isError())
73// {101 {
74// qWarning() << __PRETTY_FUNCTION__ << error->message;102 qCritical() << __PRETTY_FUNCTION__ << reply.error().message();
75// g_error_free(error);103 }
76// }104 }
77}105}
78106
79QString107QString
80Notification::summary()108Notification::summary() const
81{109{
82 return d->m_summary;110 return d->m_summary;
83}111}
84112
85QString113QString
86Notification::body()114Notification::body() const
87{115{
88 return d->m_body;116 return d->m_body;
89}117}
90118
91QString119QString
92Notification::icon()120Notification::icon() const
93{121{
94 return d->m_icon;122 return d->m_icon;
95}123}
96124
97void125QStringList
98Notification::setHint(const QString &key, Variant value)126Notification::actions() const
99{127{
100 notify_notification_set_hint(d->m_notification.get(), key.toUtf8().constData(), value);128 return d->m_actions;
101}129}
102130
103void131QVariantMap
104Notification::setHintString(const QString &key, const QString &value)132Notification::hints() const
105{133{
106 notify_notification_set_hint_string(d->m_notification.get(), key.toUtf8().constData(), value.toUtf8().constData());134 return d->m_hints;
135}
136
137void
138Notification::addHint(const QString &key, const QVariant& value)
139{
140 d->m_hints[key] = value;
141 d->m_dirty = true;
142 Q_EMIT hintsUpdated(d->m_hints);
143}
144
145void
146Notification::setHints(const QVariantMap& hints)
147{
148 if (d->m_hints == hints)
149 {
150 return;
151 }
152
153 d->m_hints = hints;
154 d->m_dirty = true;
155 Q_EMIT hintsUpdated(d->m_hints);
156}
157
158void
159Notification::setActions(const QStringList& actions)
160{
161 if (d->m_actions == actions)
162 {
163 return;
164 }
165
166 d->m_actions = actions;
167 d->m_dirty = true;
168 Q_EMIT actionsUpdated(d->m_actions);
107}169}
108170
109void171void
@@ -115,7 +177,7 @@
115 }177 }
116178
117 d->m_summary = summary;179 d->m_summary = summary;
118 g_object_set(d->m_notification.get(), "summary", d->m_summary.toUtf8().constData(), nullptr);180 d->m_dirty = true;
119 Q_EMIT summaryUpdated(d->m_summary);181 Q_EMIT summaryUpdated(d->m_summary);
120}182}
121183
@@ -128,7 +190,7 @@
128 }190 }
129191
130 d->m_body = body;192 d->m_body = body;
131 g_object_set(d->m_notification.get(), "body", d->m_body.toUtf8().constData(), nullptr);193 d->m_dirty = true;
132 Q_EMIT bodyUpdated(d->m_body);194 Q_EMIT bodyUpdated(d->m_body);
133}195}
134196
@@ -141,35 +203,50 @@
141 }203 }
142204
143 d->m_icon = icon;205 d->m_icon = icon;
144 g_object_set(d->m_notification.get(), "icon", d->m_icon.toUtf8().constData(), nullptr);206 d->m_dirty = true;
145 Q_EMIT iconUpdated(d->m_icon);207 Q_EMIT iconUpdated(d->m_icon);
146}208}
147209
148void210void
149Notification::update()
150{
151 notify_notification_update(d->m_notification.get(), d->m_summary.toUtf8().constData(),
152 d->m_body.toUtf8().constData(), d->m_icon.toUtf8().constData());
153}
154
155void
156Notification::show()211Notification::show()
157{212{
158 GError *error = nullptr;213 if (d->m_dirty || !d->m_open)
159 notify_notification_show(d->m_notification.get(), &error);214 {
160 if (error) {215 auto reply = d->m_notificationsInterface->Notify(d->m_appName, d->m_id,
161 qCritical() << __PRETTY_FUNCTION__ << error->message;216 d->m_icon, d->m_summary,
162 g_error_free(error);217 d->m_body, d->m_actions,
218 d->m_hints,
219 d->m_expireTimeout);
220 reply.waitForFinished();
221 if (reply.isError())
222 {
223 qCritical() << __PRETTY_FUNCTION__ << reply.error().message();
224 }
225 else
226 {
227 d->m_id = reply;
228 d->m_dirty = false;
229 d->m_open = true;
230 }
163 }231 }
164}232}
165233
166void234void
167Notification::close()235Notification::close()
168{236{
169 GError *error = nullptr;237 if (d->m_id > 0)
170 notify_notification_close(d->m_notification.get(), &error);238 {
171 if (error) {239 auto reply = d->m_notificationsInterface->CloseNotification(d->m_id);
172 qCritical() << __PRETTY_FUNCTION__ << error->message;240 reply.waitForFinished();
173 g_error_free(error);241 if (reply.isError())
242 {
243 qCritical() << __PRETTY_FUNCTION__ << reply.error().message();
244 }
245 else
246 {
247 d->m_open = false;
248 }
174 }249 }
175}250}
251
252#include "notification.moc"
176253
=== modified file 'src/notify-cpp/notification.h'
--- src/notify-cpp/notification.h 2015-04-24 08:47:08 +0000
+++ src/notify-cpp/notification.h 2015-08-12 13:44:19 +0000
@@ -25,7 +25,12 @@
2525
26#include <QObject>26#include <QObject>
2727
28namespace notify {28class OrgFreedesktopNotificationsInterface;
29
30namespace notify
31{
32
33class NotificationManager;
2934
30class Notification: public QObject35class Notification: public QObject
31{36{
@@ -36,35 +41,38 @@
3641
37public:42public:
3843
39 typedef std::shared_ptr<Notification> Ptr;44 typedef std::unique_ptr<Notification> UPtr;
45 typedef std::shared_ptr<Notification> SPtr;
4046
41 Notification() = delete;
42 Notification(const QString &summary,
43 const QString &body,
44 const QString &icon);
45 virtual ~Notification();47 virtual ~Notification();
4648
47 /// @todo remember show() after set().49 /// @todo remember show() after set().
48 Q_PROPERTY(QString summary READ summary NOTIFY summaryUpdated)50 Q_PROPERTY(QString summary READ summary WRITE setSummary NOTIFY summaryUpdated)
49 QString summary();51 QString summary() const;
5052
51 /// @todo remember show() after set().53 /// @todo remember show() after set().
52 Q_PROPERTY(QString body READ body NOTIFY bodyUpdated)54 Q_PROPERTY(QString body READ body WRITE setBody NOTIFY bodyUpdated)
53 QString body();55 QString body() const;
5456
55 /// @todo remember show() after set().57 /// @todo remember show() after set().
56 Q_PROPERTY(QString icon READ icon NOTIFY iconUpdated)58 Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconUpdated)
57 QString icon();59 QString icon() const;
5860
59 void update();61 Q_PROPERTY(QStringList actions READ actions WRITE setActions NOTIFY actionsUpdated)
62 QStringList actions() const;
63
64 Q_PROPERTY(QVariantMap hints READ hints WRITE setHints NOTIFY hintsUpdated)
65 QVariantMap hints() const;
6066
61 void show();67 void show();
62 void close();68 void close();
6369
64public Q_SLOTS:70public Q_SLOTS:
65 void setHint(const QString &key, Variant value);71 void setActions(const QStringList& actions);
6672
67 void setHintString(const QString &key, const QString &value);73 void setHints(const QVariantMap& hints);
74
75 void addHint(const QString &key, const QVariant& value);
6876
69 void setSummary(const QString& summary);77 void setSummary(const QString& summary);
7078
@@ -73,12 +81,25 @@
73 void setIcon(const QString& icon);81 void setIcon(const QString& icon);
7482
75Q_SIGNALS:83Q_SIGNALS:
76 void closed();84 void closed(uint reason);
85
86 void hintsUpdated(const QVariantMap&);
87
88 void actionsUpdated(const QStringList&);
7789
78 void summaryUpdated(const QString&);90 void summaryUpdated(const QString&);
7991
80 void bodyUpdated(const QString&);92 void bodyUpdated(const QString&);
8193
82 void iconUpdated(const QString&);94 void iconUpdated(const QString&);
95
96 void actionInvoked(const QString& name);
97
98public:
99 Notification(const QString& appName,
100 const QString &summary, const QString &body,
101 const QString &icon, const QStringList &actions,
102 const QVariantMap &hints, int expireTimeout,
103 std::shared_ptr<OrgFreedesktopNotificationsInterface> notificationsInterface);
83};104};
84}105}
85106
=== modified file 'src/notify-cpp/snapdecision/sim-unlock.cpp'
--- src/notify-cpp/snapdecision/sim-unlock.cpp 2015-05-12 09:02:50 +0000
+++ src/notify-cpp/snapdecision/sim-unlock.cpp 2015-08-12 13:44:19 +0000
@@ -18,7 +18,6 @@
18 */18 */
1919
20#include "sim-unlock.h"20#include "sim-unlock.h"
21#include <notify-cpp/notification.h>
2221
23#include "menumodel-cpp/menu.h"22#include "menumodel-cpp/menu.h"
24#include "menumodel-cpp/menu-exporter.h"23#include "menumodel-cpp/menu-exporter.h"
@@ -31,6 +30,7 @@
31#include <QDebug>30#include <QDebug>
3231
33using namespace notify::snapdecision;32using namespace notify::snapdecision;
33using namespace std;
3434
35class SimUnlock::Private: public QObject35class SimUnlock::Private: public QObject
36{36{
@@ -39,8 +39,8 @@
39public:39public:
40 SimUnlock& p;40 SimUnlock& p;
4141
42 Notification::Ptr m_notification;42 NotificationManager::SPtr m_notificationManager;
43 Notification::Ptr m_pending;43 Notification::UPtr m_notification;
4444
45 QString m_title;45 QString m_title;
46 QString m_body;46 QString m_body;
@@ -48,7 +48,7 @@
4848
49 std::shared_ptr<SessionBus> m_sessionBus;49 std::shared_ptr<SessionBus> m_sessionBus;
5050
51 std::map<std::string, Variant> m_modelPaths;51 QVariantMap m_modelPaths;
5252
53 Action::Ptr m_notifyAction;53 Action::Ptr m_notifyAction;
54 Action::Ptr m_pinMinMaxAction;54 Action::Ptr m_pinMinMaxAction;
@@ -65,11 +65,6 @@
65 std::function<void()> m_pendingPopupClosed;65 std::function<void()> m_pendingPopupClosed;
6666
67public Q_SLOTS:67public Q_SLOTS:
68 void notificationClosed()
69 {
70 resetNotification(m_title, m_body);
71 Q_EMIT p.closed();
72 }
7368
74 void resetActionStates()69 void resetActionStates()
75 {70 {
@@ -90,16 +85,31 @@
90 }85 }
91 }86 }
9287
93 void resetNotification(const QString &title,88 void resetNotification()
94 const QString &body)
95 {89 {
96 m_pending = m_notification;90 QVariantMap hints({
97 m_notification = std::make_shared<notify::Notification>(title, body, "");91 { "x-canonical-snap-decisions", "true" },
98 m_notification->setHintString("x-canonical-snap-decisions", "true");92 { "x-canonical-snap-decisions-timeout", numeric_limits<int32_t>::max() },
99 m_notification->setHint("x-canonical-snap-decisions-timeout", TypedVariant<std::int32_t>(std::numeric_limits<std::int32_t>::max()));93 { "x-canonical-private-menu-model", m_modelPaths }
100 m_notification->setHint("x-canonical-private-menu-model", TypedVariant<std::map<std::string, Variant>>(m_modelPaths));94 });
95
96 if (m_notification)
97 {
98 m_notification->setSummary(m_title);
99 m_notification->setBody(m_body);
100 m_notification->setIcon("");
101 m_notification->setActions(QStringList());
102 m_notification->setHints(hints);
103 }
104 else
105 {
106 m_notification = m_notificationManager->notify(
107 m_title, m_body, "", QStringList(), hints);
108
109 connect(&p, &SimUnlock::titleUpdated, m_notification.get(), &Notification::setSummary);
110 connect(&p, &SimUnlock::bodyUpdated, m_notification.get(), &Notification::setBody);
111 }
101 resetActionStates();112 resetActionStates();
102 connect(m_notification.get(), &Notification::closed, this, &Private::notificationClosed);
103 }113 }
104114
105 void pinEntered(const Variant& state)115 void pinEntered(const Variant& state)
@@ -111,6 +121,7 @@
111 {121 {
112 if (!parameter.as<bool>())122 if (!parameter.as<bool>())
113 {123 {
124 p.close();
114 Q_EMIT p.cancelled();125 Q_EMIT p.cancelled();
115 }126 }
116 }127 }
@@ -145,11 +156,13 @@
145156
146public:157public:
147 Private(SimUnlock& parent,158 Private(SimUnlock& parent,
159 NotificationManager::SPtr notificationManager,
148 const QString &title,160 const QString &title,
149 const QString &body,161 const QString &body,
150 std::pair<std::uint8_t, std::uint8_t> pinMinMax)162 std::pair<std::uint8_t, std::uint8_t> pinMinMax)
151 : p(parent)163 : p(parent)
152 {164 {
165 m_notificationManager = notificationManager;
153 m_title = title;166 m_title = title;
154 m_body = body;167 m_body = body;
155 m_pinMinMax = pinMinMax;168 m_pinMinMax = pinMinMax;
@@ -162,12 +175,12 @@
162 std::string menuPath = "/com/canonical/indicator/network/unlocksim" + std::to_string(exportId);175 std::string menuPath = "/com/canonical/indicator/network/unlocksim" + std::to_string(exportId);
163 ++exportId;176 ++exportId;
164177
165 std::map<std::string, Variant> modelActions;178 QVariantMap modelActions;
166 modelActions["notifications"] = TypedVariant<std::string>(actionPath);179 modelActions["notifications"] = QString::fromStdString(actionPath);
167180
168 m_modelPaths["busName"] = TypedVariant<std::string>(m_sessionBus->address());181 m_modelPaths["busName"] = QString::fromStdString(m_sessionBus->address());
169 m_modelPaths["menuPath"] = TypedVariant<std::string>(menuPath);182 m_modelPaths["menuPath"] = QString::fromStdString(menuPath);
170 m_modelPaths["actions"] = TypedVariant<std::map<std::string, Variant>>(modelActions);183 m_modelPaths["actions"] = modelActions;
171184
172 m_menu = std::make_shared<Menu>();185 m_menu = std::make_shared<Menu>();
173 m_menuItem = std::make_shared<MenuItem>("", "notifications.simunlock");186 m_menuItem = std::make_shared<MenuItem>("", "notifications.simunlock");
@@ -205,19 +218,18 @@
205 m_menuExporter = std::make_shared<MenuExporter>(m_sessionBus, menuPath, m_menu);218 m_menuExporter = std::make_shared<MenuExporter>(m_sessionBus, menuPath, m_menu);
206 m_actionGroupExporter = std::make_shared<ActionGroupExporter>(m_sessionBus, m_actionGroup, actionPath);219 m_actionGroupExporter = std::make_shared<ActionGroupExporter>(m_sessionBus, m_actionGroup, actionPath);
207220
208 resetNotification(title, body);221 resetNotification();
209222
210 connect(&p, &SimUnlock::titleUpdated, m_notification.get(), &Notification::setSummary);
211 connect(&p, &SimUnlock::bodyUpdated, m_notification.get(), &Notification::setBody);
212 connect(&p, &SimUnlock::pinMinMaxUpdated, this, &Private::pinMinMaxChanged);223 connect(&p, &SimUnlock::pinMinMaxUpdated, this, &Private::pinMinMaxChanged);
213 }224 }
214};225};
215226
216SimUnlock::SimUnlock(const QString &title,227SimUnlock::SimUnlock(NotificationManager::SPtr notificationManager,
217 const QString &body,228 const QString &title,
218 std::pair<std::uint8_t, std::uint8_t> pinMinMax)229 const QString &body,
230 std::pair<std::uint8_t, std::uint8_t> pinMinMax)
219{231{
220 d.reset(new Private(*this, title, body, pinMinMax));232 d.reset(new Private(*this, notificationManager, title, body, pinMinMax));
221}233}
222234
223SimUnlock::~SimUnlock()235SimUnlock::~SimUnlock()
224236
=== modified file 'src/notify-cpp/snapdecision/sim-unlock.h'
--- src/notify-cpp/snapdecision/sim-unlock.h 2015-05-13 15:46:54 +0000
+++ src/notify-cpp/snapdecision/sim-unlock.h 2015-08-12 13:44:19 +0000
@@ -24,6 +24,8 @@
24#include <QObject>24#include <QObject>
25#include <QString>25#include <QString>
2626
27#include <notify-cpp/notification-manager.h>
28
27namespace notify {29namespace notify {
28namespace snapdecision {30namespace snapdecision {
2931
@@ -38,7 +40,8 @@
3840
39 typedef std::shared_ptr<SimUnlock> Ptr;41 typedef std::shared_ptr<SimUnlock> Ptr;
4042
41 explicit SimUnlock(const QString &title = "",43 explicit SimUnlock(NotificationManager::SPtr notificationManager,
44 const QString &title = "",
42 const QString &body = "",45 const QString &body = "",
43 std::pair<std::uint8_t, std::uint8_t> pinMinMax = {0, 0});46 std::pair<std::uint8_t, std::uint8_t> pinMinMax = {0, 0});
44 ~SimUnlock();47 ~SimUnlock();
@@ -84,8 +87,6 @@
8487
85 void cancelled();88 void cancelled();
8689
87 void closed();
88
89 void titleUpdated(const QString&);90 void titleUpdated(const QString&);
9091
91 void bodyUpdated(const QString&);92 void bodyUpdated(const QString&);
9293
=== modified file 'src/qdbus-stubs/dbus-types.h'
--- src/qdbus-stubs/dbus-types.h 2015-08-10 16:49:01 +0000
+++ src/qdbus-stubs/dbus-types.h 2015-08-12 13:44:19 +0000
@@ -56,4 +56,10 @@
56 static constexpr char const* URFKILL_OBJ_PATH = "/org/freedesktop/URfkill";56 static constexpr char const* URFKILL_OBJ_PATH = "/org/freedesktop/URfkill";
5757
58 static constexpr char const* URFKILL_WIFI_OBJ_PATH = "/org/freedesktop/URfkill/WLAN";58 static constexpr char const* URFKILL_WIFI_OBJ_PATH = "/org/freedesktop/URfkill/WLAN";
59 static constexpr char const* NOTIFY_DBUS_NAME = "org.freedesktop.Notifications";
60
61 static constexpr char const* NOTIFY_DBUS_INTERFACE = "org.freedesktop.Notifications";
62
63 static constexpr char const* NOTIFY_DBUS_PATH = "/org/freedesktop/Notifications";
64
59}65}
6066
=== modified file 'tests/integration/indicator-network-test-base.h'
--- tests/integration/indicator-network-test-base.h 2015-07-07 08:29:34 +0000
+++ tests/integration/indicator-network-test-base.h 2015-08-12 13:44:19 +0000
@@ -30,7 +30,11 @@
30#include <gtest/gtest.h>30#include <gtest/gtest.h>
3131
32inline void PrintTo(const QVariant& variant, std::ostream* os) {32inline void PrintTo(const QVariant& variant, std::ostream* os) {
33 *os << "QVariant(" << variant.toString().toStdString() << ")";33 QString output;
34 QDebug dbg(&output);
35 dbg << variant;
36
37 *os << "QVariant(" << output.toStdString() << ")";
34}38}
3539
36#define WAIT_FOR_SIGNALS(signalSpy, signalsExpected)\40#define WAIT_FOR_SIGNALS(signalSpy, signalsExpected)\
3741
=== modified file 'tests/integration/test-indicator.cpp'
--- tests/integration/test-indicator.cpp 2015-07-08 08:49:30 +0000
+++ tests/integration/test-indicator.cpp 2015-08-12 13:44:19 +0000
@@ -2077,12 +2077,12 @@
2077 // set sim locked2077 // set sim locked
2078 setSimManagerProperty(firstModem(), "PinRequired", "pin");2078 setSimManagerProperty(firstModem(), "PinRequired", "pin");
20792079
2080 QSignalSpy notificationsSpy(&notificationsMockInterface(),
2081 SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2082
2080 // start the indicator2083 // start the indicator
2081 ASSERT_NO_THROW(startIndicator());2084 ASSERT_NO_THROW(startIndicator());
20822085
2083 QSignalSpy notificationsSpy(&notificationsMockInterface(),
2084 SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2085
2086 // check indicator is a locked sim card and a 0-bar wifi icon.2086 // check indicator is a locked sim card and a 0-bar wifi icon.
2087 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.2087 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.
2088 // check that the “Unlock SIM” button has the correct action name.2088 // check that the “Unlock SIM” button has the correct action name.
@@ -2100,10 +2100,9 @@
2100 ).match());2100 ).match());
21012101
2102 // check that the "GetServerInformation" method was called2102 // check that the "GetServerInformation" method was called
2103 // check that the "Notify" method was called twice
2104 // check method arguments are correct2103 // check method arguments are correct
2105 std::string busName;2104 string busName;
2106 WAIT_FOR_SIGNALS(notificationsSpy, 3);2105 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2107 {2106 {
2108 QVariantList const& call(notificationsSpy.at(0));2107 QVariantList const& call(notificationsSpy.at(0));
2109 EXPECT_EQ("GetServerInformation", call.at(0));2108 EXPECT_EQ("GetServerInformation", call.at(0));
@@ -2147,45 +2146,9 @@
2147 ASSERT_TRUE(actions.contains("notifications"));2146 ASSERT_TRUE(actions.contains("notifications"));
2148 EXPECT_EQ("/com/canonical/indicator/network/unlocksim0", actions["notifications"]);2147 EXPECT_EQ("/com/canonical/indicator/network/unlocksim0", actions["notifications"]);
2149 }2148 }
2150 {
2151 QVariantList const& call(notificationsSpy.at(2));
2152 EXPECT_EQ("Notify", call.at(0));
2153 QVariantList const& args(call.at(1).toList());
2154 ASSERT_EQ(8, args.size());
2155 EXPECT_EQ("indicator-network", args.at(0));
2156 EXPECT_EQ(1, args.at(1));
2157 EXPECT_EQ("", args.at(2));
2158 EXPECT_EQ("Enter SIM PIN", args.at(3));
2159 EXPECT_EQ("3 attempts remaining", args.at(4));
2160 EXPECT_EQ(QStringList(), args.at(5));
2161 EXPECT_EQ(-1, args.at(7));
2162
2163 QVariantMap hints;
2164 ASSERT_TRUE(qDBusArgumentToMap(args.at(6), hints));
2165 ASSERT_EQ(3, hints.size());
2166 ASSERT_TRUE(hints.contains("x-canonical-private-menu-model"));
2167 ASSERT_TRUE(hints.contains("x-canonical-snap-decisions"));
2168 ASSERT_TRUE(hints.contains("x-canonical-snap-decisions-timeout"));
2169 EXPECT_EQ(true, hints["x-canonical-snap-decisions"]);
2170 EXPECT_EQ(numeric_limits<int32_t>::max(), hints["x-canonical-snap-decisions-timeout"]);
2171
2172 QVariantMap menuInfo;
2173 ASSERT_TRUE(qDBusArgumentToMap(hints["x-canonical-private-menu-model"], menuInfo));
2174 ASSERT_EQ(3, menuInfo.size());
2175 ASSERT_TRUE(menuInfo.contains("actions"));
2176 ASSERT_TRUE(menuInfo.contains("busName"));
2177 ASSERT_TRUE(menuInfo.contains("menuPath"));
2178 EXPECT_EQ(busName, menuInfo["busName"].toString().toStdString());
2179 EXPECT_EQ("/com/canonical/indicator/network/unlocksim0", menuInfo["menuPath"]);
2180
2181 QVariantMap actions;
2182 ASSERT_TRUE(qDBusArgumentToMap(menuInfo["actions"], actions));
2183 ASSERT_EQ(1, actions.size());
2184 ASSERT_TRUE(actions.contains("notifications"));
2185 EXPECT_EQ("/com/canonical/indicator/network/unlocksim0", actions["notifications"]);
2186 }
2187 notificationsSpy.clear();2149 notificationsSpy.clear();
21882150
2151 ASSERT_FALSE(busName.empty());
2189 // check contents of x-canonical-private-menu-model2152 // check contents of x-canonical-private-menu-model
2190 EXPECT_MATCHRESULT(mh::MenuMatcher(unlockSimParameters(busName, 0))2153 EXPECT_MATCHRESULT(mh::MenuMatcher(unlockSimParameters(busName, 0))
2191 .item(mh::MenuItemMatcher()2154 .item(mh::MenuItemMatcher()
@@ -2205,12 +2168,12 @@
2205 // set sim locked2168 // set sim locked
2206 setSimManagerProperty(firstModem(), "PinRequired", "pin");2169 setSimManagerProperty(firstModem(), "PinRequired", "pin");
22072170
2171 QSignalSpy notificationsSpy(&notificationsMockInterface(),
2172 SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2173
2208 // start the indicator2174 // start the indicator
2209 ASSERT_NO_THROW(startIndicator());2175 ASSERT_NO_THROW(startIndicator());
22102176
2211 QSignalSpy notificationsSpy(&notificationsMockInterface(),
2212 SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2213
2214 // check indicator is a locked sim card and a 0-bar wifi icon.2177 // check indicator is a locked sim card and a 0-bar wifi icon.
2215 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.2178 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.
2216 // check that the “Unlock SIM” button has the correct action name.2179 // check that the “Unlock SIM” button has the correct action name.
@@ -2228,15 +2191,13 @@
2228 ).match());2191 ).match());
22292192
2230 // check that the "GetServerInformation" method was called2193 // check that the "GetServerInformation" method was called
2231 // check that the "Notify" method was called twice
2232 // check method arguments are correct2194 // check method arguments are correct
2233 std::string busName;2195 std::string busName;
2234 WAIT_FOR_SIGNALS(notificationsSpy, 3);2196 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2235 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);2197 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);
2236 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});2198 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});
2237 CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});
2238 {2199 {
2239 QVariantList const& call(notificationsSpy.at(2));2200 QVariantList const& call(notificationsSpy.at(1));
2240 QVariantList const& args(call.at(1).toList());2201 QVariantList const& args(call.at(1).toList());
2241 QVariantMap hints;2202 QVariantMap hints;
2242 QVariantMap menuInfo;2203 QVariantMap menuInfo;
@@ -2284,11 +2245,10 @@
2284 )2245 )
2285 ).match());2246 ).match());
22862247
2287 // check that the "Notify" method was called twice2248 // check that the "Notify" method was called
2288 // check method arguments are correct (new notification index should be 2)2249 // check method arguments are correct (we re-use the same notification and reopen it)
2289 WAIT_FOR_SIGNALS(notificationsSpy, 2);2250 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2290 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 0});2251 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1});
2291 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 2});
2292 notificationsSpy.clear();2252 notificationsSpy.clear();
22932253
2294 // cancel the notification again2254 // cancel the notification again
@@ -2302,15 +2262,144 @@
2302 .activate(shared_ptr<GVariant>(g_variant_new_boolean(false), &mh::gvariant_deleter))2262 .activate(shared_ptr<GVariant>(g_variant_new_boolean(false), &mh::gvariant_deleter))
2303 ).match());2263 ).match());
23042264
2305 // check that the "NotificationClosed" signal was emitted (new notification index should be 2)2265 // check that the "NotificationClosed" signal was emitted (new notification index should be 1)
2306 WAIT_FOR_SIGNALS(notificationClosedSpy, 1);2266 WAIT_FOR_SIGNALS(notificationClosedSpy, 1);
2307 EXPECT_EQ(notificationClosedSpy.first(), QVariantList() << QVariant(2) << QVariant(1));2267 EXPECT_EQ(notificationClosedSpy.first(), QVariantList() << QVariant(1) << QVariant(1));
2308 notificationClosedSpy.clear();2268 notificationClosedSpy.clear();
23092269
2310 // check that the "CloseNotification" method was called2270 // check that the "CloseNotification" method was called
2311 // check method arguments are correct (new notification index should be 2)2271 // check method arguments are correct (still using the same notification: 1)
2312 WAIT_FOR_SIGNALS(notificationsSpy, 1);2272 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2313 CHECK_METHOD_CALL(notificationsSpy, 0, "CloseNotification", {0, "2"});2273 CHECK_METHOD_CALL(notificationsSpy, 0, "CloseNotification", {0, "1"});
2274 notificationsSpy.clear();
2275}
2276
2277TEST_F(TestIndicator, UnlockSIM_CancelFirstUnlockSecond)
2278{
2279 // set flight mode off, wifi off, and cell data off, and sim in
2280 setGlobalConnectedState(NM_STATE_DISCONNECTED);
2281
2282 // set sim locked
2283 setSimManagerProperty(firstModem(), "PinRequired", "pin");
2284
2285 // Create a second locked modem
2286 auto secondModem = createModem("ril_1");
2287 setSimManagerProperty(secondModem, "PinRequired", "pin");
2288
2289 QSignalSpy notificationsSpy(&notificationsMockInterface(),
2290 SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2291
2292 QSignalSpy secondModemMockInterfaceSpy(&modemMockInterface(secondModem),
2293 SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2294
2295 // start the indicator
2296 ASSERT_NO_THROW(startIndicator());
2297
2298 // check indicator is a locked sim card and a 0-bar wifi icon.
2299 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.
2300 // check that the “Unlock SIM” button has the correct action name.
2301 // unlock first SIM
2302 EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters())
2303 .item(mh::MenuItemMatcher()
2304 .mode(mh::MenuItemMatcher::Mode::starts_with)
2305 .item(flightModeSwitch())
2306 .item(mh::MenuItemMatcher()
2307 .item(modemInfo("SIM 1", "SIM Locked", "simcard-locked", true)
2308 .pass_through_activate("x-canonical-modem-locked-action")
2309 )
2310 .item(modemInfo("SIM 2", "SIM Locked", "simcard-locked", true))
2311 .item(cellularSettings())
2312 )
2313 ).match());
2314
2315 // check that the "GetServerInformation" method was called
2316 // check method arguments are correct
2317 std::string busName;
2318 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2319 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);
2320 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM 1 PIN"}, {4, "3 attempts remaining"});
2321 {
2322 QVariantList const& call(notificationsSpy.at(1));
2323 QVariantList const& args(call.at(1).toList());
2324 QVariantMap hints;
2325 QVariantMap menuInfo;
2326 ASSERT_TRUE(qDBusArgumentToMap(args.at(6), hints));
2327 ASSERT_TRUE(qDBusArgumentToMap(hints["x-canonical-private-menu-model"], menuInfo));
2328 busName = menuInfo["busName"].toString().toStdString();
2329 }
2330 notificationsSpy.clear();
2331
2332 // cancel the notification
2333 QSignalSpy notificationClosedSpy(&dbusMock.notificationDaemonInterface(),
2334 SIGNAL(NotificationClosed(uint, uint)));
2335
2336 EXPECT_MATCHRESULT(mh::MenuMatcher(unlockSimParameters(busName, 0))
2337 .item(mh::MenuItemMatcher()
2338 .action("notifications.simunlock")
2339 .string_attribute("x-canonical-type", "com.canonical.snapdecision.pinlock")
2340 .string_attribute("x-canonical-pin-min-max", "notifications.pinMinMax")
2341 .string_attribute("x-canonical-pin-popup", "notifications.popup")
2342 .string_attribute("x-canonical-pin-error", "notifications.error")
2343 .activate(shared_ptr<GVariant>(g_variant_new_boolean(false), &mh::gvariant_deleter))
2344 ).match());
2345
2346 // check that the "NotificationClosed" signal was emitted
2347 WAIT_FOR_SIGNALS(notificationClosedSpy, 1);
2348 EXPECT_EQ(notificationClosedSpy.first(), QVariantList() << QVariant(1) << QVariant(1));
2349 notificationClosedSpy.clear();
2350
2351 // check that the "CloseNotification" method was called
2352 // check method arguments are correct
2353 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2354 CHECK_METHOD_CALL(notificationsSpy, 0, "CloseNotification", {0, "1"});
2355 notificationsSpy.clear();
2356
2357 // Activate the second SIM unlock
2358 EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters())
2359 .item(mh::MenuItemMatcher()
2360 .mode(mh::MenuItemMatcher::Mode::starts_with)
2361 .item(flightModeSwitch())
2362 .item(mh::MenuItemMatcher()
2363 .item(modemInfo("SIM 1", "SIM Locked", "simcard-locked", true))
2364 .item(modemInfo("SIM 2", "SIM Locked", "simcard-locked", true)
2365 .pass_through_activate("x-canonical-modem-locked-action")
2366 )
2367 .item(cellularSettings())
2368 )
2369 ).match());
2370
2371 // check that the "Notify" method was called
2372 // check method arguments are correct (we re-use the same notification and reopen it)
2373 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2374 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"});
2375 notificationsSpy.clear();
2376
2377 secondModemMockInterfaceSpy.clear();
2378
2379 // enter the PIN
2380 EXPECT_MATCHRESULT(mh::MenuMatcher(unlockSimParameters(busName, 0))
2381 .item(mh::MenuItemMatcher()
2382 .action("notifications.simunlock")
2383 .string_attribute("x-canonical-type", "com.canonical.snapdecision.pinlock")
2384 .string_attribute("x-canonical-pin-min-max", "notifications.pinMinMax")
2385 .string_attribute("x-canonical-pin-popup", "notifications.popup")
2386 .string_attribute("x-canonical-pin-error", "notifications.error")
2387 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("1234"), &mh::gvariant_deleter))
2388 ).match());
2389
2390 // Check the PIN was sent to Ofono
2391 WAIT_FOR_SIGNALS(secondModemMockInterfaceSpy, 1);
2392 CHECK_METHOD_CALL(secondModemMockInterfaceSpy, 0, "EnterPin", {0, "pin"}, {1, "1234"});
2393
2394 // check that the "NotificationClosed" signal was emitted (new notification index should be 1)
2395 WAIT_FOR_SIGNALS(notificationClosedSpy, 1);
2396 EXPECT_EQ(notificationClosedSpy.first(), QVariantList() << QVariant(1) << QVariant(1));
2397 notificationClosedSpy.clear();
2398
2399 // check that the "CloseNotification" method was called
2400 // check method arguments are correct (still using the same notification: 1)
2401 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2402 CHECK_METHOD_CALL(notificationsSpy, 0, "CloseNotification", {0, "1"});
2314 notificationsSpy.clear();2403 notificationsSpy.clear();
2315}2404}
23162405
@@ -2322,12 +2411,12 @@
2322 // set sim locked2411 // set sim locked
2323 setSimManagerProperty(firstModem(), "PinRequired", "pin");2412 setSimManagerProperty(firstModem(), "PinRequired", "pin");
23242413
2414 QSignalSpy notificationsSpy(&notificationsMockInterface(),
2415 SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2416
2325 // start the indicator2417 // start the indicator
2326 ASSERT_NO_THROW(startIndicator());2418 ASSERT_NO_THROW(startIndicator());
23272419
2328 QSignalSpy notificationsSpy(&notificationsMockInterface(),
2329 SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2330
2331 // check indicator is a locked sim card and a 0-bar wifi icon.2420 // check indicator is a locked sim card and a 0-bar wifi icon.
2332 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.2421 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.
2333 // check that the “Unlock SIM” button has the correct action name.2422 // check that the “Unlock SIM” button has the correct action name.
@@ -2348,12 +2437,11 @@
2348 // check that the "Notify" method was called twice2437 // check that the "Notify" method was called twice
2349 // check method arguments are correct2438 // check method arguments are correct
2350 std::string busName;2439 std::string busName;
2351 WAIT_FOR_SIGNALS(notificationsSpy, 3);2440 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2352 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);2441 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);
2353 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});2442 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});
2354 CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});
2355 {2443 {
2356 QVariantList const& call(notificationsSpy.at(2));2444 QVariantList const& call(notificationsSpy.at(1));
2357 QVariantList const& args(call.at(1).toList());2445 QVariantList const& args(call.at(1).toList());
2358 QVariantMap hints;2446 QVariantMap hints;
2359 QVariantMap menuInfo;2447 QVariantMap menuInfo;
@@ -2406,12 +2494,12 @@
2406 // set sim locked2494 // set sim locked
2407 setSimManagerProperty(firstModem(), "PinRequired", "pin");2495 setSimManagerProperty(firstModem(), "PinRequired", "pin");
24082496
2497 QSignalSpy notificationsSpy(&notificationsMockInterface(),
2498 SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2499
2409 // start the indicator2500 // start the indicator
2410 ASSERT_NO_THROW(startIndicator());2501 ASSERT_NO_THROW(startIndicator());
24112502
2412 QSignalSpy notificationsSpy(&notificationsMockInterface(),
2413 SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2414
2415 // check indicator is a locked sim card and a 0-bar wifi icon.2503 // check indicator is a locked sim card and a 0-bar wifi icon.
2416 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.2504 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.
2417 // check that the “Unlock SIM” button has the correct action name.2505 // check that the “Unlock SIM” button has the correct action name.
@@ -2432,12 +2520,11 @@
2432 // check that the "Notify" method was called twice2520 // check that the "Notify" method was called twice
2433 // check method arguments are correct2521 // check method arguments are correct
2434 std::string busName;2522 std::string busName;
2435 WAIT_FOR_SIGNALS(notificationsSpy, 3);2523 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2436 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);2524 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);
2437 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});2525 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});
2438 CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "3 attempts remaining"});
2439 {2526 {
2440 QVariantList const& call(notificationsSpy.at(2));2527 QVariantList const& call(notificationsSpy.at(1));
2441 QVariantList const& args(call.at(1).toList());2528 QVariantList const& args(call.at(1).toList());
2442 QVariantMap hints;2529 QVariantMap hints;
2443 QVariantMap menuInfo;2530 QVariantMap menuInfo;
@@ -2464,13 +2551,11 @@
2464 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});2551 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});
2465 modemSpy.clear();2552 modemSpy.clear();
24662553
2467 // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin2554 // check that the "Notify" method was called when retries changes, then again for incorrect pin
2468 // check method arguments are correct (notification index should still be 1)2555 // check method arguments are correct (notification index should still be 1)
2469 WAIT_FOR_SIGNALS(notificationsSpy, 4);2556 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2470 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "2 attempts remaining"});2557 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "2 attempts remaining"});
2471 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "2 attempts remaining"});2558 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "2 attempts remaining"});
2472 CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "2 attempts remaining"});
2473 CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "2 attempts remaining"});
2474 notificationsSpy.clear();2559 notificationsSpy.clear();
24752560
2476 // check that the notification is displaying the appropriate error message2561 // check that the notification is displaying the appropriate error message
@@ -2498,13 +2583,11 @@
2498 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});2583 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});
2499 modemSpy.clear();2584 modemSpy.clear();
25002585
2501 // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin2586 // check that the "Notify" method was called when retries changes, then again for incorrect pin
2502 // check method arguments are correct (notification index should still be 1)2587 // check method arguments are correct (notification index should still be 1)
2503 WAIT_FOR_SIGNALS(notificationsSpy, 4);2588 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2504 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "1 attempt remaining"});2589 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "1 attempt remaining"});
2505 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "1 attempt remaining"});2590 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "1 attempt remaining"});
2506 CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "1 attempt remaining"});
2507 CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "1 attempt remaining"});
2508 notificationsSpy.clear();2591 notificationsSpy.clear();
25092592
2510 // check that the error message and last attempt popup are displayed2593 // check that the error message and last attempt popup are displayed
@@ -2537,13 +2620,11 @@
2537 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});2620 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});
2538 modemSpy.clear();2621 modemSpy.clear();
25392622
2540 // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin2623 // check that the "Notify" method was called when retries changes, then again for incorrect pin
2541 // check method arguments are correct (notification index should still be 1)2624 // check method arguments are correct (notification index should still be 1)
2542 WAIT_FOR_SIGNALS(notificationsSpy, 4);2625 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2543 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "0 attempts remaining"});2626 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "0 attempts remaining"});
2544 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "0 attempts remaining"});2627 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "0 attempts remaining"});
2545 CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "0 attempts remaining"});
2546 CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter SIM PIN"}, {4, "0 attempts remaining"});
2547 notificationsSpy.clear();2628 notificationsSpy.clear();
25482629
2549 // set sim blocked2630 // set sim blocked
@@ -2553,11 +2634,10 @@
2553 WAIT_FOR_SIGNALS(modemSpy, 1);2634 WAIT_FOR_SIGNALS(modemSpy, 1);
2554 modemSpy.clear();2635 modemSpy.clear();
25552636
2556 // check that the "Notify" method was called twice2637 // check that the "Notify" method was called
2557 // check method arguments are correct (notification index should still be 1)2638 // check method arguments are correct (notification index should still be 1)
2558 WAIT_FOR_SIGNALS(notificationsSpy, 2);2639 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2559 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter PUK code"}, {4, "10 attempts remaining"});2640 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter PUK code"}, {4, "10 attempts remaining"});
2560 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter PUK code"}, {4, "10 attempts remaining"});
2561 notificationsSpy.clear();2641 notificationsSpy.clear();
25622642
2563 // check that the error message and last attempt popup are displayed2643 // check that the error message and last attempt popup are displayed
@@ -2585,11 +2665,10 @@
2585 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("87654321"), &mh::gvariant_deleter))2665 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("87654321"), &mh::gvariant_deleter))
2586 ).match());2666 ).match());
25872667
2588 // check that the "Notify" method was called twice2668 // check that the "Notify" method was called
2589 // check method arguments are correct (notification index should still be 1)2669 // check method arguments are correct (notification index should still be 1)
2590 WAIT_FOR_SIGNALS(notificationsSpy, 2);2670 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2591 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter new SIM PIN"}, {4, "Create new PIN"});2671 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter new SIM PIN"}, {4, "Create new PIN"});
2592 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter new SIM PIN"}, {4, "Create new PIN"});
2593 notificationsSpy.clear();2672 notificationsSpy.clear();
25942673
2595 // enter new pin2674 // enter new pin
@@ -2598,11 +2677,10 @@
2598 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("4321"), &mh::gvariant_deleter))2677 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("4321"), &mh::gvariant_deleter))
2599 ).match());2678 ).match());
26002679
2601 // check that the "Notify" method was called twice2680 // check that the "Notify" method was called
2602 // check method arguments are correct (notification index should still be 1)2681 // check method arguments are correct (notification index should still be 1)
2603 WAIT_FOR_SIGNALS(notificationsSpy, 2);2682 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2604 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});2683 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
2605 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
2606 notificationsSpy.clear();2684 notificationsSpy.clear();
26072685
2608 // enter new pin again2686 // enter new pin again
@@ -2617,13 +2695,11 @@
2617 CHECK_METHOD_CALL(modemSpy, 0, "ResetPin", {0, "puk"}, {1, "87654321"}, {2, "4321"});2695 CHECK_METHOD_CALL(modemSpy, 0, "ResetPin", {0, "puk"}, {1, "87654321"}, {2, "4321"});
2618 modemSpy.clear();2696 modemSpy.clear();
26192697
2620 // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin2698 // check that the "Notify" method was called when retries changes, then again for incorrect pin
2621 // check method arguments are correct (notification index should still be 1)2699 // check method arguments are correct (notification index should still be 1)
2622 WAIT_FOR_SIGNALS(notificationsSpy, 4);2700 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2623 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});2701 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
2624 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});2702 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter PUK code"}, {4, "9 attempts remaining"});
2625 CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter PUK code"}, {4, "9 attempts remaining"});
2626 CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter PUK code"}, {4, "9 attempts remaining"});
2627 notificationsSpy.clear();2703 notificationsSpy.clear();
26282704
2629 // check that the notification is displaying the appropriate error message2705 // check that the notification is displaying the appropriate error message
@@ -2649,10 +2725,9 @@
2649 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("12345678"), &mh::gvariant_deleter))2725 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("12345678"), &mh::gvariant_deleter))
2650 ).match());2726 ).match());
26512727
2652 // check that the "Notify" method was called twice2728 // check that the "Notify" method was called
2653 WAIT_FOR_SIGNALS(notificationsSpy, 2);2729 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2654 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter new SIM PIN"}, {4, "Create new PIN"});2730 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter new SIM PIN"}, {4, "Create new PIN"});
2655 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter new SIM PIN"}, {4, "Create new PIN"});
2656 notificationsSpy.clear();2731 notificationsSpy.clear();
26572732
2658 // enter new pin2733 // enter new pin
@@ -2661,10 +2736,9 @@
2661 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("4321"), &mh::gvariant_deleter))2736 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("4321"), &mh::gvariant_deleter))
2662 ).match());2737 ).match());
26632738
2664 // check that the "Notify" method was called twice2739 // check that the "Notify" method was called
2665 WAIT_FOR_SIGNALS(notificationsSpy, 2);2740 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2666 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});2741 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
2667 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
2668 notificationsSpy.clear();2742 notificationsSpy.clear();
26692743
2670 // enter new pin again2744 // enter new pin again
@@ -2687,10 +2761,9 @@
2687 // check that the "Notify" method was called twice when retries changes2761 // check that the "Notify" method was called twice when retries changes
2688 // check that the "CloseNotification" method was called2762 // check that the "CloseNotification" method was called
2689 // check method arguments are correct2763 // check method arguments are correct
2690 WAIT_FOR_SIGNALS(notificationsSpy, 3);2764 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2691 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});2765 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});
2692 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM PIN"}, {4, "Create new PIN"});2766 CHECK_METHOD_CALL(notificationsSpy, 1, "CloseNotification", {0, "1"});
2693 CHECK_METHOD_CALL(notificationsSpy, 2, "CloseNotification", {0, "1"});
2694 notificationsSpy.clear();2767 notificationsSpy.clear();
2695}2768}
26962769
@@ -2703,12 +2776,12 @@
2703 auto secondModem = createModem("ril_1");2776 auto secondModem = createModem("ril_1");
2704 setSimManagerProperty(secondModem, "PinRequired", "pin");2777 setSimManagerProperty(secondModem, "PinRequired", "pin");
27052778
2779 QSignalSpy notificationsSpy(&notificationsMockInterface(),
2780 SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2781
2706 // start the indicator2782 // start the indicator
2707 ASSERT_NO_THROW(startIndicator());2783 ASSERT_NO_THROW(startIndicator());
27082784
2709 QSignalSpy notificationsSpy(&notificationsMockInterface(),
2710 SIGNAL(MethodCalled(const QString &, const QVariantList &)));
2711
2712 // check indicator is a locked sim card and a 0-bar wifi icon.2785 // check indicator is a locked sim card and a 0-bar wifi icon.
2713 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.2786 // check sim status shows “SIM Locked”, with locked sim card icon and a “Unlock SIM” button beneath.
2714 // check that the “Unlock SIM” button has the correct action name.2787 // check that the “Unlock SIM” button has the correct action name.
@@ -2730,12 +2803,11 @@
2730 // check that the "Notify" method was called twice2803 // check that the "Notify" method was called twice
2731 // check method arguments are correct2804 // check method arguments are correct
2732 std::string busName;2805 std::string busName;
2733 WAIT_FOR_SIGNALS(notificationsSpy, 3);2806 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2734 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);2807 CHECK_METHOD_CALL(notificationsSpy, 0, "GetServerInformation", /* no_args */);
2735 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM 2 PIN"}, {4, "3 attempts remaining"});2808 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 0}, {3, "Enter SIM 2 PIN"}, {4, "3 attempts remaining"});
2736 CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "3 attempts remaining"});
2737 {2809 {
2738 QVariantList const& call(notificationsSpy.at(2));2810 QVariantList const& call(notificationsSpy.at(1));
2739 QVariantList const& args(call.at(1).toList());2811 QVariantList const& args(call.at(1).toList());
2740 QVariantMap hints;2812 QVariantMap hints;
2741 QVariantMap menuInfo;2813 QVariantMap menuInfo;
@@ -2762,13 +2834,11 @@
2762 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});2834 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});
2763 modemSpy.clear();2835 modemSpy.clear();
27642836
2765 // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin2837 // check that the "Notify" method was called when retries changes, then again for incorrect pin
2766 // check method arguments are correct (notification index should still be 1)2838 // check method arguments are correct (notification index should still be 1)
2767 WAIT_FOR_SIGNALS(notificationsSpy, 4);2839 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2768 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "2 attempts remaining"});2840 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "2 attempts remaining"});
2769 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "2 attempts remaining"});2841 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "2 attempts remaining"});
2770 CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "2 attempts remaining"});
2771 CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "2 attempts remaining"});
2772 notificationsSpy.clear();2842 notificationsSpy.clear();
27732843
2774 // check that the notification is displaying the appropriate error message2844 // check that the notification is displaying the appropriate error message
@@ -2796,13 +2866,11 @@
2796 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});2866 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});
2797 modemSpy.clear();2867 modemSpy.clear();
27982868
2799 // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin2869 // check that the "Notify" method was called when retries changes, then again for incorrect pin
2800 // check method arguments are correct (notification index should still be 1)2870 // check method arguments are correct (notification index should still be 1)
2801 WAIT_FOR_SIGNALS(notificationsSpy, 4);2871 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2802 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "1 attempt remaining"});2872 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "1 attempt remaining"});
2803 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "1 attempt remaining"});2873 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "1 attempt remaining"});
2804 CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "1 attempt remaining"});
2805 CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "1 attempt remaining"});
2806 notificationsSpy.clear();2874 notificationsSpy.clear();
28072875
2808 // check that the error message and last attempt popup are displayed2876 // check that the error message and last attempt popup are displayed
@@ -2835,13 +2903,11 @@
2835 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});2903 CHECK_METHOD_CALL(modemSpy, 0, "EnterPin", {0, "pin"}, {1, "4321"});
2836 modemSpy.clear();2904 modemSpy.clear();
28372905
2838 // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin2906 // check that the "Notify" method was called when retries changes, then again for incorrect pin
2839 // check method arguments are correct (notification index should still be 1)2907 // check method arguments are correct (notification index should still be 1)
2840 WAIT_FOR_SIGNALS(notificationsSpy, 4);2908 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2841 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "0 attempts remaining"});2909 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "0 attempts remaining"});
2842 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "0 attempts remaining"});2910 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "0 attempts remaining"});
2843 CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "0 attempts remaining"});
2844 CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter SIM 2 PIN"}, {4, "0 attempts remaining"});
2845 notificationsSpy.clear();2911 notificationsSpy.clear();
28462912
2847 // set sim blocked2913 // set sim blocked
@@ -2851,11 +2917,10 @@
2851 WAIT_FOR_SIGNALS(modemSpy, 1);2917 WAIT_FOR_SIGNALS(modemSpy, 1);
2852 modemSpy.clear();2918 modemSpy.clear();
28532919
2854 // check that the "Notify" method was called twice2920 // check that the "Notify" method was called
2855 // check method arguments are correct (notification index should still be 1)2921 // check method arguments are correct (notification index should still be 1)
2856 WAIT_FOR_SIGNALS(notificationsSpy, 2);2922 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2857 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter PUK code for SIM 2"}, {4, "10 attempts remaining"});2923 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter PUK code for SIM 2"}, {4, "10 attempts remaining"});
2858 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter PUK code for SIM 2"}, {4, "10 attempts remaining"});
2859 notificationsSpy.clear();2924 notificationsSpy.clear();
28602925
2861 // check that the error message and last attempt popup are displayed2926 // check that the error message and last attempt popup are displayed
@@ -2883,11 +2948,10 @@
2883 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("87654321"), &mh::gvariant_deleter))2948 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("87654321"), &mh::gvariant_deleter))
2884 ).match());2949 ).match());
28852950
2886 // check that the "Notify" method was called twice2951 // check that the "Notify" method was called
2887 // check method arguments are correct (notification index should still be 1)2952 // check method arguments are correct (notification index should still be 1)
2888 WAIT_FOR_SIGNALS(notificationsSpy, 2);2953 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2889 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter new SIM 2 PIN"}, {4, "Create new PIN"});2954 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter new SIM 2 PIN"}, {4, "Create new PIN"});
2890 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter new SIM 2 PIN"}, {4, "Create new PIN"});
2891 notificationsSpy.clear();2955 notificationsSpy.clear();
28922956
2893 // enter new pin2957 // enter new pin
@@ -2896,11 +2960,10 @@
2896 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("4321"), &mh::gvariant_deleter))2960 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("4321"), &mh::gvariant_deleter))
2897 ).match());2961 ).match());
28982962
2899 // check that the "Notify" method was called twice2963 // check that the "Notify" method was called
2900 // check method arguments are correct (notification index should still be 1)2964 // check method arguments are correct (notification index should still be 1)
2901 WAIT_FOR_SIGNALS(notificationsSpy, 2);2965 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2902 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});2966 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
2903 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
2904 notificationsSpy.clear();2967 notificationsSpy.clear();
29052968
2906 // enter new pin again2969 // enter new pin again
@@ -2915,13 +2978,11 @@
2915 CHECK_METHOD_CALL(modemSpy, 0, "ResetPin", {0, "puk"}, {1, "87654321"}, {2, "4321"});2978 CHECK_METHOD_CALL(modemSpy, 0, "ResetPin", {0, "puk"}, {1, "87654321"}, {2, "4321"});
2916 modemSpy.clear();2979 modemSpy.clear();
29172980
2918 // check that the "Notify" method was called twice when retries changes, then twice again for incorrect pin2981 // check that the "Notify" method was called when retries changes, then again for incorrect pin
2919 // check method arguments are correct (notification index should still be 1)2982 // check method arguments are correct (notification index should still be 1)
2920 WAIT_FOR_SIGNALS(notificationsSpy, 4);2983 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2921 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});2984 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
2922 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});2985 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter PUK code for SIM 2"}, {4, "9 attempts remaining"});
2923 CHECK_METHOD_CALL(notificationsSpy, 2, "Notify", {1, 1}, {3, "Enter PUK code for SIM 2"}, {4, "9 attempts remaining"});
2924 CHECK_METHOD_CALL(notificationsSpy, 3, "Notify", {1, 1}, {3, "Enter PUK code for SIM 2"}, {4, "9 attempts remaining"});
2925 notificationsSpy.clear();2986 notificationsSpy.clear();
29262987
2927 // check that the notification is displaying the appropriate error message2988 // check that the notification is displaying the appropriate error message
@@ -2947,10 +3008,9 @@
2947 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("12345678"), &mh::gvariant_deleter))3008 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("12345678"), &mh::gvariant_deleter))
2948 ).match());3009 ).match());
29493010
2950 // check that the "Notify" method was called twice3011 // check that the "Notify" method was called
2951 WAIT_FOR_SIGNALS(notificationsSpy, 2);3012 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2952 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter new SIM 2 PIN"}, {4, "Create new PIN"});3013 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Enter new SIM 2 PIN"}, {4, "Create new PIN"});
2953 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Enter new SIM 2 PIN"}, {4, "Create new PIN"});
2954 notificationsSpy.clear();3014 notificationsSpy.clear();
29553015
2956 // enter new pin3016 // enter new pin
@@ -2959,10 +3019,9 @@
2959 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("4321"), &mh::gvariant_deleter))3019 .set_action_state(shared_ptr<GVariant>(g_variant_new_string("4321"), &mh::gvariant_deleter))
2960 ).match());3020 ).match());
29613021
2962 // check that the "Notify" method was called twice3022 // check that the "Notify" method was called
2963 WAIT_FOR_SIGNALS(notificationsSpy, 2);3023 WAIT_FOR_SIGNALS(notificationsSpy, 1);
2964 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});3024 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
2965 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
2966 notificationsSpy.clear();3025 notificationsSpy.clear();
29673026
2968 // enter new pin again3027 // enter new pin again
@@ -2985,10 +3044,9 @@
2985 // check that the "Notify" method was called twice when retries changes3044 // check that the "Notify" method was called twice when retries changes
2986 // check that the "CloseNotification" method was called3045 // check that the "CloseNotification" method was called
2987 // check method arguments are correct3046 // check method arguments are correct
2988 WAIT_FOR_SIGNALS(notificationsSpy, 3);3047 WAIT_FOR_SIGNALS(notificationsSpy, 2);
2989 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});3048 CHECK_METHOD_CALL(notificationsSpy, 0, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});
2990 CHECK_METHOD_CALL(notificationsSpy, 1, "Notify", {1, 1}, {3, "Confirm new SIM 2 PIN"}, {4, "Create new PIN"});3049 CHECK_METHOD_CALL(notificationsSpy, 1, "CloseNotification", {0, "1"});
2991 CHECK_METHOD_CALL(notificationsSpy, 2, "CloseNotification", {0, "1"});
2992 notificationsSpy.clear();3050 notificationsSpy.clear();
2993}3051}
29943052
29953053
=== modified file 'tests/unit/secret-agent/test-secret-agent.cpp'
--- tests/unit/secret-agent/test-secret-agent.cpp 2015-04-23 12:04:27 +0000
+++ tests/unit/secret-agent/test-secret-agent.cpp 2015-08-12 13:44:19 +0000
@@ -50,7 +50,8 @@
50 QProcessEnvironment env(QProcessEnvironment::systemEnvironment());50 QProcessEnvironment env(QProcessEnvironment::systemEnvironment());
51 env.insert("SECRET_AGENT_DEBUG_PASSWORD", "1");51 env.insert("SECRET_AGENT_DEBUG_PASSWORD", "1");
52 secretAgent.setProcessEnvironment(env);52 secretAgent.setProcessEnvironment(env);
53 secretAgent.setProcessChannelMode(QProcess::MergedChannels);53 secretAgent.setReadChannel(QProcess::StandardOutput);
54 secretAgent.setProcessChannelMode(QProcess::ForwardedErrorChannel);
54 secretAgent.start(SECRET_AGENT_BIN, QStringList() << "--print-address");55 secretAgent.start(SECRET_AGENT_BIN, QStringList() << "--print-address");
55 secretAgent.waitForStarted();56 secretAgent.waitForStarted();
56 secretAgent.waitForReadyRead();57 secretAgent.waitForReadyRead();
@@ -260,13 +261,14 @@
260/* Tests that if we request secrets and then cancel the request261/* Tests that if we request secrets and then cancel the request
261 that we close the notification */262 that we close the notification */
262TEST_F(TestSecretAgent, CancelGetSecrets) {263TEST_F(TestSecretAgent, CancelGetSecrets) {
264 QSignalSpy notificationSpy(notificationsInterface.data(), SIGNAL(MethodCalled(const QString &, const QVariantList &)));
265
263 agentInterface->GetSecrets(266 agentInterface->GetSecrets(
264 connection(SecretAgent::KEY_MGMT_WPA_PSK),267 connection(SecretAgent::KEY_MGMT_WPA_PSK),
265 QDBusObjectPath("/connection/foo"),268 QDBusObjectPath("/connection/foo"),
266 SecretAgent::WIRELESS_SECURITY_SETTING_NAME, QStringList(),269 SecretAgent::WIRELESS_SECURITY_SETTING_NAME, QStringList(),
267 5);270 5);
268271
269 QSignalSpy notificationSpy(notificationsInterface.data(), SIGNAL(MethodCalled(const QString &, const QVariantList &)));
270 notificationSpy.wait();272 notificationSpy.wait();
271273
272 ASSERT_EQ(1, notificationSpy.size());274 ASSERT_EQ(1, notificationSpy.size());

Subscribers

People subscribed via source and target branches