2
Copyright (c) 2006 Till Adam <adam@kde.org>
3
Copyright (c) 2009 David Jarvie <djarvie@kde.org>
5
This library is free software; you can redistribute it and/or modify it
6
under the terms of the GNU Library General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or (at your
8
option) any later version.
10
This library is distributed in the hope that it will be useful, but WITHOUT
11
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13
License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to the
17
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
#ifndef ICALRESOURCEBASE_H
22
#define ICALRESOURCEBASE_H
24
#include "singlefileresource.h"
31
class ICalResourceBase : public Akonadi::SingleFileResource<Settings>
37
* @param fileTypeDescription filter descriptor for the calendar file type,
38
* to display for the '*.ics *.ical' filter.
40
ICalResourceBase( const QString &id, const QString &fileTypeDescription );
44
virtual void configure( WId windowId );
47
bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts );
48
void retrieveItems( const Akonadi::Collection &col );
51
enum CheckType { CheckForAdded, CheckForChanged };
53
void initialise( const QStringList &mimeTypes, const QString &icon );
54
bool readFromFile( const QString &fileName );
55
bool writeToFile( const QString &fileName );
56
virtual void aboutToQuit();
59
* Retrieve an incidence from the calendar, and set it into a new item's payload.
60
* Retrieval of the item should be signalled by calling @p itemRetrieved().
61
* @param item the incidence ID to retrieve is provided by @c item.remoteId()
62
* @return true if item retrieved, false if not.
64
virtual bool doRetrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts ) = 0;
67
* Retrieve all incidences from the calendar, and set each into a new item's payload.
68
* Retrieval of the items should be signalled by calling @p itemsRetrieved().
70
virtual void doRetrieveItems( const Akonadi::Collection &col ) = 0;
73
* To be called at the start of derived class implementations of itemAdded()
74
* or itemChanged() to verify that required conditions are true.
75
* @param type the type of change to perform the checks for.
76
* @return true if all checks are successful, and processing can continue;
77
* false if a check failed, in which case itemAdded() or itemChanged()
78
* should stop processing.
80
template <typename PayloadPtr> bool checkItemAddedChanged( const Akonadi::Item &item, CheckType type );
82
virtual void itemRemoved( const Akonadi::Item &item );
84
/** Return the local calendar. */
85
KCal::CalendarLocal *calendar() const;
88
KCal::CalendarLocal *mCalendar;
89
const QString mFileDescription;
92
template <typename PayloadPtr>
93
bool ICalResourceBase::checkItemAddedChanged( const Akonadi::Item &item, CheckType type )
96
cancelTask( i18n("Calendar not loaded.") );
99
if ( !item.hasPayload<PayloadPtr>() ) {
100
QString msg = (type == CheckForAdded)
101
? i18n("Unable to retrieve added item %1.", item.id() )
102
: i18n("Unable to retrieve modified item %1.", item.id() );
103
cancelTask( msg.arg( item.id() ) );