| 1 |
/* |
| 2 |
* This file is part of buteo-sync-plugins package |
| 3 |
* |
| 4 |
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
| 5 |
* Copyright (C) 2013 - 2021 Jolla Ltd. |
| 6 |
* |
| 7 |
* Contact: Sateesh Kavuri <[email protected]> |
| 8 |
* |
| 9 |
* This library is free software; you can redistribute it and/or |
| 10 |
* modify it under the terms of the GNU Lesser General Public License |
| 11 |
* version 2.1 as published by the Free Software Foundation. |
| 12 |
* |
| 13 |
* This library is distributed in the hope that it will be useful, but |
| 14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public |
| 19 |
* License along with this library; if not, write to the Free Software |
| 20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 21 |
* 02110-1301 USA |
| 22 |
* |
| 23 |
*/ |
| 24 |
#ifndef CONTACT_STORAGE_HEADER_1717 |
| 25 |
#define CONTACT_STORAGE_HEADER_1717 |
| 26 |
|
| 27 |
#include <QDateTime> |
| 28 |
#include <QMap> |
| 29 |
|
| 30 |
#include "StoragePlugin.h" |
| 31 |
#include "StoragePluginLoader.h" |
| 32 |
#include "ContactsBackend.h" |
| 33 |
#include "buteosyncfw5/DeletedItemsIdStorage.h" |
| 34 |
|
| 35 |
class SimpleItem; |
| 36 |
|
| 37 |
//! \brief Harmattan Contact storage plugin |
| 38 |
// |
| 39 |
// Interface to Storage Plugin towards Sync FW |
| 40 |
class ContactStorage : public Buteo::StoragePlugin |
| 41 |
{ |
| 42 |
|
| 43 |
public: |
| 44 |
/*! \brief Constructor |
| 45 |
* |
| 46 |
*/ |
| 47 |
ContactStorage(const QString& aPluginName); |
| 48 |
|
| 49 |
/*! \brief Destructor |
| 50 |
* |
| 51 |
*/ |
| 52 |
virtual ~ContactStorage(); |
| 53 |
|
| 54 |
//////////////////////////////////////////////////////////////////////////////// |
| 55 |
// Functions below are derived from storage plugin /////////////// |
| 56 |
//////////////////////////////////////////////////////////////////////////////// |
| 57 |
|
| 58 |
/*! \brief Initializes the plugin |
| 59 |
* |
| 60 |
* |
| 61 |
* @param aProperties Properties that should be set for this plugin |
| 62 |
* @return True on success, otherwise false |
| 63 |
*/ |
| 64 |
virtual bool init( const QMap<QString, QString>& aProperties ); |
| 65 |
|
| 66 |
/*! \brief Uninitializes the plugin |
| 67 |
* |
| 68 |
*/ |
| 69 |
virtual bool uninit(); |
| 70 |
|
| 71 |
/*! \brief Returns all known items |
| 72 |
* |
| 73 |
* @param aItems Array where to place items |
| 74 |
* @return True on success, otherwise false |
| 75 |
*/ |
| 76 |
virtual bool getAllItems(QList<Buteo::StorageItem*> &aItems); |
| 77 |
|
| 78 |
|
| 79 |
/*! \brief Returns id's of all known items |
| 80 |
* |
| 81 |
* @param aItems Array where to place item id's |
| 82 |
* @return True on success, otherwise false |
| 83 |
*/ |
| 84 |
virtual bool getAllItemIds( QList<QString>& aItems ); |
| 85 |
|
| 86 |
|
| 87 |
/*! \brief Returns all new items since aTime |
| 88 |
* |
| 89 |
* @param aNewItems Array where to place items |
| 90 |
* @param aTime Timestamp |
| 91 |
* @return True on success, otherwise false |
| 92 |
*/ |
| 93 |
virtual bool getNewItems( QList<Buteo::StorageItem*>& aNewItems, const QDateTime& aTime ); |
| 94 |
|
| 95 |
|
| 96 |
/*! \brief Returns id's of all new items since aTime |
| 97 |
* |
| 98 |
* @param aNewItemIds Array where to place item id's |
| 99 |
* @param aTime Timestamp |
| 100 |
* @return True on success, otherwise false |
| 101 |
*/ |
| 102 |
virtual bool getNewItemIds( QList<QString>& aNewItemIds, const QDateTime& aTime ); |
| 103 |
|
| 104 |
/*! \brief Returns all modified items since aTime |
| 105 |
* |
| 106 |
* @param aModifiedItems Array where to place items |
| 107 |
* @param aTime Timestamp |
| 108 |
* @return True on success, otherwise false |
| 109 |
*/ |
| 110 |
virtual bool getModifiedItems( QList<Buteo::StorageItem*>& aModifiedItems, const QDateTime& aTime ); |
| 111 |
|
| 112 |
/*! \brief Returns id's of all modified items since aTime |
| 113 |
* |
| 114 |
* @param aModifiedItemIds Array where to place item id's |
| 115 |
* @param aTime Timestamp |
| 116 |
* @return True on success, otherwise false |
| 117 |
*/ |
| 118 |
virtual bool getModifiedItemIds( QList<QString>& aModifiedItemIds, const QDateTime& aTime ); |
| 119 |
|
| 120 |
|
| 121 |
/*! \brief Returns id's of all deleted items since aTime |
| 122 |
* |
| 123 |
* @param aDeletedItemIds Array where to place item id's |
| 124 |
* @param aTime Timestamp |
| 125 |
* @return True on success, otherwise false |
| 126 |
*/ |
| 127 |
virtual bool getDeletedItemIds( QList<QString>& aDeletedItemIds, const QDateTime& aTime ); |
| 128 |
|
| 129 |
/*! \brief Generates a new item |
| 130 |
* |
| 131 |
* Returned item is temporary. Therefore returned item ALWAYS has its id |
| 132 |
* set as empty ID (""). ID will be assigned only after addItem() has been |
| 133 |
* called for the item. |
| 134 |
* |
| 135 |
* @return On success pointer to the item generated, otherwise NULL |
| 136 |
*/ |
| 137 |
virtual Buteo::StorageItem* newItem(); |
| 138 |
|
| 139 |
|
| 140 |
/*! \brief Returns an item based on id |
| 141 |
* |
| 142 |
* @param aItemId Id of the item to return |
| 143 |
* @return On success pointer to the item, otherwise NULL |
| 144 |
*/ |
| 145 |
virtual Buteo::StorageItem* getItem( const QString& aItemId ); |
| 146 |
|
| 147 |
/*! \brief Returns items based on ids |
| 148 |
* |
| 149 |
* @param aItemIdList Ids of the items |
| 150 |
* @return List of items |
| 151 |
*/ |
| 152 |
virtual QList<Buteo::StorageItem*> getItems( const QStringList& aItemIdList ); |
| 153 |
|
| 154 |
/*! \brief Adds an item to the storage |
| 155 |
* |
| 156 |
* Upon successful addition, item is updated with its |
| 157 |
* assigned ID. |
| 158 |
* |
| 159 |
* @param aItem Item to add |
| 160 |
* @return Operation status code |
| 161 |
*/ |
| 162 |
virtual OperationStatus addItem( Buteo::StorageItem& aItem ); |
| 163 |
|
| 164 |
|
| 165 |
/*! \brief Adds items to the storage |
| 166 |
* |
| 167 |
* Upon successful addition, items are updated with its |
| 168 |
* assigned ID. |
| 169 |
* |
| 170 |
* @param aItems Items to add |
| 171 |
* @return Operation status codes |
| 172 |
*/ |
| 173 |
virtual QList<OperationStatus> addItems( const QList<Buteo::StorageItem*>& aItems ); |
| 174 |
|
| 175 |
|
| 176 |
/*! \brief Modifies an item in the storage |
| 177 |
* |
| 178 |
* @param aItem Item to modify |
| 179 |
* @return Operation status code |
| 180 |
*/ |
| 181 |
virtual OperationStatus modifyItem( Buteo::StorageItem& aItem ); |
| 182 |
|
| 183 |
/*! \brief Modifies item in the storage |
| 184 |
* |
| 185 |
* @param aItems Items to add |
| 186 |
* @return Operation status codes |
| 187 |
*/ |
| 188 |
virtual QList<OperationStatus> modifyItems( const QList<Buteo::StorageItem*>& aItems ); |
| 189 |
|
| 190 |
/*! \brief Deletes an item from the storage |
| 191 |
* |
| 192 |
* @param aItemId Id of the item to be deleted |
| 193 |
* @return Operation status code |
| 194 |
*/ |
| 195 |
virtual OperationStatus deleteItem( const QString& aItemId ); |
| 196 |
|
| 197 |
/*! \brief Deletes an item from the storage |
| 198 |
* |
| 199 |
* @param aItemIds Id's of the item to be deleted |
| 200 |
* @return Operation status codes |
| 201 |
*/ |
| 202 |
virtual QList<OperationStatus> deleteItems( const QList<QString>& aItemIds ); |
| 203 |
|
| 204 |
|
| 205 |
private: |
| 206 |
|
| 207 |
bool doInitItemAnalysis(); |
| 208 |
|
| 209 |
bool doUninitItemAnalysis(); |
| 210 |
|
| 211 |
/*! \brief convert list of contacts into vector of storage items |
| 212 |
* |
| 213 |
* |
| 214 |
* @param aList List of contacts |
| 215 |
* @return list of storage items |
| 216 |
*/ |
| 217 |
QList<Buteo::StorageItem*> getStoreList(QList<QContactLocalId>&aList); |
| 218 |
|
| 219 |
QByteArray getCtCaps( const QString& aFilename ) const; |
| 220 |
|
| 221 |
ContactStorage::OperationStatus mapErrorStatus(const QContactManager::Error &aContactError) const; |
| 222 |
|
| 223 |
/** |
| 224 |
* \brief Converts a vcard data to a storage item object |
| 225 |
* @param aItemKey ID of the item |
| 226 |
* @param aItemData Data of the item |
| 227 |
* @return Storage item object (a pointer to SimpleItem) |
| 228 |
*/ |
| 229 |
SimpleItem* convertVcardToStorageItem(const QContactLocalId aItemKey, |
| 230 |
const QString& aItemData); |
| 231 |
|
| 232 |
ContactsBackend* iBackend; |
| 233 |
|
| 234 |
Buteo::DeletedItemsIdStorage iDeletedItems; ///< Backend for tracking deleted items |
| 235 |
|
| 236 |
QMap<QString, QDateTime> iSnapshot; |
| 237 |
QList<QString> iFreshItems; |
| 238 |
}; |
| 239 |
|
| 240 |
class ContactsStoragePluginLoader : public Buteo::StoragePluginLoader |
| 241 |
{ |
| 242 |
Q_OBJECT |
| 243 |
Q_PLUGIN_METADATA(IID "com.buteo.plugins.storage.ContactsStoragePluginLoader") |
| 244 |
Q_INTERFACES(Buteo::StoragePluginLoader) |
| 245 |
|
| 246 |
public: |
| 247 |
Buteo::StoragePlugin* createPlugin(const QString& aPluginName) override; |
| 248 |
}; |
| 249 |
|
| 250 |
#endif //CONTACT_STORAGE_HEADER_1717 |
| 251 |
|