Commit 813eafc0 authored by chriadam's avatar chriadam

[libcontacts] Improve vCard contact import API

This commit improves the SeasideImport API by allowing clients to
specify their own SeasideContactBuilder implementation when
converting the list of Versit documents into storage QContacts.

The SeasideContactBuilder allows the client to parametrise things
like the contact filter used to determine the subset of mergable
contacts, the merge strategy to use, and so on.
parent 9ed3c641
This diff is collapsed.
/*
* Copyright (C) 2015 Jolla Mobile
* Contact: Chris Adams <chris.adams@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."
*/
#ifndef SEASIDECONTACTBUILDER_H
#define SEASIDECONTACTBUILDER_H
#include "contactcacheexport.h"
#include <QContact>
#include <QContactManager>
#include <QVersitDocument>
#include <QVersitContactHandler>
#include <QList>
QTCONTACTS_USE_NAMESPACE
QTVERSIT_USE_NAMESPACE
class CONTACTCACHE_EXPORT SeasideContactBuilderPrivate
{
public:
QContactManager *manager;
QVersitContactHandler *propertyHandler;
QSet<QContactDetail::DetailType> unimportableDetailTypes;
QStringList importableSyncTargets;
QHash<QString, int> importGuids;
QHash<QString, int> importNames;
QHash<QString, int> importLabels;
QHash<QString, QContactId> existingGuids;
QHash<QString, QContactId> existingNames;
QMap<QContactId, QString> existingContactNames;
QHash<QString, QContactId> existingNicknames;
QVariantMap extraData; // anything the derived type wants to store.
};
class CONTACTCACHE_EXPORT SeasideContactBuilder
{
public:
SeasideContactBuilder();
virtual ~SeasideContactBuilder();
virtual QVersitContactHandler *propertyHandler();
virtual QContactManager *manager();
virtual QContactFilter mergeSubsetFilter() const;
virtual bool mergeLocalIntoImport(QContact &import, const QContact &local, bool *erase);
virtual bool mergeImportIntoImport(QContact &import, QContact &otherImport, bool *erase);
virtual QList<QContact> importContacts(const QList<QVersitDocument> &documents);
virtual void preprocessContact(QContact &contact);
virtual int previousDuplicateIndex(QList<QContact> &importedContacts, int contactIndex);
virtual void buildLocalDeviceContactIndexes();
virtual QContactId matchingLocalContactId(QContact &contact);
protected:
SeasideContactBuilderPrivate *d;
};
#endif
This diff is collapsed.
......@@ -33,6 +33,7 @@
#define SEASIDEIMPORT_H
#include "contactcacheexport.h"
#include "seasidecontactbuilder.h"
#include <QContact>
#include <QVersitDocument>
......@@ -46,7 +47,7 @@ class CONTACTCACHE_EXPORT SeasideImport
~SeasideImport();
public:
static QList<QContact> buildImportContacts(const QList<QVersitDocument> &details, int *newCounti = 0, int *updatedCount = 0);
static QList<QContact> buildImportContacts(const QList<QVersitDocument> &details, int *newCount = 0, int *updatedCount = 0, int *ignoredCount = 0, SeasideContactBuilder *builder = 0);
};
#endif
......@@ -223,14 +223,32 @@ void processSyncTarget(const QContactSyncTarget &detail, QSet<int> * processedFi
}
}
void ignoreDetail(const QContactSyncTarget &detail, QSet<int> * processedFields, QList<QVersitProperty> * toBeRemoved, QList<QVersitProperty> * toBeAdded)
{
Q_UNUSED(detail)
Q_UNUSED(processedFields)
toBeAdded->clear();
toBeRemoved->clear();
}
}
SeasidePropertyHandler::SeasidePropertyHandler()
class SeasidePropertyHandlerPrivate
{
public:
QSet<QContactDetail::DetailType> m_nonexportableDetails;
};
SeasidePropertyHandler::SeasidePropertyHandler(const QSet<QContactDetail::DetailType> &nonexportableDetails)
: QVersitContactHandler()
, priv(new SeasidePropertyHandlerPrivate)
{
priv->m_nonexportableDetails = nonexportableDetails;
}
SeasidePropertyHandler::~SeasidePropertyHandler()
{
delete priv;
}
void SeasidePropertyHandler::documentProcessed(const QVersitDocument &, QContact *)
......@@ -252,7 +270,7 @@ void SeasidePropertyHandler::propertyProcessed(const QVersitDocument &, const QV
}
}
void SeasidePropertyHandler::contactProcessed(const QContact &c, QVersitDocument *)
void SeasidePropertyHandler::contactProcessed(const QContact &, QVersitDocument *)
{
}
......@@ -261,7 +279,9 @@ void SeasidePropertyHandler::detailProcessed(const QContact &, const QContactDet
{
const QContactDetail::DetailType detailType(detail.type());
if (detailType == QContactSyncTarget::Type) {
if (priv->m_nonexportableDetails.contains(detailType)) {
ignoreDetail(static_cast<const QContactSyncTarget &>(detail), processedFields, toBeRemoved, toBeAdded);
} else if (detailType == QContactSyncTarget::Type) {
processSyncTarget(static_cast<const QContactSyncTarget &>(detail), processedFields, toBeRemoved, toBeAdded);
}
}
......
......@@ -37,6 +37,7 @@
#include <QString>
#include <QByteArray>
#include <QVariantMap>
#include <QContact>
......@@ -62,10 +63,11 @@ QTVERSIT_USE_NAMESPACE
Also support the X-NEMOMOBILE-ONLINEACCOUNT-DEMO property
for loading demo online account data.
*/
class SeasidePropertyHandlerPrivate;
class CONTACTCACHE_EXPORT SeasidePropertyHandler : public QVersitContactHandler
{
public:
SeasidePropertyHandler();
SeasidePropertyHandler(const QSet<QContactDetail::DetailType> &nonexportableDetails = QSet<QContactDetail::DetailType>());
~SeasidePropertyHandler();
// QVersitContactImporterPropertyHandlerV2
......@@ -77,6 +79,9 @@ public:
void contactProcessed(const QContact &, QVersitDocument *);
void detailProcessed(const QContact &, const QContactDetail &detail,
const QVersitDocument &, QSet<int> * processedFields, QList<QVersitProperty> * toBeRemoved, QList<QVersitProperty> * toBeAdded);
private:
SeasidePropertyHandlerPrivate *priv;
};
#endif // PROPERTYHANDLER_H
......@@ -38,6 +38,7 @@ SOURCES += \
$$PWD/seasidecache.cpp \
$$PWD/seasideexport.cpp \
$$PWD/seasideimport.cpp \
$$PWD/seasidecontactbuilder.cpp \
$$PWD/seasidepropertyhandler.cpp
HEADERS += \
......@@ -46,6 +47,7 @@ HEADERS += \
$$PWD/seasidecache.h \
$$PWD/seasideexport.h \
$$PWD/seasideimport.h \
$$PWD/seasidecontactbuilder.h \
$$PWD/synchronizelists.h \
$$PWD/seasidenamegrouper.h \
$$PWD/seasidepropertyhandler.h
......@@ -56,6 +58,7 @@ headers.files = \
$$PWD/seasidecache.h \
$$PWD/seasideexport.h \
$$PWD/seasideimport.h \
$$PWD/seasidecontactbuilder.h \
$$PWD/synchronizelists.h \
$$PWD/seasidenamegrouper.h \
$$PWD/seasidepropertyhandler.h
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment