ContactsBackend.h
/*
* This file is part of buteo-sync-plugins package
*
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef CONTACTSBACKEND_H_
#define CONTACTSBACKEND_H_
#include <QContactManager>
#include <QContact>
#include <QContactChangeLogFilter>
#include <QContactId>
#include <QVersitDocument>
#include <QStringList>
using namespace QtContacts;
using namespace QtVersit;
#define QContactLocalId QContactId
enum VCARD_VERSION { VCARD_VERSION21, VCARD_VERSION30 };
struct ContactsStatus
{
QString id;
QContactManager::Error errorCode;
};
class ContactsBackend
{
public:
ContactsBackend(QVersitDocument::VersitType aVerType,
const QString &syncTarget,
const QString &originId);
~ContactsBackend();
bool init();
bool uninit();
QList<QContactLocalId> getAllContactIds();
QList<QContactLocalId> getAllNewContactIds(const QDateTime& aTimeStamp);
QList<QContactLocalId> getAllModifiedContactIds(const QDateTime& aTimeStamp);
QList<QContactLocalId> getAllDeletedContactIds(const QDateTime& aTimeStamp);
void getContact(const QContactLocalId& aContactId,
QContact& aContact);
void getContacts(const QList<QContactLocalId> &aContactIDs,
QMap<QString,QString>& aContactData );
void getContacts(const QList<QContactLocalId>& aContactIds,
QList<QContact>& aContacts);
bool addContacts( const QStringList &aContactDataList,
QMap<int, ContactsStatus> &aStatusMap );
// Functions for modifying contacts
QContactManager::Error modifyContact(const QString &id, const QString &contactdata);
QMap<int, ContactsStatus> modifyContacts(const QStringList &aContactDataList,
const QStringList &aContactsIdList);
QMap<int, ContactsStatus> deleteContacts(const QStringList &aContactIDList);
inline bool batchUpdatesEnabled() { return true; }
QDateTime lastModificationTime(const QContactLocalId &aContactId);
QDateTime getCreationTime( const QContact& aContact );
QList<QDateTime> getCreationTimes( const QList<QContactLocalId>& aContactIds );
QString convertQContactToVCard(const QContact &aContact);
private: // functions
QMap<QString, QString> convertQContactListToVCardList \
(const QList<QContact> &aContactList);
QList<QVersitDocument> convertVCardListToVersitDocumentList \
(const QStringList &aVCardList);
void prepareContactSave(QList<QContact> *contactList);
void getSpecifiedContactIds(const QContactChangeLogFilter::EventType aEventType,
const QDateTime &aTimeStamp,
QList<QContactLocalId> &aIdList);
private: // data
QContactManager *iReadMgr;
QContactManager *iWriteMgr;
QVersitDocument::VersitType iVCardVer;
QString iSyncTarget;
QString iOriginId;
};
#endif /* CONTACTSBACKEND_H_ */
ContactsBackend::getContact
void getContact(const QContactLocalId &aContactId, QContact &aContact)
Get contact data for a given gontact ID as a QContact object.
ContactsBackend::batchUpdatesEnabled
bool batchUpdatesEnabled()
Tells if batch updates are enabled.
Definition ContactsBackend.h:172
ContactsBackend::convertQContactToVCard
QString convertQContactToVCard(const QContact &aContact)
Converts a QContact to a VCard.
ContactsBackend::getCreationTimes
QList< QDateTime > getCreationTimes(const QList< QContactLocalId > &aContactIds)
Returns creation times of the contacts.
ContactsBackend::modifyContact
QContactManager::Error modifyContact(const QString &id, const QString &contactdata)
Modify a contact that whose data and ID are given as Input.
ContactsBackend::lastModificationTime
QDateTime lastModificationTime(const QContactLocalId &aContactId)
Returns the last time the contact was modified.
ContactsBackend::init
bool init()
Searches for available storage plugins and sets the manager to that plugin.
ContactsBackend::getContacts
void getContacts(const QList< QContactLocalId > &aContactIDs, QMap< QString, QString > &aContactData)
Get multiple contacts at once as vcards.
ContactsBackend::getAllDeletedContactIds
QList< QContactLocalId > getAllDeletedContactIds(const QDateTime &aTimeStamp)
Return all deleted contacts ids in a QList of QStrings.
ContactsBackend::addContacts
bool addContacts(const QStringList &aContactDataList, QMap< int, ContactsStatus > &aStatusMap)
Batch addition of contacts.
ContactsBackend::getCreationTime
QDateTime getCreationTime(const QContact &aContact)
Return creation time of single contact.
ContactsBackend::getAllModifiedContactIds
QList< QContactLocalId > getAllModifiedContactIds(const QDateTime &aTimeStamp)
Return all modified contact ids in a QList of QStrings.
ContactsBackend::~ContactsBackend
~ContactsBackend()
Destructor.
ContactsBackend::uninit
bool uninit()
releases the resources held.
ContactsBackend::ContactsBackend
ContactsBackend(QVersitDocument::VersitType aVerType, const QString &syncTarget, const QString &originId)
Constructor.
ContactsBackend::deleteContacts
QMap< int, ContactsStatus > deleteContacts(const QStringList &aContactIDList)
Batch deletion of contacts.
ContactsBackend::getAllContactIds
QList< QContactLocalId > getAllContactIds()
Return ids of all contacts retrieved from the backend.
ContactsBackend::modifyContacts
QMap< int, ContactsStatus > modifyContacts(const QStringList &aContactDataList, const QStringList &aContactsIdList)
Batch modification.
ContactsBackend::getAllNewContactIds
QList< QContactLocalId > getAllNewContactIds(const QDateTime &aTimeStamp)
Return all new contacts ids in a QList of QStrings.
ContactsBackend::getContacts
void getContacts(const QList< QContactLocalId > &aContactIds, QList< QContact > &aContacts)
Get multiple contacts at once as QContact objects.
ContactsStatus
Definition ContactsBackend.h:40