Merge lp:~boiko/telephony-service/contactwatcher_set_properties into lp:telephony-service

Proposed by Gustavo Pichorim Boiko
Status: Merged
Approved by: Tiago Salem Herrmann
Approved revision: 1129
Merged at revision: 1125
Proposed branch: lp:~boiko/telephony-service/contactwatcher_set_properties
Merge into: lp:telephony-service
Prerequisite: lp:~tiagosh/telephony-service/fix-x-ofono-unknown
Diff against target: 315 lines (+100/-75)
2 files modified
Ubuntu/Telephony/contactwatcher.cpp (+89/-70)
Ubuntu/Telephony/contactwatcher.h (+11/-5)
To merge this branch: bzr merge lp:~boiko/telephony-service/contactwatcher_set_properties
Reviewer Review Type Date Requested Status
Tiago Salem Herrmann (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+274311@code.launchpad.net

This proposal supersedes a proposal from 2015-10-08.

Commit message

Make it possible to set all fields in the contact matcher.
Some components (like HistoryService's events and threads) provide a cached contact match value and are just interested in watching for changes.

Description of the change

Make it possible to set all fields in the contact matcher.
Some components (like HistoryService's events and threads) provide a cached contact match value and are just interested in watching for changes.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Tiago Salem Herrmann (tiagosh) wrote : Posted in a previous version of this proposal

just two comments.

review: Needs Fixing
1129. By Gustavo Pichorim Boiko

Use the defined macros for unknown and private numbers.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Tiago Salem Herrmann (tiagosh) wrote :

Looks good.
thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Ubuntu/Telephony/contactwatcher.cpp'
2--- Ubuntu/Telephony/contactwatcher.cpp 2015-10-13 19:29:58 +0000
3+++ Ubuntu/Telephony/contactwatcher.cpp 2015-10-13 19:29:58 +0000
4@@ -53,6 +53,8 @@
5 connect(ContactUtils::sharedManager(),
6 SIGNAL(contactsRemoved(QList<QContactId>)),
7 SLOT(onContactsRemoved(QList<QContactId>)));
8+
9+ connect(this, SIGNAL(contactIdChanged()), SIGNAL(isUnknownChanged()));
10 }
11
12 ContactWatcher::~ContactWatcher()
13@@ -65,8 +67,9 @@
14
15 void ContactWatcher::startSearching()
16 {
17- if (!mCompleted || mIdentifier.isEmpty()) {
18- // componenty is not ready yet or no identifier given
19+ if (!mCompleted || mIdentifier.isEmpty() || !mInteractive) {
20+ // component is not ready yet or no identifier given,
21+ // or the number is not interactive and thus doesn't need contact info at all
22 return;
23 }
24
25@@ -112,6 +115,25 @@
26 mRequest->start();
27 }
28
29+void ContactWatcher::clear()
30+{
31+ setAlias(QString::null);
32+ setContactId(QString::null);
33+ setAvatar(QString::null);
34+ setDetailProperties(QVariantMap());
35+}
36+
37+void ContactWatcher::updateAlias()
38+{
39+ if (mIdentifier.isEmpty()) {
40+ setAlias(QString::null);
41+ } else if (mIdentifier.startsWith(OFONO_PRIVATE_NUMBER)) {
42+ setAlias(C::dgettext("telephony-service", "Private Number"));
43+ } else if (mIdentifier.startsWith(OFONO_UNKNOWN_NUMBER)) {
44+ setAlias(C::dgettext("telephony-service", "Unknown Number"));
45+ }
46+}
47+
48 QVariantList ContactWatcher::wrapIntList(const QList<int> &list)
49 {
50 QVariantList resultList;
51@@ -132,12 +154,21 @@
52
53 QString ContactWatcher::contactId() const
54 {
55- QString id = mContactId.toString();
56+ return mContactId;
57+}
58+
59+void ContactWatcher::setContactId(const QString &id)
60+{
61+ if (id == mContactId) {
62+ return;
63+ }
64+
65 if (id == QStringLiteral("qtcontacts:::")) {
66- return QString();
67+ mContactId = QString::null;
68 } else {
69- return id;
70+ mContactId = id;
71 }
72+ Q_EMIT contactIdChanged();
73 }
74
75 QString ContactWatcher::avatar() const
76@@ -145,11 +176,29 @@
77 return mAvatar;
78 }
79
80+void ContactWatcher::setAvatar(const QString &avatar)
81+{
82+ if (avatar == mAvatar) {
83+ return;
84+ }
85+ mAvatar = avatar;
86+ Q_EMIT avatarChanged();
87+}
88+
89 QString ContactWatcher::alias() const
90 {
91 return mAlias;
92 }
93
94+void ContactWatcher::setAlias(const QString &alias)
95+{
96+ if (alias == mAlias) {
97+ return;
98+ }
99+ mAlias = alias;
100+ Q_EMIT aliasChanged();
101+}
102+
103 QString ContactWatcher::identifier() const
104 {
105 return mIdentifier;
106@@ -169,31 +218,19 @@
107 mIdentifier = identifier;
108 Q_EMIT identifierChanged();
109
110- if (mIdentifier.isEmpty() || isPrivate || isUnknown) {
111- mAlias.clear();
112- mContactId = QContactId();
113- mAvatar.clear();
114- mDetailProperties.clear();
115-
116- if (isPrivate) {
117- mAlias = C::dgettext("telephony-service", "Private Number");
118- } else if (isUnknown) {
119- mAlias = C::dgettext("telephony-service", "Unknown Number");
120- }
121-
122- Q_EMIT contactIdChanged();
123- Q_EMIT avatarChanged();
124- Q_EMIT aliasChanged();
125- Q_EMIT detailPropertiesChanged();
126- Q_EMIT isUnknownChanged();
127- } else {
128- startSearching();
129- }
130-
131 if (isInteractive != mInteractive) {
132 mInteractive = isInteractive;
133 Q_EMIT interactiveChanged();
134 }
135+
136+ if (mIdentifier.isEmpty() || isPrivate || isUnknown) {
137+ updateAlias();
138+ setContactId(QString::null);
139+ setAvatar(QString::null);
140+ setDetailProperties(QVariantMap());
141+ } else {
142+ startSearching();
143+ }
144 }
145
146 QVariantMap ContactWatcher::detailProperties() const
147@@ -201,6 +238,15 @@
148 return mDetailProperties;
149 }
150
151+void ContactWatcher::setDetailProperties(const QVariantMap &properties)
152+{
153+ if (properties == mDetailProperties) {
154+ return;
155+ }
156+ mDetailProperties = properties;
157+ Q_EMIT detailPropertiesChanged();
158+}
159+
160 bool ContactWatcher::isUnknown() const
161 {
162 return mContactId.isNull();
163@@ -235,6 +281,7 @@
164 void ContactWatcher::componentComplete()
165 {
166 mCompleted = true;
167+ updateAlias();
168 startSearching();
169 }
170
171@@ -258,19 +305,13 @@
172
173 void ContactWatcher::onContactsRemoved(QList<QContactId> ids)
174 {
175- // if the current contact got removed, clear it before trying to search for a new one
176- if (ids.contains(mContactId)) {
177- mAlias.clear();
178- mContactId = QContactId();
179- mAvatar.clear();
180- mDetailProperties.clear();
181- Q_EMIT contactIdChanged();
182- Q_EMIT avatarChanged();
183- Q_EMIT aliasChanged();
184- Q_EMIT detailPropertiesChanged();
185- Q_EMIT isUnknownChanged();
186+ Q_FOREACH(const QContactId &id, ids) {
187+ if (id.toString() == mContactId) {
188+ clear();
189
190- startSearching();
191+ startSearching();
192+ break;
193+ }
194 }
195 }
196
197@@ -306,32 +347,18 @@
198 }
199 }
200
201- if (contact.id() != mContactId) {
202- mContactId = contact.id();
203- Q_EMIT contactIdChanged();
204- }
205-
206- QString newAvatar = contact.detail<QContactAvatar>().imageUrl().toString();
207- if (newAvatar != mAvatar) {
208- mAvatar = newAvatar;
209- Q_EMIT avatarChanged();
210- }
211-
212- QString newAlias = ContactUtils::formatContactName(contact);
213- if (newAlias != mAlias) {
214- mAlias = newAlias;
215- Q_EMIT aliasChanged();
216- Q_EMIT isUnknownChanged();
217- }
218-
219+ setContactId(contact.id().toString());
220+ setAvatar(contact.detail<QContactAvatar>().imageUrl().toString());
221+ setAlias(ContactUtils::formatContactName(contact));
222+
223+ QVariantMap detailProperties;
224 Q_FOREACH(const QString &field, mAddressableFields) {
225 if (field == "tel") {
226 Q_FOREACH(const QContactPhoneNumber phoneNumber, contact.details(QContactDetail::TypePhoneNumber)) {
227 if (PhoneUtils::comparePhoneNumbers(phoneNumber.number(), mIdentifier) > PhoneUtils::NO_MATCH) {
228- mDetailProperties["type"] = (int)QContactDetail::TypePhoneNumber;
229- mDetailProperties["phoneNumberSubTypes"] = wrapIntList(phoneNumber.subTypes());
230- mDetailProperties["phoneNumberContexts"] = wrapIntList(phoneNumber.contexts());
231- Q_EMIT detailPropertiesChanged();
232+ detailProperties["type"] = (int)QContactDetail::TypePhoneNumber;
233+ detailProperties["phoneNumberSubTypes"] = wrapIntList(phoneNumber.subTypes());
234+ detailProperties["phoneNumberContexts"] = wrapIntList(phoneNumber.contexts());
235 break;
236 }
237 }
238@@ -339,6 +366,7 @@
239 // FIXME: add proper support for more fields
240 }
241 }
242+ setDetailProperties(detailProperties);
243 }
244 }
245
246@@ -351,16 +379,7 @@
247
248 // if we got no results and we had a contact previously, we need to clear the data
249 if (request->contacts().isEmpty() && !mContactId.isNull()) {
250- mAlias.clear();
251- mContactId = QContactId();
252- mAvatar.clear();
253- mDetailProperties.clear();
254-
255- Q_EMIT contactIdChanged();
256- Q_EMIT avatarChanged();
257- Q_EMIT aliasChanged();
258- Q_EMIT detailPropertiesChanged();
259- Q_EMIT isUnknownChanged();
260+ clear();
261 }
262 }
263 }
264
265=== modified file 'Ubuntu/Telephony/contactwatcher.h'
266--- Ubuntu/Telephony/contactwatcher.h 2015-07-31 22:05:04 +0000
267+++ Ubuntu/Telephony/contactwatcher.h 2015-10-13 19:29:58 +0000
268@@ -36,14 +36,14 @@
269 Q_OBJECT
270 Q_INTERFACES(QQmlParserStatus)
271
272- Q_PROPERTY(QString contactId READ contactId NOTIFY contactIdChanged)
273- Q_PROPERTY(QString avatar READ avatar NOTIFY avatarChanged)
274- Q_PROPERTY(QString alias READ alias NOTIFY aliasChanged)
275+ Q_PROPERTY(QString contactId READ contactId WRITE setContactId NOTIFY contactIdChanged)
276+ Q_PROPERTY(QString avatar READ avatar WRITE setAvatar NOTIFY avatarChanged)
277+ Q_PROPERTY(QString alias READ alias WRITE setAlias NOTIFY aliasChanged)
278 Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged)
279 Q_PROPERTY(QString phoneNumber READ identifier WRITE setIdentifier NOTIFY identifierChanged)
280 // The details property changes according to the detail type.
281 // One property is always present on the map though, the "detailType" property.
282- Q_PROPERTY(QVariantMap detailProperties READ detailProperties NOTIFY detailPropertiesChanged)
283+ Q_PROPERTY(QVariantMap detailProperties READ detailProperties WRITE setDetailProperties NOTIFY detailPropertiesChanged)
284 Q_PROPERTY(bool isUnknown READ isUnknown NOTIFY isUnknownChanged)
285 Q_PROPERTY(bool interactive READ interactive NOTIFY interactiveChanged)
286 Q_PROPERTY(QStringList addressableFields READ addressableFields WRITE setAddressableFields NOTIFY addressableFieldsChanged)
287@@ -53,11 +53,15 @@
288 ~ContactWatcher();
289
290 QString contactId() const;
291+ void setContactId(const QString &id);
292 QString avatar() const;
293+ void setAvatar(const QString &avatar);
294 QString alias() const;
295+ void setAlias(const QString &alias);
296 QString identifier() const;
297 void setIdentifier(const QString &identifier);
298 QVariantMap detailProperties() const;
299+ void setDetailProperties(const QVariantMap &properties);
300 bool isUnknown() const;
301 bool interactive() const;
302
303@@ -91,9 +95,11 @@
304
305 private:
306 void startSearching();
307+ void clear();
308+ void updateAlias();
309
310 QContactFetchRequest *mRequest;
311- QContactId mContactId;
312+ QString mContactId;
313 QString mAvatar;
314 QString mAlias;
315 QString mIdentifier;

Subscribers

People subscribed via source and target branches