Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Latest commit

 

History

History
3444 lines (2892 loc) · 123 KB

seasidecache.cpp

File metadata and controls

3444 lines (2892 loc) · 123 KB
 
Jul 16, 2013
Jul 16, 2013
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Copyright (C) 2013 Jolla Mobile <andrew.den.exter@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#include "seasidecache.h"
#include "synchronizelists.h"
Mar 8, 2019
Mar 8, 2019
36
#include <qtcontacts-extensions.h>
Dec 10, 2013
Dec 10, 2013
37
38
39
40
41
#include <qtcontacts-extensions_impl.h>
#include <qcontactstatusflags_impl.h>
#include <contactmanagerengine.h>
#include <private/qcontactmanager_p.h>
Jul 30, 2013
Jul 30, 2013
42
Jul 16, 2013
Jul 16, 2013
43
44
#include <QCoreApplication>
#include <QStandardPaths>
Dec 10, 2013
Dec 10, 2013
45
#include <QDBusConnection>
Jul 16, 2013
Jul 16, 2013
46
47
48
49
50
51
52
53
54
#include <QDir>
#include <QEvent>
#include <QFile>
#include <QContactAvatar>
#include <QContactDetailFilter>
#include <QContactDisplayLabel>
#include <QContactEmailAddress>
#include <QContactFavorite>
Aug 5, 2013
Aug 5, 2013
55
#include <QContactGender>
Jul 16, 2013
Jul 16, 2013
56
57
58
59
60
61
62
#include <QContactName>
#include <QContactNickname>
#include <QContactOnlineAccount>
#include <QContactOrganization>
#include <QContactPhoneNumber>
#include <QContactGlobalPresence>
#include <QContactSyncTarget>
Jan 9, 2014
Jan 9, 2014
63
#include <QContactTimestamp>
Jul 16, 2013
Jul 16, 2013
64
65
66
67
68
69
70
71
#include <QVersitContactExporter>
#include <QVersitContactImporter>
#include <QVersitReader>
#include <QVersitWriter>
#include <QtDebug>
Sep 6, 2013
Sep 6, 2013
72
73
#include <mlocale.h>
Dec 10, 2013
Dec 10, 2013
74
75
#include <mce/dbus-names.h>
#include <mce/mode-names.h>
Feb 4, 2020
Feb 4, 2020
76
#include <phonenumbers/phonenumberutil.h>
Dec 10, 2013
Dec 10, 2013
77
Aug 6, 2013
Aug 6, 2013
78
QTVERSIT_USE_NAMESPACE
Jul 16, 2013
Jul 16, 2013
79
Aug 5, 2013
Aug 5, 2013
80
namespace {
Jul 16, 2013
Jul 16, 2013
81
May 27, 2014
May 27, 2014
82
83
Q_GLOBAL_STATIC(CacheConfiguration, cacheConfig)
Sep 6, 2013
Sep 6, 2013
84
85
ML10N::MLocale mLocale;
Jan 28, 2014
Jan 28, 2014
86
const QString aggregateRelationshipType = QContactRelationship::Aggregates();
Jul 31, 2014
Jul 31, 2014
87
const QString isNotRelationshipType = QString::fromLatin1("IsNot");
Jul 16, 2013
Jul 16, 2013
88
Aug 5, 2013
Aug 5, 2013
89
90
const QString syncTargetLocal = QLatin1String("local");
const QString syncTargetWasLocal = QLatin1String("was_local");
Jul 16, 2013
Jul 16, 2013
91
Mar 5, 2015
Mar 5, 2015
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Find the script that all letters in the name belong to, else yield Unknown
QChar::Script nameScript(const QString &name)
{
QChar::Script script(QChar::Script_Unknown);
if (!name.isEmpty()) {
QString::const_iterator it = name.begin(), end = name.end();
for ( ; it != end; ++it) {
const QChar::Category charCategory((*it).category());
if (charCategory >= QChar::Letter_Uppercase && charCategory <= QChar::Letter_Other) {
const QChar::Script charScript((*it).script());
if (script == QChar::Script_Unknown) {
script = charScript;
} else if (charScript != script) {
return QChar::Script_Unknown;
}
}
}
}
return script;
}
QChar::Script nameScript(const QString &firstName, const QString &lastName)
{
if (firstName.isEmpty()) {
return nameScript(lastName);
} else if (lastName.isEmpty()) {
return nameScript(firstName);
}
QChar::Script firstScript(nameScript(firstName));
if (firstScript != QChar::Script_Unknown) {
QChar::Script lastScript(nameScript(lastName));
if (lastScript == firstScript) {
return lastScript;
}
}
return QChar::Script_Unknown;
}
bool nameScriptImpliesFamilyFirst(const QString &firstName, const QString &lastName)
{
switch (nameScript(firstName, lastName)) {
// These scripts are used by cultures that conform to the family-name-first nameing convention:
case QChar::Script_Han:
case QChar::Script_Lao:
case QChar::Script_Hangul:
case QChar::Script_Khmer:
case QChar::Script_Mongolian:
case QChar::Script_Hiragana:
case QChar::Script_Katakana:
case QChar::Script_Bopomofo:
case QChar::Script_Yi:
return true;
default:
return false;
}
}
Aug 5, 2013
Aug 5, 2013
153
QString managerName()
Jul 16, 2013
Jul 16, 2013
154
{
Dec 10, 2013
Dec 10, 2013
155
return QString::fromLatin1("org.nemomobile.contacts.sqlite");
Jul 16, 2013
Jul 16, 2013
156
157
}
Dec 10, 2013
Dec 10, 2013
158
159
160
161
162
QMap<QString, QString> managerParameters()
{
QMap<QString, QString> rv;
// Report presence changes independently from other contact changes
rv.insert(QString::fromLatin1("mergePresenceChanges"), QString::fromLatin1("false"));
Apr 8, 2015
Apr 8, 2015
163
164
165
if (!qgetenv("LIBCONTACTS_TEST_MODE").isEmpty()) {
rv.insert(QString::fromLatin1("autoTest"), QString::fromLatin1("true"));
}
Dec 10, 2013
Dec 10, 2013
166
167
168
169
return rv;
}
Q_GLOBAL_STATIC_WITH_ARGS(QContactManager, manager, (managerName(), managerParameters()))
Oct 21, 2013
Oct 21, 2013
170
Jan 28, 2014
Jan 28, 2014
171
typedef QList<QContactDetail::DetailType> DetailList;
Aug 5, 2013
Aug 5, 2013
172
173
template<typename T>
Jan 28, 2014
Jan 28, 2014
174
QContactDetail::DetailType detailType()
Aug 5, 2013
Aug 5, 2013
175
176
177
178
{
return T::Type;
}
Jan 28, 2014
Jan 28, 2014
179
QContactDetail::DetailType detailType(const QContactDetail &detail)
Aug 5, 2013
Aug 5, 2013
180
181
182
183
{
return detail.type();
}
Jul 16, 2013
Jul 16, 2013
184
185
186
187
188
189
template<typename T, typename Filter, typename Field>
void setDetailType(Filter &filter, Field field)
{
filter.setDetailType(T::Type, field);
}
Aug 5, 2013
Aug 5, 2013
190
191
192
193
194
195
196
197
198
199
DetailList detailTypesHint(const QContactFetchHint &hint)
{
return hint.detailTypesHint();
}
void setDetailTypesHint(QContactFetchHint &hint, const DetailList &types)
{
hint.setDetailTypesHint(types);
}
Aug 5, 2013
Aug 5, 2013
200
201
202
203
204
205
206
207
208
209
210
211
QContactFetchHint basicFetchHint()
{
QContactFetchHint fetchHint;
// We generally have no use for these things:
fetchHint.setOptimizationHints(QContactFetchHint::NoRelationships |
QContactFetchHint::NoActionPreferences |
QContactFetchHint::NoBinaryBlobs);
return fetchHint;
}
Dec 10, 2013
Dec 10, 2013
212
213
214
215
216
QContactFetchHint presenceFetchHint()
{
QContactFetchHint fetchHint(basicFetchHint());
setDetailTypesHint(fetchHint, DetailList() << detailType<QContactPresence>()
Jun 19, 2014
Jun 19, 2014
217
218
<< detailType<QContactGlobalPresence>()
<< detailType<QContactOnlineAccount>());
Dec 10, 2013
Dec 10, 2013
219
220
221
222
return fetchHint;
}
Jan 9, 2014
Jan 9, 2014
223
DetailList contactsTableDetails()
Aug 5, 2013
Aug 5, 2013
224
225
{
DetailList types;
Jan 9, 2014
Jan 9, 2014
226
227
// These details are reported in every query
Aug 5, 2013
Aug 5, 2013
228
229
230
231
types << detailType<QContactSyncTarget>() <<
detailType<QContactName>() <<
detailType<QContactDisplayLabel>() <<
detailType<QContactFavorite>() <<
Jan 9, 2014
Jan 9, 2014
232
detailType<QContactTimestamp>() <<
Aug 5, 2013
Aug 5, 2013
233
234
235
detailType<QContactGender>() <<
detailType<QContactStatusFlags>();
Jan 9, 2014
Jan 9, 2014
236
237
238
239
240
241
242
243
244
245
return types;
}
QContactFetchHint metadataFetchHint(quint32 fetchTypes = 0)
{
QContactFetchHint fetchHint(basicFetchHint());
// Include all detail types which come from the main contacts table
DetailList types(contactsTableDetails());
Jan 9, 2014
Jan 9, 2014
246
247
248
// Include nickname, as some contacts have no other name
types << detailType<QContactNickname>();
Aug 5, 2013
Aug 5, 2013
249
250
251
252
253
254
255
256
257
if (fetchTypes & SeasideCache::FetchAccountUri) {
types << detailType<QContactOnlineAccount>();
}
if (fetchTypes & SeasideCache::FetchPhoneNumber) {
types << detailType<QContactPhoneNumber>();
}
if (fetchTypes & SeasideCache::FetchEmailAddress) {
types << detailType<QContactEmailAddress>();
}
Jan 9, 2014
Jan 9, 2014
258
259
260
if (fetchTypes & SeasideCache::FetchOrganization) {
types << detailType<QContactOrganization>();
}
Sep 9, 2020
Sep 9, 2020
261
262
263
if (fetchTypes & SeasideCache::FetchAvatar) {
types << detailType<QContactAvatar>();
}
Aug 5, 2013
Aug 5, 2013
264
Aug 5, 2013
Aug 5, 2013
265
setDetailTypesHint(fetchHint, types);
Aug 5, 2013
Aug 5, 2013
266
267
268
269
270
271
272
273
return fetchHint;
}
QContactFetchHint onlineFetchHint(quint32 fetchTypes = 0)
{
QContactFetchHint fetchHint(metadataFetchHint(fetchTypes));
// We also need global presence state
Aug 5, 2013
Aug 5, 2013
274
setDetailTypesHint(fetchHint, detailTypesHint(fetchHint) << detailType<QContactGlobalPresence>());
Aug 5, 2013
Aug 5, 2013
275
276
277
278
279
280
281
282
return fetchHint;
}
QContactFetchHint favoriteFetchHint(quint32 fetchTypes = 0)
{
QContactFetchHint fetchHint(onlineFetchHint(fetchTypes));
// We also need avatar info
Aug 5, 2013
Aug 5, 2013
283
setDetailTypesHint(fetchHint, detailTypesHint(fetchHint) << detailType<QContactAvatar>());
Aug 5, 2013
Aug 5, 2013
284
285
286
return fetchHint;
}
Jan 9, 2014
Jan 9, 2014
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
QContactFetchHint extendedMetadataFetchHint(quint32 fetchTypes)
{
QContactFetchHint fetchHint(basicFetchHint());
DetailList types;
// Only query for the specific types we need
if (fetchTypes & SeasideCache::FetchAccountUri) {
types << detailType<QContactOnlineAccount>();
}
if (fetchTypes & SeasideCache::FetchPhoneNumber) {
types << detailType<QContactPhoneNumber>();
}
if (fetchTypes & SeasideCache::FetchEmailAddress) {
types << detailType<QContactEmailAddress>();
}
if (fetchTypes & SeasideCache::FetchOrganization) {
types << detailType<QContactOrganization>();
}
Sep 9, 2020
Sep 9, 2020
306
307
308
if (fetchTypes & SeasideCache::FetchAvatar) {
types << detailType<QContactAvatar>();
}
Jan 9, 2014
Jan 9, 2014
309
310
311
312
313
setDetailTypesHint(fetchHint, types);
return fetchHint;
}
Aug 5, 2013
Aug 5, 2013
314
315
316
317
318
319
320
321
322
323
324
325
QContactFilter allFilter()
{
return QContactFilter();
}
QContactFilter favoriteFilter()
{
return QContactFavorite::match();
}
QContactFilter onlineFilter()
{
Aug 6, 2013
Aug 6, 2013
326
return QContactStatusFlags::matchFlag(QContactStatusFlags::IsOnline);
Aug 5, 2013
Aug 5, 2013
327
328
329
330
}
QContactFilter aggregateFilter()
{
Sep 2, 2013
Sep 2, 2013
331
332
static const QString aggregate(QString::fromLatin1("aggregate"));
Aug 5, 2013
Aug 5, 2013
333
334
QContactDetailFilter filter;
setDetailType<QContactSyncTarget>(filter, QContactSyncTarget::FieldSyncTarget);
Sep 2, 2013
Sep 2, 2013
335
filter.setValue(aggregate);
Aug 5, 2013
Aug 5, 2013
336
337
338
339
return filter;
}
Aug 30, 2013
Aug 30, 2013
340
341
typedef QPair<QString, QString> StringPair;
Oct 24, 2013
Oct 24, 2013
342
QList<StringPair> addressPairs(const QContactPhoneNumber &phoneNumber)
Aug 30, 2013
Aug 30, 2013
343
{
Oct 24, 2013
Oct 24, 2013
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
QList<StringPair> rv;
const QString normalized(SeasideCache::normalizePhoneNumber(phoneNumber.number()));
if (!normalized.isEmpty()) {
const QChar plus(QChar::fromLatin1('+'));
if (normalized.startsWith(plus)) {
// Also index the complete form of this number
rv.append(qMakePair(QString(), normalized));
}
// Always index the minimized form of the number
const QString minimized(SeasideCache::minimizePhoneNumber(normalized));
rv.append(qMakePair(QString(), minimized));
}
return rv;
Aug 30, 2013
Aug 30, 2013
360
361
362
363
364
365
366
367
368
}
StringPair addressPair(const QContactEmailAddress &emailAddress)
{
return qMakePair(emailAddress.emailAddress().toLower(), QString());
}
StringPair addressPair(const QContactOnlineAccount &account)
{
Oct 15, 2013
Oct 15, 2013
369
StringPair address = qMakePair(account.value<QString>(QContactOnlineAccount__FieldAccountPath), account.accountUri().toLower());
Apr 24, 2014
Apr 24, 2014
370
return !address.first.isEmpty() && !address.second.isEmpty() ? address : StringPair();
Oct 15, 2013
Oct 15, 2013
371
372
373
374
}
bool validAddressPair(const StringPair &address)
{
Apr 24, 2014
Apr 24, 2014
375
return (!address.first.isEmpty() || !address.second.isEmpty());
Aug 30, 2013
Aug 30, 2013
376
377
}
Mar 8, 2019
Mar 8, 2019
378
bool ignoreContactForDisplayLabelGroups(const QContact &contact)
Sep 2, 2013
Sep 2, 2013
379
380
381
382
383
384
385
386
387
388
389
390
391
{
static const QString aggregate(QString::fromLatin1("aggregate"));
// Don't include the self contact in name groups
if (SeasideCache::apiId(contact) == SeasideCache::selfContactId()) {
return true;
}
// Also ignore non-aggregate contacts
QContactSyncTarget syncTarget = contact.detail<QContactSyncTarget>();
return (syncTarget.syncTarget() != aggregate);
}
Jan 28, 2014
Jan 28, 2014
392
QList<quint32> internalIds(const QList<QContactId> &ids)
Sep 20, 2013
Sep 20, 2013
393
394
395
396
{
QList<quint32> rv;
rv.reserve(ids.count());
Jan 28, 2014
Jan 28, 2014
397
foreach (const QContactId &id, ids) {
Sep 20, 2013
Sep 20, 2013
398
399
400
401
402
403
rv.append(SeasideCache::internalId(id));
}
return rv;
}
Oct 24, 2013
Oct 24, 2013
404
405
406
407
408
409
410
411
412
413
414
QString::const_iterator firstDtmfChar(QString::const_iterator it, QString::const_iterator end)
{
static const QString dtmfChars(QString::fromLatin1("pPwWxX#*"));
for ( ; it != end; ++it) {
if (dtmfChars.contains(*it))
return it;
}
return end;
}
Oct 24, 2013
Oct 24, 2013
415
416
const int ExactMatch = 100;
Oct 24, 2013
Oct 24, 2013
417
418
419
420
421
422
423
424
425
426
427
428
int matchLength(const QString &lhs, const QString &rhs)
{
if (lhs.isEmpty() || rhs.isEmpty())
return 0;
QString::const_iterator lbegin = lhs.constBegin(), lend = lhs.constEnd();
QString::const_iterator rbegin = rhs.constBegin(), rend = rhs.constEnd();
// Do these numbers contain DTMF elements?
QString::const_iterator ldtmf = firstDtmfChar(lbegin, lend);
QString::const_iterator rdtmf = firstDtmfChar(rbegin, rend);
Oct 24, 2013
Oct 24, 2013
429
430
QString::const_iterator lit, rit;
bool processDtmf = false;
Oct 24, 2013
Oct 24, 2013
431
int matchLength = 0;
Oct 24, 2013
Oct 24, 2013
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
if ((ldtmf != lbegin) && (rdtmf != rbegin)) {
// Start match length calculation at the last non-DTMF digit
lit = ldtmf - 1;
rit = rdtmf - 1;
while (*lit == *rit) {
++matchLength;
--lit;
--rit;
if ((lit == lbegin) || (rit == rbegin)) {
if (*lit == *rit) {
++matchLength;
if ((lit == lbegin) && (rit == rbegin)) {
// We have a complete, exact match - this must be the best match
return ExactMatch;
} else {
// We matched all of one number - continue looking in the DTMF part
processDtmf = true;
}
Oct 24, 2013
Oct 24, 2013
454
}
Oct 24, 2013
Oct 24, 2013
455
break;
Oct 24, 2013
Oct 24, 2013
456
}
Oct 24, 2013
Oct 24, 2013
457
}
Oct 24, 2013
Oct 24, 2013
458
459
460
} else {
// Process the DTMF section for a match
processDtmf = true;
Oct 24, 2013
Oct 24, 2013
461
462
463
464
}
// Have we got a match?
if ((matchLength >= QtContactsSqliteExtensions::DefaultMaximumPhoneNumberCharacters) ||
Oct 24, 2013
Oct 24, 2013
465
processDtmf) {
Oct 24, 2013
Oct 24, 2013
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
// See if the match continues into the DTMF area
QString::const_iterator lit = ldtmf;
QString::const_iterator rit = rdtmf;
for ( ; (lit != lend) && (rit != rend); ++lit, ++rit) {
if ((*lit).toLower() != (*rit).toLower())
break;
++matchLength;
}
}
return matchLength;
}
int bestPhoneNumberMatchLength(const QContact &contact, const QString &match)
{
int bestMatchLength = 0;
foreach (const QContactPhoneNumber& phone, contact.details<QContactPhoneNumber>()) {
bestMatchLength = qMax(bestMatchLength, matchLength(SeasideCache::normalizePhoneNumber(phone.number()), match));
Oct 24, 2013
Oct 24, 2013
485
486
487
if (bestMatchLength == ExactMatch) {
return ExactMatch;
}
Oct 24, 2013
Oct 24, 2013
488
489
490
491
492
}
return bestMatchLength;
}
Aug 5, 2013
Aug 5, 2013
493
494
495
}
SeasideCache *SeasideCache::instancePtr = 0;
Mar 8, 2019
Mar 8, 2019
496
497
int SeasideCache::contactDisplayLabelGroupCount = 0;
QStringList SeasideCache::allContactDisplayLabelGroups = QStringList();
Oct 10, 2016
Oct 10, 2016
498
499
QTranslator *SeasideCache::engEnTranslator = 0;
QTranslator *SeasideCache::translator = 0;
Aug 5, 2013
Aug 5, 2013
500
Oct 21, 2013
Oct 21, 2013
501
502
503
504
505
QContactManager* SeasideCache::manager()
{
return ::manager();
}
Jul 16, 2013
Jul 16, 2013
506
507
SeasideCache* SeasideCache::instance()
{
Mar 20, 2016
Mar 20, 2016
508
509
510
if (!instancePtr) {
instancePtr = new SeasideCache;
}
Jul 16, 2013
Jul 16, 2013
511
512
513
return instancePtr;
}
Jan 28, 2014
Jan 28, 2014
514
QContactId SeasideCache::apiId(const QContact &contact)
Jul 16, 2013
Jul 16, 2013
515
516
517
518
{
return contact.id();
}
Jan 28, 2014
Jan 28, 2014
519
QContactId SeasideCache::apiId(quint32 iid)
Jul 16, 2013
Jul 16, 2013
520
521
522
523
{
return QtContactsSqliteExtensions::apiContactId(iid);
}
Jan 28, 2014
Jan 28, 2014
524
bool SeasideCache::validId(const QContactId &id)
Jul 16, 2013
Jul 16, 2013
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
{
return !id.isNull();
}
quint32 SeasideCache::internalId(const QContact &contact)
{
return internalId(contact.id());
}
quint32 SeasideCache::internalId(const QContactId &id)
{
return QtContactsSqliteExtensions::internalContactId(id);
}
SeasideCache::SeasideCache()
Oct 21, 2013
Oct 21, 2013
540
: m_syncFilter(FilterNone)
Jul 16, 2013
Jul 16, 2013
541
542
543
, m_populated(0)
, m_cacheIndex(0)
, m_queryIndex(0)
Sep 19, 2013
Sep 19, 2013
544
545
, m_fetchProcessedCount(0)
, m_fetchByIdProcessedCount(0)
Jul 16, 2013
Jul 16, 2013
546
, m_keepPopulated(false)
Aug 5, 2013
Aug 5, 2013
547
, m_populateProgress(Unpopulated)
Oct 15, 2014
Oct 15, 2014
548
, m_populating(0)
Aug 5, 2013
Aug 5, 2013
549
, m_fetchTypes(0)
Jan 9, 2014
Jan 9, 2014
550
551
, m_extraFetchTypes(0)
, m_dataTypesFetched(0)
Jul 16, 2013
Jul 16, 2013
552
553
554
, m_updatesPending(false)
, m_refreshRequired(false)
, m_contactsUpdated(false)
Dec 10, 2013
Dec 10, 2013
555
, m_displayOff(false)
Jul 16, 2013
Jul 16, 2013
556
557
{
m_timer.start();
Jul 26, 2013
Jul 26, 2013
558
m_fetchPostponed.invalidate();
Jul 16, 2013
Jul 16, 2013
559
May 27, 2014
May 27, 2014
560
561
562
563
CacheConfiguration *config(cacheConfig());
connect(config, SIGNAL(displayLabelOrderChanged(CacheConfiguration::DisplayLabelOrder)),
this, SLOT(displayLabelOrderChanged(CacheConfiguration::DisplayLabelOrder)));
connect(config, SIGNAL(sortPropertyChanged(QString)), this, SLOT(sortPropertyChanged(QString)));
Jul 16, 2013
Jul 16, 2013
564
Aug 19, 2015
Aug 19, 2015
565
566
567
568
569
570
571
// Is this a GUI application? If so, we want to defer some processing when the display is off
if (qApp && qApp->property("applicationDisplayName").isValid()) {
// Only QGuiApplication has this property
if (!QDBusConnection::systemBus().connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
MCE_DISPLAY_SIG, this, SLOT(displayStatusChanged(QString)))) {
qWarning() << "Unable to connect to MCE displayStatusChanged signal";
}
Dec 10, 2013
Dec 10, 2013
572
573
}
Oct 21, 2013
Oct 21, 2013
574
575
QContactManager *mgr(manager());
Dec 10, 2013
Dec 10, 2013
576
577
578
579
// The contactsPresenceChanged signal is not exported by QContactManager, so we
// need to find it from the manager's engine object
typedef QtContactsSqliteExtensions::ContactManagerEngine EngineType;
EngineType *cme = dynamic_cast<EngineType *>(QContactManagerData::managerData(mgr)->m_engine);
Jun 24, 2020
Jun 24, 2020
580
581
582
583
584
585
586
587
588
if (cme) {
connect(cme, SIGNAL(displayLabelGroupsChanged(QStringList)),
this, SLOT(displayLabelGroupsChanged(QStringList)));
displayLabelGroupsChanged(cme->displayLabelGroups());
connect(cme, SIGNAL(contactsPresenceChanged(QList<QContactId>)),
this, SLOT(contactsPresenceChanged(QList<QContactId>)));
} else {
qWarning() << "Unable to retrieve contact manager engine";
}
Dec 10, 2013
Dec 10, 2013
589
Apr 17, 2019
Apr 17, 2019
590
connect(mgr, SIGNAL(dataChanged()), this, SLOT(dataChanged()));
Oct 21, 2013
Oct 21, 2013
591
connect(mgr, SIGNAL(contactsAdded(QList<QContactId>)),
Jul 16, 2013
Jul 16, 2013
592
this, SLOT(contactsAdded(QList<QContactId>)));
Oct 21, 2013
Oct 21, 2013
593
connect(mgr, SIGNAL(contactsChanged(QList<QContactId>)),
Jul 16, 2013
Jul 16, 2013
594
this, SLOT(contactsChanged(QList<QContactId>)));
Oct 21, 2013
Oct 21, 2013
595
connect(mgr, SIGNAL(contactsRemoved(QList<QContactId>)),
Jul 16, 2013
Jul 16, 2013
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
this, SLOT(contactsRemoved(QList<QContactId>)));
connect(&m_fetchRequest, SIGNAL(resultsAvailable()), this, SLOT(contactsAvailable()));
connect(&m_fetchByIdRequest, SIGNAL(resultsAvailable()), this, SLOT(contactsAvailable()));
connect(&m_contactIdRequest, SIGNAL(resultsAvailable()), this, SLOT(contactIdsAvailable()));
connect(&m_relationshipsFetchRequest, SIGNAL(resultsAvailable()), this, SLOT(relationshipsAvailable()));
connect(&m_fetchRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
this, SLOT(requestStateChanged(QContactAbstractRequest::State)));
connect(&m_fetchByIdRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
this, SLOT(requestStateChanged(QContactAbstractRequest::State)));
connect(&m_contactIdRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
this, SLOT(requestStateChanged(QContactAbstractRequest::State)));
connect(&m_relationshipsFetchRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
this, SLOT(requestStateChanged(QContactAbstractRequest::State)));
connect(&m_removeRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
this, SLOT(requestStateChanged(QContactAbstractRequest::State)));
connect(&m_saveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
this, SLOT(requestStateChanged(QContactAbstractRequest::State)));
connect(&m_relationshipSaveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
this, SLOT(requestStateChanged(QContactAbstractRequest::State)));
connect(&m_relationshipRemoveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
this, SLOT(requestStateChanged(QContactAbstractRequest::State)));
Oct 21, 2013
Oct 21, 2013
620
621
622
623
624
625
626
627
m_fetchRequest.setManager(mgr);
m_fetchByIdRequest.setManager(mgr);
m_contactIdRequest.setManager(mgr);
m_relationshipsFetchRequest.setManager(mgr);
m_removeRequest.setManager(mgr);
m_saveRequest.setManager(mgr);
m_relationshipSaveRequest.setManager(mgr);
m_relationshipRemoveRequest.setManager(mgr);
Jul 16, 2013
Jul 16, 2013
628
May 27, 2014
May 27, 2014
629
setSortOrder(sortProperty());
Jul 16, 2013
Jul 16, 2013
630
631
632
633
634
635
636
637
638
639
}
SeasideCache::~SeasideCache()
{
if (instancePtr == this)
instancePtr = 0;
}
void SeasideCache::checkForExpiry()
{
Aug 26, 2015
Aug 26, 2015
640
if (instancePtr->m_users.isEmpty() && !QCoreApplication::closingDown()) {
Jul 16, 2013
Jul 16, 2013
641
642
643
644
645
646
647
648
649
650
bool unused = true;
for (int i = 0; i < FilterTypesCount; ++i) {
unused &= instancePtr->m_models[i].isEmpty();
}
if (unused) {
instancePtr->m_expiryTimer.start(30000, instancePtr);
}
}
}
Jan 9, 2014
Jan 9, 2014
651
void SeasideCache::registerModel(ListModel *model, FilterType type, FetchDataType requiredTypes, FetchDataType extraTypes)
Jul 16, 2013
Jul 16, 2013
652
{
Mar 20, 2016
Mar 20, 2016
653
654
655
656
657
658
// Ensure the cache has been instantiated
instance();
instancePtr->m_expiryTimer.stop();
for (int i = 0; i < FilterTypesCount; ++i)
instancePtr->m_models[i].removeAll(model);
Aug 5, 2013
Aug 5, 2013
659
Jul 16, 2013
Jul 16, 2013
660
instancePtr->m_models[type].append(model);
Jan 9, 2014
Jan 9, 2014
661
662
663
664
665
666
instancePtr->keepPopulated(requiredTypes & SeasideCache::FetchTypesMask, extraTypes & SeasideCache::FetchTypesMask);
if (requiredTypes & SeasideCache::FetchTypesMask) {
// If we have filtered models, they will need a contact ID refresh after the cache is populated
instancePtr->m_refreshRequired = true;
}
Jul 16, 2013
Jul 16, 2013
667
668
669
670
671
672
673
674
675
676
677
678
}
void SeasideCache::unregisterModel(ListModel *model)
{
for (int i = 0; i < FilterTypesCount; ++i)
instancePtr->m_models[i].removeAll(model);
checkForExpiry();
}
void SeasideCache::registerUser(QObject *user)
{
Mar 20, 2016
Mar 20, 2016
679
680
681
682
// Ensure the cache has been instantiated
instance();
instancePtr->m_expiryTimer.stop();
Jul 16, 2013
Jul 16, 2013
683
684
685
686
687
688
689
690
691
692
instancePtr->m_users.insert(user);
}
void SeasideCache::unregisterUser(QObject *user)
{
instancePtr->m_users.remove(user);
checkForExpiry();
}
Mar 8, 2019
Mar 8, 2019
693
void SeasideCache::registerDisplayLabelGroupChangeListener(SeasideDisplayLabelGroupChangeListener *listener)
Jul 16, 2013
Jul 16, 2013
694
{
Mar 20, 2016
Mar 20, 2016
695
696
697
// Ensure the cache has been instantiated
instance();
Mar 8, 2019
Mar 8, 2019
698
instancePtr->m_displayLabelGroupChangeListeners.append(listener);
Jul 16, 2013
Jul 16, 2013
699
700
}
Mar 8, 2019
Mar 8, 2019
701
void SeasideCache::unregisterDisplayLabelGroupChangeListener(SeasideDisplayLabelGroupChangeListener *listener)
Jul 16, 2013
Jul 16, 2013
702
703
704
{
if (!instancePtr)
return;
Mar 8, 2019
Mar 8, 2019
705
instancePtr->m_displayLabelGroupChangeListeners.removeAll(listener);
Jul 16, 2013
Jul 16, 2013
706
707
}
Aug 6, 2013
Aug 6, 2013
708
709
void SeasideCache::registerChangeListener(ChangeListener *listener)
{
Mar 20, 2016
Mar 20, 2016
710
711
712
// Ensure the cache has been instantiated
instance();
Aug 6, 2013
Aug 6, 2013
713
714
715
instancePtr->m_changeListeners.append(listener);
}
Sep 9, 2020
Sep 9, 2020
716
717
718
719
720
721
722
723
724
void SeasideCache::registerChangeListener(ChangeListener *listener, FetchDataType requiredTypes, FetchDataType extraTypes)
{
// Ensure the cache has been instantiated
instance();
instancePtr->m_changeListeners.append(listener);
instancePtr->keepPopulated(requiredTypes, extraTypes);
}
Aug 6, 2013
Aug 6, 2013
725
726
727
728
729
730
731
732
733
734
735
736
void SeasideCache::unregisterChangeListener(ChangeListener *listener)
{
if (!instancePtr)
return;
instancePtr->m_changeListeners.removeAll(listener);
}
void SeasideCache::unregisterResolveListener(ResolveListener *listener)
{
if (!instancePtr)
return;
Oct 21, 2014
Oct 21, 2014
737
QHash<QContactFetchRequest *, ResolveData>::iterator it = instancePtr->m_resolveAddresses.begin();
Aug 30, 2013
Aug 30, 2013
738
while (it != instancePtr->m_resolveAddresses.end()) {
Oct 21, 2014
Oct 21, 2014
739
740
741
if (it.value().listener == listener) {
it.key()->cancel();
delete it.key();
Aug 6, 2013
Aug 6, 2013
742
743
744
745
746
it = instancePtr->m_resolveAddresses.erase(it);
} else {
++it;
}
}
Aug 30, 2013
Aug 30, 2013
747
Oct 21, 2014
Oct 21, 2014
748
749
750
751
QList<ResolveData>::iterator it2 = instancePtr->m_unknownAddresses.begin();
while (it2 != instancePtr->m_unknownAddresses.end()) {
if (it2->listener == listener) {
it2 = instancePtr->m_unknownAddresses.erase(it2);
Aug 30, 2013
Aug 30, 2013
752
} else {
Oct 21, 2014
Oct 21, 2014
753
++it2;
Aug 30, 2013
Aug 30, 2013
754
755
}
}
Feb 4, 2015
Feb 4, 2015
756
757
758
759
760
761
762
763
764
QList<ResolveData>::iterator it3 = instancePtr->m_unknownResolveAddresses.begin();
while (it3 != instancePtr->m_unknownResolveAddresses.end()) {
if (it3->listener == listener) {
it3 = instancePtr->m_unknownResolveAddresses.erase(it3);
} else {
++it3;
}
}
Feb 12, 2015
Feb 12, 2015
765
766
767
768
769
770
771
772
773
QSet<ResolveData>::iterator it4 = instancePtr->m_pendingResolve.begin();
while (it4 != instancePtr->m_pendingResolve.end()) {
if (it4->listener == listener) {
it4 = instancePtr->m_pendingResolve.erase(it4);
} else {
++it4;
}
}
Aug 6, 2013
Aug 6, 2013
774
775
}
Mar 8, 2019
Mar 8, 2019
776
QString SeasideCache::displayLabelGroup(const CacheItem *cacheItem)
Jul 16, 2013
Jul 16, 2013
777
778
{
if (!cacheItem)
Sep 6, 2013
Sep 6, 2013
779
return QString();
Jul 16, 2013
Jul 16, 2013
780
Mar 8, 2019
Mar 8, 2019
781
return cacheItem->displayLabelGroup;
Aug 16, 2013
Aug 16, 2013
782
783
}
Mar 8, 2019
Mar 8, 2019
784
QStringList SeasideCache::allDisplayLabelGroups()
Jul 16, 2013
Jul 16, 2013
785
{
Mar 20, 2016
Mar 20, 2016
786
787
788
// Ensure the cache has been instantiated
instance();
Mar 8, 2019
Mar 8, 2019
789
return allContactDisplayLabelGroups;
Jul 16, 2013
Jul 16, 2013
790
791
}
Mar 8, 2019
Mar 8, 2019
792
QHash<QString, QSet<quint32> > SeasideCache::displayLabelGroupMembers()
Jul 16, 2013
Jul 16, 2013
793
794
{
if (instancePtr)
Mar 8, 2019
Mar 8, 2019
795
return instancePtr->m_contactDisplayLabelGroups;
Sep 6, 2013
Sep 6, 2013
796
return QHash<QString, QSet<quint32> >();
Jul 16, 2013
Jul 16, 2013
797
798
799
800
}
SeasideCache::DisplayLabelOrder SeasideCache::displayLabelOrder()
{
May 27, 2014
May 27, 2014
801
return static_cast<DisplayLabelOrder>(cacheConfig()->displayLabelOrder());
Jul 16, 2013
Jul 16, 2013
802
803
}
Aug 29, 2013
Aug 29, 2013
804
805
QString SeasideCache::sortProperty()
{
May 27, 2014
May 27, 2014
806
return cacheConfig()->sortProperty();
Aug 29, 2013
Aug 29, 2013
807
808
}
Aug 30, 2013
Aug 30, 2013
809
810
QString SeasideCache::groupProperty()
{
May 27, 2014
May 27, 2014
811
return cacheConfig()->groupProperty();
Aug 30, 2013
Aug 30, 2013
812
813
}
Jul 16, 2013
Jul 16, 2013
814
815
816
817
818
819
int SeasideCache::contactId(const QContact &contact)
{
quint32 internal = internalId(contact);
return static_cast<int>(internal);
}
Jan 28, 2014
Jan 28, 2014
820
SeasideCache::CacheItem *SeasideCache::itemById(const QContactId &id, bool requireComplete)
Jul 16, 2013
Jul 16, 2013
821
822
823
824
825
826
827
828
829
830
831
832
833
834
{
if (!validId(id))
return 0;
quint32 iid = internalId(id);
CacheItem *item = 0;
QHash<quint32, CacheItem>::iterator it = instancePtr->m_people.find(iid);
if (it != instancePtr->m_people.end()) {
item = &(*it);
} else {
// Insert a new item into the cache if the one doesn't exist.
item = &(instancePtr->m_people[iid]);
Oct 2, 2013
Oct 2, 2013
835
836
837
item->iid = iid;
item->contactState = ContactAbsent;
Jul 16, 2013
Jul 16, 2013
838
839
840
item->contact.setId(id);
}
Aug 5, 2013
Aug 5, 2013
841
842
if (requireComplete) {
ensureCompletion(item);
Jul 16, 2013
Jul 16, 2013
843
844
845
846
}
return item;
}
Aug 5, 2013
Aug 5, 2013
847
SeasideCache::CacheItem *SeasideCache::itemById(int id, bool requireComplete)
Jul 16, 2013
Jul 16, 2013
848
849
850
851
{
if (id != 0) {
QContactId contactId(apiId(static_cast<quint32>(id)));
if (!contactId.isNull()) {
Aug 5, 2013
Aug 5, 2013
852
return itemById(contactId, requireComplete);
Jul 16, 2013
Jul 16, 2013
853
854
855
856
857
858
}
}
return 0;
}
Jan 28, 2014
Jan 28, 2014
859
SeasideCache::CacheItem *SeasideCache::existingItem(const QContactId &id)
Jul 16, 2013
Jul 16, 2013
860
{
Jul 29, 2013
Jul 29, 2013
861
862
return existingItem(internalId(id));
}
Jul 16, 2013
Jul 16, 2013
863
Jul 29, 2013
Jul 29, 2013
864
865
SeasideCache::CacheItem *SeasideCache::existingItem(quint32 iid)
{
Jul 16, 2013
Jul 16, 2013
866
867
868
869
870
871
QHash<quint32, CacheItem>::iterator it = instancePtr->m_people.find(iid);
return it != instancePtr->m_people.end()
? &(*it)
: 0;
}
Jan 28, 2014
Jan 28, 2014
872
QContact SeasideCache::contactById(const QContactId &id)
Jul 16, 2013
Jul 16, 2013
873
874
875
876
877
{
quint32 iid = internalId(id);
return instancePtr->m_people.value(iid, CacheItem()).contact;
}
Aug 5, 2013
Aug 5, 2013
878
void SeasideCache::ensureCompletion(CacheItem *cacheItem)
Jul 16, 2013
Jul 16, 2013
879
{
Aug 5, 2013
Aug 5, 2013
880
if (cacheItem->contactState < ContactRequested) {
Aug 19, 2013
Aug 19, 2013
881
refreshContact(cacheItem);
Aug 5, 2013
Aug 5, 2013
882
883
884
}
}
Aug 19, 2013
Aug 19, 2013
885
886
887
888
889
890
891
void SeasideCache::refreshContact(CacheItem *cacheItem)
{
cacheItem->contactState = ContactRequested;
instancePtr->m_changedContacts.append(cacheItem->apiId());
instancePtr->fetchContacts();
}
Aug 5, 2013
Aug 5, 2013
892
893
SeasideCache::CacheItem *SeasideCache::itemByPhoneNumber(const QString &number, bool requireComplete)
{
Oct 24, 2013
Oct 24, 2013
894
895
896
const QString normalized(normalizePhoneNumber(number));
if (normalized.isEmpty())
return 0;
Oct 24, 2013
Oct 24, 2013
897
Oct 24, 2013
Oct 24, 2013
898
899
900
901
902
const QChar plus(QChar::fromLatin1('+'));
if (normalized.startsWith(plus)) {
// See if there is a match for the complete form of this number
if (CacheItem *item = instancePtr->itemMatchingPhoneNumber(normalized, normalized, requireComplete)) {
return item;
Oct 24, 2013
Oct 24, 2013
903
904
}
}
Aug 5, 2013
Aug 5, 2013
905
Oct 24, 2013
Oct 24, 2013
906
907
908
909
910
911
912
913
914
const QString minimized(minimizePhoneNumber(normalized));
if (((instancePtr->m_fetchTypes & SeasideCache::FetchPhoneNumber) == 0) &&
!instancePtr->m_resolvedPhoneNumbers.contains(minimized)) {
// We haven't previously queried this number, so there may be more matches than any
// that we already have cached; return 0 to force a query
return 0;
}
return instancePtr->itemMatchingPhoneNumber(minimized, normalized, requireComplete);
Jul 16, 2013
Jul 16, 2013
915
916
}
Aug 5, 2013
Aug 5, 2013
917
SeasideCache::CacheItem *SeasideCache::itemByEmailAddress(const QString &email, bool requireComplete)
Jul 16, 2013
Jul 16, 2013
918
{
Apr 10, 2014
Apr 10, 2014
919
920
921
if (email.trimmed().isEmpty())
return 0;
Jul 16, 2013
Jul 16, 2013
922
923
QHash<QString, quint32>::const_iterator it = instancePtr->m_emailAddressIds.find(email.toLower());
if (it != instancePtr->m_emailAddressIds.end())
Aug 5, 2013
Aug 5, 2013
924
925
return itemById(*it, requireComplete);
Jul 16, 2013
Jul 16, 2013
926
927
928
return 0;
}
Aug 5, 2013
Aug 5, 2013
929
930
SeasideCache::CacheItem *SeasideCache::itemByOnlineAccount(const QString &localUid, const QString &remoteUid, bool requireComplete)
{
Apr 10, 2014
Apr 10, 2014
931
932
933
if (localUid.trimmed().isEmpty() || remoteUid.trimmed().isEmpty())
return 0;
Aug 5, 2013
Aug 5, 2013
934
935
936
937
938
939
940
941
942
943
944
QPair<QString, QString> address = qMakePair(localUid, remoteUid.toLower());
QHash<QPair<QString, QString>, quint32>::const_iterator it = instancePtr->m_onlineAccountIds.find(address);
if (it != instancePtr->m_onlineAccountIds.end())
return itemById(*it, requireComplete);
return 0;
}
SeasideCache::CacheItem *SeasideCache::resolvePhoneNumber(ResolveListener *listener, const QString &number, bool requireComplete)
{
Mar 20, 2016
Mar 20, 2016
945
946
947
// Ensure the cache has been instantiated
instance();
Aug 5, 2013
Aug 5, 2013
948
949
CacheItem *item = itemByPhoneNumber(number, requireComplete);
if (!item) {
Aug 19, 2015
Aug 19, 2015
950
951
952
953
// Don't bother trying to resolve an invalid number
const QString normalized(normalizePhoneNumber(number));
if (!normalized.isEmpty()) {
instancePtr->resolveAddress(listener, QString(), number, requireComplete);
Aug 24, 2015
Aug 24, 2015
954
955
956
957
958
959
960
961
} else {
// Report this address is unknown
ResolveData data;
data.second = number;
data.listener = listener;
instancePtr->m_unknownResolveAddresses.append(data);
instancePtr->requestUpdate();
Aug 19, 2015
Aug 19, 2015
962
}
Aug 6, 2013
Aug 6, 2013
963
964
} else if (requireComplete) {
ensureCompletion(item);
Aug 5, 2013
Aug 5, 2013
965
966
967
968
969
970
971
}
return item;
}
SeasideCache::CacheItem *SeasideCache::resolveEmailAddress(ResolveListener *listener, const QString &address, bool requireComplete)
{
Mar 20, 2016
Mar 20, 2016
972
973
974
// Ensure the cache has been instantiated
instance();
Aug 5, 2013
Aug 5, 2013
975
976
977
CacheItem *item = itemByEmailAddress(address, requireComplete);
if (!item) {
instancePtr->resolveAddress(listener, address, QString(), requireComplete);
Aug 6, 2013
Aug 6, 2013
978
979
} else if (requireComplete) {
ensureCompletion(item);
Aug 5, 2013
Aug 5, 2013
980
981
982
983
984
985
}
return item;
}
SeasideCache::CacheItem *SeasideCache::resolveOnlineAccount(ResolveListener *listener, const QString &localUid, const QString &remoteUid, bool requireComplete)
{
Mar 20, 2016
Mar 20, 2016
986
987
988
// Ensure the cache has been instantiated
instance();
Aug 5, 2013
Aug 5, 2013
989
990
991
CacheItem *item = itemByOnlineAccount(localUid, remoteUid, requireComplete);
if (!item) {
instancePtr->resolveAddress(listener, localUid, remoteUid, requireComplete);
Aug 6, 2013
Aug 6, 2013
992
993
} else if (requireComplete) {
ensureCompletion(item);
Aug 5, 2013
Aug 5, 2013
994
995
996
997
}
return item;
}
Jan 28, 2014
Jan 28, 2014
998
QContactId SeasideCache::selfContactId()
Jul 16, 2013
Jul 16, 2013
999
{
Oct 21, 2013
Oct 21, 2013
1000
return manager()->selfContactId();