Merge lp:~mardy/accounts-qml-module/applications into lp:accounts-qml-module
- applications
- Merge into trunk
Proposed by
Alberto Mardegan
Status: | Merged |
---|---|
Approved by: | Ken VanDine |
Approved revision: | 29 |
Merged at revision: | 28 |
Proposed branch: | lp:~mardy/accounts-qml-module/applications |
Merge into: | lp:accounts-qml-module |
Diff against target: |
505 lines (+410/-0) 9 files modified
src/application-model.cpp (+156/-0) src/application-model.h (+76/-0) src/application.cpp (+66/-0) src/application.h (+43/-0) src/plugin.cpp (+2/-0) src/src.pro (+4/-0) tests/data/mailer.application (+12/-0) tests/tst_plugin.cpp (+50/-0) tests/tst_plugin.pro (+1/-0) |
To merge this branch: | bzr merge lp:~mardy/accounts-qml-module/applications |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ken VanDine | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email:
|
Commit message
Add ApplicationModel
Description of the change
Add ApplicationModel
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Approve
(continuous-integration)
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ken VanDine (ken-vandine) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'src/application-model.cpp' | |||
2 | --- src/application-model.cpp 1970-01-01 00:00:00 +0000 | |||
3 | +++ src/application-model.cpp 2013-06-13 08:40:35 +0000 | |||
4 | @@ -0,0 +1,156 @@ | |||
5 | 1 | /* | ||
6 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
7 | 3 | * | ||
8 | 4 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
9 | 5 | * | ||
10 | 6 | * This program is free software; you can redistribute it and/or modify | ||
11 | 7 | * it under the terms of the GNU Lesser General Public License as published by | ||
12 | 8 | * the Free Software Foundation; version 2.1. | ||
13 | 9 | * | ||
14 | 10 | * This program is distributed in the hope that it will be useful, | ||
15 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | 13 | * GNU Lesser General Public License for more details. | ||
18 | 14 | * | ||
19 | 15 | * You should have received a copy of the GNU Lesser General Public License | ||
20 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
21 | 17 | */ | ||
22 | 18 | |||
23 | 19 | #include "debug.h" | ||
24 | 20 | #include "application-model.h" | ||
25 | 21 | #include "application.h" | ||
26 | 22 | |||
27 | 23 | #include <Accounts/Manager> | ||
28 | 24 | |||
29 | 25 | using namespace OnlineAccounts; | ||
30 | 26 | |||
31 | 27 | /*! | ||
32 | 28 | * \qmltype ApplicationModel | ||
33 | 29 | * \inqmlmodule Ubuntu.OnlineAccounts 0.1 | ||
34 | 30 | * \ingroup Ubuntu | ||
35 | 31 | * | ||
36 | 32 | * \brief A model of the applications using online accounts. | ||
37 | 33 | * | ||
38 | 34 | * The ApplicationModel is a model representing the applications using online | ||
39 | 35 | * accounts installed on the system. | ||
40 | 36 | * | ||
41 | 37 | * In the current implementation, the model is valid only if its \l | ||
42 | 38 | * ApplicationModel::service property is set to a valid service ID. | ||
43 | 39 | * | ||
44 | 40 | * The model defines the following roles: | ||
45 | 41 | * \list | ||
46 | 42 | * \li \c applicationId is the unique identifier of the application | ||
47 | 43 | * \li \c displayName is the application display name | ||
48 | 44 | * \li \c iconName is the name of the application icon | ||
49 | 45 | * \li \c serviceUsage is a description of how the application uses the | ||
50 | 46 | * service; this is set to a valid value only if the \l | ||
51 | 47 | * ApplicationModel::service property is set to a valid service ID. | ||
52 | 48 | * \li \c application is the Application object | ||
53 | 49 | * \endlist | ||
54 | 50 | */ | ||
55 | 51 | |||
56 | 52 | ApplicationModel::ApplicationModel(QObject *parent): | ||
57 | 53 | QAbstractListModel(parent), | ||
58 | 54 | manager(SharedManager::instance()) | ||
59 | 55 | { | ||
60 | 56 | } | ||
61 | 57 | |||
62 | 58 | ApplicationModel::~ApplicationModel() | ||
63 | 59 | { | ||
64 | 60 | } | ||
65 | 61 | |||
66 | 62 | /* | ||
67 | 63 | * \qmlproperty int ApplicationModel::count | ||
68 | 64 | * The number of items in the model. | ||
69 | 65 | */ | ||
70 | 66 | int ApplicationModel::rowCount(const QModelIndex &parent) const | ||
71 | 67 | { | ||
72 | 68 | Q_UNUSED(parent); | ||
73 | 69 | return applications.count(); | ||
74 | 70 | } | ||
75 | 71 | |||
76 | 72 | /*! | ||
77 | 73 | * \qmlproperty string ApplicationModel::service | ||
78 | 74 | * If set, the model will list only those accounts services for this | ||
79 | 75 | * specific service. | ||
80 | 76 | */ | ||
81 | 77 | void ApplicationModel::setService(const QString &serviceId) | ||
82 | 78 | { | ||
83 | 79 | if (serviceId == m_service.name()) return; | ||
84 | 80 | m_service = manager->service(serviceId); | ||
85 | 81 | |||
86 | 82 | beginResetModel(); | ||
87 | 83 | qDeleteAll(applications); | ||
88 | 84 | applications.clear(); | ||
89 | 85 | |||
90 | 86 | computeApplicationList(); | ||
91 | 87 | endResetModel(); | ||
92 | 88 | Q_EMIT serviceChanged(); | ||
93 | 89 | } | ||
94 | 90 | |||
95 | 91 | QString ApplicationModel::service() const | ||
96 | 92 | { | ||
97 | 93 | return m_service.name(); | ||
98 | 94 | } | ||
99 | 95 | |||
100 | 96 | /* | ||
101 | 97 | * \qmlmethod variant ApplicationModel::get(int row, string roleName) | ||
102 | 98 | * | ||
103 | 99 | * Returns the data at \a row for the role \a roleName. | ||
104 | 100 | */ | ||
105 | 101 | QVariant ApplicationModel::get(int row, const QString &roleName) const | ||
106 | 102 | { | ||
107 | 103 | int role = roleNames().key(roleName.toLatin1(), -1); | ||
108 | 104 | return data(index(row), role); | ||
109 | 105 | } | ||
110 | 106 | |||
111 | 107 | QVariant ApplicationModel::data(const QModelIndex &index, int role) const | ||
112 | 108 | { | ||
113 | 109 | if (index.row() < 0 || index.row() >= applications.count()) | ||
114 | 110 | return QVariant(); | ||
115 | 111 | |||
116 | 112 | Application *application = applications.at(index.row()); | ||
117 | 113 | QVariant ret; | ||
118 | 114 | |||
119 | 115 | switch (role) { | ||
120 | 116 | case Qt::DisplayRole: | ||
121 | 117 | case ApplicationIdRole: | ||
122 | 118 | ret = application->name(); | ||
123 | 119 | break; | ||
124 | 120 | case DisplayNameRole: | ||
125 | 121 | case IconNameRole: | ||
126 | 122 | // FIXME: implement when libaccounts-qt 1.8 is released | ||
127 | 123 | break; | ||
128 | 124 | case ServiceUsageRole: | ||
129 | 125 | ret = application->serviceUsage(m_service); | ||
130 | 126 | break; | ||
131 | 127 | case ApplicationRole: | ||
132 | 128 | ret = QVariant::fromValue<QObject*>(application); | ||
133 | 129 | break; | ||
134 | 130 | } | ||
135 | 131 | |||
136 | 132 | return ret; | ||
137 | 133 | } | ||
138 | 134 | |||
139 | 135 | QHash<int, QByteArray> ApplicationModel::roleNames() const | ||
140 | 136 | { | ||
141 | 137 | static QHash<int, QByteArray> roles; | ||
142 | 138 | if (roles.isEmpty()) { | ||
143 | 139 | roles[ApplicationIdRole] = "applicationId"; | ||
144 | 140 | roles[DisplayNameRole] = "displayName"; | ||
145 | 141 | roles[IconNameRole] = "iconName"; | ||
146 | 142 | roles[ServiceUsageRole] = "serviceUsage"; | ||
147 | 143 | roles[ApplicationRole] = "application"; | ||
148 | 144 | } | ||
149 | 145 | return roles; | ||
150 | 146 | } | ||
151 | 147 | |||
152 | 148 | void ApplicationModel::computeApplicationList() | ||
153 | 149 | { | ||
154 | 150 | if (!m_service.isValid()) return; | ||
155 | 151 | |||
156 | 152 | Q_FOREACH(const Accounts::Application &app, | ||
157 | 153 | manager->applicationList(m_service)) { | ||
158 | 154 | applications.append(new Application(app, this)); | ||
159 | 155 | } | ||
160 | 156 | } | ||
161 | 0 | 157 | ||
162 | === added file 'src/application-model.h' | |||
163 | --- src/application-model.h 1970-01-01 00:00:00 +0000 | |||
164 | +++ src/application-model.h 2013-06-13 08:40:35 +0000 | |||
165 | @@ -0,0 +1,76 @@ | |||
166 | 1 | /* | ||
167 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
168 | 3 | * | ||
169 | 4 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
170 | 5 | * | ||
171 | 6 | * This program is free software; you can redistribute it and/or modify | ||
172 | 7 | * it under the terms of the GNU Lesser General Public License as published by | ||
173 | 8 | * the Free Software Foundation; version 2.1. | ||
174 | 9 | * | ||
175 | 10 | * This program is distributed in the hope that it will be useful, | ||
176 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
177 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
178 | 13 | * GNU Lesser General Public License for more details. | ||
179 | 14 | * | ||
180 | 15 | * You should have received a copy of the GNU Lesser General Public License | ||
181 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
182 | 17 | */ | ||
183 | 18 | |||
184 | 19 | #ifndef ONLINE_ACCOUNTS_APPLICATION_MODEL_H | ||
185 | 20 | #define ONLINE_ACCOUNTS_APPLICATION_MODEL_H | ||
186 | 21 | |||
187 | 22 | #include "manager.h" | ||
188 | 23 | #include <Accounts/Service> | ||
189 | 24 | #include <QAbstractListModel> | ||
190 | 25 | #include <QList> | ||
191 | 26 | #include <QSharedPointer> | ||
192 | 27 | |||
193 | 28 | namespace OnlineAccounts { | ||
194 | 29 | |||
195 | 30 | class Application; | ||
196 | 31 | |||
197 | 32 | class ApplicationModel: public QAbstractListModel | ||
198 | 33 | { | ||
199 | 34 | Q_OBJECT | ||
200 | 35 | Q_PROPERTY(int count READ rowCount NOTIFY countChanged) | ||
201 | 36 | Q_PROPERTY(QString service READ service WRITE setService \ | ||
202 | 37 | NOTIFY serviceChanged) | ||
203 | 38 | |||
204 | 39 | public: | ||
205 | 40 | ApplicationModel(QObject *parent = 0); | ||
206 | 41 | ~ApplicationModel(); | ||
207 | 42 | |||
208 | 43 | enum Roles { | ||
209 | 44 | ApplicationIdRole = Qt::UserRole + 1, | ||
210 | 45 | DisplayNameRole, | ||
211 | 46 | IconNameRole, | ||
212 | 47 | ServiceUsageRole, | ||
213 | 48 | ApplicationRole, | ||
214 | 49 | }; | ||
215 | 50 | |||
216 | 51 | void setService(const QString &serviceId); | ||
217 | 52 | QString service() const; | ||
218 | 53 | |||
219 | 54 | Q_INVOKABLE QVariant get(int row, const QString &roleName) const; | ||
220 | 55 | |||
221 | 56 | // reimplemented virtual methods | ||
222 | 57 | int rowCount(const QModelIndex &parent = QModelIndex()) const; | ||
223 | 58 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | ||
224 | 59 | QHash<int, QByteArray> roleNames() const; | ||
225 | 60 | |||
226 | 61 | Q_SIGNALS: | ||
227 | 62 | void countChanged(); | ||
228 | 63 | void serviceChanged(); | ||
229 | 64 | |||
230 | 65 | private: | ||
231 | 66 | void computeApplicationList(); | ||
232 | 67 | |||
233 | 68 | private: | ||
234 | 69 | QSharedPointer<Accounts::Manager> manager; | ||
235 | 70 | QList<Application*> applications; | ||
236 | 71 | Accounts::Service m_service; | ||
237 | 72 | }; | ||
238 | 73 | |||
239 | 74 | }; // namespace | ||
240 | 75 | |||
241 | 76 | #endif // ONLINE_ACCOUNTS_APPLICATION_MODEL_H | ||
242 | 0 | 77 | ||
243 | === added file 'src/application.cpp' | |||
244 | --- src/application.cpp 1970-01-01 00:00:00 +0000 | |||
245 | +++ src/application.cpp 2013-06-13 08:40:35 +0000 | |||
246 | @@ -0,0 +1,66 @@ | |||
247 | 1 | /* | ||
248 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
249 | 3 | * | ||
250 | 4 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
251 | 5 | * | ||
252 | 6 | * This program is free software; you can redistribute it and/or modify | ||
253 | 7 | * it under the terms of the GNU Lesser General Public License as published by | ||
254 | 8 | * the Free Software Foundation; version 2.1. | ||
255 | 9 | * | ||
256 | 10 | * This program is distributed in the hope that it will be useful, | ||
257 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
258 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
259 | 13 | * GNU Lesser General Public License for more details. | ||
260 | 14 | * | ||
261 | 15 | * You should have received a copy of the GNU Lesser General Public License | ||
262 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
263 | 17 | */ | ||
264 | 18 | |||
265 | 19 | |||
266 | 20 | #include "application.h" | ||
267 | 21 | #include "debug.h" | ||
268 | 22 | |||
269 | 23 | using namespace OnlineAccounts; | ||
270 | 24 | |||
271 | 25 | /*! | ||
272 | 26 | * \qmltype Account | ||
273 | 27 | * \inqmlmodule Ubuntu.OnlineAccounts 0.1 | ||
274 | 28 | * \ingroup Ubuntu | ||
275 | 29 | * | ||
276 | 30 | * \brief Represents an instance of an online account. | ||
277 | 31 | * | ||
278 | 32 | * The Account element represents an online account. Currently, instances of | ||
279 | 33 | * this object cannot be created directly, but are instantiated by the \l | ||
280 | 34 | * ApplicationModel element. | ||
281 | 35 | */ | ||
282 | 36 | Application::Application(const Accounts::Application &application, | ||
283 | 37 | QObject *parent): | ||
284 | 38 | QObject(parent), | ||
285 | 39 | Accounts::Application(application) | ||
286 | 40 | { | ||
287 | 41 | } | ||
288 | 42 | |||
289 | 43 | Application::~Application() | ||
290 | 44 | { | ||
291 | 45 | } | ||
292 | 46 | |||
293 | 47 | /*! | ||
294 | 48 | * \qmlproperty string Application::applicationId | ||
295 | 49 | * Unique identifier for this application. | ||
296 | 50 | */ | ||
297 | 51 | |||
298 | 52 | /*! | ||
299 | 53 | * \qmlproperty string Application::description | ||
300 | 54 | * Description of the application. | ||
301 | 55 | */ | ||
302 | 56 | |||
303 | 57 | /*! | ||
304 | 58 | * \qmlmethod string Application::serviceUsage(Service service) | ||
305 | 59 | * | ||
306 | 60 | * Returns a textual description of how the application can make use of \a | ||
307 | 61 | * service. | ||
308 | 62 | */ | ||
309 | 63 | QString Application::serviceUsage(const Accounts::Service &service) | ||
310 | 64 | { | ||
311 | 65 | return Accounts::Application::serviceUsage(service); | ||
312 | 66 | } | ||
313 | 0 | 67 | ||
314 | === added file 'src/application.h' | |||
315 | --- src/application.h 1970-01-01 00:00:00 +0000 | |||
316 | +++ src/application.h 2013-06-13 08:40:35 +0000 | |||
317 | @@ -0,0 +1,43 @@ | |||
318 | 1 | /* | ||
319 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
320 | 3 | * | ||
321 | 4 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
322 | 5 | * | ||
323 | 6 | * This program is free software; you can redistribute it and/or modify | ||
324 | 7 | * it under the terms of the GNU Lesser General Public License as published by | ||
325 | 8 | * the Free Software Foundation; version 2.1. | ||
326 | 9 | * | ||
327 | 10 | * This program is distributed in the hope that it will be useful, | ||
328 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
329 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
330 | 13 | * GNU Lesser General Public License for more details. | ||
331 | 14 | * | ||
332 | 15 | * You should have received a copy of the GNU Lesser General Public License | ||
333 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
334 | 17 | */ | ||
335 | 18 | |||
336 | 19 | #ifndef ONLINE_ACCOUNTS_APPLICATION_H | ||
337 | 20 | #define ONLINE_ACCOUNTS_APPLICATION_H | ||
338 | 21 | |||
339 | 22 | #include <QObject> | ||
340 | 23 | |||
341 | 24 | #include <Accounts/Application> | ||
342 | 25 | |||
343 | 26 | namespace OnlineAccounts { | ||
344 | 27 | |||
345 | 28 | class Application: public QObject, public Accounts::Application | ||
346 | 29 | { | ||
347 | 30 | Q_OBJECT | ||
348 | 31 | Q_PROPERTY(QString applicationId READ name CONSTANT) | ||
349 | 32 | Q_PROPERTY(QString description READ description CONSTANT) | ||
350 | 33 | |||
351 | 34 | public: | ||
352 | 35 | Application(const Accounts::Application &application, QObject *parent = 0); | ||
353 | 36 | ~Application(); | ||
354 | 37 | |||
355 | 38 | Q_INVOKABLE QString serviceUsage(const Accounts::Service &service); | ||
356 | 39 | }; | ||
357 | 40 | |||
358 | 41 | }; // namespace | ||
359 | 42 | |||
360 | 43 | #endif // ONLINE_ACCOUNTS_APPLICATION_H | ||
361 | 0 | 44 | ||
362 | === modified file 'src/plugin.cpp' | |||
363 | --- src/plugin.cpp 2013-05-31 06:46:13 +0000 | |||
364 | +++ src/plugin.cpp 2013-06-13 08:40:35 +0000 | |||
365 | @@ -19,6 +19,7 @@ | |||
366 | 19 | #include "account-service-model.h" | 19 | #include "account-service-model.h" |
367 | 20 | #include "account-service.h" | 20 | #include "account-service.h" |
368 | 21 | #include "account.h" | 21 | #include "account.h" |
369 | 22 | #include "application-model.h" | ||
370 | 22 | #include "credentials.h" | 23 | #include "credentials.h" |
371 | 23 | #include "manager.h" | 24 | #include "manager.h" |
372 | 24 | #include "plugin.h" | 25 | #include "plugin.h" |
373 | @@ -43,6 +44,7 @@ | |||
374 | 43 | qmlRegisterType<AccountServiceModel>(uri, 0, 1, "AccountServiceModel"); | 44 | qmlRegisterType<AccountServiceModel>(uri, 0, 1, "AccountServiceModel"); |
375 | 44 | qmlRegisterType<AccountService>(uri, 0, 1, "AccountService"); | 45 | qmlRegisterType<AccountService>(uri, 0, 1, "AccountService"); |
376 | 45 | qmlRegisterType<Account>(uri, 0, 1, "Account"); | 46 | qmlRegisterType<Account>(uri, 0, 1, "Account"); |
377 | 47 | qmlRegisterType<ApplicationModel>(uri, 0, 1, "ApplicationModel"); | ||
378 | 46 | qmlRegisterType<Credentials>(uri, 0, 1, "Credentials"); | 48 | qmlRegisterType<Credentials>(uri, 0, 1, "Credentials"); |
379 | 47 | qmlRegisterType<ProviderModel>(uri, 0, 1, "ProviderModel"); | 49 | qmlRegisterType<ProviderModel>(uri, 0, 1, "ProviderModel"); |
380 | 48 | qmlRegisterSingletonType<Manager>(uri, 0, 1, "Manager", createManager); | 50 | qmlRegisterSingletonType<Manager>(uri, 0, 1, "Manager", createManager); |
381 | 49 | 51 | ||
382 | === modified file 'src/src.pro' | |||
383 | --- src/src.pro 2013-06-03 10:30:40 +0000 | |||
384 | +++ src/src.pro 2013-06-13 08:40:35 +0000 | |||
385 | @@ -30,6 +30,8 @@ | |||
386 | 30 | account-service-model.cpp \ | 30 | account-service-model.cpp \ |
387 | 31 | account-service.cpp \ | 31 | account-service.cpp \ |
388 | 32 | account.cpp \ | 32 | account.cpp \ |
389 | 33 | application-model.cpp \ | ||
390 | 34 | application.cpp \ | ||
391 | 33 | credentials.cpp \ | 35 | credentials.cpp \ |
392 | 34 | manager.cpp \ | 36 | manager.cpp \ |
393 | 35 | plugin.cpp \ | 37 | plugin.cpp \ |
394 | @@ -39,6 +41,8 @@ | |||
395 | 39 | account-service-model.h \ | 41 | account-service-model.h \ |
396 | 40 | account-service.h \ | 42 | account-service.h \ |
397 | 41 | account.h \ | 43 | account.h \ |
398 | 44 | application-model.h \ | ||
399 | 45 | application.h \ | ||
400 | 42 | credentials.h \ | 46 | credentials.h \ |
401 | 43 | debug.h \ | 47 | debug.h \ |
402 | 44 | manager.h \ | 48 | manager.h \ |
403 | 45 | 49 | ||
404 | === added file 'tests/data/mailer.application' | |||
405 | --- tests/data/mailer.application 1970-01-01 00:00:00 +0000 | |||
406 | +++ tests/data/mailer.application 2013-06-13 08:40:35 +0000 | |||
407 | @@ -0,0 +1,12 @@ | |||
408 | 1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
409 | 2 | <application id="mailer"> | ||
410 | 3 | <description>Mailer application</description> | ||
411 | 4 | <translations>mailer-catalog</translations> | ||
412 | 5 | |||
413 | 6 | <service-types> | ||
414 | 7 | <service-type id="e-mail"> | ||
415 | 8 | <description>Mailer can retrieve your e-mails</description> | ||
416 | 9 | </service-type> | ||
417 | 10 | </service-types> | ||
418 | 11 | |||
419 | 12 | </application> | ||
420 | 0 | 13 | ||
421 | === modified file 'tests/tst_plugin.cpp' | |||
422 | --- tests/tst_plugin.cpp 2013-06-03 10:30:40 +0000 | |||
423 | +++ tests/tst_plugin.cpp 2013-06-13 08:40:35 +0000 | |||
424 | @@ -54,6 +54,7 @@ | |||
425 | 54 | void testAccountCredentialsRemoval_data(); | 54 | void testAccountCredentialsRemoval_data(); |
426 | 55 | void testAccountCredentialsRemoval(); | 55 | void testAccountCredentialsRemoval(); |
427 | 56 | void testAccountServiceCredentials(); | 56 | void testAccountServiceCredentials(); |
428 | 57 | void testApplicationModel(); | ||
429 | 57 | 58 | ||
430 | 58 | private: | 59 | private: |
431 | 59 | void clearDb(); | 60 | void clearDb(); |
432 | @@ -84,6 +85,7 @@ | |||
433 | 84 | { | 85 | { |
434 | 85 | qputenv("QML2_IMPORT_PATH", "../src"); | 86 | qputenv("QML2_IMPORT_PATH", "../src"); |
435 | 86 | qputenv("ACCOUNTS", "/tmp/"); | 87 | qputenv("ACCOUNTS", "/tmp/"); |
436 | 88 | qputenv("AG_APPLICATIONS", APPLICATIONS_DIR); | ||
437 | 87 | qputenv("AG_SERVICES", SERVICES_DIR); | 89 | qputenv("AG_SERVICES", SERVICES_DIR); |
438 | 88 | qputenv("AG_SERVICE_TYPES", SERVICE_TYPES_DIR); | 90 | qputenv("AG_SERVICE_TYPES", SERVICE_TYPES_DIR); |
439 | 89 | qputenv("AG_PROVIDERS", PROVIDERS_DIR); | 91 | qputenv("AG_PROVIDERS", PROVIDERS_DIR); |
440 | @@ -1278,5 +1280,53 @@ | |||
441 | 1278 | delete accountService; | 1280 | delete accountService; |
442 | 1279 | } | 1281 | } |
443 | 1280 | 1282 | ||
444 | 1283 | void PluginTest::testApplicationModel() | ||
445 | 1284 | { | ||
446 | 1285 | QQmlEngine engine; | ||
447 | 1286 | QQmlComponent component(&engine); | ||
448 | 1287 | component.setData("import Ubuntu.OnlineAccounts 0.1\n" | ||
449 | 1288 | "ApplicationModel {}", | ||
450 | 1289 | QUrl()); | ||
451 | 1290 | QObject *qmlModel = component.create(); | ||
452 | 1291 | QVERIFY(qmlModel != 0); | ||
453 | 1292 | QAbstractListModel *model = qobject_cast<QAbstractListModel*>(qmlModel); | ||
454 | 1293 | QVERIFY(model != 0); | ||
455 | 1294 | |||
456 | 1295 | QCOMPARE(model->rowCount(), 0); | ||
457 | 1296 | /* Retrieve a couple of invalid indexes */ | ||
458 | 1297 | QVERIFY(!get(model, 0, "applicationId").isValid()); | ||
459 | 1298 | QVERIFY(!get(model, -1, "applicationId").isValid()); | ||
460 | 1299 | |||
461 | 1300 | /* Set a valid service on the model */ | ||
462 | 1301 | qmlModel->setProperty("service", QString("badmail")); | ||
463 | 1302 | QCOMPARE(model->property("service").toString(), QString("badmail")); | ||
464 | 1303 | |||
465 | 1304 | QCOMPARE(model->rowCount(), 1); | ||
466 | 1305 | QCOMPARE(model->property("count").toInt(), 1); | ||
467 | 1306 | |||
468 | 1307 | QCOMPARE(get(model, 0, "applicationId").toString(), QString("mailer")); | ||
469 | 1308 | QCOMPARE(get(model, 0, "serviceUsage").toString(), | ||
470 | 1309 | QString("Mailer can retrieve your e-mails")); | ||
471 | 1310 | |||
472 | 1311 | |||
473 | 1312 | QVariant value; | ||
474 | 1313 | QVERIFY(QMetaObject::invokeMethod(model, "get", | ||
475 | 1314 | Q_RETURN_ARG(QVariant, value), | ||
476 | 1315 | Q_ARG(int, 0), | ||
477 | 1316 | Q_ARG(QString, "applicationId"))); | ||
478 | 1317 | QCOMPARE(value.toString(), QString("mailer")); | ||
479 | 1318 | |||
480 | 1319 | /* Get an Application from the model */ | ||
481 | 1320 | QObject *application = get(model, 0, "application").value<QObject*>(); | ||
482 | 1321 | QCOMPARE(application->metaObject()->className(), | ||
483 | 1322 | "OnlineAccounts::Application"); | ||
484 | 1323 | |||
485 | 1324 | /* Reset the model to an invalid service */ | ||
486 | 1325 | qmlModel->setProperty("service", QString()); | ||
487 | 1326 | QCOMPARE(model->rowCount(), 0); | ||
488 | 1327 | |||
489 | 1328 | delete qmlModel; | ||
490 | 1329 | } | ||
491 | 1330 | |||
492 | 1281 | QTEST_MAIN(PluginTest); | 1331 | QTEST_MAIN(PluginTest); |
493 | 1282 | #include "tst_plugin.moc" | 1332 | #include "tst_plugin.moc" |
494 | 1283 | 1333 | ||
495 | === modified file 'tests/tst_plugin.pro' | |||
496 | --- tests/tst_plugin.pro 2013-04-10 11:42:03 +0000 | |||
497 | +++ tests/tst_plugin.pro 2013-06-13 08:40:35 +0000 | |||
498 | @@ -25,6 +25,7 @@ | |||
499 | 25 | DATA_PATH = $${TOP_SRC_DIR}/tests/data/ | 25 | DATA_PATH = $${TOP_SRC_DIR}/tests/data/ |
500 | 26 | 26 | ||
501 | 27 | DEFINES += \ | 27 | DEFINES += \ |
502 | 28 | APPLICATIONS_DIR=\\\"$$DATA_PATH\\\" \ | ||
503 | 28 | SERVICES_DIR=\\\"$$DATA_PATH\\\" \ | 29 | SERVICES_DIR=\\\"$$DATA_PATH\\\" \ |
504 | 29 | SERVICE_TYPES_DIR=\\\"$$DATA_PATH\\\" \ | 30 | SERVICE_TYPES_DIR=\\\"$$DATA_PATH\\\" \ |
505 | 30 | PROVIDERS_DIR=\\\"$$DATA_PATH\\\" | 31 | PROVIDERS_DIR=\\\"$$DATA_PATH\\\" |
PASSED: Continuous integration, rev:29 jenkins. qa.ubuntu. com/job/ accounts- qml-module- ci/14/ jenkins. qa.ubuntu. com/job/ accounts- qml-module- saucy-amd64- ci/4
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ accounts- qml-module- ci/14/rebuild
http://