File: ContactBuilder.cpp

package info (click to toggle)
buteo-sync-plugins 0.8.36-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,068 kB
  • sloc: cpp: 8,130; xml: 755; sh: 207; perl: 82; makefile: 11
file content (86 lines) | stat: -rw-r--r-- 3,717 bytes parent folder | download | duplicates (2)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "ContactBuilder.h"

#include <QContactDetailFilter>
#include <QContactInvalidFilter>
#include <QContactSyncTarget>

#include <qtcontacts-extensions.h>
#include <qtcontacts-extensions_impl.h>
#include <QContactOriginMetadata>
#include <qcontactoriginmetadata_impl.h>

#include <seasidepropertyhandler.h>

ContactBuilder::ContactBuilder(QContactManager *mgr, const QString &syncTarget, const QString &originId, ContactBuilder::MatchFilterMode mode)
{
    QSet<QContactDetail::DetailType> ignoredDetailTypes = QSet<QContactDetail::DetailType>()
                                                          << QContactDetail::TypeGlobalPresence
                                                          << QContactDetail::TypePresence
                                                          << QContactDetail::TypeOnlineAccount
                                                          << QContactDetail::TypeVersion
                                                          << QContactDetail::TypeSyncTarget
                                                          << QContactDetail::TypeRingtone;

    d->manager = mgr;
    d->propertyHandler = new SeasidePropertyHandler(ignoredDetailTypes);
    d->unimportableDetailTypes = ignoredDetailTypes;

    d->extraData.insert("syncTarget", syncTarget);
    d->extraData.insert("originId", originId);
    d->extraData.insert("mode", static_cast<int>(mode));
}


ContactBuilder::~ContactBuilder()
{
    delete d->propertyHandler;
    d->propertyHandler = 0;
}


QContactFilter ContactBuilder::mergeSubsetFilter() const
{
    ContactBuilder::MatchFilterMode mode = static_cast<ContactBuilder::MatchFilterMode>(d->extraData.value("mode").toInt());
    if (mode == ContactBuilder::NoFilterRequiredMode) {
        // the caller already knows which id is for which contact
        // and we don't need to do any merging or matching.
        return QContactInvalidFilter();
    }

    // Import the vcard data into existing contacts. We want to do a careful merge instead of
    // overwriting existing contacts to avoid losing data about user-applied contact links.
    QString syncTarget = d->extraData.value("syncTarget").toString();
    QString originId = d->extraData.value("originId").toString();
    QContactDetailFilter syncTargetFilter;
    syncTargetFilter.setDetailType(QContactSyncTarget::Type, QContactSyncTarget::FieldSyncTarget);
    syncTargetFilter.setValue(syncTarget);
    QContactDetailFilter originIdFilter = QContactOriginMetadata::matchId(originId);

    // If the origin id is unknown, every contact is a new contact.  Otherwise, ensure we filter
    // based on the origin id as well as the synctarget, to minimise match surface to valid only.
    QContactFilter mergeMatchFilter = (originId.isEmpty() ? QContactInvalidFilter() : originIdFilter & syncTargetFilter);
    return mergeMatchFilter;
}

bool ContactBuilder::mergeLocalIntoImport(QContact &import, const QContact &local, bool *erase)
{
    // Always perform "clobber" save, never attempt to merge details.
    // This is because the "local" contact here will actually have the appropriate
    // sync target and origin Id already (due to our mergeMatchFilter() impl).
    import.setId(local.id()); // overwrite the local with the import contact.
    *erase = false; // we don't allow erasure.
    return true; // contact is modified / requires save.
}

// don't allow merging contacts in the import list.
bool ContactBuilder::mergeImportIntoImport(QContact &, QContact &, bool *erase)
{
    *erase = false;
    return false;
}

// don't allow de-duplication of contacts in the import list.
int ContactBuilder::previousDuplicateIndex(QList<QContact> &, QContact &, int)
{
    return -1;
}