summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2005-11-28 01:23:02 (UTC)
committer zautrix <zautrix>2005-11-28 01:23:02 (UTC)
commite08811c2246f63b2b63f9db6b65701344460f3d7 (patch) (unidiff)
treed450f486a9472d80eb86f605237b828a0e7ffae6 /libkcal
parent854d4a0c686962cd73ac7418b5fbf4b2d73adab7 (diff)
downloadkdepimpi-e08811c2246f63b2b63f9db6b65701344460f3d7.zip
kdepimpi-e08811c2246f63b2b63f9db6b65701344460f3d7.tar.gz
kdepimpi-e08811c2246f63b2b63f9db6b65701344460f3d7.tar.bz2
ync
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp9
-rw-r--r--libkcal/calendar.h3
-rw-r--r--libkcal/calendarlocal.cpp81
-rw-r--r--libkcal/calendarlocal.h3
-rw-r--r--libkcal/incidence.cpp6
-rw-r--r--libkcal/incidence.h1
6 files changed, 83 insertions, 20 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 8535191..1350f6d 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,523 +1,526 @@
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
11 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 13 Library General Public License for more details.
15 14
16 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
20*/ 19*/
21 20
22#include <stdlib.h> 21#include <stdlib.h>
23#include <time.h> 22#include <time.h>
24 23
25#include <kdebug.h> 24#include <kdebug.h>
26#include <kglobal.h> 25#include <kglobal.h>
27#include <klocale.h> 26#include <klocale.h>
28 27
29#include "exceptions.h" 28#include "exceptions.h"
30#include "calfilter.h" 29#include "calfilter.h"
31 30
32#include "calendar.h" 31#include "calendar.h"
33#include "syncdefines.h" 32#include "syncdefines.h"
34 33
35using namespace KCal; 34using namespace KCal;
36 35
37Calendar::Calendar() 36Calendar::Calendar()
38{ 37{
39 38
40 init(); 39 init();
41 setTimeZoneId( " 00:00 Europe/London(UTC)" ); 40 setTimeZoneId( " 00:00 Europe/London(UTC)" );
42} 41}
43 42
44Calendar::Calendar( const QString &timeZoneId ) 43Calendar::Calendar( const QString &timeZoneId )
45{ 44{
46 45
47 init(); 46 init();
48 setTimeZoneId(timeZoneId); 47 setTimeZoneId(timeZoneId);
49} 48}
50 49
51void Calendar::init() 50void Calendar::init()
52{ 51{
53 mObserver = 0; 52 mObserver = 0;
54 mNewObserver = false; 53 mNewObserver = false;
55 mUndoIncidence = 0; 54 mUndoIncidence = 0;
56 mDeleteIncidencesOnClose = true; 55 mDeleteIncidencesOnClose = true;
57 mModified = false; 56 mModified = false;
58 mDefaultCalendar = 1; 57 mDefaultCalendar = 1;
59 // Setup default filter, which does nothing 58 // Setup default filter, which does nothing
60 mDefaultFilter = new CalFilter; 59 mDefaultFilter = new CalFilter;
61 mFilter = mDefaultFilter; 60 mFilter = mDefaultFilter;
62 mFilter->setEnabled(false); 61 mFilter->setEnabled(false);
63 62
64 // initialize random numbers. This is a hack, and not 63 // initialize random numbers. This is a hack, and not
65 // even that good of one at that. 64 // even that good of one at that.
66// srandom(time(0)); 65// srandom(time(0));
67 66
68 // user information... 67 // user information...
69 setOwner(i18n("Unknown Name")); 68 setOwner(i18n("Unknown Name"));
70 setEmail(i18n("unknown@nowhere")); 69 setEmail(i18n("unknown@nowhere"));
71 70
72#if 0 71#if 0
73 tmpStr = KOPrefs::instance()->mTimeZone; 72 tmpStr = KOPrefs::instance()->mTimeZone;
74// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; 73// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
75 int dstSetting = KOPrefs::instance()->mDaylightSavings; 74 int dstSetting = KOPrefs::instance()->mDaylightSavings;
76 extern long int timezone; 75 extern long int timezone;
77 struct tm *now; 76 struct tm *now;
78 time_t curtime; 77 time_t curtime;
79 curtime = time(0); 78 curtime = time(0);
80 now = localtime(&curtime); 79 now = localtime(&curtime);
81 int hourOff = - ((timezone / 60) / 60); 80 int hourOff = - ((timezone / 60) / 60);
82 if (now->tm_isdst) 81 if (now->tm_isdst)
83 hourOff += 1; 82 hourOff += 1;
84 QString tzStr; 83 QString tzStr;
85 tzStr.sprintf("%.2d%.2d", 84 tzStr.sprintf("%.2d%.2d",
86 hourOff, 85 hourOff,
87 abs((timezone / 60) % 60)); 86 abs((timezone / 60) % 60));
88 87
89 // if no time zone was in the config file, write what we just discovered. 88 // if no time zone was in the config file, write what we just discovered.
90 if (tmpStr.isEmpty()) { 89 if (tmpStr.isEmpty()) {
91// KOPrefs::instance()->mTimeZone = tzStr; 90// KOPrefs::instance()->mTimeZone = tzStr;
92 } else { 91 } else {
93 tzStr = tmpStr; 92 tzStr = tmpStr;
94 } 93 }
95 94
96 // if daylight savings has changed since last load time, we need 95 // if daylight savings has changed since last load time, we need
97 // to rewrite these settings to the config file. 96 // to rewrite these settings to the config file.
98 if ((now->tm_isdst && !dstSetting) || 97 if ((now->tm_isdst && !dstSetting) ||
99 (!now->tm_isdst && dstSetting)) { 98 (!now->tm_isdst && dstSetting)) {
100 KOPrefs::instance()->mTimeZone = tzStr; 99 KOPrefs::instance()->mTimeZone = tzStr;
101 KOPrefs::instance()->mDaylightSavings = now->tm_isdst; 100 KOPrefs::instance()->mDaylightSavings = now->tm_isdst;
102 } 101 }
103 102
104 setTimeZone(tzStr); 103 setTimeZone(tzStr);
105#endif 104#endif
106 105
107// KOPrefs::instance()->writeConfig(); 106// KOPrefs::instance()->writeConfig();
108} 107}
109 108
110Calendar::~Calendar() 109Calendar::~Calendar()
111{ 110{
112 delete mDefaultFilter; 111 delete mDefaultFilter;
113 clearUndo( 0 ); 112 clearUndo( 0 );
114} 113}
115void Calendar::clearUndo( Incidence * newUndo ) 114void Calendar::clearUndo( Incidence * newUndo )
116{ 115{
117 116
118 if ( mUndoIncidence ) { 117 if ( mUndoIncidence ) {
119 if ( mUndoIncidence->typeID() == eventID ) 118 if ( mUndoIncidence->typeID() == eventID )
120 delete ((Event*) mUndoIncidence) ; 119 delete ((Event*) mUndoIncidence) ;
121 else if ( mUndoIncidence->typeID() == todoID ) 120 else if ( mUndoIncidence->typeID() == todoID )
122 delete ( (Todo*) mUndoIncidence ); 121 delete ( (Todo*) mUndoIncidence );
123 else if ( mUndoIncidence->typeID() == journalID ) 122 else if ( mUndoIncidence->typeID() == journalID )
124 delete ( (Journal*) mUndoIncidence ); 123 delete ( (Journal*) mUndoIncidence );
125 else 124 else
126 delete mUndoIncidence; 125 delete mUndoIncidence;
127 } 126 }
128 mUndoIncidence = newUndo; 127 mUndoIncidence = newUndo;
129 if ( mUndoIncidence ) { 128 if ( mUndoIncidence ) {
130 mUndoIncidence->clearRelations(); 129 mUndoIncidence->clearRelations();
131 } 130 }
132 131
133} 132}
134 133
135void Calendar::setDontDeleteIncidencesOnClose () 134void Calendar::setDontDeleteIncidencesOnClose ()
136{ 135{
137 mDeleteIncidencesOnClose = false; 136 mDeleteIncidencesOnClose = false;
138} 137}
139void Calendar::setDefaultCalendar( int d ) 138void Calendar::setDefaultCalendar( int d )
140{ 139{
141 mDefaultCalendar = d; 140 mDefaultCalendar = d;
142} 141}
143int Calendar::defaultCalendar() 142int Calendar::defaultCalendar()
144{ 143{
145 return mDefaultCalendar; 144 return mDefaultCalendar;
146} 145}
147const QString &Calendar::getOwner() const 146const QString &Calendar::getOwner() const
148{ 147{
149 return mOwner; 148 return mOwner;
150} 149}
151 150
152bool Calendar::undoDeleteIncidence() 151bool Calendar::undoDeleteIncidence()
153{ 152{
154 if (!mUndoIncidence) 153 if (!mUndoIncidence)
155 return false; 154 return false;
156 addIncidence(mUndoIncidence); 155 addIncidence(mUndoIncidence);
157 mUndoIncidence = 0; 156 mUndoIncidence = 0;
158 return true; 157 return true;
159} 158}
160void Calendar::setOwner(const QString &os) 159void Calendar::setOwner(const QString &os)
161{ 160{
162 int i; 161 int i;
163 mOwner = os; 162 mOwner = os;
164 i = mOwner.find(','); 163 i = mOwner.find(',');
165 if (i != -1) 164 if (i != -1)
166 mOwner = mOwner.left(i); 165 mOwner = mOwner.left(i);
167 166
168 setModified( true ); 167 setModified( true );
169} 168}
170 169
171void Calendar::setTimeZone(const QString & tz) 170void Calendar::setTimeZone(const QString & tz)
172{ 171{
173 bool neg = FALSE; 172 bool neg = FALSE;
174 int hours, minutes; 173 int hours, minutes;
175 QString tmpStr(tz); 174 QString tmpStr(tz);
176 175
177 if (tmpStr.left(1) == "-") 176 if (tmpStr.left(1) == "-")
178 neg = TRUE; 177 neg = TRUE;
179 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 178 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
180 tmpStr.remove(0, 1); 179 tmpStr.remove(0, 1);
181 hours = tmpStr.left(2).toInt(); 180 hours = tmpStr.left(2).toInt();
182 if (tmpStr.length() > 2) 181 if (tmpStr.length() > 2)
183 minutes = tmpStr.right(2).toInt(); 182 minutes = tmpStr.right(2).toInt();
184 else 183 else
185 minutes = 0; 184 minutes = 0;
186 mTimeZone = (60*hours+minutes); 185 mTimeZone = (60*hours+minutes);
187 if (neg) 186 if (neg)
188 mTimeZone = -mTimeZone; 187 mTimeZone = -mTimeZone;
189 mLocalTime = false; 188 mLocalTime = false;
190 189
191 setModified( true ); 190 setModified( true );
192} 191}
193 192
194QString Calendar::getTimeZoneStr() const 193QString Calendar::getTimeZoneStr() const
195{ 194{
196 if (mLocalTime) 195 if (mLocalTime)
197 return ""; 196 return "";
198 QString tmpStr; 197 QString tmpStr;
199 int hours = abs(mTimeZone / 60); 198 int hours = abs(mTimeZone / 60);
200 int minutes = abs(mTimeZone % 60); 199 int minutes = abs(mTimeZone % 60);
201 bool neg = mTimeZone < 0; 200 bool neg = mTimeZone < 0;
202 201
203 tmpStr.sprintf("%c%.2d%.2d", 202 tmpStr.sprintf("%c%.2d%.2d",
204 (neg ? '-' : '+'), 203 (neg ? '-' : '+'),
205 hours, minutes); 204 hours, minutes);
206 return tmpStr; 205 return tmpStr;
207} 206}
208 207
209void Calendar::setTimeZone(int tz) 208void Calendar::setTimeZone(int tz)
210{ 209{
211 mTimeZone = tz; 210 mTimeZone = tz;
212 mLocalTime = false; 211 mLocalTime = false;
213 212
214 setModified( true ); 213 setModified( true );
215} 214}
216 215
217int Calendar::getTimeZone() const 216int Calendar::getTimeZone() const
218{ 217{
219 return mTimeZone; 218 return mTimeZone;
220} 219}
221 220
222void Calendar::setTimeZoneId(const QString &id) 221void Calendar::setTimeZoneId(const QString &id)
223{ 222{
224 mTimeZoneId = id; 223 mTimeZoneId = id;
225 mLocalTime = false; 224 mLocalTime = false;
226 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 225 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
227 if ( mTimeZone > 1000) 226 if ( mTimeZone > 1000)
228 setLocalTime(); 227 setLocalTime();
229 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 228 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
230 setModified( true ); 229 setModified( true );
231} 230}
232 231
233QString Calendar::timeZoneId() const 232QString Calendar::timeZoneId() const
234{ 233{
235 return mTimeZoneId; 234 return mTimeZoneId;
236} 235}
237 236
238void Calendar::setLocalTime() 237void Calendar::setLocalTime()
239{ 238{
240 //qDebug("Calendar::setLocalTime() "); 239 //qDebug("Calendar::setLocalTime() ");
241 mLocalTime = true; 240 mLocalTime = true;
242 mTimeZone = 0; 241 mTimeZone = 0;
243 mTimeZoneId = ""; 242 mTimeZoneId = "";
244 243
245 setModified( true ); 244 setModified( true );
246} 245}
247 246
248bool Calendar::isLocalTime() const 247bool Calendar::isLocalTime() const
249{ 248{
250 return mLocalTime; 249 return mLocalTime;
251} 250}
252 251
253const QString &Calendar::getEmail() 252const QString &Calendar::getEmail()
254{ 253{
255 return mOwnerEmail; 254 return mOwnerEmail;
256} 255}
257 256
258void Calendar::setEmail(const QString &e) 257void Calendar::setEmail(const QString &e)
259{ 258{
260 mOwnerEmail = e; 259 mOwnerEmail = e;
261 260
262 setModified( true ); 261 setModified( true );
263} 262}
264 263
265void Calendar::setFilter(CalFilter *filter) 264void Calendar::setFilter(CalFilter *filter)
266{ 265{
267 mFilter = filter; 266 mFilter = filter;
268} 267}
269 268
270CalFilter *Calendar::filter() 269CalFilter *Calendar::filter()
271{ 270{
272 return mFilter; 271 return mFilter;
273} 272}
274 273
275QPtrList<Incidence> Calendar::incidences() 274QPtrList<Incidence> Calendar::incidences()
276{ 275{
277 QPtrList<Incidence> incidences; 276 QPtrList<Incidence> incidences;
278 277
279 Incidence *i; 278 Incidence *i;
280 279
281 QPtrList<Event> e = events(); 280 QPtrList<Event> e = events();
282 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 281 for( i = e.first(); i; i = e.next() ) incidences.append( i );
283 282
284 QPtrList<Todo> t = todos(); 283 QPtrList<Todo> t = todos();
285 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 284 for( i = t.first(); i; i = t.next() ) incidences.append( i );
286 285
287 QPtrList<Journal> j = journals(); 286 QPtrList<Journal> j = journals();
288 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 287 for( i = j.first(); i; i = j.next() ) incidences.append( i );
289 288
290 return incidences; 289 return incidences;
291} 290}
292 291
293void Calendar::resetPilotStat(int id ) 292void Calendar::resetPilotStat(int id )
294{ 293{
295 QPtrList<Incidence> incidences; 294 QPtrList<Incidence> incidences;
296 295
297 Incidence *i; 296 Incidence *i;
298 297
299 QPtrList<Event> e = rawEvents(); 298 QPtrList<Event> e = rawEvents();
300 for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); 299 for( i = e.first(); i; i = e.next() ) i->setPilotId( id );
301 300
302 QPtrList<Todo> t = rawTodos(); 301 QPtrList<Todo> t = rawTodos();
303 for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); 302 for( i = t.first(); i; i = t.next() ) i->setPilotId( id );
304 303
305 QPtrList<Journal> j = journals(); 304 QPtrList<Journal> j = journals();
306 for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); 305 for( i = j.first(); i; i = j.next() ) i->setPilotId( id );
307} 306}
308void Calendar::resetTempSyncStat() 307void Calendar::resetTempSyncStat()
309{ 308{
310 QPtrList<Incidence> incidences; 309 QPtrList<Incidence> incidences;
311 310
312 Incidence *i; 311 Incidence *i;
313 312
314 QPtrList<Event> e = rawEvents(); 313 QPtrList<Event> e = rawEvents();
315 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 314 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
316 315
317 QPtrList<Todo> t = rawTodos(); 316 QPtrList<Todo> t = rawTodos();
318 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 317 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
319 318
320 QPtrList<Journal> j = journals(); 319 QPtrList<Journal> j = journals();
321 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 320 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
322} 321}
323QPtrList<Incidence> Calendar::rawIncidences() 322QPtrList<Incidence> Calendar::rawIncidences()
324{ 323{
325 QPtrList<Incidence> incidences; 324 QPtrList<Incidence> incidences;
326 325
327 Incidence *i; 326 Incidence *i;
328 327
329 QPtrList<Event> e = rawEvents(); 328 QPtrList<Event> e = rawEvents();
330 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 329 for( i = e.first(); i; i = e.next() ) incidences.append( i );
331 330
332 QPtrList<Todo> t = rawTodos(); 331 QPtrList<Todo> t = rawTodos();
333 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 332 for( i = t.first(); i; i = t.next() ) incidences.append( i );
334 333
335 QPtrList<Journal> j = journals(); 334 QPtrList<Journal> j = journals();
336 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 335 for( i = j.first(); i; i = j.next() ) incidences.append( i );
337 336
338 return incidences; 337 return incidences;
339} 338}
340 339
341QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 340QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
342{ 341{
343 QPtrList<Event> el = rawEventsForDate(date,sorted); 342 QPtrList<Event> el = rawEventsForDate(date,sorted);
344 mFilter->apply(&el); 343 mFilter->apply(&el);
345 return el; 344 return el;
346} 345}
347 346
348QPtrList<Event> Calendar::events( const QDateTime &qdt ) 347QPtrList<Event> Calendar::events( const QDateTime &qdt )
349{ 348{
350 QPtrList<Event> el = rawEventsForDate(qdt); 349 QPtrList<Event> el = rawEventsForDate(qdt);
351 mFilter->apply(&el); 350 mFilter->apply(&el);
352 return el; 351 return el;
353} 352}
354 353
355QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 354QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
356 bool inclusive) 355 bool inclusive)
357{ 356{
358 QPtrList<Event> el = rawEvents(start,end,inclusive); 357 QPtrList<Event> el = rawEvents(start,end,inclusive);
359 mFilter->apply(&el); 358 mFilter->apply(&el);
360 return el; 359 return el;
361} 360}
362 361
363QPtrList<Event> Calendar::events() 362QPtrList<Event> Calendar::events()
364{ 363{
365 QPtrList<Event> el = rawEvents(); 364 QPtrList<Event> el = rawEvents();
366 mFilter->apply(&el); 365 mFilter->apply(&el);
367 return el; 366 return el;
368} 367}
369void Calendar::addIncidenceBranch(Incidence *i) 368void Calendar::addIncidenceBranch(Incidence *i)
370{ 369{
371 addIncidence( i ); 370 addIncidence( i );
372 Incidence * inc; 371 Incidence * inc;
373 QPtrList<Incidence> Relations = i->relations(); 372 QPtrList<Incidence> Relations = i->relations();
374 for (inc=Relations.first();inc;inc=Relations.next()) { 373 for (inc=Relations.first();inc;inc=Relations.next()) {
375 addIncidenceBranch( inc ); 374 addIncidenceBranch( inc );
376 } 375 }
377} 376}
378 377
379bool Calendar::addIncidence(Incidence *i) 378bool Calendar::addIncidence(Incidence *i)
380{ 379{
381 Incidence::AddVisitor<Calendar> v(this); 380 Incidence::AddVisitor<Calendar> v(this);
382 if ( i->calID() == 0 ) 381 if ( i->calID() == 0 )
383 i->setCalID_block( mDefaultCalendar ); 382 i->setCalID_block( mDefaultCalendar );
384 i->setCalEnabled( true ); 383 i->setCalEnabled( true );
385 return i->accept(v); 384 return i->accept(v);
386} 385}
387void Calendar::deleteIncidence(Incidence *in) 386void Calendar::deleteIncidence(Incidence *in)
388{ 387{
389 if ( in->typeID() == eventID ) 388 if ( in->typeID() == eventID )
390 deleteEvent( (Event*) in ); 389 deleteEvent( (Event*) in );
391 else if ( in->typeID() == todoID ) 390 else if ( in->typeID() == todoID )
392 deleteTodo( (Todo*) in); 391 deleteTodo( (Todo*) in);
393 else if ( in->typeID() == journalID ) 392 else if ( in->typeID() == journalID )
394 deleteJournal( (Journal*) in ); 393 deleteJournal( (Journal*) in );
395} 394}
396 395
397Incidence* Calendar::incidence( const QString& uid ) 396Incidence* Calendar::incidence( const QString& uid )
398{ 397{
399 Incidence* i; 398 Incidence* i;
400 399
401 if( (i = todo( uid )) != 0 ) 400 if( (i = todo( uid )) != 0 )
402 return i; 401 return i;
403 if( (i = event( uid )) != 0 ) 402 if( (i = event( uid )) != 0 )
404 return i; 403 return i;
405 if( (i = journal( uid )) != 0 ) 404 if( (i = journal( uid )) != 0 )
406 return i; 405 return i;
407 406
408 return 0; 407 return 0;
409} 408}
410 409
411QPtrList<Todo> Calendar::todos() 410QPtrList<Todo> Calendar::todos()
412{ 411{
413 QPtrList<Todo> tl = rawTodos(); 412 QPtrList<Todo> tl = rawTodos();
414 mFilter->apply( &tl ); 413 mFilter->apply( &tl );
415 return tl; 414 return tl;
416} 415}
417 416
418// When this is called, the todo have already been added to the calendar. 417// When this is called, the todo have already been added to the calendar.
419// This method is only about linking related todos 418// This method is only about linking related todos
420void Calendar::setupRelations( Incidence *incidence ) 419void Calendar::setupRelations( Incidence *incidence )
421{ 420{
422 QString uid = incidence->uid(); 421 QString uid = incidence->uid();
423 //qDebug("Calendar::setupRelations "); 422 //qDebug("Calendar::setupRelations %s", incidence->summary().latin1());
424 // First, go over the list of orphans and see if this is their parent 423 // First, go over the list of orphans and see if this is their parent
425 while( Incidence* i = mOrphans[ uid ] ) { 424 while( Incidence* i = mOrphans[ uid ] ) {
426 mOrphans.remove( uid ); 425 mOrphans.remove( uid );
427 i->setRelatedTo( incidence ); 426 i->setRelatedTo( incidence );
427 //qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1());
428 incidence->addRelation( i ); 428 incidence->addRelation( i );
429 mOrphanUids.remove( i->uid() ); 429 mOrphanUids.remove( i->uid() );
430 } 430 }
431 431
432 // Now see about this incidences parent 432 // Now see about this incidences parent
433 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 433 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
434 // This incidence has a uid it is related to, but is not registered to it yet 434 // This incidence has a uid it is related to, but is not registered to it yet
435 // Try to find it 435 // Try to find it
436 Incidence* parent = this->incidence( incidence->relatedToUid() ); 436 //qDebug("Test parent for %s", incidence->summary().latin1());
437 Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true );
437 if( parent ) { 438 if( parent ) {
438 // Found it 439 // Found it
440 // qDebug("parent found for for %s", incidence->summary().latin1());
439 incidence->setRelatedTo( parent ); 441 incidence->setRelatedTo( parent );
440 parent->addRelation( incidence ); 442 parent->addRelation( incidence );
441 } else { 443 } else {
444 // qDebug("NO parent found for for %s", incidence->summary().latin1());
442 // Not found, put this in the mOrphans list 445 // Not found, put this in the mOrphans list
443 mOrphans.insert( incidence->relatedToUid(), incidence ); 446 mOrphans.insert( incidence->relatedToUid(), incidence );
444 mOrphanUids.insert( incidence->uid(), incidence ); 447 mOrphanUids.insert( incidence->uid(), incidence );
445 } 448 }
446 } 449 }
447} 450}
448 451
449// If a task with subtasks is deleted, move it's subtasks to the orphans list 452// If a task with subtasks is deleted, move it's subtasks to the orphans list
450void Calendar::removeRelations( Incidence *incidence ) 453void Calendar::removeRelations( Incidence *incidence )
451{ 454{
452 // qDebug("Calendar::removeRelations "); 455 // qDebug("Calendar::removeRelations ");
453 QString uid = incidence->uid(); 456 QString uid = incidence->uid();
454 457
455 QPtrList<Incidence> relations = incidence->relations(); 458 QPtrList<Incidence> relations = incidence->relations();
456 for( Incidence* i = relations.first(); i; i = relations.next() ) 459 for( Incidence* i = relations.first(); i; i = relations.next() )
457 if( !mOrphanUids.find( i->uid() ) ) { 460 if( !mOrphanUids.find( i->uid() ) ) {
458 mOrphans.insert( uid, i ); 461 mOrphans.insert( uid, i );
459 mOrphanUids.insert( i->uid(), i ); 462 mOrphanUids.insert( i->uid(), i );
460 i->setRelatedTo( 0 ); 463 i->setRelatedTo( 0 );
461 i->setRelatedToUid( uid ); 464 i->setRelatedToUid( uid );
462 } 465 }
463 466
464 // If this incidence is related to something else, tell that about it 467 // If this incidence is related to something else, tell that about it
465 if( incidence->relatedTo() ) 468 if( incidence->relatedTo() )
466 incidence->relatedTo()->removeRelation( incidence ); 469 incidence->relatedTo()->removeRelation( incidence );
467 470
468 // Remove this one from the orphans list 471 // Remove this one from the orphans list
469 if( mOrphanUids.remove( uid ) ) { 472 if( mOrphanUids.remove( uid ) ) {
470 QString r2uid = incidence->relatedToUid(); 473 QString r2uid = incidence->relatedToUid();
471 QPtrList<Incidence> tempList; 474 QPtrList<Incidence> tempList;
472 while( Incidence* i = mOrphans[ r2uid ] ) { 475 while( Incidence* i = mOrphans[ r2uid ] ) {
473 mOrphans.remove( r2uid ); 476 mOrphans.remove( r2uid );
474 if ( i != incidence ) tempList.append( i ); 477 if ( i != incidence ) tempList.append( i );
475 } 478 }
476 Incidence* inc = tempList.first(); 479 Incidence* inc = tempList.first();
477 while ( inc ) { 480 while ( inc ) {
478 mOrphans.insert( r2uid, inc ); 481 mOrphans.insert( r2uid, inc );
479 inc = tempList.next(); 482 inc = tempList.next();
480 } 483 }
481 } 484 }
482 // LR: and another big bad bug found 485 // LR: and another big bad bug found
483#if 0 486#if 0
484 // This incidence is located in the orphans list - it should be removed 487 // This incidence is located in the orphans list - it should be removed
485 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 488 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
486 // Removing wasn't that easy 489 // Removing wasn't that easy
487 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 490 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
488 if( it.current()->uid() == uid ) { 491 if( it.current()->uid() == uid ) {
489 mOrphans.remove( it.currentKey() ); 492 mOrphans.remove( it.currentKey() );
490 break; 493 break;
491 } 494 }
492 } 495 }
493 } 496 }
494#endif 497#endif
495} 498}
496 499
497void Calendar::registerObserver( Observer *observer ) 500void Calendar::registerObserver( Observer *observer )
498{ 501{
499 mObserver = observer; 502 mObserver = observer;
500 mNewObserver = true; 503 mNewObserver = true;
501} 504}
502 505
503void Calendar::setModified( bool modified ) 506void Calendar::setModified( bool modified )
504{ 507{
505 if ( mObserver ) mObserver->calendarModified( modified, this ); 508 if ( mObserver ) mObserver->calendarModified( modified, this );
506 if ( modified != mModified || mNewObserver ) { 509 if ( modified != mModified || mNewObserver ) {
507 mNewObserver = false; 510 mNewObserver = false;
508 // if ( mObserver ) mObserver->calendarModified( modified, this ); 511 // if ( mObserver ) mObserver->calendarModified( modified, this );
509 mModified = modified; 512 mModified = modified;
510 } 513 }
511} 514}
512 515
513void Calendar::setLoadedProductId( const QString &id ) 516void Calendar::setLoadedProductId( const QString &id )
514{ 517{
515 mLoadedProductId = id; 518 mLoadedProductId = id;
516} 519}
517 520
518QString Calendar::loadedProductId() 521QString Calendar::loadedProductId()
519{ 522{
520 return mLoadedProductId; 523 return mLoadedProductId;
521} 524}
522 525
523//#include "calendar.moc" 526//#include "calendar.moc"
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index f301768..fbc40ad 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -1,384 +1,385 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#ifndef CALENDAR_H 22#ifndef CALENDAR_H
23#define CALENDAR_H 23#define CALENDAR_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qptrlist.h> 28#include <qptrlist.h>
29#include <qdict.h> 29#include <qdict.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "event.h" 32#include "event.h"
33#include "todo.h" 33#include "todo.h"
34#include "journal.h" 34#include "journal.h"
35#include "calfilter.h" 35#include "calfilter.h"
36 36
37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ 37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */
38 38
39class KConfig; 39class KConfig;
40 40
41namespace KCal { 41namespace KCal {
42 42
43 43
44/** 44/**
45 This is the main "calendar" object class for KOrganizer. It holds 45 This is the main "calendar" object class for KOrganizer. It holds
46 information like all appointments/events, user information, etc. etc. 46 information like all appointments/events, user information, etc. etc.
47 one calendar is associated with each CalendarView (@see calendarview.h). 47 one calendar is associated with each CalendarView (@see calendarview.h).
48 This is an abstract base class defining the interface to a calendar. It is 48 This is an abstract base class defining the interface to a calendar. It is
49 implemented by subclasses like @see CalendarLocal, which use different 49 implemented by subclasses like @see CalendarLocal, which use different
50 methods to store and access the data. 50 methods to store and access the data.
51 51
52 Ownership of events etc. is handled by the following policy: As soon as an 52 Ownership of events etc. is handled by the following policy: As soon as an
53 event (or any other subclass of IncidenceBase) object is added to the 53 event (or any other subclass of IncidenceBase) object is added to the
54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes 54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes
55 care of deleting it. All Events returned by the query functions are returned 55 care of deleting it. All Events returned by the query functions are returned
56 as pointers, that means all changes to the returned events are immediately 56 as pointers, that means all changes to the returned events are immediately
57 visible in the Calendar. You shouldn't delete any Event object you get from 57 visible in the Calendar. You shouldn't delete any Event object you get from
58 Calendar. 58 Calendar.
59*/ 59*/
60class Calendar : public QObject, public CustomProperties, 60class Calendar : public QObject, public CustomProperties,
61 public IncidenceBase::Observer 61 public IncidenceBase::Observer
62{ 62{
63 Q_OBJECT 63 Q_OBJECT
64public: 64public:
65 Calendar(); 65 Calendar();
66 Calendar(const QString &timeZoneId); 66 Calendar(const QString &timeZoneId);
67 virtual ~Calendar(); 67 virtual ~Calendar();
68 Incidence * undoIncidence() { return mUndoIncidence; }; 68 Incidence * undoIncidence() { return mUndoIncidence; };
69 bool undoDeleteIncidence(); 69 bool undoDeleteIncidence();
70 void deleteIncidence(Incidence *in); 70 void deleteIncidence(Incidence *in);
71 void resetTempSyncStat(); 71 void resetTempSyncStat();
72 void resetPilotStat(int id); 72 void resetPilotStat(int id);
73 /** 73 /**
74 Clears out the current calendar, freeing all used memory etc. 74 Clears out the current calendar, freeing all used memory etc.
75 */ 75 */
76 virtual void close() = 0; 76 virtual void close() = 0;
77 virtual void addCalendar( Calendar* ) = 0; 77 virtual void addCalendar( Calendar* ) = 0;
78 virtual bool addCalendarFile( QString name, int id ) = 0; 78 virtual bool addCalendarFile( QString name, int id ) = 0;
79 virtual bool mergeCalendarFile( QString name ) = 0; 79 virtual bool mergeCalendarFile( QString name ) = 0;
80 virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ) = 0; 80 virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ,int * isDup = 0 ) = 0;
81 virtual Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0) = 0;
81 virtual void setSyncEventsReadOnly() = 0; 82 virtual void setSyncEventsReadOnly() = 0;
82 virtual void setSyncEventsEnabled() = 0; 83 virtual void setSyncEventsEnabled() = 0;
83 virtual void stopAllTodos() = 0; 84 virtual void stopAllTodos() = 0;
84 virtual void clearUndo( Incidence * newUndo ); 85 virtual void clearUndo( Incidence * newUndo );
85 86
86 /** 87 /**
87 Sync changes in memory to persistant storage. 88 Sync changes in memory to persistant storage.
88 */ 89 */
89 virtual void save() = 0; 90 virtual void save() = 0;
90 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 91 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
91 virtual void removeSyncInfo( QString syncProfile) = 0; 92 virtual void removeSyncInfo( QString syncProfile) = 0;
92 virtual bool isSaving() { return false; } 93 virtual bool isSaving() { return false; }
93 94
94 /** 95 /**
95 Return the owner of the calendar's full name. 96 Return the owner of the calendar's full name.
96 */ 97 */
97 const QString &getOwner() const; 98 const QString &getOwner() const;
98 /** 99 /**
99 Set the owner of the calendar. Should be owner's full name. 100 Set the owner of the calendar. Should be owner's full name.
100 */ 101 */
101 void setOwner( const QString &os ); 102 void setOwner( const QString &os );
102 /** 103 /**
103 Return the email address of the calendar owner. 104 Return the email address of the calendar owner.
104 */ 105 */
105 const QString &getEmail(); 106 const QString &getEmail();
106 /** 107 /**
107 Set the email address of the calendar owner. 108 Set the email address of the calendar owner.
108 */ 109 */
109 void setEmail( const QString & ); 110 void setEmail( const QString & );
110 111
111 /** 112 /**
112 Set time zone from a timezone string (e.g. -2:00) 113 Set time zone from a timezone string (e.g. -2:00)
113 */ 114 */
114 void setTimeZone( const QString &tz ); 115 void setTimeZone( const QString &tz );
115 /** 116 /**
116 Set time zone from a minutes value (e.g. -60) 117 Set time zone from a minutes value (e.g. -60)
117 */ 118 */
118 void setTimeZone( int tz ); 119 void setTimeZone( int tz );
119 /** 120 /**
120 Return time zone as offest in minutes. 121 Return time zone as offest in minutes.
121 */ 122 */
122 int getTimeZone() const; 123 int getTimeZone() const;
123 /** 124 /**
124 Compute an ISO 8601 format string from the time zone. 125 Compute an ISO 8601 format string from the time zone.
125 */ 126 */
126 QString getTimeZoneStr() const; 127 QString getTimeZoneStr() const;
127 /** 128 /**
128 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal 129 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal
129 values). 130 values).
130 */ 131 */
131 void setTimeZoneId( const QString & ); 132 void setTimeZoneId( const QString & );
132 /** 133 /**
133 Return time zone id. 134 Return time zone id.
134 */ 135 */
135 QString timeZoneId() const; 136 QString timeZoneId() const;
136 /** 137 /**
137 Use local time, not UTC or a time zone. 138 Use local time, not UTC or a time zone.
138 */ 139 */
139 void setLocalTime(); 140 void setLocalTime();
140 /** 141 /**
141 Return whether local time is being used. 142 Return whether local time is being used.
142 */ 143 */
143 bool isLocalTime() const; 144 bool isLocalTime() const;
144 145
145 /** 146 /**
146 Add an incidence to calendar. 147 Add an incidence to calendar.
147 148
148 @return true on success, false on error. 149 @return true on success, false on error.
149 */ 150 */
150 virtual bool addIncidence( Incidence * ); 151 virtual bool addIncidence( Incidence * );
151 152
152 // Adds an incidence and all relatedto incidences to the cal 153 // Adds an incidence and all relatedto incidences to the cal
153 void addIncidenceBranch( Incidence * ); 154 void addIncidenceBranch( Incidence * );
154 /** 155 /**
155 Return filtered list of all incidences of this calendar. 156 Return filtered list of all incidences of this calendar.
156 */ 157 */
157 virtual QPtrList<Incidence> incidences(); 158 virtual QPtrList<Incidence> incidences();
158 159
159 /** 160 /**
160 Return unfiltered list of all incidences of this calendar. 161 Return unfiltered list of all incidences of this calendar.
161 */ 162 */
162 virtual QPtrList<Incidence> rawIncidences(); 163 virtual QPtrList<Incidence> rawIncidences();
163 164
164 /** 165 /**
165 Adds a Event to this calendar object. 166 Adds a Event to this calendar object.
166 @param anEvent a pointer to the event to add 167 @param anEvent a pointer to the event to add
167 168
168 @return true on success, false on error. 169 @return true on success, false on error.
169 */ 170 */
170 virtual bool addEventNoDup( Event *event ) = 0; 171 virtual bool addEventNoDup( Event *event ) = 0;
171 virtual bool addAnniversaryNoDup( Event *event ) = 0; 172 virtual bool addAnniversaryNoDup( Event *event ) = 0;
172 virtual bool addEvent( Event *anEvent ) = 0; 173 virtual bool addEvent( Event *anEvent ) = 0;
173 /** 174 /**
174 Delete event from calendar. 175 Delete event from calendar.
175 */ 176 */
176 virtual void deleteEvent( Event * ) = 0; 177 virtual void deleteEvent( Event * ) = 0;
177 /** 178 /**
178 Retrieves an event on the basis of the unique string ID. 179 Retrieves an event on the basis of the unique string ID.
179 */ 180 */
180 virtual Event *event( const QString &UniqueStr ) = 0; 181 virtual Event *event( const QString &UniqueStr ) = 0;
181 virtual Event *event( QString, QString ) = 0; 182 virtual Event *event( QString, QString ) = 0;
182 /** 183 /**
183 Builds and then returns a list of all events that match for the 184 Builds and then returns a list of all events that match for the
184 date specified. useful for dayView, etc. etc. 185 date specified. useful for dayView, etc. etc.
185 The calendar filter is applied. 186 The calendar filter is applied.
186 */ 187 */
187 QPtrList<Event> events( const QDate &date, bool sorted = false); 188 QPtrList<Event> events( const QDate &date, bool sorted = false);
188 /** 189 /**
189 Get events, which occur on the given date. 190 Get events, which occur on the given date.
190 The calendar filter is applied. 191 The calendar filter is applied.
191 */ 192 */
192 QPtrList<Event> events( const QDateTime &qdt ); 193 QPtrList<Event> events( const QDateTime &qdt );
193 /** 194 /**
194 Get events in a range of dates. If inclusive is set to true, only events 195 Get events in a range of dates. If inclusive is set to true, only events
195 are returned, which are completely included in the range. 196 are returned, which are completely included in the range.
196 The calendar filter is applied. 197 The calendar filter is applied.
197 */ 198 */
198 QPtrList<Event> events( const QDate &start, const QDate &end, 199 QPtrList<Event> events( const QDate &start, const QDate &end,
199 bool inclusive = false); 200 bool inclusive = false);
200 /** 201 /**
201 Return filtered list of all events in calendar. 202 Return filtered list of all events in calendar.
202 */ 203 */
203 virtual QPtrList<Event> events(); 204 virtual QPtrList<Event> events();
204 /** 205 /**
205 Return unfiltered list of all events in calendar. 206 Return unfiltered list of all events in calendar.
206 */ 207 */
207 virtual QPtrList<Event> rawEvents() = 0; 208 virtual QPtrList<Event> rawEvents() = 0;
208 209
209 /** 210 /**
210 Add a todo to the todolist. 211 Add a todo to the todolist.
211 212
212 @return true on success, false on error. 213 @return true on success, false on error.
213 */ 214 */
214 virtual bool addTodo( Todo *todo ) = 0; 215 virtual bool addTodo( Todo *todo ) = 0;
215 virtual bool addTodoNoDup( Todo *todo ) = 0; 216 virtual bool addTodoNoDup( Todo *todo ) = 0;
216 /** 217 /**
217 Remove a todo from the todolist. 218 Remove a todo from the todolist.
218 */ 219 */
219 virtual void deleteTodo( Todo * ) = 0; 220 virtual void deleteTodo( Todo * ) = 0;
220 virtual void deleteJournal( Journal * ) = 0; 221 virtual void deleteJournal( Journal * ) = 0;
221 /** 222 /**
222 Return filterd list of todos. 223 Return filterd list of todos.
223 */ 224 */
224 virtual QPtrList<Todo> todos(); 225 virtual QPtrList<Todo> todos();
225 /** 226 /**
226 Searches todolist for an event with this unique string identifier, 227 Searches todolist for an event with this unique string identifier,
227 returns a pointer or null. 228 returns a pointer or null.
228 */ 229 */
229 virtual Todo *todo( const QString &uid ) = 0; 230 virtual Todo *todo( const QString &uid ) = 0;
230 virtual Todo *todo( QString, QString ) = 0; 231 virtual Todo *todo( QString, QString ) = 0;
231 /** 232 /**
232 Returns list of todos due on the specified date. 233 Returns list of todos due on the specified date.
233 */ 234 */
234 virtual QPtrList<Todo> todos( const QDate &date ) = 0; 235 virtual QPtrList<Todo> todos( const QDate &date ) = 0;
235 /** 236 /**
236 Return unfiltered list of todos. 237 Return unfiltered list of todos.
237 */ 238 */
238 virtual QPtrList<Todo> rawTodos() = 0; 239 virtual QPtrList<Todo> rawTodos() = 0;
239 240
240 /** 241 /**
241 Add a Journal entry to calendar. 242 Add a Journal entry to calendar.
242 243
243 @return true on success, false on error. 244 @return true on success, false on error.
244 */ 245 */
245 virtual bool addJournal( Journal * ) = 0; 246 virtual bool addJournal( Journal * ) = 0;
246 /** 247 /**
247 Return Journal for given date. 248 Return Journal for given date.
248 */ 249 */
249 virtual Journal *journal( const QDate & ) = 0; 250 virtual Journal *journal( const QDate & ) = 0;
250 virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; 251 virtual QPtrList<Journal> journals4Date( const QDate & ) = 0;
251 /** 252 /**
252 Return Journal with given UID. 253 Return Journal with given UID.
253 */ 254 */
254 virtual Journal *journal( const QString &UID ) = 0; 255 virtual Journal *journal( const QString &UID ) = 0;
255 /** 256 /**
256 Return list of all Journal entries. 257 Return list of all Journal entries.
257 */ 258 */
258 virtual QPtrList<Journal> journals() = 0; 259 virtual QPtrList<Journal> journals() = 0;
259 260
260 /** 261 /**
261 Searches all incidence types for an incidence with this unique 262 Searches all incidence types for an incidence with this unique
262 string identifier, returns a pointer or null. 263 string identifier, returns a pointer or null.
263 */ 264 */
264 Incidence* incidence( const QString&UID ); 265 Incidence* incidence( const QString&UID );
265 266
266 /** 267 /**
267 Setup relations for an incidence. 268 Setup relations for an incidence.
268 */ 269 */
269 virtual void setupRelations( Incidence * ); 270 virtual void setupRelations( Incidence * );
270 /** 271 /**
271 Remove all relations to an incidence 272 Remove all relations to an incidence
272 */ 273 */
273 virtual void removeRelations( Incidence * ); 274 virtual void removeRelations( Incidence * );
274 275
275 /** 276 /**
276 Set calendar filter, which filters events for the events() functions. 277 Set calendar filter, which filters events for the events() functions.
277 The Filter object is owned by the caller. 278 The Filter object is owned by the caller.
278 */ 279 */
279 void setFilter( CalFilter * ); 280 void setFilter( CalFilter * );
280 /** 281 /**
281 Return calendar filter. 282 Return calendar filter.
282 */ 283 */
283 CalFilter *filter(); 284 CalFilter *filter();
284 virtual QDateTime nextAlarm( int daysTo ) = 0; 285 virtual QDateTime nextAlarm( int daysTo ) = 0;
285 virtual QString nextSummary( ) const = 0; 286 virtual QString nextSummary( ) const = 0;
286 virtual void reInitAlarmSettings() = 0; 287 virtual void reInitAlarmSettings() = 0;
287 virtual QDateTime nextAlarmEventDateTime() const = 0; 288 virtual QDateTime nextAlarmEventDateTime() const = 0;
288 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; 289 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0;
289 /** 290 /**
290 Return all alarms, which ocur in the given time interval. 291 Return all alarms, which ocur in the given time interval.
291 */ 292 */
292 virtual Alarm::List alarms( const QDateTime &from, 293 virtual Alarm::List alarms( const QDateTime &from,
293 const QDateTime &to ) = 0; 294 const QDateTime &to ) = 0;
294 295
295 class Observer { 296 class Observer {
296 public: 297 public:
297 virtual void calendarModified( bool, Calendar * ) = 0; 298 virtual void calendarModified( bool, Calendar * ) = 0;
298 }; 299 };
299 300
300 void registerObserver( Observer * ); 301 void registerObserver( Observer * );
301 302
302 void setModified( bool ); 303 void setModified( bool );
303 304
304 /** 305 /**
305 Set product id returned by loadedProductId(). This function is only 306 Set product id returned by loadedProductId(). This function is only
306 useful for the calendar loading code. 307 useful for the calendar loading code.
307 */ 308 */
308 void setLoadedProductId( const QString & ); 309 void setLoadedProductId( const QString & );
309 /** 310 /**
310 Return product id taken from file that has been loaded. Returns 311 Return product id taken from file that has been loaded. Returns
311 QString::null, if no calendar has been loaded. 312 QString::null, if no calendar has been loaded.
312 */ 313 */
313 QString loadedProductId(); 314 QString loadedProductId();
314 int defaultCalendar(); 315 int defaultCalendar();
315 void setDontDeleteIncidencesOnClose (); 316 void setDontDeleteIncidencesOnClose ();
316 public slots: 317 public slots:
317 void setDefaultCalendar( int ); 318 void setDefaultCalendar( int );
318 virtual void setCalendarEnabled( int id, bool enable ) = 0; 319 virtual void setCalendarEnabled( int id, bool enable ) = 0;
319 virtual void setAllCalendarEnabled( bool enable ) = 0; 320 virtual void setAllCalendarEnabled( bool enable ) = 0;
320 virtual void setAlarmEnabled( int id, bool enable ) = 0; 321 virtual void setAlarmEnabled( int id, bool enable ) = 0;
321 virtual void setReadOnly( int id, bool enable ) = 0; 322 virtual void setReadOnly( int id, bool enable ) = 0;
322 virtual void setDefaultCalendarEnabledOnly() = 0; 323 virtual void setDefaultCalendarEnabledOnly() = 0;
323 virtual void setCalendarRemove( int id ) = 0; 324 virtual void setCalendarRemove( int id ) = 0;
324 virtual void getIncidenceCount( int calId, int& events, int & todos, int & journals) = 0; 325 virtual void getIncidenceCount( int calId, int& events, int & todos, int & journals) = 0;
325 326
326 signals: 327 signals:
327 void calendarChanged(); 328 void calendarChanged();
328 void calendarSaved(); 329 void calendarSaved();
329 void calendarLoaded(); 330 void calendarLoaded();
330 void addAlarm(const QDateTime &qdt, const QString &noti ); 331 void addAlarm(const QDateTime &qdt, const QString &noti );
331 void removeAlarm(const QDateTime &qdt, const QString &noti ); 332 void removeAlarm(const QDateTime &qdt, const QString &noti );
332 333
333 protected: 334 protected:
334 /** 335 /**
335 Get unfiltered events, which occur on the given date. 336 Get unfiltered events, which occur on the given date.
336 */ 337 */
337 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; 338 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
338 /** 339 /**
339 Get unfiltered events, which occur on the given date. 340 Get unfiltered events, which occur on the given date.
340 */ 341 */
341 virtual QPtrList<Event> rawEventsForDate( const QDate &date, 342 virtual QPtrList<Event> rawEventsForDate( const QDate &date,
342 bool sorted = false ) = 0; 343 bool sorted = false ) = 0;
343 /** 344 /**
344 Get events in a range of dates. If inclusive is set to true, only events 345 Get events in a range of dates. If inclusive is set to true, only events
345 are returned, which are completely included in the range. 346 are returned, which are completely included in the range.
346 */ 347 */
347 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 348 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
348 bool inclusive = false ) = 0; 349 bool inclusive = false ) = 0;
349 350
350 Incidence *mNextAlarmIncidence; 351 Incidence *mNextAlarmIncidence;
351 Incidence *mUndoIncidence; 352 Incidence *mUndoIncidence;
352 int mDefaultCalendar; 353 int mDefaultCalendar;
353 bool mDeleteIncidencesOnClose; 354 bool mDeleteIncidencesOnClose;
354 355
355private: 356private:
356 void init(); 357 void init();
357 358
358 QString mOwner; // who the calendar belongs to 359 QString mOwner; // who the calendar belongs to
359 QString mOwnerEmail; // email address of the owner 360 QString mOwnerEmail; // email address of the owner
360 int mTimeZone; // timezone OFFSET from GMT (MINUTES) 361 int mTimeZone; // timezone OFFSET from GMT (MINUTES)
361 bool mLocalTime; // use local time, not UTC or a time zone 362 bool mLocalTime; // use local time, not UTC or a time zone
362 363
363 364
364 CalFilter *mFilter; 365 CalFilter *mFilter;
365 CalFilter *mDefaultFilter; 366 CalFilter *mDefaultFilter;
366 367
367 368
368 QString mTimeZoneId; 369 QString mTimeZoneId;
369 370
370 Observer *mObserver; 371 Observer *mObserver;
371 bool mNewObserver; 372 bool mNewObserver;
372 373
373 bool mModified; 374 bool mModified;
374 375
375 QString mLoadedProductId; 376 QString mLoadedProductId;
376 377
377 // This list is used to put together related todos 378 // This list is used to put together related todos
378 QDict<Incidence> mOrphans; 379 QDict<Incidence> mOrphans;
379 QDict<Incidence> mOrphanUids; 380 QDict<Incidence> mOrphanUids;
380}; 381};
381 382
382} 383}
383 384
384#endif 385#endif
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index ad8ace3..980663f 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,1089 +1,1140 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 registerObserver( 0 ); 68 registerObserver( 0 );
69 if ( mDeleteIncidencesOnClose ) 69 if ( mDeleteIncidencesOnClose )
70 close(); 70 close();
71} 71}
72bool CalendarLocal::mergeCalendarFile( QString name ) 72bool CalendarLocal::mergeCalendarFile( QString name )
73{ 73{
74 CalendarLocal calendar( timeZoneId() ); 74 CalendarLocal calendar( timeZoneId() );
75 calendar.setDefaultCalendar( 1 ); 75 calendar.setDefaultCalendar( 1 );
76 if ( calendar.load( name ) ) { 76 if ( calendar.load( name ) ) {
77 mergeCalendar( &calendar ); 77 mergeCalendar( &calendar );
78 return true; 78 return true;
79 } 79 }
80 return false; 80 return false;
81} 81}
82 82
83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly ) 83Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup )
84{ 84{
85
86 int calID = 0;
87 if ( isDup && *isDup > 0 )
88 calID = *isDup;
85 Todo *todo;; 89 Todo *todo;;
86 Incidence *retVal = 0; 90 Todo *retVal = 0;
87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 91 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
88 if ( todo->uid() == uid ) { 92 if ( todo->uid() == uid ) {
89 if ( enabledOnly ) 93 if( calID ) {
90 if ( !todo->calEnabled() ) 94 if ( todo->calID() != calID )
91 continue; 95 continue;
96 }
97 else {
98 if ( enabledOnly ) {
99 if ( !todo->calEnabled() ) {
100 if ( isDup )
101 *isDup = todo->calID();
102 continue;
103 }
104 }
105 }
92 if ( doNotCheckDuplicates ) return todo; 106 if ( doNotCheckDuplicates ) return todo;
93 if ( retVal ) { 107 if ( retVal ) {
94 if ( retVal->calID() > todo->calID() ) { 108 if ( retVal->calID() > todo->calID() ) {
109 if ( isDup )
110 *isDup = retVal->calID();
95 retVal = todo; 111 retVal = todo;
96 } 112 }
97 } else { 113 } else {
98 retVal = todo; 114 retVal = todo;
99 } 115 }
100 } 116 }
101 } 117 }
118 return retVal;
119}
120//if ( isDup) and * isDup == 0: store duplicate found cal id in isDup
121//if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly
122
123Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup )
124{
125 int calID = 0;
126 if ( isDup && *isDup > 0 )
127 calID = *isDup;
128 Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup );
102 if ( retVal ) return retVal; 129 if ( retVal ) return retVal;
103 Event *event; 130 Event *event;
104 for ( event = mEventList.first(); event; event = mEventList.next() ) { 131 for ( event = mEventList.first(); event; event = mEventList.next() ) {
105 if ( event->uid() == uid ) { 132 if ( event->uid() == uid ) {
106 if ( enabledOnly ) 133 if( calID ) {
107 if ( !event->calEnabled() ) 134 if ( event->calID() != calID )
108 continue; 135 continue;
136 }
137 else {
138 if ( enabledOnly ) {
139 if ( !event->calEnabled() ) {
140 if ( isDup )
141 *isDup =event->calID() ;
142 continue;
143 }
144 }
145 }
109 if ( doNotCheckDuplicates ) return event; 146 if ( doNotCheckDuplicates ) return event;
110 if ( retVal ) { 147 if ( retVal ) {
111 if ( retVal->calID() > event->calID() ) { 148 if ( retVal->calID() > event->calID() ) {
149 if ( isDup )
150 *isDup = retVal->calID();
112 retVal = event; 151 retVal = event;
113 } 152 }
114 } else { 153 } else {
115 retVal = event; 154 retVal = event;
116 } 155 }
117 } 156 }
118 } 157 }
119 if ( retVal ) return retVal; 158 if ( retVal ) return retVal;
120 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 159 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
121 if ( it->uid() == uid ) { 160 if ( it->uid() == uid ) {
122 if ( enabledOnly ) 161 if( calID ) {
123 if ( !it->calEnabled() ) 162 if ( event->calID() != calID )
124 continue; 163 continue;
164 }
165 else {
166 if ( enabledOnly ) {
167 if ( !it->calEnabled() ) {
168 if ( isDup )
169 *isDup = it->calID();
170 continue;
171 }
172 }
173 }
125 if ( doNotCheckDuplicates ) return it; 174 if ( doNotCheckDuplicates ) return it;
126 if ( retVal ) { 175 if ( retVal ) {
127 if ( retVal->calID() > it->calID() ) { 176 if ( retVal->calID() > it->calID() ) {
177 if ( isDup )
178 *isDup = retVal->calID();
128 retVal = it; 179 retVal = it;
129 } 180 }
130 } else { 181 } else {
131 retVal = it; 182 retVal = it;
132 } 183 }
133 } 184 }
134 return retVal; 185 return retVal;
135} 186}
136 187
137bool CalendarLocal::mergeCalendar( Calendar* remote ) 188bool CalendarLocal::mergeCalendar( Calendar* remote )
138{ 189{
139 // 1 look for raw inc in local 190 // 1 look for raw inc in local
140 // if inc not in remote, delete in local 191 // if inc not in remote, delete in local
141 // 2 look for raw inc in remote 192 // 2 look for raw inc in remote
142 // if inc in local, replace it 193 // if inc in local, replace it
143 // if not in local, add it to default calendar 194 // if not in local, add it to default calendar
144 QPtrList<Incidence> localInc = rawIncidences(); 195 QPtrList<Incidence> localInc = rawIncidences();
145 Incidence* inL = localInc.first(); 196 Incidence* inL = localInc.first();
146 while ( inL ) { 197 while ( inL ) {
147 if ( ! inL->isReadOnly () ) 198 if ( ! inL->isReadOnly () )
148 if ( !remote->incidenceForUid( inL->uid(), true )) 199 if ( !remote->incidenceForUid( inL->uid(), true ))
149 deleteIncidence( inL ); 200 deleteIncidence( inL );
150 inL = localInc.next(); 201 inL = localInc.next();
151 } 202 }
152 QPtrList<Incidence> er = remote->rawIncidences(); 203 QPtrList<Incidence> er = remote->rawIncidences();
153 Incidence* inR = er.first(); 204 Incidence* inR = er.first();
154 while ( inR ) { 205 while ( inR ) {
155 inL = incidenceForUid( inR->uid(),false ); 206 inL = incidenceForUid( inR->uid(),false );
156 if ( inL ) { 207 if ( inL ) {
157 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { 208 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
158 int calID = inL->calID(); 209 int calID = inL->calID();
159 deleteIncidence( inL ); 210 deleteIncidence( inL );
160 inL = inR->clone(); 211 inL = inR->clone();
161 inL->setCalID_block( calID ); 212 inL->setCalID_block( calID );
162 addIncidence( inL ); 213 addIncidence( inL );
163 } 214 }
164 } else { 215 } else {
165 inL = inR->clone(); 216 inL = inR->clone();
166 inL->setCalID_block( 0 );// add to default cal 217 inL->setCalID_block( 0 );// add to default cal
167 addIncidence( inL ); 218 addIncidence( inL );
168 } 219 }
169 inR = er.next(); 220 inR = er.next();
170 } 221 }
171 return true; 222 return true;
172} 223}
173 224
174 225
175bool CalendarLocal::addCalendarFile( QString name, int id ) 226bool CalendarLocal::addCalendarFile( QString name, int id )
176{ 227{
177 CalendarLocal calendar( timeZoneId() ); 228 CalendarLocal calendar( timeZoneId() );
178 calendar.setDefaultCalendar( id ); 229 calendar.setDefaultCalendar( id );
179 if ( calendar.load( name ) ) { 230 if ( calendar.load( name ) ) {
180 addCalendar( &calendar ); 231 addCalendar( &calendar );
181 return true; 232 return true;
182 } 233 }
183 return false; 234 return false;
184} 235}
185void CalendarLocal::setSyncEventsEnabled() 236void CalendarLocal::setSyncEventsEnabled()
186{ 237{
187 Event * ev; 238 Event * ev;
188 ev = mEventList.first(); 239 ev = mEventList.first();
189 while ( ev ) { 240 while ( ev ) {
190 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 241 if ( ev->uid().left(15) == QString("last-syncEvent-") )
191 ev->setCalEnabled( true ); 242 ev->setCalEnabled( true );
192 ev = mEventList.next(); 243 ev = mEventList.next();
193 } 244 }
194} 245}
195void CalendarLocal::setSyncEventsReadOnly() 246void CalendarLocal::setSyncEventsReadOnly()
196{ 247{
197 Event * ev; 248 Event * ev;
198 ev = mEventList.first(); 249 ev = mEventList.first();
199 while ( ev ) { 250 while ( ev ) {
200 if ( ev->uid().left(15) == QString("last-syncEvent-") ) { 251 if ( ev->uid().left(15) == QString("last-syncEvent-") ) {
201 ev->setReadOnly( true ); 252 ev->setReadOnly( true );
202 } 253 }
203 ev = mEventList.next(); 254 ev = mEventList.next();
204 } 255 }
205} 256}
206 257
207void CalendarLocal::addCalendar( Calendar* cal ) 258void CalendarLocal::addCalendar( Calendar* cal )
208{ 259{
209 cal->setDontDeleteIncidencesOnClose(); 260 cal->setDontDeleteIncidencesOnClose();
210 setSyncEventsEnabled(); 261 setSyncEventsEnabled();
211 { 262 {
212 QPtrList<Event> EventList = cal->rawEvents(); 263 QPtrList<Event> EventList = cal->rawEvents();
213 QPtrList<Event> el; 264 QPtrList<Event> el;
214 Event * ev = EventList.first(); 265 Event * ev = EventList.first();
215 while ( ev ) { 266 while ( ev ) {
216 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { 267 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) {
217 Event * se = event( ev->uid() ); 268 Event * se = event( ev->uid() );
218 if ( se ) 269 if ( se )
219 el.append( se ); 270 el.append( se );
220 ev->setCalID_block( 1 ); 271 ev->setCalID_block( 1 );
221 } 272 }
222 ev->unRegisterObserver( cal ); 273 ev->unRegisterObserver( cal );
223 ev->registerObserver( this ); 274 ev->registerObserver( this );
224 mEventList.append( ev ); 275 mEventList.append( ev );
225 ev = EventList.next(); 276 ev = EventList.next();
226 } 277 }
227 for ( ev = el.first(); ev; ev = el.next() ) { 278 for ( ev = el.first(); ev; ev = el.next() ) {
228 deleteIncidence ( ev ); 279 deleteIncidence ( ev );
229 } 280 }
230 } 281 }
231 { 282 {
232 283
233 QPtrList<Todo> TodoList = cal->rawTodos(); 284 QPtrList<Todo> TodoList = cal->rawTodos();
234 Todo * ev = TodoList.first(); 285 Todo * ev = TodoList.first();
235 while ( ev ) { 286 while ( ev ) {
236 QString rel = ev->relatedToUid(); 287 ev->resetRelatedTo();
237 if ( !rel.isEmpty() ){
238 ev->setRelatedTo ( 0 );
239 ev->setRelatedToUid( rel );
240 }
241 ev = TodoList.next(); 288 ev = TodoList.next();
242 } 289 }
243 //TodoList = cal->rawTodos(); 290 //TodoList = cal->rawTodos();
244 ev = TodoList.first(); 291 ev = TodoList.first();
245 while ( ev ) { 292 while ( ev ) {
246 ev->unRegisterObserver( cal ); 293 ev->unRegisterObserver( cal );
247 ev->registerObserver( this ); 294 ev->registerObserver( this );
248 mTodoList.append( ev ); 295 mTodoList.append( ev );
249 setupRelations( ev ); 296 setupRelations( ev );
250 ev = TodoList.next(); 297 ev = TodoList.next();
251 } 298 }
252 } 299 }
253 { 300 {
254 QPtrList<Journal> JournalList = cal->journals(); 301 QPtrList<Journal> JournalList = cal->journals();
255 Journal * ev = JournalList.first(); 302 Journal * ev = JournalList.first();
256 while ( ev ) { 303 while ( ev ) {
257 ev->unRegisterObserver( cal ); 304 ev->unRegisterObserver( cal );
258 ev->registerObserver( this ); 305 ev->registerObserver( this );
259 mJournalList.append( ev ); 306 mJournalList.append( ev );
260 ev = JournalList.next(); 307 ev = JournalList.next();
261 } 308 }
262 } 309 }
263 setModified( true ); 310 setModified( true );
264} 311}
265bool CalendarLocal::load( const QString &fileName ) 312bool CalendarLocal::load( const QString &fileName )
266{ 313{
267 FileStorage storage( this, fileName ); 314 FileStorage storage( this, fileName );
268 return storage.load(); 315 return storage.load();
269} 316}
270 317
271bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 318bool CalendarLocal::save( const QString &fileName, CalFormat *format )
272{ 319{
273 FileStorage storage( this, fileName, format ); 320 FileStorage storage( this, fileName, format );
274 return storage.save(); 321 return storage.save();
275} 322}
276 323
277void CalendarLocal::stopAllTodos() 324void CalendarLocal::stopAllTodos()
278{ 325{
279 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 326 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
280 it->setRunning( false ); 327 it->setRunning( false );
281 328
282} 329}
283void CalendarLocal::close() 330void CalendarLocal::close()
284{ 331{
285 332
286 Todo * i; 333 Todo * i;
287 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 334 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
288 335
289 mEventList.setAutoDelete( true ); 336 mEventList.setAutoDelete( true );
290 mTodoList.setAutoDelete( true ); 337 mTodoList.setAutoDelete( true );
291 mJournalList.setAutoDelete( true ); 338 mJournalList.setAutoDelete( true );
292 339
293 mEventList.clear(); 340 mEventList.clear();
294 mTodoList.clear(); 341 mTodoList.clear();
295 mJournalList.clear(); 342 mJournalList.clear();
296 343
297 mEventList.setAutoDelete( false ); 344 mEventList.setAutoDelete( false );
298 mTodoList.setAutoDelete( false ); 345 mTodoList.setAutoDelete( false );
299 mJournalList.setAutoDelete( false ); 346 mJournalList.setAutoDelete( false );
300 347
301 setModified( false ); 348 setModified( false );
302} 349}
303 350
304bool CalendarLocal::addAnniversaryNoDup( Event *event ) 351bool CalendarLocal::addAnniversaryNoDup( Event *event )
305{ 352{
306 QString cat; 353 QString cat;
307 bool isBirthday = true; 354 bool isBirthday = true;
308 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 355 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
309 isBirthday = false; 356 isBirthday = false;
310 cat = i18n( "Anniversary" ); 357 cat = i18n( "Anniversary" );
311 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 358 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
312 isBirthday = true; 359 isBirthday = true;
313 cat = i18n( "Birthday" ); 360 cat = i18n( "Birthday" );
314 } else { 361 } else {
315 qDebug("addAnniversaryNoDup called without fitting category! "); 362 qDebug("addAnniversaryNoDup called without fitting category! ");
316 return false; 363 return false;
317 } 364 }
318 Event * eve; 365 Event * eve;
319 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 366 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
320 if ( !(eve->categories().contains( cat ) )) 367 if ( !(eve->categories().contains( cat ) ))
321 continue; 368 continue;
322 // now we have an event with fitting category 369 // now we have an event with fitting category
323 if ( eve->dtStart().date() != event->dtStart().date() ) 370 if ( eve->dtStart().date() != event->dtStart().date() )
324 continue; 371 continue;
325 // now we have an event with fitting category+date 372 // now we have an event with fitting category+date
326 if ( eve->summary() != event->summary() ) 373 if ( eve->summary() != event->summary() )
327 continue; 374 continue;
328 // now we have an event with fitting category+date+summary 375 // now we have an event with fitting category+date+summary
329 return false; 376 return false;
330 } 377 }
331 return addEvent( event ); 378 return addEvent( event );
332 379
333} 380}
334bool CalendarLocal::addEventNoDup( Event *event ) 381bool CalendarLocal::addEventNoDup( Event *event )
335{ 382{
336 Event * eve; 383 Event * eve;
337 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 384 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
338 if ( *eve == *event ) { 385 if ( *eve == *event ) {
339 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 386 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
340 return false; 387 return false;
341 } 388 }
342 } 389 }
343 return addEvent( event ); 390 return addEvent( event );
344} 391}
345 392
346bool CalendarLocal::addEvent( Event *event ) 393bool CalendarLocal::addEvent( Event *event )
347{ 394{
348 insertEvent( event ); 395 insertEvent( event );
349 396
350 event->registerObserver( this ); 397 event->registerObserver( this );
351 398
352 setModified( true ); 399 setModified( true );
353 if ( event->calID() == 0 ) 400 if ( event->calID() == 0 )
354 event->setCalID_block( mDefaultCalendar ); 401 event->setCalID_block( mDefaultCalendar );
355 event->setCalEnabled( true ); 402 event->setCalEnabled( true );
356 403
357 return true; 404 return true;
358} 405}
359 406
360void CalendarLocal::deleteEvent( Event *event ) 407void CalendarLocal::deleteEvent( Event *event )
361{ 408{
362 clearUndo(event); 409 clearUndo(event);
363 if ( mEventList.removeRef( event ) ) { 410 if ( mEventList.removeRef( event ) ) {
364 setModified( true ); 411 setModified( true );
365 } 412 }
366} 413}
367 414
368 415
369Event *CalendarLocal::event( const QString &uid ) 416Event *CalendarLocal::event( const QString &uid )
370{ 417{
371 Event *event; 418 Event *event;
372 Event *retVal = 0; 419 Event *retVal = 0;
373 for ( event = mEventList.first(); event; event = mEventList.next() ) { 420 for ( event = mEventList.first(); event; event = mEventList.next() ) {
374 if ( event->calEnabled() && event->uid() == uid ) { 421 if ( event->calEnabled() && event->uid() == uid ) {
375 if ( retVal ) { 422 if ( retVal ) {
376 if ( retVal->calID() > event->calID() ) { 423 if ( retVal->calID() > event->calID() ) {
377 retVal = event; 424 retVal = event;
378 } 425 }
379 } else { 426 } else {
380 retVal = event; 427 retVal = event;
381 } 428 }
382 } 429 }
383 } 430 }
384 return retVal; 431 return retVal;
385} 432}
386bool CalendarLocal::addTodoNoDup( Todo *todo ) 433bool CalendarLocal::addTodoNoDup( Todo *todo )
387{ 434{
388 Todo * eve; 435 Todo * eve;
389 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 436 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
390 if ( *eve == *todo ) { 437 if ( *eve == *todo ) {
391 //qDebug("duplicate todo found! not inserted! "); 438 //qDebug("duplicate todo found! not inserted! ");
392 return false; 439 return false;
393 } 440 }
394 } 441 }
395 return addTodo( todo ); 442 return addTodo( todo );
396} 443}
397bool CalendarLocal::addTodo( Todo *todo ) 444bool CalendarLocal::addTodo( Todo *todo )
398{ 445{
399 mTodoList.append( todo ); 446 mTodoList.append( todo );
400 447
401 todo->registerObserver( this ); 448 todo->registerObserver( this );
402 449
403 // Set up subtask relations 450 // Set up subtask relations
404 setupRelations( todo ); 451 setupRelations( todo );
405 452
406 setModified( true ); 453 setModified( true );
407 if ( todo->calID() == 0 ) 454 if ( todo->calID() == 0 )
408 todo->setCalID_block( mDefaultCalendar ); 455 todo->setCalID_block( mDefaultCalendar );
409 todo->setCalEnabled( true ); 456 todo->setCalEnabled( true );
410 return true; 457 return true;
411} 458}
412 459
413void CalendarLocal::deleteTodo( Todo *todo ) 460void CalendarLocal::deleteTodo( Todo *todo )
414{ 461{
462 QString uid = todo->uid();
415 // Handle orphaned children 463 // Handle orphaned children
416 removeRelations( todo ); 464 removeRelations( todo );
417 clearUndo(todo); 465 clearUndo(todo);
418 466
419 if ( mTodoList.removeRef( todo ) ) { 467 if ( mTodoList.removeRef( todo ) ) {
420 setModified( true ); 468 setModified( true );
421 } 469 }
470 Todo* dup = todoForUid( uid );
471 if ( dup )
472 setupRelations( dup );
422} 473}
423 474
424QPtrList<Todo> CalendarLocal::rawTodos() 475QPtrList<Todo> CalendarLocal::rawTodos()
425{ 476{
426 QPtrList<Todo> el; 477 QPtrList<Todo> el;
427 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 478 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
428 if ( it->calEnabled() ) el.append( it ); 479 if ( it->calEnabled() ) el.append( it );
429 return el; 480 return el;
430} 481}
431Todo *CalendarLocal::todo( QString syncProf, QString id ) 482Todo *CalendarLocal::todo( QString syncProf, QString id )
432{ 483{
433 Todo *todo; 484 Todo *todo;
434 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 485 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
435 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 486 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
436 } 487 }
437 488
438 return 0; 489 return 0;
439} 490}
440void CalendarLocal::removeSyncInfo( QString syncProfile) 491void CalendarLocal::removeSyncInfo( QString syncProfile)
441{ 492{
442 QPtrList<Incidence> all = rawIncidences() ; 493 QPtrList<Incidence> all = rawIncidences() ;
443 Incidence *inc; 494 Incidence *inc;
444 for ( inc = all.first(); inc; inc = all.next() ) { 495 for ( inc = all.first(); inc; inc = all.next() ) {
445 inc->removeID( syncProfile ); 496 inc->removeID( syncProfile );
446 } 497 }
447 if ( syncProfile.isEmpty() ) { 498 if ( syncProfile.isEmpty() ) {
448 QPtrList<Event> el; 499 QPtrList<Event> el;
449 Event *todo; 500 Event *todo;
450 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 501 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
451 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 502 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
452 el.append( todo ); 503 el.append( todo );
453 } 504 }
454 for ( todo = el.first(); todo; todo = el.next() ) { 505 for ( todo = el.first(); todo; todo = el.next() ) {
455 deleteIncidence ( todo ); 506 deleteIncidence ( todo );
456 } 507 }
457 } else { 508 } else {
458 Event *lse = event( "last-syncEvent-"+ syncProfile); 509 Event *lse = event( "last-syncEvent-"+ syncProfile);
459 if ( lse ) 510 if ( lse )
460 deleteIncidence ( lse ); 511 deleteIncidence ( lse );
461 } 512 }
462} 513}
463QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 514QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
464{ 515{
465 QPtrList<Event> el; 516 QPtrList<Event> el;
466 Event *todo; 517 Event *todo;
467 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 518 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
468 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 519 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
469 if ( todo->summary().left(3) == "E: " ) 520 if ( todo->summary().left(3) == "E: " )
470 el.append( todo ); 521 el.append( todo );
471 } 522 }
472 523
473 return el; 524 return el;
474 525
475} 526}
476Event *CalendarLocal::event( QString syncProf, QString id ) 527Event *CalendarLocal::event( QString syncProf, QString id )
477{ 528{
478 Event *todo; 529 Event *todo;
479 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 530 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
480 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 531 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
481 } 532 }
482 533
483 return 0; 534 return 0;
484} 535}
485Todo *CalendarLocal::todo( const QString &uid ) 536Todo *CalendarLocal::todo( const QString &uid )
486{ 537{
487 Todo *todo; 538 Todo *todo;
488 Todo *retVal = 0; 539 Todo *retVal = 0;
489 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 540 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
490 if ( todo->calEnabled() && todo->uid() == uid ) { 541 if ( todo->calEnabled() && todo->uid() == uid ) {
491 if ( retVal ) { 542 if ( retVal ) {
492 if ( retVal->calID() > todo->calID() ) { 543 if ( retVal->calID() > todo->calID() ) {
493 retVal = todo; 544 retVal = todo;
494 } 545 }
495 } else { 546 } else {
496 retVal = todo; 547 retVal = todo;
497 } 548 }
498 } 549 }
499 } 550 }
500 return retVal; 551 return retVal;
501} 552}
502void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) 553void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals)
503{ 554{
504 events = 0; 555 events = 0;
505 todos = 0; 556 todos = 0;
506 journals = 0; 557 journals = 0;
507 { 558 {
508 Todo *todo; 559 Todo *todo;
509 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 560 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
510 if ( todo->calID() == calId ) 561 if ( todo->calID() == calId )
511 ++todos; 562 ++todos;
512 } 563 }
513 } 564 }
514 { 565 {
515 Event *todo; 566 Event *todo;
516 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 567 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
517 if ( todo->calID() == calId ) 568 if ( todo->calID() == calId )
518 ++events; 569 ++events;
519 570
520 } 571 }
521 } 572 }
522 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 573 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
523 if ( it->calID() == calId ) ++journals; 574 if ( it->calID() == calId ) ++journals;
524 575
525} 576}
526QString CalendarLocal::nextSummary() const 577QString CalendarLocal::nextSummary() const
527{ 578{
528 return mNextSummary; 579 return mNextSummary;
529} 580}
530QDateTime CalendarLocal::nextAlarmEventDateTime() const 581QDateTime CalendarLocal::nextAlarmEventDateTime() const
531{ 582{
532 return mNextAlarmEventDateTime; 583 return mNextAlarmEventDateTime;
533} 584}
534void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 585void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
535{ 586{
536 //mNextAlarmIncidence 587 //mNextAlarmIncidence
537 //mNextAlarmDateTime 588 //mNextAlarmDateTime
538 //return mNextSummary; 589 //return mNextSummary;
539 //return mNextAlarmEventDateTime; 590 //return mNextAlarmEventDateTime;
540 bool newNextAlarm = false; 591 bool newNextAlarm = false;
541 bool computeNextAlarm = false; 592 bool computeNextAlarm = false;
542 bool ok; 593 bool ok;
543 int offset; 594 int offset;
544 QDateTime nextA; 595 QDateTime nextA;
545 // QString nextSum; 596 // QString nextSum;
546 //QDateTime nextEvent; 597 //QDateTime nextEvent;
547 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 598 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
548 computeNextAlarm = true; 599 computeNextAlarm = true;
549 } else { 600 } else {
550 if ( ! deleted ) { 601 if ( ! deleted ) {
551 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 602 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
552 if ( ok ) { 603 if ( ok ) {
553 if ( nextA < mNextAlarmDateTime ) { 604 if ( nextA < mNextAlarmDateTime ) {
554 deRegisterAlarm(); 605 deRegisterAlarm();
555 mNextAlarmDateTime = nextA; 606 mNextAlarmDateTime = nextA;
556 mNextSummary = incidence->summary(); 607 mNextSummary = incidence->summary();
557 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 608 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
558 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 609 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
559 newNextAlarm = true; 610 newNextAlarm = true;
560 mNextAlarmIncidence = incidence; 611 mNextAlarmIncidence = incidence;
561 } else { 612 } else {
562 if ( incidence == mNextAlarmIncidence ) { 613 if ( incidence == mNextAlarmIncidence ) {
563 computeNextAlarm = true; 614 computeNextAlarm = true;
564 } 615 }
565 } 616 }
566 } else { 617 } else {
567 if ( mNextAlarmIncidence == incidence ) { 618 if ( mNextAlarmIncidence == incidence ) {
568 computeNextAlarm = true; 619 computeNextAlarm = true;
569 } 620 }
570 } 621 }
571 } else { // deleted 622 } else { // deleted
572 if ( incidence == mNextAlarmIncidence ) { 623 if ( incidence == mNextAlarmIncidence ) {
573 computeNextAlarm = true; 624 computeNextAlarm = true;
574 } 625 }
575 } 626 }
576 } 627 }
577 if ( computeNextAlarm ) { 628 if ( computeNextAlarm ) {
578 deRegisterAlarm(); 629 deRegisterAlarm();
579 nextA = nextAlarm( 1000 ); 630 nextA = nextAlarm( 1000 );
580 if (! mNextAlarmIncidence ) { 631 if (! mNextAlarmIncidence ) {
581 return; 632 return;
582 } 633 }
583 newNextAlarm = true; 634 newNextAlarm = true;
584 } 635 }
585 if ( newNextAlarm ) 636 if ( newNextAlarm )
586 registerAlarm(); 637 registerAlarm();
587} 638}
588QString CalendarLocal:: getAlarmNotification() 639QString CalendarLocal:: getAlarmNotification()
589{ 640{
590 QString ret; 641 QString ret;
591 // this should not happen 642 // this should not happen
592 if (! mNextAlarmIncidence ) 643 if (! mNextAlarmIncidence )
593 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 644 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
594 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 645 Alarm* alarm = mNextAlarmIncidence->alarms().first();
595 if ( alarm->type() == Alarm::Procedure ) { 646 if ( alarm->type() == Alarm::Procedure ) {
596 ret = "proc_alarm" + alarm->programFile()+"+++"; 647 ret = "proc_alarm" + alarm->programFile()+"+++";
597 } else { 648 } else {
598 ret = "audio_alarm" +alarm->audioFile() +"+++"; 649 ret = "audio_alarm" +alarm->audioFile() +"+++";
599 } 650 }
600 ret += "cal_alarm"+ mNextSummary.left( 25 ); 651 ret += "cal_alarm"+ mNextSummary.left( 25 );
601 if ( mNextSummary.length() > 25 ) 652 if ( mNextSummary.length() > 25 )
602 ret += "\n" + mNextSummary.mid(25, 25 ); 653 ret += "\n" + mNextSummary.mid(25, 25 );
603 ret+= "\n"+mNextAlarmEventDateTimeString; 654 ret+= "\n"+mNextAlarmEventDateTimeString;
604 return ret; 655 return ret;
605} 656}
606void CalendarLocal::registerAlarm() 657void CalendarLocal::registerAlarm()
607{ 658{
608 mLastAlarmNotificationString = getAlarmNotification(); 659 mLastAlarmNotificationString = getAlarmNotification();
609 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 660 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
610 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 661 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
611// #ifndef DESKTOP_VERSION 662// #ifndef DESKTOP_VERSION
612// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 663// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
613// #endif 664// #endif
614} 665}
615void CalendarLocal::deRegisterAlarm() 666void CalendarLocal::deRegisterAlarm()
616{ 667{
617 if ( mLastAlarmNotificationString.isNull() ) 668 if ( mLastAlarmNotificationString.isNull() )
618 return; 669 return;
619 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 670 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
620 671
621 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 672 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
622 mNextAlarmEventDateTime = QDateTime(); 673 mNextAlarmEventDateTime = QDateTime();
623// #ifndef DESKTOP_VERSION 674// #ifndef DESKTOP_VERSION
624// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 675// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
625// #endif 676// #endif
626} 677}
627 678
628QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 679QPtrList<Todo> CalendarLocal::todos( const QDate &date )
629{ 680{
630 QPtrList<Todo> todos; 681 QPtrList<Todo> todos;
631 682
632 Todo *todo; 683 Todo *todo;
633 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 684 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
634 if ( !todo->calEnabled() ) continue; 685 if ( !todo->calEnabled() ) continue;
635 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 686 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
636 todos.append( todo ); 687 todos.append( todo );
637 } 688 }
638 } 689 }
639 690
640 filter()->apply( &todos ); 691 filter()->apply( &todos );
641 return todos; 692 return todos;
642} 693}
643void CalendarLocal::reInitAlarmSettings() 694void CalendarLocal::reInitAlarmSettings()
644{ 695{
645 if ( !mNextAlarmIncidence ) { 696 if ( !mNextAlarmIncidence ) {
646 nextAlarm( 1000 ); 697 nextAlarm( 1000 );
647 } 698 }
648 deRegisterAlarm(); 699 deRegisterAlarm();
649 mNextAlarmIncidence = 0; 700 mNextAlarmIncidence = 0;
650 checkAlarmForIncidence( 0, false ); 701 checkAlarmForIncidence( 0, false );
651 702
652} 703}
653 704
654 705
655 706
656QDateTime CalendarLocal::nextAlarm( int daysTo ) 707QDateTime CalendarLocal::nextAlarm( int daysTo )
657{ 708{
658 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 709 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
659 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 710 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
660 QDateTime next; 711 QDateTime next;
661 Event *e; 712 Event *e;
662 bool ok; 713 bool ok;
663 bool found = false; 714 bool found = false;
664 int offset; 715 int offset;
665 mNextAlarmIncidence = 0; 716 mNextAlarmIncidence = 0;
666 for( e = mEventList.first(); e; e = mEventList.next() ) { 717 for( e = mEventList.first(); e; e = mEventList.next() ) {
667 if ( !e->calEnabled() ) continue; 718 if ( !e->calEnabled() ) continue;
668 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 719 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
669 if ( ok ) { 720 if ( ok ) {
670 if ( next < nextA ) { 721 if ( next < nextA ) {
671 nextA = next; 722 nextA = next;
672 found = true; 723 found = true;
673 mNextSummary = e->summary(); 724 mNextSummary = e->summary();
674 mNextAlarmEventDateTime = next.addSecs(offset ) ; 725 mNextAlarmEventDateTime = next.addSecs(offset ) ;
675 mNextAlarmIncidence = (Incidence *) e; 726 mNextAlarmIncidence = (Incidence *) e;
676 } 727 }
677 } 728 }
678 } 729 }
679 Todo *t; 730 Todo *t;
680 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 731 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
681 if ( !t->calEnabled() ) continue; 732 if ( !t->calEnabled() ) continue;
682 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 733 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
683 if ( ok ) { 734 if ( ok ) {
684 if ( next < nextA ) { 735 if ( next < nextA ) {
685 nextA = next; 736 nextA = next;
686 found = true; 737 found = true;
687 mNextSummary = t->summary(); 738 mNextSummary = t->summary();
688 mNextAlarmEventDateTime = next.addSecs(offset ); 739 mNextAlarmEventDateTime = next.addSecs(offset );
689 mNextAlarmIncidence = (Incidence *) t; 740 mNextAlarmIncidence = (Incidence *) t;
690 } 741 }
691 } 742 }
692 } 743 }
693 if ( mNextAlarmIncidence ) { 744 if ( mNextAlarmIncidence ) {
694 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 745 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
695 mNextAlarmDateTime = nextA; 746 mNextAlarmDateTime = nextA;
696 } 747 }
697 return nextA; 748 return nextA;
698} 749}
699Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 750Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
700{ 751{
701 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 752 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
702} 753}
703 754
704Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 755Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
705{ 756{
706 757
707 Alarm::List alarms; 758 Alarm::List alarms;
708 759
709 Event *e; 760 Event *e;
710 761
711 for( e = mEventList.first(); e; e = mEventList.next() ) { 762 for( e = mEventList.first(); e; e = mEventList.next() ) {
712 if ( !e->calEnabled() ) continue; 763 if ( !e->calEnabled() ) continue;
713 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 764 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
714 else appendAlarms( alarms, e, from, to ); 765 else appendAlarms( alarms, e, from, to );
715 } 766 }
716 767
717 Todo *t; 768 Todo *t;
718 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 769 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
719 if ( !t->calEnabled() ) continue; 770 if ( !t->calEnabled() ) continue;
720 appendAlarms( alarms, t, from, to ); 771 appendAlarms( alarms, t, from, to );
721 } 772 }
722 773
723 return alarms; 774 return alarms;
724} 775}
725 776
726void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 777void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
727 const QDateTime &from, const QDateTime &to ) 778 const QDateTime &from, const QDateTime &to )
728{ 779{
729 QPtrList<Alarm> alarmList = incidence->alarms(); 780 QPtrList<Alarm> alarmList = incidence->alarms();
730 Alarm *alarm; 781 Alarm *alarm;
731 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 782 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
732// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 783// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
733// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 784// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
734 if ( alarm->enabled() ) { 785 if ( alarm->enabled() ) {
735 if ( alarm->time() >= from && alarm->time() <= to ) { 786 if ( alarm->time() >= from && alarm->time() <= to ) {
736 alarms.append( alarm ); 787 alarms.append( alarm );
737 } 788 }
738 } 789 }
739 } 790 }
740} 791}
741 792
742void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 793void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
743 Incidence *incidence, 794 Incidence *incidence,
744 const QDateTime &from, 795 const QDateTime &from,
745 const QDateTime &to ) 796 const QDateTime &to )
746{ 797{
747 798
748 QPtrList<Alarm> alarmList = incidence->alarms(); 799 QPtrList<Alarm> alarmList = incidence->alarms();
749 Alarm *alarm; 800 Alarm *alarm;
750 QDateTime qdt; 801 QDateTime qdt;
751 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 802 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
752 if (incidence->recursOn(from.date())) { 803 if (incidence->recursOn(from.date())) {
753 qdt.setTime(alarm->time().time()); 804 qdt.setTime(alarm->time().time());
754 qdt.setDate(from.date()); 805 qdt.setDate(from.date());
755 } 806 }
756 else qdt = alarm->time(); 807 else qdt = alarm->time();
757 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 808 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
758 if ( alarm->enabled() ) { 809 if ( alarm->enabled() ) {
759 if ( qdt >= from && qdt <= to ) { 810 if ( qdt >= from && qdt <= to ) {
760 alarms.append( alarm ); 811 alarms.append( alarm );
761 } 812 }
762 } 813 }
763 } 814 }
764} 815}
765 816
766 817
767/****************************** PROTECTED METHODS ****************************/ 818/****************************** PROTECTED METHODS ****************************/
768 819
769// after changes are made to an event, this should be called. 820// after changes are made to an event, this should be called.
770void CalendarLocal::update( IncidenceBase *incidence ) 821void CalendarLocal::update( IncidenceBase *incidence )
771{ 822{
772 incidence->setSyncStatus( Event::SYNCMOD ); 823 incidence->setSyncStatus( Event::SYNCMOD );
773 incidence->setLastModified( QDateTime::currentDateTime() ); 824 incidence->setLastModified( QDateTime::currentDateTime() );
774 // we should probably update the revision number here, 825 // we should probably update the revision number here,
775 // or internally in the Event itself when certain things change. 826 // or internally in the Event itself when certain things change.
776 // need to verify with ical documentation. 827 // need to verify with ical documentation.
777 828
778 setModified( true ); 829 setModified( true );
779} 830}
780 831
781void CalendarLocal::insertEvent( Event *event ) 832void CalendarLocal::insertEvent( Event *event )
782{ 833{
783 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 834 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
784} 835}
785 836
786 837
787QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 838QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
788{ 839{
789 QPtrList<Event> eventList; 840 QPtrList<Event> eventList;
790 841
791 Event *event; 842 Event *event;
792 for( event = mEventList.first(); event; event = mEventList.next() ) { 843 for( event = mEventList.first(); event; event = mEventList.next() ) {
793 if ( !event->calEnabled() ) continue; 844 if ( !event->calEnabled() ) continue;
794 if ( event->doesRecur() ) { 845 if ( event->doesRecur() ) {
795 if ( event->isMultiDay() ) { 846 if ( event->isMultiDay() ) {
796 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 847 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
797 int i; 848 int i;
798 for ( i = 0; i <= extraDays; i++ ) { 849 for ( i = 0; i <= extraDays; i++ ) {
799 if ( event->recursOn( qd.addDays( -i ) ) ) { 850 if ( event->recursOn( qd.addDays( -i ) ) ) {
800 eventList.append( event ); 851 eventList.append( event );
801 break; 852 break;
802 } 853 }
803 } 854 }
804 } else { 855 } else {
805 if ( event->recursOn( qd ) ) 856 if ( event->recursOn( qd ) )
806 eventList.append( event ); 857 eventList.append( event );
807 } 858 }
808 } else { 859 } else {
809 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 860 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
810 eventList.append( event ); 861 eventList.append( event );
811 } 862 }
812 } 863 }
813 } 864 }
814 865
815 if ( !sorted ) { 866 if ( !sorted ) {
816 return eventList; 867 return eventList;
817 } 868 }
818 869
819 // kdDebug(5800) << "Sorting events for date\n" << endl; 870 // kdDebug(5800) << "Sorting events for date\n" << endl;
820 // now, we have to sort it based on dtStart.time() 871 // now, we have to sort it based on dtStart.time()
821 QPtrList<Event> eventListSorted; 872 QPtrList<Event> eventListSorted;
822 Event *sortEvent; 873 Event *sortEvent;
823 for ( event = eventList.first(); event; event = eventList.next() ) { 874 for ( event = eventList.first(); event; event = eventList.next() ) {
824 sortEvent = eventListSorted.first(); 875 sortEvent = eventListSorted.first();
825 int i = 0; 876 int i = 0;
826 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 877 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
827 { 878 {
828 i++; 879 i++;
829 sortEvent = eventListSorted.next(); 880 sortEvent = eventListSorted.next();
830 } 881 }
831 eventListSorted.insert( i, event ); 882 eventListSorted.insert( i, event );
832 } 883 }
833 return eventListSorted; 884 return eventListSorted;
834} 885}
835 886
836 887
837QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 888QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
838 bool inclusive ) 889 bool inclusive )
839{ 890{
840 Event *event = 0; 891 Event *event = 0;
841 892
842 QPtrList<Event> eventList; 893 QPtrList<Event> eventList;
843 894
844 // Get non-recurring events 895 // Get non-recurring events
845 for( event = mEventList.first(); event; event = mEventList.next() ) { 896 for( event = mEventList.first(); event; event = mEventList.next() ) {
846 if ( !event->calEnabled() ) continue; 897 if ( !event->calEnabled() ) continue;
847 if ( event->doesRecur() ) { 898 if ( event->doesRecur() ) {
848 QDate rStart = event->dtStart().date(); 899 QDate rStart = event->dtStart().date();
849 bool found = false; 900 bool found = false;
850 if ( inclusive ) { 901 if ( inclusive ) {
851 if ( rStart >= start && rStart <= end ) { 902 if ( rStart >= start && rStart <= end ) {
852 // Start date of event is in range. Now check for end date. 903 // Start date of event is in range. Now check for end date.
853 // if duration is negative, event recurs forever, so do not include it. 904 // if duration is negative, event recurs forever, so do not include it.
854 if ( event->recurrence()->duration() == 0 ) { // End date set 905 if ( event->recurrence()->duration() == 0 ) { // End date set
855 QDate rEnd = event->recurrence()->endDate(); 906 QDate rEnd = event->recurrence()->endDate();
856 if ( rEnd >= start && rEnd <= end ) { // End date within range 907 if ( rEnd >= start && rEnd <= end ) { // End date within range
857 found = true; 908 found = true;
858 } 909 }
859 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 910 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
860 // TODO: Calculate end date from duration. Should be done in Event 911 // TODO: Calculate end date from duration. Should be done in Event
861 // For now exclude all events with a duration. 912 // For now exclude all events with a duration.
862 } 913 }
863 } 914 }
864 } else { 915 } else {
865 bool founOne; 916 bool founOne;
866 QDate next = event->getNextOccurence( start, &founOne ).date(); 917 QDate next = event->getNextOccurence( start, &founOne ).date();
867 if ( founOne ) { 918 if ( founOne ) {
868 if ( next <= end ) { 919 if ( next <= end ) {
869 found = true; 920 found = true;
870 } 921 }
871 } 922 }
872 923
873 /* 924 /*
874 // crap !!! 925 // crap !!!
875 if ( rStart <= end ) { // Start date not after range 926 if ( rStart <= end ) { // Start date not after range
876 if ( rStart >= start ) { // Start date within range 927 if ( rStart >= start ) { // Start date within range
877 found = true; 928 found = true;
878 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 929 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
879 found = true; 930 found = true;
880 } else if ( event->recurrence()->duration() == 0 ) { // End date set 931 } else if ( event->recurrence()->duration() == 0 ) { // End date set
881 QDate rEnd = event->recurrence()->endDate(); 932 QDate rEnd = event->recurrence()->endDate();
882 if ( rEnd >= start && rEnd <= end ) { // End date within range 933 if ( rEnd >= start && rEnd <= end ) { // End date within range
883 found = true; 934 found = true;
884 } 935 }
885 } else { // Duration set 936 } else { // Duration set
886 // TODO: Calculate end date from duration. Should be done in Event 937 // TODO: Calculate end date from duration. Should be done in Event
887 // For now include all events with a duration. 938 // For now include all events with a duration.
888 found = true; 939 found = true;
889 } 940 }
890 } 941 }
891 */ 942 */
892 943
893 } 944 }
894 945
895 if ( found ) eventList.append( event ); 946 if ( found ) eventList.append( event );
896 } else { 947 } else {
897 QDate s = event->dtStart().date(); 948 QDate s = event->dtStart().date();
898 QDate e = event->dtEnd().date(); 949 QDate e = event->dtEnd().date();
899 950
900 if ( inclusive ) { 951 if ( inclusive ) {
901 if ( s >= start && e <= end ) { 952 if ( s >= start && e <= end ) {
902 eventList.append( event ); 953 eventList.append( event );
903 } 954 }
904 } else { 955 } else {
905 if ( ( e >= start && s <= end ) ) { 956 if ( ( e >= start && s <= end ) ) {
906 eventList.append( event ); 957 eventList.append( event );
907 } 958 }
908 } 959 }
909 } 960 }
910 } 961 }
911 962
912 return eventList; 963 return eventList;
913} 964}
914 965
915QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 966QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
916{ 967{
917 return rawEventsForDate( qdt.date() ); 968 return rawEventsForDate( qdt.date() );
918} 969}
919 970
920QPtrList<Event> CalendarLocal::rawEvents() 971QPtrList<Event> CalendarLocal::rawEvents()
921{ 972{
922 QPtrList<Event> el; 973 QPtrList<Event> el;
923 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 974 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
924 if ( it->calEnabled() ) el.append( it ); 975 if ( it->calEnabled() ) el.append( it );
925 return el; 976 return el;
926} 977}
927 978
928bool CalendarLocal::addJournal(Journal *journal) 979bool CalendarLocal::addJournal(Journal *journal)
929{ 980{
930 mJournalList.append(journal); 981 mJournalList.append(journal);
931 982
932 journal->registerObserver( this ); 983 journal->registerObserver( this );
933 984
934 setModified( true ); 985 setModified( true );
935 if ( journal->calID() == 0 ) 986 if ( journal->calID() == 0 )
936 journal->setCalID_block( mDefaultCalendar ); 987 journal->setCalID_block( mDefaultCalendar );
937 journal->setCalEnabled( true ); 988 journal->setCalEnabled( true );
938 return true; 989 return true;
939} 990}
940 991
941void CalendarLocal::deleteJournal( Journal *journal ) 992void CalendarLocal::deleteJournal( Journal *journal )
942{ 993{
943 clearUndo(journal); 994 clearUndo(journal);
944 if ( mJournalList.removeRef(journal) ) { 995 if ( mJournalList.removeRef(journal) ) {
945 setModified( true ); 996 setModified( true );
946 } 997 }
947} 998}
948 999
949QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) 1000QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date )
950{ 1001{
951 QPtrList<Journal> el; 1002 QPtrList<Journal> el;
952 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1003 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
953 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); 1004 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it );
954 return el; 1005 return el;
955} 1006}
956Journal *CalendarLocal::journal( const QDate &date ) 1007Journal *CalendarLocal::journal( const QDate &date )
957{ 1008{
958// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 1009// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
959 1010
960 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1011 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
961 if ( it->calEnabled() && it->dtStart().date() == date ) 1012 if ( it->calEnabled() && it->dtStart().date() == date )
962 return it; 1013 return it;
963 1014
964 return 0; 1015 return 0;
965} 1016}
966 1017
967Journal *CalendarLocal::journal( const QString &uid ) 1018Journal *CalendarLocal::journal( const QString &uid )
968{ 1019{
969 Journal * retVal = 0; 1020 Journal * retVal = 0;
970 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1021 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
971 if ( it->calEnabled() && it->uid() == uid ) { 1022 if ( it->calEnabled() && it->uid() == uid ) {
972 if ( retVal ) { 1023 if ( retVal ) {
973 if ( retVal->calID() > it->calID() ) { 1024 if ( retVal->calID() > it->calID() ) {
974 retVal = it; 1025 retVal = it;
975 } 1026 }
976 } else { 1027 } else {
977 retVal = it; 1028 retVal = it;
978 } 1029 }
979 } 1030 }
980 return retVal; 1031 return retVal;
981} 1032}
982 1033
983QPtrList<Journal> CalendarLocal::journals() 1034QPtrList<Journal> CalendarLocal::journals()
984{ 1035{
985 QPtrList<Journal> el; 1036 QPtrList<Journal> el;
986 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1037 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
987 if ( it->calEnabled() ) el.append( it ); 1038 if ( it->calEnabled() ) el.append( it );
988 return el; 1039 return el;
989} 1040}
990void CalendarLocal::setCalendarRemove( int id ) 1041void CalendarLocal::setCalendarRemove( int id )
991{ 1042{
992 1043
993 { 1044 {
994 QPtrList<Event> EventList = mEventList; 1045 QPtrList<Event> EventList = mEventList;
995 Event * ev = EventList.first(); 1046 Event * ev = EventList.first();
996 while ( ev ) { 1047 while ( ev ) {
997 if ( ev->calID() == id && ev->uid().left( 15 ) != QString("last-syncEvent-") ) 1048 if ( ev->calID() == id && ev->uid().left( 15 ) != QString("last-syncEvent-") )
998 deleteEvent( ev ); 1049 deleteEvent( ev );
999 ev = EventList.next(); 1050 ev = EventList.next();
1000 } 1051 }
1001 } 1052 }
1002 { 1053 {
1003 1054
1004 QPtrList<Todo> TodoList = mTodoList; 1055 QPtrList<Todo> TodoList = mTodoList;
1005 Todo * ev = TodoList.first(); 1056 Todo * ev = TodoList.first();
1006 while ( ev ) { 1057 while ( ev ) {
1007 if ( ev->calID() == id ) 1058 if ( ev->calID() == id )
1008 deleteTodo( ev ); 1059 deleteTodo( ev );
1009 ev = TodoList.next(); 1060 ev = TodoList.next();
1010 } 1061 }
1011 } 1062 }
1012 { 1063 {
1013 QPtrList<Journal> JournalList = mJournalList; 1064 QPtrList<Journal> JournalList = mJournalList;
1014 Journal * ev = JournalList.first(); 1065 Journal * ev = JournalList.first();
1015 while ( ev ) { 1066 while ( ev ) {
1016 if ( ev->calID() == id ) 1067 if ( ev->calID() == id )
1017 deleteJournal( ev ); 1068 deleteJournal( ev );
1018 ev = JournalList.next(); 1069 ev = JournalList.next();
1019 } 1070 }
1020 } 1071 }
1021 1072
1022 clearUndo(0); 1073 clearUndo(0);
1023 1074
1024} 1075}
1025 1076
1026void CalendarLocal::setAllCalendarEnabled( bool enable ) 1077void CalendarLocal::setAllCalendarEnabled( bool enable )
1027{ 1078{
1028 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1079 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1029 it->setCalEnabled( enable ); 1080 it->setCalEnabled( enable );
1030 1081
1031 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1082 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1032 it->setCalEnabled( enable ); 1083 it->setCalEnabled( enable );
1033 1084
1034 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1085 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1035 it->setCalEnabled( enable ); 1086 it->setCalEnabled( enable );
1036 1087
1037 1088
1038} 1089}
1039void CalendarLocal::setCalendarEnabled( int id, bool enable ) 1090void CalendarLocal::setCalendarEnabled( int id, bool enable )
1040{ 1091{
1041 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1092 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1042 if ( it->calID() == id ) it->setCalEnabled( enable ); 1093 if ( it->calID() == id ) it->setCalEnabled( enable );
1043 1094
1044 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1095 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1045 if ( it->calID() == id ) it->setCalEnabled( enable ); 1096 if ( it->calID() == id ) it->setCalEnabled( enable );
1046 1097
1047 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1098 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1048 if ( it->calID() == id ) it->setCalEnabled( enable ); 1099 if ( it->calID() == id ) it->setCalEnabled( enable );
1049 1100
1050} 1101}
1051 1102
1052void CalendarLocal::setReadOnly( int id, bool enable ) 1103void CalendarLocal::setReadOnly( int id, bool enable )
1053{ 1104{
1054 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1105 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1055 if ( it->calID() == id ) it->setReadOnly( enable ); 1106 if ( it->calID() == id ) it->setReadOnly( enable );
1056 1107
1057 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1108 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1058 if ( it->calID() == id ) it->setReadOnly( enable ); 1109 if ( it->calID() == id ) it->setReadOnly( enable );
1059 1110
1060 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1111 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1061 if ( it->calID() == id ) it->setReadOnly( enable ); 1112 if ( it->calID() == id ) it->setReadOnly( enable );
1062 1113
1063} 1114}
1064 1115
1065void CalendarLocal::setAlarmEnabled( int id, bool enable ) 1116void CalendarLocal::setAlarmEnabled( int id, bool enable )
1066{ 1117{
1067 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1118 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1068 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1119 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1069 1120
1070 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1121 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1071 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1122 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1072 1123
1073 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1124 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1074 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1125 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1075 reInitAlarmSettings(); 1126 reInitAlarmSettings();
1076 1127
1077} 1128}
1078void CalendarLocal::setDefaultCalendarEnabledOnly() 1129void CalendarLocal::setDefaultCalendarEnabledOnly()
1079{ 1130{
1080 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1131 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1081 it->setCalEnabled( it->calID() == mDefaultCalendar ); 1132 it->setCalEnabled( it->calID() == mDefaultCalendar );
1082 1133
1083 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1134 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1084 it->setCalEnabled( it->calID() == mDefaultCalendar); 1135 it->setCalEnabled( it->calID() == mDefaultCalendar);
1085 1136
1086 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1137 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1087 it->setCalEnabled( it->calID() == mDefaultCalendar); 1138 it->setCalEnabled( it->calID() == mDefaultCalendar);
1088 1139
1089} 1140}
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index b611704..1ceabce 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -1,233 +1,234 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22#ifndef KCAL_CALENDARLOCAL_H 22#ifndef KCAL_CALENDARLOCAL_H
23#define KCAL_CALENDARLOCAL_H 23#define KCAL_CALENDARLOCAL_H
24 24
25#include "calendar.h" 25#include "calendar.h"
26 26
27namespace KCal { 27namespace KCal {
28 28
29class CalFormat; 29class CalFormat;
30 30
31/** 31/**
32 This class provides a calendar stored as a local file. 32 This class provides a calendar stored as a local file.
33*/ 33*/
34class CalendarLocal : public Calendar 34class CalendarLocal : public Calendar
35{ 35{
36 public: 36 public:
37 /** 37 /**
38 Constructs a new calendar, with variables initialized to sane values. 38 Constructs a new calendar, with variables initialized to sane values.
39 */ 39 */
40 CalendarLocal(); 40 CalendarLocal();
41 /** 41 /**
42 Constructs a new calendar, with variables initialized to sane values. 42 Constructs a new calendar, with variables initialized to sane values.
43 */ 43 */
44 CalendarLocal( const QString &timeZoneId ); 44 CalendarLocal( const QString &timeZoneId );
45 ~CalendarLocal(); 45 ~CalendarLocal();
46 void addCalendar( Calendar* ); 46 void addCalendar( Calendar* );
47 bool addCalendarFile( QString name, int id ); 47 bool addCalendarFile( QString name, int id );
48 bool mergeCalendarFile( QString name ); 48 bool mergeCalendarFile( QString name );
49 bool mergeCalendar( Calendar* cal ); 49 bool mergeCalendar( Calendar* cal );
50 Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly = false ); 50 Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly = false,int * isDup = 0 );
51 Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0 );
51 void setSyncEventsReadOnly(); 52 void setSyncEventsReadOnly();
52 void setSyncEventsEnabled(); 53 void setSyncEventsEnabled();
53 void stopAllTodos(); 54 void stopAllTodos();
54 /** 55 /**
55 Loads a calendar on disk in vCalendar or iCalendar format into the current 56 Loads a calendar on disk in vCalendar or iCalendar format into the current
56 calendar. Any information already present is lost. 57 calendar. Any information already present is lost.
57 @return true, if successfull, false on error. 58 @return true, if successfull, false on error.
58 @param fileName the name of the calendar on disk. 59 @param fileName the name of the calendar on disk.
59 */ 60 */
60 bool load( const QString &fileName ); 61 bool load( const QString &fileName );
61 /** 62 /**
62 Writes out the calendar to disk in the specified \a format. 63 Writes out the calendar to disk in the specified \a format.
63 CalendarLocal takes ownership of the CalFormat object. 64 CalendarLocal takes ownership of the CalFormat object.
64 @return true, if successfull, false on error. 65 @return true, if successfull, false on error.
65 @param fileName the name of the file 66 @param fileName the name of the file
66 */ 67 */
67 bool save( const QString &fileName, CalFormat *format = 0 ); 68 bool save( const QString &fileName, CalFormat *format = 0 );
68 69
69 /** 70 /**
70 Clears out the current calendar, freeing all used memory etc. etc. 71 Clears out the current calendar, freeing all used memory etc. etc.
71 */ 72 */
72 void close(); 73 void close();
73 74
74 void save() {} 75 void save() {}
75 76
76 /** 77 /**
77 Add Event to calendar. 78 Add Event to calendar.
78 */ 79 */
79 void removeSyncInfo( QString syncProfile); 80 void removeSyncInfo( QString syncProfile);
80 bool addAnniversaryNoDup( Event *event ); 81 bool addAnniversaryNoDup( Event *event );
81 bool addEventNoDup( Event *event ); 82 bool addEventNoDup( Event *event );
82 bool addEvent( Event *event ); 83 bool addEvent( Event *event );
83 /** 84 /**
84 Deletes an event from this calendar. 85 Deletes an event from this calendar.
85 */ 86 */
86 void deleteEvent( Event *event ); 87 void deleteEvent( Event *event );
87 88
88 /** 89 /**
89 Retrieves an event on the basis of the unique string ID. 90 Retrieves an event on the basis of the unique string ID.
90 */ 91 */
91 Event *event( const QString &uid ); 92 Event *event( const QString &uid );
92 /** 93 /**
93 Return unfiltered list of all events in calendar. 94 Return unfiltered list of all events in calendar.
94 */ 95 */
95 QPtrList<Event> rawEvents(); 96 QPtrList<Event> rawEvents();
96 QPtrList<Event> getExternLastSyncEvents(); 97 QPtrList<Event> getExternLastSyncEvents();
97 /** 98 /**
98 Add a todo to the todolist. 99 Add a todo to the todolist.
99 */ 100 */
100 bool addTodo( Todo *todo ); 101 bool addTodo( Todo *todo );
101 bool addTodoNoDup( Todo *todo ); 102 bool addTodoNoDup( Todo *todo );
102 /** 103 /**
103 Remove a todo from the todolist. 104 Remove a todo from the todolist.
104 */ 105 */
105 void deleteTodo( Todo * ); 106 void deleteTodo( Todo * );
106 /** 107 /**
107 Searches todolist for an event with this unique string identifier, 108 Searches todolist for an event with this unique string identifier,
108 returns a pointer or null. 109 returns a pointer or null.
109 */ 110 */
110 Todo *todo( const QString &uid ); 111 Todo *todo( const QString &uid );
111 /** 112 /**
112 Return list of all todos. 113 Return list of all todos.
113 */ 114 */
114 QPtrList<Todo> rawTodos(); 115 QPtrList<Todo> rawTodos();
115 /** 116 /**
116 Returns list of todos due on the specified date. 117 Returns list of todos due on the specified date.
117 */ 118 */
118 QPtrList<Todo> todos( const QDate &date ); 119 QPtrList<Todo> todos( const QDate &date );
119 /** 120 /**
120 Return list of all todos. 121 Return list of all todos.
121 122
122 Workaround because compiler does not recognize function of base class. 123 Workaround because compiler does not recognize function of base class.
123 */ 124 */
124 QPtrList<Todo> todos() { return Calendar::todos(); } 125 QPtrList<Todo> todos() { return Calendar::todos(); }
125 126
126 /** 127 /**
127 Add a Journal entry to calendar. 128 Add a Journal entry to calendar.
128 */ 129 */
129 bool addJournal( Journal * ); 130 bool addJournal( Journal * );
130 /** 131 /**
131 Remove a Journal from the calendar. 132 Remove a Journal from the calendar.
132 */ 133 */
133 void deleteJournal( Journal * ); 134 void deleteJournal( Journal * );
134 /** 135 /**
135 Return Journal for given date. 136 Return Journal for given date.
136 */ 137 */
137 Journal *journal( const QDate & ); 138 Journal *journal( const QDate & );
138 QPtrList<Journal> journals4Date( const QDate & ); 139 QPtrList<Journal> journals4Date( const QDate & );
139 /** 140 /**
140 Return Journal with given UID. 141 Return Journal with given UID.
141 */ 142 */
142 Journal *journal( const QString &uid ); 143 Journal *journal( const QString &uid );
143 /** 144 /**
144 Return list of all Journals stored in calendar. 145 Return list of all Journals stored in calendar.
145 */ 146 */
146 QPtrList<Journal> journals(); 147 QPtrList<Journal> journals();
147 148
148 /** 149 /**
149 Return all alarms, which ocur in the given time interval. 150 Return all alarms, which ocur in the given time interval.
150 */ 151 */
151 Alarm::List alarms( const QDateTime &from, const QDateTime &to ); 152 Alarm::List alarms( const QDateTime &from, const QDateTime &to );
152 153
153 /** 154 /**
154 Return all alarms, which ocur before given date. 155 Return all alarms, which ocur before given date.
155 */ 156 */
156 Alarm::List alarmsTo( const QDateTime &to ); 157 Alarm::List alarmsTo( const QDateTime &to );
157 158
158 QDateTime nextAlarm( int daysTo ) ; 159 QDateTime nextAlarm( int daysTo ) ;
159 QDateTime nextAlarmEventDateTime() const; 160 QDateTime nextAlarmEventDateTime() const;
160 void checkAlarmForIncidence( Incidence *, bool deleted ) ; 161 void checkAlarmForIncidence( Incidence *, bool deleted ) ;
161 void registerAlarm(); 162 void registerAlarm();
162 void deRegisterAlarm(); 163 void deRegisterAlarm();
163 QString getAlarmNotification(); 164 QString getAlarmNotification();
164 QString nextSummary() const ; 165 QString nextSummary() const ;
165 /** 166 /**
166 This method should be called whenever a Event is modified directly 167 This method should be called whenever a Event is modified directly
167 via it's pointer. It makes sure that the calendar is internally 168 via it's pointer. It makes sure that the calendar is internally
168 consistent. 169 consistent.
169 */ 170 */
170 void update( IncidenceBase *incidence ); 171 void update( IncidenceBase *incidence );
171 172
172 /** 173 /**
173 Builds and then returns a list of all events that match for the 174 Builds and then returns a list of all events that match for the
174 date specified. useful for dayView, etc. etc. 175 date specified. useful for dayView, etc. etc.
175 */ 176 */
176 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); 177 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false );
177 /** 178 /**
178 Get unfiltered events for date \a qdt. 179 Get unfiltered events for date \a qdt.
179 */ 180 */
180 QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); 181 QPtrList<Event> rawEventsForDate( const QDateTime &qdt );
181 /** 182 /**
182 Get unfiltered events in a range of dates. If inclusive is set to true, 183 Get unfiltered events in a range of dates. If inclusive is set to true,
183 only events are returned, which are completely included in the range. 184 only events are returned, which are completely included in the range.
184 */ 185 */
185 QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 186 QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
186 bool inclusive = false ); 187 bool inclusive = false );
187 Todo *todo( QString, QString ); 188 Todo *todo( QString, QString );
188 Event *event( QString, QString ); 189 Event *event( QString, QString );
189 void getIncidenceCount( int calId, int& events, int & todos, int & journals); 190 void getIncidenceCount( int calId, int& events, int & todos, int & journals);
190 191
191public slots: 192public slots:
192 void setCalendarEnabled( int id, bool enable ); 193 void setCalendarEnabled( int id, bool enable );
193 void setAlarmEnabled( int id, bool enable ); 194 void setAlarmEnabled( int id, bool enable );
194 void setReadOnly( int id, bool enable ); 195 void setReadOnly( int id, bool enable );
195 void setDefaultCalendarEnabledOnly(); 196 void setDefaultCalendarEnabledOnly();
196 void setCalendarRemove( int id ); 197 void setCalendarRemove( int id );
197 void setAllCalendarEnabled( bool enable ); 198 void setAllCalendarEnabled( bool enable );
198 199
199 protected: 200 protected:
200 201
201 // Event* mNextAlarmEvent; 202 // Event* mNextAlarmEvent;
202 QString mNextSummary; 203 QString mNextSummary;
203 QString mNextAlarmEventDateTimeString; 204 QString mNextAlarmEventDateTimeString;
204 QString mLastAlarmNotificationString; 205 QString mLastAlarmNotificationString;
205 QDateTime mNextAlarmEventDateTime; 206 QDateTime mNextAlarmEventDateTime;
206 QDateTime mNextAlarmDateTime; 207 QDateTime mNextAlarmDateTime;
207 void reInitAlarmSettings(); 208 void reInitAlarmSettings();
208 209
209 /** Notification function of IncidenceBase::Observer. */ 210 /** Notification function of IncidenceBase::Observer. */
210 void incidenceUpdated( IncidenceBase *i ) { update( i ); } 211 void incidenceUpdated( IncidenceBase *i ) { update( i ); }
211 212
212 /** inserts an event into its "proper place" in the calendar. */ 213 /** inserts an event into its "proper place" in the calendar. */
213 void insertEvent( Event *event ); 214 void insertEvent( Event *event );
214 215
215 /** Append alarms of incidence in interval to list of alarms. */ 216 /** Append alarms of incidence in interval to list of alarms. */
216 void appendAlarms( Alarm::List &alarms, Incidence *incidence, 217 void appendAlarms( Alarm::List &alarms, Incidence *incidence,
217 const QDateTime &from, const QDateTime &to ); 218 const QDateTime &from, const QDateTime &to );
218 219
219 /** Append alarms of recurring events in interval to list of alarms. */ 220 /** Append alarms of recurring events in interval to list of alarms. */
220 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, 221 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence,
221 const QDateTime &from, const QDateTime &to ); 222 const QDateTime &from, const QDateTime &to );
222 223
223 private: 224 private:
224 void init(); 225 void init();
225 226
226 QPtrList<Event> mEventList; 227 QPtrList<Event> mEventList;
227 QPtrList<Todo> mTodoList; 228 QPtrList<Todo> mTodoList;
228 QPtrList<Journal> mJournalList; 229 QPtrList<Journal> mJournalList;
229}; 230};
230 231
231} 232}
232 233
233#endif 234#endif
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index fe9f854..7dd9bd2 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -1,866 +1,872 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "calformat.h" 25#include "calformat.h"
26 26
27#include "incidence.h" 27#include "incidence.h"
28#include "todo.h" 28#include "todo.h"
29 29
30using namespace KCal; 30using namespace KCal;
31 31
32Incidence::Incidence() : 32Incidence::Incidence() :
33 IncidenceBase(), 33 IncidenceBase(),
34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) 34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3)
35{ 35{
36 mRecurrence = 0;//new Recurrence(this); 36 mRecurrence = 0;//new Recurrence(this);
37 mCancelled = false; 37 mCancelled = false;
38 recreate(); 38 recreate();
39 mHasStartDate = true; 39 mHasStartDate = true;
40 mAlarms.setAutoDelete(true); 40 mAlarms.setAutoDelete(true);
41 mAttachments.setAutoDelete(true); 41 mAttachments.setAutoDelete(true);
42 mHasRecurrenceID = false; 42 mHasRecurrenceID = false;
43 mHoliday = false; 43 mHoliday = false;
44 mBirthday = false; 44 mBirthday = false;
45 mAnniversary = false; 45 mAnniversary = false;
46 46
47} 47}
48 48
49Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) 49Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
50{ 50{
51// TODO: reenable attributes currently commented out. 51// TODO: reenable attributes currently commented out.
52 mRevision = i.mRevision; 52 mRevision = i.mRevision;
53 mCreated = i.mCreated; 53 mCreated = i.mCreated;
54 mDescription = i.mDescription; 54 mDescription = i.mDescription;
55 mSummary = i.mSummary; 55 mSummary = i.mSummary;
56 mCategories = i.mCategories; 56 mCategories = i.mCategories;
57// Incidence *mRelatedTo; Incidence *mRelatedTo; 57// Incidence *mRelatedTo; Incidence *mRelatedTo;
58 mRelatedTo = 0; 58 mRelatedTo = 0;
59 mRelatedToUid = i.mRelatedToUid; 59 mRelatedToUid = i.mRelatedToUid;
60// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; 60// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations;
61 mExDates = i.mExDates; 61 mExDates = i.mExDates;
62 QPtrListIterator<Attachment> itat( i.mAttachments ); 62 QPtrListIterator<Attachment> itat( i.mAttachments );
63 Attachment *at; 63 Attachment *at;
64 while( (at = itat.current()) ) { 64 while( (at = itat.current()) ) {
65 Attachment *a = new Attachment( *at ); 65 Attachment *a = new Attachment( *at );
66 mAttachments.append( a ); 66 mAttachments.append( a );
67 ++itat; 67 ++itat;
68 } 68 }
69 mAttachments.setAutoDelete( true ); 69 mAttachments.setAutoDelete( true );
70 mResources = i.mResources; 70 mResources = i.mResources;
71 mSecrecy = i.mSecrecy; 71 mSecrecy = i.mSecrecy;
72 mPriority = i.mPriority; 72 mPriority = i.mPriority;
73 mLocation = i.mLocation; 73 mLocation = i.mLocation;
74 mCancelled = i.mCancelled; 74 mCancelled = i.mCancelled;
75 mHasStartDate = i.mHasStartDate; 75 mHasStartDate = i.mHasStartDate;
76 QPtrListIterator<Alarm> it( i.mAlarms ); 76 QPtrListIterator<Alarm> it( i.mAlarms );
77 const Alarm *a; 77 const Alarm *a;
78 while( (a = it.current()) ) { 78 while( (a = it.current()) ) {
79 Alarm *b = new Alarm( *a ); 79 Alarm *b = new Alarm( *a );
80 b->setParent( this ); 80 b->setParent( this );
81 mAlarms.append( b ); 81 mAlarms.append( b );
82 82
83 ++it; 83 ++it;
84 } 84 }
85 mAlarms.setAutoDelete(true); 85 mAlarms.setAutoDelete(true);
86 mHasRecurrenceID = i.mHasRecurrenceID; 86 mHasRecurrenceID = i.mHasRecurrenceID;
87 mRecurrenceID = i.mRecurrenceID; 87 mRecurrenceID = i.mRecurrenceID;
88 if ( i.mRecurrence ) 88 if ( i.mRecurrence )
89 mRecurrence = new Recurrence( *(i.mRecurrence), this ); 89 mRecurrence = new Recurrence( *(i.mRecurrence), this );
90 else 90 else
91 mRecurrence = 0; 91 mRecurrence = 0;
92 mHoliday = i.mHoliday ; 92 mHoliday = i.mHoliday ;
93 mBirthday = i.mBirthday; 93 mBirthday = i.mBirthday;
94 mAnniversary = i.mAnniversary; 94 mAnniversary = i.mAnniversary;
95} 95}
96 96
97Incidence::~Incidence() 97Incidence::~Incidence()
98{ 98{
99 99
100 Incidence *ev; 100 Incidence *ev;
101 QPtrList<Incidence> Relations = relations(); 101 QPtrList<Incidence> Relations = relations();
102 for (ev=Relations.first();ev;ev=Relations.next()) { 102 for (ev=Relations.first();ev;ev=Relations.next()) {
103 if (ev->relatedTo() == this) ev->setRelatedTo(0); 103 if (ev->relatedTo() == this) ev->setRelatedTo(0);
104 } 104 }
105 if (relatedTo()) relatedTo()->removeRelation(this); 105 if (relatedTo()) relatedTo()->removeRelation(this);
106 if ( mRecurrence ) 106 if ( mRecurrence )
107 delete mRecurrence; 107 delete mRecurrence;
108 108
109} 109}
110QString Incidence::durationText() 110QString Incidence::durationText()
111{ 111{
112 return "---"; 112 return "---";
113} 113}
114QString Incidence::durationText4Time( int offset ) 114QString Incidence::durationText4Time( int offset )
115{ 115{
116 int min = offset/60; 116 int min = offset/60;
117 int hours = min /60; 117 int hours = min /60;
118 min = min % 60; 118 min = min % 60;
119 int days = hours /24; 119 int days = hours /24;
120 hours = hours % 24; 120 hours = hours % 24;
121 121
122 if ( doesFloat() || ( min == 0 && hours == 0 ) ) { 122 if ( doesFloat() || ( min == 0 && hours == 0 ) ) {
123 if ( days == 1 ) 123 if ( days == 1 )
124 return "1" + i18n(" day"); 124 return "1" + i18n(" day");
125 else 125 else
126 return QString::number( days )+ i18n(" days"); 126 return QString::number( days )+ i18n(" days");
127 127
128 } 128 }
129 QString message = QString::number ( hours ) +":"; 129 QString message = QString::number ( hours ) +":";
130 if ( min < 10 ) message += "0"; 130 if ( min < 10 ) message += "0";
131 message += QString::number ( min ); 131 message += QString::number ( min );
132 if ( days > 0 ) { 132 if ( days > 0 ) {
133 if ( days == 1 ) 133 if ( days == 1 )
134 message = "1" + i18n(" day") + " "+message; 134 message = "1" + i18n(" day") + " "+message;
135 else 135 else
136 message = QString::number( days )+ i18n(" days") + " "+message; 136 message = QString::number( days )+ i18n(" days") + " "+message;
137 } 137 }
138 return message; 138 return message;
139} 139}
140bool Incidence::isHoliday() const 140bool Incidence::isHoliday() const
141{ 141{
142 return mHoliday; 142 return mHoliday;
143} 143}
144bool Incidence::isBirthday() const 144bool Incidence::isBirthday() const
145{ 145{
146 146
147 return mBirthday ; 147 return mBirthday ;
148} 148}
149bool Incidence::isAnniversary() const 149bool Incidence::isAnniversary() const
150{ 150{
151 return mAnniversary ; 151 return mAnniversary ;
152 152
153} 153}
154 154
155bool Incidence::hasRecurrenceID() const 155bool Incidence::hasRecurrenceID() const
156{ 156{
157 return mHasRecurrenceID; 157 return mHasRecurrenceID;
158} 158}
159 159
160void Incidence::setHasRecurrenceID( bool b ) 160void Incidence::setHasRecurrenceID( bool b )
161{ 161{
162 mHasRecurrenceID = b; 162 mHasRecurrenceID = b;
163} 163}
164 164
165void Incidence::setRecurrenceID(QDateTime d) 165void Incidence::setRecurrenceID(QDateTime d)
166{ 166{
167 mRecurrenceID = d; 167 mRecurrenceID = d;
168 mHasRecurrenceID = true; 168 mHasRecurrenceID = true;
169 updated(); 169 updated();
170} 170}
171QDateTime Incidence::recurrenceID () const 171QDateTime Incidence::recurrenceID () const
172{ 172{
173 return mRecurrenceID; 173 return mRecurrenceID;
174} 174}
175 175
176bool Incidence::cancelled() const 176bool Incidence::cancelled() const
177{ 177{
178 return mCancelled; 178 return mCancelled;
179} 179}
180void Incidence::setCancelled( bool b ) 180void Incidence::setCancelled( bool b )
181{ 181{
182 mCancelled = b; 182 mCancelled = b;
183 updated(); 183 updated();
184} 184}
185bool Incidence::hasStartDate() const 185bool Incidence::hasStartDate() const
186{ 186{
187 return mHasStartDate; 187 return mHasStartDate;
188} 188}
189 189
190void Incidence::setHasStartDate(bool f) 190void Incidence::setHasStartDate(bool f)
191{ 191{
192 if (mReadOnly) return; 192 if (mReadOnly) return;
193 mHasStartDate = f; 193 mHasStartDate = f;
194 updated(); 194 updated();
195} 195}
196 196
197// A string comparison that considers that null and empty are the same 197// A string comparison that considers that null and empty are the same
198static bool stringCompare( const QString& s1, const QString& s2 ) 198static bool stringCompare( const QString& s1, const QString& s2 )
199{ 199{
200 if ( s1.isEmpty() && s2.isEmpty() ) 200 if ( s1.isEmpty() && s2.isEmpty() )
201 return true; 201 return true;
202 return s1 == s2; 202 return s1 == s2;
203} 203}
204 204
205bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 205bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
206{ 206{
207 207
208 if( i1.alarms().count() != i2.alarms().count() ) { 208 if( i1.alarms().count() != i2.alarms().count() ) {
209 return false; // no need to check further 209 return false; // no need to check further
210 } 210 }
211 if ( i1.alarms().count() > 0 ) { 211 if ( i1.alarms().count() > 0 ) {
212 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) 212 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) )
213 { 213 {
214 qDebug("alarm not equal "); 214 qDebug("alarm not equal ");
215 return false; 215 return false;
216 } 216 }
217 } 217 }
218#if 0 218#if 0
219 QPtrListIterator<Alarm> a1( i1.alarms() ); 219 QPtrListIterator<Alarm> a1( i1.alarms() );
220 QPtrListIterator<Alarm> a2( i2.alarms() ); 220 QPtrListIterator<Alarm> a2( i2.alarms() );
221 for( ; a1.current() && a2.current(); ++a1, ++a2 ) { 221 for( ; a1.current() && a2.current(); ++a1, ++a2 ) {
222 if( *a1.current() == *a2.current() ) { 222 if( *a1.current() == *a2.current() ) {
223 continue; 223 continue;
224 } 224 }
225 else { 225 else {
226 return false; 226 return false;
227 } 227 }
228 } 228 }
229#endif 229#endif
230 230
231 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { 231 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) {
232 if ( i1.hasRecurrenceID() ) { 232 if ( i1.hasRecurrenceID() ) {
233 if ( i1.recurrenceID() != i2.recurrenceID() ) 233 if ( i1.recurrenceID() != i2.recurrenceID() )
234 return false; 234 return false;
235 } 235 }
236 236
237 } else { 237 } else {
238 return false; 238 return false;
239 } 239 }
240 240
241 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) 241 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) )
242 return false; 242 return false;
243 if ( i1.hasStartDate() == i2.hasStartDate() ) { 243 if ( i1.hasStartDate() == i2.hasStartDate() ) {
244 if ( i1.hasStartDate() ) { 244 if ( i1.hasStartDate() ) {
245 if ( i1.dtStart() != i2.dtStart() ) 245 if ( i1.dtStart() != i2.dtStart() )
246 return false; 246 return false;
247 } 247 }
248 } else { 248 } else {
249 return false; 249 return false;
250 } 250 }
251 if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { 251 if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) {
252 if (!( *i1.mRecurrence == *i2.mRecurrence) ) { 252 if (!( *i1.mRecurrence == *i2.mRecurrence) ) {
253 //qDebug("recurrence is NOT equal "); 253 //qDebug("recurrence is NOT equal ");
254 return false; 254 return false;
255 } 255 }
256 } else { 256 } else {
257 // one ( or both ) recurrence is 0 257 // one ( or both ) recurrence is 0
258 if ( i1.mRecurrence == 0 ) { 258 if ( i1.mRecurrence == 0 ) {
259 if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) 259 if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone )
260 return false; 260 return false;
261 } else { 261 } else {
262 // i1.mRecurrence != 0 262 // i1.mRecurrence != 0
263 // i2.mRecurrence == 0 263 // i2.mRecurrence == 0
264 if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) 264 if ( i1.mRecurrence->doesRecur() != Recurrence::rNone )
265 return false; 265 return false;
266 } 266 }
267 } 267 }
268 268
269 return 269 return
270 // i1.created() == i2.created() && 270 // i1.created() == i2.created() &&
271 stringCompare( i1.description(), i2.description() ) && 271 stringCompare( i1.description(), i2.description() ) &&
272 stringCompare( i1.summary(), i2.summary() ) && 272 stringCompare( i1.summary(), i2.summary() ) &&
273 i1.categories() == i2.categories() && 273 i1.categories() == i2.categories() &&
274 // no need to compare mRelatedTo 274 // no need to compare mRelatedTo
275 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && 275 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) &&
276 // i1.relations() == i2.relations() && 276 // i1.relations() == i2.relations() &&
277 i1.exDates() == i2.exDates() && 277 i1.exDates() == i2.exDates() &&
278 i1.attachments() == i2.attachments() && 278 i1.attachments() == i2.attachments() &&
279 i1.resources() == i2.resources() && 279 i1.resources() == i2.resources() &&
280 i1.secrecy() == i2.secrecy() && 280 i1.secrecy() == i2.secrecy() &&
281 i1.priority() == i2.priority() && 281 i1.priority() == i2.priority() &&
282 i1.cancelled() == i2.cancelled() && 282 i1.cancelled() == i2.cancelled() &&
283 stringCompare( i1.location(), i2.location() ); 283 stringCompare( i1.location(), i2.location() );
284} 284}
285 285
286Incidence* Incidence::recreateCloneException( QDate d ) 286Incidence* Incidence::recreateCloneException( QDate d )
287{ 287{
288 Incidence* newInc = clone(); 288 Incidence* newInc = clone();
289 newInc->recreate(); 289 newInc->recreate();
290 if ( doesRecur() ) { 290 if ( doesRecur() ) {
291 addExDate( d ); 291 addExDate( d );
292 newInc->recurrence()->unsetRecurs(); 292 newInc->recurrence()->unsetRecurs();
293 if ( typeID() == eventID ) { 293 if ( typeID() == eventID ) {
294 int len = dtStart().secsTo( ((Event*)this)->dtEnd()); 294 int len = dtStart().secsTo( ((Event*)this)->dtEnd());
295 QTime tim = dtStart().time(); 295 QTime tim = dtStart().time();
296 newInc->setDtStart( QDateTime(d, tim) ); 296 newInc->setDtStart( QDateTime(d, tim) );
297 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 297 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
298 } else { 298 } else {
299 int len = dtStart().secsTo( ((Todo*)this)->dtDue()); 299 int len = dtStart().secsTo( ((Todo*)this)->dtDue());
300 QTime tim = ((Todo*)this)->dtDue().time(); 300 QTime tim = ((Todo*)this)->dtDue().time();
301 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); 301 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) );
302 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); 302 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) );
303 ((Todo*)this)->setRecurDates(); 303 ((Todo*)this)->setRecurDates();
304 } 304 }
305 newInc->setExDates( DateList () ); 305 newInc->setExDates( DateList () );
306 } 306 }
307 return newInc; 307 return newInc;
308} 308}
309 309
310void Incidence::recreate() 310void Incidence::recreate()
311{ 311{
312 setCreated(QDateTime::currentDateTime()); 312 setCreated(QDateTime::currentDateTime());
313 313
314 setUid(CalFormat::createUniqueId()); 314 setUid(CalFormat::createUniqueId());
315 315
316 setRevision(0); 316 setRevision(0);
317 setIDStr( ":" ); 317 setIDStr( ":" );
318 setLastModified(QDateTime::currentDateTime()); 318 setLastModified(QDateTime::currentDateTime());
319} 319}
320void Incidence::cloneRelations( Incidence * newInc ) 320void Incidence::cloneRelations( Incidence * newInc )
321{ 321{
322 // newInc is already a clone of this incidence 322 // newInc is already a clone of this incidence
323 Incidence * inc; 323 Incidence * inc;
324 Incidence * cloneInc; 324 Incidence * cloneInc;
325 QPtrList<Incidence> Relations = relations(); 325 QPtrList<Incidence> Relations = relations();
326 for (inc=Relations.first();inc;inc=Relations.next()) { 326 for (inc=Relations.first();inc;inc=Relations.next()) {
327 cloneInc = inc->clone(); 327 cloneInc = inc->clone();
328 cloneInc->recreate(); 328 cloneInc->recreate();
329 cloneInc->setRelatedTo( newInc ); 329 cloneInc->setRelatedTo( newInc );
330 inc->cloneRelations( cloneInc ); 330 inc->cloneRelations( cloneInc );
331 } 331 }
332} 332}
333void Incidence::setReadOnly( bool readOnly ) 333void Incidence::setReadOnly( bool readOnly )
334{ 334{
335 IncidenceBase::setReadOnly( readOnly ); 335 IncidenceBase::setReadOnly( readOnly );
336 if ( mRecurrence ) 336 if ( mRecurrence )
337 mRecurrence->setRecurReadOnly( readOnly); 337 mRecurrence->setRecurReadOnly( readOnly);
338} 338}
339void Incidence::setLastModifiedSubInvalid() 339void Incidence::setLastModifiedSubInvalid()
340{ 340{
341 mLastModifiedSub = QDateTime(); 341 mLastModifiedSub = QDateTime();
342 if ( mRelatedTo ) 342 if ( mRelatedTo )
343 mRelatedTo->setLastModifiedSubInvalid(); 343 mRelatedTo->setLastModifiedSubInvalid();
344} 344}
345QString Incidence::lastModifiedSubSortKey() const 345QString Incidence::lastModifiedSubSortKey() const
346{ 346{
347 if ( mLastModifiedSubSortKey.isEmpty() ) 347 if ( mLastModifiedSubSortKey.isEmpty() )
348 return lastModifiedSortKey(); 348 return lastModifiedSortKey();
349 return mLastModifiedSubSortKey; 349 return mLastModifiedSubSortKey;
350} 350}
351QDateTime Incidence::lastModifiedSub() 351QDateTime Incidence::lastModifiedSub()
352{ 352{
353 if ( !mRelations.count() ) 353 if ( !mRelations.count() )
354 return lastModified(); 354 return lastModified();
355 if ( mLastModifiedSub.isValid() ) 355 if ( mLastModifiedSub.isValid() )
356 return mLastModifiedSub; 356 return mLastModifiedSub;
357 mLastModifiedSub = lastModified(); 357 mLastModifiedSub = lastModified();
358 Incidence * inc; 358 Incidence * inc;
359 QPtrList<Incidence> Relations = relations(); 359 QPtrList<Incidence> Relations = relations();
360 for (inc=Relations.first();inc;inc=Relations.next()) { 360 for (inc=Relations.first();inc;inc=Relations.next()) {
361 if ( inc->lastModifiedSub() > mLastModifiedSub ) 361 if ( inc->lastModifiedSub() > mLastModifiedSub )
362 mLastModifiedSub = inc->lastModifiedSub(); 362 mLastModifiedSub = inc->lastModifiedSub();
363 } 363 }
364 mLastModifiedSubSortKey.sprintf("%04d%02d%02d%02d%02d%02d", 364 mLastModifiedSubSortKey.sprintf("%04d%02d%02d%02d%02d%02d",
365 mLastModifiedSub.date().year(), 365 mLastModifiedSub.date().year(),
366 mLastModifiedSub.date().month(), 366 mLastModifiedSub.date().month(),
367 mLastModifiedSub.date().day(), 367 mLastModifiedSub.date().day(),
368 mLastModifiedSub.time().hour(), 368 mLastModifiedSub.time().hour(),
369 mLastModifiedSub.time().minute(), 369 mLastModifiedSub.time().minute(),
370 mLastModifiedSub.time().second() ); 370 mLastModifiedSub.time().second() );
371 return mLastModifiedSub; 371 return mLastModifiedSub;
372} 372}
373void Incidence::setCreated(QDateTime created) 373void Incidence::setCreated(QDateTime created)
374{ 374{
375 if (mReadOnly) return; 375 if (mReadOnly) return;
376 mCreated = getEvenTime(created); 376 mCreated = getEvenTime(created);
377} 377}
378 378
379QDateTime Incidence::created() const 379QDateTime Incidence::created() const
380{ 380{
381 return mCreated; 381 return mCreated;
382} 382}
383 383
384void Incidence::setRevision(int rev) 384void Incidence::setRevision(int rev)
385{ 385{
386 if (mReadOnly) return; 386 if (mReadOnly) return;
387 mRevision = rev; 387 mRevision = rev;
388 388
389 updated(); 389 updated();
390} 390}
391 391
392int Incidence::revision() const 392int Incidence::revision() const
393{ 393{
394 return mRevision; 394 return mRevision;
395} 395}
396 396
397void Incidence::setDtStart(const QDateTime &dtStart) 397void Incidence::setDtStart(const QDateTime &dtStart)
398{ 398{
399 399
400 QDateTime dt = getEvenTime(dtStart); 400 QDateTime dt = getEvenTime(dtStart);
401 401
402 if ( mRecurrence ) 402 if ( mRecurrence )
403 mRecurrence->setRecurStart( dt); 403 mRecurrence->setRecurStart( dt);
404 IncidenceBase::setDtStart( dt ); 404 IncidenceBase::setDtStart( dt );
405} 405}
406 406
407void Incidence::setDescription(const QString &description) 407void Incidence::setDescription(const QString &description)
408{ 408{
409 if (mReadOnly) return; 409 if (mReadOnly) return;
410 mDescription = description; 410 mDescription = description;
411 updated(); 411 updated();
412} 412}
413 413
414QString Incidence::description() const 414QString Incidence::description() const
415{ 415{
416 return mDescription; 416 return mDescription;
417} 417}
418 418
419 419
420void Incidence::setSummary(const QString &summary) 420void Incidence::setSummary(const QString &summary)
421{ 421{
422 if (mReadOnly) return; 422 if (mReadOnly) return;
423 mSummary = summary; 423 mSummary = summary;
424 updated(); 424 updated();
425} 425}
426 426
427QString Incidence::summary() const 427QString Incidence::summary() const
428{ 428{
429 return mSummary; 429 return mSummary;
430} 430}
431void Incidence::checkCategories() 431void Incidence::checkCategories()
432{ 432{
433 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); 433 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday"));
434 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); 434 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday"));
435 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); 435 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary"));
436} 436}
437 437
438void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false 438void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false
439{ 439{
440 if (mReadOnly) return; 440 if (mReadOnly) return;
441 int i; 441 int i;
442 for( i = 0; i < categories.count(); ++i ) { 442 for( i = 0; i < categories.count(); ++i ) {
443 if ( !mCategories.contains (categories[i])) 443 if ( !mCategories.contains (categories[i]))
444 mCategories.append( categories[i] ); 444 mCategories.append( categories[i] );
445 } 445 }
446 checkCategories(); 446 checkCategories();
447 updated(); 447 updated();
448 if ( addToRelations ) { 448 if ( addToRelations ) {
449 Incidence * inc; 449 Incidence * inc;
450 QPtrList<Incidence> Relations = relations(); 450 QPtrList<Incidence> Relations = relations();
451 for (inc=Relations.first();inc;inc=Relations.next()) { 451 for (inc=Relations.first();inc;inc=Relations.next()) {
452 inc->addCategories( categories, true ); 452 inc->addCategories( categories, true );
453 } 453 }
454 } 454 }
455} 455}
456 456
457void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false 457void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false
458{ 458{
459 if (mReadOnly) return; 459 if (mReadOnly) return;
460 mCategories = categories; 460 mCategories = categories;
461 checkCategories(); 461 checkCategories();
462 updated(); 462 updated();
463 if ( setForRelations ) { 463 if ( setForRelations ) {
464 Incidence * inc; 464 Incidence * inc;
465 QPtrList<Incidence> Relations = relations(); 465 QPtrList<Incidence> Relations = relations();
466 for (inc=Relations.first();inc;inc=Relations.next()) { 466 for (inc=Relations.first();inc;inc=Relations.next()) {
467 inc->setCategories( categories, true ); 467 inc->setCategories( categories, true );
468 } 468 }
469 } 469 }
470} 470}
471 471
472// TODO: remove setCategories(QString) function 472// TODO: remove setCategories(QString) function
473void Incidence::setCategories(const QString &catStr) 473void Incidence::setCategories(const QString &catStr)
474{ 474{
475 if (mReadOnly) return; 475 if (mReadOnly) return;
476 mCategories.clear(); 476 mCategories.clear();
477 477
478 if (catStr.isEmpty()) return; 478 if (catStr.isEmpty()) return;
479 479
480 mCategories = QStringList::split(",",catStr); 480 mCategories = QStringList::split(",",catStr);
481 481
482 QStringList::Iterator it; 482 QStringList::Iterator it;
483 for(it = mCategories.begin();it != mCategories.end(); ++it) { 483 for(it = mCategories.begin();it != mCategories.end(); ++it) {
484 *it = (*it).stripWhiteSpace(); 484 *it = (*it).stripWhiteSpace();
485 } 485 }
486 checkCategories(); 486 checkCategories();
487 updated(); 487 updated();
488} 488}
489// using this makes filtering 3 times faster 489// using this makes filtering 3 times faster
490QStringList* Incidence::categoriesP() 490QStringList* Incidence::categoriesP()
491{ 491{
492 return &mCategories; 492 return &mCategories;
493} 493}
494 494
495QStringList Incidence::categories() const 495QStringList Incidence::categories() const
496{ 496{
497 return mCategories; 497 return mCategories;
498} 498}
499 499
500QString Incidence::categoriesStr() 500QString Incidence::categoriesStr()
501{ 501{
502 return mCategories.join(","); 502 return mCategories.join(",");
503} 503}
504QString Incidence::categoriesStrWithSpace() 504QString Incidence::categoriesStrWithSpace()
505{ 505{
506 return mCategories.join(", "); 506 return mCategories.join(", ");
507} 507}
508 508
509void Incidence::setRelatedToUid(const QString &relatedToUid) 509void Incidence::setRelatedToUid(const QString &relatedToUid)
510{ 510{
511 if (mReadOnly) return; 511 if (mReadOnly) return;
512 mRelatedToUid = relatedToUid; 512 mRelatedToUid = relatedToUid;
513} 513}
514void Incidence::clearRelations() 514void Incidence::clearRelations()
515{ 515{
516 mRelatedTo = 0; 516 mRelatedTo = 0;
517 mRelations.clear(); 517 mRelations.clear();
518} 518}
519QString Incidence::relatedToUid() const 519QString Incidence::relatedToUid() const
520{ 520{
521 return mRelatedToUid; 521 return mRelatedToUid;
522} 522}
523void Incidence::resetRelatedTo()
524{
525 QString store = mRelatedToUid;
526 setRelatedTo( 0 );
527 mRelatedToUid = store;
528}
523 529
524void Incidence::setRelatedTo(Incidence *relatedTo) 530void Incidence::setRelatedTo(Incidence *relatedTo)
525{ 531{
526 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 532 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
527 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 533 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
528 if (mReadOnly || mRelatedTo == relatedTo) return; 534 if (mReadOnly || mRelatedTo == relatedTo) return;
529 if(mRelatedTo) { 535 if(mRelatedTo) {
530 // updated(); 536 // updated();
531 mRelatedTo->removeRelation(this); 537 mRelatedTo->removeRelation(this);
532 } 538 }
533 mRelatedTo = relatedTo; 539 mRelatedTo = relatedTo;
534 if (mRelatedTo) { 540 if (mRelatedTo) {
535 mRelatedTo->addRelation(this); 541 mRelatedTo->addRelation(this);
536 mRelatedToUid = mRelatedTo->uid(); 542 mRelatedToUid = mRelatedTo->uid();
537 } else { 543 } else {
538 mRelatedToUid = ""; 544 mRelatedToUid = "";
539 } 545 }
540} 546}
541 547
542Incidence *Incidence::relatedTo() const 548Incidence *Incidence::relatedTo() const
543{ 549{
544 return mRelatedTo; 550 return mRelatedTo;
545} 551}
546 552
547QPtrList<Incidence> Incidence::relations() const 553QPtrList<Incidence> Incidence::relations() const
548{ 554{
549 return mRelations; 555 return mRelations;
550} 556}
551 557
552void Incidence::addRelationsToList(QPtrList<Incidence> *rel) 558void Incidence::addRelationsToList(QPtrList<Incidence> *rel)
553{ 559{
554 Incidence* inc; 560 Incidence* inc;
555 QPtrList<Incidence> Relations = relations(); 561 QPtrList<Incidence> Relations = relations();
556 for (inc=Relations.first();inc;inc=Relations.next()) { 562 for (inc=Relations.first();inc;inc=Relations.next()) {
557 inc->addRelationsToList( rel ); 563 inc->addRelationsToList( rel );
558 } 564 }
559 if ( rel->findRef( this ) == -1 ) 565 if ( rel->findRef( this ) == -1 )
560 rel->append( this ); 566 rel->append( this );
561} 567}
562 568
563void Incidence::addRelation(Incidence *event) 569void Incidence::addRelation(Incidence *event)
564{ 570{
565 setLastModifiedSubInvalid(); 571 setLastModifiedSubInvalid();
566 if( mRelations.findRef( event ) == -1 ) { 572 if( mRelations.findRef( event ) == -1 ) {
567 mRelations.append(event); 573 mRelations.append(event);
568 //updated(); 574 //updated();
569 } 575 }
570} 576}
571 577
572void Incidence::removeRelation(Incidence *event) 578void Incidence::removeRelation(Incidence *event)
573{ 579{
574 setLastModifiedSubInvalid(); 580 setLastModifiedSubInvalid();
575 mRelations.removeRef(event); 581 mRelations.removeRef(event);
576// if (event->getRelatedTo() == this) event->setRelatedTo(0); 582// if (event->getRelatedTo() == this) event->setRelatedTo(0);
577} 583}
578 584
579bool Incidence::recursOn(const QDate &qd) const 585bool Incidence::recursOn(const QDate &qd) const
580{ 586{
581 if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true; 587 if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true;
582 else return false; 588 else return false;
583} 589}
584 590
585void Incidence::setExDates(const DateList &exDates) 591void Incidence::setExDates(const DateList &exDates)
586{ 592{
587 if (mReadOnly) return; 593 if (mReadOnly) return;
588 mExDates = exDates; 594 mExDates = exDates;
589 recurrence()->setRecurExDatesCount(mExDates.count()); 595 recurrence()->setRecurExDatesCount(mExDates.count());
590 596
591 updated(); 597 updated();
592} 598}
593 599
594void Incidence::addExDate(const QDate &date) 600void Incidence::addExDate(const QDate &date)
595{ 601{
596 if (mReadOnly) return; 602 if (mReadOnly) return;
597 mExDates.append(date); 603 mExDates.append(date);
598 604
599 recurrence()->setRecurExDatesCount(mExDates.count()); 605 recurrence()->setRecurExDatesCount(mExDates.count());
600 606
601 updated(); 607 updated();
602} 608}
603 609
604DateList Incidence::exDates() const 610DateList Incidence::exDates() const
605{ 611{
606 return mExDates; 612 return mExDates;
607} 613}
608 614
609bool Incidence::isException(const QDate &date) const 615bool Incidence::isException(const QDate &date) const
610{ 616{
611 DateList::ConstIterator it; 617 DateList::ConstIterator it;
612 for( it = mExDates.begin(); it != mExDates.end(); ++it ) { 618 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
613 if ( (*it) == date ) { 619 if ( (*it) == date ) {
614 return true; 620 return true;
615 } 621 }
616 } 622 }
617 623
618 return false; 624 return false;
619} 625}
620 626
621void Incidence::addAttachment(Attachment *attachment) 627void Incidence::addAttachment(Attachment *attachment)
622{ 628{
623 if (mReadOnly || !attachment) return; 629 if (mReadOnly || !attachment) return;
624 mAttachments.append(attachment); 630 mAttachments.append(attachment);
625 updated(); 631 updated();
626} 632}
627 633
628void Incidence::deleteAttachment(Attachment *attachment) 634void Incidence::deleteAttachment(Attachment *attachment)
629{ 635{
630 mAttachments.removeRef(attachment); 636 mAttachments.removeRef(attachment);
631} 637}
632 638
633void Incidence::deleteAttachments(const QString& mime) 639void Incidence::deleteAttachments(const QString& mime)
634{ 640{
635 Attachment *at = mAttachments.first(); 641 Attachment *at = mAttachments.first();
636 while (at) { 642 while (at) {
637 if (at->mimeType() == mime) 643 if (at->mimeType() == mime)
638 mAttachments.remove(); 644 mAttachments.remove();
639 else 645 else
640 at = mAttachments.next(); 646 at = mAttachments.next();
641 } 647 }
642} 648}
643 649
644QPtrList<Attachment> Incidence::attachments() const 650QPtrList<Attachment> Incidence::attachments() const
645{ 651{
646 return mAttachments; 652 return mAttachments;
647} 653}
648 654
649QPtrList<Attachment> Incidence::attachments(const QString& mime) const 655QPtrList<Attachment> Incidence::attachments(const QString& mime) const
650{ 656{
651 QPtrList<Attachment> attachments; 657 QPtrList<Attachment> attachments;
652 QPtrListIterator<Attachment> it( mAttachments ); 658 QPtrListIterator<Attachment> it( mAttachments );
653 Attachment *at; 659 Attachment *at;
654 while ( (at = it.current()) ) { 660 while ( (at = it.current()) ) {
655 if (at->mimeType() == mime) 661 if (at->mimeType() == mime)
656 attachments.append(at); 662 attachments.append(at);
657 ++it; 663 ++it;
658 } 664 }
659 665
660 return attachments; 666 return attachments;
661} 667}
662 668
663void Incidence::setResources(const QStringList &resources) 669void Incidence::setResources(const QStringList &resources)
664{ 670{
665 if (mReadOnly) return; 671 if (mReadOnly) return;
666 mResources = resources; 672 mResources = resources;
667 updated(); 673 updated();
668} 674}
669 675
670QStringList Incidence::resources() const 676QStringList Incidence::resources() const
671{ 677{
672 return mResources; 678 return mResources;
673} 679}
674 680
675 681
676void Incidence::setPriority(int priority) 682void Incidence::setPriority(int priority)
677{ 683{
678 if (mReadOnly) return; 684 if (mReadOnly) return;
679 mPriority = priority; 685 mPriority = priority;
680 updated(); 686 updated();
681} 687}
682 688
683int Incidence::priority() const 689int Incidence::priority() const
684{ 690{
685 return mPriority; 691 return mPriority;
686} 692}
687 693
688void Incidence::setSecrecy(int sec) 694void Incidence::setSecrecy(int sec)
689{ 695{
690 if (mReadOnly) return; 696 if (mReadOnly) return;
691 mSecrecy = sec; 697 mSecrecy = sec;
692 updated(); 698 updated();
693} 699}
694 700
695int Incidence::secrecy() const 701int Incidence::secrecy() const
696{ 702{
697 return mSecrecy; 703 return mSecrecy;
698} 704}
699 705
700QString Incidence::secrecyStr() const 706QString Incidence::secrecyStr() const
701{ 707{
702 return secrecyName(mSecrecy); 708 return secrecyName(mSecrecy);
703} 709}
704 710
705QString Incidence::secrecyName(int secrecy) 711QString Incidence::secrecyName(int secrecy)
706{ 712{
707 switch (secrecy) { 713 switch (secrecy) {
708 case SecrecyPublic: 714 case SecrecyPublic:
709 return i18n("Public"); 715 return i18n("Public");
710 break; 716 break;
711 case SecrecyPrivate: 717 case SecrecyPrivate:
712 return i18n("Private"); 718 return i18n("Private");
713 break; 719 break;
714 case SecrecyConfidential: 720 case SecrecyConfidential:
715 return i18n("Confidential"); 721 return i18n("Confidential");
716 break; 722 break;
717 default: 723 default:
718 return i18n("Undefined"); 724 return i18n("Undefined");
719 break; 725 break;
720 } 726 }
721} 727}
722 728
723QStringList Incidence::secrecyList() 729QStringList Incidence::secrecyList()
724{ 730{
725 QStringList list; 731 QStringList list;
726 list << secrecyName(SecrecyPublic); 732 list << secrecyName(SecrecyPublic);
727 list << secrecyName(SecrecyPrivate); 733 list << secrecyName(SecrecyPrivate);
728 list << secrecyName(SecrecyConfidential); 734 list << secrecyName(SecrecyConfidential);
729 735
730 return list; 736 return list;
731} 737}
732 738
733 739
734QPtrList<Alarm> Incidence::alarms() const 740QPtrList<Alarm> Incidence::alarms() const
735{ 741{
736 return mAlarms; 742 return mAlarms;
737} 743}
738 744
739Alarm* Incidence::newAlarm() 745Alarm* Incidence::newAlarm()
740{ 746{
741 Alarm* alarm = new Alarm(this); 747 Alarm* alarm = new Alarm(this);
742 mAlarms.append(alarm); 748 mAlarms.append(alarm);
743// updated(); 749// updated();
744 return alarm; 750 return alarm;
745} 751}
746 752
747void Incidence::addAlarm(Alarm *alarm) 753void Incidence::addAlarm(Alarm *alarm)
748{ 754{
749 mAlarms.append(alarm); 755 mAlarms.append(alarm);
750 updated(); 756 updated();
751} 757}
752 758
753void Incidence::removeAlarm(Alarm *alarm) 759void Incidence::removeAlarm(Alarm *alarm)
754{ 760{
755 mAlarms.removeRef(alarm); 761 mAlarms.removeRef(alarm);
756 updated(); 762 updated();
757} 763}
758 764
759void Incidence::clearAlarms() 765void Incidence::clearAlarms()
760{ 766{
761 mAlarms.clear(); 767 mAlarms.clear();
762 updated(); 768 updated();
763} 769}
764 770
765bool Incidence::isAlarmEnabled() const 771bool Incidence::isAlarmEnabled() const
766{ 772{
767 Alarm* alarm; 773 Alarm* alarm;
768 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 774 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
769 if (alarm->enabled()) 775 if (alarm->enabled())
770 return true; 776 return true;
771 } 777 }
772 return false; 778 return false;
773} 779}
774#include <stdlib.h> 780#include <stdlib.h>
775Recurrence *Incidence::recurrence() 781Recurrence *Incidence::recurrence()
776{ 782{
777 if ( ! mRecurrence ) { 783 if ( ! mRecurrence ) {
778 mRecurrence = new Recurrence(this); 784 mRecurrence = new Recurrence(this);
779 mRecurrence->setRecurStart( dtStart() ); 785 mRecurrence->setRecurStart( dtStart() );
780 mRecurrence->setRecurReadOnly( isReadOnly()); 786 mRecurrence->setRecurReadOnly( isReadOnly());
781 //qDebug("creating new recurence "); 787 //qDebug("creating new recurence ");
782 //abort(); 788 //abort();
783 } 789 }
784 return mRecurrence; 790 return mRecurrence;
785} 791}
786void Incidence::setRecurrence( Recurrence * r) 792void Incidence::setRecurrence( Recurrence * r)
787{ 793{
788 if ( mRecurrence ) 794 if ( mRecurrence )
789 delete mRecurrence; 795 delete mRecurrence;
790 mRecurrence = r; 796 mRecurrence = r;
791} 797}
792 798
793void Incidence::setLocation(const QString &location) 799void Incidence::setLocation(const QString &location)
794{ 800{
795 if (mReadOnly) return; 801 if (mReadOnly) return;
796 mLocation = location; 802 mLocation = location;
797 updated(); 803 updated();
798} 804}
799 805
800QString Incidence::location() const 806QString Incidence::location() const
801{ 807{
802 return mLocation; 808 return mLocation;
803} 809}
804QString Incidence::recurrenceText() const 810QString Incidence::recurrenceText() const
805{ 811{
806 if ( mRecurrence ) return mRecurrence->recurrenceText(); 812 if ( mRecurrence ) return mRecurrence->recurrenceText();
807 return i18n("No"); 813 return i18n("No");
808} 814}
809 815
810ushort Incidence::doesRecur() const 816ushort Incidence::doesRecur() const
811{ 817{
812 if ( mRecurrence ) return mRecurrence->doesRecur(); 818 if ( mRecurrence ) return mRecurrence->doesRecur();
813 else return Recurrence::rNone; 819 else return Recurrence::rNone;
814} 820}
815 821
816QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const 822QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const
817{ 823{
818 QDateTime incidenceStart = dt; 824 QDateTime incidenceStart = dt;
819 *ok = false; 825 *ok = false;
820 if ( doesRecur() ) { 826 if ( doesRecur() ) {
821 bool last; 827 bool last;
822 mRecurrence->getPreviousDateTime( incidenceStart , &last ); 828 mRecurrence->getPreviousDateTime( incidenceStart , &last );
823 int count = 0; 829 int count = 0;
824 if ( !last ) { 830 if ( !last ) {
825 while ( !last ) { 831 while ( !last ) {
826 ++count; 832 ++count;
827 incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); 833 incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last );
828 if ( recursOn( incidenceStart.date() ) ) { 834 if ( recursOn( incidenceStart.date() ) ) {
829 last = true; // exit while llop 835 last = true; // exit while llop
830 } else { 836 } else {
831 if ( last ) { // no alarm on last recurrence 837 if ( last ) { // no alarm on last recurrence
832 return QDateTime (); 838 return QDateTime ();
833 } 839 }
834 int year = incidenceStart.date().year(); 840 int year = incidenceStart.date().year();
835 // workaround for bug in recurrence 841 // workaround for bug in recurrence
836 if ( count == 100 || year < 1000 || year > 5000 ) { 842 if ( count == 100 || year < 1000 || year > 5000 ) {
837 return QDateTime (); 843 return QDateTime ();
838 } 844 }
839 incidenceStart = incidenceStart.addSecs( 1 ); 845 incidenceStart = incidenceStart.addSecs( 1 );
840 } 846 }
841 } 847 }
842 } else { 848 } else {
843 return QDateTime (); 849 return QDateTime ();
844 } 850 }
845 } else { 851 } else {
846 if ( hasStartDate () ) { 852 if ( hasStartDate () ) {
847 incidenceStart = dtStart(); 853 incidenceStart = dtStart();
848 } 854 }
849 if ( typeID() == todoID ) { 855 if ( typeID() == todoID ) {
850 if ( ((Todo*)this)->hasDueDate() ) 856 if ( ((Todo*)this)->hasDueDate() )
851 incidenceStart = ((Todo*)this)->dtDue(); 857 incidenceStart = ((Todo*)this)->dtDue();
852 } 858 }
853 } 859 }
854 if ( incidenceStart > dt ) 860 if ( incidenceStart > dt )
855 *ok = true; 861 *ok = true;
856 return incidenceStart; 862 return incidenceStart;
857} 863}
858QDateTime Incidence::dtStart() const 864QDateTime Incidence::dtStart() const
859{ 865{
860 if ( doesRecur() ) { 866 if ( doesRecur() ) {
861 if ( typeID() == todoID ) { 867 if ( typeID() == todoID ) {
862 ((Todo*)this)->checkSetCompletedFalse(); 868 ((Todo*)this)->checkSetCompletedFalse();
863 } 869 }
864 } 870 }
865 return mDtStart; 871 return mDtStart;
866} 872}
diff --git a/libkcal/incidence.h b/libkcal/incidence.h
index dc49640..f89942f 100644
--- a/libkcal/incidence.h
+++ b/libkcal/incidence.h
@@ -1,326 +1,327 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20#ifndef INCIDENCE_H 20#ifndef INCIDENCE_H
21#define INCIDENCE_H 21#define INCIDENCE_H
22// 22//
23// Incidence - base class of calendaring components 23// Incidence - base class of calendaring components
24// 24//
25 25
26#include <qdatetime.h> 26#include <qdatetime.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qvaluelist.h> 28#include <qvaluelist.h>
29 29
30#include "recurrence.h" 30#include "recurrence.h"
31#include "alarm.h" 31#include "alarm.h"
32#include "attachment.h" 32#include "attachment.h"
33#include "listbase.h" 33#include "listbase.h"
34#include "incidencebase.h" 34#include "incidencebase.h"
35 35
36namespace KCal { 36namespace KCal {
37 37
38class Event; 38class Event;
39class Todo; 39class Todo;
40class Journal; 40class Journal;
41 41
42/** 42/**
43 This class provides the base class common to all calendar components. 43 This class provides the base class common to all calendar components.
44*/ 44*/
45class Incidence : public IncidenceBase 45class Incidence : public IncidenceBase
46{ 46{
47 public: 47 public:
48 /** 48 /**
49 This class provides the interface for a visitor of calendar components. It 49 This class provides the interface for a visitor of calendar components. It
50 serves as base class for concrete visitors, which implement certain actions on 50 serves as base class for concrete visitors, which implement certain actions on
51 calendar components. It allows to add functions, which operate on the concrete 51 calendar components. It allows to add functions, which operate on the concrete
52 types of calendar components, without changing the calendar component classes. 52 types of calendar components, without changing the calendar component classes.
53 */ 53 */
54 class Visitor 54 class Visitor
55 { 55 {
56 public: 56 public:
57 /** Destruct Incidence::Visitor */ 57 /** Destruct Incidence::Visitor */
58 virtual ~Visitor() {} 58 virtual ~Visitor() {}
59 59
60 /** 60 /**
61 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions 61 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
62 on an Event object. 62 on an Event object.
63 */ 63 */
64 virtual bool visit(Event *) { return false; } 64 virtual bool visit(Event *) { return false; }
65 /** 65 /**
66 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions 66 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
67 on an Todo object. 67 on an Todo object.
68 */ 68 */
69 virtual bool visit(Todo *) { return false; } 69 virtual bool visit(Todo *) { return false; }
70 /** 70 /**
71 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions 71 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
72 on an Journal object. 72 on an Journal object.
73 */ 73 */
74 virtual bool visit(Journal *) { return false; } 74 virtual bool visit(Journal *) { return false; }
75 75
76 protected: 76 protected:
77 /** Constructor is protected to prevent direct creation of visitor base class. */ 77 /** Constructor is protected to prevent direct creation of visitor base class. */
78 Visitor() {} 78 Visitor() {}
79 }; 79 };
80 80
81 /** 81 /**
82 This class implements a visitor for adding an Incidence to a resource 82 This class implements a visitor for adding an Incidence to a resource
83 supporting addEvent(), addTodo() and addJournal() calls. 83 supporting addEvent(), addTodo() and addJournal() calls.
84 */ 84 */
85 template<class T> 85 template<class T>
86 class AddVisitor : public Visitor 86 class AddVisitor : public Visitor
87 { 87 {
88 public: 88 public:
89 AddVisitor( T *r ) : mResource( r ) {} 89 AddVisitor( T *r ) : mResource( r ) {}
90 bool visit( Event *e ) { return mResource->addEvent( e ); } 90 bool visit( Event *e ) { return mResource->addEvent( e ); }
91 bool visit( Todo *t ) { return mResource->addTodo( t ); } 91 bool visit( Todo *t ) { return mResource->addTodo( t ); }
92 bool visit( Journal *j ) { return mResource->addJournal( j ); } 92 bool visit( Journal *j ) { return mResource->addJournal( j ); }
93 93
94 private: 94 private:
95 T *mResource; 95 T *mResource;
96 }; 96 };
97 97
98 /** enumeration for describing an event's secrecy. */ 98 /** enumeration for describing an event's secrecy. */
99 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; 99 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 };
100 typedef ListBase<Incidence> List; 100 typedef ListBase<Incidence> List;
101 Incidence(); 101 Incidence();
102 Incidence(const Incidence &); 102 Incidence(const Incidence &);
103 ~Incidence(); 103 ~Incidence();
104 104
105 /** 105 /**
106 Accept IncidenceVisitor. A class taking part in the visitor mechanism has to 106 Accept IncidenceVisitor. A class taking part in the visitor mechanism has to
107 provide this implementation: 107 provide this implementation:
108 <pre> 108 <pre>
109 bool accept(Visitor &v) { return v.visit(this); } 109 bool accept(Visitor &v) { return v.visit(this); }
110 </pre> 110 </pre>
111 */ 111 */
112 virtual bool accept(Visitor &) { return false; } 112 virtual bool accept(Visitor &) { return false; }
113 113
114 virtual Incidence *clone() = 0; 114 virtual Incidence *clone() = 0;
115 virtual void cloneRelations( Incidence * ); 115 virtual void cloneRelations( Incidence * );
116 void addRelationsToList(QPtrList<Incidence> *rel); 116 void addRelationsToList(QPtrList<Incidence> *rel);
117 void clearRelations(); 117 void clearRelations();
118 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; 118 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0;
119 void setReadOnly( bool ); 119 void setReadOnly( bool );
120 120
121 /** 121 /**
122 Recreate event. The event is made a new unique event, but already stored 122 Recreate event. The event is made a new unique event, but already stored
123 event information is preserved. Sets uniquie id, creation date, last 123 event information is preserved. Sets uniquie id, creation date, last
124 modification date and revision number. 124 modification date and revision number.
125 */ 125 */
126 void recreate(); 126 void recreate();
127 Incidence* recreateCloneException(QDate); 127 Incidence* recreateCloneException(QDate);
128 128
129 /** set creation date */ 129 /** set creation date */
130 void setCreated(QDateTime); 130 void setCreated(QDateTime);
131 /** return time and date of creation. */ 131 /** return time and date of creation. */
132 QDateTime created() const; 132 QDateTime created() const;
133 133
134 /** set the number of revisions this event has seen */ 134 /** set the number of revisions this event has seen */
135 void setRevision(int rev); 135 void setRevision(int rev);
136 /** return the number of revisions this event has seen */ 136 /** return the number of revisions this event has seen */
137 int revision() const; 137 int revision() const;
138 138
139 /** Set starting date/time. */ 139 /** Set starting date/time. */
140 virtual void setDtStart(const QDateTime &dtStart); 140 virtual void setDtStart(const QDateTime &dtStart);
141 /** Return the incidence's ending date/time as a QDateTime. */ 141 /** Return the incidence's ending date/time as a QDateTime. */
142 virtual QDateTime dtEnd() const { return QDateTime(); } 142 virtual QDateTime dtEnd() const { return QDateTime(); }
143 143
144 /** sets the event's lengthy description. */ 144 /** sets the event's lengthy description. */
145 void setDescription(const QString &description); 145 void setDescription(const QString &description);
146 /** returns a reference to the event's description. */ 146 /** returns a reference to the event's description. */
147 QString description() const; 147 QString description() const;
148 148
149 /** sets the event's short summary. */ 149 /** sets the event's short summary. */
150 void setSummary(const QString &summary); 150 void setSummary(const QString &summary);
151 /** returns a reference to the event's summary. */ 151 /** returns a reference to the event's summary. */
152 QString summary() const; 152 QString summary() const;
153 153
154 /** set event's applicable categories */ 154 /** set event's applicable categories */
155 void setCategories(const QStringList &categories, bool setForRelations = false); 155 void setCategories(const QStringList &categories, bool setForRelations = false);
156 void addCategories(const QStringList &categories, bool addToRelations = false); 156 void addCategories(const QStringList &categories, bool addToRelations = false);
157 /** set event's categories based on a comma delimited string */ 157 /** set event's categories based on a comma delimited string */
158 void setCategories(const QString &catStr); 158 void setCategories(const QString &catStr);
159 /** return categories in a list */ 159 /** return categories in a list */
160 QStringList categories() const; 160 QStringList categories() const;
161 QStringList* categoriesP(); 161 QStringList* categoriesP();
162 /** return categories as a comma separated string */ 162 /** return categories as a comma separated string */
163 QString categoriesStr(); 163 QString categoriesStr();
164 QString categoriesStrWithSpace(); 164 QString categoriesStrWithSpace();
165 165
166 /** point at some other event to which the event relates. This function should 166 /** point at some other event to which the event relates. This function should
167 * only be used when constructing a calendar before the related Event 167 * only be used when constructing a calendar before the related Event
168 * exists. */ 168 * exists. */
169 void setRelatedToUid(const QString &); 169 void setRelatedToUid(const QString &);
170 /** what event does this one relate to? This function should 170 /** what event does this one relate to? This function should
171 * only be used when constructing a calendar before the related Event 171 * only be used when constructing a calendar before the related Event
172 * exists. */ 172 * exists. */
173 QString relatedToUid() const; 173 QString relatedToUid() const;
174 /** point at some other event to which the event relates */ 174 /** point at some other event to which the event relates */
175 void setRelatedTo(Incidence *relatedTo); 175 void setRelatedTo(Incidence *relatedTo);
176 void resetRelatedTo();
176 /** what event does this one relate to? */ 177 /** what event does this one relate to? */
177 Incidence *relatedTo() const; 178 Incidence *relatedTo() const;
178 /** All events that are related to this event */ 179 /** All events that are related to this event */
179 QPtrList<Incidence> relations() const; 180 QPtrList<Incidence> relations() const;
180 /** Add an event which is related to this event */ 181 /** Add an event which is related to this event */
181 void addRelation(Incidence *); 182 void addRelation(Incidence *);
182 /** Remove event that is related to this event */ 183 /** Remove event that is related to this event */
183 void removeRelation(Incidence *); 184 void removeRelation(Incidence *);
184 185
185 /** returns the list of dates which are exceptions to the recurrence rule */ 186 /** returns the list of dates which are exceptions to the recurrence rule */
186 DateList exDates() const; 187 DateList exDates() const;
187 /** sets the list of dates which are exceptions to the recurrence rule */ 188 /** sets the list of dates which are exceptions to the recurrence rule */
188 void setExDates(const DateList &_exDates); 189 void setExDates(const DateList &_exDates);
189 void setExDates(const char *dates); 190 void setExDates(const char *dates);
190 /** Add a date to the list of exceptions of the recurrence rule. */ 191 /** Add a date to the list of exceptions of the recurrence rule. */
191 void addExDate(const QDate &date); 192 void addExDate(const QDate &date);
192 193
193 /** returns true if there is an exception for this date in the recurrence 194 /** returns true if there is an exception for this date in the recurrence
194 rule set, or false otherwise. */ 195 rule set, or false otherwise. */
195 bool isException(const QDate &qd) const; 196 bool isException(const QDate &qd) const;
196 197
197 /** add attachment to this event */ 198 /** add attachment to this event */
198 void addAttachment(Attachment *attachment); 199 void addAttachment(Attachment *attachment);
199 /** remove and delete a specific attachment */ 200 /** remove and delete a specific attachment */
200 void deleteAttachment(Attachment *attachment); 201 void deleteAttachment(Attachment *attachment);
201 /** remove and delete all attachments with this mime type */ 202 /** remove and delete all attachments with this mime type */
202 void deleteAttachments(const QString& mime); 203 void deleteAttachments(const QString& mime);
203 /** return list of all associated attachments */ 204 /** return list of all associated attachments */
204 QPtrList<Attachment> attachments() const; 205 QPtrList<Attachment> attachments() const;
205 /** find a list of attachments with this mime type */ 206 /** find a list of attachments with this mime type */
206 QPtrList<Attachment> attachments(const QString& mime) const; 207 QPtrList<Attachment> attachments(const QString& mime) const;
207 208
208 /** sets the event's status the value specified. See the enumeration 209 /** sets the event's status the value specified. See the enumeration
209 * above for possible values. */ 210 * above for possible values. */
210 void setSecrecy(int); 211 void setSecrecy(int);
211 /** return the event's secrecy. */ 212 /** return the event's secrecy. */
212 int secrecy() const; 213 int secrecy() const;
213 /** return the event's secrecy in string format. */ 214 /** return the event's secrecy in string format. */
214 QString secrecyStr() const; 215 QString secrecyStr() const;
215 /** return list of all availbale secrecy classes */ 216 /** return list of all availbale secrecy classes */
216 static QStringList secrecyList(); 217 static QStringList secrecyList();
217 /** return human-readable name of secrecy class */ 218 /** return human-readable name of secrecy class */
218 static QString secrecyName(int); 219 static QString secrecyName(int);
219 220
220 /** returns TRUE if the date specified is one on which the event will 221 /** returns TRUE if the date specified is one on which the event will
221 * recur. */ 222 * recur. */
222 bool recursOn(const QDate &qd) const; 223 bool recursOn(const QDate &qd) const;
223 224
224 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): 225 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?):
225 226
226 /** set resources used, such as Office, Car, etc. */ 227 /** set resources used, such as Office, Car, etc. */
227 void setResources(const QStringList &resources); 228 void setResources(const QStringList &resources);
228 /** return list of current resources */ 229 /** return list of current resources */
229 QStringList resources() const; 230 QStringList resources() const;
230 231
231 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ 232 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */
232 void setPriority(int priority); 233 void setPriority(int priority);
233 /** get the event's priority */ 234 /** get the event's priority */
234 int priority() const; 235 int priority() const;
235 236
236 /** All alarms that are associated with this incidence */ 237 /** All alarms that are associated with this incidence */
237 QPtrList<Alarm> alarms() const; 238 QPtrList<Alarm> alarms() const;
238 /** Create a new alarm which is associated with this incidence */ 239 /** Create a new alarm which is associated with this incidence */
239 Alarm* newAlarm(); 240 Alarm* newAlarm();
240 /** Add an alarm which is associated with this incidence */ 241 /** Add an alarm which is associated with this incidence */
241 void addAlarm(Alarm*); 242 void addAlarm(Alarm*);
242 /** Remove an alarm that is associated with this incidence */ 243 /** Remove an alarm that is associated with this incidence */
243 void removeAlarm(Alarm*); 244 void removeAlarm(Alarm*);
244 /** Remove all alarms that are associated with this incidence */ 245 /** Remove all alarms that are associated with this incidence */
245 void clearAlarms(); 246 void clearAlarms();
246 /** return whether any alarm associated with this incidence is enabled */ 247 /** return whether any alarm associated with this incidence is enabled */
247 bool isAlarmEnabled() const; 248 bool isAlarmEnabled() const;
248 249
249 /** 250 /**
250 Return the recurrence rule associated with this incidence. If there is 251 Return the recurrence rule associated with this incidence. If there is
251 none, returns an appropriate (non-0) object. 252 none, returns an appropriate (non-0) object.
252 */ 253 */
253 Recurrence *recurrence(); 254 Recurrence *recurrence();
254 void setRecurrence(Recurrence * r); 255 void setRecurrence(Recurrence * r);
255 /** 256 /**
256 Forward to Recurrence::doesRecur(). 257 Forward to Recurrence::doesRecur().
257 */ 258 */
258 ushort doesRecur() const; 259 ushort doesRecur() const;
259 260
260 /** set the event's/todo's location. Do _not_ use it with journal */ 261 /** set the event's/todo's location. Do _not_ use it with journal */
261 void setLocation(const QString &location); 262 void setLocation(const QString &location);
262 /** return the event's/todo's location. Do _not_ use it with journal */ 263 /** return the event's/todo's location. Do _not_ use it with journal */
263 QString location() const; 264 QString location() const;
264 /** returns TRUE or FALSE depending on whether the todo has a start date */ 265 /** returns TRUE or FALSE depending on whether the todo has a start date */
265 bool hasStartDate() const; 266 bool hasStartDate() const;
266 /** sets the event's hasStartDate value. */ 267 /** sets the event's hasStartDate value. */
267 void setHasStartDate(bool f); 268 void setHasStartDate(bool f);
268 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; 269 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const;
269 bool cancelled() const; 270 bool cancelled() const;
270 void setCancelled( bool b ); 271 void setCancelled( bool b );
271 272
272 bool hasRecurrenceID() const; 273 bool hasRecurrenceID() const;
273 void setHasRecurrenceID( bool b ); 274 void setHasRecurrenceID( bool b );
274 275
275 void setRecurrenceID(QDateTime); 276 void setRecurrenceID(QDateTime);
276 QDateTime recurrenceID () const; 277 QDateTime recurrenceID () const;
277 QDateTime dtStart() const; 278 QDateTime dtStart() const;
278 bool isHoliday() const; 279 bool isHoliday() const;
279 bool isBirthday() const; 280 bool isBirthday() const;
280 bool isAnniversary() const; 281 bool isAnniversary() const;
281 QDateTime lastModifiedSub(); 282 QDateTime lastModifiedSub();
282 QString lastModifiedSubSortKey() const; 283 QString lastModifiedSubSortKey() const;
283 QString recurrenceText() const; 284 QString recurrenceText() const;
284 void setLastModifiedSubInvalid(); 285 void setLastModifiedSubInvalid();
285 286
286 virtual QString durationText(); 287 virtual QString durationText();
287 QString durationText4Time( int secs ); 288 QString durationText4Time( int secs );
288 Recurrence *mRecurrence; 289 Recurrence *mRecurrence;
289protected: 290protected:
290 QPtrList<Alarm> mAlarms; 291 QPtrList<Alarm> mAlarms;
291 QPtrList<Incidence> mRelations; 292 QPtrList<Incidence> mRelations;
292 QDateTime mRecurrenceID; 293 QDateTime mRecurrenceID;
293 bool mHasRecurrenceID; 294 bool mHasRecurrenceID;
294 private: 295 private:
295 void checkCategories(); 296 void checkCategories();
296 QString mLastModifiedSubSortKey; 297 QString mLastModifiedSubSortKey;
297 bool mHoliday, mBirthday, mAnniversary; 298 bool mHoliday, mBirthday, mAnniversary;
298 int mRevision; 299 int mRevision;
299 bool mCancelled; 300 bool mCancelled;
300 301
301 // base components of jounal, event and todo 302 // base components of jounal, event and todo
302 QDateTime mCreated; 303 QDateTime mCreated;
303 QDateTime mLastModifiedSub; 304 QDateTime mLastModifiedSub;
304 QString mDescription; 305 QString mDescription;
305 QString mSummary; 306 QString mSummary;
306 QStringList mCategories; 307 QStringList mCategories;
307 Incidence *mRelatedTo; 308 Incidence *mRelatedTo;
308 QString mRelatedToUid; 309 QString mRelatedToUid;
309 DateList mExDates; 310 DateList mExDates;
310 QPtrList<Attachment> mAttachments; 311 QPtrList<Attachment> mAttachments;
311 QStringList mResources; 312 QStringList mResources;
312 bool mHasStartDate; // if todo has associated start date 313 bool mHasStartDate; // if todo has associated start date
313 314
314 int mSecrecy; 315 int mSecrecy;
315 int mPriority; // 1 = highest, 2 = less, etc. 316 int mPriority; // 1 = highest, 2 = less, etc.
316 317
317 //QPtrList<Alarm> mAlarms; 318 //QPtrList<Alarm> mAlarms;
318 319
319 QString mLocation; 320 QString mLocation;
320}; 321};
321 322
322bool operator==( const Incidence&, const Incidence& ); 323bool operator==( const Incidence&, const Incidence& );
323 324
324} 325}
325 326
326#endif 327#endif