Merge lp:~mardy/online-accounts-api/ready-1513075 into lp:online-accounts-api

Proposed by Alberto Mardegan
Status: Merged
Approved by: David Barth
Approved revision: 17
Merged at revision: 18
Proposed branch: lp:~mardy/online-accounts-api/ready-1513075
Merge into: lp:online-accounts-api
Diff against target: 126 lines (+40/-1)
3 files modified
src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp (+27/-0)
src/lib/Ubuntu/OnlineAccounts.2/account_model.h (+4/-0)
tests/lib/qml_module/tst_qml_module.cpp (+9/-1)
To merge this branch: bzr merge lp:~mardy/online-accounts-api/ready-1513075
Reviewer Review Type Date Requested Status
Online Accounts Pending
Review via email: mp+282935@code.launchpad.net

Commit message

Add a property to signal when the account model is ready.

Description of the change

Add a property to signal when the account model is ready.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp'
2--- src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp 2015-10-30 15:35:40 +0000
3+++ src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp 2016-01-18 12:31:53 +0000
4@@ -60,6 +60,7 @@
5 QList<Account*> m_accounts;
6 QString m_applicationId;
7 QString m_serviceId;
8+ bool m_isReady;
9 bool m_updateQueued;
10 bool m_applicationIdChanged;
11 bool m_serviceIdChanged;
12@@ -71,6 +72,7 @@
13 AccountModelPrivate::AccountModelPrivate(AccountModel *q):
14 QObject(q),
15 m_manager(0),
16+ m_isReady(false),
17 m_updateQueued(true), // because componentComplete will be called
18 m_applicationIdChanged(false),
19 m_serviceIdChanged(false),
20@@ -87,10 +89,17 @@
21
22 void AccountModelPrivate::queueUpdate()
23 {
24+ Q_Q(AccountModel);
25+
26 if (m_updateQueued) return;
27
28 m_updateQueued = true;
29 QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection);
30+
31+ if (m_isReady) {
32+ m_isReady = false;
33+ Q_EMIT q->isReadyChanged();
34+ }
35 }
36
37 void AccountModelPrivate::updateAccountList()
38@@ -106,6 +115,9 @@
39 }
40 q->endResetModel();
41 Q_EMIT q->accountListChanged();
42+
43+ m_isReady = true;
44+ Q_EMIT q->isReadyChanged();
45 }
46
47 Account *AccountModelPrivate::handleAccount(OnlineAccounts::Account *account)
48@@ -296,6 +308,21 @@
49 }
50
51 /*!
52+ * \qmlproperty bool AccountModel::ready
53+ *
54+ * Whether the model is up to date: retrieving the account list is an
55+ * asynchronous operation, and therefore short delays are expected between
56+ * changing one model parameter and receiving the updated account list.
57+ * Applications should not rely on the model contents while this property is
58+ * false.
59+ */
60+bool AccountModel::isReady() const
61+{
62+ Q_D(const AccountModel);
63+ return d->m_isReady;
64+}
65+
66+/*!
67 * \qmlproperty string AccountModel::applicationId
68 *
69 * The short application identifier (that is, the \c APP_ID minus the version
70
71=== modified file 'src/lib/Ubuntu/OnlineAccounts.2/account_model.h'
72--- src/lib/Ubuntu/OnlineAccounts.2/account_model.h 2015-09-23 08:23:49 +0000
73+++ src/lib/Ubuntu/OnlineAccounts.2/account_model.h 2016-01-18 12:31:53 +0000
74@@ -36,6 +36,7 @@
75 Q_OBJECT
76 Q_INTERFACES(QQmlParserStatus)
77 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
78+ Q_PROPERTY(bool ready READ isReady NOTIFY isReadyChanged)
79 Q_PROPERTY(QString applicationId READ applicationId \
80 WRITE setApplicationId NOTIFY applicationIdChanged)
81 Q_PROPERTY(QString serviceId READ serviceId \
82@@ -57,6 +58,8 @@
83 explicit AccountModel(QObject *parent = 0);
84 ~AccountModel();
85
86+ bool isReady() const;
87+
88 void setApplicationId(const QString &applicationId);
89 QString applicationId() const;
90
91@@ -79,6 +82,7 @@
92 void componentComplete() Q_DECL_OVERRIDE;
93
94 Q_SIGNALS:
95+ void isReadyChanged();
96 void countChanged();
97 void applicationIdChanged();
98 void serviceIdChanged();
99
100=== modified file 'tests/lib/qml_module/tst_qml_module.cpp'
101--- tests/lib/qml_module/tst_qml_module.cpp 2015-10-30 15:35:40 +0000
102+++ tests/lib/qml_module/tst_qml_module.cpp 2016-01-18 12:31:53 +0000
103@@ -151,6 +151,8 @@
104 QVERIFY(object->setProperty("serviceId", "bar"));
105 QCOMPARE(object->property("serviceId").toString(), QString("bar"));
106
107+ QCOMPARE(object->property("ready").toBool(), false);
108+
109 delete object;
110 }
111
112@@ -201,7 +203,13 @@
113 QAbstractListModel *model = qobject_cast<QAbstractListModel*>(object);
114 QVERIFY(model != 0);
115
116- QTRY_COMPARE(model->rowCount(), 1);
117+ QCOMPARE(object->property("ready").toBool(), false);
118+ QSignalSpy ready(object, SIGNAL(isReadyChanged()));
119+
120+ ready.wait();
121+ QCOMPARE(object->property("ready").toBool(), true);
122+
123+ QCOMPARE(model->rowCount(), 1);
124 QCOMPARE(model->data(model->index(0), Qt::DisplayRole).toString(),
125 QString("%1 - %2").arg(displayName).arg(serviceId));
126 QCOMPARE(get(model, 0, "displayName").toString(), displayName);

Subscribers

People subscribed via source and target branches