CalendarBackend.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 CALENDARBACKEND_H_490498898043897984389983478
#define CALENDARBACKEND_H_490498898043897984389983478
#include <QString>
#include "definitions.h"
//calendar related includes
#include "extendedcalendar.h"
#include "notebook.h"
#include <sqlitestorage.h>
#include <KCalendarCore/MemoryCalendar>
#include <KCalendarCore/VCalFormat>
#include <KCalendarCore/ICalFormat>
static const QString ID_SEPARATOR("::");
class CalendarBackend
{
public:
//error status code return by calender backend.
enum ErrorStatus
{
STATUS_GENERIC_ERROR = -3,
STATUS_ITEM_DUPLICATE = -2,
STATUS_ITEM_NOT_FOUND = -1,
STATUS_OK = 0
};
CalendarBackend();
virtual ~CalendarBackend();
// \param strNotebookName Name of the notebook to use
bool init( const QString& aNotebookName, const QString& aUid = "" );
bool uninit();
// @param aIncidences List of incidences
// @return True on success, otherwise false
bool getAllIncidences( KCalendarCore::Incidence::List& aIncidences );
// @param aIncidences List of incidences
// @param aTime Timestamp
// @return True on success, otherwise false
bool getAllNew( KCalendarCore::Incidence::List& aIncidences, const QDateTime& aTime );
// @param aIncidences List of incidences
// @param aTime Timestamp
// @return True on success, otherwise false
bool getAllModified( KCalendarCore::Incidence::List& aIncidences, const QDateTime& aTime );
// @param aIncidences List of incidences
// @param aTime Timestamp
// @return True on success, otherwise false
bool getAllDeleted( KCalendarCore::Incidence::List& aIncidences, const QDateTime& aTime );
// Caller must not free the returned pointer.
// \param aUID Item UID
// \return The incidence (should not be freed by caller).
KCalendarCore::Incidence::Ptr getIncidence( const QString& aUID );
// \param pInci Incidence
QString getVCalString( KCalendarCore::Incidence::Ptr aInci );
// \param pInci Incidence
QString getICalString( KCalendarCore::Incidence::Ptr aInci );
// Caller has to free the returned incidence after user.
// \param aVString Incidence representation in VCalendar format.
// \return Incidence pointer
KCalendarCore::Incidence::Ptr getIncidenceFromVcal( const QString& aVString );
// Caller has to free the returned incidence after user.
// \param aIString Incidence representation in ICalendar format.
// \return Incidence pointer
KCalendarCore::Incidence::Ptr getIncidenceFromIcal( const QString& aIString );
//
// Duplicate checking will be done if id the of item is not empty.
// If an entry exists, it will be overwritten.
// The uid of incidence will be updated.
// \param aInci Incidence to be added.
// \param commitNow - indicates if we have to commit to the backend immediately
// \return true if addition is success, otherwise false
bool addIncidence( KCalendarCore::Incidence::Ptr aInci, bool commitNow = true );
bool commitChanges();
//
// if there is no incidence with old id exists, a new incidence
// will be created.
// The uid of incidence will be updated.
// \param aInci Incidence to be modified
// \param aUID UID of item
// \return true if modification was success, otherwise false
bool modifyIncidence( KCalendarCore::Incidence::Ptr aInci, const QString& aUID, bool commitNow = true );
// \param aUID id of the incidence to be deleted
// \return errorCode of the operation as status.
ErrorStatus deleteIncidence( const QString& aUID);
private:
bool modifyIncidence( KCalendarCore::Incidence::Ptr aIncidence, KCalendarCore::Incidence::Ptr aIncidenceData );
void filterIncidences( KCalendarCore::Incidence::List& aList );
QString iNotebookStr;
mKCal::ExtendedCalendar::Ptr iCalendar;
mKCal::ExtendedStorage::Ptr iStorage;
};
#endif //CALENDARBACKEND_H_490498898043897984389983478
CalendarBackend::getAllDeleted
bool getAllDeleted(KCalendarCore::Incidence::List &aIncidences, const QDateTime &aTime)
returns all deleted items after the date
CalendarBackend::getICalString
QString getICalString(KCalendarCore::Incidence::Ptr aInci)
returns ICalendar representation of incidence
CalendarBackend::modifyIncidence
bool modifyIncidence(KCalendarCore::Incidence::Ptr aInci, const QString &aUID, bool commitNow=true)
Modify the incidence in calendar.
CalendarBackend::addIncidence
bool addIncidence(KCalendarCore::Incidence::Ptr aInci, bool commitNow=true)
Add the incidence to calendar.
CalendarBackend::deleteIncidence
ErrorStatus deleteIncidence(const QString &aUID)
delete the incidence
CalendarBackend::~CalendarBackend
virtual ~CalendarBackend()
destructor
CalendarBackend::uninit
bool uninit()
Uninitializes the storage.
CalendarBackend::ErrorStatus
ErrorStatus
Definition CalendarBackend.h:47
CalendarBackend::STATUS_OK
@ STATUS_OK
Definition CalendarBackend.h:51
CalendarBackend::STATUS_ITEM_NOT_FOUND
@ STATUS_ITEM_NOT_FOUND
Definition CalendarBackend.h:50
CalendarBackend::STATUS_GENERIC_ERROR
@ STATUS_GENERIC_ERROR
Definition CalendarBackend.h:48
CalendarBackend::STATUS_ITEM_DUPLICATE
@ STATUS_ITEM_DUPLICATE
Definition CalendarBackend.h:49
CalendarBackend::CalendarBackend
CalendarBackend()
constructor
CalendarBackend::init
bool init(const QString &aNotebookName, const QString &aUid="")
Initializes the CalendarBackend.
CalendarBackend::getIncidence
KCalendarCore::Incidence::Ptr getIncidence(const QString &aUID)
Get incidence based on uid.
CalendarBackend::getVCalString
QString getVCalString(KCalendarCore::Incidence::Ptr aInci)
returns VCalendar representation of incidence
CalendarBackend::getAllIncidences
bool getAllIncidences(KCalendarCore::Incidence::List &aIncidences)
returns all incidences inside this calendar
CalendarBackend::getAllNew
bool getAllNew(KCalendarCore::Incidence::List &aIncidences, const QDateTime &aTime)
returns all new items after the date
CalendarBackend::commitChanges
bool commitChanges()
Tell Calendar to commit changes to their db.
CalendarBackend::getIncidenceFromIcal
KCalendarCore::Incidence::Ptr getIncidenceFromIcal(const QString &aIString)
get Incidence from ICalendar string
CalendarBackend::getIncidenceFromVcal
KCalendarCore::Incidence::Ptr getIncidenceFromVcal(const QString &aVString)
get Incidence from VCalendar string
CalendarBackend::getAllModified
bool getAllModified(KCalendarCore::Incidence::List &aIncidences, const QDateTime &aTime)
returns all modified items after the date