Debian Codegraph @

storageplugins/hcontacts/ContactBuilder.cpp

raw
1 #include "ContactBuilder.h"
2
3 #include <QContactDetailFilter>
4 #include <QContactInvalidFilter>
5 #include <QContactSyncTarget>
6
7 #include <qtcontacts-extensions.h>
8 #include <qtcontacts-extensions_impl.h>
9 #include <QContactOriginMetadata>
10 #include <qcontactoriginmetadata_impl.h>
11
12 #include <seasidepropertyhandler.h>
13
14 ContactBuilder::ContactBuilder(QContactManager *mgr, const QString &syncTarget, const QString &originId, ContactBuilder::MatchFilterMode mode)
15 {
16 QSet<QContactDetail::DetailType> ignoredDetailTypes = QSet<QContactDetail::DetailType>()
17 << QContactDetail::TypeGlobalPresence
18 << QContactDetail::TypePresence
19 << QContactDetail::TypeOnlineAccount
20 << QContactDetail::TypeVersion
21 << QContactDetail::TypeSyncTarget
22 << QContactDetail::TypeRingtone;
23
24 d->manager = mgr;
25 d->propertyHandler = new SeasidePropertyHandler(ignoredDetailTypes);
26 d->unimportableDetailTypes = ignoredDetailTypes;
27
28 d->extraData.insert("syncTarget", syncTarget);
29 d->extraData.insert("originId", originId);
30 d->extraData.insert("mode", static_cast<int>(mode));
31 }
32
33
34 ContactBuilder::~ContactBuilder()
35 {
36 delete d->propertyHandler;
37 d->propertyHandler = 0;
38 }
39
40
41 QContactFilter ContactBuilder::mergeSubsetFilter() const
42 {
43 ContactBuilder::MatchFilterMode mode = static_cast<ContactBuilder::MatchFilterMode>(d->extraData.value("mode").toInt());
44 if (mode == ContactBuilder::NoFilterRequiredMode) {
45 // the caller already knows which id is for which contact
46 // and we don't need to do any merging or matching.
47 return QContactInvalidFilter();
48 }
49
50 // Import the vcard data into existing contacts. We want to do a careful merge instead of
51 // overwriting existing contacts to avoid losing data about user-applied contact links.
52 QString syncTarget = d->extraData.value("syncTarget").toString();
53 QString originId = d->extraData.value("originId").toString();
54 QContactDetailFilter syncTargetFilter;
55 syncTargetFilter.setDetailType(QContactSyncTarget::Type, QContactSyncTarget::FieldSyncTarget);
56 syncTargetFilter.setValue(syncTarget);
57 QContactDetailFilter originIdFilter = QContactOriginMetadata::matchId(originId);
58
59 // If the origin id is unknown, every contact is a new contact. Otherwise, ensure we filter
60 // based on the origin id as well as the synctarget, to minimise match surface to valid only.
61 QContactFilter mergeMatchFilter = (originId.isEmpty() ? QContactInvalidFilter() : originIdFilter & syncTargetFilter);
62 return mergeMatchFilter;
63 }
64
65 bool ContactBuilder::mergeLocalIntoImport(QContact &import, const QContact &local, bool *erase)
66 {
67 // Always perform "clobber" save, never attempt to merge details.
68 // This is because the "local" contact here will actually have the appropriate
69 // sync target and origin Id already (due to our mergeMatchFilter() impl).
70 import.setId(local.id()); // overwrite the local with the import contact.
71 *erase = false; // we don't allow erasure.
72 return true; // contact is modified / requires save.
73 }
74
75 // don't allow merging contacts in the import list.
76 bool ContactBuilder::mergeImportIntoImport(QContact &, QContact &, bool *erase)
77 {
78 *erase = false;
79 return false;
80 }
81
82 // don't allow de-duplication of contacts in the import list.
83 int ContactBuilder::previousDuplicateIndex(QList<QContact> &, QContact &, int)
84 {
85 return -1;
86 }