summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2005-11-25 20:49:16 (UTC)
committer zautrix <zautrix>2005-11-25 20:49:16 (UTC)
commit2468bddcb380d8621d5bb49b69b3492d90562d93 (patch) (unidiff)
treec310f4fff5e476087e8406614e57a7f258f1b14f /libkcal
parent7a439999b9fa2bd7ad76e195cdf95bf5211952cb (diff)
downloadkdepimpi-2468bddcb380d8621d5bb49b69b3492d90562d93.zip
kdepimpi-2468bddcb380d8621d5bb49b69b3492d90562d93.tar.gz
kdepimpi-2468bddcb380d8621d5bb49b69b3492d90562d93.tar.bz2
sync
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.h1
-rw-r--r--libkcal/calendarlocal.cpp25
-rw-r--r--libkcal/calendarlocal.h1
3 files changed, 26 insertions, 1 deletions
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index 0a94914..66836a1 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -1,383 +1,384 @@
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 Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0;
81 virtual void setSyncEventsReadOnly() = 0; 81 virtual void setSyncEventsReadOnly() = 0;
82 virtual void setSyncEventsEnabled() = 0; 82 virtual void setSyncEventsEnabled() = 0;
83 virtual void stopAllTodos() = 0; 83 virtual void stopAllTodos() = 0;
84 virtual void clearUndo( Incidence * newUndo ); 84 virtual void clearUndo( Incidence * newUndo );
85 85
86 /** 86 /**
87 Sync changes in memory to persistant storage. 87 Sync changes in memory to persistant storage.
88 */ 88 */
89 virtual void save() = 0; 89 virtual void save() = 0;
90 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 90 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
91 virtual void removeSyncInfo( QString syncProfile) = 0; 91 virtual void removeSyncInfo( QString syncProfile) = 0;
92 virtual bool isSaving() { return false; } 92 virtual bool isSaving() { return false; }
93 93
94 /** 94 /**
95 Return the owner of the calendar's full name. 95 Return the owner of the calendar's full name.
96 */ 96 */
97 const QString &getOwner() const; 97 const QString &getOwner() const;
98 /** 98 /**
99 Set the owner of the calendar. Should be owner's full name. 99 Set the owner of the calendar. Should be owner's full name.
100 */ 100 */
101 void setOwner( const QString &os ); 101 void setOwner( const QString &os );
102 /** 102 /**
103 Return the email address of the calendar owner. 103 Return the email address of the calendar owner.
104 */ 104 */
105 const QString &getEmail(); 105 const QString &getEmail();
106 /** 106 /**
107 Set the email address of the calendar owner. 107 Set the email address of the calendar owner.
108 */ 108 */
109 void setEmail( const QString & ); 109 void setEmail( const QString & );
110 110
111 /** 111 /**
112 Set time zone from a timezone string (e.g. -2:00) 112 Set time zone from a timezone string (e.g. -2:00)
113 */ 113 */
114 void setTimeZone( const QString &tz ); 114 void setTimeZone( const QString &tz );
115 /** 115 /**
116 Set time zone from a minutes value (e.g. -60) 116 Set time zone from a minutes value (e.g. -60)
117 */ 117 */
118 void setTimeZone( int tz ); 118 void setTimeZone( int tz );
119 /** 119 /**
120 Return time zone as offest in minutes. 120 Return time zone as offest in minutes.
121 */ 121 */
122 int getTimeZone() const; 122 int getTimeZone() const;
123 /** 123 /**
124 Compute an ISO 8601 format string from the time zone. 124 Compute an ISO 8601 format string from the time zone.
125 */ 125 */
126 QString getTimeZoneStr() const; 126 QString getTimeZoneStr() const;
127 /** 127 /**
128 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal 128 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal
129 values). 129 values).
130 */ 130 */
131 void setTimeZoneId( const QString & ); 131 void setTimeZoneId( const QString & );
132 /** 132 /**
133 Return time zone id. 133 Return time zone id.
134 */ 134 */
135 QString timeZoneId() const; 135 QString timeZoneId() const;
136 /** 136 /**
137 Use local time, not UTC or a time zone. 137 Use local time, not UTC or a time zone.
138 */ 138 */
139 void setLocalTime(); 139 void setLocalTime();
140 /** 140 /**
141 Return whether local time is being used. 141 Return whether local time is being used.
142 */ 142 */
143 bool isLocalTime() const; 143 bool isLocalTime() const;
144 144
145 /** 145 /**
146 Add an incidence to calendar. 146 Add an incidence to calendar.
147 147
148 @return true on success, false on error. 148 @return true on success, false on error.
149 */ 149 */
150 virtual bool addIncidence( Incidence * ); 150 virtual bool addIncidence( Incidence * );
151 151
152 // Adds an incidence and all relatedto incidences to the cal 152 // Adds an incidence and all relatedto incidences to the cal
153 void addIncidenceBranch( Incidence * ); 153 void addIncidenceBranch( Incidence * );
154 /** 154 /**
155 Return filtered list of all incidences of this calendar. 155 Return filtered list of all incidences of this calendar.
156 */ 156 */
157 virtual QPtrList<Incidence> incidences(); 157 virtual QPtrList<Incidence> incidences();
158 158
159 /** 159 /**
160 Return unfiltered list of all incidences of this calendar. 160 Return unfiltered list of all incidences of this calendar.
161 */ 161 */
162 virtual QPtrList<Incidence> rawIncidences(); 162 virtual QPtrList<Incidence> rawIncidences();
163 163
164 /** 164 /**
165 Adds a Event to this calendar object. 165 Adds a Event to this calendar object.
166 @param anEvent a pointer to the event to add 166 @param anEvent a pointer to the event to add
167 167
168 @return true on success, false on error. 168 @return true on success, false on error.
169 */ 169 */
170 virtual bool addEventNoDup( Event *event ) = 0; 170 virtual bool addEventNoDup( Event *event ) = 0;
171 virtual bool addAnniversaryNoDup( Event *event ) = 0; 171 virtual bool addAnniversaryNoDup( Event *event ) = 0;
172 virtual bool addEvent( Event *anEvent ) = 0; 172 virtual bool addEvent( Event *anEvent ) = 0;
173 /** 173 /**
174 Delete event from calendar. 174 Delete event from calendar.
175 */ 175 */
176 virtual void deleteEvent( Event * ) = 0; 176 virtual void deleteEvent( Event * ) = 0;
177 /** 177 /**
178 Retrieves an event on the basis of the unique string ID. 178 Retrieves an event on the basis of the unique string ID.
179 */ 179 */
180 virtual Event *event( const QString &UniqueStr ) = 0; 180 virtual Event *event( const QString &UniqueStr ) = 0;
181 virtual Event *event( QString, QString ) = 0; 181 virtual Event *event( QString, QString ) = 0;
182 /** 182 /**
183 Builds and then returns a list of all events that match for the 183 Builds and then returns a list of all events that match for the
184 date specified. useful for dayView, etc. etc. 184 date specified. useful for dayView, etc. etc.
185 The calendar filter is applied. 185 The calendar filter is applied.
186 */ 186 */
187 QPtrList<Event> events( const QDate &date, bool sorted = false); 187 QPtrList<Event> events( const QDate &date, bool sorted = false);
188 /** 188 /**
189 Get events, which occur on the given date. 189 Get events, which occur on the given date.
190 The calendar filter is applied. 190 The calendar filter is applied.
191 */ 191 */
192 QPtrList<Event> events( const QDateTime &qdt ); 192 QPtrList<Event> events( const QDateTime &qdt );
193 /** 193 /**
194 Get events in a range of dates. If inclusive is set to true, only events 194 Get events in a range of dates. If inclusive is set to true, only events
195 are returned, which are completely included in the range. 195 are returned, which are completely included in the range.
196 The calendar filter is applied. 196 The calendar filter is applied.
197 */ 197 */
198 QPtrList<Event> events( const QDate &start, const QDate &end, 198 QPtrList<Event> events( const QDate &start, const QDate &end,
199 bool inclusive = false); 199 bool inclusive = false);
200 /** 200 /**
201 Return filtered list of all events in calendar. 201 Return filtered list of all events in calendar.
202 */ 202 */
203 virtual QPtrList<Event> events(); 203 virtual QPtrList<Event> events();
204 /** 204 /**
205 Return unfiltered list of all events in calendar. 205 Return unfiltered list of all events in calendar.
206 */ 206 */
207 virtual QPtrList<Event> rawEvents() = 0; 207 virtual QPtrList<Event> rawEvents() = 0;
208 208
209 /** 209 /**
210 Add a todo to the todolist. 210 Add a todo to the todolist.
211 211
212 @return true on success, false on error. 212 @return true on success, false on error.
213 */ 213 */
214 virtual bool addTodo( Todo *todo ) = 0; 214 virtual bool addTodo( Todo *todo ) = 0;
215 virtual bool addTodoNoDup( Todo *todo ) = 0; 215 virtual bool addTodoNoDup( Todo *todo ) = 0;
216 /** 216 /**
217 Remove a todo from the todolist. 217 Remove a todo from the todolist.
218 */ 218 */
219 virtual void deleteTodo( Todo * ) = 0; 219 virtual void deleteTodo( Todo * ) = 0;
220 virtual void deleteJournal( Journal * ) = 0; 220 virtual void deleteJournal( Journal * ) = 0;
221 /** 221 /**
222 Return filterd list of todos. 222 Return filterd list of todos.
223 */ 223 */
224 virtual QPtrList<Todo> todos(); 224 virtual QPtrList<Todo> todos();
225 /** 225 /**
226 Searches todolist for an event with this unique string identifier, 226 Searches todolist for an event with this unique string identifier,
227 returns a pointer or null. 227 returns a pointer or null.
228 */ 228 */
229 virtual Todo *todo( const QString &uid ) = 0; 229 virtual Todo *todo( const QString &uid ) = 0;
230 virtual Todo *todo( QString, QString ) = 0; 230 virtual Todo *todo( QString, QString ) = 0;
231 /** 231 /**
232 Returns list of todos due on the specified date. 232 Returns list of todos due on the specified date.
233 */ 233 */
234 virtual QPtrList<Todo> todos( const QDate &date ) = 0; 234 virtual QPtrList<Todo> todos( const QDate &date ) = 0;
235 /** 235 /**
236 Return unfiltered list of todos. 236 Return unfiltered list of todos.
237 */ 237 */
238 virtual QPtrList<Todo> rawTodos() = 0; 238 virtual QPtrList<Todo> rawTodos() = 0;
239 239
240 /** 240 /**
241 Add a Journal entry to calendar. 241 Add a Journal entry to calendar.
242 242
243 @return true on success, false on error. 243 @return true on success, false on error.
244 */ 244 */
245 virtual bool addJournal( Journal * ) = 0; 245 virtual bool addJournal( Journal * ) = 0;
246 /** 246 /**
247 Return Journal for given date. 247 Return Journal for given date.
248 */ 248 */
249 virtual Journal *journal( const QDate & ) = 0; 249 virtual Journal *journal( const QDate & ) = 0;
250 virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; 250 virtual QPtrList<Journal> journals4Date( const QDate & ) = 0;
251 /** 251 /**
252 Return Journal with given UID. 252 Return Journal with given UID.
253 */ 253 */
254 virtual Journal *journal( const QString &UID ) = 0; 254 virtual Journal *journal( const QString &UID ) = 0;
255 /** 255 /**
256 Return list of all Journal entries. 256 Return list of all Journal entries.
257 */ 257 */
258 virtual QPtrList<Journal> journals() = 0; 258 virtual QPtrList<Journal> journals() = 0;
259 259
260 /** 260 /**
261 Searches all incidence types for an incidence with this unique 261 Searches all incidence types for an incidence with this unique
262 string identifier, returns a pointer or null. 262 string identifier, returns a pointer or null.
263 */ 263 */
264 Incidence* incidence( const QString&UID ); 264 Incidence* incidence( const QString&UID );
265 265
266 /** 266 /**
267 Setup relations for an incidence. 267 Setup relations for an incidence.
268 */ 268 */
269 virtual void setupRelations( Incidence * ); 269 virtual void setupRelations( Incidence * );
270 /** 270 /**
271 Remove all relations to an incidence 271 Remove all relations to an incidence
272 */ 272 */
273 virtual void removeRelations( Incidence * ); 273 virtual void removeRelations( Incidence * );
274 274
275 /** 275 /**
276 Set calendar filter, which filters events for the events() functions. 276 Set calendar filter, which filters events for the events() functions.
277 The Filter object is owned by the caller. 277 The Filter object is owned by the caller.
278 */ 278 */
279 void setFilter( CalFilter * ); 279 void setFilter( CalFilter * );
280 /** 280 /**
281 Return calendar filter. 281 Return calendar filter.
282 */ 282 */
283 CalFilter *filter(); 283 CalFilter *filter();
284 virtual QDateTime nextAlarm( int daysTo ) = 0; 284 virtual QDateTime nextAlarm( int daysTo ) = 0;
285 virtual QString nextSummary( ) const = 0; 285 virtual QString nextSummary( ) const = 0;
286 virtual void reInitAlarmSettings() = 0; 286 virtual void reInitAlarmSettings() = 0;
287 virtual QDateTime nextAlarmEventDateTime() const = 0; 287 virtual QDateTime nextAlarmEventDateTime() const = 0;
288 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; 288 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0;
289 /** 289 /**
290 Return all alarms, which ocur in the given time interval. 290 Return all alarms, which ocur in the given time interval.
291 */ 291 */
292 virtual Alarm::List alarms( const QDateTime &from, 292 virtual Alarm::List alarms( const QDateTime &from,
293 const QDateTime &to ) = 0; 293 const QDateTime &to ) = 0;
294 294
295 class Observer { 295 class Observer {
296 public: 296 public:
297 virtual void calendarModified( bool, Calendar * ) = 0; 297 virtual void calendarModified( bool, Calendar * ) = 0;
298 }; 298 };
299 299
300 void registerObserver( Observer * ); 300 void registerObserver( Observer * );
301 301
302 void setModified( bool ); 302 void setModified( bool );
303 303
304 /** 304 /**
305 Set product id returned by loadedProductId(). This function is only 305 Set product id returned by loadedProductId(). This function is only
306 useful for the calendar loading code. 306 useful for the calendar loading code.
307 */ 307 */
308 void setLoadedProductId( const QString & ); 308 void setLoadedProductId( const QString & );
309 /** 309 /**
310 Return product id taken from file that has been loaded. Returns 310 Return product id taken from file that has been loaded. Returns
311 QString::null, if no calendar has been loaded. 311 QString::null, if no calendar has been loaded.
312 */ 312 */
313 QString loadedProductId(); 313 QString loadedProductId();
314 int defaultCalendar(); 314 int defaultCalendar();
315 void setDontDeleteIncidencesOnClose (); 315 void setDontDeleteIncidencesOnClose ();
316 public slots: 316 public slots:
317 void setDefaultCalendar( int ); 317 void setDefaultCalendar( int );
318 virtual void setCalendarEnabled( int id, bool enable ) = 0; 318 virtual void setCalendarEnabled( int id, bool enable ) = 0;
319 virtual void setAllCalendarEnabled( bool enable ) = 0;
319 virtual void setAlarmEnabled( int id, bool enable ) = 0; 320 virtual void setAlarmEnabled( int id, bool enable ) = 0;
320 virtual void setReadOnly( int id, bool enable ) = 0; 321 virtual void setReadOnly( int id, bool enable ) = 0;
321 virtual void setDefaultCalendarEnabledOnly() = 0; 322 virtual void setDefaultCalendarEnabledOnly() = 0;
322 virtual void setCalendarRemove( int id ) = 0; 323 virtual void setCalendarRemove( int id ) = 0;
323 virtual void getIncidenceCount( int calId, int& events, int & todos, int & journals) = 0; 324 virtual void getIncidenceCount( int calId, int& events, int & todos, int & journals) = 0;
324 325
325 signals: 326 signals:
326 void calendarChanged(); 327 void calendarChanged();
327 void calendarSaved(); 328 void calendarSaved();
328 void calendarLoaded(); 329 void calendarLoaded();
329 void addAlarm(const QDateTime &qdt, const QString &noti ); 330 void addAlarm(const QDateTime &qdt, const QString &noti );
330 void removeAlarm(const QDateTime &qdt, const QString &noti ); 331 void removeAlarm(const QDateTime &qdt, const QString &noti );
331 332
332 protected: 333 protected:
333 /** 334 /**
334 Get unfiltered events, which occur on the given date. 335 Get unfiltered events, which occur on the given date.
335 */ 336 */
336 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; 337 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
337 /** 338 /**
338 Get unfiltered events, which occur on the given date. 339 Get unfiltered events, which occur on the given date.
339 */ 340 */
340 virtual QPtrList<Event> rawEventsForDate( const QDate &date, 341 virtual QPtrList<Event> rawEventsForDate( const QDate &date,
341 bool sorted = false ) = 0; 342 bool sorted = false ) = 0;
342 /** 343 /**
343 Get events in a range of dates. If inclusive is set to true, only events 344 Get events in a range of dates. If inclusive is set to true, only events
344 are returned, which are completely included in the range. 345 are returned, which are completely included in the range.
345 */ 346 */
346 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 347 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
347 bool inclusive = false ) = 0; 348 bool inclusive = false ) = 0;
348 349
349 Incidence *mNextAlarmIncidence; 350 Incidence *mNextAlarmIncidence;
350 Incidence *mUndoIncidence; 351 Incidence *mUndoIncidence;
351 int mDefaultCalendar; 352 int mDefaultCalendar;
352 bool mDeleteIncidencesOnClose; 353 bool mDeleteIncidencesOnClose;
353 354
354private: 355private:
355 void init(); 356 void init();
356 357
357 QString mOwner; // who the calendar belongs to 358 QString mOwner; // who the calendar belongs to
358 QString mOwnerEmail; // email address of the owner 359 QString mOwnerEmail; // email address of the owner
359 int mTimeZone; // timezone OFFSET from GMT (MINUTES) 360 int mTimeZone; // timezone OFFSET from GMT (MINUTES)
360 bool mLocalTime; // use local time, not UTC or a time zone 361 bool mLocalTime; // use local time, not UTC or a time zone
361 362
362 363
363 CalFilter *mFilter; 364 CalFilter *mFilter;
364 CalFilter *mDefaultFilter; 365 CalFilter *mDefaultFilter;
365 366
366 367
367 QString mTimeZoneId; 368 QString mTimeZoneId;
368 369
369 Observer *mObserver; 370 Observer *mObserver;
370 bool mNewObserver; 371 bool mNewObserver;
371 372
372 bool mModified; 373 bool mModified;
373 374
374 QString mLoadedProductId; 375 QString mLoadedProductId;
375 376
376 // This list is used to put together related todos 377 // This list is used to put together related todos
377 QDict<Incidence> mOrphans; 378 QDict<Incidence> mOrphans;
378 QDict<Incidence> mOrphanUids; 379 QDict<Incidence> mOrphanUids;
379}; 380};
380 381
381} 382}
382 383
383#endif 384#endif
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 45e3128..2a57724 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,1056 +1,1079 @@
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 registerObserver( 0 ); 68 registerObserver( 0 );
69 if ( mDeleteIncidencesOnClose ) 69 if ( mDeleteIncidencesOnClose )
70 close(); 70 close();
71} 71}
72bool CalendarLocal::mergeCalendarFile( QString name ) 72bool CalendarLocal::mergeCalendarFile( QString name )
73{ 73{
74 CalendarLocal calendar( timeZoneId() ); 74 CalendarLocal calendar( timeZoneId() );
75 calendar.setDefaultCalendar( 1 ); 75 calendar.setDefaultCalendar( 1 );
76 if ( calendar.load( name ) ) { 76 if ( calendar.load( name ) ) {
77 mergeCalendar( &calendar ); 77 mergeCalendar( &calendar );
78 return true; 78 return true;
79 } 79 }
80 return false; 80 return false;
81} 81}
82 82
83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) 83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates)
84{ 84{
85 Todo *todo;; 85 Todo *todo;;
86 Incidence *retVal = 0; 86 Incidence *retVal = 0;
87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
88 if ( todo->uid() == uid ) { 88 if ( todo->uid() == uid ) {
89 if ( doNotCheckDuplicates ) return todo; 89 if ( doNotCheckDuplicates ) return todo;
90 if ( retVal ) { 90 if ( retVal ) {
91 if ( retVal->calID() > todo->calID() ) { 91 if ( retVal->calID() > todo->calID() ) {
92 retVal = todo; 92 retVal = todo;
93 } 93 }
94 } else { 94 } else {
95 retVal = todo; 95 retVal = todo;
96 } 96 }
97 } 97 }
98 } 98 }
99 if ( retVal ) return retVal; 99 if ( retVal ) return retVal;
100 Event *event; 100 Event *event;
101 for ( event = mEventList.first(); event; event = mEventList.next() ) { 101 for ( event = mEventList.first(); event; event = mEventList.next() ) {
102 if ( event->uid() == uid ) { 102 if ( event->uid() == uid ) {
103 if ( doNotCheckDuplicates ) return event; 103 if ( doNotCheckDuplicates ) return event;
104 if ( retVal ) { 104 if ( retVal ) {
105 if ( retVal->calID() > event->calID() ) { 105 if ( retVal->calID() > event->calID() ) {
106 retVal = event; 106 retVal = event;
107 } 107 }
108 } else { 108 } else {
109 retVal = event; 109 retVal = event;
110 } 110 }
111 } 111 }
112 } 112 }
113 if ( retVal ) return retVal; 113 if ( retVal ) return retVal;
114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
115 if ( it->uid() == uid ) { 115 if ( it->uid() == uid ) {
116 if ( doNotCheckDuplicates ) return it; 116 if ( doNotCheckDuplicates ) return it;
117 if ( retVal ) { 117 if ( retVal ) {
118 if ( retVal->calID() > it->calID() ) { 118 if ( retVal->calID() > it->calID() ) {
119 retVal = it; 119 retVal = it;
120 } 120 }
121 } else { 121 } else {
122 retVal = it; 122 retVal = it;
123 } 123 }
124 } 124 }
125 return retVal; 125 return retVal;
126} 126}
127 127
128bool CalendarLocal::mergeCalendar( Calendar* remote ) 128bool CalendarLocal::mergeCalendar( Calendar* remote )
129{ 129{
130 // 1 look for raw inc in local 130 // 1 look for raw inc in local
131 // if inc not in remote, delete in local 131 // if inc not in remote, delete in local
132 // 2 look for raw inc in remote 132 // 2 look for raw inc in remote
133 // if inc in local, replace it 133 // if inc in local, replace it
134 // if not in local, add it to default calendar 134 // if not in local, add it to default calendar
135 QPtrList<Incidence> localInc = rawIncidences(); 135 QPtrList<Incidence> localInc = rawIncidences();
136 Incidence* inL = localInc.first(); 136 Incidence* inL = localInc.first();
137 while ( inL ) { 137 while ( inL ) {
138 if ( ! inL->isReadOnly () ) 138 if ( ! inL->isReadOnly () )
139 if ( !remote->incidenceForUid( inL->uid(), true )) 139 if ( !remote->incidenceForUid( inL->uid(), true ))
140 deleteIncidence( inL ); 140 deleteIncidence( inL );
141 inL = localInc.next(); 141 inL = localInc.next();
142 } 142 }
143 QPtrList<Incidence> er = remote->rawIncidences(); 143 QPtrList<Incidence> er = remote->rawIncidences();
144 Incidence* inR = er.first(); 144 Incidence* inR = er.first();
145 while ( inR ) { 145 while ( inR ) {
146 inL = incidenceForUid( inR->uid(),false ); 146 inL = incidenceForUid( inR->uid(),false );
147 if ( inL ) { 147 if ( inL ) {
148 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { 148 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
149 int calID = inL->calID(); 149 int calID = inL->calID();
150 deleteIncidence( inL ); 150 deleteIncidence( inL );
151 inL = inR->clone(); 151 inL = inR->clone();
152 inL->setCalID( calID ); 152 inL->setCalID( calID );
153 addIncidence( inL ); 153 addIncidence( inL );
154 } 154 }
155 } else { 155 } else {
156 inL = inR->clone(); 156 inL = inR->clone();
157 inL->setCalID( 0 );// add to default cal 157 inL->setCalID( 0 );// add to default cal
158 addIncidence( inL ); 158 addIncidence( inL );
159 } 159 }
160 inR = er.next(); 160 inR = er.next();
161 } 161 }
162 return true; 162 return true;
163} 163}
164 164
165 165
166bool CalendarLocal::addCalendarFile( QString name, int id ) 166bool CalendarLocal::addCalendarFile( QString name, int id )
167{ 167{
168 CalendarLocal calendar( timeZoneId() ); 168 CalendarLocal calendar( timeZoneId() );
169 calendar.setDefaultCalendar( id ); 169 calendar.setDefaultCalendar( id );
170 if ( calendar.load( name ) ) { 170 if ( calendar.load( name ) ) {
171 addCalendar( &calendar ); 171 addCalendar( &calendar );
172 return true; 172 return true;
173 } 173 }
174 return false; 174 return false;
175} 175}
176void CalendarLocal::setSyncEventsEnabled() 176void CalendarLocal::setSyncEventsEnabled()
177{ 177{
178 Event * ev; 178 Event * ev;
179 ev = mEventList.first(); 179 ev = mEventList.first();
180 while ( ev ) { 180 while ( ev ) {
181 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 181 if ( ev->uid().left(15) == QString("last-syncEvent-") )
182 ev->setCalEnabled( true ); 182 ev->setCalEnabled( true );
183 ev = mEventList.next(); 183 ev = mEventList.next();
184 } 184 }
185} 185}
186void CalendarLocal::setSyncEventsReadOnly() 186void CalendarLocal::setSyncEventsReadOnly()
187{ 187{
188 Event * ev; 188 Event * ev;
189 ev = mEventList.first(); 189 ev = mEventList.first();
190 while ( ev ) { 190 while ( ev ) {
191 if ( ev->uid().left(15) == QString("last-syncEvent-") ) { 191 if ( ev->uid().left(15) == QString("last-syncEvent-") ) {
192 ev->setReadOnly( true ); 192 ev->setReadOnly( true );
193 ev->setCalID( 1 );
194 } 193 }
195 ev = mEventList.next(); 194 ev = mEventList.next();
196 } 195 }
197} 196}
197
198void CalendarLocal::addCalendar( Calendar* cal ) 198void CalendarLocal::addCalendar( Calendar* cal )
199{ 199{
200 cal->setDontDeleteIncidencesOnClose(); 200 cal->setDontDeleteIncidencesOnClose();
201 setSyncEventsEnabled();
201 { 202 {
202 QPtrList<Event> EventList = cal->rawEvents(); 203 QPtrList<Event> EventList = cal->rawEvents();
204 QPtrList<Event> el;
203 Event * ev = EventList.first(); 205 Event * ev = EventList.first();
204 while ( ev ) { 206 while ( ev ) {
207 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) {
208 Event * se = event( ev->uid() );
209 if ( se )
210 el.append( se );
211 }
205 ev->unRegisterObserver( cal ); 212 ev->unRegisterObserver( cal );
206 ev->registerObserver( this ); 213 ev->registerObserver( this );
207 mEventList.append( ev ); 214 mEventList.append( ev );
208 ev = EventList.next(); 215 ev = EventList.next();
209 } 216 }
217 for ( ev = el.first(); ev; ev = el.next() ) {
218 deleteIncidence ( ev );
219 }
210 } 220 }
211 { 221 {
212 222
213 QPtrList<Todo> TodoList = cal->rawTodos(); 223 QPtrList<Todo> TodoList = cal->rawTodos();
214 Todo * ev = TodoList.first(); 224 Todo * ev = TodoList.first();
215 while ( ev ) { 225 while ( ev ) {
216 QString rel = ev->relatedToUid(); 226 QString rel = ev->relatedToUid();
217 if ( !rel.isEmpty() ){ 227 if ( !rel.isEmpty() ){
218 ev->setRelatedTo ( 0 ); 228 ev->setRelatedTo ( 0 );
219 ev->setRelatedToUid( rel ); 229 ev->setRelatedToUid( rel );
220 } 230 }
221 ev = TodoList.next(); 231 ev = TodoList.next();
222 } 232 }
223 //TodoList = cal->rawTodos(); 233 //TodoList = cal->rawTodos();
224 ev = TodoList.first(); 234 ev = TodoList.first();
225 while ( ev ) { 235 while ( ev ) {
226 ev->unRegisterObserver( cal ); 236 ev->unRegisterObserver( cal );
227 ev->registerObserver( this ); 237 ev->registerObserver( this );
228 mTodoList.append( ev ); 238 mTodoList.append( ev );
229 setupRelations( ev ); 239 setupRelations( ev );
230 ev = TodoList.next(); 240 ev = TodoList.next();
231 } 241 }
232 } 242 }
233 { 243 {
234 QPtrList<Journal> JournalList = cal->journals(); 244 QPtrList<Journal> JournalList = cal->journals();
235 Journal * ev = JournalList.first(); 245 Journal * ev = JournalList.first();
236 while ( ev ) { 246 while ( ev ) {
237 ev->unRegisterObserver( cal ); 247 ev->unRegisterObserver( cal );
238 ev->registerObserver( this ); 248 ev->registerObserver( this );
239 mJournalList.append( ev ); 249 mJournalList.append( ev );
240 ev = JournalList.next(); 250 ev = JournalList.next();
241 } 251 }
242 } 252 }
243 setModified( true ); 253 setModified( true );
244} 254}
245bool CalendarLocal::load( const QString &fileName ) 255bool CalendarLocal::load( const QString &fileName )
246{ 256{
247 FileStorage storage( this, fileName ); 257 FileStorage storage( this, fileName );
248 return storage.load(); 258 return storage.load();
249} 259}
250 260
251bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 261bool CalendarLocal::save( const QString &fileName, CalFormat *format )
252{ 262{
253 FileStorage storage( this, fileName, format ); 263 FileStorage storage( this, fileName, format );
254 return storage.save(); 264 return storage.save();
255} 265}
256 266
257void CalendarLocal::stopAllTodos() 267void CalendarLocal::stopAllTodos()
258{ 268{
259 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 269 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
260 it->setRunning( false ); 270 it->setRunning( false );
261 271
262} 272}
263void CalendarLocal::close() 273void CalendarLocal::close()
264{ 274{
265 275
266 Todo * i; 276 Todo * i;
267 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 277 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
268 278
269 mEventList.setAutoDelete( true ); 279 mEventList.setAutoDelete( true );
270 mTodoList.setAutoDelete( true ); 280 mTodoList.setAutoDelete( true );
271 mJournalList.setAutoDelete( true ); 281 mJournalList.setAutoDelete( true );
272 282
273 mEventList.clear(); 283 mEventList.clear();
274 mTodoList.clear(); 284 mTodoList.clear();
275 mJournalList.clear(); 285 mJournalList.clear();
276 286
277 mEventList.setAutoDelete( false ); 287 mEventList.setAutoDelete( false );
278 mTodoList.setAutoDelete( false ); 288 mTodoList.setAutoDelete( false );
279 mJournalList.setAutoDelete( false ); 289 mJournalList.setAutoDelete( false );
280 290
281 setModified( false ); 291 setModified( false );
282} 292}
283 293
284bool CalendarLocal::addAnniversaryNoDup( Event *event ) 294bool CalendarLocal::addAnniversaryNoDup( Event *event )
285{ 295{
286 QString cat; 296 QString cat;
287 bool isBirthday = true; 297 bool isBirthday = true;
288 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 298 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
289 isBirthday = false; 299 isBirthday = false;
290 cat = i18n( "Anniversary" ); 300 cat = i18n( "Anniversary" );
291 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 301 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
292 isBirthday = true; 302 isBirthday = true;
293 cat = i18n( "Birthday" ); 303 cat = i18n( "Birthday" );
294 } else { 304 } else {
295 qDebug("addAnniversaryNoDup called without fitting category! "); 305 qDebug("addAnniversaryNoDup called without fitting category! ");
296 return false; 306 return false;
297 } 307 }
298 Event * eve; 308 Event * eve;
299 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 309 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
300 if ( !(eve->categories().contains( cat ) )) 310 if ( !(eve->categories().contains( cat ) ))
301 continue; 311 continue;
302 // now we have an event with fitting category 312 // now we have an event with fitting category
303 if ( eve->dtStart().date() != event->dtStart().date() ) 313 if ( eve->dtStart().date() != event->dtStart().date() )
304 continue; 314 continue;
305 // now we have an event with fitting category+date 315 // now we have an event with fitting category+date
306 if ( eve->summary() != event->summary() ) 316 if ( eve->summary() != event->summary() )
307 continue; 317 continue;
308 // now we have an event with fitting category+date+summary 318 // now we have an event with fitting category+date+summary
309 return false; 319 return false;
310 } 320 }
311 return addEvent( event ); 321 return addEvent( event );
312 322
313} 323}
314bool CalendarLocal::addEventNoDup( Event *event ) 324bool CalendarLocal::addEventNoDup( Event *event )
315{ 325{
316 Event * eve; 326 Event * eve;
317 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 327 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
318 if ( *eve == *event ) { 328 if ( *eve == *event ) {
319 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 329 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
320 return false; 330 return false;
321 } 331 }
322 } 332 }
323 return addEvent( event ); 333 return addEvent( event );
324} 334}
325 335
326bool CalendarLocal::addEvent( Event *event ) 336bool CalendarLocal::addEvent( Event *event )
327{ 337{
328 insertEvent( event ); 338 insertEvent( event );
329 339
330 event->registerObserver( this ); 340 event->registerObserver( this );
331 341
332 setModified( true ); 342 setModified( true );
333 if ( event->calID() == 0 ) 343 if ( event->calID() == 0 )
334 event->setCalID( mDefaultCalendar ); 344 event->setCalID( mDefaultCalendar );
335 event->setCalEnabled( true ); 345 event->setCalEnabled( true );
336 346
337 return true; 347 return true;
338} 348}
339 349
340void CalendarLocal::deleteEvent( Event *event ) 350void CalendarLocal::deleteEvent( Event *event )
341{ 351{
342 clearUndo(event); 352 clearUndo(event);
343 if ( mEventList.removeRef( event ) ) { 353 if ( mEventList.removeRef( event ) ) {
344 setModified( true ); 354 setModified( true );
345 } 355 }
346} 356}
347 357
348 358
349Event *CalendarLocal::event( const QString &uid ) 359Event *CalendarLocal::event( const QString &uid )
350{ 360{
351 Event *event; 361 Event *event;
352 Event *retVal = 0; 362 Event *retVal = 0;
353 for ( event = mEventList.first(); event; event = mEventList.next() ) { 363 for ( event = mEventList.first(); event; event = mEventList.next() ) {
354 if ( event->calEnabled() && event->uid() == uid ) { 364 if ( event->calEnabled() && event->uid() == uid ) {
355 if ( retVal ) { 365 if ( retVal ) {
356 if ( retVal->calID() > event->calID() ) { 366 if ( retVal->calID() > event->calID() ) {
357 retVal = event; 367 retVal = event;
358 } 368 }
359 } else { 369 } else {
360 retVal = event; 370 retVal = event;
361 } 371 }
362 } 372 }
363 } 373 }
364 return retVal; 374 return retVal;
365} 375}
366bool CalendarLocal::addTodoNoDup( Todo *todo ) 376bool CalendarLocal::addTodoNoDup( Todo *todo )
367{ 377{
368 Todo * eve; 378 Todo * eve;
369 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 379 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
370 if ( *eve == *todo ) { 380 if ( *eve == *todo ) {
371 //qDebug("duplicate todo found! not inserted! "); 381 //qDebug("duplicate todo found! not inserted! ");
372 return false; 382 return false;
373 } 383 }
374 } 384 }
375 return addTodo( todo ); 385 return addTodo( todo );
376} 386}
377bool CalendarLocal::addTodo( Todo *todo ) 387bool CalendarLocal::addTodo( Todo *todo )
378{ 388{
379 mTodoList.append( todo ); 389 mTodoList.append( todo );
380 390
381 todo->registerObserver( this ); 391 todo->registerObserver( this );
382 392
383 // Set up subtask relations 393 // Set up subtask relations
384 setupRelations( todo ); 394 setupRelations( todo );
385 395
386 setModified( true ); 396 setModified( true );
387 if ( todo->calID() == 0 ) 397 if ( todo->calID() == 0 )
388 todo->setCalID( mDefaultCalendar ); 398 todo->setCalID( mDefaultCalendar );
389 todo->setCalEnabled( true ); 399 todo->setCalEnabled( true );
390 return true; 400 return true;
391} 401}
392 402
393void CalendarLocal::deleteTodo( Todo *todo ) 403void CalendarLocal::deleteTodo( Todo *todo )
394{ 404{
395 // Handle orphaned children 405 // Handle orphaned children
396 removeRelations( todo ); 406 removeRelations( todo );
397 clearUndo(todo); 407 clearUndo(todo);
398 408
399 if ( mTodoList.removeRef( todo ) ) { 409 if ( mTodoList.removeRef( todo ) ) {
400 setModified( true ); 410 setModified( true );
401 } 411 }
402} 412}
403 413
404QPtrList<Todo> CalendarLocal::rawTodos() 414QPtrList<Todo> CalendarLocal::rawTodos()
405{ 415{
406 QPtrList<Todo> el; 416 QPtrList<Todo> el;
407 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 417 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
408 if ( it->calEnabled() ) el.append( it ); 418 if ( it->calEnabled() ) el.append( it );
409 return el; 419 return el;
410} 420}
411Todo *CalendarLocal::todo( QString syncProf, QString id ) 421Todo *CalendarLocal::todo( QString syncProf, QString id )
412{ 422{
413 Todo *todo; 423 Todo *todo;
414 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 424 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
415 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 425 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
416 } 426 }
417 427
418 return 0; 428 return 0;
419} 429}
420void CalendarLocal::removeSyncInfo( QString syncProfile) 430void CalendarLocal::removeSyncInfo( QString syncProfile)
421{ 431{
422 QPtrList<Incidence> all = rawIncidences() ; 432 QPtrList<Incidence> all = rawIncidences() ;
423 Incidence *inc; 433 Incidence *inc;
424 for ( inc = all.first(); inc; inc = all.next() ) { 434 for ( inc = all.first(); inc; inc = all.next() ) {
425 inc->removeID( syncProfile ); 435 inc->removeID( syncProfile );
426 } 436 }
427 if ( syncProfile.isEmpty() ) { 437 if ( syncProfile.isEmpty() ) {
428 QPtrList<Event> el; 438 QPtrList<Event> el;
429 Event *todo; 439 Event *todo;
430 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 440 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
431 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 441 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
432 el.append( todo ); 442 el.append( todo );
433 } 443 }
434 for ( todo = el.first(); todo; todo = el.next() ) { 444 for ( todo = el.first(); todo; todo = el.next() ) {
435 deleteIncidence ( todo ); 445 deleteIncidence ( todo );
436 } 446 }
437 } else { 447 } else {
438 Event *lse = event( "last-syncEvent-"+ syncProfile); 448 Event *lse = event( "last-syncEvent-"+ syncProfile);
439 if ( lse ) 449 if ( lse )
440 deleteIncidence ( lse ); 450 deleteIncidence ( lse );
441 } 451 }
442} 452}
443QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 453QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
444{ 454{
445 QPtrList<Event> el; 455 QPtrList<Event> el;
446 Event *todo; 456 Event *todo;
447 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 457 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
448 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 458 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
449 if ( todo->summary().left(3) == "E: " ) 459 if ( todo->summary().left(3) == "E: " )
450 el.append( todo ); 460 el.append( todo );
451 } 461 }
452 462
453 return el; 463 return el;
454 464
455} 465}
456Event *CalendarLocal::event( QString syncProf, QString id ) 466Event *CalendarLocal::event( QString syncProf, QString id )
457{ 467{
458 Event *todo; 468 Event *todo;
459 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 469 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
460 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 470 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
461 } 471 }
462 472
463 return 0; 473 return 0;
464} 474}
465Todo *CalendarLocal::todo( const QString &uid ) 475Todo *CalendarLocal::todo( const QString &uid )
466{ 476{
467 Todo *todo; 477 Todo *todo;
468 Todo *retVal = 0; 478 Todo *retVal = 0;
469 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 479 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
470 if ( todo->calEnabled() && todo->uid() == uid ) { 480 if ( todo->calEnabled() && todo->uid() == uid ) {
471 if ( retVal ) { 481 if ( retVal ) {
472 if ( retVal->calID() > todo->calID() ) { 482 if ( retVal->calID() > todo->calID() ) {
473 retVal = todo; 483 retVal = todo;
474 } 484 }
475 } else { 485 } else {
476 retVal = todo; 486 retVal = todo;
477 } 487 }
478 } 488 }
479 } 489 }
480 return retVal; 490 return retVal;
481} 491}
482void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) 492void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals)
483{ 493{
484 events = 0; 494 events = 0;
485 todos = 0; 495 todos = 0;
486 journals = 0; 496 journals = 0;
487 { 497 {
488 Todo *todo; 498 Todo *todo;
489 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 499 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
490 if ( todo->calID() == calId ) 500 if ( todo->calID() == calId )
491 ++todos; 501 ++todos;
492 } 502 }
493 } 503 }
494 { 504 {
495 Event *todo; 505 Event *todo;
496 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 506 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
497 if ( todo->calID() == calId ) 507 if ( todo->calID() == calId )
498 ++events; 508 ++events;
499 509
500 } 510 }
501 } 511 }
502 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 512 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
503 if ( it->calID() == calId ) ++journals; 513 if ( it->calID() == calId ) ++journals;
504 514
505} 515}
506QString CalendarLocal::nextSummary() const 516QString CalendarLocal::nextSummary() const
507{ 517{
508 return mNextSummary; 518 return mNextSummary;
509} 519}
510QDateTime CalendarLocal::nextAlarmEventDateTime() const 520QDateTime CalendarLocal::nextAlarmEventDateTime() const
511{ 521{
512 return mNextAlarmEventDateTime; 522 return mNextAlarmEventDateTime;
513} 523}
514void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 524void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
515{ 525{
516 //mNextAlarmIncidence 526 //mNextAlarmIncidence
517 //mNextAlarmDateTime 527 //mNextAlarmDateTime
518 //return mNextSummary; 528 //return mNextSummary;
519 //return mNextAlarmEventDateTime; 529 //return mNextAlarmEventDateTime;
520 bool newNextAlarm = false; 530 bool newNextAlarm = false;
521 bool computeNextAlarm = false; 531 bool computeNextAlarm = false;
522 bool ok; 532 bool ok;
523 int offset; 533 int offset;
524 QDateTime nextA; 534 QDateTime nextA;
525 // QString nextSum; 535 // QString nextSum;
526 //QDateTime nextEvent; 536 //QDateTime nextEvent;
527 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 537 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
528 computeNextAlarm = true; 538 computeNextAlarm = true;
529 } else { 539 } else {
530 if ( ! deleted ) { 540 if ( ! deleted ) {
531 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 541 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
532 if ( ok ) { 542 if ( ok ) {
533 if ( nextA < mNextAlarmDateTime ) { 543 if ( nextA < mNextAlarmDateTime ) {
534 deRegisterAlarm(); 544 deRegisterAlarm();
535 mNextAlarmDateTime = nextA; 545 mNextAlarmDateTime = nextA;
536 mNextSummary = incidence->summary(); 546 mNextSummary = incidence->summary();
537 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 547 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
538 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 548 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
539 newNextAlarm = true; 549 newNextAlarm = true;
540 mNextAlarmIncidence = incidence; 550 mNextAlarmIncidence = incidence;
541 } else { 551 } else {
542 if ( incidence == mNextAlarmIncidence ) { 552 if ( incidence == mNextAlarmIncidence ) {
543 computeNextAlarm = true; 553 computeNextAlarm = true;
544 } 554 }
545 } 555 }
546 } else { 556 } else {
547 if ( mNextAlarmIncidence == incidence ) { 557 if ( mNextAlarmIncidence == incidence ) {
548 computeNextAlarm = true; 558 computeNextAlarm = true;
549 } 559 }
550 } 560 }
551 } else { // deleted 561 } else { // deleted
552 if ( incidence == mNextAlarmIncidence ) { 562 if ( incidence == mNextAlarmIncidence ) {
553 computeNextAlarm = true; 563 computeNextAlarm = true;
554 } 564 }
555 } 565 }
556 } 566 }
557 if ( computeNextAlarm ) { 567 if ( computeNextAlarm ) {
558 deRegisterAlarm(); 568 deRegisterAlarm();
559 nextA = nextAlarm( 1000 ); 569 nextA = nextAlarm( 1000 );
560 if (! mNextAlarmIncidence ) { 570 if (! mNextAlarmIncidence ) {
561 return; 571 return;
562 } 572 }
563 newNextAlarm = true; 573 newNextAlarm = true;
564 } 574 }
565 if ( newNextAlarm ) 575 if ( newNextAlarm )
566 registerAlarm(); 576 registerAlarm();
567} 577}
568QString CalendarLocal:: getAlarmNotification() 578QString CalendarLocal:: getAlarmNotification()
569{ 579{
570 QString ret; 580 QString ret;
571 // this should not happen 581 // this should not happen
572 if (! mNextAlarmIncidence ) 582 if (! mNextAlarmIncidence )
573 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 583 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
574 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 584 Alarm* alarm = mNextAlarmIncidence->alarms().first();
575 if ( alarm->type() == Alarm::Procedure ) { 585 if ( alarm->type() == Alarm::Procedure ) {
576 ret = "proc_alarm" + alarm->programFile()+"+++"; 586 ret = "proc_alarm" + alarm->programFile()+"+++";
577 } else { 587 } else {
578 ret = "audio_alarm" +alarm->audioFile() +"+++"; 588 ret = "audio_alarm" +alarm->audioFile() +"+++";
579 } 589 }
580 ret += "cal_alarm"+ mNextSummary.left( 25 ); 590 ret += "cal_alarm"+ mNextSummary.left( 25 );
581 if ( mNextSummary.length() > 25 ) 591 if ( mNextSummary.length() > 25 )
582 ret += "\n" + mNextSummary.mid(25, 25 ); 592 ret += "\n" + mNextSummary.mid(25, 25 );
583 ret+= "\n"+mNextAlarmEventDateTimeString; 593 ret+= "\n"+mNextAlarmEventDateTimeString;
584 return ret; 594 return ret;
585} 595}
586void CalendarLocal::registerAlarm() 596void CalendarLocal::registerAlarm()
587{ 597{
588 mLastAlarmNotificationString = getAlarmNotification(); 598 mLastAlarmNotificationString = getAlarmNotification();
589 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 599 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
590 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 600 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
591// #ifndef DESKTOP_VERSION 601// #ifndef DESKTOP_VERSION
592// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 602// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
593// #endif 603// #endif
594} 604}
595void CalendarLocal::deRegisterAlarm() 605void CalendarLocal::deRegisterAlarm()
596{ 606{
597 if ( mLastAlarmNotificationString.isNull() ) 607 if ( mLastAlarmNotificationString.isNull() )
598 return; 608 return;
599 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 609 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
600 610
601 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 611 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
602 mNextAlarmEventDateTime = QDateTime(); 612 mNextAlarmEventDateTime = QDateTime();
603// #ifndef DESKTOP_VERSION 613// #ifndef DESKTOP_VERSION
604// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 614// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
605// #endif 615// #endif
606} 616}
607 617
608QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 618QPtrList<Todo> CalendarLocal::todos( const QDate &date )
609{ 619{
610 QPtrList<Todo> todos; 620 QPtrList<Todo> todos;
611 621
612 Todo *todo; 622 Todo *todo;
613 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 623 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
614 if ( !todo->calEnabled() ) continue; 624 if ( !todo->calEnabled() ) continue;
615 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 625 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
616 todos.append( todo ); 626 todos.append( todo );
617 } 627 }
618 } 628 }
619 629
620 filter()->apply( &todos ); 630 filter()->apply( &todos );
621 return todos; 631 return todos;
622} 632}
623void CalendarLocal::reInitAlarmSettings() 633void CalendarLocal::reInitAlarmSettings()
624{ 634{
625 if ( !mNextAlarmIncidence ) { 635 if ( !mNextAlarmIncidence ) {
626 nextAlarm( 1000 ); 636 nextAlarm( 1000 );
627 } 637 }
628 deRegisterAlarm(); 638 deRegisterAlarm();
629 mNextAlarmIncidence = 0; 639 mNextAlarmIncidence = 0;
630 checkAlarmForIncidence( 0, false ); 640 checkAlarmForIncidence( 0, false );
631 641
632} 642}
633 643
634 644
635 645
636QDateTime CalendarLocal::nextAlarm( int daysTo ) 646QDateTime CalendarLocal::nextAlarm( int daysTo )
637{ 647{
638 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 648 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
639 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 649 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
640 QDateTime next; 650 QDateTime next;
641 Event *e; 651 Event *e;
642 bool ok; 652 bool ok;
643 bool found = false; 653 bool found = false;
644 int offset; 654 int offset;
645 mNextAlarmIncidence = 0; 655 mNextAlarmIncidence = 0;
646 for( e = mEventList.first(); e; e = mEventList.next() ) { 656 for( e = mEventList.first(); e; e = mEventList.next() ) {
647 if ( !e->calEnabled() ) continue; 657 if ( !e->calEnabled() ) continue;
648 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 658 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
649 if ( ok ) { 659 if ( ok ) {
650 if ( next < nextA ) { 660 if ( next < nextA ) {
651 nextA = next; 661 nextA = next;
652 found = true; 662 found = true;
653 mNextSummary = e->summary(); 663 mNextSummary = e->summary();
654 mNextAlarmEventDateTime = next.addSecs(offset ) ; 664 mNextAlarmEventDateTime = next.addSecs(offset ) ;
655 mNextAlarmIncidence = (Incidence *) e; 665 mNextAlarmIncidence = (Incidence *) e;
656 } 666 }
657 } 667 }
658 } 668 }
659 Todo *t; 669 Todo *t;
660 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 670 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
661 if ( !t->calEnabled() ) continue; 671 if ( !t->calEnabled() ) continue;
662 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 672 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
663 if ( ok ) { 673 if ( ok ) {
664 if ( next < nextA ) { 674 if ( next < nextA ) {
665 nextA = next; 675 nextA = next;
666 found = true; 676 found = true;
667 mNextSummary = t->summary(); 677 mNextSummary = t->summary();
668 mNextAlarmEventDateTime = next.addSecs(offset ); 678 mNextAlarmEventDateTime = next.addSecs(offset );
669 mNextAlarmIncidence = (Incidence *) t; 679 mNextAlarmIncidence = (Incidence *) t;
670 } 680 }
671 } 681 }
672 } 682 }
673 if ( mNextAlarmIncidence ) { 683 if ( mNextAlarmIncidence ) {
674 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 684 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
675 mNextAlarmDateTime = nextA; 685 mNextAlarmDateTime = nextA;
676 } 686 }
677 return nextA; 687 return nextA;
678} 688}
679Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 689Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
680{ 690{
681 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 691 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
682} 692}
683 693
684Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 694Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
685{ 695{
686 696
687 Alarm::List alarms; 697 Alarm::List alarms;
688 698
689 Event *e; 699 Event *e;
690 700
691 for( e = mEventList.first(); e; e = mEventList.next() ) { 701 for( e = mEventList.first(); e; e = mEventList.next() ) {
692 if ( !e->calEnabled() ) continue; 702 if ( !e->calEnabled() ) continue;
693 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 703 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
694 else appendAlarms( alarms, e, from, to ); 704 else appendAlarms( alarms, e, from, to );
695 } 705 }
696 706
697 Todo *t; 707 Todo *t;
698 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 708 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
699 if ( !t->calEnabled() ) continue; 709 if ( !t->calEnabled() ) continue;
700 appendAlarms( alarms, t, from, to ); 710 appendAlarms( alarms, t, from, to );
701 } 711 }
702 712
703 return alarms; 713 return alarms;
704} 714}
705 715
706void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 716void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
707 const QDateTime &from, const QDateTime &to ) 717 const QDateTime &from, const QDateTime &to )
708{ 718{
709 QPtrList<Alarm> alarmList = incidence->alarms(); 719 QPtrList<Alarm> alarmList = incidence->alarms();
710 Alarm *alarm; 720 Alarm *alarm;
711 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 721 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
712// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 722// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
713// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 723// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
714 if ( alarm->enabled() ) { 724 if ( alarm->enabled() ) {
715 if ( alarm->time() >= from && alarm->time() <= to ) { 725 if ( alarm->time() >= from && alarm->time() <= to ) {
716 alarms.append( alarm ); 726 alarms.append( alarm );
717 } 727 }
718 } 728 }
719 } 729 }
720} 730}
721 731
722void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 732void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
723 Incidence *incidence, 733 Incidence *incidence,
724 const QDateTime &from, 734 const QDateTime &from,
725 const QDateTime &to ) 735 const QDateTime &to )
726{ 736{
727 737
728 QPtrList<Alarm> alarmList = incidence->alarms(); 738 QPtrList<Alarm> alarmList = incidence->alarms();
729 Alarm *alarm; 739 Alarm *alarm;
730 QDateTime qdt; 740 QDateTime qdt;
731 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 741 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
732 if (incidence->recursOn(from.date())) { 742 if (incidence->recursOn(from.date())) {
733 qdt.setTime(alarm->time().time()); 743 qdt.setTime(alarm->time().time());
734 qdt.setDate(from.date()); 744 qdt.setDate(from.date());
735 } 745 }
736 else qdt = alarm->time(); 746 else qdt = alarm->time();
737 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 747 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
738 if ( alarm->enabled() ) { 748 if ( alarm->enabled() ) {
739 if ( qdt >= from && qdt <= to ) { 749 if ( qdt >= from && qdt <= to ) {
740 alarms.append( alarm ); 750 alarms.append( alarm );
741 } 751 }
742 } 752 }
743 } 753 }
744} 754}
745 755
746 756
747/****************************** PROTECTED METHODS ****************************/ 757/****************************** PROTECTED METHODS ****************************/
748 758
749// after changes are made to an event, this should be called. 759// after changes are made to an event, this should be called.
750void CalendarLocal::update( IncidenceBase *incidence ) 760void CalendarLocal::update( IncidenceBase *incidence )
751{ 761{
752 incidence->setSyncStatus( Event::SYNCMOD ); 762 incidence->setSyncStatus( Event::SYNCMOD );
753 incidence->setLastModified( QDateTime::currentDateTime() ); 763 incidence->setLastModified( QDateTime::currentDateTime() );
754 // we should probably update the revision number here, 764 // we should probably update the revision number here,
755 // or internally in the Event itself when certain things change. 765 // or internally in the Event itself when certain things change.
756 // need to verify with ical documentation. 766 // need to verify with ical documentation.
757 767
758 setModified( true ); 768 setModified( true );
759} 769}
760 770
761void CalendarLocal::insertEvent( Event *event ) 771void CalendarLocal::insertEvent( Event *event )
762{ 772{
763 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 773 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
764} 774}
765 775
766 776
767QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 777QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
768{ 778{
769 QPtrList<Event> eventList; 779 QPtrList<Event> eventList;
770 780
771 Event *event; 781 Event *event;
772 for( event = mEventList.first(); event; event = mEventList.next() ) { 782 for( event = mEventList.first(); event; event = mEventList.next() ) {
773 if ( !event->calEnabled() ) continue; 783 if ( !event->calEnabled() ) continue;
774 if ( event->doesRecur() ) { 784 if ( event->doesRecur() ) {
775 if ( event->isMultiDay() ) { 785 if ( event->isMultiDay() ) {
776 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 786 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
777 int i; 787 int i;
778 for ( i = 0; i <= extraDays; i++ ) { 788 for ( i = 0; i <= extraDays; i++ ) {
779 if ( event->recursOn( qd.addDays( -i ) ) ) { 789 if ( event->recursOn( qd.addDays( -i ) ) ) {
780 eventList.append( event ); 790 eventList.append( event );
781 break; 791 break;
782 } 792 }
783 } 793 }
784 } else { 794 } else {
785 if ( event->recursOn( qd ) ) 795 if ( event->recursOn( qd ) )
786 eventList.append( event ); 796 eventList.append( event );
787 } 797 }
788 } else { 798 } else {
789 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 799 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
790 eventList.append( event ); 800 eventList.append( event );
791 } 801 }
792 } 802 }
793 } 803 }
794 804
795 if ( !sorted ) { 805 if ( !sorted ) {
796 return eventList; 806 return eventList;
797 } 807 }
798 808
799 // kdDebug(5800) << "Sorting events for date\n" << endl; 809 // kdDebug(5800) << "Sorting events for date\n" << endl;
800 // now, we have to sort it based on dtStart.time() 810 // now, we have to sort it based on dtStart.time()
801 QPtrList<Event> eventListSorted; 811 QPtrList<Event> eventListSorted;
802 Event *sortEvent; 812 Event *sortEvent;
803 for ( event = eventList.first(); event; event = eventList.next() ) { 813 for ( event = eventList.first(); event; event = eventList.next() ) {
804 sortEvent = eventListSorted.first(); 814 sortEvent = eventListSorted.first();
805 int i = 0; 815 int i = 0;
806 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 816 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
807 { 817 {
808 i++; 818 i++;
809 sortEvent = eventListSorted.next(); 819 sortEvent = eventListSorted.next();
810 } 820 }
811 eventListSorted.insert( i, event ); 821 eventListSorted.insert( i, event );
812 } 822 }
813 return eventListSorted; 823 return eventListSorted;
814} 824}
815 825
816 826
817QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 827QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
818 bool inclusive ) 828 bool inclusive )
819{ 829{
820 Event *event = 0; 830 Event *event = 0;
821 831
822 QPtrList<Event> eventList; 832 QPtrList<Event> eventList;
823 833
824 // Get non-recurring events 834 // Get non-recurring events
825 for( event = mEventList.first(); event; event = mEventList.next() ) { 835 for( event = mEventList.first(); event; event = mEventList.next() ) {
826 if ( !event->calEnabled() ) continue; 836 if ( !event->calEnabled() ) continue;
827 if ( event->doesRecur() ) { 837 if ( event->doesRecur() ) {
828 QDate rStart = event->dtStart().date(); 838 QDate rStart = event->dtStart().date();
829 bool found = false; 839 bool found = false;
830 if ( inclusive ) { 840 if ( inclusive ) {
831 if ( rStart >= start && rStart <= end ) { 841 if ( rStart >= start && rStart <= end ) {
832 // Start date of event is in range. Now check for end date. 842 // Start date of event is in range. Now check for end date.
833 // if duration is negative, event recurs forever, so do not include it. 843 // if duration is negative, event recurs forever, so do not include it.
834 if ( event->recurrence()->duration() == 0 ) { // End date set 844 if ( event->recurrence()->duration() == 0 ) { // End date set
835 QDate rEnd = event->recurrence()->endDate(); 845 QDate rEnd = event->recurrence()->endDate();
836 if ( rEnd >= start && rEnd <= end ) { // End date within range 846 if ( rEnd >= start && rEnd <= end ) { // End date within range
837 found = true; 847 found = true;
838 } 848 }
839 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 849 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
840 // TODO: Calculate end date from duration. Should be done in Event 850 // TODO: Calculate end date from duration. Should be done in Event
841 // For now exclude all events with a duration. 851 // For now exclude all events with a duration.
842 } 852 }
843 } 853 }
844 } else { 854 } else {
845 bool founOne; 855 bool founOne;
846 QDate next = event->getNextOccurence( start, &founOne ).date(); 856 QDate next = event->getNextOccurence( start, &founOne ).date();
847 if ( founOne ) { 857 if ( founOne ) {
848 if ( next <= end ) { 858 if ( next <= end ) {
849 found = true; 859 found = true;
850 } 860 }
851 } 861 }
852 862
853 /* 863 /*
854 // crap !!! 864 // crap !!!
855 if ( rStart <= end ) { // Start date not after range 865 if ( rStart <= end ) { // Start date not after range
856 if ( rStart >= start ) { // Start date within range 866 if ( rStart >= start ) { // Start date within range
857 found = true; 867 found = true;
858 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 868 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
859 found = true; 869 found = true;
860 } else if ( event->recurrence()->duration() == 0 ) { // End date set 870 } else if ( event->recurrence()->duration() == 0 ) { // End date set
861 QDate rEnd = event->recurrence()->endDate(); 871 QDate rEnd = event->recurrence()->endDate();
862 if ( rEnd >= start && rEnd <= end ) { // End date within range 872 if ( rEnd >= start && rEnd <= end ) { // End date within range
863 found = true; 873 found = true;
864 } 874 }
865 } else { // Duration set 875 } else { // Duration set
866 // TODO: Calculate end date from duration. Should be done in Event 876 // TODO: Calculate end date from duration. Should be done in Event
867 // For now include all events with a duration. 877 // For now include all events with a duration.
868 found = true; 878 found = true;
869 } 879 }
870 } 880 }
871 */ 881 */
872 882
873 } 883 }
874 884
875 if ( found ) eventList.append( event ); 885 if ( found ) eventList.append( event );
876 } else { 886 } else {
877 QDate s = event->dtStart().date(); 887 QDate s = event->dtStart().date();
878 QDate e = event->dtEnd().date(); 888 QDate e = event->dtEnd().date();
879 889
880 if ( inclusive ) { 890 if ( inclusive ) {
881 if ( s >= start && e <= end ) { 891 if ( s >= start && e <= end ) {
882 eventList.append( event ); 892 eventList.append( event );
883 } 893 }
884 } else { 894 } else {
885 if ( ( e >= start && s <= end ) ) { 895 if ( ( e >= start && s <= end ) ) {
886 eventList.append( event ); 896 eventList.append( event );
887 } 897 }
888 } 898 }
889 } 899 }
890 } 900 }
891 901
892 return eventList; 902 return eventList;
893} 903}
894 904
895QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 905QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
896{ 906{
897 return rawEventsForDate( qdt.date() ); 907 return rawEventsForDate( qdt.date() );
898} 908}
899 909
900QPtrList<Event> CalendarLocal::rawEvents() 910QPtrList<Event> CalendarLocal::rawEvents()
901{ 911{
902 QPtrList<Event> el; 912 QPtrList<Event> el;
903 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 913 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
904 if ( it->calEnabled() ) el.append( it ); 914 if ( it->calEnabled() ) el.append( it );
905 return el; 915 return el;
906} 916}
907 917
908bool CalendarLocal::addJournal(Journal *journal) 918bool CalendarLocal::addJournal(Journal *journal)
909{ 919{
910 mJournalList.append(journal); 920 mJournalList.append(journal);
911 921
912 journal->registerObserver( this ); 922 journal->registerObserver( this );
913 923
914 setModified( true ); 924 setModified( true );
915 if ( journal->calID() == 0 ) 925 if ( journal->calID() == 0 )
916 journal->setCalID( mDefaultCalendar ); 926 journal->setCalID( mDefaultCalendar );
917 journal->setCalEnabled( true ); 927 journal->setCalEnabled( true );
918 return true; 928 return true;
919} 929}
920 930
921void CalendarLocal::deleteJournal( Journal *journal ) 931void CalendarLocal::deleteJournal( Journal *journal )
922{ 932{
923 clearUndo(journal); 933 clearUndo(journal);
924 if ( mJournalList.removeRef(journal) ) { 934 if ( mJournalList.removeRef(journal) ) {
925 setModified( true ); 935 setModified( true );
926 } 936 }
927} 937}
928 938
929QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) 939QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date )
930{ 940{
931 QPtrList<Journal> el; 941 QPtrList<Journal> el;
932 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 942 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
933 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); 943 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it );
934 return el; 944 return el;
935} 945}
936Journal *CalendarLocal::journal( const QDate &date ) 946Journal *CalendarLocal::journal( const QDate &date )
937{ 947{
938// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 948// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
939 949
940 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 950 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
941 if ( it->calEnabled() && it->dtStart().date() == date ) 951 if ( it->calEnabled() && it->dtStart().date() == date )
942 return it; 952 return it;
943 953
944 return 0; 954 return 0;
945} 955}
946 956
947Journal *CalendarLocal::journal( const QString &uid ) 957Journal *CalendarLocal::journal( const QString &uid )
948{ 958{
949 Journal * retVal = 0; 959 Journal * retVal = 0;
950 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 960 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
951 if ( it->calEnabled() && it->uid() == uid ) { 961 if ( it->calEnabled() && it->uid() == uid ) {
952 if ( retVal ) { 962 if ( retVal ) {
953 if ( retVal->calID() > it->calID() ) { 963 if ( retVal->calID() > it->calID() ) {
954 retVal = it; 964 retVal = it;
955 } 965 }
956 } else { 966 } else {
957 retVal = it; 967 retVal = it;
958 } 968 }
959 } 969 }
960 return retVal; 970 return retVal;
961} 971}
962 972
963QPtrList<Journal> CalendarLocal::journals() 973QPtrList<Journal> CalendarLocal::journals()
964{ 974{
965 QPtrList<Journal> el; 975 QPtrList<Journal> el;
966 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 976 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
967 if ( it->calEnabled() ) el.append( it ); 977 if ( it->calEnabled() ) el.append( it );
968 return el; 978 return el;
969} 979}
970void CalendarLocal::setCalendarRemove( int id ) 980void CalendarLocal::setCalendarRemove( int id )
971{ 981{
972 982
973 { 983 {
974 QPtrList<Event> EventList = mEventList; 984 QPtrList<Event> EventList = mEventList;
975 Event * ev = EventList.first(); 985 Event * ev = EventList.first();
976 while ( ev ) { 986 while ( ev ) {
977 if ( ev->calID() == id ) 987 if ( ev->calID() == id )
978 deleteEvent( ev ); 988 deleteEvent( ev );
979 ev = EventList.next(); 989 ev = EventList.next();
980 } 990 }
981 } 991 }
982 { 992 {
983 993
984 QPtrList<Todo> TodoList = mTodoList; 994 QPtrList<Todo> TodoList = mTodoList;
985 Todo * ev = TodoList.first(); 995 Todo * ev = TodoList.first();
986 while ( ev ) { 996 while ( ev ) {
987 if ( ev->calID() == id ) 997 if ( ev->calID() == id )
988 deleteTodo( ev ); 998 deleteTodo( ev );
989 ev = TodoList.next(); 999 ev = TodoList.next();
990 } 1000 }
991 } 1001 }
992 { 1002 {
993 QPtrList<Journal> JournalList = mJournalList; 1003 QPtrList<Journal> JournalList = mJournalList;
994 Journal * ev = JournalList.first(); 1004 Journal * ev = JournalList.first();
995 while ( ev ) { 1005 while ( ev ) {
996 if ( ev->calID() == id ) 1006 if ( ev->calID() == id )
997 deleteJournal( ev ); 1007 deleteJournal( ev );
998 ev = JournalList.next(); 1008 ev = JournalList.next();
999 } 1009 }
1000 } 1010 }
1001 1011
1002 clearUndo(0); 1012 clearUndo(0);
1003 1013
1004} 1014}
1005 1015
1016void CalendarLocal::setAllCalendarEnabled( bool enable )
1017{
1018 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1019 it->setCalEnabled( enable );
1020
1021 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1022 it->setCalEnabled( enable );
1023
1024 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1025 it->setCalEnabled( enable );
1026
1027
1028}
1006void CalendarLocal::setCalendarEnabled( int id, bool enable ) 1029void CalendarLocal::setCalendarEnabled( int id, bool enable )
1007{ 1030{
1008 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1031 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1009 if ( it->calID() == id ) it->setCalEnabled( enable ); 1032 if ( it->calID() == id ) it->setCalEnabled( enable );
1010 1033
1011 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1034 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1012 if ( it->calID() == id ) it->setCalEnabled( enable ); 1035 if ( it->calID() == id ) it->setCalEnabled( enable );
1013 1036
1014 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1037 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1015 if ( it->calID() == id ) it->setCalEnabled( enable ); 1038 if ( it->calID() == id ) it->setCalEnabled( enable );
1016 1039
1017} 1040}
1018 1041
1019void CalendarLocal::setReadOnly( int id, bool enable ) 1042void CalendarLocal::setReadOnly( int id, bool enable )
1020{ 1043{
1021 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1044 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1022 if ( it->calID() == id ) it->setReadOnly( enable ); 1045 if ( it->calID() == id ) it->setReadOnly( enable );
1023 1046
1024 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1047 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1025 if ( it->calID() == id ) it->setReadOnly( enable ); 1048 if ( it->calID() == id ) it->setReadOnly( enable );
1026 1049
1027 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1050 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1028 if ( it->calID() == id ) it->setReadOnly( enable ); 1051 if ( it->calID() == id ) it->setReadOnly( enable );
1029 1052
1030} 1053}
1031 1054
1032void CalendarLocal::setAlarmEnabled( int id, bool enable ) 1055void CalendarLocal::setAlarmEnabled( int id, bool enable )
1033{ 1056{
1034 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1057 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1035 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1058 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1036 1059
1037 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1060 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1038 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1061 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1039 1062
1040 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1063 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1041 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1064 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1042 reInitAlarmSettings(); 1065 reInitAlarmSettings();
1043 1066
1044} 1067}
1045void CalendarLocal::setDefaultCalendarEnabledOnly() 1068void CalendarLocal::setDefaultCalendarEnabledOnly()
1046{ 1069{
1047 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1070 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1048 it->setCalEnabled( it->calID() == mDefaultCalendar ); 1071 it->setCalEnabled( it->calID() == mDefaultCalendar );
1049 1072
1050 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1073 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1051 it->setCalEnabled( it->calID() == mDefaultCalendar); 1074 it->setCalEnabled( it->calID() == mDefaultCalendar);
1052 1075
1053 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1076 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1054 it->setCalEnabled( it->calID() == mDefaultCalendar); 1077 it->setCalEnabled( it->calID() == mDefaultCalendar);
1055 1078
1056} 1079}
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index eb7bf34..b70f0c9 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -1,232 +1,233 @@
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, bool doNotCheckDuplicates ); 50 Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates );
51 void setSyncEventsReadOnly(); 51 void setSyncEventsReadOnly();
52 void setSyncEventsEnabled(); 52 void setSyncEventsEnabled();
53 void stopAllTodos(); 53 void stopAllTodos();
54 /** 54 /**
55 Loads a calendar on disk in vCalendar or iCalendar format into the current 55 Loads a calendar on disk in vCalendar or iCalendar format into the current
56 calendar. Any information already present is lost. 56 calendar. Any information already present is lost.
57 @return true, if successfull, false on error. 57 @return true, if successfull, false on error.
58 @param fileName the name of the calendar on disk. 58 @param fileName the name of the calendar on disk.
59 */ 59 */
60 bool load( const QString &fileName ); 60 bool load( const QString &fileName );
61 /** 61 /**
62 Writes out the calendar to disk in the specified \a format. 62 Writes out the calendar to disk in the specified \a format.
63 CalendarLocal takes ownership of the CalFormat object. 63 CalendarLocal takes ownership of the CalFormat object.
64 @return true, if successfull, false on error. 64 @return true, if successfull, false on error.
65 @param fileName the name of the file 65 @param fileName the name of the file
66 */ 66 */
67 bool save( const QString &fileName, CalFormat *format = 0 ); 67 bool save( const QString &fileName, CalFormat *format = 0 );
68 68
69 /** 69 /**
70 Clears out the current calendar, freeing all used memory etc. etc. 70 Clears out the current calendar, freeing all used memory etc. etc.
71 */ 71 */
72 void close(); 72 void close();
73 73
74 void save() {} 74 void save() {}
75 75
76 /** 76 /**
77 Add Event to calendar. 77 Add Event to calendar.
78 */ 78 */
79 void removeSyncInfo( QString syncProfile); 79 void removeSyncInfo( QString syncProfile);
80 bool addAnniversaryNoDup( Event *event ); 80 bool addAnniversaryNoDup( Event *event );
81 bool addEventNoDup( Event *event ); 81 bool addEventNoDup( Event *event );
82 bool addEvent( Event *event ); 82 bool addEvent( Event *event );
83 /** 83 /**
84 Deletes an event from this calendar. 84 Deletes an event from this calendar.
85 */ 85 */
86 void deleteEvent( Event *event ); 86 void deleteEvent( Event *event );
87 87
88 /** 88 /**
89 Retrieves an event on the basis of the unique string ID. 89 Retrieves an event on the basis of the unique string ID.
90 */ 90 */
91 Event *event( const QString &uid ); 91 Event *event( const QString &uid );
92 /** 92 /**
93 Return unfiltered list of all events in calendar. 93 Return unfiltered list of all events in calendar.
94 */ 94 */
95 QPtrList<Event> rawEvents(); 95 QPtrList<Event> rawEvents();
96 QPtrList<Event> getExternLastSyncEvents(); 96 QPtrList<Event> getExternLastSyncEvents();
97 /** 97 /**
98 Add a todo to the todolist. 98 Add a todo to the todolist.
99 */ 99 */
100 bool addTodo( Todo *todo ); 100 bool addTodo( Todo *todo );
101 bool addTodoNoDup( Todo *todo ); 101 bool addTodoNoDup( Todo *todo );
102 /** 102 /**
103 Remove a todo from the todolist. 103 Remove a todo from the todolist.
104 */ 104 */
105 void deleteTodo( Todo * ); 105 void deleteTodo( Todo * );
106 /** 106 /**
107 Searches todolist for an event with this unique string identifier, 107 Searches todolist for an event with this unique string identifier,
108 returns a pointer or null. 108 returns a pointer or null.
109 */ 109 */
110 Todo *todo( const QString &uid ); 110 Todo *todo( const QString &uid );
111 /** 111 /**
112 Return list of all todos. 112 Return list of all todos.
113 */ 113 */
114 QPtrList<Todo> rawTodos(); 114 QPtrList<Todo> rawTodos();
115 /** 115 /**
116 Returns list of todos due on the specified date. 116 Returns list of todos due on the specified date.
117 */ 117 */
118 QPtrList<Todo> todos( const QDate &date ); 118 QPtrList<Todo> todos( const QDate &date );
119 /** 119 /**
120 Return list of all todos. 120 Return list of all todos.
121 121
122 Workaround because compiler does not recognize function of base class. 122 Workaround because compiler does not recognize function of base class.
123 */ 123 */
124 QPtrList<Todo> todos() { return Calendar::todos(); } 124 QPtrList<Todo> todos() { return Calendar::todos(); }
125 125
126 /** 126 /**
127 Add a Journal entry to calendar. 127 Add a Journal entry to calendar.
128 */ 128 */
129 bool addJournal( Journal * ); 129 bool addJournal( Journal * );
130 /** 130 /**
131 Remove a Journal from the calendar. 131 Remove a Journal from the calendar.
132 */ 132 */
133 void deleteJournal( Journal * ); 133 void deleteJournal( Journal * );
134 /** 134 /**
135 Return Journal for given date. 135 Return Journal for given date.
136 */ 136 */
137 Journal *journal( const QDate & ); 137 Journal *journal( const QDate & );
138 QPtrList<Journal> journals4Date( const QDate & ); 138 QPtrList<Journal> journals4Date( const QDate & );
139 /** 139 /**
140 Return Journal with given UID. 140 Return Journal with given UID.
141 */ 141 */
142 Journal *journal( const QString &uid ); 142 Journal *journal( const QString &uid );
143 /** 143 /**
144 Return list of all Journals stored in calendar. 144 Return list of all Journals stored in calendar.
145 */ 145 */
146 QPtrList<Journal> journals(); 146 QPtrList<Journal> journals();
147 147
148 /** 148 /**
149 Return all alarms, which ocur in the given time interval. 149 Return all alarms, which ocur in the given time interval.
150 */ 150 */
151 Alarm::List alarms( const QDateTime &from, const QDateTime &to ); 151 Alarm::List alarms( const QDateTime &from, const QDateTime &to );
152 152
153 /** 153 /**
154 Return all alarms, which ocur before given date. 154 Return all alarms, which ocur before given date.
155 */ 155 */
156 Alarm::List alarmsTo( const QDateTime &to ); 156 Alarm::List alarmsTo( const QDateTime &to );
157 157
158 QDateTime nextAlarm( int daysTo ) ; 158 QDateTime nextAlarm( int daysTo ) ;
159 QDateTime nextAlarmEventDateTime() const; 159 QDateTime nextAlarmEventDateTime() const;
160 void checkAlarmForIncidence( Incidence *, bool deleted ) ; 160 void checkAlarmForIncidence( Incidence *, bool deleted ) ;
161 void registerAlarm(); 161 void registerAlarm();
162 void deRegisterAlarm(); 162 void deRegisterAlarm();
163 QString getAlarmNotification(); 163 QString getAlarmNotification();
164 QString nextSummary() const ; 164 QString nextSummary() const ;
165 /** 165 /**
166 This method should be called whenever a Event is modified directly 166 This method should be called whenever a Event is modified directly
167 via it's pointer. It makes sure that the calendar is internally 167 via it's pointer. It makes sure that the calendar is internally
168 consistent. 168 consistent.
169 */ 169 */
170 void update( IncidenceBase *incidence ); 170 void update( IncidenceBase *incidence );
171 171
172 /** 172 /**
173 Builds and then returns a list of all events that match for the 173 Builds and then returns a list of all events that match for the
174 date specified. useful for dayView, etc. etc. 174 date specified. useful for dayView, etc. etc.
175 */ 175 */
176 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); 176 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false );
177 /** 177 /**
178 Get unfiltered events for date \a qdt. 178 Get unfiltered events for date \a qdt.
179 */ 179 */
180 QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); 180 QPtrList<Event> rawEventsForDate( const QDateTime &qdt );
181 /** 181 /**
182 Get unfiltered events in a range of dates. If inclusive is set to true, 182 Get unfiltered events in a range of dates. If inclusive is set to true,
183 only events are returned, which are completely included in the range. 183 only events are returned, which are completely included in the range.
184 */ 184 */
185 QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 185 QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
186 bool inclusive = false ); 186 bool inclusive = false );
187 Todo *todo( QString, QString ); 187 Todo *todo( QString, QString );
188 Event *event( QString, QString ); 188 Event *event( QString, QString );
189 void getIncidenceCount( int calId, int& events, int & todos, int & journals); 189 void getIncidenceCount( int calId, int& events, int & todos, int & journals);
190 190
191public slots: 191public slots:
192 void setCalendarEnabled( int id, bool enable ); 192 void setCalendarEnabled( int id, bool enable );
193 void setAlarmEnabled( int id, bool enable ); 193 void setAlarmEnabled( int id, bool enable );
194 void setReadOnly( int id, bool enable ); 194 void setReadOnly( int id, bool enable );
195 void setDefaultCalendarEnabledOnly(); 195 void setDefaultCalendarEnabledOnly();
196 void setCalendarRemove( int id ); 196 void setCalendarRemove( int id );
197 void setAllCalendarEnabled( bool enable );
197 198
198 protected: 199 protected:
199 200
200 // Event* mNextAlarmEvent; 201 // Event* mNextAlarmEvent;
201 QString mNextSummary; 202 QString mNextSummary;
202 QString mNextAlarmEventDateTimeString; 203 QString mNextAlarmEventDateTimeString;
203 QString mLastAlarmNotificationString; 204 QString mLastAlarmNotificationString;
204 QDateTime mNextAlarmEventDateTime; 205 QDateTime mNextAlarmEventDateTime;
205 QDateTime mNextAlarmDateTime; 206 QDateTime mNextAlarmDateTime;
206 void reInitAlarmSettings(); 207 void reInitAlarmSettings();
207 208
208 /** Notification function of IncidenceBase::Observer. */ 209 /** Notification function of IncidenceBase::Observer. */
209 void incidenceUpdated( IncidenceBase *i ) { update( i ); } 210 void incidenceUpdated( IncidenceBase *i ) { update( i ); }
210 211
211 /** inserts an event into its "proper place" in the calendar. */ 212 /** inserts an event into its "proper place" in the calendar. */
212 void insertEvent( Event *event ); 213 void insertEvent( Event *event );
213 214
214 /** Append alarms of incidence in interval to list of alarms. */ 215 /** Append alarms of incidence in interval to list of alarms. */
215 void appendAlarms( Alarm::List &alarms, Incidence *incidence, 216 void appendAlarms( Alarm::List &alarms, Incidence *incidence,
216 const QDateTime &from, const QDateTime &to ); 217 const QDateTime &from, const QDateTime &to );
217 218
218 /** Append alarms of recurring events in interval to list of alarms. */ 219 /** Append alarms of recurring events in interval to list of alarms. */
219 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, 220 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence,
220 const QDateTime &from, const QDateTime &to ); 221 const QDateTime &from, const QDateTime &to );
221 222
222 private: 223 private:
223 void init(); 224 void init();
224 225
225 QPtrList<Event> mEventList; 226 QPtrList<Event> mEventList;
226 QPtrList<Todo> mTodoList; 227 QPtrList<Todo> mTodoList;
227 QPtrList<Journal> mJournalList; 228 QPtrList<Journal> mJournalList;
228}; 229};
229 230
230} 231}
231 232
232#endif 233#endif