Merge lp:~tiagosh/telephony-service/refactor-ussd into lp:telephony-service

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 1060
Merged at revision: 1065
Proposed branch: lp:~tiagosh/telephony-service/refactor-ussd
Merge into: lp:telephony-service
Diff against target: 768 lines (+235/-211)
10 files modified
Ubuntu/Telephony/components.cpp (+1/-1)
indicator/ussdindicator.cpp (+49/-14)
indicator/ussdindicator.h (+7/-1)
libtelephonyservice/ofonoaccountentry.cpp (+7/-0)
libtelephonyservice/ofonoaccountentry.h (+4/-0)
libtelephonyservice/telepathyhelper.cpp (+31/-0)
libtelephonyservice/telepathyhelper.h (+7/-1)
libtelephonyservice/ussdmanager.cpp (+82/-175)
libtelephonyservice/ussdmanager.h (+15/-19)
tests/libtelephonyservice/TelepathyHelperTest.cpp (+32/-0)
To merge this branch: bzr merge lp:~tiagosh/telephony-service/refactor-ussd
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+256937@code.launchpad.net

Commit message

Add an USSDManager instance to each OfonoAccountEntry.

Description of the change

Add an USSDManager instance to each OfonoAccountEntry.

--Checklist--
Are there any related MPs required for this MP to build/function as expected? Please list.
No

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)
Yes

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?
Yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/<package-name>) on device or emulator?
Yes

If you changed the UI, was the change specified/approved by design?
N/A

If you changed UI labels, did you update the pot file?
N/A

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?
N/A

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1058. By Tiago Salem Herrmann

merge trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Code looks good, just a couple diff comments.

review: Needs Fixing
1059. By Tiago Salem Herrmann

add more checks for null pointers

1060. By Tiago Salem Herrmann

merge trunk

Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?
Yes

Did CI run pass? If not, please explain why.
No, but not related to the changes.

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
Yes

Code looks good and works as expected!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Ubuntu/Telephony/components.cpp'
--- Ubuntu/Telephony/components.cpp 2014-08-25 14:49:53 +0000
+++ Ubuntu/Telephony/components.cpp 2015-04-22 13:43:13 +0000
@@ -54,7 +54,6 @@
54 mRootContext->setContextProperty("telepathyHelper", TelepathyHelper::instance());54 mRootContext->setContextProperty("telepathyHelper", TelepathyHelper::instance());
55 mRootContext->setContextProperty("chatManager", ChatManager::instance());55 mRootContext->setContextProperty("chatManager", ChatManager::instance());
56 mRootContext->setContextProperty("callManager", CallManager::instance());56 mRootContext->setContextProperty("callManager", CallManager::instance());
57 mRootContext->setContextProperty("ussdManager", USSDManager::instance());
58 mRootContext->setContextProperty("greeter", GreeterContacts::instance());57 mRootContext->setContextProperty("greeter", GreeterContacts::instance());
5958
60}59}
@@ -66,6 +65,7 @@
66 qmlRegisterUncreatableType<CallEntry>(uri, 0, 1, "CallEntry", "Objects of this type are created in CallManager and made available to QML for usage");65 qmlRegisterUncreatableType<CallEntry>(uri, 0, 1, "CallEntry", "Objects of this type are created in CallManager and made available to QML for usage");
67 qmlRegisterUncreatableType<AudioOutput>(uri, 0, 1, "AudioOutput", "Objects of this type are created in CallEntry and made available to QML for usage");66 qmlRegisterUncreatableType<AudioOutput>(uri, 0, 1, "AudioOutput", "Objects of this type are created in CallEntry and made available to QML for usage");
68 qmlRegisterUncreatableType<AccountEntry>(uri, 0, 1, "AccountEntry", "Objects of this type are created in TelepathyHelper and made available to QML");67 qmlRegisterUncreatableType<AccountEntry>(uri, 0, 1, "AccountEntry", "Objects of this type are created in TelepathyHelper and made available to QML");
68 qmlRegisterUncreatableType<USSDManager>(uri, 0, 1, "USSDManager", "Objects of this type are created in AccountEntry and made available to QML");
69 qmlRegisterType<ContactWatcher>(uri, 0, 1, "ContactWatcher");69 qmlRegisterType<ContactWatcher>(uri, 0, 1, "ContactWatcher");
70 qmlRegisterType<PhoneUtils>(uri, 0, 1, "PhoneUtils");70 qmlRegisterType<PhoneUtils>(uri, 0, 1, "PhoneUtils");
71}71}
7272
=== modified file 'indicator/ussdindicator.cpp'
--- indicator/ussdindicator.cpp 2014-03-31 19:37:40 +0000
+++ indicator/ussdindicator.cpp 2015-04-22 13:43:13 +0000
@@ -27,6 +27,8 @@
27#include <libnotify/notify.h>27#include <libnotify/notify.h>
28#include "ringtone.h"28#include "ringtone.h"
29#include "ussdindicator.h"29#include "ussdindicator.h"
30#include "ofonoaccountentry.h"
31#include "telepathyhelper.h"
3032
31USSDIndicator::USSDIndicator(QObject *parent)33USSDIndicator::USSDIndicator(QObject *parent)
32: QObject(parent),34: QObject(parent),
@@ -35,35 +37,63 @@
35 m_notifications("org.freedesktop.Notifications",37 m_notifications("org.freedesktop.Notifications",
36 "/org/freedesktop/Notifications", QDBusConnection::sessionBus())38 "/org/freedesktop/Notifications", QDBusConnection::sessionBus())
37{39{
38 connect(USSDManager::instance(), SIGNAL(notificationReceived(const QString &)), SLOT(onNotificationReceived(const QString &)));40 setupAccounts();
39 connect(USSDManager::instance(), SIGNAL(requestReceived(const QString &)), SLOT(onRequestReceived(const QString &)));41 connect(TelepathyHelper::instance(), SIGNAL(accountsChanged()), this, SLOT(setupAccounts()));
40 connect(USSDManager::instance(), SIGNAL(initiateUSSDComplete(const QString &)), SLOT(onInitiateUSSDComplete(const QString &)));
41 connect(USSDManager::instance(), SIGNAL(respondComplete(bool, const QString &)), SLOT(onRespondComplete(bool, const QString &)));
42 connect(USSDManager::instance(), SIGNAL(stateChanged(const QString &)), SLOT(onStateChanged(const QString &)));
43
44 connect(&m_notifications, SIGNAL(ActionInvoked(uint, const QString &)), this, SLOT(actionInvoked(uint, const QString &)));42 connect(&m_notifications, SIGNAL(ActionInvoked(uint, const QString &)), this, SLOT(actionInvoked(uint, const QString &)));
45 connect(&m_notifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(notificationClosed(uint, uint)));43 connect(&m_notifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(notificationClosed(uint, uint)));
46}44}
4745
46void USSDIndicator::setupAccounts()
47{
48 Q_FOREACH(AccountEntry *account, TelepathyHelper::instance()->accounts()) {
49 OfonoAccountEntry *ofonoAccount = qobject_cast<OfonoAccountEntry*>(account);
50 if (!ofonoAccount) {
51 continue;
52 }
53
54 connect(ofonoAccount->ussdManager(), SIGNAL(notificationReceived(const QString &)), SLOT(onNotificationReceived(const QString &)), Qt::UniqueConnection);
55 connect(ofonoAccount->ussdManager(), SIGNAL(requestReceived(const QString &)), SLOT(onRequestReceived(const QString &)), Qt::UniqueConnection);
56 connect(ofonoAccount->ussdManager(), SIGNAL(initiateUSSDComplete(const QString &)), SLOT(onInitiateUSSDComplete(const QString &)), Qt::UniqueConnection);
57 connect(ofonoAccount->ussdManager(), SIGNAL(respondComplete(bool, const QString &)), SLOT(onRespondComplete(bool, const QString &)), Qt::UniqueConnection);
58 connect(ofonoAccount->ussdManager(), SIGNAL(stateChanged(const QString &)), SLOT(onStateChanged(const QString &)), Qt::UniqueConnection);
59 }
60}
61
48void USSDIndicator::onNotificationReceived(const QString &message)62void USSDIndicator::onNotificationReceived(const QString &message)
49{63{
50 showUSSDNotification(message, false);64 USSDManager *ussdManager = qobject_cast<USSDManager*>(sender());
65 if (!ussdManager) {
66 return;
67 }
68 showUSSDNotification(message, false, ussdManager);
51}69}
5270
53void USSDIndicator::onRequestReceived(const QString &message)71void USSDIndicator::onRequestReceived(const QString &message)
54{72{
55 showUSSDNotification(message, true);73 USSDManager *ussdManager = qobject_cast<USSDManager*>(sender());
74 if (!ussdManager) {
75 return;
76 }
77 showUSSDNotification(message, true, ussdManager);
56}78}
5779
58void USSDIndicator::onInitiateUSSDComplete(const QString &ussdResp)80void USSDIndicator::onInitiateUSSDComplete(const QString &ussdResp)
59{81{
60 showUSSDNotification(ussdResp, (USSDManager::instance()->state() == "user-response"));82 USSDManager *ussdManager = qobject_cast<USSDManager*>(sender());
83 if (!ussdManager) {
84 return;
85 }
86 showUSSDNotification(ussdResp, (ussdManager->state() == "user-response"), ussdManager);
61}87}
6288
63void USSDIndicator::onRespondComplete(bool success, const QString &ussdResp)89void USSDIndicator::onRespondComplete(bool success, const QString &ussdResp)
64{90{
91 USSDManager *ussdManager = qobject_cast<USSDManager*>(sender());
92 if (!ussdManager) {
93 return;
94 }
65 if (success) {95 if (success) {
66 showUSSDNotification(ussdResp, (USSDManager::instance()->state() == "user-response"));96 showUSSDNotification(ussdResp, (ussdManager->state() == "user-response"), ussdManager);
67 }97 }
68}98}
6999
@@ -72,7 +102,7 @@
72 // TODO: check if we should close notifications when the state is idle102 // TODO: check if we should close notifications when the state is idle
73}103}
74104
75void USSDIndicator::showUSSDNotification(const QString &message, bool replyRequired)105void USSDIndicator::showUSSDNotification(const QString &message, bool replyRequired, USSDManager *ussdManager)
76{106{
77 USSDMenu *menu = replyRequired ? &m_menuRequest : &m_menuNotification;107 USSDMenu *menu = replyRequired ? &m_menuRequest : &m_menuNotification;
78 QString actionId = "ok_id";108 QString actionId = "ok_id";
@@ -102,7 +132,7 @@
102 "", message,132 "", message,
103 QStringList() << actionId << actionLabel << "cancel_id"133 QStringList() << actionId << actionLabel << "cancel_id"
104 << C::gettext("Cancel"), notificationHints, 0);134 << C::gettext("Cancel"), notificationHints, 0);
105135 mUSSDRequests[m_notificationId] = ussdManager;
106136
107 Ringtone::instance()->playIncomingMessageSound();137 Ringtone::instance()->playIncomingMessageSound();
108}138}
@@ -113,12 +143,17 @@
113 return;143 return;
114 }144 }
115145
146 USSDManager *ussdManager = mUSSDRequests.take(id);
147 if (!ussdManager) {
148 return;
149 }
150
116 m_notificationId = 0;151 m_notificationId = 0;
117152
118 if (actionKey == "reply_id") {153 if (actionKey == "reply_id") {
119 USSDManager::instance()->respond(m_menuRequest.response(), USSDManager::instance()->activeAccountId());154 ussdManager->respond(m_menuRequest.response());
120 } else if (actionKey == "cancel_id") {155 } else if (actionKey == "cancel_id") {
121 USSDManager::instance()->cancel(USSDManager::instance()->activeAccountId());156 ussdManager->cancel();
122 }157 }
123 m_menuRequest.clearResponse();158 m_menuRequest.clearResponse();
124}159}
125160
=== modified file 'indicator/ussdindicator.h'
--- indicator/ussdindicator.h 2014-03-31 19:37:40 +0000
+++ indicator/ussdindicator.h 2015-04-22 13:43:13 +0000
@@ -27,13 +27,14 @@
27#include "indicator/NotificationsInterface.h"27#include "indicator/NotificationsInterface.h"
28#include "ussdmanager.h"28#include "ussdmanager.h"
29#include "ussdmenu.h"29#include "ussdmenu.h"
30#include "ofonoaccountentry.h"
3031
31class USSDIndicator : public QObject32class USSDIndicator : public QObject
32{33{
33 Q_OBJECT34 Q_OBJECT
34public:35public:
35 explicit USSDIndicator(QObject *parent = 0);36 explicit USSDIndicator(QObject *parent = 0);
36 void showUSSDNotification(const QString &message, bool replyRequired);37 void showUSSDNotification(const QString &message, bool replyRequired, USSDManager *ussdManager);
3738
38public Q_SLOTS:39public Q_SLOTS:
39 void onNotificationReceived(const QString &message);40 void onNotificationReceived(const QString &message);
@@ -43,12 +44,17 @@
43 void onStateChanged(const QString &state);44 void onStateChanged(const QString &state);
44 void actionInvoked(uint id, const QString &actionKey);45 void actionInvoked(uint id, const QString &actionKey);
45 void notificationClosed(uint id, uint reason);46 void notificationClosed(uint id, uint reason);
47private Q_SLOTS:
48 void setupAccounts();
49
46private:50private:
47 unsigned int m_notificationId;51 unsigned int m_notificationId;
48 USSDMenu m_menuRequest;52 USSDMenu m_menuRequest;
49 USSDMenu m_menuNotification;53 USSDMenu m_menuNotification;
50 QString mPendingMessage;54 QString mPendingMessage;
51 org::freedesktop::Notifications m_notifications;55 org::freedesktop::Notifications m_notifications;
56 QMap<int, USSDManager*> mUSSDRequests;
57 QList<OfonoAccountEntry*> mAccounts;
52};58};
5359
54#endif // USSDINDICATOR_H60#endif // USSDINDICATOR_H
5561
=== modified file 'libtelephonyservice/ofonoaccountentry.cpp'
--- libtelephonyservice/ofonoaccountentry.cpp 2015-03-17 18:26:32 +0000
+++ libtelephonyservice/ofonoaccountentry.cpp 2015-04-22 13:43:13 +0000
@@ -37,6 +37,13 @@
37 connect(this,37 connect(this,
38 SIGNAL(statusMessageChanged()),38 SIGNAL(statusMessageChanged()),
39 SIGNAL(emergencyCallsAvailableChanged()));39 SIGNAL(emergencyCallsAvailableChanged()));
40
41 mUssdManager = new USSDManager(this, this);
42}
43
44USSDManager *OfonoAccountEntry::ussdManager() const
45{
46 return mUssdManager;
40}47}
4148
42QStringList OfonoAccountEntry::emergencyNumbers() const49QStringList OfonoAccountEntry::emergencyNumbers() const
4350
=== modified file 'libtelephonyservice/ofonoaccountentry.h'
--- libtelephonyservice/ofonoaccountentry.h 2015-03-17 18:21:59 +0000
+++ libtelephonyservice/ofonoaccountentry.h 2015-04-22 13:43:13 +0000
@@ -23,6 +23,7 @@
23#define OFONOACCOUNTENTRY_H23#define OFONOACCOUNTENTRY_H
2424
25#include "accountentry.h"25#include "accountentry.h"
26#include "ussdmanager.h"
2627
27class OfonoAccountEntry : public AccountEntry28class OfonoAccountEntry : public AccountEntry
28{29{
@@ -35,6 +36,7 @@
35 Q_PROPERTY(bool emergencyCallsAvailable READ emergencyCallsAvailable NOTIFY emergencyCallsAvailableChanged)36 Q_PROPERTY(bool emergencyCallsAvailable READ emergencyCallsAvailable NOTIFY emergencyCallsAvailableChanged)
36 Q_PROPERTY(bool simLocked READ simLocked NOTIFY simLockedChanged)37 Q_PROPERTY(bool simLocked READ simLocked NOTIFY simLockedChanged)
37 Q_PROPERTY(QString serial READ serial NOTIFY serialChanged)38 Q_PROPERTY(QString serial READ serial NOTIFY serialChanged)
39 Q_PROPERTY(USSDManager* ussdManager READ ussdManager CONSTANT)
38 friend class AccountEntryFactory;40 friend class AccountEntryFactory;
3941
40public:42public:
@@ -46,6 +48,7 @@
46 bool emergencyCallsAvailable() const;48 bool emergencyCallsAvailable() const;
47 bool simLocked() const;49 bool simLocked() const;
48 QString serial() const;50 QString serial() const;
51 USSDManager *ussdManager() const;
4952
50 // reimplemented from AccountEntry53 // reimplemented from AccountEntry
51 virtual AccountEntry::AccountType type() const;54 virtual AccountEntry::AccountType type() const;
@@ -81,6 +84,7 @@
81 uint mVoicemailCount;84 uint mVoicemailCount;
82 bool mVoicemailIndicator;85 bool mVoicemailIndicator;
83 QString mSerial;86 QString mSerial;
87 USSDManager *mUssdManager;
84};88};
8589
86#endif // OFONOACCOUNTENTRY_H90#endif // OFONOACCOUNTENTRY_H
8791
=== modified file 'libtelephonyservice/telepathyhelper.cpp'
--- libtelephonyservice/telepathyhelper.cpp 2015-03-26 21:52:43 +0000
+++ libtelephonyservice/telepathyhelper.cpp 2015-04-22 13:43:13 +0000
@@ -162,6 +162,22 @@
162 return activeAccountList;162 return activeAccountList;
163}163}
164164
165QList<AccountEntry*> TelepathyHelper::phoneAccounts() const
166{
167 QList<AccountEntry*> accountList;
168 Q_FOREACH(AccountEntry *account, mAccounts) {
169 if (account->type() == AccountEntry::PhoneAccount) {
170 accountList << account;
171 }
172 }
173 return accountList;
174}
175
176QQmlListProperty<AccountEntry> TelepathyHelper::qmlPhoneAccounts()
177{
178 return QQmlListProperty<AccountEntry>(this, 0, phoneAccountsCount, phoneAccountAt);
179}
180
165QQmlListProperty<AccountEntry> TelepathyHelper::qmlAccounts()181QQmlListProperty<AccountEntry> TelepathyHelper::qmlAccounts()
166{182{
167 return QQmlListProperty<AccountEntry>(this, 0, accountsCount, accountAt);183 return QQmlListProperty<AccountEntry>(this, 0, accountsCount, accountAt);
@@ -357,12 +373,24 @@
357 return spec;373 return spec;
358}374}
359375
376int TelepathyHelper::phoneAccountsCount(QQmlListProperty<AccountEntry> *p)
377{
378 Q_UNUSED(p)
379 return TelepathyHelper::instance()->phoneAccounts().count();
380}
381
360int TelepathyHelper::accountsCount(QQmlListProperty<AccountEntry> *p)382int TelepathyHelper::accountsCount(QQmlListProperty<AccountEntry> *p)
361{383{
362 Q_UNUSED(p)384 Q_UNUSED(p)
363 return TelepathyHelper::instance()->accounts().count();385 return TelepathyHelper::instance()->accounts().count();
364}386}
365387
388AccountEntry *TelepathyHelper::phoneAccountAt(QQmlListProperty<AccountEntry> *p, int index)
389{
390 Q_UNUSED(p)
391 return TelepathyHelper::instance()->phoneAccounts()[index];
392}
393
366AccountEntry *TelepathyHelper::accountAt(QQmlListProperty<AccountEntry> *p, int index)394AccountEntry *TelepathyHelper::accountAt(QQmlListProperty<AccountEntry> *p, int index)
367{395{
368 Q_UNUSED(p)396 Q_UNUSED(p)
@@ -391,6 +419,7 @@
391419
392 Q_EMIT accountIdsChanged();420 Q_EMIT accountIdsChanged();
393 Q_EMIT accountsChanged();421 Q_EMIT accountsChanged();
422 Q_EMIT phoneAccountsChanged();
394 Q_EMIT activeAccountsChanged();423 Q_EMIT activeAccountsChanged();
395 onSettingsChanged("defaultSimForMessages");424 onSettingsChanged("defaultSimForMessages");
396 onSettingsChanged("defaultSimForCalls");425 onSettingsChanged("defaultSimForCalls");
@@ -418,6 +447,7 @@
418447
419 Q_EMIT accountIdsChanged();448 Q_EMIT accountIdsChanged();
420 Q_EMIT accountsChanged();449 Q_EMIT accountsChanged();
450 Q_EMIT phoneAccountsChanged();
421 Q_EMIT activeAccountsChanged();451 Q_EMIT activeAccountsChanged();
422 onSettingsChanged("defaultSimForMessages");452 onSettingsChanged("defaultSimForMessages");
423 onSettingsChanged("defaultSimForCalls");453 onSettingsChanged("defaultSimForCalls");
@@ -452,6 +482,7 @@
452482
453 Q_EMIT accountIdsChanged();483 Q_EMIT accountIdsChanged();
454 Q_EMIT accountsChanged();484 Q_EMIT accountsChanged();
485 Q_EMIT phoneAccountsChanged();
455 Q_EMIT activeAccountsChanged();486 Q_EMIT activeAccountsChanged();
456 onSettingsChanged("defaultSimForMessages");487 onSettingsChanged("defaultSimForMessages");
457 onSettingsChanged("defaultSimForCalls");488 onSettingsChanged("defaultSimForCalls");
458489
=== modified file 'libtelephonyservice/telepathyhelper.h'
--- libtelephonyservice/telepathyhelper.h 2015-03-23 18:17:51 +0000
+++ libtelephonyservice/telepathyhelper.h 2015-04-22 13:43:13 +0000
@@ -48,6 +48,7 @@
48 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)48 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
49 Q_PROPERTY(QStringList accountIds READ accountIds NOTIFY accountIdsChanged)49 Q_PROPERTY(QStringList accountIds READ accountIds NOTIFY accountIdsChanged)
50 Q_PROPERTY(QQmlListProperty<AccountEntry> accounts READ qmlAccounts NOTIFY accountsChanged)50 Q_PROPERTY(QQmlListProperty<AccountEntry> accounts READ qmlAccounts NOTIFY accountsChanged)
51 Q_PROPERTY(QQmlListProperty<AccountEntry> phoneAccounts READ qmlPhoneAccounts NOTIFY phoneAccountsChanged)
51 Q_PROPERTY(QQmlListProperty<AccountEntry> activeAccounts READ qmlActiveAccounts NOTIFY activeAccountsChanged)52 Q_PROPERTY(QQmlListProperty<AccountEntry> activeAccounts READ qmlActiveAccounts NOTIFY activeAccountsChanged)
52 Q_PROPERTY(AccountEntry *defaultMessagingAccount READ defaultMessagingAccount NOTIFY defaultMessagingAccountChanged)53 Q_PROPERTY(AccountEntry *defaultMessagingAccount READ defaultMessagingAccount NOTIFY defaultMessagingAccountChanged)
53 Q_PROPERTY(AccountEntry *defaultCallAccount READ defaultCallAccount NOTIFY defaultCallAccountChanged)54 Q_PROPERTY(AccountEntry *defaultCallAccount READ defaultCallAccount NOTIFY defaultCallAccountChanged)
@@ -65,8 +66,10 @@
6566
66 static TelepathyHelper *instance();67 static TelepathyHelper *instance();
67 QList<AccountEntry*> accounts() const;68 QList<AccountEntry*> accounts() const;
69 QList<AccountEntry*> phoneAccounts() const;
68 QList<AccountEntry*> activeAccounts() const;70 QList<AccountEntry*> activeAccounts() const;
69 QQmlListProperty<AccountEntry> qmlAccounts();71 QQmlListProperty<AccountEntry> qmlAccounts();
72 QQmlListProperty<AccountEntry> qmlPhoneAccounts();
70 QQmlListProperty<AccountEntry> qmlActiveAccounts();73 QQmlListProperty<AccountEntry> qmlActiveAccounts();
71 ChannelObserver *channelObserver() const;74 ChannelObserver *channelObserver() const;
72 QDBusInterface *handlerInterface() const;75 QDBusInterface *handlerInterface() const;
@@ -97,7 +100,9 @@
97 static AccountEntry *accountAt(QQmlListProperty<AccountEntry> *p, int index);100 static AccountEntry *accountAt(QQmlListProperty<AccountEntry> *p, int index);
98 static int activeAccountsCount(QQmlListProperty<AccountEntry> *p);101 static int activeAccountsCount(QQmlListProperty<AccountEntry> *p);
99 static AccountEntry *activeAccountAt(QQmlListProperty<AccountEntry> *p, int index);102 static AccountEntry *activeAccountAt(QQmlListProperty<AccountEntry> *p, int index);
100103 static int phoneAccountsCount(QQmlListProperty<AccountEntry> *p);
104 static AccountEntry *phoneAccountAt(QQmlListProperty<AccountEntry> *p, int index);
105
101Q_SIGNALS:106Q_SIGNALS:
102 void channelObserverCreated(ChannelObserver *observer);107 void channelObserverCreated(ChannelObserver *observer);
103 void channelObserverUnregistered();108 void channelObserverUnregistered();
@@ -105,6 +110,7 @@
105 void connectedChanged();110 void connectedChanged();
106 void accountIdsChanged();111 void accountIdsChanged();
107 void accountsChanged();112 void accountsChanged();
113 void phoneAccountsChanged();
108 void activeAccountsChanged();114 void activeAccountsChanged();
109 void setupReady();115 void setupReady();
110 void defaultMessagingAccountChanged();116 void defaultMessagingAccountChanged();
111117
=== modified file 'libtelephonyservice/ussdmanager.cpp'
--- libtelephonyservice/ussdmanager.cpp 2015-02-03 17:30:41 +0000
+++ libtelephonyservice/ussdmanager.cpp 2015-04-22 13:43:13 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2012 Canonical, Ltd.2 * Copyright (C) 2012-2015 Canonical, Ltd.
3 *3 *
4 * Authors:4 * Authors:
5 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>5 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
@@ -30,198 +30,105 @@
30typedef QMap<QString, QVariant> dbusQMap;30typedef QMap<QString, QVariant> dbusQMap;
31Q_DECLARE_METATYPE(dbusQMap)31Q_DECLARE_METATYPE(dbusQMap)
3232
33USSDManager *USSDManager::instance()33USSDManager::USSDManager(AccountEntry *account, QObject *parent)
34{34: QObject(parent),
35 static USSDManager *self = new USSDManager();35 mState("idle"),
36 return self;36 mAccount(account)
37}37{
3838 connect(mAccount, SIGNAL(connectedChanged()), this, SLOT(onConnectionChanged()));
39USSDManager::USSDManager(QObject *parent)39 onConnectionChanged();
40: QObject(parent)40}
41{41
42 connect(TelepathyHelper::instance(), SIGNAL(accountsChanged()), SLOT(onAccountsChanged()));42void USSDManager::initiate(const QString &command)
43 onAccountsChanged();43{
44}44 QDBusInterface ussdIface(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE);
45
46Tp::ConnectionPtr USSDManager::connectionForAccountId(const QString &accountId)
47{
48 AccountEntry *accountEntry;
49 if (accountId.isNull()) {
50 accountEntry = TelepathyHelper::instance()->accounts()[0];
51 } else {
52 accountEntry = TelepathyHelper::instance()->accountForId(accountId);
53 }
54
55 return accountEntry->account()->connection();
56}
57
58void USSDManager::initiate(const QString &command, const QString &accountId)
59{
60 Tp::ConnectionPtr conn = connectionForAccountId(accountId);
61 QString busName = conn->busName();
62 QString objectPath = conn->objectPath();
63 QDBusInterface ussdIface(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE);
64 ussdIface.asyncCall("Initiate", command);45 ussdIface.asyncCall("Initiate", command);
65}46}
6647
67void USSDManager::respond(const QString &reply, const QString &accountId)48void USSDManager::respond(const QString &reply)
68{49{
69 Tp::ConnectionPtr conn = connectionForAccountId(accountId);50 QDBusInterface ussdIface(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE);
70 QString busName = conn->busName();
71 QString objectPath = conn->objectPath();
72 QDBusInterface ussdIface(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE);
73 ussdIface.asyncCall("Respond", reply);51 ussdIface.asyncCall("Respond", reply);
74}52}
7553
76void USSDManager::cancel(const QString &accountId)54void USSDManager::cancel()
77{55{
78 Tp::ConnectionPtr conn = connectionForAccountId(accountId);56 QDBusInterface ussdIface(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE);
79 QString busName = conn->busName();
80 QString objectPath = conn->objectPath();
81 QDBusInterface ussdIface(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE);
82 ussdIface.asyncCall("Cancel");57 ussdIface.asyncCall("Cancel");
83}58}
8459
85void USSDManager::disconnectAllSignals(const Tp::ConnectionPtr& conn)60void USSDManager::connectAllSignals()
86{61{
87 if (conn.isNull()) {62 if (mBusName.isEmpty() || mObjectPath.isEmpty()) {
88 return;63 return;
89 }64 }
9065
91 QString busName = conn->busName();66 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "StateChanged", this, SLOT(onStateChanged(QString)));
92 QString objectPath = conn->objectPath();67 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RequestReceived", this, SIGNAL(requestReceived(QString)));
9368 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "NotificationReceived", this, SIGNAL(notificationReceived(QString)));
94 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "StateChanged", this, SLOT(onStateChanged(QString)));69 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateUSSDComplete", this, SIGNAL(initiateUSSDComplete(QString)));
95 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RequestReceived", this, SIGNAL(requestReceived(QString)));70 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RespondComplete", this, SIGNAL(respondComplete(bool, QString)));
96 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "NotificationReceived", this, SIGNAL(notificationReceived(QString)));71 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "BarringComplete", this, SIGNAL(barringComplete(QString, QString, QVariantMap)));
97 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateUSSDComplete", this, SIGNAL(initiateUSSDComplete(QString)));72 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ForwardingComplete", this, SIGNAL(forwardingComplete(QString, QString, QVariantMap)));
98 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RespondComplete", this, SIGNAL(respondComplete(bool, QString)));73 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "WaitingComplete", this, SIGNAL(waitingComplete(QString, QVariantMap)));
99 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "BarringComplete", this, SIGNAL(barringComplete(QString, QString, QVariantMap)));74 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLinePresentationComplete", this, SIGNAL(callingLinePresentationComplete(QString, QString)));
100 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ForwardingComplete", this, SIGNAL(forwardingComplete(QString, QString, QVariantMap)));75 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLineRestrictionComplete", this, SIGNAL(callingLineRestrictionComplete(QString, QString)));
101 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "WaitingComplete", this, SIGNAL(waitingComplete(QString, QVariantMap)));76 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLineRestrictionComplete", this, SIGNAL(connectedLineRestrictionComplete(QString, QString)));
102 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLinePresentationComplete", this, SIGNAL(callingLinePresentationComplete(QString, QString)));77 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLinePresentationComplete", this, SIGNAL(connectedLinePresentationComplete(QString, QString)));
103 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLineRestrictionComplete", this, SIGNAL(callingLineRestrictionComplete(QString, QString)));78 QDBusConnection::sessionBus().connect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateFailed", this, SIGNAL(initiateFailed()));
104 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLineRestrictionComplete", this, SIGNAL(connectedLineRestrictionComplete(QString, QString)));79}
105 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLinePresentationComplete", this, SIGNAL(connectedLinePresentationComplete(QString, QString)));80
106 QDBusConnection::sessionBus().disconnect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateFailed", this, SIGNAL(initiateFailed()));81void USSDManager::disconnectAllSignals()
107}82{
10883 if (mBusName.isEmpty() || mObjectPath.isEmpty()) {
109void USSDManager::connectAllSignals(const Tp::ConnectionPtr& conn)84 return;
110{85 }
111 if (conn.isNull()) {86 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "StateChanged", this, SLOT(onStateChanged(QString)));
112 return;87 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RequestReceived", this, SIGNAL(requestReceived(QString)));
113 }88 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "NotificationReceived", this, SIGNAL(notificationReceived(QString)));
11489 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateUSSDComplete", this, SIGNAL(initiateUSSDComplete(QString)));
115 QString busName = conn->busName();90 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RespondComplete", this, SIGNAL(respondComplete(bool, QString)));
116 QString objectPath = conn->objectPath();91 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "BarringComplete", this, SIGNAL(barringComplete(QString, QString, QVariantMap)));
11792 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ForwardingComplete", this, SIGNAL(forwardingComplete(QString, QString, QVariantMap)));
118 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "StateChanged", this, SLOT(onStateChanged(QString)));93 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "WaitingComplete", this, SIGNAL(waitingComplete(QString, QVariantMap)));
119 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RequestReceived", this, SIGNAL(requestReceived(QString)));94 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLinePresentationComplete", this, SIGNAL(callingLinePresentationComplete(QString, QString)));
120 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "NotificationReceived", this, SIGNAL(notificationReceived(QString)));95 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLineRestrictionComplete", this, SIGNAL(callingLineRestrictionComplete(QString, QString)));
121 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateUSSDComplete", this, SIGNAL(initiateUSSDComplete(QString)));96 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLineRestrictionComplete", this, SIGNAL(connectedLineRestrictionComplete(QString, QString)));
122 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "RespondComplete", this, SIGNAL(respondComplete(bool, QString)));97 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLinePresentationComplete", this, SIGNAL(connectedLinePresentationComplete(QString, QString)));
123 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "BarringComplete", this, SIGNAL(barringComplete(QString, QString, QVariantMap)));98 QDBusConnection::sessionBus().disconnect(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateFailed", this, SIGNAL(initiateFailed()));
124 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ForwardingComplete", this, SIGNAL(forwardingComplete(QString, QString, QVariantMap)));99}
125 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "WaitingComplete", this, SIGNAL(waitingComplete(QString, QVariantMap)));100
126 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLinePresentationComplete", this, SIGNAL(callingLinePresentationComplete(QString, QString)));101void USSDManager::onConnectionChanged()
127 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "CallingLineRestrictionComplete", this, SIGNAL(callingLineRestrictionComplete(QString, QString)));102{
128 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLineRestrictionComplete", this, SIGNAL(connectedLineRestrictionComplete(QString, QString)));103 disconnectAllSignals();
129 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "ConnectedLinePresentationComplete", this, SIGNAL(connectedLinePresentationComplete(QString, QString)));104
130 QDBusConnection::sessionBus().connect(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE, "InitiateFailed", this, SIGNAL(initiateFailed()));105 if (mAccount->account()->connection().isNull()) {
131}106 qDebug() << "USSDManager: Failed to connect signals";
132107 return;
133void USSDManager::accountConnectedChanged()108 }
134{109
135 AccountEntry *accountEntry = qobject_cast<AccountEntry*>(sender());110 mBusName = mAccount->account()->connection()->busName();
136 if (!accountEntry) {111 mObjectPath = mAccount->account()->connection()->objectPath();
137 return;112
138 }113 QDBusInterface ussdIface(mBusName, mObjectPath, CANONICAL_TELEPHONY_USSD_IFACE);
139 Tp::ConnectionPtr conn(accountEntry->account()->connection());114 mState = ussdIface.property("State").toString();
140 disconnectAllSignals(conn);115
141116 connectAllSignals();
142 if (accountEntry->connected()) {117}
143 QString busName = conn->busName();118
144 QString objectPath = conn->objectPath();119void USSDManager::onStateChanged(const QString &state)
145120{
146 connectAllSignals(conn);121 mState = state;
147122 Q_EMIT stateChanged(mState);
148 QDBusInterface ussdIface(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE);
149 mStates[accountEntry->accountId()] = ussdIface.property("State").toString();
150 }
151}
152
153void USSDManager::onAccountsChanged()
154{
155 Q_FOREACH (AccountEntry *accountEntry, TelepathyHelper::instance()->accounts()) {
156 QObject::disconnect(accountEntry, SIGNAL(connectedChanged()), this, SLOT(accountConnectedChanged()));
157 QObject::connect(accountEntry, SIGNAL(connectedChanged()), this, SLOT(accountConnectedChanged()));
158
159 // disconnect all and reconnect only the online accounts
160 Tp::ConnectionPtr conn(accountEntry->account()->connection());
161 disconnectAllSignals(conn);
162 mStates.remove(accountEntry->accountId());
163
164 if (accountEntry->connected()) {
165 QString busName = conn->busName();
166 QString objectPath = conn->objectPath();
167
168 connectAllSignals(conn);
169
170 QDBusInterface ussdIface(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE);
171 mStates[accountEntry->accountId()] = ussdIface.property("State").toString();
172 }
173 }
174 Q_EMIT stateChanged(state());
175 Q_EMIT activeChanged();123 Q_EMIT activeChanged();
176 Q_EMIT activeAccountIdChanged();
177}
178
179void USSDManager::onStateChanged(const QString &)
180{
181 Q_FOREACH (AccountEntry *accountEntry, TelepathyHelper::instance()->accounts()) {
182 Tp::ConnectionPtr conn(accountEntry->account()->connection());
183 if (accountEntry->connected()) {
184 QString busName = conn->busName();
185 QString objectPath = conn->objectPath();
186 QDBusInterface ussdIface(busName, objectPath, CANONICAL_TELEPHONY_USSD_IFACE);
187 mStates[accountEntry->accountId()] = ussdIface.property("State").toString();
188 }
189 }
190 Q_EMIT stateChanged(state());
191}124}
192125
193bool USSDManager::active() const126bool USSDManager::active() const
194{127{
195 QMap<QString, QString>::const_iterator i = mStates.constBegin();128 return mState != "idle";
196 while (i != mStates.constEnd()) {
197 if (i.value() != "idle") {
198 return true;
199 }
200 ++i;
201 }
202 return false;
203}
204
205QString USSDManager::activeAccountId() const
206{
207 QMap<QString, QString>::const_iterator i = mStates.constBegin();
208 while (i != mStates.constEnd()) {
209 if (i.value() != "idle") {
210 return i.key();
211 }
212 ++i;
213 }
214 return QString::null;
215}129}
216130
217QString USSDManager::state() const131QString USSDManager::state() const
218{132{
219 QMap<QString, QString>::const_iterator i = mStates.constBegin();133 return mState;
220 while (i != mStates.constEnd()) {
221 if (i.value() != "idle") {
222 return i.value();
223 }
224 ++i;
225 }
226 return "idle";
227}134}
228135
=== modified file 'libtelephonyservice/ussdmanager.h'
--- libtelephonyservice/ussdmanager.h 2015-02-03 17:30:41 +0000
+++ libtelephonyservice/ussdmanager.h 2015-04-22 13:43:13 +0000
@@ -28,6 +28,7 @@
28#include <TelepathyQt/Connection>28#include <TelepathyQt/Connection>
2929
30class TelepathyHelper;30class TelepathyHelper;
31class AccountEntry;
3132
32class USSDManager : public QObject33class USSDManager : public QObject
33{34{
@@ -35,30 +36,23 @@
35 Q_PROPERTY(bool active 36 Q_PROPERTY(bool active
36 READ active37 READ active
37 NOTIFY activeChanged)38 NOTIFY activeChanged)
38 Q_PROPERTY(QString activeAccountId
39 READ activeAccountId
40 NOTIFY activeAccountIdChanged)
41 Q_PROPERTY(QString state 39 Q_PROPERTY(QString state
42 READ state40 READ state
43 NOTIFY stateChanged)41 NOTIFY stateChanged)
44public:42public:
45 static USSDManager *instance();43 explicit USSDManager(AccountEntry *account, QObject *parent = 0);
46 Q_INVOKABLE void initiate(const QString &command, const QString &accountId = QString::null);44 Q_INVOKABLE void initiate(const QString &command);
47 Q_INVOKABLE void respond(const QString &reply, const QString &accountId = QString::null);45 Q_INVOKABLE void respond(const QString &reply);
48 Q_INVOKABLE void cancel(const QString &accountId = QString::null);46 Q_INVOKABLE void cancel();
4947
50 bool active() const;48 bool active() const;
51 QString activeAccountId() const;
52 QString state() const;49 QString state() const;
5350
54public Q_SLOTS:51public Q_SLOTS:
55 void onAccountsChanged();
56 void onStateChanged(const QString &state);52 void onStateChanged(const QString &state);
57 void accountConnectedChanged();
5853
59Q_SIGNALS:54Q_SIGNALS:
60 void activeChanged();55 void activeChanged();
61 void activeAccountIdChanged();
62 void stateChanged(const QString &state);56 void stateChanged(const QString &state);
6357
64 void notificationReceived(const QString &message);58 void notificationReceived(const QString &message);
@@ -75,15 +69,17 @@
75 void connectedLineRestrictionComplete(const QString &ssOp, const QString &status);69 void connectedLineRestrictionComplete(const QString &ssOp, const QString &status);
76 void initiateFailed();70 void initiateFailed();
7771
72private Q_SLOTS:
73 void onConnectionChanged();
74
78private:75private:
79 explicit USSDManager(QObject *parent = 0);76 void connectAllSignals();
8077 void disconnectAllSignals();
81 Tp::ConnectionPtr connectionForAccountId(const QString &accountId = QString::null);78
8279 QString mState;
83 void disconnectAllSignals(const Tp::ConnectionPtr& conn);80 QString mBusName;
84 void connectAllSignals(const Tp::ConnectionPtr& conn);81 QString mObjectPath;
8582 AccountEntry *mAccount;
86 QMap<QString, QString> mStates;
87};83};
8884
89#endif // USSDMANAGER_H85#endif // USSDMANAGER_H
9086
=== modified file 'tests/libtelephonyservice/TelepathyHelperTest.cpp'
--- tests/libtelephonyservice/TelepathyHelperTest.cpp 2015-04-16 02:51:08 +0000
+++ tests/libtelephonyservice/TelepathyHelperTest.cpp 2015-04-22 13:43:13 +0000
@@ -37,6 +37,7 @@
37 void cleanup();37 void cleanup();
38 void testConnected();38 void testConnected();
39 void testAccounts();39 void testAccounts();
40 void testPhoneAccounts();
40 void testAccountSorting();41 void testAccountSorting();
41 void testAccountIds();42 void testAccountIds();
42 void testActiveAccounts();43 void testActiveAccounts();
@@ -147,6 +148,37 @@
147 QCOMPARE(TelepathyHelper::instance()->accounts()[1]->accountId(), second->accountId());148 QCOMPARE(TelepathyHelper::instance()->accounts()[1]->accountId(), second->accountId());
148}149}
149150
151void TelepathyHelperTest::testPhoneAccounts()
152{
153 QCOMPARE(TelepathyHelper::instance()->phoneAccounts().count(), 1);
154 AccountEntry *phoneAccount = TelepathyHelper::instance()->phoneAccounts()[0];
155 QVERIFY(phoneAccount->accountId() == mPhoneTpAccount->uniqueIdentifier());
156
157 // now check that new phone accounts are captured
158 QSignalSpy phoneAccountsChangedSpy(TelepathyHelper::instance(), SIGNAL(phoneAccountsChanged()));
159 Tp::AccountPtr newAccount = addAccount("mock", "ofono", "extra");
160 QVERIFY(!newAccount.isNull());
161
162 QTRY_COMPARE(phoneAccountsChangedSpy.count(), 1);
163 QCOMPARE(TelepathyHelper::instance()->phoneAccounts().count(), 2);
164
165 bool accountFound = false;
166 Q_FOREACH(AccountEntry *entry, TelepathyHelper::instance()->phoneAccounts()) {
167 if (entry->accountId() == newAccount->uniqueIdentifier()) {
168 accountFound = true;
169 break;
170 }
171 }
172 QVERIFY(accountFound);
173
174 // now remove the extra phone account and make sure it is properly removed
175 phoneAccountsChangedSpy.clear();
176 QVERIFY(removeAccount(newAccount));
177 QTRY_COMPARE(phoneAccountsChangedSpy.count(), 1);
178 QCOMPARE(TelepathyHelper::instance()->phoneAccounts().count(), 1);
179 QCOMPARE(TelepathyHelper::instance()->phoneAccounts()[0]->accountId(), phoneAccount->accountId());
180}
181
150void TelepathyHelperTest::testAccountSorting()182void TelepathyHelperTest::testAccountSorting()
151{183{
152 // create two accounts with modem-objpath parameters and make sure they are listed first184 // create two accounts with modem-objpath parameters and make sure they are listed first

Subscribers

People subscribed via source and target branches