| 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 |
|
| 24 |
#ifndef CALENDARBACKEND_H_490498898043897984389983478 |
| 25 |
#define CALENDARBACKEND_H_490498898043897984389983478 |
| 26 |
|
| 27 |
#include <QString> |
| 28 |
|
| 29 |
#include "definitions.h" |
| 30 |
|
| 31 |
//calendar related includes |
| 32 |
#include "extendedcalendar.h" |
| 33 |
#include "notebook.h" |
| 34 |
#include <sqlitestorage.h> |
| 35 |
#include <KCalendarCore/MemoryCalendar> |
| 36 |
#include <KCalendarCore/VCalFormat> |
| 37 |
#include <KCalendarCore/ICalFormat> |
| 38 |
|
| 39 |
static const QString ID_SEPARATOR("::"); |
| 40 |
//! \brief Calendar implementation for synchronization |
| 41 |
class CalendarBackend |
| 42 |
{ |
| 43 |
|
| 44 |
public: |
| 45 |
//error status code return by calender backend. |
| 46 |
enum ErrorStatus |
| 47 |
{ |
| 48 |
STATUS_GENERIC_ERROR = -3, /*!< General error occurred during operation*/ |
| 49 |
STATUS_ITEM_DUPLICATE = -2, /*!< Operation was not performed as object was duplicate*/ |
| 50 |
STATUS_ITEM_NOT_FOUND = -1, /*!< Operation failed as object was not found*/ |
| 51 |
STATUS_OK = 0 /*!< Operation was completed successfully*/ |
| 52 |
}; |
| 53 |
|
| 54 |
//! \brief constructor |
| 55 |
CalendarBackend(); |
| 56 |
|
| 57 |
//! \brief destructor |
| 58 |
virtual ~CalendarBackend(); |
| 59 |
|
| 60 |
//! \brief Initializes the CalendarBackend |
| 61 |
// \param strNotebookName Name of the notebook to use |
| 62 |
bool init( const QString& aNotebookName, const QString& aUid = "" ); |
| 63 |
|
| 64 |
//! \brief Uninitializes the storage |
| 65 |
bool uninit(); |
| 66 |
|
| 67 |
//! \brief returns all incidences inside this calendar |
| 68 |
// @param aIncidences List of incidences |
| 69 |
// @return True on success, otherwise false |
| 70 |
bool getAllIncidences( KCalendarCore::Incidence::List& aIncidences ); |
| 71 |
|
| 72 |
//! \brief returns all new items after the date |
| 73 |
// @param aIncidences List of incidences |
| 74 |
// @param aTime Timestamp |
| 75 |
// @return True on success, otherwise false |
| 76 |
bool getAllNew( KCalendarCore::Incidence::List& aIncidences, const QDateTime& aTime ); |
| 77 |
|
| 78 |
//! \brief returns all modified items after the date |
| 79 |
// @param aIncidences List of incidences |
| 80 |
// @param aTime Timestamp |
| 81 |
// @return True on success, otherwise false |
| 82 |
bool getAllModified( KCalendarCore::Incidence::List& aIncidences, const QDateTime& aTime ); |
| 83 |
|
| 84 |
//! \brief returns all deleted items after the date |
| 85 |
// @param aIncidences List of incidences |
| 86 |
// @param aTime Timestamp |
| 87 |
// @return True on success, otherwise false |
| 88 |
bool getAllDeleted( KCalendarCore::Incidence::List& aIncidences, const QDateTime& aTime ); |
| 89 |
|
| 90 |
//! \brief Get incidence based on uid. |
| 91 |
// Caller must not free the returned pointer. |
| 92 |
// \param aUID Item UID |
| 93 |
// \return The incidence (should not be freed by caller). |
| 94 |
KCalendarCore::Incidence::Ptr getIncidence( const QString& aUID ); |
| 95 |
|
| 96 |
//! \brief returns VCalendar representation of incidence |
| 97 |
// \param pInci Incidence |
| 98 |
QString getVCalString( KCalendarCore::Incidence::Ptr aInci ); |
| 99 |
|
| 100 |
//! \brief returns ICalendar representation of incidence |
| 101 |
// \param pInci Incidence |
| 102 |
QString getICalString( KCalendarCore::Incidence::Ptr aInci ); |
| 103 |
|
| 104 |
//! \brief get Incidence from VCalendar string |
| 105 |
// Caller has to free the returned incidence after user. |
| 106 |
// \param aVString Incidence representation in VCalendar format. |
| 107 |
// \return Incidence pointer |
| 108 |
KCalendarCore::Incidence::Ptr getIncidenceFromVcal( const QString& aVString ); |
| 109 |
|
| 110 |
//! \brief get Incidence from ICalendar string |
| 111 |
// Caller has to free the returned incidence after user. |
| 112 |
// \param aIString Incidence representation in ICalendar format. |
| 113 |
// \return Incidence pointer |
| 114 |
KCalendarCore::Incidence::Ptr getIncidenceFromIcal( const QString& aIString ); |
| 115 |
|
| 116 |
//! \brief Add the incidence to calendar |
| 117 |
// |
| 118 |
// Duplicate checking will be done if id the of item is not empty. |
| 119 |
// If an entry exists, it will be overwritten. |
| 120 |
// The uid of incidence will be updated. |
| 121 |
// \param aInci Incidence to be added. |
| 122 |
// \param commitNow - indicates if we have to commit to the backend immediately |
| 123 |
// \return true if addition is success, otherwise false |
| 124 |
bool addIncidence( KCalendarCore::Incidence::Ptr aInci, bool commitNow = true ); |
| 125 |
|
| 126 |
//! \brief Tell Calendar to commit changes to their db |
| 127 |
/// \return true if committed succesfully, false otherwise |
| 128 |
bool commitChanges(); |
| 129 |
|
| 130 |
//! \brief Modify the incidence in calendar |
| 131 |
// |
| 132 |
// if there is no incidence with old id exists, a new incidence |
| 133 |
// will be created. |
| 134 |
// The uid of incidence will be updated. |
| 135 |
// \param aInci Incidence to be modified |
| 136 |
// \param aUID UID of item |
| 137 |
// \return true if modification was success, otherwise false |
| 138 |
bool modifyIncidence( KCalendarCore::Incidence::Ptr aInci, const QString& aUID, bool commitNow = true ); |
| 139 |
|
| 140 |
//! \brief delete the incidence |
| 141 |
// \param aUID id of the incidence to be deleted |
| 142 |
// \return errorCode of the operation as status. |
| 143 |
ErrorStatus deleteIncidence( const QString& aUID); |
| 144 |
|
| 145 |
private: |
| 146 |
bool modifyIncidence( KCalendarCore::Incidence::Ptr aIncidence, KCalendarCore::Incidence::Ptr aIncidenceData ); |
| 147 |
|
| 148 |
void filterIncidences( KCalendarCore::Incidence::List& aList ); |
| 149 |
|
| 150 |
QString iNotebookStr; |
| 151 |
mKCal::ExtendedCalendar::Ptr iCalendar; |
| 152 |
mKCal::ExtendedStorage::Ptr iStorage; |
| 153 |
|
| 154 |
}; |
| 155 |
|
| 156 |
|
| 157 |
#endif //CALENDARBACKEND_H_490498898043897984389983478 |