Merge lp:~mardy/online-accounts-api/providers-1627001 into lp:online-accounts-api
- providers-1627001
- Merge into trunk
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Approved by: | Alberto Mardegan | ||||||||
Approved revision: | 52 | ||||||||
Merged at revision: | 38 | ||||||||
Proposed branch: | lp:~mardy/online-accounts-api/providers-1627001 | ||||||||
Merge into: | lp:online-accounts-api | ||||||||
Diff against target: |
1839 lines (+826/-80) 34 files modified
debian/control (+1/-1) src/lib/OnlineAccounts/CMakeLists.txt (+2/-0) src/lib/OnlineAccounts/Service (+1/-0) src/lib/OnlineAccounts/account.cpp (+11/-0) src/lib/OnlineAccounts/account.h (+3/-0) src/lib/OnlineAccounts/account_p.h (+2/-0) src/lib/OnlineAccounts/dbus_interface.cpp (+2/-0) src/lib/OnlineAccounts/manager.cpp (+14/-1) src/lib/OnlineAccounts/manager.h (+6/-1) src/lib/OnlineAccounts/manager_p.h (+6/-0) src/lib/OnlineAccounts/service.cpp (+54/-0) src/lib/OnlineAccounts/service.h (+83/-0) src/lib/OnlineAccountsDaemon/CMakeLists.txt (+1/-0) src/lib/OnlineAccountsDaemon/com.ubuntu.OnlineAccounts.Manager.xml (+14/-0) src/lib/OnlineAccountsDaemon/dbus_constants.h (+3/-0) src/lib/OnlineAccountsDaemon/i18n.cpp (+34/-0) src/lib/OnlineAccountsDaemon/i18n.h (+32/-0) src/lib/OnlineAccountsDaemon/manager.cpp (+86/-10) src/lib/OnlineAccountsDaemon/manager.h (+2/-1) src/lib/OnlineAccountsDaemon/manager_adaptor.cpp (+7/-3) src/lib/OnlineAccountsDaemon/manager_adaptor.h (+4/-1) src/lib/Ubuntu/OnlineAccounts.2/account.cpp (+34/-4) src/lib/Ubuntu/OnlineAccounts.2/account.h (+10/-1) src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp (+28/-1) src/lib/Ubuntu/OnlineAccounts.2/account_model.h (+9/-0) src/lib/Ubuntu/OnlineAccounts.2/plugin.cpp (+5/-0) tests/daemon/functional_tests/data/com.ubuntu.tests_application.application (+4/-1) tests/daemon/functional_tests/data/com.ubuntu.tests_coolshare.service (+1/-1) tests/daemon/functional_tests/data/coolmail.service (+0/-1) tests/daemon/functional_tests/data/missing-provider.service (+14/-0) tests/daemon/functional_tests/functional_tests.cpp (+133/-10) tests/daemon/functional_tests/test_process.py (+5/-2) tests/lib/OnlineAccounts/functional_tests/functional_tests.cpp (+108/-22) tests/lib/qml_module/tst_qml_module.cpp (+107/-19) |
||||||||
To merge this branch: | bzr merge lp:~mardy/online-accounts-api/providers-1627001 | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexandre Abreu (community) | Approve | ||
Review via email: mp+310060@code.launchpad.net |
Commit message
Add provider information to public API
Allow clients to retrieve the list of available service providers, consisting of translated display name and icon URL.
Also, add a service() method to the Account class, to get the data associated with each account.
Description of the change
Add provider information to public API
Allow clients to retrieve the list of available service providers, consisting of translated display name and icon URL.
Also, add a service() method to the Account class, to get the data associated with each account.
Michi Henning (michihenning) wrote : | # |
- 35. By Alberto Mardegan
-
Bump dependency on libaccounts-qt
- 36. By Alberto Mardegan
-
Add missing files
- 37. By Alberto Mardegan
-
DOn't use qjsEngine() it doesn't exist in QT 5.4
Alberto Mardegan (mardy) wrote : | # |
> I may be missing something here, but (not being familiar with the code), it
> looks like the translated service name is not present? We need the translated
> name of the service too (such as "Google" or "Dropbox", or their equivalents
> in Arabic script, or whatever).
It's there, line 549 of the diff. I'll soon prepare a test app to verify that everything is place, in case unit tests are not catching everything.
- 38. By Alberto Mardegan
-
more of the same
- 39. By Alberto Mardegan
-
Cast QList<QString> to QStringList
- 40. By Alberto Mardegan
-
Don't use Q_GADGET functionality in Qt < 5.5
- 41. By Alberto Mardegan
-
Fix typo
- 42. By Alberto Mardegan
-
type conv for qt 5.4
- 43. By Alberto Mardegan
-
fix
- 44. By Alberto Mardegan
-
skip test
- 45. By Alberto Mardegan
-
fix
- 46. By Alberto Mardegan
-
Fallback to provider's icon and display name
- 47. By Alberto Mardegan
-
test debugging
- 48. By Alberto Mardegan
-
fix test
- 49. By Alberto Mardegan
-
remove debugging
- 50. By Alberto Mardegan
-
Don't crash if serviceList property is retrieved when the model is not ready
With this fix, we also need a signal to inform the QML engine of when the
property becomes available - 51. By Alberto Mardegan
-
Skip missing providers
- 52. By Alberto Mardegan
-
Expose enums to QML
Alberto Mardegan (mardy) wrote : | # |
This is implemented and available for testing here: https:/
See the "Test plan" in that silo for a quick way to test it.
Alexandre Abreu (abreu-alexandre) wrote : | # |
LGTM
one inlined question
- 53. By Alberto Mardegan
-
Remove commented line
Preview Diff
1 | === modified file 'debian/control' | |||
2 | --- debian/control 2016-10-03 07:46:50 +0000 | |||
3 | +++ debian/control 2016-11-10 09:12:06 +0000 | |||
4 | @@ -6,7 +6,7 @@ | |||
5 | 6 | debhelper (>= 9), | 6 | debhelper (>= 9), |
6 | 7 | pkg-config, | 7 | pkg-config, |
7 | 8 | python3:any, | 8 | python3:any, |
9 | 9 | libaccounts-qt5-dev, | 9 | libaccounts-qt5-dev (>= 1.15), |
10 | 10 | libapparmor-dev, | 10 | libapparmor-dev, |
11 | 11 | libonline-accounts-client-dev (>= 0.7), | 11 | libonline-accounts-client-dev (>= 0.7), |
12 | 12 | libqtdbusmock1-dev, | 12 | libqtdbusmock1-dev, |
13 | 13 | 13 | ||
14 | === modified file 'src/lib/OnlineAccounts/CMakeLists.txt' | |||
15 | --- src/lib/OnlineAccounts/CMakeLists.txt 2016-11-01 09:48:22 +0000 | |||
16 | +++ src/lib/OnlineAccounts/CMakeLists.txt 2016-11-10 09:12:06 +0000 | |||
17 | @@ -22,6 +22,7 @@ | |||
18 | 22 | manager.cpp | 22 | manager.cpp |
19 | 23 | pending_call.cpp | 23 | pending_call.cpp |
20 | 24 | request_access_reply.cpp | 24 | request_access_reply.cpp |
21 | 25 | service.cpp | ||
22 | 25 | ) | 26 | ) |
23 | 26 | set_target_properties(${CLIENT_LIB} PROPERTIES | 27 | set_target_properties(${CLIENT_LIB} PROPERTIES |
24 | 27 | VERSION 1.0.0 | 28 | VERSION 1.0.0 |
25 | @@ -52,5 +53,6 @@ | |||
26 | 52 | PasswordData | 53 | PasswordData |
27 | 53 | PendingCall pending_call.h | 54 | PendingCall pending_call.h |
28 | 54 | PendingCallWatcher | 55 | PendingCallWatcher |
29 | 56 | Service service.h | ||
30 | 55 | DESTINATION include/${CLIENT_LIB}/OnlineAccounts | 57 | DESTINATION include/${CLIENT_LIB}/OnlineAccounts |
31 | 56 | ) | 58 | ) |
32 | 57 | 59 | ||
33 | === added file 'src/lib/OnlineAccounts/Service' | |||
34 | --- src/lib/OnlineAccounts/Service 1970-01-01 00:00:00 +0000 | |||
35 | +++ src/lib/OnlineAccounts/Service 2016-11-10 09:12:06 +0000 | |||
36 | @@ -0,0 +1,1 @@ | |||
37 | 1 | #include "service.h" | ||
38 | 0 | 2 | ||
39 | === modified file 'src/lib/OnlineAccounts/account.cpp' | |||
40 | --- src/lib/OnlineAccounts/account.cpp 2015-08-26 13:32:38 +0000 | |||
41 | +++ src/lib/OnlineAccounts/account.cpp 2016-11-10 09:12:06 +0000 | |||
42 | @@ -53,6 +53,11 @@ | |||
43 | 53 | } | 53 | } |
44 | 54 | } | 54 | } |
45 | 55 | 55 | ||
46 | 56 | Service AccountPrivate::service() const | ||
47 | 57 | { | ||
48 | 58 | return m_manager->d_ptr->service(m_info.service()); | ||
49 | 59 | } | ||
50 | 60 | |||
51 | 56 | Account::Account(AccountPrivate *priv, QObject *parent): | 61 | Account::Account(AccountPrivate *priv, QObject *parent): |
52 | 57 | QObject(parent), | 62 | QObject(parent), |
53 | 58 | d_ptr(priv) | 63 | d_ptr(priv) |
54 | @@ -72,6 +77,12 @@ | |||
55 | 72 | return d->m_isValid; | 77 | return d->m_isValid; |
56 | 73 | } | 78 | } |
57 | 74 | 79 | ||
58 | 80 | Service Account::service() const | ||
59 | 81 | { | ||
60 | 82 | Q_D(const Account); | ||
61 | 83 | return d->service(); | ||
62 | 84 | } | ||
63 | 85 | |||
64 | 75 | AccountId Account::id() const | 86 | AccountId Account::id() const |
65 | 76 | { | 87 | { |
66 | 77 | Q_D(const Account); | 88 | Q_D(const Account); |
67 | 78 | 89 | ||
68 | === modified file 'src/lib/OnlineAccounts/account.h' | |||
69 | --- src/lib/OnlineAccounts/account.h 2015-08-26 13:32:38 +0000 | |||
70 | +++ src/lib/OnlineAccounts/account.h 2016-11-10 09:12:06 +0000 | |||
71 | @@ -26,6 +26,7 @@ | |||
72 | 26 | 26 | ||
73 | 27 | #include "global.h" | 27 | #include "global.h" |
74 | 28 | #include "pending_call.h" | 28 | #include "pending_call.h" |
75 | 29 | #include "service.h" | ||
76 | 29 | 30 | ||
77 | 30 | namespace OnlineAccounts { | 31 | namespace OnlineAccounts { |
78 | 31 | 32 | ||
79 | @@ -43,6 +44,8 @@ | |||
80 | 43 | /* Returns false if account deleted or disabled */ | 44 | /* Returns false if account deleted or disabled */ |
81 | 44 | bool isValid() const; | 45 | bool isValid() const; |
82 | 45 | 46 | ||
83 | 47 | Service service() const; | ||
84 | 48 | |||
85 | 46 | AccountId id() const; | 49 | AccountId id() const; |
86 | 47 | QString displayName() const; | 50 | QString displayName() const; |
87 | 48 | QString serviceId() const; | 51 | QString serviceId() const; |
88 | 49 | 52 | ||
89 | === modified file 'src/lib/OnlineAccounts/account_p.h' | |||
90 | --- src/lib/OnlineAccounts/account_p.h 2015-03-04 10:01:32 +0000 | |||
91 | +++ src/lib/OnlineAccounts/account_p.h 2016-11-10 09:12:06 +0000 | |||
92 | @@ -37,6 +37,8 @@ | |||
93 | 37 | void setInvalid(); | 37 | void setInvalid(); |
94 | 38 | void update(const AccountInfo &info); | 38 | void update(const AccountInfo &info); |
95 | 39 | 39 | ||
96 | 40 | Service service() const; | ||
97 | 41 | |||
98 | 40 | private: | 42 | private: |
99 | 41 | Manager *m_manager; | 43 | Manager *m_manager; |
100 | 42 | AccountInfo m_info; | 44 | AccountInfo m_info; |
101 | 43 | 45 | ||
102 | === modified file 'src/lib/OnlineAccounts/dbus_interface.cpp' | |||
103 | --- src/lib/OnlineAccounts/dbus_interface.cpp 2015-03-03 07:09:50 +0000 | |||
104 | +++ src/lib/OnlineAccounts/dbus_interface.cpp 2016-11-10 09:12:06 +0000 | |||
105 | @@ -22,6 +22,7 @@ | |||
106 | 22 | 22 | ||
107 | 23 | #include <QDBusMetaType> | 23 | #include <QDBusMetaType> |
108 | 24 | #include <QDebug> | 24 | #include <QDebug> |
109 | 25 | #include <QVariantMap> | ||
110 | 25 | #include <climits> | 26 | #include <climits> |
111 | 26 | 27 | ||
112 | 27 | using namespace OnlineAccounts; | 28 | using namespace OnlineAccounts; |
113 | @@ -37,6 +38,7 @@ | |||
114 | 37 | 38 | ||
115 | 38 | qDBusRegisterMetaType<AccountInfo>(); | 39 | qDBusRegisterMetaType<AccountInfo>(); |
116 | 39 | qDBusRegisterMetaType<QList<AccountInfo>>(); | 40 | qDBusRegisterMetaType<QList<AccountInfo>>(); |
117 | 41 | qDBusRegisterMetaType<QList<QVariantMap>>(); | ||
118 | 40 | 42 | ||
119 | 41 | bool ok = connect("AccountChanged", "s(ua{sv})", | 43 | bool ok = connect("AccountChanged", "s(ua{sv})", |
120 | 42 | this, SLOT(onAccountChanged(const QString&,const OnlineAccounts::AccountInfo&))); | 44 | this, SLOT(onAccountChanged(const QString&,const OnlineAccounts::AccountInfo&))); |
121 | 43 | 45 | ||
122 | === modified file 'src/lib/OnlineAccounts/manager.cpp' | |||
123 | --- src/lib/OnlineAccounts/manager.cpp 2016-11-01 09:48:22 +0000 | |||
124 | +++ src/lib/OnlineAccounts/manager.cpp 2016-11-10 09:12:06 +0000 | |||
125 | @@ -45,6 +45,7 @@ | |||
126 | 45 | q_ptr(q) | 45 | q_ptr(q) |
127 | 46 | { | 46 | { |
128 | 47 | qRegisterMetaType<Account*>(); | 47 | qRegisterMetaType<Account*>(); |
129 | 48 | qRegisterMetaType<Service>("OnlineAccounts::Service"); | ||
130 | 48 | 49 | ||
131 | 49 | QObject::connect(&m_daemon, | 50 | QObject::connect(&m_daemon, |
132 | 50 | SIGNAL(accountChanged(const QString&, const OnlineAccounts::AccountInfo&)), | 51 | SIGNAL(accountChanged(const QString&, const OnlineAccounts::AccountInfo&)), |
133 | @@ -125,7 +126,7 @@ | |||
134 | 125 | 126 | ||
135 | 126 | Q_ASSERT(m_getAccountsCall); | 127 | Q_ASSERT(m_getAccountsCall); |
136 | 127 | 128 | ||
138 | 128 | QDBusPendingReply<QList<AccountInfo> > reply = *m_getAccountsCall; | 129 | QDBusPendingReply<QList<AccountInfo>,QList<QVariantMap>> reply = *m_getAccountsCall; |
139 | 129 | if (Q_UNLIKELY(reply.isError())) { | 130 | if (Q_UNLIKELY(reply.isError())) { |
140 | 130 | qCWarning(DBG_ONLINE_ACCOUNTS) << "GetAccounts call failed:" << | 131 | qCWarning(DBG_ONLINE_ACCOUNTS) << "GetAccounts call failed:" << |
141 | 131 | reply.error(); | 132 | reply.error(); |
142 | @@ -136,6 +137,12 @@ | |||
143 | 136 | Q_FOREACH(const AccountInfo &info, accountInfos) { | 137 | Q_FOREACH(const AccountInfo &info, accountInfos) { |
144 | 137 | m_accounts.insert({info.id(), info.service()}, AccountData(info)); | 138 | m_accounts.insert({info.id(), info.service()}, AccountData(info)); |
145 | 138 | } | 139 | } |
146 | 140 | |||
147 | 141 | QList<QVariantMap> services = reply.argumentAt<1>(); | ||
148 | 142 | for (const QVariantMap &data: services) { | ||
149 | 143 | Service service(new Service::ServiceData(data)); | ||
150 | 144 | m_services.insert(service.id(), service); | ||
151 | 145 | } | ||
152 | 139 | } | 146 | } |
153 | 140 | m_getAccountsCall->deleteLater(); | 147 | m_getAccountsCall->deleteLater(); |
154 | 141 | m_getAccountsCall = 0; | 148 | m_getAccountsCall = 0; |
155 | @@ -197,6 +204,12 @@ | |||
156 | 197 | } | 204 | } |
157 | 198 | } | 205 | } |
158 | 199 | 206 | ||
159 | 207 | QList<Service> Manager::availableServices() const | ||
160 | 208 | { | ||
161 | 209 | Q_D(const Manager); | ||
162 | 210 | return d->m_services.values(); | ||
163 | 211 | } | ||
164 | 212 | |||
165 | 200 | QList<Account*> Manager::availableAccounts(const QString &service) | 213 | QList<Account*> Manager::availableAccounts(const QString &service) |
166 | 201 | { | 214 | { |
167 | 202 | Q_D(Manager); | 215 | Q_D(Manager); |
168 | 203 | 216 | ||
169 | === modified file 'src/lib/OnlineAccounts/manager.h' | |||
170 | --- src/lib/OnlineAccounts/manager.h 2016-07-22 05:08:06 +0000 | |||
171 | +++ src/lib/OnlineAccounts/manager.h 2016-11-10 09:12:06 +0000 | |||
172 | @@ -27,12 +27,14 @@ | |||
173 | 27 | #include "error.h" | 27 | #include "error.h" |
174 | 28 | #include "global.h" | 28 | #include "global.h" |
175 | 29 | #include "pending_call.h" | 29 | #include "pending_call.h" |
176 | 30 | #include "service.h" | ||
177 | 30 | 31 | ||
178 | 31 | class QDBusConnection; | 32 | class QDBusConnection; |
179 | 32 | 33 | ||
180 | 33 | namespace OnlineAccounts { | 34 | namespace OnlineAccounts { |
181 | 34 | 35 | ||
182 | 35 | class Account; | 36 | class Account; |
183 | 37 | class AccountPrivate; | ||
184 | 36 | class AuthenticationData; | 38 | class AuthenticationData; |
185 | 37 | class RequestAccessReplyPrivate; | 39 | class RequestAccessReplyPrivate; |
186 | 38 | 40 | ||
187 | @@ -44,12 +46,14 @@ | |||
188 | 44 | public: | 46 | public: |
189 | 45 | explicit Manager(const QString &applicationId, QObject *parent = 0); | 47 | explicit Manager(const QString &applicationId, QObject *parent = 0); |
190 | 46 | Manager(const QString &applicationId, const QDBusConnection &bus, | 48 | Manager(const QString &applicationId, const QDBusConnection &bus, |
192 | 47 | QObject *parent = 0); | 49 | QObject *parent = 0); |
193 | 48 | ~Manager(); | 50 | ~Manager(); |
194 | 49 | 51 | ||
195 | 50 | bool isReady() const; | 52 | bool isReady() const; |
196 | 51 | void waitForReady(); | 53 | void waitForReady(); |
197 | 52 | 54 | ||
198 | 55 | QList<Service> availableServices() const; | ||
199 | 56 | |||
200 | 53 | QList<Account*> availableAccounts(const QString &service = QString()); | 57 | QList<Account*> availableAccounts(const QString &service = QString()); |
201 | 54 | Account *account(AccountId accountId); | 58 | Account *account(AccountId accountId); |
202 | 55 | Account *account(AccountId accountId, const QString &service); | 59 | Account *account(AccountId accountId, const QString &service); |
203 | @@ -63,6 +67,7 @@ | |||
204 | 63 | 67 | ||
205 | 64 | private: | 68 | private: |
206 | 65 | friend class Account; | 69 | friend class Account; |
207 | 70 | friend class AccountPrivate; | ||
208 | 66 | friend class RequestAccessReplyPrivate; | 71 | friend class RequestAccessReplyPrivate; |
209 | 67 | Q_DECLARE_PRIVATE(Manager) | 72 | Q_DECLARE_PRIVATE(Manager) |
210 | 68 | Q_DISABLE_COPY(Manager) | 73 | Q_DISABLE_COPY(Manager) |
211 | 69 | 74 | ||
212 | === modified file 'src/lib/OnlineAccounts/manager_p.h' | |||
213 | --- src/lib/OnlineAccounts/manager_p.h 2016-07-22 05:08:06 +0000 | |||
214 | +++ src/lib/OnlineAccounts/manager_p.h 2016-11-10 09:12:06 +0000 | |||
215 | @@ -58,6 +58,11 @@ | |||
216 | 58 | 58 | ||
217 | 59 | Account *ensureAccount(const AccountInfo &info); | 59 | Account *ensureAccount(const AccountInfo &info); |
218 | 60 | 60 | ||
219 | 61 | static Service serviceFromMap(const QVariantMap &map); | ||
220 | 62 | Service service(const QString &serviceId) { | ||
221 | 63 | return m_services.value(serviceId); | ||
222 | 64 | } | ||
223 | 65 | |||
224 | 61 | private: | 66 | private: |
225 | 62 | void retrieveAccounts(); | 67 | void retrieveAccounts(); |
226 | 63 | 68 | ||
227 | @@ -71,6 +76,7 @@ | |||
228 | 71 | DBusInterface m_daemon; | 76 | DBusInterface m_daemon; |
229 | 72 | QDBusPendingCallWatcher *m_getAccountsCall; | 77 | QDBusPendingCallWatcher *m_getAccountsCall; |
230 | 73 | QMap<QPair<AccountId,QString>,AccountData> m_accounts; | 78 | QMap<QPair<AccountId,QString>,AccountData> m_accounts; |
231 | 79 | QMap<QString,Service> m_services; | ||
232 | 74 | mutable Manager *q_ptr; | 80 | mutable Manager *q_ptr; |
233 | 75 | }; | 81 | }; |
234 | 76 | 82 | ||
235 | 77 | 83 | ||
236 | === added file 'src/lib/OnlineAccounts/service.cpp' | |||
237 | --- src/lib/OnlineAccounts/service.cpp 1970-01-01 00:00:00 +0000 | |||
238 | +++ src/lib/OnlineAccounts/service.cpp 2016-11-10 09:12:06 +0000 | |||
239 | @@ -0,0 +1,54 @@ | |||
240 | 1 | /* | ||
241 | 2 | * This file is part of libOnlineAccounts | ||
242 | 3 | * | ||
243 | 4 | * Copyright (C) 2016 Canonical Ltd. | ||
244 | 5 | * | ||
245 | 6 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
246 | 7 | * | ||
247 | 8 | * This program is free software: you can redistribute it and/or modify it | ||
248 | 9 | * under the terms of the GNU Lesser General Public License version 3, as | ||
249 | 10 | * published by the Free Software Foundation. | ||
250 | 11 | * | ||
251 | 12 | * This program is distributed in the hope that it will be useful, but | ||
252 | 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
253 | 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
254 | 15 | * PURPOSE. See the GNU Lesser General Public License for more details. | ||
255 | 16 | * | ||
256 | 17 | * You should have received a copy of the GNU Lesser General Public License | ||
257 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
258 | 19 | */ | ||
259 | 20 | |||
260 | 21 | #include "service.h" | ||
261 | 22 | |||
262 | 23 | #include <QVariantMap> | ||
263 | 24 | #include "OnlineAccountsDaemon/dbus_constants.h" | ||
264 | 25 | |||
265 | 26 | using namespace OnlineAccounts; | ||
266 | 27 | |||
267 | 28 | Service::ServiceData::ServiceData(const QVariantMap &map): | ||
268 | 29 | m_id(map.value(ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID).toString()), | ||
269 | 30 | m_displayName(map.value(ONLINE_ACCOUNTS_INFO_KEY_DISPLAY_NAME).toString()), | ||
270 | 31 | m_iconSource(map.value(ONLINE_ACCOUNTS_INFO_KEY_ICON_SOURCE).toString()) | ||
271 | 32 | { | ||
272 | 33 | } | ||
273 | 34 | |||
274 | 35 | Service::Service(): | ||
275 | 36 | d(new ServiceData(QVariantMap())) | ||
276 | 37 | { | ||
277 | 38 | } | ||
278 | 39 | |||
279 | 40 | Service::Service(const QVariantMap &map): | ||
280 | 41 | d(new ServiceData(map)) | ||
281 | 42 | { | ||
282 | 43 | } | ||
283 | 44 | |||
284 | 45 | #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) | ||
285 | 46 | QVariantMap Service::toMap() const | ||
286 | 47 | { | ||
287 | 48 | return QVariantMap { | ||
288 | 49 | { "serviceId", id() }, | ||
289 | 50 | { "displayName", displayName() }, | ||
290 | 51 | { "iconSource", iconSource() }, | ||
291 | 52 | }; | ||
292 | 53 | } | ||
293 | 54 | #endif | ||
294 | 0 | 55 | ||
295 | === added file 'src/lib/OnlineAccounts/service.h' | |||
296 | --- src/lib/OnlineAccounts/service.h 1970-01-01 00:00:00 +0000 | |||
297 | +++ src/lib/OnlineAccounts/service.h 2016-11-10 09:12:06 +0000 | |||
298 | @@ -0,0 +1,83 @@ | |||
299 | 1 | /* | ||
300 | 2 | * This file is part of libOnlineAccounts | ||
301 | 3 | * | ||
302 | 4 | * Copyright (C) 2016 Canonical Ltd. | ||
303 | 5 | * | ||
304 | 6 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
305 | 7 | * | ||
306 | 8 | * This program is free software: you can redistribute it and/or modify it | ||
307 | 9 | * under the terms of the GNU Lesser General Public License version 3, as | ||
308 | 10 | * published by the Free Software Foundation. | ||
309 | 11 | * | ||
310 | 12 | * This program is distributed in the hope that it will be useful, but | ||
311 | 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
312 | 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
313 | 15 | * PURPOSE. See the GNU Lesser General Public License for more details. | ||
314 | 16 | * | ||
315 | 17 | * You should have received a copy of the GNU Lesser General Public License | ||
316 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
317 | 19 | */ | ||
318 | 20 | |||
319 | 21 | #ifndef ONLINE_ACCOUNTS_SERVICE_H | ||
320 | 22 | #define ONLINE_ACCOUNTS_SERVICE_H | ||
321 | 23 | |||
322 | 24 | #include <QObject> | ||
323 | 25 | #include <QSharedData> | ||
324 | 26 | #include <QSharedDataPointer> | ||
325 | 27 | #include <QUrl> | ||
326 | 28 | #include <QVariantMap> | ||
327 | 29 | |||
328 | 30 | #include "global.h" | ||
329 | 31 | |||
330 | 32 | namespace OnlineAccounts { | ||
331 | 33 | |||
332 | 34 | class Manager; | ||
333 | 35 | class ManagerPrivate; | ||
334 | 36 | |||
335 | 37 | class ONLINE_ACCOUNTS_EXPORT Service | ||
336 | 38 | { | ||
337 | 39 | Q_GADGET | ||
338 | 40 | Q_PROPERTY(QString serviceId READ id CONSTANT) | ||
339 | 41 | Q_PROPERTY(QString displayName READ displayName CONSTANT) | ||
340 | 42 | Q_PROPERTY(QUrl iconSource READ iconSource CONSTANT) | ||
341 | 43 | |||
342 | 44 | private: | ||
343 | 45 | class ServiceData: public QSharedData { | ||
344 | 46 | ServiceData(const QVariantMap &map); | ||
345 | 47 | friend class ManagerPrivate; | ||
346 | 48 | friend class Service; | ||
347 | 49 | QString m_id; | ||
348 | 50 | QString m_displayName; | ||
349 | 51 | QUrl m_iconSource; | ||
350 | 52 | }; | ||
351 | 53 | |||
352 | 54 | public: | ||
353 | 55 | Service(); | ||
354 | 56 | ~Service() {} | ||
355 | 57 | |||
356 | 58 | Service(const Service &other): d(other.d) {} | ||
357 | 59 | |||
358 | 60 | bool isValid() const { return !d->m_id.isEmpty(); } | ||
359 | 61 | QString id() const { return d->m_id; } | ||
360 | 62 | QString displayName() const { return d->m_displayName; } | ||
361 | 63 | QUrl iconSource() const { return d->m_iconSource; } | ||
362 | 64 | |||
363 | 65 | #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) | ||
364 | 66 | QVariantMap toMap() const; | ||
365 | 67 | #endif | ||
366 | 68 | |||
367 | 69 | protected: | ||
368 | 70 | Service(const QVariantMap &map); | ||
369 | 71 | |||
370 | 72 | private: | ||
371 | 73 | friend class Manager; | ||
372 | 74 | friend class ManagerPrivate; | ||
373 | 75 | Service(ServiceData *d): d(d) {}; | ||
374 | 76 | QSharedDataPointer<ServiceData> d; | ||
375 | 77 | }; | ||
376 | 78 | |||
377 | 79 | } // namespace | ||
378 | 80 | |||
379 | 81 | Q_DECLARE_METATYPE(OnlineAccounts::Service) | ||
380 | 82 | |||
381 | 83 | #endif // ONLINE_ACCOUNTS_SERVICE_H | ||
382 | 0 | 84 | ||
383 | === modified file 'src/lib/OnlineAccountsDaemon/CMakeLists.txt' | |||
384 | --- src/lib/OnlineAccountsDaemon/CMakeLists.txt 2015-09-04 08:32:00 +0000 | |||
385 | +++ src/lib/OnlineAccountsDaemon/CMakeLists.txt 2016-11-10 09:12:06 +0000 | |||
386 | @@ -23,6 +23,7 @@ | |||
387 | 23 | authentication_request.cpp | 23 | authentication_request.cpp |
388 | 24 | authenticator.cpp | 24 | authenticator.cpp |
389 | 25 | client_registry.cpp | 25 | client_registry.cpp |
390 | 26 | i18n.cpp | ||
391 | 26 | manager.cpp | 27 | manager.cpp |
392 | 27 | manager_adaptor.cpp | 28 | manager_adaptor.cpp |
393 | 28 | state_saver.cpp | 29 | state_saver.cpp |
394 | 29 | 30 | ||
395 | === modified file 'src/lib/OnlineAccountsDaemon/com.ubuntu.OnlineAccounts.Manager.xml' | |||
396 | --- src/lib/OnlineAccountsDaemon/com.ubuntu.OnlineAccounts.Manager.xml 2015-08-28 14:25:23 +0000 | |||
397 | +++ src/lib/OnlineAccountsDaemon/com.ubuntu.OnlineAccounts.Manager.xml 2016-11-10 09:12:06 +0000 | |||
398 | @@ -49,6 +49,7 @@ | |||
399 | 49 | --> | 49 | --> |
400 | 50 | <method name="GetAccounts"> | 50 | <method name="GetAccounts"> |
401 | 51 | <arg name="filters" type="a{sv}" direction="in" /> | 51 | <arg name="filters" type="a{sv}" direction="in" /> |
402 | 52 | |||
403 | 52 | <!-- | 53 | <!-- |
404 | 53 | The return value is a list of account IDs paired with a dictionary of account data. | 54 | The return value is a list of account IDs paired with a dictionary of account data. |
405 | 54 | This will always include: | 55 | This will always include: |
406 | @@ -61,9 +62,22 @@ | |||
407 | 61 | the framework level. | 62 | the framework level. |
408 | 62 | --> | 63 | --> |
409 | 63 | <arg name="accounts" type="a(ua{sv})" direction="out" /> | 64 | <arg name="accounts" type="a(ua{sv})" direction="out" /> |
410 | 65 | |||
411 | 66 | <!-- | ||
412 | 67 | The returned "services" is a list of dictionaries of the services' data. | ||
413 | 68 | This will always include: | ||
414 | 69 | - "serviceId" (s) | ||
415 | 70 | - "displayName" (s): the translated display name | ||
416 | 71 | - "iconSource" (s): URL to the service icon; if the URL starts with | ||
417 | 72 | "image://theme/", then what follows is the symbolic icon name | ||
418 | 73 | --> | ||
419 | 74 | <arg name="services" type="aa{sv}" direction="out" /> | ||
420 | 75 | |||
421 | 64 | <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> | 76 | <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> |
422 | 65 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" | 77 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" |
423 | 66 | value="QList<AccountInfo>"/> | 78 | value="QList<AccountInfo>"/> |
424 | 79 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" | ||
425 | 80 | value="QList<QVariantMap>"/> | ||
426 | 67 | </method> | 81 | </method> |
427 | 68 | 82 | ||
428 | 69 | <!-- | 83 | <!-- |
429 | 70 | 84 | ||
430 | === modified file 'src/lib/OnlineAccountsDaemon/dbus_constants.h' | |||
431 | --- src/lib/OnlineAccountsDaemon/dbus_constants.h 2016-02-11 09:00:13 +0000 | |||
432 | +++ src/lib/OnlineAccountsDaemon/dbus_constants.h 2016-11-10 09:12:06 +0000 | |||
433 | @@ -42,6 +42,9 @@ | |||
434 | 42 | # define ONLINE_ACCOUNTS_INFO_CHANGE_DISABLED 1 | 42 | # define ONLINE_ACCOUNTS_INFO_CHANGE_DISABLED 1 |
435 | 43 | # define ONLINE_ACCOUNTS_INFO_CHANGE_UPDATED 2 | 43 | # define ONLINE_ACCOUNTS_INFO_CHANGE_UPDATED 2 |
436 | 44 | 44 | ||
437 | 45 | /* Keys for the service info dictionary */ | ||
438 | 46 | #define ONLINE_ACCOUNTS_INFO_KEY_ICON_SOURCE "iconSource" | ||
439 | 47 | |||
440 | 45 | /* Error codes */ | 48 | /* Error codes */ |
441 | 46 | #define ONLINE_ACCOUNTS_ERROR_PREFIX "com.ubuntu.OnlineAccounts.Error." | 49 | #define ONLINE_ACCOUNTS_ERROR_PREFIX "com.ubuntu.OnlineAccounts.Error." |
442 | 47 | #define ONLINE_ACCOUNTS_ERROR_NO_ACCOUNT \ | 50 | #define ONLINE_ACCOUNTS_ERROR_NO_ACCOUNT \ |
443 | 48 | 51 | ||
444 | === added file 'src/lib/OnlineAccountsDaemon/i18n.cpp' | |||
445 | --- src/lib/OnlineAccountsDaemon/i18n.cpp 1970-01-01 00:00:00 +0000 | |||
446 | +++ src/lib/OnlineAccountsDaemon/i18n.cpp 2016-11-10 09:12:06 +0000 | |||
447 | @@ -0,0 +1,34 @@ | |||
448 | 1 | /* | ||
449 | 2 | * This file is part of OnlineAccountsDaemon | ||
450 | 3 | * | ||
451 | 4 | * Copyright (C) 2016 Canonical Ltd. | ||
452 | 5 | * | ||
453 | 6 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
454 | 7 | * | ||
455 | 8 | * This program is free software: you can redistribute it and/or modify it | ||
456 | 9 | * under the terms of the GNU Lesser General Public License version 3, as | ||
457 | 10 | * published by the Free Software Foundation. | ||
458 | 11 | * | ||
459 | 12 | * This program is distributed in the hope that it will be useful, but | ||
460 | 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
461 | 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
462 | 15 | * PURPOSE. See the GNU Lesser General Public License for more details. | ||
463 | 16 | * | ||
464 | 17 | * You should have received a copy of the GNU Lesser General Public License | ||
465 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
466 | 19 | */ | ||
467 | 20 | |||
468 | 21 | #define NO_TR_OVERRIDE | ||
469 | 22 | #include "i18n.h" | ||
470 | 23 | |||
471 | 24 | #include <libintl.h> | ||
472 | 25 | |||
473 | 26 | namespace OnlineAccountsDaemon { | ||
474 | 27 | |||
475 | 28 | QString translate(const QString &text, const QString &domain) | ||
476 | 29 | { | ||
477 | 30 | return QString::fromUtf8(dgettext(domain.toUtf8().constData(), | ||
478 | 31 | text.toUtf8().constData())); | ||
479 | 32 | } | ||
480 | 33 | |||
481 | 34 | }; // namespace | ||
482 | 0 | 35 | ||
483 | === added file 'src/lib/OnlineAccountsDaemon/i18n.h' | |||
484 | --- src/lib/OnlineAccountsDaemon/i18n.h 1970-01-01 00:00:00 +0000 | |||
485 | +++ src/lib/OnlineAccountsDaemon/i18n.h 2016-11-10 09:12:06 +0000 | |||
486 | @@ -0,0 +1,32 @@ | |||
487 | 1 | /* | ||
488 | 2 | * This file is part of OnlineAccountsDaemon | ||
489 | 3 | * | ||
490 | 4 | * Copyright (C) 2016 Canonical Ltd. | ||
491 | 5 | * | ||
492 | 6 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
493 | 7 | * | ||
494 | 8 | * This program is free software: you can redistribute it and/or modify it | ||
495 | 9 | * under the terms of the GNU Lesser General Public License version 3, as | ||
496 | 10 | * published by the Free Software Foundation. | ||
497 | 11 | * | ||
498 | 12 | * This program is distributed in the hope that it will be useful, but | ||
499 | 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
500 | 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
501 | 15 | * PURPOSE. See the GNU Lesser General Public License for more details. | ||
502 | 16 | * | ||
503 | 17 | * You should have received a copy of the GNU Lesser General Public License | ||
504 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
505 | 19 | */ | ||
506 | 20 | |||
507 | 21 | #ifndef ONLINE_ACCOUNTS_DAEMON_I18N_H | ||
508 | 22 | #define ONLINE_ACCOUNTS_DAEMON_I18N_H | ||
509 | 23 | |||
510 | 24 | #include <QString> | ||
511 | 25 | |||
512 | 26 | namespace OnlineAccountsDaemon { | ||
513 | 27 | |||
514 | 28 | QString translate(const QString &text, const QString &domain); | ||
515 | 29 | |||
516 | 30 | } // namespace | ||
517 | 31 | |||
518 | 32 | #endif // ONLINE_ACCOUNTS_DAEMON_I18N_H | ||
519 | 0 | 33 | ||
520 | === modified file 'src/lib/OnlineAccountsDaemon/manager.cpp' | |||
521 | --- src/lib/OnlineAccountsDaemon/manager.cpp 2016-09-28 13:09:06 +0000 | |||
522 | +++ src/lib/OnlineAccountsDaemon/manager.cpp 2016-11-10 09:12:06 +0000 | |||
523 | @@ -36,6 +36,7 @@ | |||
524 | 36 | #include "authenticator.h" | 36 | #include "authenticator.h" |
525 | 37 | #include "client_registry.h" | 37 | #include "client_registry.h" |
526 | 38 | #include "dbus_constants.h" | 38 | #include "dbus_constants.h" |
527 | 39 | #include "i18n.h" | ||
528 | 39 | #include "manager_adaptor.h" | 40 | #include "manager_adaptor.h" |
529 | 40 | #include "state_saver.h" | 41 | #include "state_saver.h" |
530 | 41 | 42 | ||
531 | @@ -78,8 +79,10 @@ | |||
532 | 78 | const QStringList &clients); | 79 | const QStringList &clients); |
533 | 79 | 80 | ||
534 | 80 | AccountInfo readAccountInfo(const Accounts::AccountService *as); | 81 | AccountInfo readAccountInfo(const Accounts::AccountService *as); |
535 | 82 | QList<QVariantMap> buildServiceList(const Accounts::Application &app) const; | ||
536 | 81 | QList<AccountInfo> getAccounts(const QVariantMap &filters, | 83 | QList<AccountInfo> getAccounts(const QVariantMap &filters, |
538 | 82 | const CallContext &context); | 84 | const CallContext &context, |
539 | 85 | QList<QVariantMap> &services); | ||
540 | 83 | void authenticate(uint accountId, const QString &serviceId, | 86 | void authenticate(uint accountId, const QString &serviceId, |
541 | 84 | bool interactive, bool invalidate, | 87 | bool interactive, bool invalidate, |
542 | 85 | const QVariantMap ¶meters, | 88 | const QVariantMap ¶meters, |
543 | @@ -89,6 +92,8 @@ | |||
544 | 89 | const CallContext &context); | 92 | const CallContext &context); |
545 | 90 | bool canAccess(const QString &context, const QString &serviceId); | 93 | bool canAccess(const QString &context, const QString &serviceId); |
546 | 91 | 94 | ||
547 | 95 | static QString applicationIdFromLabel(const QString &label); | ||
548 | 96 | |||
549 | 92 | void notifyAccountChange(const ActiveAccount &account, uint change); | 97 | void notifyAccountChange(const ActiveAccount &account, uint change); |
550 | 93 | 98 | ||
551 | 94 | private Q_SLOTS: | 99 | private Q_SLOTS: |
552 | @@ -344,22 +349,82 @@ | |||
553 | 344 | return AccountInfo(as->account()->id(), info); | 349 | return AccountInfo(as->account()->id(), info); |
554 | 345 | } | 350 | } |
555 | 346 | 351 | ||
556 | 352 | QList<QVariantMap> | ||
557 | 353 | ManagerPrivate::buildServiceList(const Accounts::Application &app) const | ||
558 | 354 | { | ||
559 | 355 | QList<QVariantMap> services; | ||
560 | 356 | |||
561 | 357 | const auto serviceList = m_manager.serviceList(app); | ||
562 | 358 | for (const Accounts::Service &service: serviceList) { | ||
563 | 359 | QString displayName = translate(service.displayName(), | ||
564 | 360 | service.trCatalog()); | ||
565 | 361 | QString icon = service.iconName(); | ||
566 | 362 | |||
567 | 363 | /* Applications might declare support for a service while the provider | ||
568 | 364 | * (and account plugin) for that account is not installed. We probably | ||
569 | 365 | * don't want to include these services in the list, as it would lead | ||
570 | 366 | * to empty/invalid UI elements. */ | ||
571 | 367 | Accounts::Provider provider = m_manager.provider(service.provider()); | ||
572 | 368 | if (!provider.isValid()) continue; | ||
573 | 369 | |||
574 | 370 | /* Now check the service data; if either display name or icon are | ||
575 | 371 | * empty, fetch this information from the provider file, as a fallback | ||
576 | 372 | */ | ||
577 | 373 | if (displayName.isEmpty() || | ||
578 | 374 | // sometimes we use a '.' as display name placeholder | ||
579 | 375 | displayName == ".") { | ||
580 | 376 | displayName = translate(provider.displayName(), | ||
581 | 377 | provider.trCatalog()); | ||
582 | 378 | } | ||
583 | 379 | if (icon.isEmpty()) { | ||
584 | 380 | icon = provider.iconName(); | ||
585 | 381 | } | ||
586 | 382 | |||
587 | 383 | QString iconSource; | ||
588 | 384 | if (icon.startsWith('/')) { | ||
589 | 385 | iconSource = QStringLiteral("file:/") + icon; | ||
590 | 386 | } else { | ||
591 | 387 | iconSource = QStringLiteral("image://theme/") + icon; | ||
592 | 388 | } | ||
593 | 389 | |||
594 | 390 | services.append({ | ||
595 | 391 | { ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID, service.name() }, | ||
596 | 392 | { ONLINE_ACCOUNTS_INFO_KEY_DISPLAY_NAME, displayName }, | ||
597 | 393 | { ONLINE_ACCOUNTS_INFO_KEY_ICON_SOURCE, iconSource }, | ||
598 | 394 | }); | ||
599 | 395 | } | ||
600 | 396 | |||
601 | 397 | return services; | ||
602 | 398 | } | ||
603 | 399 | |||
604 | 347 | QList<AccountInfo> ManagerPrivate::getAccounts(const QVariantMap &filters, | 400 | QList<AccountInfo> ManagerPrivate::getAccounts(const QVariantMap &filters, |
606 | 348 | const CallContext &context) | 401 | const CallContext &context, |
607 | 402 | QList<QVariantMap> &services) | ||
608 | 349 | { | 403 | { |
609 | 350 | QString desiredApplicationId = filters.value("applicationId").toString(); | 404 | QString desiredApplicationId = filters.value("applicationId").toString(); |
610 | 351 | QString desiredServiceId = filters.value("serviceId").toString(); | 405 | QString desiredServiceId = filters.value("serviceId").toString(); |
611 | 352 | Accounts::AccountId desiredAccountId = filters.value("accountId").toUInt(); | 406 | Accounts::AccountId desiredAccountId = filters.value("accountId").toUInt(); |
612 | 353 | 407 | ||
618 | 354 | Accounts::Application application = desiredApplicationId.isEmpty() ? | 408 | QString applicationId = desiredApplicationId.isEmpty() ? |
619 | 355 | Accounts::Application() : m_manager.application(desiredApplicationId); | 409 | applicationIdFromLabel(context.securityContext()) : desiredApplicationId; |
620 | 356 | 410 | ||
621 | 357 | if (application.isValid() && | 411 | Accounts::Application application = m_manager.application(applicationId); |
622 | 358 | canAccess(context.securityContext(), desiredApplicationId)) { | 412 | |
623 | 413 | QList<AccountInfo> accounts; | ||
624 | 414 | |||
625 | 415 | if (!application.isValid() || | ||
626 | 416 | !canAccess(context.securityContext(), applicationId)) { | ||
627 | 417 | if (!desiredApplicationId.isEmpty()) { | ||
628 | 418 | context.sendError(ONLINE_ACCOUNTS_ERROR_PERMISSION_DENIED, | ||
629 | 419 | QString("App '%1' cannot act as '%2'"). | ||
630 | 420 | arg(applicationId).arg(desiredApplicationId)); | ||
631 | 421 | return accounts; | ||
632 | 422 | } | ||
633 | 423 | } else { | ||
634 | 359 | m_clients.insert(context.clientName(), application); | 424 | m_clients.insert(context.clientName(), application); |
635 | 360 | } | 425 | } |
636 | 361 | 426 | ||
638 | 362 | QList<AccountInfo> accounts; | 427 | services = buildServiceList(application); |
639 | 363 | 428 | ||
640 | 364 | Q_FOREACH(Accounts::AccountId accountId, m_manager.accountListEnabled()) { | 429 | Q_FOREACH(Accounts::AccountId accountId, m_manager.accountListEnabled()) { |
641 | 365 | if (desiredAccountId != 0 && accountId != desiredAccountId) { | 430 | if (desiredAccountId != 0 && accountId != desiredAccountId) { |
642 | @@ -473,6 +538,16 @@ | |||
643 | 473 | return serviceId.left(pos) == pkgname; | 538 | return serviceId.left(pos) == pkgname; |
644 | 474 | } | 539 | } |
645 | 475 | 540 | ||
646 | 541 | QString ManagerPrivate::applicationIdFromLabel(const QString &label) | ||
647 | 542 | { | ||
648 | 543 | QStringList parts = label.split('_'); | ||
649 | 544 | if (parts.count() == 3) { | ||
650 | 545 | return QStringList(parts.mid(0, 2)).join('_'); | ||
651 | 546 | } else { | ||
652 | 547 | return QString(); | ||
653 | 548 | } | ||
654 | 549 | } | ||
655 | 550 | |||
656 | 476 | void ManagerPrivate::onAccountServiceEnabled(bool enabled) | 551 | void ManagerPrivate::onAccountServiceEnabled(bool enabled) |
657 | 477 | { | 552 | { |
658 | 478 | auto as = qobject_cast<Accounts::AccountService*>(sender()); | 553 | auto as = qobject_cast<Accounts::AccountService*>(sender()); |
659 | @@ -553,10 +628,11 @@ | |||
660 | 553 | } | 628 | } |
661 | 554 | 629 | ||
662 | 555 | QList<AccountInfo> Manager::getAccounts(const QVariantMap &filters, | 630 | QList<AccountInfo> Manager::getAccounts(const QVariantMap &filters, |
664 | 556 | const CallContext &context) | 631 | const CallContext &context, |
665 | 632 | QList<QVariantMap> &services) | ||
666 | 557 | { | 633 | { |
667 | 558 | Q_D(Manager); | 634 | Q_D(Manager); |
669 | 559 | return d->getAccounts(filters, context); | 635 | return d->getAccounts(filters, context, services); |
670 | 560 | } | 636 | } |
671 | 561 | 637 | ||
672 | 562 | void Manager::authenticate(uint accountId, const QString &serviceId, | 638 | void Manager::authenticate(uint accountId, const QString &serviceId, |
673 | 563 | 639 | ||
674 | === modified file 'src/lib/OnlineAccountsDaemon/manager.h' | |||
675 | --- src/lib/OnlineAccountsDaemon/manager.h 2015-09-03 13:28:30 +0000 | |||
676 | +++ src/lib/OnlineAccountsDaemon/manager.h 2016-11-10 09:12:06 +0000 | |||
677 | @@ -52,7 +52,8 @@ | |||
678 | 52 | bool isIdle() const; | 52 | bool isIdle() const; |
679 | 53 | 53 | ||
680 | 54 | QList<AccountInfo> getAccounts(const QVariantMap &filters, | 54 | QList<AccountInfo> getAccounts(const QVariantMap &filters, |
682 | 55 | const CallContext &context); | 55 | const CallContext &context, |
683 | 56 | QList<QVariantMap> &services); | ||
684 | 56 | void authenticate(uint accountId, const QString &serviceId, | 57 | void authenticate(uint accountId, const QString &serviceId, |
685 | 57 | bool interactive, bool invalidate, | 58 | bool interactive, bool invalidate, |
686 | 58 | const QVariantMap ¶meters, | 59 | const QVariantMap ¶meters, |
687 | 59 | 60 | ||
688 | === modified file 'src/lib/OnlineAccountsDaemon/manager_adaptor.cpp' | |||
689 | --- src/lib/OnlineAccountsDaemon/manager_adaptor.cpp 2015-08-28 14:25:23 +0000 | |||
690 | +++ src/lib/OnlineAccountsDaemon/manager_adaptor.cpp 2016-11-10 09:12:06 +0000 | |||
691 | @@ -147,6 +147,7 @@ | |||
692 | 147 | qRegisterMetaType<QList<AccountInfo> >("QList<AccountInfo>"); | 147 | qRegisterMetaType<QList<AccountInfo> >("QList<AccountInfo>"); |
693 | 148 | qDBusRegisterMetaType<AccountInfo>(); | 148 | qDBusRegisterMetaType<AccountInfo>(); |
694 | 149 | qDBusRegisterMetaType<QList<AccountInfo>>(); | 149 | qDBusRegisterMetaType<QList<AccountInfo>>(); |
695 | 150 | qDBusRegisterMetaType<QList<QVariantMap>>(); | ||
696 | 150 | 151 | ||
697 | 151 | setAutoRelaySignals(false); | 152 | setAutoRelaySignals(false); |
698 | 152 | } | 153 | } |
699 | @@ -175,10 +176,13 @@ | |||
700 | 175 | return QVariantMap(); | 176 | return QVariantMap(); |
701 | 176 | } | 177 | } |
702 | 177 | 178 | ||
704 | 178 | QList<AccountInfo> ManagerAdaptor::GetAccounts(const QVariantMap &filters) | 179 | void ManagerAdaptor::GetAccounts(const QVariantMap &filters, |
705 | 180 | QList<AccountInfo> &accounts, | ||
706 | 181 | QList<QVariantMap> &services) | ||
707 | 179 | { | 182 | { |
710 | 180 | return parent()->getAccounts(filters, | 183 | accounts = parent()->getAccounts(filters, |
711 | 181 | CallContext(dbusContext())); | 184 | CallContext(dbusContext()), |
712 | 185 | services); | ||
713 | 182 | } | 186 | } |
714 | 183 | 187 | ||
715 | 184 | AccountInfo ManagerAdaptor::RequestAccess(const QString &serviceId, | 188 | AccountInfo ManagerAdaptor::RequestAccess(const QString &serviceId, |
716 | 185 | 189 | ||
717 | === modified file 'src/lib/OnlineAccountsDaemon/manager_adaptor.h' | |||
718 | --- src/lib/OnlineAccountsDaemon/manager_adaptor.h 2015-09-02 11:42:04 +0000 | |||
719 | +++ src/lib/OnlineAccountsDaemon/manager_adaptor.h 2016-11-10 09:12:06 +0000 | |||
720 | @@ -85,6 +85,7 @@ | |||
721 | 85 | " <method name=\"GetAccounts\">\n" | 85 | " <method name=\"GetAccounts\">\n" |
722 | 86 | " <arg direction=\"in\" type=\"a{sv}\" name=\"filters\"/>\n" | 86 | " <arg direction=\"in\" type=\"a{sv}\" name=\"filters\"/>\n" |
723 | 87 | " <arg direction=\"out\" type=\"a(ua{sv})\" name=\"accounts\"/>\n" | 87 | " <arg direction=\"out\" type=\"a(ua{sv})\" name=\"accounts\"/>\n" |
724 | 88 | " <arg direction=\"out\" type=\"aa{sv}\" name=\"services\"/>\n" | ||
725 | 88 | " </method>\n" | 89 | " </method>\n" |
726 | 89 | " <method name=\"Authenticate\">\n" | 90 | " <method name=\"Authenticate\">\n" |
727 | 90 | " <arg direction=\"in\" type=\"u\" name=\"accountId\"/>\n" | 91 | " <arg direction=\"in\" type=\"u\" name=\"accountId\"/>\n" |
728 | @@ -123,7 +124,9 @@ | |||
729 | 123 | QVariantMap Authenticate(uint accountId, const QString &serviceId, | 124 | QVariantMap Authenticate(uint accountId, const QString &serviceId, |
730 | 124 | bool interactive, bool invalidate, | 125 | bool interactive, bool invalidate, |
731 | 125 | const QVariantMap ¶meters); | 126 | const QVariantMap ¶meters); |
733 | 126 | QList<AccountInfo> GetAccounts(const QVariantMap &filters); | 127 | void GetAccounts(const QVariantMap &filters, |
734 | 128 | QList<AccountInfo> &accounts, | ||
735 | 129 | QList<QVariantMap> &services); | ||
736 | 127 | AccountInfo RequestAccess(const QString &serviceId, | 130 | AccountInfo RequestAccess(const QString &serviceId, |
737 | 128 | const QVariantMap ¶meters, | 131 | const QVariantMap ¶meters, |
738 | 129 | QVariantMap &credentials); | 132 | QVariantMap &credentials); |
739 | 130 | 133 | ||
740 | === modified file 'src/lib/Ubuntu/OnlineAccounts.2/account.cpp' | |||
741 | --- src/lib/Ubuntu/OnlineAccounts.2/account.cpp 2016-01-13 14:23:12 +0000 | |||
742 | +++ src/lib/Ubuntu/OnlineAccounts.2/account.cpp 2016-11-10 09:12:06 +0000 | |||
743 | @@ -26,6 +26,9 @@ | |||
744 | 26 | #include "OnlineAccounts/AuthenticationReply" | 26 | #include "OnlineAccounts/AuthenticationReply" |
745 | 27 | #include "OnlineAccounts/PendingCall" | 27 | #include "OnlineAccounts/PendingCall" |
746 | 28 | 28 | ||
747 | 29 | #include <QDebug> | ||
748 | 30 | #include <QJSEngine> | ||
749 | 31 | |||
750 | 29 | using namespace OnlineAccountsModule; | 32 | using namespace OnlineAccountsModule; |
751 | 30 | 33 | ||
752 | 31 | namespace OnlineAccountsModule { | 34 | namespace OnlineAccountsModule { |
753 | @@ -36,20 +39,25 @@ | |||
754 | 36 | Q_DECLARE_PUBLIC(Account) | 39 | Q_DECLARE_PUBLIC(Account) |
755 | 37 | 40 | ||
756 | 38 | public: | 41 | public: |
758 | 39 | AccountPrivate(OnlineAccounts::Account *account, Account *q); | 42 | AccountPrivate(OnlineAccounts::Account *account, QJSEngine *engine, |
759 | 43 | Account *q); | ||
760 | 40 | 44 | ||
761 | 41 | private Q_SLOTS: | 45 | private Q_SLOTS: |
762 | 42 | void onAuthenticationFinished(); | 46 | void onAuthenticationFinished(); |
763 | 43 | 47 | ||
764 | 44 | private: | 48 | private: |
765 | 45 | OnlineAccounts::Account *m_account; | 49 | OnlineAccounts::Account *m_account; |
766 | 50 | QJSEngine *m_engine; | ||
767 | 46 | mutable Account *q_ptr; | 51 | mutable Account *q_ptr; |
768 | 47 | }; | 52 | }; |
769 | 48 | 53 | ||
770 | 49 | } // namespace | 54 | } // namespace |
771 | 50 | 55 | ||
773 | 51 | AccountPrivate::AccountPrivate(OnlineAccounts::Account *account, Account *q): | 56 | AccountPrivate::AccountPrivate(OnlineAccounts::Account *account, |
774 | 57 | QJSEngine *engine, | ||
775 | 58 | Account *q): | ||
776 | 52 | m_account(account), | 59 | m_account(account), |
777 | 60 | m_engine(engine), | ||
778 | 53 | q_ptr(q) | 61 | q_ptr(q) |
779 | 54 | { | 62 | { |
780 | 55 | QObject::connect(account, SIGNAL(changed()), | 63 | QObject::connect(account, SIGNAL(changed()), |
781 | @@ -122,9 +130,10 @@ | |||
782 | 122 | * \endlist | 130 | * \endlist |
783 | 123 | */ | 131 | */ |
784 | 124 | 132 | ||
786 | 125 | Account::Account(OnlineAccounts::Account *account, QObject *parent): | 133 | Account::Account(OnlineAccounts::Account *account, QJSEngine *engine, |
787 | 134 | QObject *parent): | ||
788 | 126 | QObject(parent), | 135 | QObject(parent), |
790 | 127 | d_ptr(new AccountPrivate(account, this)) | 136 | d_ptr(new AccountPrivate(account, engine, this)) |
791 | 128 | { | 137 | { |
792 | 129 | } | 138 | } |
793 | 130 | 139 | ||
794 | @@ -187,6 +196,27 @@ | |||
795 | 187 | } | 196 | } |
796 | 188 | 197 | ||
797 | 189 | /*! | 198 | /*! |
798 | 199 | * \qmlproperty int Account::service | ||
799 | 200 | * | ||
800 | 201 | * Service data associated with this account. This is an object containing the | ||
801 | 202 | * following properties: | ||
802 | 203 | * \list | ||
803 | 204 | * \li \c serviceId - same service ID returned by Account::serviceId | ||
804 | 205 | * \li \c displayName - the localized display name for the service | ||
805 | 206 | * \li \c iconSource - URL for the icon; can be a "file://" URL to a local | ||
806 | 207 | * file, or an icon from the theme if the URL starts with "image://theme/" | ||
807 | 208 | */ | ||
808 | 209 | QJSValue Account::service() const | ||
809 | 210 | { | ||
810 | 211 | Q_D(const Account); | ||
811 | 212 | #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) | ||
812 | 213 | return d->m_engine->toScriptValue(d->m_account->service()); | ||
813 | 214 | #else | ||
814 | 215 | return d->m_engine->toScriptValue(d->m_account->service().toMap()); | ||
815 | 216 | #endif | ||
816 | 217 | } | ||
817 | 218 | |||
818 | 219 | /*! | ||
819 | 190 | * \qmlproperty enumeration Account::authenticationMethod | 220 | * \qmlproperty enumeration Account::authenticationMethod |
820 | 191 | * | 221 | * |
821 | 192 | * The authentication method used when authenticating with the account. | 222 | * The authentication method used when authenticating with the account. |
822 | 193 | 223 | ||
823 | === modified file 'src/lib/Ubuntu/OnlineAccounts.2/account.h' | |||
824 | --- src/lib/Ubuntu/OnlineAccounts.2/account.h 2016-01-13 14:23:12 +0000 | |||
825 | +++ src/lib/Ubuntu/OnlineAccounts.2/account.h 2016-11-10 09:12:06 +0000 | |||
826 | @@ -21,10 +21,13 @@ | |||
827 | 21 | #ifndef ONLINE_ACCOUNTS_MODULE_ACCOUNT_H | 21 | #ifndef ONLINE_ACCOUNTS_MODULE_ACCOUNT_H |
828 | 22 | #define ONLINE_ACCOUNTS_MODULE_ACCOUNT_H | 22 | #define ONLINE_ACCOUNTS_MODULE_ACCOUNT_H |
829 | 23 | 23 | ||
830 | 24 | #include <QJSValue> | ||
831 | 24 | #include <QObject> | 25 | #include <QObject> |
832 | 25 | #include <QString> | 26 | #include <QString> |
833 | 26 | #include <QVariantMap> | 27 | #include <QVariantMap> |
834 | 27 | 28 | ||
835 | 29 | class QJSEngine; | ||
836 | 30 | |||
837 | 28 | namespace OnlineAccounts { | 31 | namespace OnlineAccounts { |
838 | 29 | class Account; | 32 | class Account; |
839 | 30 | } | 33 | } |
840 | @@ -40,6 +43,7 @@ | |||
841 | 40 | Q_PROPERTY(QString displayName READ displayName NOTIFY accountChanged) | 43 | Q_PROPERTY(QString displayName READ displayName NOTIFY accountChanged) |
842 | 41 | Q_PROPERTY(int accountId READ accountId CONSTANT) | 44 | Q_PROPERTY(int accountId READ accountId CONSTANT) |
843 | 42 | Q_PROPERTY(QString serviceId READ serviceId CONSTANT) | 45 | Q_PROPERTY(QString serviceId READ serviceId CONSTANT) |
844 | 46 | Q_PROPERTY(QJSValue service READ service CONSTANT) | ||
845 | 43 | Q_PROPERTY(AuthenticationMethod authenticationMethod \ | 47 | Q_PROPERTY(AuthenticationMethod authenticationMethod \ |
846 | 44 | READ authenticationMethod CONSTANT) | 48 | READ authenticationMethod CONSTANT) |
847 | 45 | Q_PROPERTY(QVariantMap settings READ settings NOTIFY accountChanged) | 49 | Q_PROPERTY(QVariantMap settings READ settings NOTIFY accountChanged) |
848 | @@ -64,13 +68,15 @@ | |||
849 | 64 | ErrorCodeInteractionRequired, | 68 | ErrorCodeInteractionRequired, |
850 | 65 | }; | 69 | }; |
851 | 66 | 70 | ||
853 | 67 | explicit Account(OnlineAccounts::Account *account, QObject *parent = 0); | 71 | explicit Account(OnlineAccounts::Account *account, QJSEngine *engine, |
854 | 72 | QObject *parent = 0); | ||
855 | 68 | ~Account(); | 73 | ~Account(); |
856 | 69 | 74 | ||
857 | 70 | bool isValid() const; | 75 | bool isValid() const; |
858 | 71 | QString displayName() const; | 76 | QString displayName() const; |
859 | 72 | int accountId() const; | 77 | int accountId() const; |
860 | 73 | QString serviceId() const; | 78 | QString serviceId() const; |
861 | 79 | QJSValue service() const; | ||
862 | 74 | AuthenticationMethod authenticationMethod() const; | 80 | AuthenticationMethod authenticationMethod() const; |
863 | 75 | QVariantMap settings() const; | 81 | QVariantMap settings() const; |
864 | 76 | 82 | ||
865 | @@ -90,4 +96,7 @@ | |||
866 | 90 | 96 | ||
867 | 91 | } // namespace | 97 | } // namespace |
868 | 92 | 98 | ||
869 | 99 | Q_DECLARE_METATYPE(OnlineAccountsModule::Account::AuthenticationMethod) | ||
870 | 100 | Q_DECLARE_METATYPE(OnlineAccountsModule::Account::ErrorCode) | ||
871 | 101 | |||
872 | 93 | #endif // ONLINE_ACCOUNTS_MODULE_ACCOUNT_H | 102 | #endif // ONLINE_ACCOUNTS_MODULE_ACCOUNT_H |
873 | 94 | 103 | ||
874 | === modified file 'src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp' | |||
875 | --- src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp 2016-01-18 12:23:07 +0000 | |||
876 | +++ src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp 2016-11-10 09:12:06 +0000 | |||
877 | @@ -30,6 +30,7 @@ | |||
878 | 30 | #include <QDebug> | 30 | #include <QDebug> |
879 | 31 | #include <QQmlEngine> | 31 | #include <QQmlEngine> |
880 | 32 | #include <QVariantMap> | 32 | #include <QVariantMap> |
881 | 33 | #include <QtQml> | ||
882 | 33 | 34 | ||
883 | 34 | using namespace OnlineAccountsModule; | 35 | using namespace OnlineAccountsModule; |
884 | 35 | 36 | ||
885 | @@ -85,6 +86,7 @@ | |||
886 | 85 | roleNames[AccountModel::AuthenticationMethodRole] = "authenticationMethod"; | 86 | roleNames[AccountModel::AuthenticationMethodRole] = "authenticationMethod"; |
887 | 86 | roleNames[AccountModel::SettingsRole] = "settings"; | 87 | roleNames[AccountModel::SettingsRole] = "settings"; |
888 | 87 | roleNames[AccountModel::AccountRole] = "account"; | 88 | roleNames[AccountModel::AccountRole] = "account"; |
889 | 89 | roleNames[AccountModel::ServiceRole] = "service"; | ||
890 | 88 | } | 90 | } |
891 | 89 | 91 | ||
892 | 90 | void AccountModelPrivate::queueUpdate() | 92 | void AccountModelPrivate::queueUpdate() |
893 | @@ -122,13 +124,17 @@ | |||
894 | 122 | 124 | ||
895 | 123 | Account *AccountModelPrivate::handleAccount(OnlineAccounts::Account *account) | 125 | Account *AccountModelPrivate::handleAccount(OnlineAccounts::Account *account) |
896 | 124 | { | 126 | { |
897 | 127 | Q_Q(AccountModel); | ||
898 | 128 | |||
899 | 125 | /* First, check if the account is already handled */ | 129 | /* First, check if the account is already handled */ |
900 | 126 | Q_FOREACH(Account *a, m_accounts) { | 130 | Q_FOREACH(Account *a, m_accounts) { |
901 | 127 | if (account == a->internalObject()) { | 131 | if (account == a->internalObject()) { |
902 | 128 | return a; | 132 | return a; |
903 | 129 | } | 133 | } |
904 | 130 | } | 134 | } |
906 | 131 | Account *a = new Account(account, this); | 135 | |
907 | 136 | QQmlEngine *engine = qmlEngine(q); | ||
908 | 137 | Account *a = new Account(account, engine, this); | ||
909 | 132 | QQmlEngine::setObjectOwnership(a, QQmlEngine::CppOwnership); | 138 | QQmlEngine::setObjectOwnership(a, QQmlEngine::CppOwnership); |
910 | 133 | QObject::connect(a, SIGNAL(validChanged()), | 139 | QObject::connect(a, SIGNAL(validChanged()), |
911 | 134 | this, SLOT(onAccountValidChanged())); | 140 | this, SLOT(onAccountValidChanged())); |
912 | @@ -386,6 +392,24 @@ | |||
913 | 386 | return objects; | 392 | return objects; |
914 | 387 | } | 393 | } |
915 | 388 | 394 | ||
916 | 395 | QJSValue AccountModel::serviceList() const | ||
917 | 396 | { | ||
918 | 397 | Q_D(const AccountModel); | ||
919 | 398 | QJSEngine *engine = qmlEngine(this); | ||
920 | 399 | QJSValue ret = engine->newArray(); | ||
921 | 400 | if (!d->m_manager) return ret; | ||
922 | 401 | int i = 0; | ||
923 | 402 | Q_FOREACH(const auto &service, d->m_manager->availableServices()) { | ||
924 | 403 | #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) | ||
925 | 404 | QJSValue v = engine->toScriptValue(service); | ||
926 | 405 | #else | ||
927 | 406 | QJSValue v = engine->toScriptValue(service.toMap()); | ||
928 | 407 | #endif | ||
929 | 408 | ret.setProperty(i++, v); | ||
930 | 409 | } | ||
931 | 410 | return ret; | ||
932 | 411 | } | ||
933 | 412 | |||
934 | 389 | /*! | 413 | /*! |
935 | 390 | * \qmlsignal AccountModel::accessReply(jsobject reply, jsobject authenticationData) | 414 | * \qmlsignal AccountModel::accessReply(jsobject reply, jsobject authenticationData) |
936 | 391 | * | 415 | * |
937 | @@ -495,6 +519,9 @@ | |||
938 | 495 | case AccountRole: | 519 | case AccountRole: |
939 | 496 | ret = QVariant::fromValue<QObject*>(account); | 520 | ret = QVariant::fromValue<QObject*>(account); |
940 | 497 | break; | 521 | break; |
941 | 522 | case ServiceRole: | ||
942 | 523 | ret = QVariant::fromValue(account->service()); | ||
943 | 524 | break; | ||
944 | 498 | } | 525 | } |
945 | 499 | 526 | ||
946 | 500 | return ret; | 527 | return ret; |
947 | 501 | 528 | ||
948 | === modified file 'src/lib/Ubuntu/OnlineAccounts.2/account_model.h' | |||
949 | --- src/lib/Ubuntu/OnlineAccounts.2/account_model.h 2016-01-18 12:23:07 +0000 | |||
950 | +++ src/lib/Ubuntu/OnlineAccounts.2/account_model.h 2016-11-10 09:12:06 +0000 | |||
951 | @@ -21,8 +21,12 @@ | |||
952 | 21 | #ifndef ONLINE_ACCOUNTS_MODULE_ACCOUNT_MODEL_H | 21 | #ifndef ONLINE_ACCOUNTS_MODULE_ACCOUNT_MODEL_H |
953 | 22 | #define ONLINE_ACCOUNTS_MODULE_ACCOUNT_MODEL_H | 22 | #define ONLINE_ACCOUNTS_MODULE_ACCOUNT_MODEL_H |
954 | 23 | 23 | ||
955 | 24 | #include "OnlineAccounts/Service" | ||
956 | 25 | |||
957 | 24 | #include <QAbstractListModel> | 26 | #include <QAbstractListModel> |
958 | 25 | #include <QQmlParserStatus> | 27 | #include <QQmlParserStatus> |
959 | 28 | #include <QQmlListProperty> | ||
960 | 29 | #include <QJSValue> | ||
961 | 26 | #include <QString> | 30 | #include <QString> |
962 | 27 | #include <QVariant> | 31 | #include <QVariant> |
963 | 28 | 32 | ||
964 | @@ -43,6 +47,8 @@ | |||
965 | 43 | WRITE setServiceId NOTIFY serviceIdChanged) | 47 | WRITE setServiceId NOTIFY serviceIdChanged) |
966 | 44 | Q_PROPERTY(QList<QObject*> accountList READ accountList \ | 48 | Q_PROPERTY(QList<QObject*> accountList READ accountList \ |
967 | 45 | NOTIFY accountListChanged) | 49 | NOTIFY accountListChanged) |
968 | 50 | Q_PROPERTY(QJSValue serviceList READ serviceList \ | ||
969 | 51 | NOTIFY isReadyChanged) | ||
970 | 46 | 52 | ||
971 | 47 | public: | 53 | public: |
972 | 48 | enum Roles { | 54 | enum Roles { |
973 | @@ -53,6 +59,7 @@ | |||
974 | 53 | AuthenticationMethodRole, | 59 | AuthenticationMethodRole, |
975 | 54 | SettingsRole, | 60 | SettingsRole, |
976 | 55 | AccountRole, | 61 | AccountRole, |
977 | 62 | ServiceRole, | ||
978 | 56 | }; | 63 | }; |
979 | 57 | 64 | ||
980 | 58 | explicit AccountModel(QObject *parent = 0); | 65 | explicit AccountModel(QObject *parent = 0); |
981 | @@ -68,6 +75,8 @@ | |||
982 | 68 | 75 | ||
983 | 69 | QList<QObject*> accountList() const; | 76 | QList<QObject*> accountList() const; |
984 | 70 | 77 | ||
985 | 78 | QJSValue serviceList() const; | ||
986 | 79 | |||
987 | 71 | Q_INVOKABLE void requestAccess(const QString &service, | 80 | Q_INVOKABLE void requestAccess(const QString &service, |
988 | 72 | const QVariantMap ¶ms); | 81 | const QVariantMap ¶ms); |
989 | 73 | 82 | ||
990 | 74 | 83 | ||
991 | === modified file 'src/lib/Ubuntu/OnlineAccounts.2/plugin.cpp' | |||
992 | --- src/lib/Ubuntu/OnlineAccounts.2/plugin.cpp 2015-07-31 12:44:30 +0000 | |||
993 | +++ src/lib/Ubuntu/OnlineAccounts.2/plugin.cpp 2016-11-10 09:12:06 +0000 | |||
994 | @@ -20,6 +20,7 @@ | |||
995 | 20 | 20 | ||
996 | 21 | #include "plugin.h" | 21 | #include "plugin.h" |
997 | 22 | 22 | ||
998 | 23 | #include "account.h" | ||
999 | 23 | #include "account_model.h" | 24 | #include "account_model.h" |
1000 | 24 | 25 | ||
1001 | 25 | #include <QDebug> | 26 | #include <QDebug> |
1002 | @@ -32,4 +33,8 @@ | |||
1003 | 32 | qDebug() << Q_FUNC_INFO << uri; | 33 | qDebug() << Q_FUNC_INFO << uri; |
1004 | 33 | 34 | ||
1005 | 34 | qmlRegisterType<AccountModel>(uri, 2, 0, "AccountModel"); | 35 | qmlRegisterType<AccountModel>(uri, 2, 0, "AccountModel"); |
1006 | 36 | qmlRegisterUncreatableType<Account>(uri, 2, 0, "Account", | ||
1007 | 37 | "Cannot be created from QML"); | ||
1008 | 38 | qmlRegisterUncreatableType<OnlineAccounts::Service>(uri, 2, 0, "Service", | ||
1009 | 39 | "Cannot be created from QML"); | ||
1010 | 35 | } | 40 | } |
1011 | 36 | 41 | ||
1012 | === modified file 'tests/daemon/functional_tests/data/com.ubuntu.tests_application.application' | |||
1013 | --- tests/daemon/functional_tests/data/com.ubuntu.tests_application.application 2015-07-07 12:58:49 +0000 | |||
1014 | +++ tests/daemon/functional_tests/data/com.ubuntu.tests_application.application 2016-11-10 09:12:06 +0000 | |||
1015 | @@ -5,9 +5,12 @@ | |||
1016 | 5 | <desktop-entry>mailer.desktop</desktop-entry> | 5 | <desktop-entry>mailer.desktop</desktop-entry> |
1017 | 6 | 6 | ||
1018 | 7 | <services> | 7 | <services> |
1020 | 8 | <service id="coolshare"> | 8 | <service id="com.ubuntu.tests_coolshare"> |
1021 | 9 | <description>Mailer can even share stuff on CoolShare</description> | 9 | <description>Mailer can even share stuff on CoolShare</description> |
1022 | 10 | </service> | 10 | </service> |
1023 | 11 | <service id="missing-provider"> | ||
1024 | 12 | <description>service exists, provider does not</description> | ||
1025 | 13 | </service> | ||
1026 | 11 | </services> | 14 | </services> |
1027 | 12 | <profile>com.ubuntu.tests_application_0.3</profile> | 15 | <profile>com.ubuntu.tests_application_0.3</profile> |
1028 | 13 | </application> | 16 | </application> |
1029 | 14 | 17 | ||
1030 | === modified file 'tests/daemon/functional_tests/data/com.ubuntu.tests_coolshare.service' | |||
1031 | --- tests/daemon/functional_tests/data/com.ubuntu.tests_coolshare.service 2016-09-28 13:09:06 +0000 | |||
1032 | +++ tests/daemon/functional_tests/data/com.ubuntu.tests_coolshare.service 2016-11-10 09:12:06 +0000 | |||
1033 | @@ -1,5 +1,5 @@ | |||
1034 | 1 | <?xml version="1.0" encoding="UTF-8" ?> | 1 | <?xml version="1.0" encoding="UTF-8" ?> |
1036 | 2 | <service id="coolshare"> | 2 | <service id="com.ubuntu.tests_coolshare"> |
1037 | 3 | <type>sharing</type> | 3 | <type>sharing</type> |
1038 | 4 | <name>Cool Share</name> | 4 | <name>Cool Share</name> |
1039 | 5 | <icon>general_otherservice</icon> | 5 | <icon>general_otherservice</icon> |
1040 | 6 | 6 | ||
1041 | === modified file 'tests/daemon/functional_tests/data/coolmail.service' | |||
1042 | --- tests/daemon/functional_tests/data/coolmail.service 2015-07-02 08:29:48 +0000 | |||
1043 | +++ tests/daemon/functional_tests/data/coolmail.service 2016-11-10 09:12:06 +0000 | |||
1044 | @@ -2,7 +2,6 @@ | |||
1045 | 2 | <service id="coolmail"> | 2 | <service id="coolmail"> |
1046 | 3 | <type>e-mail</type> | 3 | <type>e-mail</type> |
1047 | 4 | <name>Cool Mail</name> | 4 | <name>Cool Mail</name> |
1048 | 5 | <icon>general_myservice</icon> | ||
1049 | 6 | <provider>cool</provider> | 5 | <provider>cool</provider> |
1050 | 7 | 6 | ||
1051 | 8 | <template> | 7 | <template> |
1052 | 9 | 8 | ||
1053 | === added file 'tests/daemon/functional_tests/data/missing-provider.service' | |||
1054 | --- tests/daemon/functional_tests/data/missing-provider.service 1970-01-01 00:00:00 +0000 | |||
1055 | +++ tests/daemon/functional_tests/data/missing-provider.service 2016-11-10 09:12:06 +0000 | |||
1056 | @@ -0,0 +1,14 @@ | |||
1057 | 1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
1058 | 2 | <service id="missing-provider"> | ||
1059 | 3 | <type>sharing</type> | ||
1060 | 4 | <name>Orphan</name> | ||
1061 | 5 | <icon>icon_missing_provider</icon> | ||
1062 | 6 | <provider>missing</provider> | ||
1063 | 7 | |||
1064 | 8 | <template> | ||
1065 | 9 | <group name="auth"> | ||
1066 | 10 | <setting name="method">password</setting> | ||
1067 | 11 | <setting name="mechanism">password</setting> | ||
1068 | 12 | </group> | ||
1069 | 13 | </template> | ||
1070 | 14 | </service> | ||
1071 | 0 | 15 | ||
1072 | === modified file 'tests/daemon/functional_tests/functional_tests.cpp' | |||
1073 | --- tests/daemon/functional_tests/functional_tests.cpp 2016-10-13 13:42:12 +0000 | |||
1074 | +++ tests/daemon/functional_tests/functional_tests.cpp 2016-11-10 09:12:06 +0000 | |||
1075 | @@ -60,8 +60,28 @@ | |||
1076 | 60 | return qstrdup(doc.toJson(QJsonDocument::Compact).data()); | 60 | return qstrdup(doc.toJson(QJsonDocument::Compact).data()); |
1077 | 61 | } | 61 | } |
1078 | 62 | 62 | ||
1079 | 63 | template<> | ||
1080 | 64 | char *toString(const QSet<QVariantMap> &set) | ||
1081 | 65 | { | ||
1082 | 66 | QByteArray ba = "QSet<QVariantMap>("; | ||
1083 | 67 | QStringList list; | ||
1084 | 68 | Q_FOREACH(const QVariantMap &map, set) { | ||
1085 | 69 | list.append(QJsonDocument::fromVariant(map).toJson(QJsonDocument::Compact)); | ||
1086 | 70 | } | ||
1087 | 71 | ba += list.join(", "); | ||
1088 | 72 | ba += ")"; | ||
1089 | 73 | return qstrdup(ba.data()); | ||
1090 | 74 | } | ||
1091 | 75 | |||
1092 | 63 | } // QTest namespace | 76 | } // QTest namespace |
1093 | 64 | 77 | ||
1094 | 78 | static inline uint qHash(const QVariantMap &m, uint seed = 0) | ||
1095 | 79 | { | ||
1096 | 80 | QString signature = QStringList(m.keys()).join(' ') + | ||
1097 | 81 | m.value(ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID).toString(); | ||
1098 | 82 | return ::qHash(signature, seed); | ||
1099 | 83 | } | ||
1100 | 84 | |||
1101 | 65 | class TestProcess: public QProcess | 85 | class TestProcess: public QProcess |
1102 | 66 | { | 86 | { |
1103 | 67 | Q_OBJECT | 87 | Q_OBJECT |
1104 | @@ -90,6 +110,12 @@ | |||
1105 | 90 | void quit() { write("\n"); waitForFinished(); } | 110 | void quit() { write("\n"); waitForFinished(); } |
1106 | 91 | 111 | ||
1107 | 92 | QList<AccountInfo> getAccounts(const QVariantMap &filters) { | 112 | QList<AccountInfo> getAccounts(const QVariantMap &filters) { |
1108 | 113 | QList<QVariantMap> services; | ||
1109 | 114 | return getAccounts(filters, services); | ||
1110 | 115 | } | ||
1111 | 116 | |||
1112 | 117 | QList<AccountInfo> getAccounts(const QVariantMap &filters, | ||
1113 | 118 | QList<QVariantMap> &services) { | ||
1114 | 93 | QJsonDocument doc(QJsonObject::fromVariantMap(filters)); | 119 | QJsonDocument doc(QJsonObject::fromVariantMap(filters)); |
1115 | 94 | m_replyExpected = true; | 120 | m_replyExpected = true; |
1116 | 95 | write("GetAccounts -f "); | 121 | write("GetAccounts -f "); |
1117 | @@ -97,16 +123,31 @@ | |||
1118 | 97 | 123 | ||
1119 | 98 | waitForReadyRead(); | 124 | waitForReadyRead(); |
1120 | 99 | doc = QJsonDocument::fromJson(readLine()); | 125 | doc = QJsonDocument::fromJson(readLine()); |
1121 | 126 | qDebug() << "Got Json:" << doc; | ||
1122 | 100 | m_replyExpected = false; | 127 | m_replyExpected = false; |
1123 | 101 | QList<AccountInfo> accountInfos; | 128 | QList<AccountInfo> accountInfos; |
1125 | 102 | Q_FOREACH(const QJsonValue &v, doc.array()) { | 129 | if (checkError(doc)) return accountInfos; |
1126 | 130 | const QJsonArray accountsJson = doc.array().at(0).toArray(); | ||
1127 | 131 | const QJsonArray servicesJson = doc.array().at(1).toArray(); | ||
1128 | 132 | Q_FOREACH(const QJsonValue &v, accountsJson) { | ||
1129 | 103 | QJsonArray a = v.toArray(); | 133 | QJsonArray a = v.toArray(); |
1130 | 104 | accountInfos.append(AccountInfo(a.at(0).toInt(), | 134 | accountInfos.append(AccountInfo(a.at(0).toInt(), |
1131 | 105 | a.at(1).toObject().toVariantMap())); | 135 | a.at(1).toObject().toVariantMap())); |
1132 | 106 | } | 136 | } |
1133 | 137 | Q_FOREACH(const QJsonValue &v, servicesJson) { | ||
1134 | 138 | services.append(v.toObject().toVariantMap()); | ||
1135 | 139 | } | ||
1136 | 107 | return accountInfos; | 140 | return accountInfos; |
1137 | 108 | } | 141 | } |
1138 | 109 | 142 | ||
1139 | 143 | QString errorName() const { return m_errorName; } | ||
1140 | 144 | |||
1141 | 145 | protected: | ||
1142 | 146 | bool checkError(const QJsonDocument &doc) { | ||
1143 | 147 | m_errorName = doc.object().value("error").toString(); | ||
1144 | 148 | return !m_errorName.isEmpty(); | ||
1145 | 149 | } | ||
1146 | 150 | |||
1147 | 110 | private Q_SLOTS: | 151 | private Q_SLOTS: |
1148 | 111 | void onReadyRead() { | 152 | void onReadyRead() { |
1149 | 112 | if (m_replyExpected) return; | 153 | if (m_replyExpected) return; |
1150 | @@ -128,6 +169,7 @@ | |||
1151 | 128 | 169 | ||
1152 | 129 | private: | 170 | private: |
1153 | 130 | QString m_uniqueName; | 171 | QString m_uniqueName; |
1154 | 172 | QString m_errorName; | ||
1155 | 131 | bool m_replyExpected; | 173 | bool m_replyExpected; |
1156 | 132 | }; | 174 | }; |
1157 | 133 | 175 | ||
1158 | @@ -275,35 +317,113 @@ | |||
1159 | 275 | delete m_dbus; | 317 | delete m_dbus; |
1160 | 276 | } | 318 | } |
1161 | 277 | 319 | ||
1162 | 320 | |||
1163 | 278 | void FunctionalTests::testGetAccountsFiltering_data() | 321 | void FunctionalTests::testGetAccountsFiltering_data() |
1164 | 279 | { | 322 | { |
1165 | 280 | QTest::addColumn<QVariantMap>("filters"); | 323 | QTest::addColumn<QVariantMap>("filters"); |
1166 | 281 | QTest::addColumn<QString>("securityContext"); | 324 | QTest::addColumn<QString>("securityContext"); |
1167 | 325 | QTest::addColumn<QString>("expectedError"); | ||
1168 | 282 | QTest::addColumn<QList<int> >("expectedAccountIds"); | 326 | QTest::addColumn<QList<int> >("expectedAccountIds"); |
1169 | 327 | QTest::addColumn<QList<QVariantMap> >("expectedServices"); | ||
1170 | 283 | 328 | ||
1171 | 284 | QVariantMap filters; | 329 | QVariantMap filters; |
1172 | 285 | QTest::newRow("empty filters") << | 330 | QTest::newRow("empty filters") << |
1173 | 286 | filters << | 331 | filters << |
1174 | 287 | "unconfined" << | 332 | "unconfined" << |
1176 | 288 | (QList<int>() << 1 << 2 << 3); | 333 | QString() << |
1177 | 334 | (QList<int>() << 1 << 2 << 3) << | ||
1178 | 335 | QList<QVariantMap> {}; | ||
1179 | 289 | 336 | ||
1180 | 290 | QTest::newRow("empty filters, confined") << | 337 | QTest::newRow("empty filters, confined") << |
1181 | 291 | filters << | 338 | filters << |
1182 | 292 | "com.ubuntu.tests_application_0.2" << | 339 | "com.ubuntu.tests_application_0.2" << |
1190 | 293 | (QList<int>() << 2); | 340 | QString() << |
1191 | 294 | 341 | (QList<int>() << 2) << | |
1192 | 295 | filters[ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID] = "coolmail"; | 342 | QList<QVariantMap> { |
1193 | 296 | QTest::newRow("by service ID") << | 343 | { |
1194 | 297 | filters << | 344 | { ONLINE_ACCOUNTS_INFO_KEY_DISPLAY_NAME, "Cool Share" }, |
1195 | 298 | "unconfined" << | 345 | { ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID, "com.ubuntu.tests_coolshare" }, |
1196 | 299 | (QList<int>() << 1 << 3); | 346 | { ONLINE_ACCOUNTS_INFO_KEY_ICON_SOURCE, "image://theme/general_otherservice" }, |
1197 | 347 | }, | ||
1198 | 348 | }; | ||
1199 | 349 | |||
1200 | 350 | filters[ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID] = "coolmail"; | ||
1201 | 351 | QTest::newRow("unconfined, by service ID") << | ||
1202 | 352 | filters << | ||
1203 | 353 | "unconfined" << | ||
1204 | 354 | QString() << | ||
1205 | 355 | (QList<int>() << 1 << 3) << | ||
1206 | 356 | QList<QVariantMap> {}; | ||
1207 | 357 | filters.clear(); | ||
1208 | 358 | |||
1209 | 359 | filters[ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID] = "coolmail"; | ||
1210 | 360 | QTest::newRow("confined, by service ID") << | ||
1211 | 361 | filters << | ||
1212 | 362 | "com.ubuntu.tests_application_0.2" << | ||
1213 | 363 | QString() << | ||
1214 | 364 | (QList<int>()) << | ||
1215 | 365 | QList<QVariantMap> { | ||
1216 | 366 | { | ||
1217 | 367 | { ONLINE_ACCOUNTS_INFO_KEY_DISPLAY_NAME, "Cool Share" }, | ||
1218 | 368 | { ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID, "com.ubuntu.tests_coolshare" }, | ||
1219 | 369 | { ONLINE_ACCOUNTS_INFO_KEY_ICON_SOURCE, "image://theme/general_otherservice" }, | ||
1220 | 370 | }, | ||
1221 | 371 | }; | ||
1222 | 372 | filters.clear(); | ||
1223 | 373 | |||
1224 | 374 | filters["applicationId"] = "com.ubuntu.tests_application"; | ||
1225 | 375 | QTest::newRow("by app ID") << | ||
1226 | 376 | filters << | ||
1227 | 377 | "unconfined" << | ||
1228 | 378 | QString() << | ||
1229 | 379 | (QList<int>() << 2) << | ||
1230 | 380 | QList<QVariantMap> { | ||
1231 | 381 | { | ||
1232 | 382 | { ONLINE_ACCOUNTS_INFO_KEY_DISPLAY_NAME, "Cool Share" }, | ||
1233 | 383 | { ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID, "com.ubuntu.tests_coolshare" }, | ||
1234 | 384 | { ONLINE_ACCOUNTS_INFO_KEY_ICON_SOURCE, "image://theme/general_otherservice" }, | ||
1235 | 385 | }, | ||
1236 | 386 | }; | ||
1237 | 387 | filters.clear(); | ||
1238 | 388 | |||
1239 | 389 | filters["applicationId"] = "mailer"; | ||
1240 | 390 | QTest::newRow("confined app requesting other app ID") << | ||
1241 | 391 | filters << | ||
1242 | 392 | "com.ubuntu.tests_application_0.2" << | ||
1243 | 393 | ONLINE_ACCOUNTS_ERROR_PERMISSION_DENIED << | ||
1244 | 394 | (QList<int>()) << | ||
1245 | 395 | QList<QVariantMap> {}; | ||
1246 | 396 | filters.clear(); | ||
1247 | 397 | |||
1248 | 398 | filters["applicationId"] = "mailer"; | ||
1249 | 399 | QTest::newRow("by app ID, with service fallback") << | ||
1250 | 400 | filters << | ||
1251 | 401 | "unconfined" << | ||
1252 | 402 | QString() << | ||
1253 | 403 | QList<int>{ 3, 1 } << | ||
1254 | 404 | QList<QVariantMap> { | ||
1255 | 405 | { | ||
1256 | 406 | { ONLINE_ACCOUNTS_INFO_KEY_DISPLAY_NAME, "OAuth 1 test" }, | ||
1257 | 407 | { ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID, "oauth1auth" }, | ||
1258 | 408 | { ONLINE_ACCOUNTS_INFO_KEY_ICON_SOURCE, "image://theme/general_myservice" }, | ||
1259 | 409 | }, | ||
1260 | 410 | { | ||
1261 | 411 | { ONLINE_ACCOUNTS_INFO_KEY_DISPLAY_NAME, "Cool Mail" }, | ||
1262 | 412 | { ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID, "coolmail" }, | ||
1263 | 413 | { ONLINE_ACCOUNTS_INFO_KEY_ICON_SOURCE, "image://theme/general_myprovider" }, | ||
1264 | 414 | }, | ||
1265 | 415 | }; | ||
1266 | 416 | filters.clear(); | ||
1267 | 417 | |||
1268 | 300 | } | 418 | } |
1269 | 301 | 419 | ||
1270 | 302 | void FunctionalTests::testGetAccountsFiltering() | 420 | void FunctionalTests::testGetAccountsFiltering() |
1271 | 303 | { | 421 | { |
1272 | 304 | QFETCH(QVariantMap, filters); | 422 | QFETCH(QVariantMap, filters); |
1273 | 305 | QFETCH(QString, securityContext); | 423 | QFETCH(QString, securityContext); |
1274 | 424 | QFETCH(QString, expectedError); | ||
1275 | 306 | QFETCH(QList<int>, expectedAccountIds); | 425 | QFETCH(QList<int>, expectedAccountIds); |
1276 | 426 | QFETCH(QList<QVariantMap>, expectedServices); | ||
1277 | 307 | 427 | ||
1278 | 308 | DaemonInterface *daemon = new DaemonInterface(m_dbus->sessionConnection()); | 428 | DaemonInterface *daemon = new DaemonInterface(m_dbus->sessionConnection()); |
1279 | 309 | 429 | ||
1280 | @@ -313,7 +433,10 @@ | |||
1281 | 313 | }; | 433 | }; |
1282 | 314 | m_dbus->dbusApparmor().setCredentials(testProcess.uniqueName(), credentials); | 434 | m_dbus->dbusApparmor().setCredentials(testProcess.uniqueName(), credentials); |
1283 | 315 | 435 | ||
1285 | 316 | QList<AccountInfo> accountInfos = testProcess.getAccounts(filters); | 436 | QList<QVariantMap> services; |
1286 | 437 | QList<AccountInfo> accountInfos = testProcess.getAccounts(filters, services); | ||
1287 | 438 | QCOMPARE(testProcess.errorName(), expectedError); | ||
1288 | 439 | QCOMPARE(services.toSet(), expectedServices.toSet()); | ||
1289 | 317 | QList<int> accountIds; | 440 | QList<int> accountIds; |
1290 | 318 | Q_FOREACH(const AccountInfo &info, accountInfos) { | 441 | Q_FOREACH(const AccountInfo &info, accountInfos) { |
1291 | 319 | accountIds.append(info.id() + m_firstAccountId); | 442 | accountIds.append(info.id() + m_firstAccountId); |
1292 | 320 | 443 | ||
1293 | === modified file 'tests/daemon/functional_tests/test_process.py' | |||
1294 | --- tests/daemon/functional_tests/test_process.py 2016-07-19 11:55:45 +0000 | |||
1295 | +++ tests/daemon/functional_tests/test_process.py 2016-11-10 09:12:06 +0000 | |||
1296 | @@ -30,8 +30,11 @@ | |||
1297 | 30 | filters = dbus.Dictionary(signature='sv') | 30 | filters = dbus.Dictionary(signature='sv') |
1298 | 31 | if args.filters: | 31 | if args.filters: |
1299 | 32 | filters.update(json.loads(args.filters)) | 32 | filters.update(json.loads(args.filters)) |
1302 | 33 | print('%s' % json.dumps(self.manager.GetAccounts(filters), sort_keys=True), | 33 | try: |
1303 | 34 | flush=True) | 34 | print('%s' % json.dumps(self.manager.GetAccounts(filters), sort_keys=True), |
1304 | 35 | flush=True) | ||
1305 | 36 | except dbus.exceptions.DBusException as err: | ||
1306 | 37 | print('{ "error": "%s" }' % err.get_dbus_name(), flush=True) | ||
1307 | 35 | 38 | ||
1308 | 36 | def on_account_changed(self, serviceId, accountInfo): | 39 | def on_account_changed(self, serviceId, accountInfo): |
1309 | 37 | info = json.dumps(accountInfo, sort_keys=True) | 40 | info = json.dumps(accountInfo, sort_keys=True) |
1310 | 38 | 41 | ||
1311 | === modified file 'tests/lib/OnlineAccounts/functional_tests/functional_tests.cpp' | |||
1312 | --- tests/lib/OnlineAccounts/functional_tests/functional_tests.cpp 2016-07-22 05:08:06 +0000 | |||
1313 | +++ tests/lib/OnlineAccounts/functional_tests/functional_tests.cpp 2016-11-10 09:12:06 +0000 | |||
1314 | @@ -26,18 +26,22 @@ | |||
1315 | 26 | #include "OnlineAccounts/account_info.h" | 26 | #include "OnlineAccounts/account_info.h" |
1316 | 27 | #include "OnlineAccountsDaemon/dbus_constants.h" | 27 | #include "OnlineAccountsDaemon/dbus_constants.h" |
1317 | 28 | #include <QDBusConnection> | 28 | #include <QDBusConnection> |
1318 | 29 | #include <QJsonDocument> | ||
1319 | 30 | #include <QJsonObject> | ||
1320 | 29 | #include <QObject> | 31 | #include <QObject> |
1321 | 30 | #include <QSignalSpy> | 32 | #include <QSignalSpy> |
1322 | 31 | #include <QTest> | 33 | #include <QTest> |
1323 | 32 | #include <libqtdbusmock/DBusMock.h> | 34 | #include <libqtdbusmock/DBusMock.h> |
1324 | 33 | 35 | ||
1325 | 34 | namespace QTest { | 36 | namespace QTest { |
1326 | 37 | |||
1327 | 35 | template<> | 38 | template<> |
1328 | 36 | char *toString(const QVariantMap &map) | 39 | char *toString(const QVariantMap &map) |
1329 | 37 | { | 40 | { |
1330 | 38 | QJsonDocument doc(QJsonObject::fromVariantMap(map)); | 41 | QJsonDocument doc(QJsonObject::fromVariantMap(map)); |
1331 | 39 | return qstrdup(doc.toJson(QJsonDocument::Compact).data()); | 42 | return qstrdup(doc.toJson(QJsonDocument::Compact).data()); |
1332 | 40 | } | 43 | } |
1333 | 44 | |||
1334 | 41 | } // QTest namespace | 45 | } // QTest namespace |
1335 | 42 | 46 | ||
1336 | 43 | class FunctionalTests: public QObject | 47 | class FunctionalTests: public QObject |
1337 | @@ -82,6 +86,8 @@ | |||
1338 | 82 | void testManagerReady(); | 86 | void testManagerReady(); |
1339 | 83 | void testManagerAvailableAccounts_data(); | 87 | void testManagerAvailableAccounts_data(); |
1340 | 84 | void testManagerAvailableAccounts(); | 88 | void testManagerAvailableAccounts(); |
1341 | 89 | void testManagerAvailableServices_data(); | ||
1342 | 90 | void testManagerAvailableServices(); | ||
1343 | 85 | void testManagerAccount(); | 91 | void testManagerAccount(); |
1344 | 86 | void testManagerRequestAccess_data(); | 92 | void testManagerRequestAccess_data(); |
1345 | 87 | void testManagerRequestAccess(); | 93 | void testManagerRequestAccess(); |
1346 | @@ -132,7 +138,7 @@ | |||
1347 | 132 | QFETCH(bool, haveGetAccountsMethod); | 138 | QFETCH(bool, haveGetAccountsMethod); |
1348 | 133 | 139 | ||
1349 | 134 | if (haveGetAccountsMethod) { | 140 | if (haveGetAccountsMethod) { |
1351 | 135 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", "ret = []"); | 141 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})aa{sv}", "ret = ([], [])"); |
1352 | 136 | } | 142 | } |
1353 | 137 | OnlineAccounts::Manager manager("my-app"); | 143 | OnlineAccounts::Manager manager("my-app"); |
1354 | 138 | 144 | ||
1355 | @@ -150,12 +156,12 @@ | |||
1356 | 150 | QTest::addColumn<QStringList>("expectedDisplayNames"); | 156 | QTest::addColumn<QStringList>("expectedDisplayNames"); |
1357 | 151 | 157 | ||
1358 | 152 | QTest::newRow("no accounts") << | 158 | QTest::newRow("no accounts") << |
1360 | 153 | "ret = []" << | 159 | "ret = ([], [])" << |
1361 | 154 | QList<int>() << | 160 | QList<int>() << |
1362 | 155 | QStringList(); | 161 | QStringList(); |
1363 | 156 | 162 | ||
1364 | 157 | QTest::newRow("one account, no data") << | 163 | QTest::newRow("one account, no data") << |
1366 | 158 | "ret = [(1, {'displayName': 'Tom'})]" << | 164 | "ret = ([(1, {'displayName': 'Tom'})], [])" << |
1367 | 159 | (QList<int>() << 1) << | 165 | (QList<int>() << 1) << |
1368 | 160 | (QStringList() << "Tom"); | 166 | (QStringList() << "Tom"); |
1369 | 161 | } | 167 | } |
1370 | @@ -166,7 +172,7 @@ | |||
1371 | 166 | QFETCH(QList<int>, expectedIds); | 172 | QFETCH(QList<int>, expectedIds); |
1372 | 167 | QFETCH(QStringList, expectedDisplayNames); | 173 | QFETCH(QStringList, expectedDisplayNames); |
1373 | 168 | 174 | ||
1375 | 169 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", reply); | 175 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})aa{sv}", reply); |
1376 | 170 | OnlineAccounts::Manager manager("my-app"); | 176 | OnlineAccounts::Manager manager("my-app"); |
1377 | 171 | 177 | ||
1378 | 172 | manager.waitForReady(); | 178 | manager.waitForReady(); |
1379 | @@ -181,10 +187,77 @@ | |||
1380 | 181 | QCOMPARE(displayNames, expectedDisplayNames); | 187 | QCOMPARE(displayNames, expectedDisplayNames); |
1381 | 182 | } | 188 | } |
1382 | 183 | 189 | ||
1383 | 190 | void FunctionalTests::testManagerAvailableServices_data() | ||
1384 | 191 | { | ||
1385 | 192 | QTest::addColumn<QString>("reply"); | ||
1386 | 193 | QTest::addColumn<QList<QVariantMap>>("expectedServices"); | ||
1387 | 194 | |||
1388 | 195 | QTest::newRow("no services") << | ||
1389 | 196 | "ret = ([], [])" << | ||
1390 | 197 | QList<QVariantMap> {}; | ||
1391 | 198 | |||
1392 | 199 | QTest::newRow("one service") << | ||
1393 | 200 | "ret = ([], [{" | ||
1394 | 201 | "'" ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID "': 'app_coolshare'," | ||
1395 | 202 | "'" ONLINE_ACCOUNTS_INFO_KEY_DISPLAY_NAME "': 'Cool Share'," | ||
1396 | 203 | "'" ONLINE_ACCOUNTS_INFO_KEY_ICON_SOURCE "': 'image://theme/coolshare'," | ||
1397 | 204 | "}])" << | ||
1398 | 205 | QList<QVariantMap> { | ||
1399 | 206 | { | ||
1400 | 207 | { "serviceId", "app_coolshare" }, | ||
1401 | 208 | { "displayName", "Cool Share" }, | ||
1402 | 209 | { "iconSource", "image://theme/coolshare"}, | ||
1403 | 210 | }, | ||
1404 | 211 | }; | ||
1405 | 212 | } | ||
1406 | 213 | |||
1407 | 214 | void FunctionalTests::testManagerAvailableServices() | ||
1408 | 215 | { | ||
1409 | 216 | QFETCH(QString, reply); | ||
1410 | 217 | QFETCH(QList<QVariantMap>, expectedServices); | ||
1411 | 218 | |||
1412 | 219 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})aa{sv}", reply); | ||
1413 | 220 | OnlineAccounts::Manager manager("my-app"); | ||
1414 | 221 | |||
1415 | 222 | manager.waitForReady(); | ||
1416 | 223 | const auto availableServices = manager.availableServices(); | ||
1417 | 224 | #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) | ||
1418 | 225 | QList<QVariantMap> services; | ||
1419 | 226 | for (const OnlineAccounts::Service &service: availableServices) { | ||
1420 | 227 | QVariantMap data; | ||
1421 | 228 | |||
1422 | 229 | const QMetaObject &mo = service.staticMetaObject; | ||
1423 | 230 | for (int i = mo.propertyOffset(); i < mo.propertyCount(); i++) { | ||
1424 | 231 | const QMetaProperty prop = mo.property(i); | ||
1425 | 232 | data.insert(prop.name(), prop.readOnGadget(&service)); | ||
1426 | 233 | } | ||
1427 | 234 | |||
1428 | 235 | services.append(data); | ||
1429 | 236 | } | ||
1430 | 237 | |||
1431 | 238 | QCOMPARE(services, expectedServices); | ||
1432 | 239 | #else | ||
1433 | 240 | QCOMPARE(availableServices.count(), expectedServices.count()); | ||
1434 | 241 | #endif | ||
1435 | 242 | } | ||
1436 | 243 | |||
1437 | 184 | void FunctionalTests::testManagerAccount() | 244 | void FunctionalTests::testManagerAccount() |
1438 | 185 | { | 245 | { |
1441 | 186 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", | 246 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})aa{sv}", |
1442 | 187 | "ret = [(1, {'displayName': 'John'})]"); | 247 | "ret = ([" |
1443 | 248 | " (1, {" | ||
1444 | 249 | " 'displayName': 'John'," | ||
1445 | 250 | " 'serviceId': 'app_coolshare'," | ||
1446 | 251 | " })," | ||
1447 | 252 | " (2, {" | ||
1448 | 253 | " 'displayName': 'Bob'," | ||
1449 | 254 | " 'serviceId': 'a missing one'," | ||
1450 | 255 | " })," | ||
1451 | 256 | "], [{" | ||
1452 | 257 | " 'serviceId': 'app_coolshare'," | ||
1453 | 258 | " 'displayName': 'Cool Share'," | ||
1454 | 259 | " 'iconSource': 'image://theme/coolshare'," | ||
1455 | 260 | "}])"); | ||
1456 | 188 | OnlineAccounts::Manager manager("my-app"); | 261 | OnlineAccounts::Manager manager("my-app"); |
1457 | 189 | 262 | ||
1458 | 190 | manager.waitForReady(); | 263 | manager.waitForReady(); |
1459 | @@ -193,10 +266,22 @@ | |||
1460 | 193 | OnlineAccounts::Account *account = manager.account(4); | 266 | OnlineAccounts::Account *account = manager.account(4); |
1461 | 194 | QVERIFY(!account); | 267 | QVERIFY(!account); |
1462 | 195 | 268 | ||
1463 | 269 | // valid account linking to invalid service | ||
1464 | 270 | account = manager.account(2); | ||
1465 | 271 | QVERIFY(account); | ||
1466 | 272 | QCOMPARE(account->displayName(), QString("Bob")); | ||
1467 | 273 | QCOMPARE(account->serviceId(), QString("a missing one")); | ||
1468 | 274 | QVERIFY(!account->service().isValid()); | ||
1469 | 275 | |||
1470 | 196 | // valid account | 276 | // valid account |
1471 | 197 | account = manager.account(1); | 277 | account = manager.account(1); |
1472 | 198 | QVERIFY(account); | 278 | QVERIFY(account); |
1473 | 199 | QCOMPARE(account->displayName(), QString("John")); | 279 | QCOMPARE(account->displayName(), QString("John")); |
1474 | 280 | QCOMPARE(account->serviceId(), QString("app_coolshare")); | ||
1475 | 281 | QVERIFY(account->service().isValid()); | ||
1476 | 282 | QCOMPARE(account->service().displayName(), QString("Cool Share")); | ||
1477 | 283 | QCOMPARE(account->service().iconSource(), | ||
1478 | 284 | QUrl("image://theme/coolshare")); | ||
1479 | 200 | } | 285 | } |
1480 | 201 | 286 | ||
1481 | 202 | void FunctionalTests::testManagerRequestAccess_data() | 287 | void FunctionalTests::testManagerRequestAccess_data() |
1482 | @@ -236,7 +321,7 @@ | |||
1483 | 236 | QFETCH(QString, displayName); | 321 | QFETCH(QString, displayName); |
1484 | 237 | QFETCH(QString, accessToken); | 322 | QFETCH(QString, accessToken); |
1485 | 238 | 323 | ||
1487 | 239 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", "ret = []"); | 324 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})aa{sv}", "ret = ([], [])"); |
1488 | 240 | addMockedMethod("RequestAccess", "sa{sv}", "(ua{sv})a{sv}", reply); | 325 | addMockedMethod("RequestAccess", "sa{sv}", "(ua{sv})a{sv}", reply); |
1489 | 241 | OnlineAccounts::Manager manager("my-app"); | 326 | OnlineAccounts::Manager manager("my-app"); |
1490 | 242 | 327 | ||
1491 | @@ -277,12 +362,12 @@ | |||
1492 | 277 | QTest::addColumn<QVariantMap>("settings"); | 362 | QTest::addColumn<QVariantMap>("settings"); |
1493 | 278 | 363 | ||
1494 | 279 | QTest::newRow("empty account") << | 364 | QTest::newRow("empty account") << |
1496 | 280 | "ret = [(1, {})]" << | 365 | "[(1, {})]" << |
1497 | 281 | 1 << | 366 | 1 << |
1498 | 282 | "" << "" << 0 << QVariantMap(); | 367 | "" << "" << 0 << QVariantMap(); |
1499 | 283 | 368 | ||
1500 | 284 | QTest::newRow("no settings") << | 369 | QTest::newRow("no settings") << |
1502 | 285 | "ret = [(3, {" | 370 | "[(3, {" |
1503 | 286 | " 'displayName': 'Bob'," | 371 | " 'displayName': 'Bob'," |
1504 | 287 | " 'serviceId': 'MyService'," | 372 | " 'serviceId': 'MyService'," |
1505 | 288 | " 'authMethod': 1," | 373 | " 'authMethod': 1," |
1506 | @@ -297,7 +382,7 @@ | |||
1507 | 297 | settings.insert("Host", "example.com"); | 382 | settings.insert("Host", "example.com"); |
1508 | 298 | settings.insert("Port", int(7000)); | 383 | settings.insert("Port", int(7000)); |
1509 | 299 | QTest::newRow("with settings") << | 384 | QTest::newRow("with settings") << |
1511 | 300 | "ret = [(4, {" | 385 | "[(4, {" |
1512 | 301 | " 'displayName': 'Tom'," | 386 | " 'displayName': 'Tom'," |
1513 | 302 | " 'serviceId': 'MyService'," | 387 | " 'serviceId': 'MyService'," |
1514 | 303 | " 'authMethod': 2," | 388 | " 'authMethod': 2," |
1515 | @@ -320,7 +405,8 @@ | |||
1516 | 320 | QFETCH(int, authenticationMethod); | 405 | QFETCH(int, authenticationMethod); |
1517 | 321 | QFETCH(QVariantMap, settings); | 406 | QFETCH(QVariantMap, settings); |
1518 | 322 | 407 | ||
1520 | 323 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", reply); | 408 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})aa{sv}", |
1521 | 409 | QString("ret = (%1, [])").arg(reply)); | ||
1522 | 324 | OnlineAccounts::Manager manager("my-app"); | 410 | OnlineAccounts::Manager manager("my-app"); |
1523 | 325 | 411 | ||
1524 | 326 | manager.waitForReady(); | 412 | manager.waitForReady(); |
1525 | @@ -347,7 +433,7 @@ | |||
1526 | 347 | 433 | ||
1527 | 348 | void FunctionalTests::testPendingCallWatcher() | 434 | void FunctionalTests::testPendingCallWatcher() |
1528 | 349 | { | 435 | { |
1530 | 350 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", "ret = []"); | 436 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})aa{sv}", "ret = ([], [])"); |
1531 | 351 | addMockedMethod("RequestAccess", "sa{sv}", "(ua{sv})a{sv}", | 437 | addMockedMethod("RequestAccess", "sa{sv}", "(ua{sv})a{sv}", |
1532 | 352 | "ret = ((1, {'displayName': 'Bob'}),{})"); | 438 | "ret = ((1, {'displayName': 'Bob'}),{})"); |
1533 | 353 | OnlineAccounts::Manager manager("my-app"); | 439 | OnlineAccounts::Manager manager("my-app"); |
1534 | @@ -378,7 +464,7 @@ | |||
1535 | 378 | 464 | ||
1536 | 379 | void FunctionalTests::testAccountChanges() | 465 | void FunctionalTests::testAccountChanges() |
1537 | 380 | { | 466 | { |
1539 | 381 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", "ret = []"); | 467 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})aa{sv}", "ret = ([], [])"); |
1540 | 382 | OnlineAccounts::Manager manager("my-app"); | 468 | OnlineAccounts::Manager manager("my-app"); |
1541 | 383 | QSignalSpy accountAvailable(&manager, | 469 | QSignalSpy accountAvailable(&manager, |
1542 | 384 | SIGNAL(accountAvailable(OnlineAccounts::Account*))); | 470 | SIGNAL(accountAvailable(OnlineAccounts::Account*))); |
1543 | @@ -442,8 +528,8 @@ | |||
1544 | 442 | 528 | ||
1545 | 443 | void FunctionalTests::testMultipleServices() | 529 | void FunctionalTests::testMultipleServices() |
1546 | 444 | { | 530 | { |
1549 | 445 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", | 531 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})aa{sv}", |
1550 | 446 | "ret = [" | 532 | "ret = ([" |
1551 | 447 | "(1, {" | 533 | "(1, {" |
1552 | 448 | " 'displayName': 'One'," | 534 | " 'displayName': 'One'," |
1553 | 449 | " 'serviceId': 'service2'," | 535 | " 'serviceId': 'service2'," |
1554 | @@ -464,7 +550,7 @@ | |||
1555 | 464 | " 'serviceId': 'service1'," | 550 | " 'serviceId': 'service1'," |
1556 | 465 | " 'authMethod': 1," | 551 | " 'authMethod': 1," |
1557 | 466 | "})," | 552 | "})," |
1559 | 467 | "]"); | 553 | "], [])"); |
1560 | 468 | OnlineAccounts::Manager manager("my-app"); | 554 | OnlineAccounts::Manager manager("my-app"); |
1561 | 469 | manager.waitForReady(); | 555 | manager.waitForReady(); |
1562 | 470 | 556 | ||
1563 | @@ -494,8 +580,8 @@ | |||
1564 | 494 | 580 | ||
1565 | 495 | void FunctionalTests::testAuthentication() | 581 | void FunctionalTests::testAuthentication() |
1566 | 496 | { | 582 | { |
1569 | 497 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", | 583 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})aa{sv}", |
1570 | 498 | "ret = [" | 584 | "ret = ([" |
1571 | 499 | "(1, {" | 585 | "(1, {" |
1572 | 500 | " 'displayName': 'Bob'," | 586 | " 'displayName': 'Bob'," |
1573 | 501 | " 'serviceId': 'MyService0'," | 587 | " 'serviceId': 'MyService0'," |
1574 | @@ -516,7 +602,7 @@ | |||
1575 | 516 | " 'serviceId': 'MyService3'," | 602 | " 'serviceId': 'MyService3'," |
1576 | 517 | " 'authMethod': 4," | 603 | " 'authMethod': 4," |
1577 | 518 | "})," | 604 | "})," |
1579 | 519 | "]"); | 605 | "], [])"); |
1580 | 520 | addMockedMethod("Authenticate", "usbba{sv}", "a{sv}", | 606 | addMockedMethod("Authenticate", "usbba{sv}", "a{sv}", |
1581 | 521 | "if args[0] == 1:\n" | 607 | "if args[0] == 1:\n" |
1582 | 522 | " ret = {" | 608 | " ret = {" |
1583 | @@ -671,12 +757,12 @@ | |||
1584 | 671 | QFETCH(int, errorCode); | 757 | QFETCH(int, errorCode); |
1585 | 672 | QFETCH(QString, errorMessage); | 758 | QFETCH(QString, errorMessage); |
1586 | 673 | 759 | ||
1589 | 674 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", | 760 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})aa{sv}", |
1590 | 675 | "ret = [(1, {" | 761 | "ret = ([(1, {" |
1591 | 676 | " 'displayName': 'Bob'," | 762 | " 'displayName': 'Bob'," |
1592 | 677 | " 'serviceId': 'MyService0'," | 763 | " 'serviceId': 'MyService0'," |
1593 | 678 | " 'authMethod': 2," | 764 | " 'authMethod': 2," |
1595 | 679 | "})]"); | 765 | "})], [])"); |
1596 | 680 | addMockedMethod("Authenticate", "usbba{sv}", "a{sv}", reply); | 766 | addMockedMethod("Authenticate", "usbba{sv}", "a{sv}", reply); |
1597 | 681 | OnlineAccounts::Manager manager("my-app"); | 767 | OnlineAccounts::Manager manager("my-app"); |
1598 | 682 | manager.waitForReady(); | 768 | manager.waitForReady(); |
1599 | 683 | 769 | ||
1600 | === modified file 'tests/lib/qml_module/tst_qml_module.cpp' | |||
1601 | --- tests/lib/qml_module/tst_qml_module.cpp 2016-10-06 08:20:10 +0000 | |||
1602 | +++ tests/lib/qml_module/tst_qml_module.cpp 2016-11-10 09:12:06 +0000 | |||
1603 | @@ -55,14 +55,18 @@ | |||
1604 | 55 | } | 55 | } |
1605 | 56 | 56 | ||
1606 | 57 | void addMockedMethod(const QString &name, | 57 | void addMockedMethod(const QString &name, |
1610 | 58 | const QString &in_sig, | 58 | const QString &in_sig, |
1611 | 59 | const QString &out_sig, | 59 | const QString &out_sig, |
1612 | 60 | const QString &code) | 60 | const QString &code) |
1613 | 61 | { | 61 | { |
1614 | 62 | return mocked().AddMethod(ONLINE_ACCOUNTS_MANAGER_INTERFACE, | 62 | return mocked().AddMethod(ONLINE_ACCOUNTS_MANAGER_INTERFACE, |
1615 | 63 | name, in_sig, out_sig, code).waitForFinished(); | 63 | name, in_sig, out_sig, code).waitForFinished(); |
1616 | 64 | } | 64 | } |
1617 | 65 | 65 | ||
1618 | 66 | void addGetAccountsMethod(const QString &code) { | ||
1619 | 67 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})aa{sv}", code); | ||
1620 | 68 | } | ||
1621 | 69 | |||
1622 | 66 | void emitAccountChanged(const QString &service, | 70 | void emitAccountChanged(const QString &service, |
1623 | 67 | uint accountId, | 71 | uint accountId, |
1624 | 68 | const QVariantMap &changes) | 72 | const QVariantMap &changes) |
1625 | @@ -90,6 +94,8 @@ | |||
1626 | 90 | void initTestCase(); | 94 | void initTestCase(); |
1627 | 91 | void testModuleImport(); | 95 | void testModuleImport(); |
1628 | 92 | void testModelProperties(); | 96 | void testModelProperties(); |
1629 | 97 | void testServices_data(); | ||
1630 | 98 | void testServices(); | ||
1631 | 93 | void testModelRoles_data(); | 99 | void testModelRoles_data(); |
1632 | 94 | void testModelRoles(); | 100 | void testModelRoles(); |
1633 | 95 | void testModelFilters_data(); | 101 | void testModelFilters_data(); |
1634 | @@ -156,9 +162,85 @@ | |||
1635 | 156 | delete object; | 162 | delete object; |
1636 | 157 | } | 163 | } |
1637 | 158 | 164 | ||
1638 | 165 | void ModuleTest::testServices_data() | ||
1639 | 166 | { | ||
1640 | 167 | QTest::addColumn<QString>("reply"); | ||
1641 | 168 | QTest::addColumn<QList<QVariantMap>>("expectedServices"); | ||
1642 | 169 | |||
1643 | 170 | QTest::newRow("no services") << | ||
1644 | 171 | "[]" << | ||
1645 | 172 | QList<QVariantMap> {}; | ||
1646 | 173 | |||
1647 | 174 | QTest::newRow("one service") << | ||
1648 | 175 | "[{" | ||
1649 | 176 | "'" ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID "': 'app_coolshare'," | ||
1650 | 177 | "'" ONLINE_ACCOUNTS_INFO_KEY_DISPLAY_NAME "': 'Cool Share'," | ||
1651 | 178 | "'" ONLINE_ACCOUNTS_INFO_KEY_ICON_SOURCE "': 'image://theme/coolshare'," | ||
1652 | 179 | "}]" << | ||
1653 | 180 | QList<QVariantMap> { | ||
1654 | 181 | { | ||
1655 | 182 | { "serviceId", "app_coolshare" }, | ||
1656 | 183 | { "displayName", "Cool Share" }, | ||
1657 | 184 | { "iconSource", "image://theme/coolshare"}, | ||
1658 | 185 | }, | ||
1659 | 186 | }; | ||
1660 | 187 | } | ||
1661 | 188 | |||
1662 | 189 | void ModuleTest::testServices() | ||
1663 | 190 | { | ||
1664 | 191 | QFETCH(QString, reply); | ||
1665 | 192 | QFETCH(QList<QVariantMap>, expectedServices); | ||
1666 | 193 | |||
1667 | 194 | addGetAccountsMethod(QString("ret = ([], %1)").arg(reply)); | ||
1668 | 195 | |||
1669 | 196 | QQmlEngine engine; | ||
1670 | 197 | QQmlComponent component(&engine); | ||
1671 | 198 | /* We could return the serviceList property directly, but that would be | ||
1672 | 199 | * passing a OnlineAccounts::Service as QJSValue, which might not be a | ||
1673 | 200 | * proof that every property is properly accessible from QML. Therefore, we | ||
1674 | 201 | * explicitly run through the list and copy it as a new object. */ | ||
1675 | 202 | component.setData("import Ubuntu.OnlineAccounts 2.0\n" | ||
1676 | 203 | "AccountModel {\n" | ||
1677 | 204 | " applicationId: \"foo\"\n" | ||
1678 | 205 | " function getServices() {\n" | ||
1679 | 206 | " var ret = [];\n" | ||
1680 | 207 | " for (var i = 0; i < serviceList.length; i++) {\n" | ||
1681 | 208 | " var s = serviceList[i];\n" | ||
1682 | 209 | " var service = {};\n" | ||
1683 | 210 | " for (var key in s) { service[key] = s[key]; }\n" | ||
1684 | 211 | " ret.push(service);\n" | ||
1685 | 212 | " }\n" | ||
1686 | 213 | " return ret;\n" | ||
1687 | 214 | " }\n" | ||
1688 | 215 | "}", | ||
1689 | 216 | QUrl()); | ||
1690 | 217 | QObject *object = component.create(); | ||
1691 | 218 | QVERIFY(object != 0); | ||
1692 | 219 | QAbstractListModel *model = qobject_cast<QAbstractListModel*>(object); | ||
1693 | 220 | QVERIFY(model != 0); | ||
1694 | 221 | |||
1695 | 222 | QSignalSpy ready(object, SIGNAL(isReadyChanged())); | ||
1696 | 223 | ready.wait(); | ||
1697 | 224 | |||
1698 | 225 | QVariant serviceList; | ||
1699 | 226 | bool ok = QMetaObject::invokeMethod(object, "getServices", | ||
1700 | 227 | Q_RETURN_ARG(QVariant, serviceList)); | ||
1701 | 228 | QVERIFY(ok); | ||
1702 | 229 | |||
1703 | 230 | QVariantList serviceVariantList = serviceList.toList(); | ||
1704 | 231 | QList<QVariantMap> services; | ||
1705 | 232 | for (const QVariant &v: serviceVariantList) { | ||
1706 | 233 | services.append(v.toMap()); | ||
1707 | 234 | } | ||
1708 | 235 | |||
1709 | 236 | QCOMPARE(services, expectedServices); | ||
1710 | 237 | delete object; | ||
1711 | 238 | } | ||
1712 | 239 | |||
1713 | 159 | void ModuleTest::testModelRoles_data() | 240 | void ModuleTest::testModelRoles_data() |
1714 | 160 | { | 241 | { |
1715 | 161 | QTest::addColumn<QString>("accountData"); | 242 | QTest::addColumn<QString>("accountData"); |
1716 | 243 | QTest::addColumn<QString>("serviceData"); | ||
1717 | 162 | QTest::addColumn<QString>("displayName"); | 244 | QTest::addColumn<QString>("displayName"); |
1718 | 163 | QTest::addColumn<QString>("serviceId"); | 245 | QTest::addColumn<QString>("serviceId"); |
1719 | 164 | QTest::addColumn<int>("authenticationMethod"); | 246 | QTest::addColumn<int>("authenticationMethod"); |
1720 | @@ -167,6 +249,7 @@ | |||
1721 | 167 | QVariantMap settings; | 249 | QVariantMap settings; |
1722 | 168 | QTest::newRow("empty") << | 250 | QTest::newRow("empty") << |
1723 | 169 | "{}" << | 251 | "{}" << |
1724 | 252 | "" << | ||
1725 | 170 | "" << "" << 0 << settings; | 253 | "" << "" << 0 << settings; |
1726 | 171 | 254 | ||
1727 | 172 | settings.insert("Server", "www.example.com"); | 255 | settings.insert("Server", "www.example.com"); |
1728 | @@ -179,19 +262,23 @@ | |||
1729 | 179 | " '" ONLINE_ACCOUNTS_INFO_KEY_SETTINGS "Server': 'www.example.com'," | 262 | " '" ONLINE_ACCOUNTS_INFO_KEY_SETTINGS "Server': 'www.example.com'," |
1730 | 180 | " '" ONLINE_ACCOUNTS_INFO_KEY_SETTINGS "Port': 9900," | 263 | " '" ONLINE_ACCOUNTS_INFO_KEY_SETTINGS "Port': 9900," |
1731 | 181 | "}" << | 264 | "}" << |
1732 | 265 | "{" | ||
1733 | 266 | " '" ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID "': 'cool'," | ||
1734 | 267 | "}" << | ||
1735 | 182 | "Tom" << "cool" << 2 << settings; | 268 | "Tom" << "cool" << 2 << settings; |
1736 | 183 | } | 269 | } |
1737 | 184 | 270 | ||
1738 | 185 | void ModuleTest::testModelRoles() | 271 | void ModuleTest::testModelRoles() |
1739 | 186 | { | 272 | { |
1740 | 187 | QFETCH(QString, accountData); | 273 | QFETCH(QString, accountData); |
1741 | 274 | QFETCH(QString, serviceData); | ||
1742 | 188 | QFETCH(QString, displayName); | 275 | QFETCH(QString, displayName); |
1743 | 189 | QFETCH(QString, serviceId); | 276 | QFETCH(QString, serviceId); |
1744 | 190 | QFETCH(int, authenticationMethod); | 277 | QFETCH(int, authenticationMethod); |
1745 | 191 | QFETCH(QVariantMap, settings); | 278 | QFETCH(QVariantMap, settings); |
1746 | 192 | 279 | ||
1749 | 193 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", | 280 | addGetAccountsMethod(QString("ret = ([(1, %1)], [%2])"). |
1750 | 194 | QString("ret = [(1, %1)]").arg(accountData)); | 281 | arg(accountData).arg(serviceData)); |
1751 | 195 | 282 | ||
1752 | 196 | QQmlEngine engine; | 283 | QQmlEngine engine; |
1753 | 197 | QQmlComponent component(&engine); | 284 | QQmlComponent component(&engine); |
1754 | @@ -218,7 +305,6 @@ | |||
1755 | 218 | QCOMPARE(get(model, 0, "serviceId").toString(), serviceId); | 305 | QCOMPARE(get(model, 0, "serviceId").toString(), serviceId); |
1756 | 219 | QCOMPARE(get(model, 0, "authenticationMethod").toInt(), | 306 | QCOMPARE(get(model, 0, "authenticationMethod").toInt(), |
1757 | 220 | authenticationMethod); | 307 | authenticationMethod); |
1758 | 221 | // until https://bugs.launchpad.net/bugs/1479768 is fixed | ||
1759 | 222 | QCOMPARE(get(model, 0, "settings").toMap(), settings); | 308 | QCOMPARE(get(model, 0, "settings").toMap(), settings); |
1760 | 223 | QObject *account = get(model, 0, "account").value<QObject*>(); | 309 | QObject *account = get(model, 0, "account").value<QObject*>(); |
1761 | 224 | QVERIFY(account != 0); | 310 | QVERIFY(account != 0); |
1762 | @@ -226,6 +312,10 @@ | |||
1763 | 226 | QCOMPARE(account, | 312 | QCOMPARE(account, |
1764 | 227 | model->property("accountList").value<QList<QObject*> >().first()); | 313 | model->property("accountList").value<QList<QObject*> >().first()); |
1765 | 228 | 314 | ||
1766 | 315 | QJSValue service = get(model, 0, "service").value<QJSValue>(); | ||
1767 | 316 | QVERIFY(service.isObject()); | ||
1768 | 317 | QCOMPARE(service.property("serviceId").toString(), serviceId); | ||
1769 | 318 | |||
1770 | 229 | delete object; | 319 | delete object; |
1771 | 230 | } | 320 | } |
1772 | 231 | 321 | ||
1773 | @@ -237,17 +327,17 @@ | |||
1774 | 237 | QTest::addColumn<QStringList>("expectedDisplayNames"); | 327 | QTest::addColumn<QStringList>("expectedDisplayNames"); |
1775 | 238 | 328 | ||
1776 | 239 | QTest::newRow("no accounts") << | 329 | QTest::newRow("no accounts") << |
1778 | 240 | "ret = []" << | 330 | "[]" << |
1779 | 241 | "" << | 331 | "" << |
1780 | 242 | QList<int>(); | 332 | QList<int>(); |
1781 | 243 | 333 | ||
1782 | 244 | QTest::newRow("one account, no service filter") << | 334 | QTest::newRow("one account, no service filter") << |
1784 | 245 | "ret = [(1, {'displayName': 'Tom', 'serviceId': 'Foo' })]" << | 335 | "[(1, {'displayName': 'Tom', 'serviceId': 'Foo' })]" << |
1785 | 246 | "" << | 336 | "" << |
1786 | 247 | (QList<int>() << 1); | 337 | (QList<int>() << 1); |
1787 | 248 | 338 | ||
1788 | 249 | QTest::newRow("one account, with service filter") << | 339 | QTest::newRow("one account, with service filter") << |
1790 | 250 | "ret = [(1, {'displayName': 'Tom', 'serviceId': 'Foo' })]" << | 340 | "[(1, {'displayName': 'Tom', 'serviceId': 'Foo' })]" << |
1791 | 251 | "serviceId: \"bar\"" << | 341 | "serviceId: \"bar\"" << |
1792 | 252 | QList<int>(); | 342 | QList<int>(); |
1793 | 253 | } | 343 | } |
1794 | @@ -258,7 +348,7 @@ | |||
1795 | 258 | QFETCH(QString, filters); | 348 | QFETCH(QString, filters); |
1796 | 259 | QFETCH(QList<int>, expectedIds); | 349 | QFETCH(QList<int>, expectedIds); |
1797 | 260 | 350 | ||
1799 | 261 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", reply); | 351 | addGetAccountsMethod(QString("ret = (%1, [])").arg(reply)); |
1800 | 262 | 352 | ||
1801 | 263 | QQmlEngine engine; | 353 | QQmlEngine engine; |
1802 | 264 | QQmlComponent component(&engine); | 354 | QQmlComponent component(&engine); |
1803 | @@ -287,7 +377,7 @@ | |||
1804 | 287 | 377 | ||
1805 | 288 | void ModuleTest::testModelChanges() | 378 | void ModuleTest::testModelChanges() |
1806 | 289 | { | 379 | { |
1808 | 290 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", "ret = []"); | 380 | addGetAccountsMethod("ret = ([], [])"); |
1809 | 291 | QQmlEngine engine; | 381 | QQmlEngine engine; |
1810 | 292 | QQmlComponent component(&engine); | 382 | QQmlComponent component(&engine); |
1811 | 293 | component.setData("import Ubuntu.OnlineAccounts 2.0\n" | 383 | component.setData("import Ubuntu.OnlineAccounts 2.0\n" |
1812 | @@ -397,8 +487,7 @@ | |||
1813 | 397 | QFETCH(QVariantMap, expectedAccessReply); | 487 | QFETCH(QVariantMap, expectedAccessReply); |
1814 | 398 | QFETCH(QVariantMap, expectedAuthenticationData); | 488 | QFETCH(QVariantMap, expectedAuthenticationData); |
1815 | 399 | 489 | ||
1818 | 400 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", | 490 | addGetAccountsMethod("ret = ([(1, {'displayName': 'Tom', 'serviceId': 'Foo' })], [])"); |
1817 | 401 | "ret = [(1, {'displayName': 'Tom', 'serviceId': 'Foo' })]"); | ||
1819 | 402 | addMockedMethod("RequestAccess", "sa{sv}", "(ua{sv})a{sv}", reply); | 491 | addMockedMethod("RequestAccess", "sa{sv}", "(ua{sv})a{sv}", reply); |
1820 | 403 | 492 | ||
1821 | 404 | QQmlEngine engine; | 493 | QQmlEngine engine; |
1822 | @@ -536,12 +625,11 @@ | |||
1823 | 536 | QFETCH(QVariantMap, params); | 625 | QFETCH(QVariantMap, params); |
1824 | 537 | QFETCH(QVariantMap, expectedAuthenticationData); | 626 | QFETCH(QVariantMap, expectedAuthenticationData); |
1825 | 538 | 627 | ||
1832 | 539 | addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})", | 628 | addGetAccountsMethod(QString("ret = ([(1, {" |
1833 | 540 | QString("ret = [(1, {" | 629 | " 'displayName': 'Bob'," |
1834 | 541 | " 'displayName': 'Bob'," | 630 | " 'serviceId': 'MyService0'," |
1835 | 542 | " 'serviceId': 'MyService0'," | 631 | " 'authMethod': %1," |
1836 | 543 | " 'authMethod': %1," | 632 | "})], [])").arg(authMethod)); |
1831 | 544 | "})]").arg(authMethod)); | ||
1837 | 545 | addMockedMethod("Authenticate", "usbba{sv}", "a{sv}", reply); | 633 | addMockedMethod("Authenticate", "usbba{sv}", "a{sv}", reply); |
1838 | 546 | 634 | ||
1839 | 547 | QQmlEngine engine; | 635 | QQmlEngine engine; |
I may be missing something here, but (not being familiar with the code), it looks like the translated service name is not present? We need the translated name of the service too (such as "Google" or "Dropbox", or their equivalents in Arabic script, or whatever).