Commit 4497d8f4 authored by chriadam's avatar chriadam

[qtcontacts-sqlite] Initial commit

The qtcontacts-sqlite backend for the QtPIM and QtMobility Contacts
APIs stores contact information to an SQLite database.
parents
This repository contains a backend for the QtContacts API.
It stores contact information to a local SQLite database.
TEMPLATE = subdirs
SUBDIRS = \
src \
tests
tests.depends = src
Name: qtcontacts-sqlite
Version: 0.0.1
Release: 0
Summary: SQLite-based plugin for QtContacts
Group: System/Plugins
License: TBD
URL: TBD
Source0: %{name}-%{version}.tar.gz
BuildRequires: pkgconfig(QtCore)
BuildRequires: pkgconfig(QtSql)
BuildRequires: pkgconfig(QtDBus)
BuildRequires: pkgconfig(QtContacts)
%description
%{summary}.
%files
%defattr(-,root,root,-)
%{_libdir}/qt4/plugins/contacts/*.so*
%package tests
Summary: Unit tests for qtcontacts-sqlite
Group: System/Libraries
BuildRequires: pkgconfig(QtTest)
Requires: %{name} = %{version}-%{release}
%description tests
This package contains unit tests for the qtcontacts-sqlite library.
%files tests
%defattr(-,root,root,-)
/opt/tests/qtcontacts-sqlite/*
%prep
%setup -q -n %{name}-%{version}
%build
%qmake
make %{?jobs:-j%jobs}
%install
rm -rf %{buildroot}
%qmake_install
/*
* Copyright (C) 2013 Jolla Ltd. <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 "contactnotifier.h"
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusMetaType>
#include <QVector>
#define NOTIFIER_PATH "/org/nemomobile/contacts/sqlite"
#define NOTIFIER_INTERFACE "org.nemomobile.contacts.sqlite"
Q_DECLARE_METATYPE(QVector<QContactLocalId>)
Q_DECLARE_METATYPE(QList<QContactLocalId>)
namespace ContactNotifier
{
void initialize()
{
qDBusRegisterMetaType<QVector<QContactLocalId> >();
qDBusRegisterMetaType<QList<QContactLocalId> >();
}
void contactsAdded(const QVector<QContactLocalId> &contactIds)
{
QDBusMessage message = QDBusMessage::createSignal(
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String("contactsAdded"));
message.setArguments(QVariantList() << QVariant::fromValue(contactIds));
QDBusConnection::sessionBus().send(message);
}
void contactsChanged(const QVector<QContactLocalId> &contactIds)
{
QDBusMessage message = QDBusMessage::createSignal(
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String("contactsChanged"));
message.setArguments(QVariantList() << QVariant::fromValue(contactIds));
QDBusConnection::sessionBus().send(message);
}
void contactsRemoved(const QList<QContactLocalId> &contactIds)
{
QDBusMessage message = QDBusMessage::createSignal(
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String("contactsRemoved"));
message.setArguments(QVariantList() << QVariant::fromValue(contactIds));
QDBusConnection::sessionBus().send(message);
}
void selfContactIdChanged(QContactLocalId oldId, QContactLocalId newId)
{
QDBusMessage message = QDBusMessage::createSignal(
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String("selfContactIdChanged"));
message.setArguments(QVariantList() << oldId << newId);
QDBusConnection::sessionBus().send(message);
}
void relationshipsAdded(const QSet<QContactLocalId> &contactIds)
{
QDBusMessage message = QDBusMessage::createSignal(
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String("relationshipsAdded"));
message.setArguments(QVariantList() << QVariant::fromValue(contactIds.toList()));
QDBusConnection::sessionBus().send(message);
}
void relationshipsRemoved(const QSet<QContactLocalId> &contactIds)
{
QDBusMessage message = QDBusMessage::createSignal(
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String("relationshipsRemoved"));
message.setArguments(QVariantList() << QVariant::fromValue(contactIds.toList()));
QDBusConnection::sessionBus().send(message);
}
bool connect(const char *name, const char *signature, QObject *receiver, const char *slot)
{
return QDBusConnection::sessionBus().connect(
QString(),
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String(name),
QLatin1String(signature),
receiver,
slot);
}
}
/*
* Copyright (C) 2013 Jolla Ltd. <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."
*/
#ifndef QTCONTACTSSQLITE_CONTACTNOTIFIER_H
#define QTCONTACTSSQLITE_CONTACTNOTIFIER_H
#include <QContact>
#include <QObject>
#include <QSet>
QTM_USE_NAMESPACE
namespace ContactNotifier
{
void initialize();
void contactsAdded(const QVector<QContactLocalId> &contactIds);
void contactsChanged(const QVector<QContactLocalId> &contactIds);
void contactsRemoved(const QList<QContactLocalId> &contactIds);
void selfContactIdChanged(QContactLocalId oldId, QContactLocalId newId);
void relationshipsAdded(const QSet<QContactLocalId> &contactIds);
void relationshipsRemoved(const QSet<QContactLocalId> &contactIds);
bool connect(const char *name, const char *signature, QObject *receiver, const char *slot);
}
#endif
This diff is collapsed.
/*
* Copyright (C) 2013 Jolla Ltd. <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."
*/
#ifndef CONTACTREADER_H
#define CONTACTREADER_H
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QContact>
#include <QContactManager>
#include "contactsdatabase.h"
QTM_USE_NAMESPACE
class ContactReader
{
public:
ContactReader(const QSqlDatabase &database);
virtual ~ContactReader();
QContactManager::Error readContacts(
const QString &table,
QList<QContact> *contacts,
const QContactFilter &filter,
const QList<QContactSortOrder> &order,
const QStringList &details);
QContactManager::Error readContacts(
const QString &table,
QList<QContact> *contacts,
const QList<QContactLocalId> &contactIds,
const QStringList &details);
QContactManager::Error readContactIds(
QList<QContactLocalId> *contactIds,
const QContactFilter &filter,
const QList<QContactSortOrder> &order);
QContactManager::Error getIdentity(
ContactsDatabase::Identity identity, QContactLocalId *contactId);
QContactManager::Error readRelationships(
QList<QContactRelationship> *relationships,
const QString &type,
const QContactId &first,
const QContactId &second);
protected:
QContactManager::Error queryContacts(
const QString &table, QList<QContact> *contacts, const QStringList &details);
virtual void contactsAvailable(const QList<QContact> &contacts);
virtual void contactIdsAvailable(const QList<QContactLocalId> &contactIds);
private:
QSqlDatabase m_database;
};
#endif
This diff is collapsed.
/*
* Copyright (C) 2013 Jolla Ltd. <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."
*/
#ifndef QTCONTACTSSQLITE_CONTACTSDATABASE
#define QTCONTACTSSQLITE_CONTACTSDATABASE
#include <QSqlDatabase>
#include <QContactDetail>
class ContactsDatabase
{
public:
enum Identity {
SelfContactId
};
static QSqlDatabase open(const QString &databaseName);
static QSqlQuery prepare(const char *statement, const QSqlDatabase &database);
private:
};
QTM_BEGIN_NAMESPACE
class QContactTpMetadata : public QContactDetail
{
public:
Q_DECLARE_CUSTOM_CONTACT_DETAIL(QContactTpMetadata, "TpMetadata")
};
QTM_END_NAMESPACE
#endif
This diff is collapsed.
/*
* Copyright (C) 2013 Jolla Ltd. <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."
*/
#ifndef QTCONTACTSSQLITE_CONTACTSENGINE
#define QTCONTACTSSQLITE_CONTACTSENGINE
#include <QContactManagerEngineV2>
#include <QSqlDatabase>
#include "contactreader.h"
#include "contactwriter.h"
QTM_USE_NAMESPACE
class JobThread;
class ContactsEngine : public QContactManagerEngineV2
{
Q_OBJECT
public:
ContactsEngine(const QString &name);
~ContactsEngine();
QContactManager::Error open();
QString managerName() const;
int managerVersion() const;
QList<QContactLocalId> contactIds(
const QContactFilter &filter,
const QList<QContactSortOrder> &sortOrders,
QContactManager::Error* error) const;
QList<QContact> contacts(
const QList<QContactLocalId> &localIds,
const QContactFetchHint &fetchHint,
QMap<int, QContactManager::Error> *errorMap,
QContactManager::Error *error) const;
QContact contact(
const QContactLocalId &contactId,
const QContactFetchHint &fetchHint,
QContactManager::Error* error) const;
QList<QContact> contacts(
const QContactFilter &filter,
const QList<QContactSortOrder> &sortOrders,
const QContactFetchHint &fetchHint,
QContactManager::Error* error) const;
QList<QContact> contacts(
const QContactFilter &filter,
const QList<QContactSortOrder> &sortOrders,
const QContactFetchHint &fetchHint,
QMap<int, QContactManager::Error> *errorMap,
QContactManager::Error *error) const;
bool saveContacts(
QList<QContact> *contacts,
QMap<int, QContactManager::Error> *errorMap,
QContactManager::Error *error);
bool saveContacts(
QList<QContact> *contacts,
const QStringList &definitionMask,
QMap<int, QContactManager::Error> *errorMap,
QContactManager::Error *error);
bool removeContact(const QContactLocalId& contactId, QContactManager::Error* error);
bool removeContacts(
const QList<QContactLocalId> &contactIds,
QMap<int, QContactManager::Error> *errorMap,
QContactManager::Error* error);
QContactLocalId selfContactId(QContactManager::Error* error) const;
bool setSelfContactId(const QContactLocalId& contactId, QContactManager::Error* error);
QList<QContactRelationship> relationships(
const QString &relationshipType,
const QContactId &participantId,
QContactRelationship::Role role,
QContactManager::Error *error) const;
bool saveRelationships(
QList<QContactRelationship> *relationships,
QMap<int, QContactManager::Error> *errorMap,
QContactManager::Error *error);
bool removeRelationships(
const QList<QContactRelationship> &relationships,
QMap<int, QContactManager::Error> *errorMap,
QContactManager::Error *error);
void requestDestroyed(QContactAbstractRequest* req);
bool startRequest(QContactAbstractRequest* req);
bool cancelRequest(QContactAbstractRequest* req);
bool waitForRequestFinished(QContactAbstractRequest* req, int msecs);
QMap<QString, QContactDetailDefinition> detailDefinitions(const QString& contactType, QContactManager::Error* error) const;
bool hasFeature(QContactManager::ManagerFeature feature, const QString& contactType) const;
bool isRelationshipTypeSupported(const QString& relationshipType, const QString& contactType) const;
QStringList supportedContactTypes() const;
private slots:
void _q_contactsChanged(const QList<QContactLocalId> &contacts);
void _q_contactsAdded(const QList<QContactLocalId> &contacts);
void _q_contactsRemoved(const QList<QContactLocalId> &contacts);
void _q_selfContactIdChanged(quint32,quint32);
private:
QString databaseUuid();
QString m_databaseUuid;
const QString m_name;
QSqlDatabase m_database;
mutable ContactReader *m_synchronousReader;
ContactWriter *m_synchronousWriter;
JobThread *m_jobThread;
};
#endif
/*
* Copyright (C) 2013 Jolla Ltd. <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 "contactsengine.h"
#include <QContactManagerEngineFactory>
#include <QtDebug>
QTM_USE_NAMESPACE
class ContactsFactory : public QObject, public QContactManagerEngineFactory
{
Q_OBJECT
Q_INTERFACES(QtMobility::QContactManagerEngineFactory)
public:
ContactsFactory();
QContactManagerEngine *engine(
const QMap<QString, QString> &parameters, QContactManager::Error* error);
QString managerName() const;
QList<int> supportedImplementationVersions() const;
};
ContactsFactory::ContactsFactory()
{
}
QContactManagerEngine *ContactsFactory::engine(
const QMap<QString, QString> &parameters, QContactManager::Error* error)
{
Q_UNUSED(parameters);
ContactsEngine *engine = new ContactsEngine(QLatin1String("org.nemomobile.contacts.sqlite"));
QContactManager::Error err = engine->open();
if (error)
*error = err;
if (err != QContactManager::NoError) {
delete engine;
return 0;
} else {
return engine;
}
}
QString ContactsFactory::managerName() const
{
return QLatin1String("org.nemomobile.contacts.sqlite");
}
QList<int> ContactsFactory::supportedImplementationVersions() const
{
return QList<int>() << 1 << 2;
}
Q_EXPORT_PLUGIN2(qtcontacts_sqlite, ContactsFactory);
#include "contactsplugin.moc"
This diff is collapsed.
/*
* Copyright (C) 2013 Jolla Ltd. <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."
*/
#ifndef QTCONTACTSSQLITE_CONTACTWRITER
#define QTCONTACTSSQLITE_CONTACTWRITER
#include <QSqlQuery>
#include <QContactAddress>
#include <QContactAnniversary>
#include <QContactAvatar>
#include <QContactBirthday>
#include <QContactEmailAddress>
#include <QContactGuid>
#include <QContactHobby>
#include <QContactNickname>
#include <QContactNote>
#include <QContactOnlineAccount>
#include <QContactOrganization>
#include <QContactPhoneNumber>
#include <QContactPresence>
#include <QContactRingtone>
#include <QContactSyncTarget>
#include <QContactTag>
#include <QContactUrl>
#include <QContactManager>
#include "contactsdatabase.h"
QTM_USE_NAMESPACE
class ContactWriter
{
public:
ContactWriter(const QSqlDatabase &database);
~ContactWriter();
QContactManager::Error save(
QList<QContact> *contacts,
const QStringList &definitionMask,
QMap<int, QContactManager::Error> *errorMap);
QContactManager::Error remove(const QList<QContactLocalId> &contactIds);
QContactManager::Error setIdentity(ContactsDatabase::Identity identity, QContactLocalId contactId);
QContactManager::Error save(
const QList<QContactRelationship> &relationships,
QMap<int, QContactManager::Error> *errorMap);
QContactManager::Error remove(
const QList<QContactRelationship> &relationships,
QMap<int, QContactManager::Error> *errorMap);
private:
QContactManager::Error create(QContact *contact, const QStringList &definitionMask);
QContactManager::Error update(QContact *contact, const QStringList &definitionMask);
QContactManager::Error write(
QContactLocalId contactId, QContact *contact, const QStringList &definitionMask);
void bindContactDetails(const QContact &contact, QSqlQuery &query);
template <typename T> bool writeDetails(
QContactLocalId contactId,
QContact *contact,
QSqlQuery &removeQuery,
const QStringList &definitionMask,
QContactManager::Error *error);
template <typename T> bool writeCommonDetails(
QContactLocalId contactId, const QSqlQuery &query, const T &detail, QContactManager::Error *error);
template <typename T> bool removeCommonDetails(
QContactLocalId contactId, QContactManager::Error *error);
QSqlQuery &bindDetail(QContactLocalId contactId, const QContactAddress &detail);
QSqlQuery &bindDetail(QContactLocalId contactId, const QContactAnniversary &detail);
QSqlQuery &bindDetail(QContactLocalId contactId, const QContactAvatar &