summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp26
1 files changed, 5 insertions, 21 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index e8c969f..1a1c6be 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -79,514 +79,499 @@ bool CalendarLocal::mergeCalendarFile( QString name )
79 } 79 }
80 return false; 80 return false;
81} 81}
82 82
83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) 83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates)
84{ 84{
85 Todo *todo;; 85 Todo *todo;;
86 Incidence *retVal = 0; 86 Incidence *retVal = 0;
87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
88 if ( todo->uid() == uid ) { 88 if ( todo->uid() == uid ) {
89 if ( doNotCheckDuplicates ) return todo; 89 if ( doNotCheckDuplicates ) return todo;
90 if ( retVal ) { 90 if ( retVal ) {
91 if ( retVal->calID() > todo->calID() ) { 91 if ( retVal->calID() > todo->calID() ) {
92 retVal = todo; 92 retVal = todo;
93 } 93 }
94 } else { 94 } else {
95 retVal = todo; 95 retVal = todo;
96 } 96 }
97 } 97 }
98 } 98 }
99 if ( retVal ) return retVal; 99 if ( retVal ) return retVal;
100 Event *event; 100 Event *event;
101 for ( event = mEventList.first(); event; event = mEventList.next() ) { 101 for ( event = mEventList.first(); event; event = mEventList.next() ) {
102 if ( event->uid() == uid ) { 102 if ( event->uid() == uid ) {
103 if ( doNotCheckDuplicates ) return event; 103 if ( doNotCheckDuplicates ) return event;
104 if ( retVal ) { 104 if ( retVal ) {
105 if ( retVal->calID() > event->calID() ) { 105 if ( retVal->calID() > event->calID() ) {
106 retVal = event; 106 retVal = event;
107 } 107 }
108 } else { 108 } else {
109 retVal = event; 109 retVal = event;
110 } 110 }
111 } 111 }
112 } 112 }
113 if ( retVal ) return retVal; 113 if ( retVal ) return retVal;
114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
115 if ( it->uid() == uid ) { 115 if ( it->uid() == uid ) {
116 if ( doNotCheckDuplicates ) return it; 116 if ( doNotCheckDuplicates ) return it;
117 if ( retVal ) { 117 if ( retVal ) {
118 if ( retVal->calID() > it->calID() ) { 118 if ( retVal->calID() > it->calID() ) {
119 retVal = it; 119 retVal = it;
120 } 120 }
121 } else { 121 } else {
122 retVal = it; 122 retVal = it;
123 } 123 }
124 } 124 }
125 return retVal; 125 return retVal;
126} 126}
127 127
128bool CalendarLocal::mergeCalendar( Calendar* remote ) 128bool CalendarLocal::mergeCalendar( Calendar* remote )
129{ 129{
130 // 1 look for raw inc in local 130 // 1 look for raw inc in local
131 // if inc not in remote, delete in local 131 // if inc not in remote, delete in local
132 // 2 look for raw inc in remote 132 // 2 look for raw inc in remote
133 // if inc in local, replace it 133 // if inc in local, replace it
134 // if not in local, add it to default calendar 134 // if not in local, add it to default calendar
135 QPtrList<Incidence> localInc = rawIncidences(); 135 QPtrList<Incidence> localInc = rawIncidences();
136 Incidence* inL = localInc.first(); 136 Incidence* inL = localInc.first();
137 while ( inL ) { 137 while ( inL ) {
138 if ( ! inL->isReadOnly () ) 138 if ( ! inL->isReadOnly () )
139 if ( !remote->incidenceForUid( inL->uid(), true )) 139 if ( !remote->incidenceForUid( inL->uid(), true ))
140 deleteIncidence( inL ); 140 deleteIncidence( inL );
141 inL = localInc.next(); 141 inL = localInc.next();
142 } 142 }
143 QPtrList<Incidence> er = remote->rawIncidences(); 143 QPtrList<Incidence> er = remote->rawIncidences();
144 Incidence* inR = er.first(); 144 Incidence* inR = er.first();
145 while ( inR ) { 145 while ( inR ) {
146 inL = incidenceForUid( inR->uid(),false ); 146 inL = incidenceForUid( inR->uid(),false );
147 if ( inL ) { 147 if ( inL ) {
148 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { 148 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
149 int calID = inL->calID(); 149 int calID = inL->calID();
150 deleteIncidence( inL ); 150 deleteIncidence( inL );
151 inL = inR->clone(); 151 inL = inR->clone();
152 inL->setCalID( calID ); 152 inL->setCalID( calID );
153 addIncidence( inL ); 153 addIncidence( inL );
154 } 154 }
155 } else { 155 } else {
156 inL = inR->clone(); 156 inL = inR->clone();
157 inL->setCalID( 0 );// add to default cal 157 inL->setCalID( 0 );// add to default cal
158 addIncidence( inL ); 158 addIncidence( inL );
159 } 159 }
160 inR = er.next(); 160 inR = er.next();
161 } 161 }
162 return true; 162 return true;
163} 163}
164 164
165 165
166bool CalendarLocal::addCalendarFile( QString name, int id ) 166bool CalendarLocal::addCalendarFile( QString name, int id )
167{ 167{
168 CalendarLocal calendar( timeZoneId() ); 168 CalendarLocal calendar( timeZoneId() );
169 calendar.setDefaultCalendar( id ); 169 calendar.setDefaultCalendar( id );
170 if ( calendar.load( name ) ) { 170 if ( calendar.load( name ) ) {
171 addCalendar( &calendar ); 171 addCalendar( &calendar );
172 return true; 172 return true;
173 } 173 }
174 return false; 174 return false;
175} 175}
176void CalendarLocal::setSyncEventsReadOnly() 176void CalendarLocal::setSyncEventsReadOnly()
177{ 177{
178 Event * ev; 178 Event * ev;
179 ev = mEventList.first(); 179 ev = mEventList.first();
180 while ( ev ) { 180 while ( ev ) {
181 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 181 if ( ev->uid().left(15) == QString("last-syncEvent-") )
182 ev->setReadOnly( true ); 182 ev->setReadOnly( true );
183 ev = mEventList.next(); 183 ev = mEventList.next();
184 } 184 }
185} 185}
186void CalendarLocal::addCalendar( Calendar* cal ) 186void CalendarLocal::addCalendar( Calendar* cal )
187{ 187{
188 cal->setDontDeleteIncidencesOnClose(); 188 cal->setDontDeleteIncidencesOnClose();
189 { 189 {
190 QPtrList<Event> EventList = cal->rawEvents(); 190 QPtrList<Event> EventList = cal->rawEvents();
191 Event * ev = EventList.first(); 191 Event * ev = EventList.first();
192 while ( ev ) { 192 while ( ev ) {
193 ev->unRegisterObserver( cal ); 193 ev->unRegisterObserver( cal );
194 ev->registerObserver( this ); 194 ev->registerObserver( this );
195 mEventList.append( ev ); 195 mEventList.append( ev );
196 ev = EventList.next(); 196 ev = EventList.next();
197 } 197 }
198 } 198 }
199 { 199 {
200 200
201 QPtrList<Todo> TodoList = cal->rawTodos(); 201 QPtrList<Todo> TodoList = cal->rawTodos();
202 Todo * ev = TodoList.first(); 202 Todo * ev = TodoList.first();
203 while ( ev ) { 203 while ( ev ) {
204 QString rel = ev->relatedToUid(); 204 QString rel = ev->relatedToUid();
205 if ( !rel.isEmpty() ){ 205 if ( !rel.isEmpty() ){
206 ev->setRelatedTo ( 0 ); 206 ev->setRelatedTo ( 0 );
207 ev->setRelatedToUid( rel ); 207 ev->setRelatedToUid( rel );
208 } 208 }
209 ev = TodoList.next(); 209 ev = TodoList.next();
210 } 210 }
211 //TodoList = cal->rawTodos(); 211 //TodoList = cal->rawTodos();
212 ev = TodoList.first(); 212 ev = TodoList.first();
213 while ( ev ) { 213 while ( ev ) {
214 ev->unRegisterObserver( cal ); 214 ev->unRegisterObserver( cal );
215 ev->registerObserver( this ); 215 ev->registerObserver( this );
216 mTodoList.append( ev ); 216 mTodoList.append( ev );
217 setupRelations( ev ); 217 setupRelations( ev );
218 ev = TodoList.next(); 218 ev = TodoList.next();
219 } 219 }
220 } 220 }
221 { 221 {
222 QPtrList<Journal> JournalList = cal->journals(); 222 QPtrList<Journal> JournalList = cal->journals();
223 Journal * ev = JournalList.first(); 223 Journal * ev = JournalList.first();
224 while ( ev ) { 224 while ( ev ) {
225 ev->unRegisterObserver( cal ); 225 ev->unRegisterObserver( cal );
226 ev->registerObserver( this ); 226 ev->registerObserver( this );
227 mJournalList.append( ev ); 227 mJournalList.append( ev );
228 ev = JournalList.next(); 228 ev = JournalList.next();
229 } 229 }
230 } 230 }
231 setModified( true ); 231 setModified( true );
232} 232}
233bool CalendarLocal::load( const QString &fileName ) 233bool CalendarLocal::load( const QString &fileName )
234{ 234{
235 FileStorage storage( this, fileName ); 235 FileStorage storage( this, fileName );
236 return storage.load(); 236 return storage.load();
237} 237}
238 238
239bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 239bool CalendarLocal::save( const QString &fileName, CalFormat *format )
240{ 240{
241 FileStorage storage( this, fileName, format ); 241 FileStorage storage( this, fileName, format );
242 return storage.save(); 242 return storage.save();
243} 243}
244 244
245void CalendarLocal::stopAllTodos() 245void CalendarLocal::stopAllTodos()
246{ 246{
247 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 247 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
248 it->setRunning( false ); 248 it->setRunning( false );
249 249
250} 250}
251void CalendarLocal::close() 251void CalendarLocal::close()
252{ 252{
253 253
254 Todo * i; 254 Todo * i;
255 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 255 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
256 256
257 mEventList.setAutoDelete( true ); 257 mEventList.setAutoDelete( true );
258 mTodoList.setAutoDelete( true ); 258 mTodoList.setAutoDelete( true );
259 mJournalList.setAutoDelete( true ); 259 mJournalList.setAutoDelete( true );
260 260
261 mEventList.clear(); 261 mEventList.clear();
262 mTodoList.clear(); 262 mTodoList.clear();
263 mJournalList.clear(); 263 mJournalList.clear();
264 264
265 mEventList.setAutoDelete( false ); 265 mEventList.setAutoDelete( false );
266 mTodoList.setAutoDelete( false ); 266 mTodoList.setAutoDelete( false );
267 mJournalList.setAutoDelete( false ); 267 mJournalList.setAutoDelete( false );
268 268
269 setModified( false ); 269 setModified( false );
270} 270}
271 void CalendarLocal::clearUndo() 271
272{
273 if ( mUndoIncidence ) {
274 if ( mUndoIncidence->typeID() == eventID )
275 delete ((Event*) mUndoIncidence) ;
276 else if ( mUndoIncidence->typeID() == todoID )
277 delete ( (Todo*) mUndoIncidence );
278 else if ( mUndoIncidence->typeID() == journalID )
279 delete ( (Journal*) mUndoIncidence );
280 else
281 delete mUndoIncidence;
282 }
283 mUndoIncidence = 0;
284}
285bool CalendarLocal::addAnniversaryNoDup( Event *event ) 272bool CalendarLocal::addAnniversaryNoDup( Event *event )
286{ 273{
287 QString cat; 274 QString cat;
288 bool isBirthday = true; 275 bool isBirthday = true;
289 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 276 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
290 isBirthday = false; 277 isBirthday = false;
291 cat = i18n( "Anniversary" ); 278 cat = i18n( "Anniversary" );
292 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 279 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
293 isBirthday = true; 280 isBirthday = true;
294 cat = i18n( "Birthday" ); 281 cat = i18n( "Birthday" );
295 } else { 282 } else {
296 qDebug("addAnniversaryNoDup called without fitting category! "); 283 qDebug("addAnniversaryNoDup called without fitting category! ");
297 return false; 284 return false;
298 } 285 }
299 Event * eve; 286 Event * eve;
300 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 287 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
301 if ( !(eve->categories().contains( cat ) )) 288 if ( !(eve->categories().contains( cat ) ))
302 continue; 289 continue;
303 // now we have an event with fitting category 290 // now we have an event with fitting category
304 if ( eve->dtStart().date() != event->dtStart().date() ) 291 if ( eve->dtStart().date() != event->dtStart().date() )
305 continue; 292 continue;
306 // now we have an event with fitting category+date 293 // now we have an event with fitting category+date
307 if ( eve->summary() != event->summary() ) 294 if ( eve->summary() != event->summary() )
308 continue; 295 continue;
309 // now we have an event with fitting category+date+summary 296 // now we have an event with fitting category+date+summary
310 return false; 297 return false;
311 } 298 }
312 return addEvent( event ); 299 return addEvent( event );
313 300
314} 301}
315bool CalendarLocal::addEventNoDup( Event *event ) 302bool CalendarLocal::addEventNoDup( Event *event )
316{ 303{
317 Event * eve; 304 Event * eve;
318 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 305 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
319 if ( *eve == *event ) { 306 if ( *eve == *event ) {
320 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 307 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
321 return false; 308 return false;
322 } 309 }
323 } 310 }
324 return addEvent( event ); 311 return addEvent( event );
325} 312}
326 313
327bool CalendarLocal::addEvent( Event *event ) 314bool CalendarLocal::addEvent( Event *event )
328{ 315{
329 insertEvent( event ); 316 insertEvent( event );
330 317
331 event->registerObserver( this ); 318 event->registerObserver( this );
332 319
333 setModified( true ); 320 setModified( true );
334 if ( event->calID() == 0 ) 321 if ( event->calID() == 0 )
335 event->setCalID( mDefaultCalendar ); 322 event->setCalID( mDefaultCalendar );
336 event->setCalEnabled( true ); 323 event->setCalEnabled( true );
337 324
338 return true; 325 return true;
339} 326}
340 327
341void CalendarLocal::deleteEvent( Event *event ) 328void CalendarLocal::deleteEvent( Event *event )
342{ 329{
343 clearUndo(); 330 clearUndo(event);
344 mUndoIncidence = event;
345 if ( mEventList.removeRef( event ) ) { 331 if ( mEventList.removeRef( event ) ) {
346 setModified( true ); 332 setModified( true );
347 } 333 }
348} 334}
349 335
350 336
351Event *CalendarLocal::event( const QString &uid ) 337Event *CalendarLocal::event( const QString &uid )
352{ 338{
353 Event *event; 339 Event *event;
354 Event *retVal = 0; 340 Event *retVal = 0;
355 for ( event = mEventList.first(); event; event = mEventList.next() ) { 341 for ( event = mEventList.first(); event; event = mEventList.next() ) {
356 if ( event->calEnabled() && event->uid() == uid ) { 342 if ( event->calEnabled() && event->uid() == uid ) {
357 if ( retVal ) { 343 if ( retVal ) {
358 if ( retVal->calID() > event->calID() ) { 344 if ( retVal->calID() > event->calID() ) {
359 retVal = event; 345 retVal = event;
360 } 346 }
361 } else { 347 } else {
362 retVal = event; 348 retVal = event;
363 } 349 }
364 } 350 }
365 } 351 }
366 return retVal; 352 return retVal;
367} 353}
368bool CalendarLocal::addTodoNoDup( Todo *todo ) 354bool CalendarLocal::addTodoNoDup( Todo *todo )
369{ 355{
370 Todo * eve; 356 Todo * eve;
371 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 357 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
372 if ( *eve == *todo ) { 358 if ( *eve == *todo ) {
373 //qDebug("duplicate todo found! not inserted! "); 359 //qDebug("duplicate todo found! not inserted! ");
374 return false; 360 return false;
375 } 361 }
376 } 362 }
377 return addTodo( todo ); 363 return addTodo( todo );
378} 364}
379bool CalendarLocal::addTodo( Todo *todo ) 365bool CalendarLocal::addTodo( Todo *todo )
380{ 366{
381 mTodoList.append( todo ); 367 mTodoList.append( todo );
382 368
383 todo->registerObserver( this ); 369 todo->registerObserver( this );
384 370
385 // Set up subtask relations 371 // Set up subtask relations
386 setupRelations( todo ); 372 setupRelations( todo );
387 373
388 setModified( true ); 374 setModified( true );
389 if ( todo->calID() == 0 ) 375 if ( todo->calID() == 0 )
390 todo->setCalID( mDefaultCalendar ); 376 todo->setCalID( mDefaultCalendar );
391 todo->setCalEnabled( true ); 377 todo->setCalEnabled( true );
392 return true; 378 return true;
393} 379}
394 380
395void CalendarLocal::deleteTodo( Todo *todo ) 381void CalendarLocal::deleteTodo( Todo *todo )
396{ 382{
397 // Handle orphaned children 383 // Handle orphaned children
398 clearUndo();
399 removeRelations( todo ); 384 removeRelations( todo );
400 mUndoIncidence = todo; 385 clearUndo(todo);
401 386
402 if ( mTodoList.removeRef( todo ) ) { 387 if ( mTodoList.removeRef( todo ) ) {
403 setModified( true ); 388 setModified( true );
404 } 389 }
405} 390}
406 391
407QPtrList<Todo> CalendarLocal::rawTodos() 392QPtrList<Todo> CalendarLocal::rawTodos()
408{ 393{
409 QPtrList<Todo> el; 394 QPtrList<Todo> el;
410 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 395 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
411 if ( it->calEnabled() ) el.append( it ); 396 if ( it->calEnabled() ) el.append( it );
412 return el; 397 return el;
413} 398}
414Todo *CalendarLocal::todo( QString syncProf, QString id ) 399Todo *CalendarLocal::todo( QString syncProf, QString id )
415{ 400{
416 Todo *todo; 401 Todo *todo;
417 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 402 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
418 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 403 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
419 } 404 }
420 405
421 return 0; 406 return 0;
422} 407}
423void CalendarLocal::removeSyncInfo( QString syncProfile) 408void CalendarLocal::removeSyncInfo( QString syncProfile)
424{ 409{
425 QPtrList<Incidence> all = rawIncidences() ; 410 QPtrList<Incidence> all = rawIncidences() ;
426 Incidence *inc; 411 Incidence *inc;
427 for ( inc = all.first(); inc; inc = all.next() ) { 412 for ( inc = all.first(); inc; inc = all.next() ) {
428 inc->removeID( syncProfile ); 413 inc->removeID( syncProfile );
429 } 414 }
430 if ( syncProfile.isEmpty() ) { 415 if ( syncProfile.isEmpty() ) {
431 QPtrList<Event> el; 416 QPtrList<Event> el;
432 Event *todo; 417 Event *todo;
433 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 418 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
434 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 419 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
435 el.append( todo ); 420 el.append( todo );
436 } 421 }
437 for ( todo = el.first(); todo; todo = el.next() ) { 422 for ( todo = el.first(); todo; todo = el.next() ) {
438 deleteIncidence ( todo ); 423 deleteIncidence ( todo );
439 } 424 }
440 } else { 425 } else {
441 Event *lse = event( "last-syncEvent-"+ syncProfile); 426 Event *lse = event( "last-syncEvent-"+ syncProfile);
442 if ( lse ) 427 if ( lse )
443 deleteIncidence ( lse ); 428 deleteIncidence ( lse );
444 } 429 }
445} 430}
446QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 431QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
447{ 432{
448 QPtrList<Event> el; 433 QPtrList<Event> el;
449 Event *todo; 434 Event *todo;
450 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 435 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
451 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 436 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
452 if ( todo->summary().left(3) == "E: " ) 437 if ( todo->summary().left(3) == "E: " )
453 el.append( todo ); 438 el.append( todo );
454 } 439 }
455 440
456 return el; 441 return el;
457 442
458} 443}
459Event *CalendarLocal::event( QString syncProf, QString id ) 444Event *CalendarLocal::event( QString syncProf, QString id )
460{ 445{
461 Event *todo; 446 Event *todo;
462 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 447 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
463 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 448 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
464 } 449 }
465 450
466 return 0; 451 return 0;
467} 452}
468Todo *CalendarLocal::todo( const QString &uid ) 453Todo *CalendarLocal::todo( const QString &uid )
469{ 454{
470 Todo *todo;; 455 Todo *todo;;
471 Todo *retVal = 0; 456 Todo *retVal = 0;
472 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 457 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
473 if ( todo->calEnabled() && todo->uid() == uid ) { 458 if ( todo->calEnabled() && todo->uid() == uid ) {
474 if ( retVal ) { 459 if ( retVal ) {
475 if ( retVal->calID() > todo->calID() ) { 460 if ( retVal->calID() > todo->calID() ) {
476 retVal = todo; 461 retVal = todo;
477 } 462 }
478 } else { 463 } else {
479 retVal = todo; 464 retVal = todo;
480 } 465 }
481 } 466 }
482 } 467 }
483 return retVal; 468 return retVal;
484} 469}
485QString CalendarLocal::nextSummary() const 470QString CalendarLocal::nextSummary() const
486{ 471{
487 return mNextSummary; 472 return mNextSummary;
488} 473}
489QDateTime CalendarLocal::nextAlarmEventDateTime() const 474QDateTime CalendarLocal::nextAlarmEventDateTime() const
490{ 475{
491 return mNextAlarmEventDateTime; 476 return mNextAlarmEventDateTime;
492} 477}
493void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 478void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
494{ 479{
495 //mNextAlarmIncidence 480 //mNextAlarmIncidence
496 //mNextAlarmDateTime 481 //mNextAlarmDateTime
497 //return mNextSummary; 482 //return mNextSummary;
498 //return mNextAlarmEventDateTime; 483 //return mNextAlarmEventDateTime;
499 bool newNextAlarm = false; 484 bool newNextAlarm = false;
500 bool computeNextAlarm = false; 485 bool computeNextAlarm = false;
501 bool ok; 486 bool ok;
502 int offset; 487 int offset;
503 QDateTime nextA; 488 QDateTime nextA;
504 // QString nextSum; 489 // QString nextSum;
505 //QDateTime nextEvent; 490 //QDateTime nextEvent;
506 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 491 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
507 computeNextAlarm = true; 492 computeNextAlarm = true;
508 } else { 493 } else {
509 if ( ! deleted ) { 494 if ( ! deleted ) {
510 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 495 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
511 if ( ok ) { 496 if ( ok ) {
512 if ( nextA < mNextAlarmDateTime ) { 497 if ( nextA < mNextAlarmDateTime ) {
513 deRegisterAlarm(); 498 deRegisterAlarm();
514 mNextAlarmDateTime = nextA; 499 mNextAlarmDateTime = nextA;
515 mNextSummary = incidence->summary(); 500 mNextSummary = incidence->summary();
516 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 501 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
517 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 502 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
518 newNextAlarm = true; 503 newNextAlarm = true;
519 mNextAlarmIncidence = incidence; 504 mNextAlarmIncidence = incidence;
520 } else { 505 } else {
521 if ( incidence == mNextAlarmIncidence ) { 506 if ( incidence == mNextAlarmIncidence ) {
522 computeNextAlarm = true; 507 computeNextAlarm = true;
523 } 508 }
524 } 509 }
525 } else { 510 } else {
526 if ( mNextAlarmIncidence == incidence ) { 511 if ( mNextAlarmIncidence == incidence ) {
527 computeNextAlarm = true; 512 computeNextAlarm = true;
528 } 513 }
529 } 514 }
530 } else { // deleted 515 } else { // deleted
531 if ( incidence == mNextAlarmIncidence ) { 516 if ( incidence == mNextAlarmIncidence ) {
532 computeNextAlarm = true; 517 computeNextAlarm = true;
533 } 518 }
534 } 519 }
535 } 520 }
536 if ( computeNextAlarm ) { 521 if ( computeNextAlarm ) {
537 deRegisterAlarm(); 522 deRegisterAlarm();
538 nextA = nextAlarm( 1000 ); 523 nextA = nextAlarm( 1000 );
539 if (! mNextAlarmIncidence ) { 524 if (! mNextAlarmIncidence ) {
540 return; 525 return;
541 } 526 }
542 newNextAlarm = true; 527 newNextAlarm = true;
543 } 528 }
544 if ( newNextAlarm ) 529 if ( newNextAlarm )
545 registerAlarm(); 530 registerAlarm();
546} 531}
547QString CalendarLocal:: getAlarmNotification() 532QString CalendarLocal:: getAlarmNotification()
548{ 533{
549 QString ret; 534 QString ret;
550 // this should not happen 535 // this should not happen
551 if (! mNextAlarmIncidence ) 536 if (! mNextAlarmIncidence )
552 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 537 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
553 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 538 Alarm* alarm = mNextAlarmIncidence->alarms().first();
554 if ( alarm->type() == Alarm::Procedure ) { 539 if ( alarm->type() == Alarm::Procedure ) {
555 ret = "proc_alarm" + alarm->programFile()+"+++"; 540 ret = "proc_alarm" + alarm->programFile()+"+++";
556 } else { 541 } else {
557 ret = "audio_alarm" +alarm->audioFile() +"+++"; 542 ret = "audio_alarm" +alarm->audioFile() +"+++";
558 } 543 }
559 ret += "cal_alarm"+ mNextSummary.left( 25 ); 544 ret += "cal_alarm"+ mNextSummary.left( 25 );
560 if ( mNextSummary.length() > 25 ) 545 if ( mNextSummary.length() > 25 )
561 ret += "\n" + mNextSummary.mid(25, 25 ); 546 ret += "\n" + mNextSummary.mid(25, 25 );
562 ret+= "\n"+mNextAlarmEventDateTimeString; 547 ret+= "\n"+mNextAlarmEventDateTimeString;
563 return ret; 548 return ret;
564} 549}
565void CalendarLocal::registerAlarm() 550void CalendarLocal::registerAlarm()
566{ 551{
567 mLastAlarmNotificationString = getAlarmNotification(); 552 mLastAlarmNotificationString = getAlarmNotification();
568 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 553 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
569 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 554 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
570// #ifndef DESKTOP_VERSION 555// #ifndef DESKTOP_VERSION
571// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 556// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
572// #endif 557// #endif
573} 558}
574void CalendarLocal::deRegisterAlarm() 559void CalendarLocal::deRegisterAlarm()
575{ 560{
576 if ( mLastAlarmNotificationString.isNull() ) 561 if ( mLastAlarmNotificationString.isNull() )
577 return; 562 return;
578 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 563 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
579 564
580 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 565 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
581 mNextAlarmEventDateTime = QDateTime(); 566 mNextAlarmEventDateTime = QDateTime();
582// #ifndef DESKTOP_VERSION 567// #ifndef DESKTOP_VERSION
583// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 568// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
584// #endif 569// #endif
585} 570}
586 571
587QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 572QPtrList<Todo> CalendarLocal::todos( const QDate &date )
588{ 573{
589 QPtrList<Todo> todos; 574 QPtrList<Todo> todos;
590 575
591 Todo *todo; 576 Todo *todo;
592 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 577 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
@@ -710,327 +695,326 @@ void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
710 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 695 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
711 if (incidence->recursOn(from.date())) { 696 if (incidence->recursOn(from.date())) {
712 qdt.setTime(alarm->time().time()); 697 qdt.setTime(alarm->time().time());
713 qdt.setDate(from.date()); 698 qdt.setDate(from.date());
714 } 699 }
715 else qdt = alarm->time(); 700 else qdt = alarm->time();
716 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 701 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
717 if ( alarm->enabled() ) { 702 if ( alarm->enabled() ) {
718 if ( qdt >= from && qdt <= to ) { 703 if ( qdt >= from && qdt <= to ) {
719 alarms.append( alarm ); 704 alarms.append( alarm );
720 } 705 }
721 } 706 }
722 } 707 }
723} 708}
724 709
725 710
726/****************************** PROTECTED METHODS ****************************/ 711/****************************** PROTECTED METHODS ****************************/
727 712
728// after changes are made to an event, this should be called. 713// after changes are made to an event, this should be called.
729void CalendarLocal::update( IncidenceBase *incidence ) 714void CalendarLocal::update( IncidenceBase *incidence )
730{ 715{
731 incidence->setSyncStatus( Event::SYNCMOD ); 716 incidence->setSyncStatus( Event::SYNCMOD );
732 incidence->setLastModified( QDateTime::currentDateTime() ); 717 incidence->setLastModified( QDateTime::currentDateTime() );
733 // we should probably update the revision number here, 718 // we should probably update the revision number here,
734 // or internally in the Event itself when certain things change. 719 // or internally in the Event itself when certain things change.
735 // need to verify with ical documentation. 720 // need to verify with ical documentation.
736 721
737 setModified( true ); 722 setModified( true );
738} 723}
739 724
740void CalendarLocal::insertEvent( Event *event ) 725void CalendarLocal::insertEvent( Event *event )
741{ 726{
742 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 727 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
743} 728}
744 729
745 730
746QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 731QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
747{ 732{
748 QPtrList<Event> eventList; 733 QPtrList<Event> eventList;
749 734
750 Event *event; 735 Event *event;
751 for( event = mEventList.first(); event; event = mEventList.next() ) { 736 for( event = mEventList.first(); event; event = mEventList.next() ) {
752 if ( !event->calEnabled() ) continue; 737 if ( !event->calEnabled() ) continue;
753 if ( event->doesRecur() ) { 738 if ( event->doesRecur() ) {
754 if ( event->isMultiDay() ) { 739 if ( event->isMultiDay() ) {
755 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 740 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
756 int i; 741 int i;
757 for ( i = 0; i <= extraDays; i++ ) { 742 for ( i = 0; i <= extraDays; i++ ) {
758 if ( event->recursOn( qd.addDays( -i ) ) ) { 743 if ( event->recursOn( qd.addDays( -i ) ) ) {
759 eventList.append( event ); 744 eventList.append( event );
760 break; 745 break;
761 } 746 }
762 } 747 }
763 } else { 748 } else {
764 if ( event->recursOn( qd ) ) 749 if ( event->recursOn( qd ) )
765 eventList.append( event ); 750 eventList.append( event );
766 } 751 }
767 } else { 752 } else {
768 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 753 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
769 eventList.append( event ); 754 eventList.append( event );
770 } 755 }
771 } 756 }
772 } 757 }
773 758
774 if ( !sorted ) { 759 if ( !sorted ) {
775 return eventList; 760 return eventList;
776 } 761 }
777 762
778 // kdDebug(5800) << "Sorting events for date\n" << endl; 763 // kdDebug(5800) << "Sorting events for date\n" << endl;
779 // now, we have to sort it based on dtStart.time() 764 // now, we have to sort it based on dtStart.time()
780 QPtrList<Event> eventListSorted; 765 QPtrList<Event> eventListSorted;
781 Event *sortEvent; 766 Event *sortEvent;
782 for ( event = eventList.first(); event; event = eventList.next() ) { 767 for ( event = eventList.first(); event; event = eventList.next() ) {
783 sortEvent = eventListSorted.first(); 768 sortEvent = eventListSorted.first();
784 int i = 0; 769 int i = 0;
785 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 770 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
786 { 771 {
787 i++; 772 i++;
788 sortEvent = eventListSorted.next(); 773 sortEvent = eventListSorted.next();
789 } 774 }
790 eventListSorted.insert( i, event ); 775 eventListSorted.insert( i, event );
791 } 776 }
792 return eventListSorted; 777 return eventListSorted;
793} 778}
794 779
795 780
796QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 781QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
797 bool inclusive ) 782 bool inclusive )
798{ 783{
799 Event *event = 0; 784 Event *event = 0;
800 785
801 QPtrList<Event> eventList; 786 QPtrList<Event> eventList;
802 787
803 // Get non-recurring events 788 // Get non-recurring events
804 for( event = mEventList.first(); event; event = mEventList.next() ) { 789 for( event = mEventList.first(); event; event = mEventList.next() ) {
805 if ( !event->calEnabled() ) continue; 790 if ( !event->calEnabled() ) continue;
806 if ( event->doesRecur() ) { 791 if ( event->doesRecur() ) {
807 QDate rStart = event->dtStart().date(); 792 QDate rStart = event->dtStart().date();
808 bool found = false; 793 bool found = false;
809 if ( inclusive ) { 794 if ( inclusive ) {
810 if ( rStart >= start && rStart <= end ) { 795 if ( rStart >= start && rStart <= end ) {
811 // Start date of event is in range. Now check for end date. 796 // Start date of event is in range. Now check for end date.
812 // if duration is negative, event recurs forever, so do not include it. 797 // if duration is negative, event recurs forever, so do not include it.
813 if ( event->recurrence()->duration() == 0 ) { // End date set 798 if ( event->recurrence()->duration() == 0 ) { // End date set
814 QDate rEnd = event->recurrence()->endDate(); 799 QDate rEnd = event->recurrence()->endDate();
815 if ( rEnd >= start && rEnd <= end ) { // End date within range 800 if ( rEnd >= start && rEnd <= end ) { // End date within range
816 found = true; 801 found = true;
817 } 802 }
818 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 803 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
819 // TODO: Calculate end date from duration. Should be done in Event 804 // TODO: Calculate end date from duration. Should be done in Event
820 // For now exclude all events with a duration. 805 // For now exclude all events with a duration.
821 } 806 }
822 } 807 }
823 } else { 808 } else {
824 bool founOne; 809 bool founOne;
825 QDate next = event->getNextOccurence( start, &founOne ).date(); 810 QDate next = event->getNextOccurence( start, &founOne ).date();
826 if ( founOne ) { 811 if ( founOne ) {
827 if ( next <= end ) { 812 if ( next <= end ) {
828 found = true; 813 found = true;
829 } 814 }
830 } 815 }
831 816
832 /* 817 /*
833 // crap !!! 818 // crap !!!
834 if ( rStart <= end ) { // Start date not after range 819 if ( rStart <= end ) { // Start date not after range
835 if ( rStart >= start ) { // Start date within range 820 if ( rStart >= start ) { // Start date within range
836 found = true; 821 found = true;
837 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 822 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
838 found = true; 823 found = true;
839 } else if ( event->recurrence()->duration() == 0 ) { // End date set 824 } else if ( event->recurrence()->duration() == 0 ) { // End date set
840 QDate rEnd = event->recurrence()->endDate(); 825 QDate rEnd = event->recurrence()->endDate();
841 if ( rEnd >= start && rEnd <= end ) { // End date within range 826 if ( rEnd >= start && rEnd <= end ) { // End date within range
842 found = true; 827 found = true;
843 } 828 }
844 } else { // Duration set 829 } else { // Duration set
845 // TODO: Calculate end date from duration. Should be done in Event 830 // TODO: Calculate end date from duration. Should be done in Event
846 // For now include all events with a duration. 831 // For now include all events with a duration.
847 found = true; 832 found = true;
848 } 833 }
849 } 834 }
850 */ 835 */
851 836
852 } 837 }
853 838
854 if ( found ) eventList.append( event ); 839 if ( found ) eventList.append( event );
855 } else { 840 } else {
856 QDate s = event->dtStart().date(); 841 QDate s = event->dtStart().date();
857 QDate e = event->dtEnd().date(); 842 QDate e = event->dtEnd().date();
858 843
859 if ( inclusive ) { 844 if ( inclusive ) {
860 if ( s >= start && e <= end ) { 845 if ( s >= start && e <= end ) {
861 eventList.append( event ); 846 eventList.append( event );
862 } 847 }
863 } else { 848 } else {
864 if ( ( e >= start && s <= end ) ) { 849 if ( ( e >= start && s <= end ) ) {
865 eventList.append( event ); 850 eventList.append( event );
866 } 851 }
867 } 852 }
868 } 853 }
869 } 854 }
870 855
871 return eventList; 856 return eventList;
872} 857}
873 858
874QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 859QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
875{ 860{
876 return rawEventsForDate( qdt.date() ); 861 return rawEventsForDate( qdt.date() );
877} 862}
878 863
879QPtrList<Event> CalendarLocal::rawEvents() 864QPtrList<Event> CalendarLocal::rawEvents()
880{ 865{
881 QPtrList<Event> el; 866 QPtrList<Event> el;
882 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 867 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
883 if ( it->calEnabled() ) el.append( it ); 868 if ( it->calEnabled() ) el.append( it );
884 return el; 869 return el;
885} 870}
886 871
887bool CalendarLocal::addJournal(Journal *journal) 872bool CalendarLocal::addJournal(Journal *journal)
888{ 873{
889 mJournalList.append(journal); 874 mJournalList.append(journal);
890 875
891 journal->registerObserver( this ); 876 journal->registerObserver( this );
892 877
893 setModified( true ); 878 setModified( true );
894 if ( journal->calID() == 0 ) 879 if ( journal->calID() == 0 )
895 journal->setCalID( mDefaultCalendar ); 880 journal->setCalID( mDefaultCalendar );
896 journal->setCalEnabled( true ); 881 journal->setCalEnabled( true );
897 return true; 882 return true;
898} 883}
899 884
900void CalendarLocal::deleteJournal( Journal *journal ) 885void CalendarLocal::deleteJournal( Journal *journal )
901{ 886{
902 clearUndo(); 887 clearUndo(journal);
903 mUndoIncidence = journal;
904 if ( mJournalList.removeRef(journal) ) { 888 if ( mJournalList.removeRef(journal) ) {
905 setModified( true ); 889 setModified( true );
906 } 890 }
907} 891}
908 892
909QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) 893QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date )
910{ 894{
911 QPtrList<Journal> el; 895 QPtrList<Journal> el;
912 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 896 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
913 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); 897 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it );
914 return el; 898 return el;
915} 899}
916Journal *CalendarLocal::journal( const QDate &date ) 900Journal *CalendarLocal::journal( const QDate &date )
917{ 901{
918// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 902// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
919 903
920 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 904 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
921 if ( it->calEnabled() && it->dtStart().date() == date ) 905 if ( it->calEnabled() && it->dtStart().date() == date )
922 return it; 906 return it;
923 907
924 return 0; 908 return 0;
925} 909}
926 910
927Journal *CalendarLocal::journal( const QString &uid ) 911Journal *CalendarLocal::journal( const QString &uid )
928{ 912{
929 Journal * retVal = 0; 913 Journal * retVal = 0;
930 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 914 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
931 if ( it->calEnabled() && it->uid() == uid ) { 915 if ( it->calEnabled() && it->uid() == uid ) {
932 if ( retVal ) { 916 if ( retVal ) {
933 if ( retVal->calID() > it->calID() ) { 917 if ( retVal->calID() > it->calID() ) {
934 retVal = it; 918 retVal = it;
935 } 919 }
936 } else { 920 } else {
937 retVal = it; 921 retVal = it;
938 } 922 }
939 } 923 }
940 return retVal; 924 return retVal;
941} 925}
942 926
943QPtrList<Journal> CalendarLocal::journals() 927QPtrList<Journal> CalendarLocal::journals()
944{ 928{
945 QPtrList<Journal> el; 929 QPtrList<Journal> el;
946 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 930 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
947 if ( it->calEnabled() ) el.append( it ); 931 if ( it->calEnabled() ) el.append( it );
948 return el; 932 return el;
949} 933}
950void CalendarLocal::setCalendarRemove( int id ) 934void CalendarLocal::setCalendarRemove( int id )
951{ 935{
952 936
953 { 937 {
954 QPtrList<Event> EventList = mEventList; 938 QPtrList<Event> EventList = mEventList;
955 Event * ev = EventList.first(); 939 Event * ev = EventList.first();
956 while ( ev ) { 940 while ( ev ) {
957 if ( ev->calID() == id ) 941 if ( ev->calID() == id )
958 deleteEvent( ev ); 942 deleteEvent( ev );
959 ev = EventList.next(); 943 ev = EventList.next();
960 } 944 }
961 } 945 }
962 { 946 {
963 947
964 QPtrList<Todo> TodoList = mTodoList; 948 QPtrList<Todo> TodoList = mTodoList;
965 Todo * ev = TodoList.first(); 949 Todo * ev = TodoList.first();
966 while ( ev ) { 950 while ( ev ) {
967 if ( ev->calID() == id ) 951 if ( ev->calID() == id )
968 deleteTodo( ev ); 952 deleteTodo( ev );
969 ev = TodoList.next(); 953 ev = TodoList.next();
970 } 954 }
971 } 955 }
972 { 956 {
973 QPtrList<Journal> JournalList = mJournalList; 957 QPtrList<Journal> JournalList = mJournalList;
974 Journal * ev = JournalList.first(); 958 Journal * ev = JournalList.first();
975 while ( ev ) { 959 while ( ev ) {
976 if ( ev->calID() == id ) 960 if ( ev->calID() == id )
977 deleteJournal( ev ); 961 deleteJournal( ev );
978 ev = JournalList.next(); 962 ev = JournalList.next();
979 } 963 }
980 } 964 }
981 965
982 clearUndo(); 966 clearUndo(0);
983 967
984} 968}
985 969
986void CalendarLocal::setCalendarEnabled( int id, bool enable ) 970void CalendarLocal::setCalendarEnabled( int id, bool enable )
987{ 971{
988 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 972 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
989 if ( it->calID() == id ) it->setCalEnabled( enable ); 973 if ( it->calID() == id ) it->setCalEnabled( enable );
990 974
991 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 975 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
992 if ( it->calID() == id ) it->setCalEnabled( enable ); 976 if ( it->calID() == id ) it->setCalEnabled( enable );
993 977
994 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 978 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
995 if ( it->calID() == id ) it->setCalEnabled( enable ); 979 if ( it->calID() == id ) it->setCalEnabled( enable );
996 980
997} 981}
998 982
999void CalendarLocal::setReadOnly( int id, bool enable ) 983void CalendarLocal::setReadOnly( int id, bool enable )
1000{ 984{
1001 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 985 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1002 if ( it->calID() == id ) it->setReadOnly( enable ); 986 if ( it->calID() == id ) it->setReadOnly( enable );
1003 987
1004 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 988 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1005 if ( it->calID() == id ) it->setReadOnly( enable ); 989 if ( it->calID() == id ) it->setReadOnly( enable );
1006 990
1007 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 991 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1008 if ( it->calID() == id ) it->setReadOnly( enable ); 992 if ( it->calID() == id ) it->setReadOnly( enable );
1009 993
1010} 994}
1011 995
1012void CalendarLocal::setAlarmEnabled( int id, bool enable ) 996void CalendarLocal::setAlarmEnabled( int id, bool enable )
1013{ 997{
1014 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 998 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1015 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 999 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1016 1000
1017 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1001 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1018 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1002 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1019 1003
1020 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1004 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1021 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1005 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1022 reInitAlarmSettings(); 1006 reInitAlarmSettings();
1023 1007
1024} 1008}
1025void CalendarLocal::setDefaultCalendarEnabledOnly() 1009void CalendarLocal::setDefaultCalendarEnabledOnly()
1026{ 1010{
1027 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1011 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1028 it->setCalEnabled( it->calID() == mDefaultCalendar ); 1012 it->setCalEnabled( it->calID() == mDefaultCalendar );
1029 1013
1030 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1014 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1031 it->setCalEnabled( it->calID() == mDefaultCalendar); 1015 it->setCalEnabled( it->calID() == mDefaultCalendar);
1032 1016
1033 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1017 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1034 it->setCalEnabled( it->calID() == mDefaultCalendar); 1018 it->setCalEnabled( it->calID() == mDefaultCalendar);
1035 1019
1036} 1020}