2
This file is part of the kolab resource - the implementation of the
3
Kolab storage format. See www.kolab.org for documentation on this.
5
Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
6
2004 Till Adam <till@klaralvdalens-datakonsult.se>
8
This library is free software; you can redistribute it and/or
9
modify it under the terms of the GNU Library General Public
10
License as published by the Free Software Foundation; either
11
version 2 of the License, or (at your option) any later version.
13
This library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
Library General Public License for more details.
18
You should have received a copy of the GNU Library General Public License
19
along with this library; see the file COPYING.LIB. If not, write to
20
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
Boston, MA 02110-1301, USA.
23
In addition, as a special exception, the copyright holders give
24
permission to link the code of this program with any edition of
25
the Qt library by Trolltech AS, Norway (or with modified versions
26
of Qt that use the same license as Qt), and distribute linked
27
combinations including the two. You must obey the GNU General
28
Public License in all respects for all of the code used other than
29
Qt. If you modify this file, you may extend this exception to
30
your version of the file, but you are not obligated to do so. If
31
you do not wish to do so, delete this exception statement from
35
#ifndef KCAL_RESOURCEKOLAB_H
36
#define KCAL_RESOURCEKOLAB_H
41
#include <kcal/calendarlocal.h>
42
#include <kcal/icalformat.h>
43
#include <kcal/resourcecalendar.h>
44
#include "kcalkolab_export.h"
45
#include "../shared/resourcekolabbase.h"
49
struct TemporarySilencer;
51
class KCALKOLAB_EXPORT ResourceKolab : public KCal::ResourceCalendar,
52
public KCal::IncidenceBase::IncidenceObserver,
53
public Kolab::ResourceKolabBase
56
friend struct TemporarySilencer;
59
ResourceKolab( const KConfigGroup& );
62
virtual ~ResourceKolab();
64
/// Load resource data.
65
bool doLoad( bool syncCache );
67
/// Save resource data.
68
bool doSave( bool syncCache );
69
bool doSave( bool syncCache, KCal::Incidence *incidence );
71
/// Open the notes resource.
73
/// Close the notes resource.
76
// The libkcal functions. See the resource for descriptions
77
bool addEvent( KCal::Event* anEvent );
78
bool deleteEvent( KCal::Event* );
79
KCal::Event* event( const QString &UniqueStr );
80
KCal::Event::List rawEvents( EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
81
KCal::Event::List rawEventsForDate(
82
const QDate& date, const KDateTime::Spec& timespec = KDateTime::Spec(),
83
EventSortField sortField=EventSortUnsorted,
84
SortDirection sortDirection=SortDirectionAscending );
85
KCal::Event::List rawEventsForDate( const KDateTime& dt );
86
KCal::Event::List rawEvents( const QDate& start, const QDate& end,
87
const KDateTime::Spec& timespec = KDateTime::Spec(),
88
bool inclusive = false );
90
bool addTodo( KCal::Todo* todo );
91
bool deleteTodo( KCal::Todo* );
92
KCal::Todo* todo( const QString& uid );
93
KCal::Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
94
KCal::Todo::List rawTodosForDate( const QDate& date );
96
bool addJournal( KCal::Journal* );
97
bool deleteJournal( KCal::Journal* );
98
KCal::Journal* journal( const QString& uid );
99
KCal::Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
100
KCal::Journal::List rawJournalsForDate( const QDate &date );
102
KCal::Alarm::List alarms( const KDateTime& from, const KDateTime& to );
103
KCal::Alarm::List alarmsTo( const KDateTime& to );
105
void setTimeZoneId( const QString& tzid );
107
bool deleteIncidence( KCal::Incidence* i );
109
/// The ResourceKolabBase methods called by KMail
110
bool fromKMailAddIncidence( const QString& type, const QString& subResource,
111
quint32 sernum, int format, const QString& data );
112
void fromKMailDelIncidence( const QString& type, const QString& subResource,
113
const QString& uid );
114
void fromKMailRefresh( const QString& type, const QString& subResource );
116
/// Listen to KMail changes in the amount of sub resources
117
void fromKMailAddSubresource( const QString& type, const QString& subResource,
118
const QString& label, bool writable,
119
bool alarmRelevant );
120
void fromKMailDelSubresource( const QString& type, const QString& subResource );
122
void fromKMailAsyncLoadResult( const QMap<quint32, QString>& map,
124
const QString& folder );
126
/** Return the list of subresources. */
127
QStringList subresources() const;
129
bool canHaveSubresources() const { return true; }
131
/** Is this subresource active? */
132
bool subresourceActive( const QString& ) const;
133
/** (De)activate the subresource */
134
virtual void setSubresourceActive( const QString &, bool );
136
/** What is the label for this subresource? */
137
virtual QString labelForSubresource( const QString& resource ) const;
139
virtual QString subresourceIdentifier( KCal::Incidence *incidence );
141
//TODO need to implement them
142
virtual void deleteAllEvents() {}
143
virtual void deleteAllTodos(){}
144
virtual void deleteAllJournals(){}
145
virtual void setTimeSpec(const KDateTime::Spec&){}
146
virtual KDateTime::Spec timeSpec() const{ return KDateTime::UTC; }
147
virtual QString timeZoneId() const { return QString(); }
148
virtual void shiftTimes(const KDateTime::Spec&, const KDateTime::Spec&){}
150
virtual bool addSubresource( const QString& resource, const QString& parent );
151
virtual bool removeSubresource( const QString& resource );
153
QString subresourceType( const QString &resource );
158
void useGlobalMode();
160
void slotEmitResourceChanged();
164
* Return list of alarms which are relevant for the current user. These
165
* are the ones coming from folders which the user has "Administer" rights
167
KCal::Alarm::List relevantAlarms( const KCal::Alarm::List &alarms );
170
void removeIncidences( const QByteArray& incidenceType );
171
void resolveConflict( KCal::Incidence*, const QString& subresource, quint32 sernum );
172
void addIncidence( const char* mimetype, const QString& xml,
173
const QString& subResource, quint32 sernum );
175
bool addIncidence( KCal::Incidence* i, const QString& subresource,
178
void addEvent( const QString& xml, const QString& subresource,
180
void addTodo( const QString& xml, const QString& subresource,
182
void addJournal( const QString& xml, const QString& subresource,
186
bool loadAllEvents();
188
bool loadAllJournals();
190
bool doLoadAll( Kolab::ResourceMap& map, const char* mimetype );
192
/// Reimplemented from IncidenceBase::Observer to know when an incidence was changed
193
void incidenceUpdated( KCal::IncidenceBase* );
194
void incidenceUpdatedSilent( KCal::IncidenceBase* incidencebase);
196
bool openResource( KConfig& config, const char* contentType,
197
Kolab::ResourceMap& map );
198
void loadSubResourceConfig( KConfig& config, const QString& name,
199
const QString& label, bool writable,
200
bool alarmRelevant, Kolab::ResourceMap& subResource );
201
bool loadSubResource( const QString& subResource, const char* mimetype );
202
bool unloadSubResource( const QString& subResource );
204
QString configFile() const {
205
return ResourceKolabBase::configFile( "kcal" );
208
Kolab::ResourceMap* subResourceMap( const QString& contentsType );
210
bool sendKMailUpdate( KCal::IncidenceBase* incidence, const QString& _subresource,
214
KCal::CalendarLocal mCalendar;
216
// The list of subresources
217
Kolab::ResourceMap mEventSubResources, mTodoSubResources, mJournalSubResources;
219
bool mOpen; // If the resource is open, this is true
220
QHash<QString, KCal::IncidenceBase*> mPendingUpdates;
221
QTimer mResourceChangedTimer;
225
This map contains the association between a new added incidence
226
and the subresource it belongs to.
227
That's needed to return the correct mapping in subresourceIdentifier().
229
We can't trust on mUidMap here, because it contains only non-pending uids.
231
QMap<QString, QString> mNewIncidencesMap;
232
int mProgressDialogIncidenceLimit;
235
* If a user has a subresource for viewing another user's folder then it can happen
236
* that addIncidence(...) adds an incidence with an already existing UID.
238
* When this happens, addIncidence(...) sets a new random UID and stores the
239
* original UID using incidence->setSchedulingID(uid) because KCal doesn't
240
* allow two incidences to have the same UID.
242
* This map keeps track of the generated UIDs (which are local) so we can delete the
243
* right incidence inside fromKMailDelIncidence(...) whenever we sync.
245
* The key is originalUID,subResource and the value is the fake UID.
247
QMap< QPair<QString, QString>, QString > mOriginalUID2fakeUID;
251
struct TemporarySilencer {
252
TemporarySilencer( ResourceKolab *_resource )
254
resource = _resource;
255
oldValue = resource->mSilent;
256
resource->mSilent = true;
260
resource->mSilent = oldValue;
262
ResourceKolab *resource;
268
#endif // KCAL_RESOURCEKOLAB_H