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