| 1 |
/* |
| 2 |
* This file is part of buteo-sync-plugins package |
| 3 |
* |
| 4 |
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
| 5 |
* |
| 6 |
* Contact: Sateesh Kavuri <[email protected]> |
| 7 |
* |
| 8 |
* This library is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU Lesser General Public License |
| 10 |
* version 2.1 as published by the Free Software Foundation. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, but |
| 13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 |
* 02110-1301 USA |
| 21 |
* |
| 22 |
*/ |
| 23 |
#ifndef CONTACTSBACKEND_H_ |
| 24 |
#define CONTACTSBACKEND_H_ |
| 25 |
|
| 26 |
#include <QContactManager> |
| 27 |
#include <QContact> |
| 28 |
#include <QContactChangeLogFilter> |
| 29 |
#include <QContactId> |
| 30 |
#include <QVersitDocument> |
| 31 |
#include <QStringList> |
| 32 |
|
| 33 |
using namespace QtContacts; |
| 34 |
using namespace QtVersit; |
| 35 |
#define QContactLocalId QContactId |
| 36 |
|
| 37 |
enum VCARD_VERSION { VCARD_VERSION21, VCARD_VERSION30 }; |
| 38 |
|
| 39 |
struct ContactsStatus |
| 40 |
{ |
| 41 |
QString id; |
| 42 |
QContactManager::Error errorCode; |
| 43 |
}; |
| 44 |
|
| 45 |
//! \brief Harmattan Contact storage plugin backend interface class |
| 46 |
/// |
| 47 |
/// This class interfaces with the backend implementation of contact manager on harmattan |
| 48 |
/// device |
| 49 |
class ContactsBackend |
| 50 |
{ |
| 51 |
|
| 52 |
public: |
| 53 |
|
| 54 |
/*! |
| 55 |
* \brief Constructor |
| 56 |
* @param aVerType |
| 57 |
*/ |
| 58 |
ContactsBackend(QVersitDocument::VersitType aVerType, |
| 59 |
const QString &syncTarget, |
| 60 |
const QString &originId); |
| 61 |
|
| 62 |
|
| 63 |
/*! |
| 64 |
* \brief Destructor |
| 65 |
*/ |
| 66 |
~ContactsBackend(); |
| 67 |
|
| 68 |
/*! |
| 69 |
* \brief Searches for available storage plugins and sets the manager to that plugin |
| 70 |
* @return |
| 71 |
*/ |
| 72 |
bool init(); |
| 73 |
|
| 74 |
/*! |
| 75 |
* \brief releases the resources held. |
| 76 |
* @return |
| 77 |
*/ |
| 78 |
bool uninit(); |
| 79 |
|
| 80 |
/*! |
| 81 |
* \brief Return ids of all contacts retrieved from the backend |
| 82 |
* @return List of contact IDs |
| 83 |
*/ |
| 84 |
QList<QContactLocalId> getAllContactIds(); |
| 85 |
|
| 86 |
/*! |
| 87 |
* \brief Return all new contacts ids in a QList of QStrings |
| 88 |
* @param aTimeStamp Timestamp of the oldest contact ID to be returned |
| 89 |
* @return List of contact IDs |
| 90 |
*/ |
| 91 |
QList<QContactLocalId> getAllNewContactIds(const QDateTime& aTimeStamp); |
| 92 |
|
| 93 |
/*! |
| 94 |
* \brief Return all modified contact ids in a QList of QStrings |
| 95 |
* @param aTimeStamp Timestamp of the oldest contact ID to be returned |
| 96 |
* @return List of contact IDs |
| 97 |
*/ |
| 98 |
QList<QContactLocalId> getAllModifiedContactIds(const QDateTime& aTimeStamp); |
| 99 |
|
| 100 |
|
| 101 |
/*! |
| 102 |
* \brief Return all deleted contacts ids in a QList of QStrings |
| 103 |
* @param aTimeStamp Timestamp of the oldest contact ID to be returned |
| 104 |
* @return List of contact IDs |
| 105 |
*/ |
| 106 |
QList<QContactLocalId> getAllDeletedContactIds(const QDateTime& aTimeStamp); |
| 107 |
|
| 108 |
/*! |
| 109 |
* \brief Get contact data for a given gontact ID as a QContact object |
| 110 |
* @param aContactId The ID of the contact |
| 111 |
* @param aContact The returned data of the contact |
| 112 |
*/ |
| 113 |
void getContact(const QContactLocalId& aContactId, |
| 114 |
QContact& aContact); |
| 115 |
|
| 116 |
|
| 117 |
/*! |
| 118 |
* \brief Get multiple contacts at once as vcards |
| 119 |
* @param aContactIDs List of contact IDs to be returned |
| 120 |
* @param aContactData Returned contact data |
| 121 |
*/ |
| 122 |
void getContacts(const QList<QContactLocalId> &aContactIDs, |
| 123 |
QMap<QString,QString>& aContactData ); |
| 124 |
/*! |
| 125 |
* \brief Get multiple contacts at once as QContact objects |
| 126 |
* @param aContactIds List of contact IDs |
| 127 |
* @param aContacts List of returned contact data |
| 128 |
*/ |
| 129 |
void getContacts(const QList<QContactLocalId>& aContactIds, |
| 130 |
QList<QContact>& aContacts); |
| 131 |
|
| 132 |
/*! |
| 133 |
* \brief Batch addition of contacts |
| 134 |
* @param aContactDataList Contact data |
| 135 |
* @param aStatusMap Returned status data |
| 136 |
* @return Errors |
| 137 |
*/ |
| 138 |
bool addContacts( const QStringList &aContactDataList, |
| 139 |
QMap<int, ContactsStatus> &aStatusMap ); |
| 140 |
|
| 141 |
// Functions for modifying contacts |
| 142 |
|
| 143 |
/*! |
| 144 |
* \brief Modify a contact that whose data and ID are given as Input |
| 145 |
* @param id Contact ID |
| 146 |
* @param contactdata Contact data |
| 147 |
* @return Error |
| 148 |
*/ |
| 149 |
QContactManager::Error modifyContact(const QString &id, const QString &contactdata); |
| 150 |
|
| 151 |
/*! |
| 152 |
* \brief Batch modification |
| 153 |
* @param aContactDataList Contact data |
| 154 |
* @param aContactsIdList Contact IDs |
| 155 |
* @return Errors |
| 156 |
*/ |
| 157 |
QMap<int, ContactsStatus> modifyContacts(const QStringList &aContactDataList, |
| 158 |
const QStringList &aContactsIdList); |
| 159 |
|
| 160 |
/*! |
| 161 |
* \brief Batch deletion of contacts |
| 162 |
* @param aContactIDList Contact IDs |
| 163 |
* @return Errors |
| 164 |
*/ |
| 165 |
QMap<int, ContactsStatus> deleteContacts(const QStringList &aContactIDList); |
| 166 |
|
| 167 |
|
| 168 |
/*! |
| 169 |
* \brief Tells if batch updates are enabled |
| 170 |
* @return True if enabled, false if not |
| 171 |
*/ |
| 172 |
inline bool batchUpdatesEnabled() { return true; } |
| 173 |
|
| 174 |
/*! |
| 175 |
* \brief Returns the last time the contact was modified |
| 176 |
* @param aContactId Id of the contact |
| 177 |
* @return Timestamp of contact's last modification time |
| 178 |
*/ |
| 179 |
QDateTime lastModificationTime(const QContactLocalId &aContactId); |
| 180 |
|
| 181 |
/*! \brief Return creation time of single contact |
| 182 |
* |
| 183 |
* @param aContact Contact |
| 184 |
* @return Creation time |
| 185 |
*/ |
| 186 |
QDateTime getCreationTime( const QContact& aContact ); |
| 187 |
|
| 188 |
/*! \brief Returns creation times of the contacts |
| 189 |
* |
| 190 |
* @param aContactIds Ids of the contacts |
| 191 |
* @return Creation times |
| 192 |
*/ |
| 193 |
QList<QDateTime> getCreationTimes( const QList<QContactLocalId>& aContactIds ); |
| 194 |
|
| 195 |
|
| 196 |
/*! \brief Converts a QContact to a VCard |
| 197 |
* |
| 198 |
* @param aContact Contact |
| 199 |
* @return VCard |
| 200 |
*/ |
| 201 |
QString convertQContactToVCard(const QContact &aContact); |
| 202 |
private: // functions |
| 203 |
|
| 204 |
QMap<QString, QString> convertQContactListToVCardList \ |
| 205 |
(const QList<QContact> &aContactList); |
| 206 |
QList<QVersitDocument> convertVCardListToVersitDocumentList \ |
| 207 |
(const QStringList &aVCardList); |
| 208 |
void prepareContactSave(QList<QContact> *contactList); |
| 209 |
|
| 210 |
/*! |
| 211 |
* \brief Returns contact IDs specified by event type and timestamp |
| 212 |
* @param aEventType Added/changed/removed contacts |
| 213 |
* @param aTimeStamp Contacts older than aTimeStamp are filtered out |
| 214 |
* @param aIdList Returned contact IDs |
| 215 |
*/ |
| 216 |
void getSpecifiedContactIds(const QContactChangeLogFilter::EventType aEventType, |
| 217 |
const QDateTime &aTimeStamp, |
| 218 |
QList<QContactLocalId> &aIdList); |
| 219 |
|
| 220 |
private: // data |
| 221 |
|
| 222 |
QContactManager *iReadMgr; ///< A pointer to contact manager |
| 223 |
QContactManager *iWriteMgr; ///< A pointer to contact manager |
| 224 |
|
| 225 |
QVersitDocument::VersitType iVCardVer; ///< VCard Version type to operate on |
| 226 |
|
| 227 |
QString iSyncTarget; ///< syncTarget to use for contact details |
| 228 |
QString iOriginId; ///< origin meta-data ID to use for contact details |
| 229 |
}; |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
#endif /* CONTACTSBACKEND_H_ */ |