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
=== modified file 'Ubuntu/Telephony/contactwatcher.cpp'
--- Ubuntu/Telephony/contactwatcher.cpp 2015-10-13 19:29:58 +0000
+++ Ubuntu/Telephony/contactwatcher.cpp 2015-10-13 19:29:58 +0000
@@ -53,6 +53,8 @@
53 connect(ContactUtils::sharedManager(),53 connect(ContactUtils::sharedManager(),
54 SIGNAL(contactsRemoved(QList<QContactId>)),54 SIGNAL(contactsRemoved(QList<QContactId>)),
55 SLOT(onContactsRemoved(QList<QContactId>)));55 SLOT(onContactsRemoved(QList<QContactId>)));
56
57 connect(this, SIGNAL(contactIdChanged()), SIGNAL(isUnknownChanged()));
56}58}
5759
58ContactWatcher::~ContactWatcher()60ContactWatcher::~ContactWatcher()
@@ -65,8 +67,9 @@
6567
66void ContactWatcher::startSearching()68void ContactWatcher::startSearching()
67{69{
68 if (!mCompleted || mIdentifier.isEmpty()) {70 if (!mCompleted || mIdentifier.isEmpty() || !mInteractive) {
69 // componenty is not ready yet or no identifier given71 // component is not ready yet or no identifier given,
72 // or the number is not interactive and thus doesn't need contact info at all
70 return;73 return;
71 }74 }
7275
@@ -112,6 +115,25 @@
112 mRequest->start();115 mRequest->start();
113}116}
114117
118void ContactWatcher::clear()
119{
120 setAlias(QString::null);
121 setContactId(QString::null);
122 setAvatar(QString::null);
123 setDetailProperties(QVariantMap());
124}
125
126void ContactWatcher::updateAlias()
127{
128 if (mIdentifier.isEmpty()) {
129 setAlias(QString::null);
130 } else if (mIdentifier.startsWith(OFONO_PRIVATE_NUMBER)) {
131 setAlias(C::dgettext("telephony-service", "Private Number"));
132 } else if (mIdentifier.startsWith(OFONO_UNKNOWN_NUMBER)) {
133 setAlias(C::dgettext("telephony-service", "Unknown Number"));
134 }
135}
136
115QVariantList ContactWatcher::wrapIntList(const QList<int> &list)137QVariantList ContactWatcher::wrapIntList(const QList<int> &list)
116{138{
117 QVariantList resultList;139 QVariantList resultList;
@@ -132,12 +154,21 @@
132154
133QString ContactWatcher::contactId() const155QString ContactWatcher::contactId() const
134{156{
135 QString id = mContactId.toString();157 return mContactId;
158}
159
160void ContactWatcher::setContactId(const QString &id)
161{
162 if (id == mContactId) {
163 return;
164 }
165
136 if (id == QStringLiteral("qtcontacts:::")) {166 if (id == QStringLiteral("qtcontacts:::")) {
137 return QString();167 mContactId = QString::null;
138 } else {168 } else {
139 return id;169 mContactId = id;
140 }170 }
171 Q_EMIT contactIdChanged();
141}172}
142173
143QString ContactWatcher::avatar() const174QString ContactWatcher::avatar() const
@@ -145,11 +176,29 @@
145 return mAvatar;176 return mAvatar;
146}177}
147178
179void ContactWatcher::setAvatar(const QString &avatar)
180{
181 if (avatar == mAvatar) {
182 return;
183 }
184 mAvatar = avatar;
185 Q_EMIT avatarChanged();
186}
187
148QString ContactWatcher::alias() const188QString ContactWatcher::alias() const
149{189{
150 return mAlias;190 return mAlias;
151}191}
152192
193void ContactWatcher::setAlias(const QString &alias)
194{
195 if (alias == mAlias) {
196 return;
197 }
198 mAlias = alias;
199 Q_EMIT aliasChanged();
200}
201
153QString ContactWatcher::identifier() const202QString ContactWatcher::identifier() const
154{203{
155 return mIdentifier;204 return mIdentifier;
@@ -169,31 +218,19 @@
169 mIdentifier = identifier;218 mIdentifier = identifier;
170 Q_EMIT identifierChanged();219 Q_EMIT identifierChanged();
171220
172 if (mIdentifier.isEmpty() || isPrivate || isUnknown) {
173 mAlias.clear();
174 mContactId = QContactId();
175 mAvatar.clear();
176 mDetailProperties.clear();
177
178 if (isPrivate) {
179 mAlias = C::dgettext("telephony-service", "Private Number");
180 } else if (isUnknown) {
181 mAlias = C::dgettext("telephony-service", "Unknown Number");
182 }
183
184 Q_EMIT contactIdChanged();
185 Q_EMIT avatarChanged();
186 Q_EMIT aliasChanged();
187 Q_EMIT detailPropertiesChanged();
188 Q_EMIT isUnknownChanged();
189 } else {
190 startSearching();
191 }
192
193 if (isInteractive != mInteractive) {221 if (isInteractive != mInteractive) {
194 mInteractive = isInteractive;222 mInteractive = isInteractive;
195 Q_EMIT interactiveChanged();223 Q_EMIT interactiveChanged();
196 }224 }
225
226 if (mIdentifier.isEmpty() || isPrivate || isUnknown) {
227 updateAlias();
228 setContactId(QString::null);
229 setAvatar(QString::null);
230 setDetailProperties(QVariantMap());
231 } else {
232 startSearching();
233 }
197}234}
198235
199QVariantMap ContactWatcher::detailProperties() const236QVariantMap ContactWatcher::detailProperties() const
@@ -201,6 +238,15 @@
201 return mDetailProperties;238 return mDetailProperties;
202}239}
203240
241void ContactWatcher::setDetailProperties(const QVariantMap &properties)
242{
243 if (properties == mDetailProperties) {
244 return;
245 }
246 mDetailProperties = properties;
247 Q_EMIT detailPropertiesChanged();
248}
249
204bool ContactWatcher::isUnknown() const250bool ContactWatcher::isUnknown() const
205{251{
206 return mContactId.isNull();252 return mContactId.isNull();
@@ -235,6 +281,7 @@
235void ContactWatcher::componentComplete()281void ContactWatcher::componentComplete()
236{282{
237 mCompleted = true;283 mCompleted = true;
284 updateAlias();
238 startSearching();285 startSearching();
239}286}
240287
@@ -258,19 +305,13 @@
258305
259void ContactWatcher::onContactsRemoved(QList<QContactId> ids)306void ContactWatcher::onContactsRemoved(QList<QContactId> ids)
260{307{
261 // if the current contact got removed, clear it before trying to search for a new one308 Q_FOREACH(const QContactId &id, ids) {
262 if (ids.contains(mContactId)) {309 if (id.toString() == mContactId) {
263 mAlias.clear();310 clear();
264 mContactId = QContactId();
265 mAvatar.clear();
266 mDetailProperties.clear();
267 Q_EMIT contactIdChanged();
268 Q_EMIT avatarChanged();
269 Q_EMIT aliasChanged();
270 Q_EMIT detailPropertiesChanged();
271 Q_EMIT isUnknownChanged();
272311
273 startSearching();312 startSearching();
313 break;
314 }
274 }315 }
275}316}
276317
@@ -306,32 +347,18 @@
306 }347 }
307 }348 }
308349
309 if (contact.id() != mContactId) {350 setContactId(contact.id().toString());
310 mContactId = contact.id();351 setAvatar(contact.detail<QContactAvatar>().imageUrl().toString());
311 Q_EMIT contactIdChanged();352 setAlias(ContactUtils::formatContactName(contact));
312 }353
313354 QVariantMap detailProperties;
314 QString newAvatar = contact.detail<QContactAvatar>().imageUrl().toString();
315 if (newAvatar != mAvatar) {
316 mAvatar = newAvatar;
317 Q_EMIT avatarChanged();
318 }
319
320 QString newAlias = ContactUtils::formatContactName(contact);
321 if (newAlias != mAlias) {
322 mAlias = newAlias;
323 Q_EMIT aliasChanged();
324 Q_EMIT isUnknownChanged();
325 }
326
327 Q_FOREACH(const QString &field, mAddressableFields) {355 Q_FOREACH(const QString &field, mAddressableFields) {
328 if (field == "tel") {356 if (field == "tel") {
329 Q_FOREACH(const QContactPhoneNumber phoneNumber, contact.details(QContactDetail::TypePhoneNumber)) {357 Q_FOREACH(const QContactPhoneNumber phoneNumber, contact.details(QContactDetail::TypePhoneNumber)) {
330 if (PhoneUtils::comparePhoneNumbers(phoneNumber.number(), mIdentifier) > PhoneUtils::NO_MATCH) {358 if (PhoneUtils::comparePhoneNumbers(phoneNumber.number(), mIdentifier) > PhoneUtils::NO_MATCH) {
331 mDetailProperties["type"] = (int)QContactDetail::TypePhoneNumber;359 detailProperties["type"] = (int)QContactDetail::TypePhoneNumber;
332 mDetailProperties["phoneNumberSubTypes"] = wrapIntList(phoneNumber.subTypes());360 detailProperties["phoneNumberSubTypes"] = wrapIntList(phoneNumber.subTypes());
333 mDetailProperties["phoneNumberContexts"] = wrapIntList(phoneNumber.contexts());361 detailProperties["phoneNumberContexts"] = wrapIntList(phoneNumber.contexts());
334 Q_EMIT detailPropertiesChanged();
335 break;362 break;
336 }363 }
337 }364 }
@@ -339,6 +366,7 @@
339 // FIXME: add proper support for more fields366 // FIXME: add proper support for more fields
340 }367 }
341 }368 }
369 setDetailProperties(detailProperties);
342 }370 }
343}371}
344372
@@ -351,16 +379,7 @@
351379
352 // if we got no results and we had a contact previously, we need to clear the data380 // if we got no results and we had a contact previously, we need to clear the data
353 if (request->contacts().isEmpty() && !mContactId.isNull()) {381 if (request->contacts().isEmpty() && !mContactId.isNull()) {
354 mAlias.clear();382 clear();
355 mContactId = QContactId();
356 mAvatar.clear();
357 mDetailProperties.clear();
358
359 Q_EMIT contactIdChanged();
360 Q_EMIT avatarChanged();
361 Q_EMIT aliasChanged();
362 Q_EMIT detailPropertiesChanged();
363 Q_EMIT isUnknownChanged();
364 }383 }
365 }384 }
366}385}
367386
=== modified file 'Ubuntu/Telephony/contactwatcher.h'
--- Ubuntu/Telephony/contactwatcher.h 2015-07-31 22:05:04 +0000
+++ Ubuntu/Telephony/contactwatcher.h 2015-10-13 19:29:58 +0000
@@ -36,14 +36,14 @@
36 Q_OBJECT36 Q_OBJECT
37 Q_INTERFACES(QQmlParserStatus)37 Q_INTERFACES(QQmlParserStatus)
3838
39 Q_PROPERTY(QString contactId READ contactId NOTIFY contactIdChanged)39 Q_PROPERTY(QString contactId READ contactId WRITE setContactId NOTIFY contactIdChanged)
40 Q_PROPERTY(QString avatar READ avatar NOTIFY avatarChanged)40 Q_PROPERTY(QString avatar READ avatar WRITE setAvatar NOTIFY avatarChanged)
41 Q_PROPERTY(QString alias READ alias NOTIFY aliasChanged)41 Q_PROPERTY(QString alias READ alias WRITE setAlias NOTIFY aliasChanged)
42 Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged)42 Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged)
43 Q_PROPERTY(QString phoneNumber READ identifier WRITE setIdentifier NOTIFY identifierChanged)43 Q_PROPERTY(QString phoneNumber READ identifier WRITE setIdentifier NOTIFY identifierChanged)
44 // The details property changes according to the detail type.44 // The details property changes according to the detail type.
45 // One property is always present on the map though, the "detailType" property.45 // One property is always present on the map though, the "detailType" property.
46 Q_PROPERTY(QVariantMap detailProperties READ detailProperties NOTIFY detailPropertiesChanged)46 Q_PROPERTY(QVariantMap detailProperties READ detailProperties WRITE setDetailProperties NOTIFY detailPropertiesChanged)
47 Q_PROPERTY(bool isUnknown READ isUnknown NOTIFY isUnknownChanged)47 Q_PROPERTY(bool isUnknown READ isUnknown NOTIFY isUnknownChanged)
48 Q_PROPERTY(bool interactive READ interactive NOTIFY interactiveChanged)48 Q_PROPERTY(bool interactive READ interactive NOTIFY interactiveChanged)
49 Q_PROPERTY(QStringList addressableFields READ addressableFields WRITE setAddressableFields NOTIFY addressableFieldsChanged)49 Q_PROPERTY(QStringList addressableFields READ addressableFields WRITE setAddressableFields NOTIFY addressableFieldsChanged)
@@ -53,11 +53,15 @@
53 ~ContactWatcher();53 ~ContactWatcher();
5454
55 QString contactId() const;55 QString contactId() const;
56 void setContactId(const QString &id);
56 QString avatar() const;57 QString avatar() const;
58 void setAvatar(const QString &avatar);
57 QString alias() const;59 QString alias() const;
60 void setAlias(const QString &alias);
58 QString identifier() const;61 QString identifier() const;
59 void setIdentifier(const QString &identifier);62 void setIdentifier(const QString &identifier);
60 QVariantMap detailProperties() const;63 QVariantMap detailProperties() const;
64 void setDetailProperties(const QVariantMap &properties);
61 bool isUnknown() const;65 bool isUnknown() const;
62 bool interactive() const;66 bool interactive() const;
6367
@@ -91,9 +95,11 @@
9195
92private:96private:
93 void startSearching();97 void startSearching();
98 void clear();
99 void updateAlias();
94100
95 QContactFetchRequest *mRequest;101 QContactFetchRequest *mRequest;
96 QContactId mContactId;102 QString mContactId;
97 QString mAvatar;103 QString mAvatar;
98 QString mAlias;104 QString mAlias;
99 QString mIdentifier;105 QString mIdentifier;

Subscribers

People subscribed via source and target branches