summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.h1
-rw-r--r--libkcal/calendarlocal.cpp35
-rw-r--r--libkcal/calendarlocal.h2
-rw-r--r--libkcal/incidencebase.cpp8
-rw-r--r--libkcal/incidencebase.h1
5 files changed, 37 insertions, 10 deletions
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index 14a1a45..95477cd 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -1,378 +1,379 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#ifndef CALENDAR_H 22#ifndef CALENDAR_H
23#define CALENDAR_H 23#define CALENDAR_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qptrlist.h> 28#include <qptrlist.h>
29#include <qdict.h> 29#include <qdict.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "event.h" 32#include "event.h"
33#include "todo.h" 33#include "todo.h"
34#include "journal.h" 34#include "journal.h"
35#include "calfilter.h" 35#include "calfilter.h"
36 36
37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ 37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */
38 38
39class KConfig; 39class KConfig;
40 40
41namespace KCal { 41namespace KCal {
42 42
43 43
44/** 44/**
45 This is the main "calendar" object class for KOrganizer. It holds 45 This is the main "calendar" object class for KOrganizer. It holds
46 information like all appointments/events, user information, etc. etc. 46 information like all appointments/events, user information, etc. etc.
47 one calendar is associated with each CalendarView (@see calendarview.h). 47 one calendar is associated with each CalendarView (@see calendarview.h).
48 This is an abstract base class defining the interface to a calendar. It is 48 This is an abstract base class defining the interface to a calendar. It is
49 implemented by subclasses like @see CalendarLocal, which use different 49 implemented by subclasses like @see CalendarLocal, which use different
50 methods to store and access the data. 50 methods to store and access the data.
51 51
52 Ownership of events etc. is handled by the following policy: As soon as an 52 Ownership of events etc. is handled by the following policy: As soon as an
53 event (or any other subclass of IncidenceBase) object is added to the 53 event (or any other subclass of IncidenceBase) object is added to the
54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes 54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes
55 care of deleting it. All Events returned by the query functions are returned 55 care of deleting it. All Events returned by the query functions are returned
56 as pointers, that means all changes to the returned events are immediately 56 as pointers, that means all changes to the returned events are immediately
57 visible in the Calendar. You shouldn't delete any Event object you get from 57 visible in the Calendar. You shouldn't delete any Event object you get from
58 Calendar. 58 Calendar.
59*/ 59*/
60class Calendar : public QObject, public CustomProperties, 60class Calendar : public QObject, public CustomProperties,
61 public IncidenceBase::Observer 61 public IncidenceBase::Observer
62{ 62{
63 Q_OBJECT 63 Q_OBJECT
64public: 64public:
65 Calendar(); 65 Calendar();
66 Calendar(const QString &timeZoneId); 66 Calendar(const QString &timeZoneId);
67 virtual ~Calendar(); 67 virtual ~Calendar();
68 Incidence * undoIncidence() { return mUndoIncidence; }; 68 Incidence * undoIncidence() { return mUndoIncidence; };
69 bool undoDeleteIncidence(); 69 bool undoDeleteIncidence();
70 void deleteIncidence(Incidence *in); 70 void deleteIncidence(Incidence *in);
71 void resetTempSyncStat(); 71 void resetTempSyncStat();
72 void resetPilotStat(int id); 72 void resetPilotStat(int id);
73 /** 73 /**
74 Clears out the current calendar, freeing all used memory etc. 74 Clears out the current calendar, freeing all used memory etc.
75 */ 75 */
76 virtual void close() = 0; 76 virtual void close() = 0;
77 virtual void addCalendar( Calendar* ) = 0; 77 virtual void addCalendar( Calendar* ) = 0;
78 virtual bool addCalendarFile( QString name, int id ) = 0; 78 virtual bool addCalendarFile( QString name, int id ) = 0;
79 virtual bool mergeCalendarFile( QString name ) = 0; 79 virtual bool mergeCalendarFile( QString name ) = 0;
80 virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0;
80 virtual void setSyncEventsReadOnly() = 0; 81 virtual void setSyncEventsReadOnly() = 0;
81 virtual void stopAllTodos() = 0; 82 virtual void stopAllTodos() = 0;
82 83
83 /** 84 /**
84 Sync changes in memory to persistant storage. 85 Sync changes in memory to persistant storage.
85 */ 86 */
86 virtual void save() = 0; 87 virtual void save() = 0;
87 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 88 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
88 virtual void removeSyncInfo( QString syncProfile) = 0; 89 virtual void removeSyncInfo( QString syncProfile) = 0;
89 virtual bool isSaving() { return false; } 90 virtual bool isSaving() { return false; }
90 91
91 /** 92 /**
92 Return the owner of the calendar's full name. 93 Return the owner of the calendar's full name.
93 */ 94 */
94 const QString &getOwner() const; 95 const QString &getOwner() const;
95 /** 96 /**
96 Set the owner of the calendar. Should be owner's full name. 97 Set the owner of the calendar. Should be owner's full name.
97 */ 98 */
98 void setOwner( const QString &os ); 99 void setOwner( const QString &os );
99 /** 100 /**
100 Return the email address of the calendar owner. 101 Return the email address of the calendar owner.
101 */ 102 */
102 const QString &getEmail(); 103 const QString &getEmail();
103 /** 104 /**
104 Set the email address of the calendar owner. 105 Set the email address of the calendar owner.
105 */ 106 */
106 void setEmail( const QString & ); 107 void setEmail( const QString & );
107 108
108 /** 109 /**
109 Set time zone from a timezone string (e.g. -2:00) 110 Set time zone from a timezone string (e.g. -2:00)
110 */ 111 */
111 void setTimeZone( const QString &tz ); 112 void setTimeZone( const QString &tz );
112 /** 113 /**
113 Set time zone from a minutes value (e.g. -60) 114 Set time zone from a minutes value (e.g. -60)
114 */ 115 */
115 void setTimeZone( int tz ); 116 void setTimeZone( int tz );
116 /** 117 /**
117 Return time zone as offest in minutes. 118 Return time zone as offest in minutes.
118 */ 119 */
119 int getTimeZone() const; 120 int getTimeZone() const;
120 /** 121 /**
121 Compute an ISO 8601 format string from the time zone. 122 Compute an ISO 8601 format string from the time zone.
122 */ 123 */
123 QString getTimeZoneStr() const; 124 QString getTimeZoneStr() const;
124 /** 125 /**
125 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal 126 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal
126 values). 127 values).
127 */ 128 */
128 void setTimeZoneId( const QString & ); 129 void setTimeZoneId( const QString & );
129 /** 130 /**
130 Return time zone id. 131 Return time zone id.
131 */ 132 */
132 QString timeZoneId() const; 133 QString timeZoneId() const;
133 /** 134 /**
134 Use local time, not UTC or a time zone. 135 Use local time, not UTC or a time zone.
135 */ 136 */
136 void setLocalTime(); 137 void setLocalTime();
137 /** 138 /**
138 Return whether local time is being used. 139 Return whether local time is being used.
139 */ 140 */
140 bool isLocalTime() const; 141 bool isLocalTime() const;
141 142
142 /** 143 /**
143 Add an incidence to calendar. 144 Add an incidence to calendar.
144 145
145 @return true on success, false on error. 146 @return true on success, false on error.
146 */ 147 */
147 virtual bool addIncidence( Incidence * ); 148 virtual bool addIncidence( Incidence * );
148 149
149 // Adds an incidence and all relatedto incidences to the cal 150 // Adds an incidence and all relatedto incidences to the cal
150 void addIncidenceBranch( Incidence * ); 151 void addIncidenceBranch( Incidence * );
151 /** 152 /**
152 Return filtered list of all incidences of this calendar. 153 Return filtered list of all incidences of this calendar.
153 */ 154 */
154 virtual QPtrList<Incidence> incidences(); 155 virtual QPtrList<Incidence> incidences();
155 156
156 /** 157 /**
157 Return unfiltered list of all incidences of this calendar. 158 Return unfiltered list of all incidences of this calendar.
158 */ 159 */
159 virtual QPtrList<Incidence> rawIncidences(); 160 virtual QPtrList<Incidence> rawIncidences();
160 161
161 /** 162 /**
162 Adds a Event to this calendar object. 163 Adds a Event to this calendar object.
163 @param anEvent a pointer to the event to add 164 @param anEvent a pointer to the event to add
164 165
165 @return true on success, false on error. 166 @return true on success, false on error.
166 */ 167 */
167 virtual bool addEventNoDup( Event *event ) = 0; 168 virtual bool addEventNoDup( Event *event ) = 0;
168 virtual bool addAnniversaryNoDup( Event *event ) = 0; 169 virtual bool addAnniversaryNoDup( Event *event ) = 0;
169 virtual bool addEvent( Event *anEvent ) = 0; 170 virtual bool addEvent( Event *anEvent ) = 0;
170 /** 171 /**
171 Delete event from calendar. 172 Delete event from calendar.
172 */ 173 */
173 virtual void deleteEvent( Event * ) = 0; 174 virtual void deleteEvent( Event * ) = 0;
174 /** 175 /**
175 Retrieves an event on the basis of the unique string ID. 176 Retrieves an event on the basis of the unique string ID.
176 */ 177 */
177 virtual Event *event( const QString &UniqueStr ) = 0; 178 virtual Event *event( const QString &UniqueStr ) = 0;
178 virtual Event *event( QString, QString ) = 0; 179 virtual Event *event( QString, QString ) = 0;
179 /** 180 /**
180 Builds and then returns a list of all events that match for the 181 Builds and then returns a list of all events that match for the
181 date specified. useful for dayView, etc. etc. 182 date specified. useful for dayView, etc. etc.
182 The calendar filter is applied. 183 The calendar filter is applied.
183 */ 184 */
184 QPtrList<Event> events( const QDate &date, bool sorted = false); 185 QPtrList<Event> events( const QDate &date, bool sorted = false);
185 /** 186 /**
186 Get events, which occur on the given date. 187 Get events, which occur on the given date.
187 The calendar filter is applied. 188 The calendar filter is applied.
188 */ 189 */
189 QPtrList<Event> events( const QDateTime &qdt ); 190 QPtrList<Event> events( const QDateTime &qdt );
190 /** 191 /**
191 Get events in a range of dates. If inclusive is set to true, only events 192 Get events in a range of dates. If inclusive is set to true, only events
192 are returned, which are completely included in the range. 193 are returned, which are completely included in the range.
193 The calendar filter is applied. 194 The calendar filter is applied.
194 */ 195 */
195 QPtrList<Event> events( const QDate &start, const QDate &end, 196 QPtrList<Event> events( const QDate &start, const QDate &end,
196 bool inclusive = false); 197 bool inclusive = false);
197 /** 198 /**
198 Return filtered list of all events in calendar. 199 Return filtered list of all events in calendar.
199 */ 200 */
200 virtual QPtrList<Event> events(); 201 virtual QPtrList<Event> events();
201 /** 202 /**
202 Return unfiltered list of all events in calendar. 203 Return unfiltered list of all events in calendar.
203 */ 204 */
204 virtual QPtrList<Event> rawEvents() = 0; 205 virtual QPtrList<Event> rawEvents() = 0;
205 206
206 /** 207 /**
207 Add a todo to the todolist. 208 Add a todo to the todolist.
208 209
209 @return true on success, false on error. 210 @return true on success, false on error.
210 */ 211 */
211 virtual bool addTodo( Todo *todo ) = 0; 212 virtual bool addTodo( Todo *todo ) = 0;
212 virtual bool addTodoNoDup( Todo *todo ) = 0; 213 virtual bool addTodoNoDup( Todo *todo ) = 0;
213 /** 214 /**
214 Remove a todo from the todolist. 215 Remove a todo from the todolist.
215 */ 216 */
216 virtual void deleteTodo( Todo * ) = 0; 217 virtual void deleteTodo( Todo * ) = 0;
217 virtual void deleteJournal( Journal * ) = 0; 218 virtual void deleteJournal( Journal * ) = 0;
218 /** 219 /**
219 Return filterd list of todos. 220 Return filterd list of todos.
220 */ 221 */
221 virtual QPtrList<Todo> todos(); 222 virtual QPtrList<Todo> todos();
222 /** 223 /**
223 Searches todolist for an event with this unique string identifier, 224 Searches todolist for an event with this unique string identifier,
224 returns a pointer or null. 225 returns a pointer or null.
225 */ 226 */
226 virtual Todo *todo( const QString &uid ) = 0; 227 virtual Todo *todo( const QString &uid ) = 0;
227 virtual Todo *todo( QString, QString ) = 0; 228 virtual Todo *todo( QString, QString ) = 0;
228 /** 229 /**
229 Returns list of todos due on the specified date. 230 Returns list of todos due on the specified date.
230 */ 231 */
231 virtual QPtrList<Todo> todos( const QDate &date ) = 0; 232 virtual QPtrList<Todo> todos( const QDate &date ) = 0;
232 /** 233 /**
233 Return unfiltered list of todos. 234 Return unfiltered list of todos.
234 */ 235 */
235 virtual QPtrList<Todo> rawTodos() = 0; 236 virtual QPtrList<Todo> rawTodos() = 0;
236 237
237 /** 238 /**
238 Add a Journal entry to calendar. 239 Add a Journal entry to calendar.
239 240
240 @return true on success, false on error. 241 @return true on success, false on error.
241 */ 242 */
242 virtual bool addJournal( Journal * ) = 0; 243 virtual bool addJournal( Journal * ) = 0;
243 /** 244 /**
244 Return Journal for given date. 245 Return Journal for given date.
245 */ 246 */
246 virtual Journal *journal( const QDate & ) = 0; 247 virtual Journal *journal( const QDate & ) = 0;
247 virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; 248 virtual QPtrList<Journal> journals4Date( const QDate & ) = 0;
248 /** 249 /**
249 Return Journal with given UID. 250 Return Journal with given UID.
250 */ 251 */
251 virtual Journal *journal( const QString &UID ) = 0; 252 virtual Journal *journal( const QString &UID ) = 0;
252 /** 253 /**
253 Return list of all Journal entries. 254 Return list of all Journal entries.
254 */ 255 */
255 virtual QPtrList<Journal> journals() = 0; 256 virtual QPtrList<Journal> journals() = 0;
256 257
257 /** 258 /**
258 Searches all incidence types for an incidence with this unique 259 Searches all incidence types for an incidence with this unique
259 string identifier, returns a pointer or null. 260 string identifier, returns a pointer or null.
260 */ 261 */
261 Incidence* incidence( const QString&UID ); 262 Incidence* incidence( const QString&UID );
262 263
263 /** 264 /**
264 Setup relations for an incidence. 265 Setup relations for an incidence.
265 */ 266 */
266 virtual void setupRelations( Incidence * ); 267 virtual void setupRelations( Incidence * );
267 /** 268 /**
268 Remove all relations to an incidence 269 Remove all relations to an incidence
269 */ 270 */
270 virtual void removeRelations( Incidence * ); 271 virtual void removeRelations( Incidence * );
271 272
272 /** 273 /**
273 Set calendar filter, which filters events for the events() functions. 274 Set calendar filter, which filters events for the events() functions.
274 The Filter object is owned by the caller. 275 The Filter object is owned by the caller.
275 */ 276 */
276 void setFilter( CalFilter * ); 277 void setFilter( CalFilter * );
277 /** 278 /**
278 Return calendar filter. 279 Return calendar filter.
279 */ 280 */
280 CalFilter *filter(); 281 CalFilter *filter();
281 virtual QDateTime nextAlarm( int daysTo ) = 0; 282 virtual QDateTime nextAlarm( int daysTo ) = 0;
282 virtual QString nextSummary( ) const = 0; 283 virtual QString nextSummary( ) const = 0;
283 virtual void reInitAlarmSettings() = 0; 284 virtual void reInitAlarmSettings() = 0;
284 virtual QDateTime nextAlarmEventDateTime() const = 0; 285 virtual QDateTime nextAlarmEventDateTime() const = 0;
285 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; 286 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0;
286 /** 287 /**
287 Return all alarms, which ocur in the given time interval. 288 Return all alarms, which ocur in the given time interval.
288 */ 289 */
289 virtual Alarm::List alarms( const QDateTime &from, 290 virtual Alarm::List alarms( const QDateTime &from,
290 const QDateTime &to ) = 0; 291 const QDateTime &to ) = 0;
291 292
292 class Observer { 293 class Observer {
293 public: 294 public:
294 virtual void calendarModified( bool, Calendar * ) = 0; 295 virtual void calendarModified( bool, Calendar * ) = 0;
295 }; 296 };
296 297
297 void registerObserver( Observer * ); 298 void registerObserver( Observer * );
298 299
299 void setModified( bool ); 300 void setModified( bool );
300 301
301 /** 302 /**
302 Set product id returned by loadedProductId(). This function is only 303 Set product id returned by loadedProductId(). This function is only
303 useful for the calendar loading code. 304 useful for the calendar loading code.
304 */ 305 */
305 void setLoadedProductId( const QString & ); 306 void setLoadedProductId( const QString & );
306 /** 307 /**
307 Return product id taken from file that has been loaded. Returns 308 Return product id taken from file that has been loaded. Returns
308 QString::null, if no calendar has been loaded. 309 QString::null, if no calendar has been loaded.
309 */ 310 */
310 QString loadedProductId(); 311 QString loadedProductId();
311 int defaultCalendar(); 312 int defaultCalendar();
312 void setDontDeleteIncidencesOnClose (); 313 void setDontDeleteIncidencesOnClose ();
313 public slots: 314 public slots:
314 void setDefaultCalendar( int ); 315 void setDefaultCalendar( int );
315 virtual void setCalendarEnabled( int id, bool enable ) = 0; 316 virtual void setCalendarEnabled( int id, bool enable ) = 0;
316 virtual void setAlarmEnabled( int id, bool enable ) = 0; 317 virtual void setAlarmEnabled( int id, bool enable ) = 0;
317 virtual void setReadOnly( int id, bool enable ) = 0; 318 virtual void setReadOnly( int id, bool enable ) = 0;
318 virtual void setDefaultCalendarEnabledOnly() = 0; 319 virtual void setDefaultCalendarEnabledOnly() = 0;
319 virtual void setCalendarRemove( int id ) = 0; 320 virtual void setCalendarRemove( int id ) = 0;
320 signals: 321 signals:
321 void calendarChanged(); 322 void calendarChanged();
322 void calendarSaved(); 323 void calendarSaved();
323 void calendarLoaded(); 324 void calendarLoaded();
324 void addAlarm(const QDateTime &qdt, const QString &noti ); 325 void addAlarm(const QDateTime &qdt, const QString &noti );
325 void removeAlarm(const QDateTime &qdt, const QString &noti ); 326 void removeAlarm(const QDateTime &qdt, const QString &noti );
326 327
327 protected: 328 protected:
328 /** 329 /**
329 Get unfiltered events, which occur on the given date. 330 Get unfiltered events, which occur on the given date.
330 */ 331 */
331 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; 332 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
332 /** 333 /**
333 Get unfiltered events, which occur on the given date. 334 Get unfiltered events, which occur on the given date.
334 */ 335 */
335 virtual QPtrList<Event> rawEventsForDate( const QDate &date, 336 virtual QPtrList<Event> rawEventsForDate( const QDate &date,
336 bool sorted = false ) = 0; 337 bool sorted = false ) = 0;
337 /** 338 /**
338 Get events in a range of dates. If inclusive is set to true, only events 339 Get events in a range of dates. If inclusive is set to true, only events
339 are returned, which are completely included in the range. 340 are returned, which are completely included in the range.
340 */ 341 */
341 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 342 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
342 bool inclusive = false ) = 0; 343 bool inclusive = false ) = 0;
343 344
344 Incidence *mNextAlarmIncidence; 345 Incidence *mNextAlarmIncidence;
345 Incidence *mUndoIncidence; 346 Incidence *mUndoIncidence;
346 int mDefaultCalendar; 347 int mDefaultCalendar;
347 bool mDeleteIncidencesOnClose; 348 bool mDeleteIncidencesOnClose;
348 349
349private: 350private:
350 void init(); 351 void init();
351 352
352 QString mOwner; // who the calendar belongs to 353 QString mOwner; // who the calendar belongs to
353 QString mOwnerEmail; // email address of the owner 354 QString mOwnerEmail; // email address of the owner
354 int mTimeZone; // timezone OFFSET from GMT (MINUTES) 355 int mTimeZone; // timezone OFFSET from GMT (MINUTES)
355 bool mLocalTime; // use local time, not UTC or a time zone 356 bool mLocalTime; // use local time, not UTC or a time zone
356 357
357 358
358 CalFilter *mFilter; 359 CalFilter *mFilter;
359 CalFilter *mDefaultFilter; 360 CalFilter *mDefaultFilter;
360 361
361 362
362 QString mTimeZoneId; 363 QString mTimeZoneId;
363 364
364 Observer *mObserver; 365 Observer *mObserver;
365 bool mNewObserver; 366 bool mNewObserver;
366 367
367 bool mModified; 368 bool mModified;
368 369
369 QString mLoadedProductId; 370 QString mLoadedProductId;
370 371
371 // This list is used to put together related todos 372 // This list is used to put together related todos
372 QDict<Incidence> mOrphans; 373 QDict<Incidence> mOrphans;
373 QDict<Incidence> mOrphanUids; 374 QDict<Incidence> mOrphanUids;
374}; 375};
375 376
376} 377}
377 378
378#endif 379#endif
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 3e42ec0..e37a7ad 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,529 +1,548 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 if ( mDeleteIncidencesOnClose ) 68 if ( mDeleteIncidencesOnClose )
69 close(); 69 close();
70} 70}
71bool CalendarLocal::mergeCalendarFile( QString name ) 71bool CalendarLocal::mergeCalendarFile( QString name )
72{ 72{
73 CalendarLocal calendar( timeZoneId() ); 73 CalendarLocal calendar( timeZoneId() );
74 calendar.setDefaultCalendar( 1 ); 74 calendar.setDefaultCalendar( 1 );
75 if ( calendar.load( name ) ) { 75 if ( calendar.load( name ) ) {
76 mergeCalendar( &calendar ); 76 mergeCalendar( &calendar );
77 return true; 77 return true;
78 } 78 }
79 return false; 79 return false;
80} 80}
81 81
82Incidence* CalendarLocal::incidenceForUid( const QString& uid ) 82Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates)
83{ 83{
84 Todo *todo;; 84 Todo *todo;;
85 Incidence *retVal = 0; 85 Incidence *retVal = 0;
86 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 86 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
87 if ( todo->uid() == uid ) { 87 if ( todo->uid() == uid ) {
88 if ( doNotCheckDuplicates ) return todo;
88 if ( retVal ) { 89 if ( retVal ) {
89 if ( retVal->calID() > todo->calID() ) { 90 if ( retVal->calID() > todo->calID() ) {
90 retVal = todo; 91 retVal = todo;
91 } 92 }
92 } else { 93 } else {
93 retVal = todo; 94 retVal = todo;
94 } 95 }
95 } 96 }
96 } 97 }
97 if ( retVal ) return retVal; 98 if ( retVal ) return retVal;
98 Event *event; 99 Event *event;
99 for ( event = mEventList.first(); event; event = mEventList.next() ) { 100 for ( event = mEventList.first(); event; event = mEventList.next() ) {
100 if ( event->uid() == uid ) { 101 if ( event->uid() == uid ) {
102 if ( doNotCheckDuplicates ) return event;
101 if ( retVal ) { 103 if ( retVal ) {
102 if ( retVal->calID() > event->calID() ) { 104 if ( retVal->calID() > event->calID() ) {
103 retVal = event; 105 retVal = event;
104 } 106 }
105 } else { 107 } else {
106 retVal = event; 108 retVal = event;
107 } 109 }
108 } 110 }
109 } 111 }
110 if ( retVal ) return retVal; 112 if ( retVal ) return retVal;
111 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 113 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
112 if ( it->uid() == uid ) { 114 if ( it->uid() == uid ) {
115 if ( doNotCheckDuplicates ) return it;
113 if ( retVal ) { 116 if ( retVal ) {
114 if ( retVal->calID() > it->calID() ) { 117 if ( retVal->calID() > it->calID() ) {
115 retVal = it; 118 retVal = it;
116 } 119 }
117 } else { 120 } else {
118 retVal = it; 121 retVal = it;
119 } 122 }
120 } 123 }
121 return retVal; 124 return retVal;
122} 125}
123 126
124bool CalendarLocal::mergeCalendar( Calendar* remote ) 127bool CalendarLocal::mergeCalendar( Calendar* remote )
125{ 128{
129 // 1 look for raw inc in local
130 // if inc not in remote, delete in local
131 // 2 look for raw inc in remote
132 // if inc in local, replace it
133 // if not in local, add it to default calendar
134 QPtrList<Incidence> localInc = rawIncidences();
135 Incidence* inL = localInc.first();
136 while ( inL ) {
137 if ( ! inL->isReadOnly () )
138 if ( !remote->incidenceForUid( inL->uid(), true ))
139 deleteIncidence( inL );
140 inL = localInc.next();
141 }
126 QPtrList<Incidence> er = remote->rawIncidences(); 142 QPtrList<Incidence> er = remote->rawIncidences();
127 Incidence* inR = er.first(); 143 Incidence* inR = er.first();
128 Incidence* inL;
129 while ( inR ) { 144 while ( inR ) {
130 inL = incidenceForUid( inR->uid() ); 145 inL = incidenceForUid( inR->uid(),false );
131 if ( inL ) { 146 if ( inL ) {
132 int calID = inL->calID(); 147 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
133 deleteIncidence( inL ); 148 int calID = inL->calID();
134 inL = inR->clone(); 149 deleteIncidence( inL );
135 inL->setCalID( calID ); 150 inL = inR->clone();
136 addIncidence( inL ); 151 inL->setCalID( calID );
152 addIncidence( inL );
153 }
137 } else { 154 } else {
138 inL = inR->clone(); 155 inL = inR->clone();
139 inL->setCalID( 0 );// add to default cal 156 inL->setCalID( 0 );// add to default cal
140 addIncidence( inL ); 157 addIncidence( inL );
141 } 158 }
142 inR = er.next(); 159 inR = er.next();
143 } 160 }
144 return true; 161 return true;
145} 162}
163
164
146bool CalendarLocal::addCalendarFile( QString name, int id ) 165bool CalendarLocal::addCalendarFile( QString name, int id )
147{ 166{
148 CalendarLocal calendar( timeZoneId() ); 167 CalendarLocal calendar( timeZoneId() );
149 calendar.setDefaultCalendar( id ); 168 calendar.setDefaultCalendar( id );
150 if ( calendar.load( name ) ) { 169 if ( calendar.load( name ) ) {
151 addCalendar( &calendar ); 170 addCalendar( &calendar );
152 return true; 171 return true;
153 } 172 }
154 return false; 173 return false;
155} 174}
156void CalendarLocal::setSyncEventsReadOnly() 175void CalendarLocal::setSyncEventsReadOnly()
157{ 176{
158 Event * ev; 177 Event * ev;
159 ev = mEventList.first(); 178 ev = mEventList.first();
160 while ( ev ) { 179 while ( ev ) {
161 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 180 if ( ev->uid().left(15) == QString("last-syncEvent-") )
162 ev->setReadOnly( true ); 181 ev->setReadOnly( true );
163 ev = mEventList.next(); 182 ev = mEventList.next();
164 } 183 }
165} 184}
166void CalendarLocal::addCalendar( Calendar* cal ) 185void CalendarLocal::addCalendar( Calendar* cal )
167{ 186{
168 cal->setDontDeleteIncidencesOnClose(); 187 cal->setDontDeleteIncidencesOnClose();
169 { 188 {
170 QPtrList<Event> EventList = cal->rawEvents(); 189 QPtrList<Event> EventList = cal->rawEvents();
171 Event * ev = EventList.first(); 190 Event * ev = EventList.first();
172 while ( ev ) { 191 while ( ev ) {
173 ev->unRegisterObserver( cal ); 192 ev->unRegisterObserver( cal );
174 ev->registerObserver( this ); 193 ev->registerObserver( this );
175 mEventList.append( ev ); 194 mEventList.append( ev );
176 ev = EventList.next(); 195 ev = EventList.next();
177 } 196 }
178 } 197 }
179 { 198 {
180 199
181 QPtrList<Todo> TodoList = cal->rawTodos(); 200 QPtrList<Todo> TodoList = cal->rawTodos();
182 Todo * ev = TodoList.first(); 201 Todo * ev = TodoList.first();
183 while ( ev ) { 202 while ( ev ) {
184 QString rel = ev->relatedToUid(); 203 QString rel = ev->relatedToUid();
185 if ( !rel.isEmpty() ){ 204 if ( !rel.isEmpty() ){
186 ev->setRelatedTo ( 0 ); 205 ev->setRelatedTo ( 0 );
187 ev->setRelatedToUid( rel ); 206 ev->setRelatedToUid( rel );
188 } 207 }
189 ev = TodoList.next(); 208 ev = TodoList.next();
190 } 209 }
191 //TodoList = cal->rawTodos(); 210 //TodoList = cal->rawTodos();
192 ev = TodoList.first(); 211 ev = TodoList.first();
193 while ( ev ) { 212 while ( ev ) {
194 ev->unRegisterObserver( cal ); 213 ev->unRegisterObserver( cal );
195 ev->registerObserver( this ); 214 ev->registerObserver( this );
196 mTodoList.append( ev ); 215 mTodoList.append( ev );
197 setupRelations( ev ); 216 setupRelations( ev );
198 ev = TodoList.next(); 217 ev = TodoList.next();
199 } 218 }
200 } 219 }
201 { 220 {
202 QPtrList<Journal> JournalList = cal->journals(); 221 QPtrList<Journal> JournalList = cal->journals();
203 Journal * ev = JournalList.first(); 222 Journal * ev = JournalList.first();
204 while ( ev ) { 223 while ( ev ) {
205 ev->unRegisterObserver( cal ); 224 ev->unRegisterObserver( cal );
206 ev->registerObserver( this ); 225 ev->registerObserver( this );
207 mJournalList.append( ev ); 226 mJournalList.append( ev );
208 ev = JournalList.next(); 227 ev = JournalList.next();
209 } 228 }
210 } 229 }
211 setModified( true ); 230 setModified( true );
212} 231}
213bool CalendarLocal::load( const QString &fileName ) 232bool CalendarLocal::load( const QString &fileName )
214{ 233{
215 FileStorage storage( this, fileName ); 234 FileStorage storage( this, fileName );
216 return storage.load(); 235 return storage.load();
217} 236}
218 237
219bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 238bool CalendarLocal::save( const QString &fileName, CalFormat *format )
220{ 239{
221 FileStorage storage( this, fileName, format ); 240 FileStorage storage( this, fileName, format );
222 return storage.save(); 241 return storage.save();
223} 242}
224 243
225void CalendarLocal::stopAllTodos() 244void CalendarLocal::stopAllTodos()
226{ 245{
227 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 246 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
228 it->setRunning( false ); 247 it->setRunning( false );
229 248
230} 249}
231void CalendarLocal::close() 250void CalendarLocal::close()
232{ 251{
233 252
234 Todo * i; 253 Todo * i;
235 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 254 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
236 255
237 mEventList.setAutoDelete( true ); 256 mEventList.setAutoDelete( true );
238 mTodoList.setAutoDelete( true ); 257 mTodoList.setAutoDelete( true );
239 mJournalList.setAutoDelete( false ); 258 mJournalList.setAutoDelete( false );
240 259
241 mEventList.clear(); 260 mEventList.clear();
242 mTodoList.clear(); 261 mTodoList.clear();
243 mJournalList.clear(); 262 mJournalList.clear();
244 263
245 mEventList.setAutoDelete( false ); 264 mEventList.setAutoDelete( false );
246 mTodoList.setAutoDelete( false ); 265 mTodoList.setAutoDelete( false );
247 mJournalList.setAutoDelete( false ); 266 mJournalList.setAutoDelete( false );
248 267
249 setModified( false ); 268 setModified( false );
250} 269}
251 270
252bool CalendarLocal::addAnniversaryNoDup( Event *event ) 271bool CalendarLocal::addAnniversaryNoDup( Event *event )
253{ 272{
254 QString cat; 273 QString cat;
255 bool isBirthday = true; 274 bool isBirthday = true;
256 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 275 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
257 isBirthday = false; 276 isBirthday = false;
258 cat = i18n( "Anniversary" ); 277 cat = i18n( "Anniversary" );
259 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 278 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
260 isBirthday = true; 279 isBirthday = true;
261 cat = i18n( "Birthday" ); 280 cat = i18n( "Birthday" );
262 } else { 281 } else {
263 qDebug("addAnniversaryNoDup called without fitting category! "); 282 qDebug("addAnniversaryNoDup called without fitting category! ");
264 return false; 283 return false;
265 } 284 }
266 Event * eve; 285 Event * eve;
267 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 286 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
268 if ( !(eve->categories().contains( cat ) )) 287 if ( !(eve->categories().contains( cat ) ))
269 continue; 288 continue;
270 // now we have an event with fitting category 289 // now we have an event with fitting category
271 if ( eve->dtStart().date() != event->dtStart().date() ) 290 if ( eve->dtStart().date() != event->dtStart().date() )
272 continue; 291 continue;
273 // now we have an event with fitting category+date 292 // now we have an event with fitting category+date
274 if ( eve->summary() != event->summary() ) 293 if ( eve->summary() != event->summary() )
275 continue; 294 continue;
276 // now we have an event with fitting category+date+summary 295 // now we have an event with fitting category+date+summary
277 return false; 296 return false;
278 } 297 }
279 return addEvent( event ); 298 return addEvent( event );
280 299
281} 300}
282bool CalendarLocal::addEventNoDup( Event *event ) 301bool CalendarLocal::addEventNoDup( Event *event )
283{ 302{
284 Event * eve; 303 Event * eve;
285 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 304 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
286 if ( *eve == *event ) { 305 if ( *eve == *event ) {
287 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 306 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
288 return false; 307 return false;
289 } 308 }
290 } 309 }
291 return addEvent( event ); 310 return addEvent( event );
292} 311}
293 312
294bool CalendarLocal::addEvent( Event *event ) 313bool CalendarLocal::addEvent( Event *event )
295{ 314{
296 insertEvent( event ); 315 insertEvent( event );
297 316
298 event->registerObserver( this ); 317 event->registerObserver( this );
299 318
300 setModified( true ); 319 setModified( true );
301 if ( event->calID() == 0 ) 320 if ( event->calID() == 0 )
302 event->setCalID( mDefaultCalendar ); 321 event->setCalID( mDefaultCalendar );
303 event->setCalEnabled( true ); 322 event->setCalEnabled( true );
304 323
305 return true; 324 return true;
306} 325}
307 326
308void CalendarLocal::deleteEvent( Event *event ) 327void CalendarLocal::deleteEvent( Event *event )
309{ 328{
310 if ( mUndoIncidence ) delete mUndoIncidence; 329 if ( mUndoIncidence ) delete mUndoIncidence;
311 mUndoIncidence = event->clone(); 330 mUndoIncidence = event->clone();
312 if ( mEventList.removeRef( event ) ) { 331 if ( mEventList.removeRef( event ) ) {
313 setModified( true ); 332 setModified( true );
314 } 333 }
315} 334}
316 335
317 336
318Event *CalendarLocal::event( const QString &uid ) 337Event *CalendarLocal::event( const QString &uid )
319{ 338{
320 Event *event; 339 Event *event;
321 Event *retVal = 0; 340 Event *retVal = 0;
322 for ( event = mEventList.first(); event; event = mEventList.next() ) { 341 for ( event = mEventList.first(); event; event = mEventList.next() ) {
323 if ( event->calEnabled() && event->uid() == uid ) { 342 if ( event->calEnabled() && event->uid() == uid ) {
324 if ( retVal ) { 343 if ( retVal ) {
325 if ( retVal->calID() > event->calID() ) { 344 if ( retVal->calID() > event->calID() ) {
326 retVal = event; 345 retVal = event;
327 } 346 }
328 } else { 347 } else {
329 retVal = event; 348 retVal = event;
330 } 349 }
331 } 350 }
332 } 351 }
333 return retVal; 352 return retVal;
334} 353}
335bool CalendarLocal::addTodoNoDup( Todo *todo ) 354bool CalendarLocal::addTodoNoDup( Todo *todo )
336{ 355{
337 Todo * eve; 356 Todo * eve;
338 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 357 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
339 if ( *eve == *todo ) { 358 if ( *eve == *todo ) {
340 //qDebug("duplicate todo found! not inserted! "); 359 //qDebug("duplicate todo found! not inserted! ");
341 return false; 360 return false;
342 } 361 }
343 } 362 }
344 return addTodo( todo ); 363 return addTodo( todo );
345} 364}
346bool CalendarLocal::addTodo( Todo *todo ) 365bool CalendarLocal::addTodo( Todo *todo )
347{ 366{
348 mTodoList.append( todo ); 367 mTodoList.append( todo );
349 368
350 todo->registerObserver( this ); 369 todo->registerObserver( this );
351 370
352 // Set up subtask relations 371 // Set up subtask relations
353 setupRelations( todo ); 372 setupRelations( todo );
354 373
355 setModified( true ); 374 setModified( true );
356 if ( todo->calID() == 0 ) 375 if ( todo->calID() == 0 )
357 todo->setCalID( mDefaultCalendar ); 376 todo->setCalID( mDefaultCalendar );
358 todo->setCalEnabled( true ); 377 todo->setCalEnabled( true );
359 return true; 378 return true;
360} 379}
361 380
362void CalendarLocal::deleteTodo( Todo *todo ) 381void CalendarLocal::deleteTodo( Todo *todo )
363{ 382{
364 // Handle orphaned children 383 // Handle orphaned children
365 if ( mUndoIncidence ) delete mUndoIncidence; 384 if ( mUndoIncidence ) delete mUndoIncidence;
366 removeRelations( todo ); 385 removeRelations( todo );
367 mUndoIncidence = todo->clone(); 386 mUndoIncidence = todo->clone();
368 387
369 if ( mTodoList.removeRef( todo ) ) { 388 if ( mTodoList.removeRef( todo ) ) {
370 setModified( true ); 389 setModified( true );
371 } 390 }
372} 391}
373 392
374QPtrList<Todo> CalendarLocal::rawTodos() 393QPtrList<Todo> CalendarLocal::rawTodos()
375{ 394{
376 QPtrList<Todo> el; 395 QPtrList<Todo> el;
377 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 396 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
378 if ( it->calEnabled() ) el.append( it ); 397 if ( it->calEnabled() ) el.append( it );
379 return el; 398 return el;
380} 399}
381Todo *CalendarLocal::todo( QString syncProf, QString id ) 400Todo *CalendarLocal::todo( QString syncProf, QString id )
382{ 401{
383 Todo *todo; 402 Todo *todo;
384 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 403 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
385 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 404 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
386 } 405 }
387 406
388 return 0; 407 return 0;
389} 408}
390void CalendarLocal::removeSyncInfo( QString syncProfile) 409void CalendarLocal::removeSyncInfo( QString syncProfile)
391{ 410{
392 QPtrList<Incidence> all = rawIncidences() ; 411 QPtrList<Incidence> all = rawIncidences() ;
393 Incidence *inc; 412 Incidence *inc;
394 for ( inc = all.first(); inc; inc = all.next() ) { 413 for ( inc = all.first(); inc; inc = all.next() ) {
395 inc->removeID( syncProfile ); 414 inc->removeID( syncProfile );
396 } 415 }
397 if ( syncProfile.isEmpty() ) { 416 if ( syncProfile.isEmpty() ) {
398 QPtrList<Event> el; 417 QPtrList<Event> el;
399 Event *todo; 418 Event *todo;
400 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 419 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
401 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 420 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
402 el.append( todo ); 421 el.append( todo );
403 } 422 }
404 for ( todo = el.first(); todo; todo = el.next() ) { 423 for ( todo = el.first(); todo; todo = el.next() ) {
405 deleteIncidence ( todo ); 424 deleteIncidence ( todo );
406 } 425 }
407 } else { 426 } else {
408 Event *lse = event( "last-syncEvent-"+ syncProfile); 427 Event *lse = event( "last-syncEvent-"+ syncProfile);
409 if ( lse ) 428 if ( lse )
410 deleteIncidence ( lse ); 429 deleteIncidence ( lse );
411 } 430 }
412} 431}
413QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 432QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
414{ 433{
415 QPtrList<Event> el; 434 QPtrList<Event> el;
416 Event *todo; 435 Event *todo;
417 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 436 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
418 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 437 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
419 if ( todo->summary().left(3) == "E: " ) 438 if ( todo->summary().left(3) == "E: " )
420 el.append( todo ); 439 el.append( todo );
421 } 440 }
422 441
423 return el; 442 return el;
424 443
425} 444}
426Event *CalendarLocal::event( QString syncProf, QString id ) 445Event *CalendarLocal::event( QString syncProf, QString id )
427{ 446{
428 Event *todo; 447 Event *todo;
429 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 448 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
430 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 449 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
431 } 450 }
432 451
433 return 0; 452 return 0;
434} 453}
435Todo *CalendarLocal::todo( const QString &uid ) 454Todo *CalendarLocal::todo( const QString &uid )
436{ 455{
437 Todo *todo;; 456 Todo *todo;;
438 Todo *retVal = 0; 457 Todo *retVal = 0;
439 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 458 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
440 if ( todo->calEnabled() && todo->uid() == uid ) { 459 if ( todo->calEnabled() && todo->uid() == uid ) {
441 if ( retVal ) { 460 if ( retVal ) {
442 if ( retVal->calID() > todo->calID() ) { 461 if ( retVal->calID() > todo->calID() ) {
443 retVal = todo; 462 retVal = todo;
444 } 463 }
445 } else { 464 } else {
446 retVal = todo; 465 retVal = todo;
447 } 466 }
448 } 467 }
449 } 468 }
450 return retVal; 469 return retVal;
451} 470}
452QString CalendarLocal::nextSummary() const 471QString CalendarLocal::nextSummary() const
453{ 472{
454 return mNextSummary; 473 return mNextSummary;
455} 474}
456QDateTime CalendarLocal::nextAlarmEventDateTime() const 475QDateTime CalendarLocal::nextAlarmEventDateTime() const
457{ 476{
458 return mNextAlarmEventDateTime; 477 return mNextAlarmEventDateTime;
459} 478}
460void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 479void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
461{ 480{
462 //mNextAlarmIncidence 481 //mNextAlarmIncidence
463 //mNextAlarmDateTime 482 //mNextAlarmDateTime
464 //return mNextSummary; 483 //return mNextSummary;
465 //return mNextAlarmEventDateTime; 484 //return mNextAlarmEventDateTime;
466 bool newNextAlarm = false; 485 bool newNextAlarm = false;
467 bool computeNextAlarm = false; 486 bool computeNextAlarm = false;
468 bool ok; 487 bool ok;
469 int offset; 488 int offset;
470 QDateTime nextA; 489 QDateTime nextA;
471 // QString nextSum; 490 // QString nextSum;
472 //QDateTime nextEvent; 491 //QDateTime nextEvent;
473 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 492 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
474 computeNextAlarm = true; 493 computeNextAlarm = true;
475 } else { 494 } else {
476 if ( ! deleted ) { 495 if ( ! deleted ) {
477 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 496 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
478 if ( ok ) { 497 if ( ok ) {
479 if ( nextA < mNextAlarmDateTime ) { 498 if ( nextA < mNextAlarmDateTime ) {
480 deRegisterAlarm(); 499 deRegisterAlarm();
481 mNextAlarmDateTime = nextA; 500 mNextAlarmDateTime = nextA;
482 mNextSummary = incidence->summary(); 501 mNextSummary = incidence->summary();
483 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 502 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
484 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 503 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
485 newNextAlarm = true; 504 newNextAlarm = true;
486 mNextAlarmIncidence = incidence; 505 mNextAlarmIncidence = incidence;
487 } else { 506 } else {
488 if ( incidence == mNextAlarmIncidence ) { 507 if ( incidence == mNextAlarmIncidence ) {
489 computeNextAlarm = true; 508 computeNextAlarm = true;
490 } 509 }
491 } 510 }
492 } else { 511 } else {
493 if ( mNextAlarmIncidence == incidence ) { 512 if ( mNextAlarmIncidence == incidence ) {
494 computeNextAlarm = true; 513 computeNextAlarm = true;
495 } 514 }
496 } 515 }
497 } else { // deleted 516 } else { // deleted
498 if ( incidence == mNextAlarmIncidence ) { 517 if ( incidence == mNextAlarmIncidence ) {
499 computeNextAlarm = true; 518 computeNextAlarm = true;
500 } 519 }
501 } 520 }
502 } 521 }
503 if ( computeNextAlarm ) { 522 if ( computeNextAlarm ) {
504 deRegisterAlarm(); 523 deRegisterAlarm();
505 nextA = nextAlarm( 1000 ); 524 nextA = nextAlarm( 1000 );
506 if (! mNextAlarmIncidence ) { 525 if (! mNextAlarmIncidence ) {
507 return; 526 return;
508 } 527 }
509 newNextAlarm = true; 528 newNextAlarm = true;
510 } 529 }
511 if ( newNextAlarm ) 530 if ( newNextAlarm )
512 registerAlarm(); 531 registerAlarm();
513} 532}
514QString CalendarLocal:: getAlarmNotification() 533QString CalendarLocal:: getAlarmNotification()
515{ 534{
516 QString ret; 535 QString ret;
517 // this should not happen 536 // this should not happen
518 if (! mNextAlarmIncidence ) 537 if (! mNextAlarmIncidence )
519 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 538 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
520 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 539 Alarm* alarm = mNextAlarmIncidence->alarms().first();
521 if ( alarm->type() == Alarm::Procedure ) { 540 if ( alarm->type() == Alarm::Procedure ) {
522 ret = "proc_alarm" + alarm->programFile()+"+++"; 541 ret = "proc_alarm" + alarm->programFile()+"+++";
523 } else { 542 } else {
524 ret = "audio_alarm" +alarm->audioFile() +"+++"; 543 ret = "audio_alarm" +alarm->audioFile() +"+++";
525 } 544 }
526 ret += "cal_alarm"+ mNextSummary.left( 25 ); 545 ret += "cal_alarm"+ mNextSummary.left( 25 );
527 if ( mNextSummary.length() > 25 ) 546 if ( mNextSummary.length() > 25 )
528 ret += "\n" + mNextSummary.mid(25, 25 ); 547 ret += "\n" + mNextSummary.mid(25, 25 );
529 ret+= "\n"+mNextAlarmEventDateTimeString; 548 ret+= "\n"+mNextAlarmEventDateTimeString;
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index 23b0542..a7a85c8 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -1,230 +1,230 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22#ifndef KCAL_CALENDARLOCAL_H 22#ifndef KCAL_CALENDARLOCAL_H
23#define KCAL_CALENDARLOCAL_H 23#define KCAL_CALENDARLOCAL_H
24 24
25#include "calendar.h" 25#include "calendar.h"
26 26
27namespace KCal { 27namespace KCal {
28 28
29class CalFormat; 29class CalFormat;
30 30
31/** 31/**
32 This class provides a calendar stored as a local file. 32 This class provides a calendar stored as a local file.
33*/ 33*/
34class CalendarLocal : public Calendar 34class CalendarLocal : public Calendar
35{ 35{
36 public: 36 public:
37 /** 37 /**
38 Constructs a new calendar, with variables initialized to sane values. 38 Constructs a new calendar, with variables initialized to sane values.
39 */ 39 */
40 CalendarLocal(); 40 CalendarLocal();
41 /** 41 /**
42 Constructs a new calendar, with variables initialized to sane values. 42 Constructs a new calendar, with variables initialized to sane values.
43 */ 43 */
44 CalendarLocal( const QString &timeZoneId ); 44 CalendarLocal( const QString &timeZoneId );
45 ~CalendarLocal(); 45 ~CalendarLocal();
46 void addCalendar( Calendar* ); 46 void addCalendar( Calendar* );
47 bool addCalendarFile( QString name, int id ); 47 bool addCalendarFile( QString name, int id );
48 bool mergeCalendarFile( QString name ); 48 bool mergeCalendarFile( QString name );
49 bool mergeCalendar( Calendar* cal ); 49 bool mergeCalendar( Calendar* cal );
50 Incidence* incidenceForUid( const QString& uid ); 50 Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates );
51 void setSyncEventsReadOnly(); 51 void setSyncEventsReadOnly();
52 void stopAllTodos(); 52 void stopAllTodos();
53 /** 53 /**
54 Loads a calendar on disk in vCalendar or iCalendar format into the current 54 Loads a calendar on disk in vCalendar or iCalendar format into the current
55 calendar. Any information already present is lost. 55 calendar. Any information already present is lost.
56 @return true, if successfull, false on error. 56 @return true, if successfull, false on error.
57 @param fileName the name of the calendar on disk. 57 @param fileName the name of the calendar on disk.
58 */ 58 */
59 bool load( const QString &fileName ); 59 bool load( const QString &fileName );
60 /** 60 /**
61 Writes out the calendar to disk in the specified \a format. 61 Writes out the calendar to disk in the specified \a format.
62 CalendarLocal takes ownership of the CalFormat object. 62 CalendarLocal takes ownership of the CalFormat object.
63 @return true, if successfull, false on error. 63 @return true, if successfull, false on error.
64 @param fileName the name of the file 64 @param fileName the name of the file
65 */ 65 */
66 bool save( const QString &fileName, CalFormat *format = 0 ); 66 bool save( const QString &fileName, CalFormat *format = 0 );
67 67
68 /** 68 /**
69 Clears out the current calendar, freeing all used memory etc. etc. 69 Clears out the current calendar, freeing all used memory etc. etc.
70 */ 70 */
71 void close(); 71 void close();
72 72
73 void save() {} 73 void save() {}
74 74
75 /** 75 /**
76 Add Event to calendar. 76 Add Event to calendar.
77 */ 77 */
78 void removeSyncInfo( QString syncProfile); 78 void removeSyncInfo( QString syncProfile);
79 bool addAnniversaryNoDup( Event *event ); 79 bool addAnniversaryNoDup( Event *event );
80 bool addEventNoDup( Event *event ); 80 bool addEventNoDup( Event *event );
81 bool addEvent( Event *event ); 81 bool addEvent( Event *event );
82 /** 82 /**
83 Deletes an event from this calendar. 83 Deletes an event from this calendar.
84 */ 84 */
85 void deleteEvent( Event *event ); 85 void deleteEvent( Event *event );
86 86
87 /** 87 /**
88 Retrieves an event on the basis of the unique string ID. 88 Retrieves an event on the basis of the unique string ID.
89 */ 89 */
90 Event *event( const QString &uid ); 90 Event *event( const QString &uid );
91 /** 91 /**
92 Return unfiltered list of all events in calendar. 92 Return unfiltered list of all events in calendar.
93 */ 93 */
94 QPtrList<Event> rawEvents(); 94 QPtrList<Event> rawEvents();
95 QPtrList<Event> getExternLastSyncEvents(); 95 QPtrList<Event> getExternLastSyncEvents();
96 /** 96 /**
97 Add a todo to the todolist. 97 Add a todo to the todolist.
98 */ 98 */
99 bool addTodo( Todo *todo ); 99 bool addTodo( Todo *todo );
100 bool addTodoNoDup( Todo *todo ); 100 bool addTodoNoDup( Todo *todo );
101 /** 101 /**
102 Remove a todo from the todolist. 102 Remove a todo from the todolist.
103 */ 103 */
104 void deleteTodo( Todo * ); 104 void deleteTodo( Todo * );
105 /** 105 /**
106 Searches todolist for an event with this unique string identifier, 106 Searches todolist for an event with this unique string identifier,
107 returns a pointer or null. 107 returns a pointer or null.
108 */ 108 */
109 Todo *todo( const QString &uid ); 109 Todo *todo( const QString &uid );
110 /** 110 /**
111 Return list of all todos. 111 Return list of all todos.
112 */ 112 */
113 QPtrList<Todo> rawTodos(); 113 QPtrList<Todo> rawTodos();
114 /** 114 /**
115 Returns list of todos due on the specified date. 115 Returns list of todos due on the specified date.
116 */ 116 */
117 QPtrList<Todo> todos( const QDate &date ); 117 QPtrList<Todo> todos( const QDate &date );
118 /** 118 /**
119 Return list of all todos. 119 Return list of all todos.
120 120
121 Workaround because compiler does not recognize function of base class. 121 Workaround because compiler does not recognize function of base class.
122 */ 122 */
123 QPtrList<Todo> todos() { return Calendar::todos(); } 123 QPtrList<Todo> todos() { return Calendar::todos(); }
124 124
125 /** 125 /**
126 Add a Journal entry to calendar. 126 Add a Journal entry to calendar.
127 */ 127 */
128 bool addJournal( Journal * ); 128 bool addJournal( Journal * );
129 /** 129 /**
130 Remove a Journal from the calendar. 130 Remove a Journal from the calendar.
131 */ 131 */
132 void deleteJournal( Journal * ); 132 void deleteJournal( Journal * );
133 /** 133 /**
134 Return Journal for given date. 134 Return Journal for given date.
135 */ 135 */
136 Journal *journal( const QDate & ); 136 Journal *journal( const QDate & );
137 QPtrList<Journal> journals4Date( const QDate & ); 137 QPtrList<Journal> journals4Date( const QDate & );
138 /** 138 /**
139 Return Journal with given UID. 139 Return Journal with given UID.
140 */ 140 */
141 Journal *journal( const QString &uid ); 141 Journal *journal( const QString &uid );
142 /** 142 /**
143 Return list of all Journals stored in calendar. 143 Return list of all Journals stored in calendar.
144 */ 144 */
145 QPtrList<Journal> journals(); 145 QPtrList<Journal> journals();
146 146
147 /** 147 /**
148 Return all alarms, which ocur in the given time interval. 148 Return all alarms, which ocur in the given time interval.
149 */ 149 */
150 Alarm::List alarms( const QDateTime &from, const QDateTime &to ); 150 Alarm::List alarms( const QDateTime &from, const QDateTime &to );
151 151
152 /** 152 /**
153 Return all alarms, which ocur before given date. 153 Return all alarms, which ocur before given date.
154 */ 154 */
155 Alarm::List alarmsTo( const QDateTime &to ); 155 Alarm::List alarmsTo( const QDateTime &to );
156 156
157 QDateTime nextAlarm( int daysTo ) ; 157 QDateTime nextAlarm( int daysTo ) ;
158 QDateTime nextAlarmEventDateTime() const; 158 QDateTime nextAlarmEventDateTime() const;
159 void checkAlarmForIncidence( Incidence *, bool deleted ) ; 159 void checkAlarmForIncidence( Incidence *, bool deleted ) ;
160 void registerAlarm(); 160 void registerAlarm();
161 void deRegisterAlarm(); 161 void deRegisterAlarm();
162 QString getAlarmNotification(); 162 QString getAlarmNotification();
163 QString nextSummary() const ; 163 QString nextSummary() const ;
164 /** 164 /**
165 This method should be called whenever a Event is modified directly 165 This method should be called whenever a Event is modified directly
166 via it's pointer. It makes sure that the calendar is internally 166 via it's pointer. It makes sure that the calendar is internally
167 consistent. 167 consistent.
168 */ 168 */
169 void update( IncidenceBase *incidence ); 169 void update( IncidenceBase *incidence );
170 170
171 /** 171 /**
172 Builds and then returns a list of all events that match for the 172 Builds and then returns a list of all events that match for the
173 date specified. useful for dayView, etc. etc. 173 date specified. useful for dayView, etc. etc.
174 */ 174 */
175 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); 175 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false );
176 /** 176 /**
177 Get unfiltered events for date \a qdt. 177 Get unfiltered events for date \a qdt.
178 */ 178 */
179 QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); 179 QPtrList<Event> rawEventsForDate( const QDateTime &qdt );
180 /** 180 /**
181 Get unfiltered events in a range of dates. If inclusive is set to true, 181 Get unfiltered events in a range of dates. If inclusive is set to true,
182 only events are returned, which are completely included in the range. 182 only events are returned, which are completely included in the range.
183 */ 183 */
184 QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 184 QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
185 bool inclusive = false ); 185 bool inclusive = false );
186 Todo *todo( QString, QString ); 186 Todo *todo( QString, QString );
187 Event *event( QString, QString ); 187 Event *event( QString, QString );
188 188
189public slots: 189public slots:
190 void setCalendarEnabled( int id, bool enable ); 190 void setCalendarEnabled( int id, bool enable );
191 void setAlarmEnabled( int id, bool enable ); 191 void setAlarmEnabled( int id, bool enable );
192 void setReadOnly( int id, bool enable ); 192 void setReadOnly( int id, bool enable );
193 void setDefaultCalendarEnabledOnly(); 193 void setDefaultCalendarEnabledOnly();
194 void setCalendarRemove( int id ); 194 void setCalendarRemove( int id );
195 195
196 protected: 196 protected:
197 197
198 // Event* mNextAlarmEvent; 198 // Event* mNextAlarmEvent;
199 QString mNextSummary; 199 QString mNextSummary;
200 QString mNextAlarmEventDateTimeString; 200 QString mNextAlarmEventDateTimeString;
201 QString mLastAlarmNotificationString; 201 QString mLastAlarmNotificationString;
202 QDateTime mNextAlarmEventDateTime; 202 QDateTime mNextAlarmEventDateTime;
203 QDateTime mNextAlarmDateTime; 203 QDateTime mNextAlarmDateTime;
204 void reInitAlarmSettings(); 204 void reInitAlarmSettings();
205 205
206 /** Notification function of IncidenceBase::Observer. */ 206 /** Notification function of IncidenceBase::Observer. */
207 void incidenceUpdated( IncidenceBase *i ) { update( i ); } 207 void incidenceUpdated( IncidenceBase *i ) { update( i ); }
208 208
209 /** inserts an event into its "proper place" in the calendar. */ 209 /** inserts an event into its "proper place" in the calendar. */
210 void insertEvent( Event *event ); 210 void insertEvent( Event *event );
211 211
212 /** Append alarms of incidence in interval to list of alarms. */ 212 /** Append alarms of incidence in interval to list of alarms. */
213 void appendAlarms( Alarm::List &alarms, Incidence *incidence, 213 void appendAlarms( Alarm::List &alarms, Incidence *incidence,
214 const QDateTime &from, const QDateTime &to ); 214 const QDateTime &from, const QDateTime &to );
215 215
216 /** Append alarms of recurring events in interval to list of alarms. */ 216 /** Append alarms of recurring events in interval to list of alarms. */
217 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, 217 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence,
218 const QDateTime &from, const QDateTime &to ); 218 const QDateTime &from, const QDateTime &to );
219 219
220 private: 220 private:
221 void init(); 221 void init();
222 222
223 QPtrList<Event> mEventList; 223 QPtrList<Event> mEventList;
224 QPtrList<Todo> mTodoList; 224 QPtrList<Todo> mTodoList;
225 QPtrList<Journal> mJournalList; 225 QPtrList<Journal> mJournalList;
226}; 226};
227 227
228} 228}
229 229
230#endif 230#endif
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index dcead02..1a19f3e 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,472 +1,478 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 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 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24#include <kidmanager.h> 24#include <kidmanager.h>
25 25
26#include "calformat.h" 26#include "calformat.h"
27#include "syncdefines.h" 27#include "syncdefines.h"
28 28
29#include "incidencebase.h" 29#include "incidencebase.h"
30 30
31using namespace KCal; 31using namespace KCal;
32 32
33IncidenceBase::IncidenceBase() : 33IncidenceBase::IncidenceBase() :
34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
35 mPilotId(0), mSyncStatus(SYNCMOD) 35 mPilotId(0), mSyncStatus(SYNCMOD)
36{ 36{
37 blockLastModified = false;
37 setUid(CalFormat::createUniqueId()); 38 setUid(CalFormat::createUniqueId());
38 mOrganizer = ""; 39 mOrganizer = "";
39 mFloats = false; 40 mFloats = false;
40 mDuration = 0; 41 mDuration = 0;
41 mHasDuration = false; 42 mHasDuration = false;
42 mPilotId = 0; 43 mPilotId = 0;
43 mExternalId = ":"; 44 mExternalId = ":";
44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 45 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
45 mSyncStatus = 0; 46 mSyncStatus = 0;
46 mAttendees.setAutoDelete( true ); 47 mAttendees.setAutoDelete( true );
47 mCalEnabled = true; 48 mCalEnabled = true;
48 mAlarmEnabled = true; 49 mAlarmEnabled = true;
49 mCalID = 0; 50 mCalID = 0;
50} 51}
51 52
52IncidenceBase::IncidenceBase(const IncidenceBase &i) : 53IncidenceBase::IncidenceBase(const IncidenceBase &i) :
53 CustomProperties( i ) 54 CustomProperties( i )
54{ 55{
55 56
57 blockLastModified = false;
56 mReadOnly = i.mReadOnly; 58 mReadOnly = i.mReadOnly;
57 mDtStart = i.mDtStart; 59 mDtStart = i.mDtStart;
58 mDuration = i.mDuration; 60 mDuration = i.mDuration;
59 mHasDuration = i.mHasDuration; 61 mHasDuration = i.mHasDuration;
60 mOrganizer = i.mOrganizer; 62 mOrganizer = i.mOrganizer;
61 mUid = i.mUid; 63 mUid = i.mUid;
62 mCalEnabled = i.mCalEnabled; 64 mCalEnabled = i.mCalEnabled;
63 mAlarmEnabled = i.mAlarmEnabled; 65 mAlarmEnabled = i.mAlarmEnabled;
64 mCalID = i.mCalID; 66 mCalID = i.mCalID;
65 QPtrList<Attendee> attendees = i.attendees(); 67 QPtrList<Attendee> attendees = i.attendees();
66 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 68 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
67 mAttendees.append( new Attendee( *a ) ); 69 mAttendees.append( new Attendee( *a ) );
68 } 70 }
69 mFloats = i.mFloats; 71 mFloats = i.mFloats;
70 mLastModified = i.mLastModified; 72 mLastModified = i.mLastModified;
71 mPilotId = i.mPilotId; 73 mPilotId = i.mPilotId;
72 mTempSyncStat = i.mTempSyncStat; 74 mTempSyncStat = i.mTempSyncStat;
73 mSyncStatus = i.mSyncStatus; 75 mSyncStatus = i.mSyncStatus;
74 mExternalId = i.mExternalId; 76 mExternalId = i.mExternalId;
75 // The copied object is a new one, so it isn't observed by the observer 77 // The copied object is a new one, so it isn't observed by the observer
76 // of the original object. 78 // of the original object.
77 mObservers.clear(); 79 mObservers.clear();
78 80
79 mAttendees.setAutoDelete( true ); 81 mAttendees.setAutoDelete( true );
80} 82}
81 83
82IncidenceBase::~IncidenceBase() 84IncidenceBase::~IncidenceBase()
83{ 85{
84} 86}
85 87
86 88
87bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 89bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
88{ 90{
89 // do not compare mSyncStatus and mExternalId 91 // do not compare mSyncStatus and mExternalId
90 if( i1.attendees().count() != i2.attendees().count() ) { 92 if( i1.attendees().count() != i2.attendees().count() ) {
91 return false; // no need to check further 93 return false; // no need to check further
92 } 94 }
93 if ( i1.attendees().count() > 0 ) { 95 if ( i1.attendees().count() > 0 ) {
94 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 96 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
95 while ( a1 ) { 97 while ( a1 ) {
96 if ( !( (*a1) == (*a2)) ) 98 if ( !( (*a1) == (*a2)) )
97 { 99 {
98 //qDebug("Attendee not equal "); 100 //qDebug("Attendee not equal ");
99 return false; 101 return false;
100 } 102 }
101 a1 = i1.attendees().next(); 103 a1 = i1.attendees().next();
102 a2 = i2.attendees().next(); 104 a2 = i2.attendees().next();
103 } 105 }
104 } 106 }
105 //if ( i1.dtStart() != i2.dtStart() ) 107 //if ( i1.dtStart() != i2.dtStart() )
106 // return false; 108 // return false;
107#if 0 109#if 0
108 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 110 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
109 qDebug("1 %d ",i1.duration() == i2.duration() ); 111 qDebug("1 %d ",i1.duration() == i2.duration() );
110 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 112 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
111 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 113 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
112 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 114 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
113 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 115 qDebug("6 %d ",i1.organizer() == i2.organizer() );
114 116
115#endif 117#endif
116 if ( i1.hasDuration() == i2.hasDuration() ) { 118 if ( i1.hasDuration() == i2.hasDuration() ) {
117 if ( i1.hasDuration() ) { 119 if ( i1.hasDuration() ) {
118 if ( i1.duration() != i2.duration() ) 120 if ( i1.duration() != i2.duration() )
119 return false; 121 return false;
120 } 122 }
121 } else { 123 } else {
122 return false; 124 return false;
123 } 125 }
124 126
125 return ( i1.organizer() == i2.organizer() && 127 return ( i1.organizer() == i2.organizer() &&
126 // i1.uid() == i2.uid() && 128 // i1.uid() == i2.uid() &&
127 // Don't compare lastModified, otherwise the operator is not 129 // Don't compare lastModified, otherwise the operator is not
128 // of much use. We are not comparing for identity, after all. 130 // of much use. We are not comparing for identity, after all.
129 i1.doesFloat() == i2.doesFloat() && 131 i1.doesFloat() == i2.doesFloat() &&
130 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 132 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
131 // no need to compare mObserver 133 // no need to compare mObserver
132} 134}
133 135
134 136
135QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 137QDateTime IncidenceBase::getEvenTime( QDateTime dt )
136{ 138{
137 QTime t = dt.time(); 139 QTime t = dt.time();
138 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 140 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
139 return dt; 141 return dt;
140} 142}
141 143
142bool IncidenceBase::isTagged() const 144bool IncidenceBase::isTagged() const
143{ 145{
144 return mIsTagged; 146 return mIsTagged;
145} 147}
146void IncidenceBase::setTagged( bool b) 148void IncidenceBase::setTagged( bool b)
147{ 149{
148 mIsTagged = b; 150 mIsTagged = b;
149} 151}
150void IncidenceBase::setCalID( int id ) 152void IncidenceBase::setCalID( int id )
151{ 153{
152 if ( mCalID > 0 ) 154 if ( mCalID > 0 ) {
155 blockLastModified = true;
153 updated(); 156 updated();
157 blockLastModified = false;
158 }
154 mCalID = id; 159 mCalID = id;
155} 160}
156int IncidenceBase::calID() const 161int IncidenceBase::calID() const
157{ 162{
158 return mCalID; 163 return mCalID;
159} 164}
160void IncidenceBase::setCalEnabled( bool b ) 165void IncidenceBase::setCalEnabled( bool b )
161{ 166{
162 mCalEnabled = b; 167 mCalEnabled = b;
163} 168}
164bool IncidenceBase::calEnabled() const 169bool IncidenceBase::calEnabled() const
165{ 170{
166 return mCalEnabled; 171 return mCalEnabled;
167} 172}
168 173
169void IncidenceBase::setAlarmEnabled( bool b ) 174void IncidenceBase::setAlarmEnabled( bool b )
170{ 175{
171 mAlarmEnabled = b; 176 mAlarmEnabled = b;
172} 177}
173bool IncidenceBase::alarmEnabled() const 178bool IncidenceBase::alarmEnabled() const
174{ 179{
175 return mAlarmEnabled; 180 return mAlarmEnabled;
176} 181}
177 182
178 183
179void IncidenceBase::setUid(const QString &uid) 184void IncidenceBase::setUid(const QString &uid)
180{ 185{
181 mUid = uid; 186 mUid = uid;
182 updated(); 187 updated();
183} 188}
184 189
185QString IncidenceBase::uid() const 190QString IncidenceBase::uid() const
186{ 191{
187 return mUid; 192 return mUid;
188} 193}
189 194
190void IncidenceBase::setLastModified(const QDateTime &lm) 195void IncidenceBase::setLastModified(const QDateTime &lm)
191{ 196{
197 if ( blockLastModified ) return;
192 // DON'T! updated() because we call this from 198 // DON'T! updated() because we call this from
193 // Calendar::updateEvent(). 199 // Calendar::updateEvent().
194 mLastModified = getEvenTime(lm); 200 mLastModified = getEvenTime(lm);
195 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 201 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
196} 202}
197 203
198QDateTime IncidenceBase::lastModified() const 204QDateTime IncidenceBase::lastModified() const
199{ 205{
200 return mLastModified; 206 return mLastModified;
201} 207}
202 208
203void IncidenceBase::setOrganizer(const QString &o) 209void IncidenceBase::setOrganizer(const QString &o)
204{ 210{
205 // we don't check for readonly here, because it is 211 // we don't check for readonly here, because it is
206 // possible that by setting the organizer we are changing 212 // possible that by setting the organizer we are changing
207 // the event's readonly status... 213 // the event's readonly status...
208 mOrganizer = o; 214 mOrganizer = o;
209 if (mOrganizer.left(7).upper() == "MAILTO:") 215 if (mOrganizer.left(7).upper() == "MAILTO:")
210 mOrganizer = mOrganizer.remove(0,7); 216 mOrganizer = mOrganizer.remove(0,7);
211 217
212 updated(); 218 updated();
213} 219}
214 220
215QString IncidenceBase::organizer() const 221QString IncidenceBase::organizer() const
216{ 222{
217 return mOrganizer; 223 return mOrganizer;
218} 224}
219 225
220void IncidenceBase::setReadOnly( bool readOnly ) 226void IncidenceBase::setReadOnly( bool readOnly )
221{ 227{
222 mReadOnly = readOnly; 228 mReadOnly = readOnly;
223} 229}
224 230
225void IncidenceBase::setDtStart(const QDateTime &dtStart) 231void IncidenceBase::setDtStart(const QDateTime &dtStart)
226{ 232{
227// if (mReadOnly) return; 233// if (mReadOnly) return;
228 mDtStart = getEvenTime(dtStart); 234 mDtStart = getEvenTime(dtStart);
229 updated(); 235 updated();
230} 236}
231 237
232 238
233QDateTime IncidenceBase::dtStart() const 239QDateTime IncidenceBase::dtStart() const
234{ 240{
235 return mDtStart; 241 return mDtStart;
236} 242}
237 243
238QString IncidenceBase::dtStartTimeStr() const 244QString IncidenceBase::dtStartTimeStr() const
239{ 245{
240 return KGlobal::locale()->formatTime(dtStart().time()); 246 return KGlobal::locale()->formatTime(dtStart().time());
241} 247}
242 248
243QString IncidenceBase::dtStartDateStr(bool shortfmt) const 249QString IncidenceBase::dtStartDateStr(bool shortfmt) const
244{ 250{
245 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 251 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
246} 252}
247 253
248QString IncidenceBase::dtStartStr(bool shortfmt) const 254QString IncidenceBase::dtStartStr(bool shortfmt) const
249{ 255{
250 if ( doesFloat() ) 256 if ( doesFloat() )
251 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 257 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
252 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 258 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
253} 259}
254 260
255 261
256bool IncidenceBase::doesFloat() const 262bool IncidenceBase::doesFloat() const
257{ 263{
258 return mFloats; 264 return mFloats;
259} 265}
260 266
261void IncidenceBase::setFloats(bool f) 267void IncidenceBase::setFloats(bool f)
262{ 268{
263 if (mReadOnly) return; 269 if (mReadOnly) return;
264 mFloats = f; 270 mFloats = f;
265 updated(); 271 updated();
266} 272}
267 273
268 274
269bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) 275bool IncidenceBase::addAttendee(Attendee *a, bool doupdate)
270{ 276{
271 if (mReadOnly) return false; 277 if (mReadOnly) return false;
272 if (a->name().left(7).upper() == "MAILTO:") 278 if (a->name().left(7).upper() == "MAILTO:")
273 a->setName(a->name().remove(0,7)); 279 a->setName(a->name().remove(0,7));
274 280
275 QPtrListIterator<Attendee> qli(mAttendees); 281 QPtrListIterator<Attendee> qli(mAttendees);
276 282
277 qli.toFirst(); 283 qli.toFirst();
278 while (qli) { 284 while (qli) {
279 if (*qli.current() == *a) 285 if (*qli.current() == *a)
280 return false; 286 return false;
281 ++qli; 287 ++qli;
282 } 288 }
283 mAttendees.append(a); 289 mAttendees.append(a);
284 if (doupdate) updated(); 290 if (doupdate) updated();
285 return true; 291 return true;
286} 292}
287 293
288#if 0 294#if 0
289void IncidenceBase::removeAttendee(Attendee *a) 295void IncidenceBase::removeAttendee(Attendee *a)
290{ 296{
291 if (mReadOnly) return; 297 if (mReadOnly) return;
292 mAttendees.removeRef(a); 298 mAttendees.removeRef(a);
293 updated(); 299 updated();
294} 300}
295 301
296void IncidenceBase::removeAttendee(const char *n) 302void IncidenceBase::removeAttendee(const char *n)
297{ 303{
298 Attendee *a; 304 Attendee *a;
299 305
300 if (mReadOnly) return; 306 if (mReadOnly) return;
301 for (a = mAttendees.first(); a; a = mAttendees.next()) 307 for (a = mAttendees.first(); a; a = mAttendees.next())
302 if (a->getName() == n) { 308 if (a->getName() == n) {
303 mAttendees.remove(); 309 mAttendees.remove();
304 break; 310 break;
305 } 311 }
306} 312}
307#endif 313#endif
308 314
309void IncidenceBase::clearAttendees() 315void IncidenceBase::clearAttendees()
310{ 316{
311 if (mReadOnly) return; 317 if (mReadOnly) return;
312 mAttendees.clear(); 318 mAttendees.clear();
313} 319}
314 320
315#if 0 321#if 0
316Attendee *IncidenceBase::getAttendee(const char *n) const 322Attendee *IncidenceBase::getAttendee(const char *n) const
317{ 323{
318 QPtrListIterator<Attendee> qli(mAttendees); 324 QPtrListIterator<Attendee> qli(mAttendees);
319 325
320 qli.toFirst(); 326 qli.toFirst();
321 while (qli) { 327 while (qli) {
322 if (qli.current()->getName() == n) 328 if (qli.current()->getName() == n)
323 return qli.current(); 329 return qli.current();
324 ++qli; 330 ++qli;
325 } 331 }
326 return 0L; 332 return 0L;
327} 333}
328#endif 334#endif
329 335
330Attendee *IncidenceBase::attendeeByMail(const QString &email) 336Attendee *IncidenceBase::attendeeByMail(const QString &email)
331{ 337{
332 QPtrListIterator<Attendee> qli(mAttendees); 338 QPtrListIterator<Attendee> qli(mAttendees);
333 339
334 qli.toFirst(); 340 qli.toFirst();
335 while (qli) { 341 while (qli) {
336 if (qli.current()->email().lower() == email.lower()) 342 if (qli.current()->email().lower() == email.lower())
337 return qli.current(); 343 return qli.current();
338 ++qli; 344 ++qli;
339 } 345 }
340 return 0L; 346 return 0L;
341} 347}
342 348
343Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 349Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
344{ 350{
345 QPtrListIterator<Attendee> qli(mAttendees); 351 QPtrListIterator<Attendee> qli(mAttendees);
346 352
347 QStringList mails = emails; 353 QStringList mails = emails;
348 if (!email.isEmpty()) { 354 if (!email.isEmpty()) {
349 mails.append(email); 355 mails.append(email);
350 } 356 }
351 qli.toFirst(); 357 qli.toFirst();
352 while (qli) { 358 while (qli) {
353 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 359 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
354 if (qli.current()->email().lower() == (*it).lower()) 360 if (qli.current()->email().lower() == (*it).lower())
355 return qli.current(); 361 return qli.current();
356 } 362 }
357 363
358 ++qli; 364 ++qli;
359 } 365 }
360 return 0L; 366 return 0L;
361} 367}
362 368
363void IncidenceBase::setDuration(int seconds) 369void IncidenceBase::setDuration(int seconds)
364{ 370{
365 mDuration = seconds; 371 mDuration = seconds;
366 setHasDuration(true); 372 setHasDuration(true);
367} 373}
368 374
369int IncidenceBase::duration() const 375int IncidenceBase::duration() const
370{ 376{
371 return mDuration; 377 return mDuration;
372} 378}
373 379
374void IncidenceBase::setHasDuration(bool b) 380void IncidenceBase::setHasDuration(bool b)
375{ 381{
376 mHasDuration = b; 382 mHasDuration = b;
377} 383}
378 384
379bool IncidenceBase::hasDuration() const 385bool IncidenceBase::hasDuration() const
380{ 386{
381 return mHasDuration; 387 return mHasDuration;
382} 388}
383 389
384void IncidenceBase::setSyncStatus(int stat) 390void IncidenceBase::setSyncStatus(int stat)
385{ 391{
386 if (mReadOnly) return; 392 if (mReadOnly) return;
387 mSyncStatus = stat; 393 mSyncStatus = stat;
388} 394}
389 395
390int IncidenceBase::syncStatus() const 396int IncidenceBase::syncStatus() const
391{ 397{
392 return mSyncStatus; 398 return mSyncStatus;
393} 399}
394 400
395void IncidenceBase::setPilotId( int id ) 401void IncidenceBase::setPilotId( int id )
396{ 402{
397 if (mReadOnly) return; 403 if (mReadOnly) return;
398 mPilotId = id; 404 mPilotId = id;
399} 405}
400 406
401int IncidenceBase::pilotId() const 407int IncidenceBase::pilotId() const
402{ 408{
403 return mPilotId; 409 return mPilotId;
404} 410}
405 411
406int IncidenceBase::tempSyncStat() const 412int IncidenceBase::tempSyncStat() const
407{ 413{
408 return mTempSyncStat; 414 return mTempSyncStat;
409} 415}
410void IncidenceBase::setTempSyncStat( int id ) 416void IncidenceBase::setTempSyncStat( int id )
411{ 417{
412 if (mReadOnly) return; 418 if (mReadOnly) return;
413 mTempSyncStat = id; 419 mTempSyncStat = id;
414} 420}
415 421
416void IncidenceBase::removeID(const QString &prof) 422void IncidenceBase::removeID(const QString &prof)
417{ 423{
418 if ( prof.isEmpty() ) 424 if ( prof.isEmpty() )
419 mExternalId = ":"; 425 mExternalId = ":";
420 else 426 else
421 mExternalId = KIdManager::removeId ( mExternalId, prof); 427 mExternalId = KIdManager::removeId ( mExternalId, prof);
422 428
423} 429}
424void IncidenceBase::setID( const QString & prof , const QString & id ) 430void IncidenceBase::setID( const QString & prof , const QString & id )
425{ 431{
426 mExternalId = KIdManager::setId ( mExternalId, prof, id ); 432 mExternalId = KIdManager::setId ( mExternalId, prof, id );
427} 433}
428QString IncidenceBase::getID( const QString & prof) 434QString IncidenceBase::getID( const QString & prof)
429{ 435{
430 return KIdManager::getId ( mExternalId, prof ); 436 return KIdManager::getId ( mExternalId, prof );
431} 437}
432 438
433// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: 439// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0:
434// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 440// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0
435void IncidenceBase::setCsum( const QString & prof , const QString & id ) 441void IncidenceBase::setCsum( const QString & prof , const QString & id )
436{ 442{
437 mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); 443 mExternalId = KIdManager::setCsum ( mExternalId, prof, id );
438} 444}
439QString IncidenceBase::getCsum( const QString & prof) 445QString IncidenceBase::getCsum( const QString & prof)
440{ 446{
441 return KIdManager::getCsum ( mExternalId, prof ); 447 return KIdManager::getCsum ( mExternalId, prof );
442} 448}
443 449
444void IncidenceBase::setIDStr( const QString & s ) 450void IncidenceBase::setIDStr( const QString & s )
445{ 451{
446 if (mReadOnly) return; 452 if (mReadOnly) return;
447 mExternalId = s; 453 mExternalId = s;
448} 454}
449 455
450QString IncidenceBase::IDStr() const 456QString IncidenceBase::IDStr() const
451{ 457{
452 return mExternalId ; 458 return mExternalId ;
453} 459}
454void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) 460void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
455{ 461{
456 if( !mObservers.contains(observer) ) mObservers.append( observer ); 462 if( !mObservers.contains(observer) ) mObservers.append( observer );
457} 463}
458 464
459void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) 465void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
460{ 466{
461 mObservers.remove( observer ); 467 mObservers.remove( observer );
462} 468}
463 469
464void IncidenceBase::updated() 470void IncidenceBase::updated()
465{ 471{
466 QPtrListIterator<Observer> it(mObservers); 472 QPtrListIterator<Observer> it(mObservers);
467 while( it.current() ) { 473 while( it.current() ) {
468 Observer *o = it.current(); 474 Observer *o = it.current();
469 ++it; 475 ++it;
470 o->incidenceUpdated( this ); 476 o->incidenceUpdated( this );
471 } 477 }
472} 478}
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index bccf287..bed73db 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -1,185 +1,186 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 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 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20#ifndef KCAL_INCIDENCEBASE_H 20#ifndef KCAL_INCIDENCEBASE_H
21#define KCAL_INCIDENCEBASE_H 21#define KCAL_INCIDENCEBASE_H
22// 22//
23// Incidence - base class of calendaring components 23// Incidence - base class of calendaring components
24// 24//
25 25
26#include <qdatetime.h> 26#include <qdatetime.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qvaluelist.h> 28#include <qvaluelist.h>
29#include <qptrlist.h> 29#include <qptrlist.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "attendee.h" 32#include "attendee.h"
33 33
34namespace KCal { 34namespace KCal {
35 35
36typedef QValueList<QDate> DateList; 36typedef QValueList<QDate> DateList;
37 enum IncTypeID { eventID,todoID,journalID,freebusyID }; 37 enum IncTypeID { eventID,todoID,journalID,freebusyID };
38 38
39/** 39/**
40 This class provides the base class common to all calendar components. 40 This class provides the base class common to all calendar components.
41*/ 41*/
42class IncidenceBase : public CustomProperties 42class IncidenceBase : public CustomProperties
43{ 43{
44 public: 44 public:
45 class Observer { 45 class Observer {
46 public: 46 public:
47 virtual void incidenceUpdated( IncidenceBase * ) = 0; 47 virtual void incidenceUpdated( IncidenceBase * ) = 0;
48 }; 48 };
49 49
50 IncidenceBase(); 50 IncidenceBase();
51 IncidenceBase(const IncidenceBase &); 51 IncidenceBase(const IncidenceBase &);
52 virtual ~IncidenceBase(); 52 virtual ~IncidenceBase();
53 53
54 virtual QCString type() const = 0; 54 virtual QCString type() const = 0;
55 virtual IncTypeID typeID() const = 0; 55 virtual IncTypeID typeID() const = 0;
56 56
57 /** Set the unique id for the event */ 57 /** Set the unique id for the event */
58 void setUid(const QString &); 58 void setUid(const QString &);
59 /** Return the unique id for the event */ 59 /** Return the unique id for the event */
60 QString uid() const; 60 QString uid() const;
61 61
62 /** Sets the time the incidence was last modified. */ 62 /** Sets the time the incidence was last modified. */
63 void setLastModified(const QDateTime &lm); 63 void setLastModified(const QDateTime &lm);
64 /** Return the time the incidence was last modified. */ 64 /** Return the time the incidence was last modified. */
65 QDateTime lastModified() const; 65 QDateTime lastModified() const;
66 66
67 /** sets the organizer for the event */ 67 /** sets the organizer for the event */
68 void setOrganizer(const QString &o); 68 void setOrganizer(const QString &o);
69 QString organizer() const; 69 QString organizer() const;
70 70
71 /** Set readonly status. */ 71 /** Set readonly status. */
72 virtual void setReadOnly( bool ); 72 virtual void setReadOnly( bool );
73 /** Return if the object is read-only. */ 73 /** Return if the object is read-only. */
74 bool isReadOnly() const { return mReadOnly; } 74 bool isReadOnly() const { return mReadOnly; }
75 75
76 /** for setting the event's starting date/time with a QDateTime. */ 76 /** for setting the event's starting date/time with a QDateTime. */
77 virtual void setDtStart(const QDateTime &dtStart); 77 virtual void setDtStart(const QDateTime &dtStart);
78 /** returns an event's starting date/time as a QDateTime. */ 78 /** returns an event's starting date/time as a QDateTime. */
79 virtual QDateTime dtStart() const; 79 virtual QDateTime dtStart() const;
80 /** returns an event's starting time as a string formatted according to the 80 /** returns an event's starting time as a string formatted according to the
81 users locale settings */ 81 users locale settings */
82 QString dtStartTimeStr() const; 82 QString dtStartTimeStr() const;
83 /** returns an event's starting date as a string formatted according to the 83 /** returns an event's starting date as a string formatted according to the
84 users locale settings */ 84 users locale settings */
85 QString dtStartDateStr(bool shortfmt=true) const; 85 QString dtStartDateStr(bool shortfmt=true) const;
86 /** returns an event's starting date and time as a string formatted according 86 /** returns an event's starting date and time as a string formatted according
87 to the users locale settings */ 87 to the users locale settings */
88 QString dtStartStr(bool shortfmt=true) const; 88 QString dtStartStr(bool shortfmt=true) const;
89 89
90 virtual void setDuration(int seconds); 90 virtual void setDuration(int seconds);
91 int duration() const; 91 int duration() const;
92 void setHasDuration(bool); 92 void setHasDuration(bool);
93 bool hasDuration() const; 93 bool hasDuration() const;
94 94
95 /** Return true or false depending on whether the incidence "floats," 95 /** Return true or false depending on whether the incidence "floats,"
96 * i.e. has a date but no time attached to it. */ 96 * i.e. has a date but no time attached to it. */
97 bool doesFloat() const; 97 bool doesFloat() const;
98 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ 98 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */
99 void setFloats(bool f); 99 void setFloats(bool f);
100 100
101 /** 101 /**
102 Add Attendee to this incidence. IncidenceBase takes ownership of the 102 Add Attendee to this incidence. IncidenceBase takes ownership of the
103 Attendee object. 103 Attendee object.
104 */ 104 */
105 bool addAttendee(Attendee *a, bool doupdate=true ); 105 bool addAttendee(Attendee *a, bool doupdate=true );
106// void removeAttendee(Attendee *a); 106// void removeAttendee(Attendee *a);
107// void removeAttendee(const char *n); 107// void removeAttendee(const char *n);
108 /** Remove all Attendees. */ 108 /** Remove all Attendees. */
109 void clearAttendees(); 109 void clearAttendees();
110 /** Return list of attendees. */ 110 /** Return list of attendees. */
111 QPtrList<Attendee> attendees() const { return mAttendees; }; 111 QPtrList<Attendee> attendees() const { return mAttendees; };
112 /** Return number of attendees. */ 112 /** Return number of attendees. */
113 int attendeeCount() const { return mAttendees.count(); }; 113 int attendeeCount() const { return mAttendees.count(); };
114 /** Return the Attendee with this email */ 114 /** Return the Attendee with this email */
115 Attendee* attendeeByMail(const QString &); 115 Attendee* attendeeByMail(const QString &);
116 /** Return first Attendee with one of this emails */ 116 /** Return first Attendee with one of this emails */
117 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); 117 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null);
118 118
119 /** pilot syncronization states */ 119 /** pilot syncronization states */
120 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; 120 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 };
121 /** Set synchronisation satus. */ 121 /** Set synchronisation satus. */
122 void setSyncStatus(int stat); 122 void setSyncStatus(int stat);
123 /** Return synchronisation status. */ 123 /** Return synchronisation status. */
124 int syncStatus() const; 124 int syncStatus() const;
125 125
126 /** Set Pilot Id. */ 126 /** Set Pilot Id. */
127 void setPilotId(int id); 127 void setPilotId(int id);
128 /** Return Pilot Id. */ 128 /** Return Pilot Id. */
129 int pilotId() const; 129 int pilotId() const;
130 130
131 void setTempSyncStat(int id); 131 void setTempSyncStat(int id);
132 int tempSyncStat() const; 132 int tempSyncStat() const;
133 void setIDStr( const QString & ); 133 void setIDStr( const QString & );
134 QString IDStr() const; 134 QString IDStr() const;
135 void setID( const QString &, const QString & ); 135 void setID( const QString &, const QString & );
136 QString getID( const QString & ); 136 QString getID( const QString & );
137 void setCsum( const QString &, const QString & ); 137 void setCsum( const QString &, const QString & );
138 QString getCsum( const QString & ); 138 QString getCsum( const QString & );
139 void removeID(const QString &); 139 void removeID(const QString &);
140 140
141 void registerObserver( Observer * ); 141 void registerObserver( Observer * );
142 void unRegisterObserver( Observer * ); 142 void unRegisterObserver( Observer * );
143 void updated(); 143 void updated();
144 void setCalID( int id ); 144 void setCalID( int id );
145 int calID() const; 145 int calID() const;
146 void setCalEnabled( bool ); 146 void setCalEnabled( bool );
147 bool calEnabled() const; 147 bool calEnabled() const;
148 void setAlarmEnabled( bool ); 148 void setAlarmEnabled( bool );
149 bool alarmEnabled() const; 149 bool alarmEnabled() const;
150 bool isTagged() const; 150 bool isTagged() const;
151 void setTagged( bool ); 151 void setTagged( bool );
152 protected: 152 protected:
153 bool blockLastModified;
153 bool mIsTagged; 154 bool mIsTagged;
154 QDateTime mDtStart; 155 QDateTime mDtStart;
155 bool mReadOnly; 156 bool mReadOnly;
156 QDateTime getEvenTime( QDateTime ); 157 QDateTime getEvenTime( QDateTime );
157 158
158 private: 159 private:
159 // base components 160 // base components
160 QString mOrganizer; 161 QString mOrganizer;
161 QString mUid; 162 QString mUid;
162 int mCalID; 163 int mCalID;
163 bool mCalEnabled; 164 bool mCalEnabled;
164 bool mAlarmEnabled; 165 bool mAlarmEnabled;
165 QDateTime mLastModified; 166 QDateTime mLastModified;
166 QPtrList<Attendee> mAttendees; 167 QPtrList<Attendee> mAttendees;
167 168
168 bool mFloats; 169 bool mFloats;
169 170
170 int mDuration; 171 int mDuration;
171 bool mHasDuration; 172 bool mHasDuration;
172 QString mExternalId; 173 QString mExternalId;
173 int mTempSyncStat; 174 int mTempSyncStat;
174 175
175 // PILOT SYNCHRONIZATION STUFF 176 // PILOT SYNCHRONIZATION STUFF
176 int mPilotId; // unique id for pilot sync 177 int mPilotId; // unique id for pilot sync
177 int mSyncStatus; // status (for sync) 178 int mSyncStatus; // status (for sync)
178 179
179 QPtrList<Observer> mObservers; 180 QPtrList<Observer> mObservers;
180}; 181};
181 182
182bool operator==( const IncidenceBase&, const IncidenceBase& ); 183bool operator==( const IncidenceBase&, const IncidenceBase& );
183} 184}
184 185
185#endif 186#endif