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