summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp80
1 files changed, 68 insertions, 12 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index fe74052..c5500bf 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -121,191 +121,197 @@ bool CalendarLocal::addAnniversaryNoDup( Event *event )
121 continue; 121 continue;
122 // now we have an event with fitting category 122 // now we have an event with fitting category
123 if ( eve->dtStart().date() != event->dtStart().date() ) 123 if ( eve->dtStart().date() != event->dtStart().date() )
124 continue; 124 continue;
125 // now we have an event with fitting category+date 125 // now we have an event with fitting category+date
126 if ( eve->summary() != event->summary() ) 126 if ( eve->summary() != event->summary() )
127 continue; 127 continue;
128 // now we have an event with fitting category+date+summary 128 // now we have an event with fitting category+date+summary
129 return false; 129 return false;
130 } 130 }
131 return addEvent( event ); 131 return addEvent( event );
132 132
133} 133}
134bool CalendarLocal::addEventNoDup( Event *event ) 134bool CalendarLocal::addEventNoDup( Event *event )
135{ 135{
136 Event * eve; 136 Event * eve;
137 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 137 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
138 if ( *eve == *event ) { 138 if ( *eve == *event ) {
139 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 139 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
140 return false; 140 return false;
141 } 141 }
142 } 142 }
143 return addEvent( event ); 143 return addEvent( event );
144} 144}
145 145
146bool CalendarLocal::addEvent( Event *event ) 146bool CalendarLocal::addEvent( Event *event )
147{ 147{
148 insertEvent( event ); 148 insertEvent( event );
149 149
150 event->registerObserver( this ); 150 event->registerObserver( this );
151 151
152 setModified( true ); 152 setModified( true );
153 event->setCalID( mDefaultCalendar );
154 event->setCalEnabled( true );
153 155
154 return true; 156 return true;
155} 157}
156 158
157void CalendarLocal::deleteEvent( Event *event ) 159void CalendarLocal::deleteEvent( Event *event )
158{ 160{
159 if ( mUndoIncidence ) delete mUndoIncidence; 161 if ( mUndoIncidence ) delete mUndoIncidence;
160 mUndoIncidence = event->clone(); 162 mUndoIncidence = event->clone();
161 if ( mEventList.removeRef( event ) ) { 163 if ( mEventList.removeRef( event ) ) {
162 setModified( true ); 164 setModified( true );
163 } 165 }
164} 166}
165 167
166 168
167Event *CalendarLocal::event( const QString &uid ) 169Event *CalendarLocal::event( const QString &uid )
168{ 170{
169 171
170 Event *event; 172 Event *event;
171 173
172 for ( event = mEventList.first(); event; event = mEventList.next() ) { 174 for ( event = mEventList.first(); event; event = mEventList.next() ) {
173 if ( event->uid() == uid ) { 175 if ( event->uid() == uid && event->calEnabled() ) {
174 return event; 176 return event;
175 } 177 }
176 } 178 }
177 179
178 return 0; 180 return 0;
179} 181}
180bool CalendarLocal::addTodoNoDup( Todo *todo ) 182bool CalendarLocal::addTodoNoDup( Todo *todo )
181{ 183{
182 Todo * eve; 184 Todo * eve;
183 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 185 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
184 if ( *eve == *todo ) { 186 if ( *eve == *todo ) {
185 //qDebug("duplicate todo found! not inserted! "); 187 //qDebug("duplicate todo found! not inserted! ");
186 return false; 188 return false;
187 } 189 }
188 } 190 }
189 return addTodo( todo ); 191 return addTodo( todo );
190} 192}
191bool CalendarLocal::addTodo( Todo *todo ) 193bool CalendarLocal::addTodo( Todo *todo )
192{ 194{
193 mTodoList.append( todo ); 195 mTodoList.append( todo );
194 196
195 todo->registerObserver( this ); 197 todo->registerObserver( this );
196 198
197 // Set up subtask relations 199 // Set up subtask relations
198 setupRelations( todo ); 200 setupRelations( todo );
199 201
200 setModified( true ); 202 setModified( true );
201 203 todo->setCalID( mDefaultCalendar );
204 todo->setCalEnabled( true );
202 return true; 205 return true;
203} 206}
204 207
205void CalendarLocal::deleteTodo( Todo *todo ) 208void CalendarLocal::deleteTodo( Todo *todo )
206{ 209{
207 // Handle orphaned children 210 // Handle orphaned children
208 if ( mUndoIncidence ) delete mUndoIncidence; 211 if ( mUndoIncidence ) delete mUndoIncidence;
209 removeRelations( todo ); 212 removeRelations( todo );
210 mUndoIncidence = todo->clone(); 213 mUndoIncidence = todo->clone();
211 214
212 if ( mTodoList.removeRef( todo ) ) { 215 if ( mTodoList.removeRef( todo ) ) {
213 setModified( true ); 216 setModified( true );
214 } 217 }
215} 218}
216 219
217QPtrList<Todo> CalendarLocal::rawTodos() 220QPtrList<Todo> CalendarLocal::rawTodos()
218{ 221{
219 return mTodoList; 222 QPtrList<Todo> el;
223 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
224 if ( it->calEnabled() ) el.append( it );
225 return el;
220} 226}
221Todo *CalendarLocal::todo( QString syncProf, QString id ) 227Todo *CalendarLocal::todo( QString syncProf, QString id )
222{ 228{
223 Todo *todo; 229 Todo *todo;
224 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 230 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
225 if ( todo->getID( syncProf ) == id ) return todo; 231 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
226 } 232 }
227 233
228 return 0; 234 return 0;
229} 235}
230void CalendarLocal::removeSyncInfo( QString syncProfile) 236void CalendarLocal::removeSyncInfo( QString syncProfile)
231{ 237{
232 QPtrList<Incidence> all = rawIncidences() ; 238 QPtrList<Incidence> all = rawIncidences() ;
233 Incidence *inc; 239 Incidence *inc;
234 for ( inc = all.first(); inc; inc = all.next() ) { 240 for ( inc = all.first(); inc; inc = all.next() ) {
235 inc->removeID( syncProfile ); 241 inc->removeID( syncProfile );
236 } 242 }
237 if ( syncProfile.isEmpty() ) { 243 if ( syncProfile.isEmpty() ) {
238 QPtrList<Event> el; 244 QPtrList<Event> el;
239 Event *todo; 245 Event *todo;
240 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 246 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
241 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 247 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
242 el.append( todo ); 248 el.append( todo );
243 } 249 }
244 for ( todo = el.first(); todo; todo = el.next() ) { 250 for ( todo = el.first(); todo; todo = el.next() ) {
245 deleteIncidence ( todo ); 251 deleteIncidence ( todo );
246 } 252 }
247 } else { 253 } else {
248 Event *lse = event( "last-syncEvent-"+ syncProfile); 254 Event *lse = event( "last-syncEvent-"+ syncProfile);
249 if ( lse ) 255 if ( lse )
250 deleteIncidence ( lse ); 256 deleteIncidence ( lse );
251 } 257 }
252} 258}
253QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 259QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
254{ 260{
255 QPtrList<Event> el; 261 QPtrList<Event> el;
256 Event *todo; 262 Event *todo;
257 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 263 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
258 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 264 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
259 if ( todo->summary().left(3) == "E: " ) 265 if ( todo->summary().left(3) == "E: " )
260 el.append( todo ); 266 el.append( todo );
261 } 267 }
262 268
263 return el; 269 return el;
264 270
265} 271}
266Event *CalendarLocal::event( QString syncProf, QString id ) 272Event *CalendarLocal::event( QString syncProf, QString id )
267{ 273{
268 Event *todo; 274 Event *todo;
269 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 275 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
270 if ( todo->getID( syncProf ) == id ) return todo; 276 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
271 } 277 }
272 278
273 return 0; 279 return 0;
274} 280}
275Todo *CalendarLocal::todo( const QString &uid ) 281Todo *CalendarLocal::todo( const QString &uid )
276{ 282{
277 Todo *todo; 283 Todo *todo;
278 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 284 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
279 if ( todo->uid() == uid ) return todo; 285 if ( todo->calEnabled() && todo->uid() == uid ) return todo;
280 } 286 }
281 287
282 return 0; 288 return 0;
283} 289}
284QString CalendarLocal::nextSummary() const 290QString CalendarLocal::nextSummary() const
285{ 291{
286 return mNextSummary; 292 return mNextSummary;
287} 293}
288QDateTime CalendarLocal::nextAlarmEventDateTime() const 294QDateTime CalendarLocal::nextAlarmEventDateTime() const
289{ 295{
290 return mNextAlarmEventDateTime; 296 return mNextAlarmEventDateTime;
291} 297}
292void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 298void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
293{ 299{
294 //mNextAlarmIncidence 300 //mNextAlarmIncidence
295 //mNextAlarmDateTime 301 //mNextAlarmDateTime
296 //return mNextSummary; 302 //return mNextSummary;
297 //return mNextAlarmEventDateTime; 303 //return mNextAlarmEventDateTime;
298 bool newNextAlarm = false; 304 bool newNextAlarm = false;
299 bool computeNextAlarm = false; 305 bool computeNextAlarm = false;
300 bool ok; 306 bool ok;
301 int offset; 307 int offset;
302 QDateTime nextA; 308 QDateTime nextA;
303 // QString nextSum; 309 // QString nextSum;
304 //QDateTime nextEvent; 310 //QDateTime nextEvent;
305 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 311 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
306 computeNextAlarm = true; 312 computeNextAlarm = true;
307 } else { 313 } else {
308 if ( ! deleted ) { 314 if ( ! deleted ) {
309 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 315 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
310 if ( ok ) { 316 if ( ok ) {
311 if ( nextA < mNextAlarmDateTime ) { 317 if ( nextA < mNextAlarmDateTime ) {
@@ -360,146 +366,151 @@ QString CalendarLocal:: getAlarmNotification()
360 ret += "\n" + mNextSummary.mid(25, 25 ); 366 ret += "\n" + mNextSummary.mid(25, 25 );
361 ret+= "\n"+mNextAlarmEventDateTimeString; 367 ret+= "\n"+mNextAlarmEventDateTimeString;
362 return ret; 368 return ret;
363} 369}
364void CalendarLocal::registerAlarm() 370void CalendarLocal::registerAlarm()
365{ 371{
366 mLastAlarmNotificationString = getAlarmNotification(); 372 mLastAlarmNotificationString = getAlarmNotification();
367 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 373 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
368 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 374 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
369// #ifndef DESKTOP_VERSION 375// #ifndef DESKTOP_VERSION
370// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 376// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
371// #endif 377// #endif
372} 378}
373void CalendarLocal::deRegisterAlarm() 379void CalendarLocal::deRegisterAlarm()
374{ 380{
375 if ( mLastAlarmNotificationString.isNull() ) 381 if ( mLastAlarmNotificationString.isNull() )
376 return; 382 return;
377 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 383 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
378 384
379 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 385 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
380 mNextAlarmEventDateTime = QDateTime(); 386 mNextAlarmEventDateTime = QDateTime();
381// #ifndef DESKTOP_VERSION 387// #ifndef DESKTOP_VERSION
382// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 388// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
383// #endif 389// #endif
384} 390}
385 391
386QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 392QPtrList<Todo> CalendarLocal::todos( const QDate &date )
387{ 393{
388 QPtrList<Todo> todos; 394 QPtrList<Todo> todos;
389 395
390 Todo *todo; 396 Todo *todo;
391 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 397 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
398 if ( !todo->calEnabled() ) continue;
392 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 399 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
393 todos.append( todo ); 400 todos.append( todo );
394 } 401 }
395 } 402 }
396 403
397 filter()->apply( &todos ); 404 filter()->apply( &todos );
398 return todos; 405 return todos;
399} 406}
400void CalendarLocal::reInitAlarmSettings() 407void CalendarLocal::reInitAlarmSettings()
401{ 408{
402 if ( !mNextAlarmIncidence ) { 409 if ( !mNextAlarmIncidence ) {
403 nextAlarm( 1000 ); 410 nextAlarm( 1000 );
404 } 411 }
405 deRegisterAlarm(); 412 deRegisterAlarm();
406 mNextAlarmIncidence = 0; 413 mNextAlarmIncidence = 0;
407 checkAlarmForIncidence( 0, false ); 414 checkAlarmForIncidence( 0, false );
408 415
409} 416}
410 417
411 418
412 419
413QDateTime CalendarLocal::nextAlarm( int daysTo ) 420QDateTime CalendarLocal::nextAlarm( int daysTo )
414{ 421{
415 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 422 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
416 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 423 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
417 QDateTime next; 424 QDateTime next;
418 Event *e; 425 Event *e;
419 bool ok; 426 bool ok;
420 bool found = false; 427 bool found = false;
421 int offset; 428 int offset;
422 mNextAlarmIncidence = 0; 429 mNextAlarmIncidence = 0;
423 for( e = mEventList.first(); e; e = mEventList.next() ) { 430 for( e = mEventList.first(); e; e = mEventList.next() ) {
431 if ( !e->calEnabled() ) continue;
424 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 432 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
425 if ( ok ) { 433 if ( ok ) {
426 if ( next < nextA ) { 434 if ( next < nextA ) {
427 nextA = next; 435 nextA = next;
428 found = true; 436 found = true;
429 mNextSummary = e->summary(); 437 mNextSummary = e->summary();
430 mNextAlarmEventDateTime = next.addSecs(offset ) ; 438 mNextAlarmEventDateTime = next.addSecs(offset ) ;
431 mNextAlarmIncidence = (Incidence *) e; 439 mNextAlarmIncidence = (Incidence *) e;
432 } 440 }
433 } 441 }
434 } 442 }
435 Todo *t; 443 Todo *t;
436 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 444 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
445 if ( !t->calEnabled() ) continue;
437 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 446 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
438 if ( ok ) { 447 if ( ok ) {
439 if ( next < nextA ) { 448 if ( next < nextA ) {
440 nextA = next; 449 nextA = next;
441 found = true; 450 found = true;
442 mNextSummary = t->summary(); 451 mNextSummary = t->summary();
443 mNextAlarmEventDateTime = next.addSecs(offset ); 452 mNextAlarmEventDateTime = next.addSecs(offset );
444 mNextAlarmIncidence = (Incidence *) t; 453 mNextAlarmIncidence = (Incidence *) t;
445 } 454 }
446 } 455 }
447 } 456 }
448 if ( mNextAlarmIncidence ) { 457 if ( mNextAlarmIncidence ) {
449 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 458 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
450 mNextAlarmDateTime = nextA; 459 mNextAlarmDateTime = nextA;
451 } 460 }
452 return nextA; 461 return nextA;
453} 462}
454Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 463Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
455{ 464{
456 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 465 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
457} 466}
458 467
459Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 468Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
460{ 469{
461 470
462 Alarm::List alarms; 471 Alarm::List alarms;
463 472
464 Event *e; 473 Event *e;
465 474
466 for( e = mEventList.first(); e; e = mEventList.next() ) { 475 for( e = mEventList.first(); e; e = mEventList.next() ) {
476 if ( !e->calEnabled() ) continue;
467 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 477 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
468 else appendAlarms( alarms, e, from, to ); 478 else appendAlarms( alarms, e, from, to );
469 } 479 }
470 480
471 Todo *t; 481 Todo *t;
472 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 482 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
473 appendAlarms( alarms, t, from, to ); 483 if ( !t->calEnabled() ) continue;
484 appendAlarms( alarms, t, from, to );
474 } 485 }
475 486
476 return alarms; 487 return alarms;
477} 488}
478 489
479void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 490void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
480 const QDateTime &from, const QDateTime &to ) 491 const QDateTime &from, const QDateTime &to )
481{ 492{
482 QPtrList<Alarm> alarmList = incidence->alarms(); 493 QPtrList<Alarm> alarmList = incidence->alarms();
483 Alarm *alarm; 494 Alarm *alarm;
484 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 495 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
485// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 496// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
486// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 497// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
487 if ( alarm->enabled() ) { 498 if ( alarm->enabled() ) {
488 if ( alarm->time() >= from && alarm->time() <= to ) { 499 if ( alarm->time() >= from && alarm->time() <= to ) {
489 alarms.append( alarm ); 500 alarms.append( alarm );
490 } 501 }
491 } 502 }
492 } 503 }
493} 504}
494 505
495void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 506void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
496 Incidence *incidence, 507 Incidence *incidence,
497 const QDateTime &from, 508 const QDateTime &from,
498 const QDateTime &to ) 509 const QDateTime &to )
499{ 510{
500 511
501 QPtrList<Alarm> alarmList = incidence->alarms(); 512 QPtrList<Alarm> alarmList = incidence->alarms();
502 Alarm *alarm; 513 Alarm *alarm;
503 QDateTime qdt; 514 QDateTime qdt;
504 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 515 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
505 if (incidence->recursOn(from.date())) { 516 if (incidence->recursOn(from.date())) {
@@ -514,116 +525,118 @@ void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
514 } 525 }
515 } 526 }
516 } 527 }
517} 528}
518 529
519 530
520/****************************** PROTECTED METHODS ****************************/ 531/****************************** PROTECTED METHODS ****************************/
521 532
522// after changes are made to an event, this should be called. 533// after changes are made to an event, this should be called.
523void CalendarLocal::update( IncidenceBase *incidence ) 534void CalendarLocal::update( IncidenceBase *incidence )
524{ 535{
525 incidence->setSyncStatus( Event::SYNCMOD ); 536 incidence->setSyncStatus( Event::SYNCMOD );
526 incidence->setLastModified( QDateTime::currentDateTime() ); 537 incidence->setLastModified( QDateTime::currentDateTime() );
527 // we should probably update the revision number here, 538 // we should probably update the revision number here,
528 // or internally in the Event itself when certain things change. 539 // or internally in the Event itself when certain things change.
529 // need to verify with ical documentation. 540 // need to verify with ical documentation.
530 541
531 setModified( true ); 542 setModified( true );
532} 543}
533 544
534void CalendarLocal::insertEvent( Event *event ) 545void CalendarLocal::insertEvent( Event *event )
535{ 546{
536 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 547 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
537} 548}
538 549
539 550
540QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 551QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
541{ 552{
542 QPtrList<Event> eventList; 553 QPtrList<Event> eventList;
543 554
544 Event *event; 555 Event *event;
545 for( event = mEventList.first(); event; event = mEventList.next() ) { 556 for( event = mEventList.first(); event; event = mEventList.next() ) {
557 if ( !event->calEnabled() ) continue;
546 if ( event->doesRecur() ) { 558 if ( event->doesRecur() ) {
547 if ( event->isMultiDay() ) { 559 if ( event->isMultiDay() ) {
548 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 560 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
549 int i; 561 int i;
550 for ( i = 0; i <= extraDays; i++ ) { 562 for ( i = 0; i <= extraDays; i++ ) {
551 if ( event->recursOn( qd.addDays( -i ) ) ) { 563 if ( event->recursOn( qd.addDays( -i ) ) ) {
552 eventList.append( event ); 564 eventList.append( event );
553 break; 565 break;
554 } 566 }
555 } 567 }
556 } else { 568 } else {
557 if ( event->recursOn( qd ) ) 569 if ( event->recursOn( qd ) )
558 eventList.append( event ); 570 eventList.append( event );
559 } 571 }
560 } else { 572 } else {
561 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 573 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
562 eventList.append( event ); 574 eventList.append( event );
563 } 575 }
564 } 576 }
565 } 577 }
566 578
567 if ( !sorted ) { 579 if ( !sorted ) {
568 return eventList; 580 return eventList;
569 } 581 }
570 582
571 // kdDebug(5800) << "Sorting events for date\n" << endl; 583 // kdDebug(5800) << "Sorting events for date\n" << endl;
572 // now, we have to sort it based on dtStart.time() 584 // now, we have to sort it based on dtStart.time()
573 QPtrList<Event> eventListSorted; 585 QPtrList<Event> eventListSorted;
574 Event *sortEvent; 586 Event *sortEvent;
575 for ( event = eventList.first(); event; event = eventList.next() ) { 587 for ( event = eventList.first(); event; event = eventList.next() ) {
576 sortEvent = eventListSorted.first(); 588 sortEvent = eventListSorted.first();
577 int i = 0; 589 int i = 0;
578 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 590 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
579 { 591 {
580 i++; 592 i++;
581 sortEvent = eventListSorted.next(); 593 sortEvent = eventListSorted.next();
582 } 594 }
583 eventListSorted.insert( i, event ); 595 eventListSorted.insert( i, event );
584 } 596 }
585 return eventListSorted; 597 return eventListSorted;
586} 598}
587 599
588 600
589QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 601QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
590 bool inclusive ) 602 bool inclusive )
591{ 603{
592 Event *event = 0; 604 Event *event = 0;
593 605
594 QPtrList<Event> eventList; 606 QPtrList<Event> eventList;
595 607
596 // Get non-recurring events 608 // Get non-recurring events
597 for( event = mEventList.first(); event; event = mEventList.next() ) { 609 for( event = mEventList.first(); event; event = mEventList.next() ) {
610 if ( !event->calEnabled() ) continue;
598 if ( event->doesRecur() ) { 611 if ( event->doesRecur() ) {
599 QDate rStart = event->dtStart().date(); 612 QDate rStart = event->dtStart().date();
600 bool found = false; 613 bool found = false;
601 if ( inclusive ) { 614 if ( inclusive ) {
602 if ( rStart >= start && rStart <= end ) { 615 if ( rStart >= start && rStart <= end ) {
603 // Start date of event is in range. Now check for end date. 616 // Start date of event is in range. Now check for end date.
604 // if duration is negative, event recurs forever, so do not include it. 617 // if duration is negative, event recurs forever, so do not include it.
605 if ( event->recurrence()->duration() == 0 ) { // End date set 618 if ( event->recurrence()->duration() == 0 ) { // End date set
606 QDate rEnd = event->recurrence()->endDate(); 619 QDate rEnd = event->recurrence()->endDate();
607 if ( rEnd >= start && rEnd <= end ) { // End date within range 620 if ( rEnd >= start && rEnd <= end ) { // End date within range
608 found = true; 621 found = true;
609 } 622 }
610 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 623 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
611 // TODO: Calculate end date from duration. Should be done in Event 624 // TODO: Calculate end date from duration. Should be done in Event
612 // For now exclude all events with a duration. 625 // For now exclude all events with a duration.
613 } 626 }
614 } 627 }
615 } else { 628 } else {
616 bool founOne; 629 bool founOne;
617 QDate next = event->getNextOccurence( start, &founOne ).date(); 630 QDate next = event->getNextOccurence( start, &founOne ).date();
618 if ( founOne ) { 631 if ( founOne ) {
619 if ( next <= end ) { 632 if ( next <= end ) {
620 found = true; 633 found = true;
621 } 634 }
622 } 635 }
623 636
624 /* 637 /*
625 // crap !!! 638 // crap !!!
626 if ( rStart <= end ) { // Start date not after range 639 if ( rStart <= end ) { // Start date not after range
627 if ( rStart >= start ) { // Start date within range 640 if ( rStart >= start ) { // Start date within range
628 found = true; 641 found = true;
629 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 642 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
@@ -641,86 +654,129 @@ QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
641 } 654 }
642 */ 655 */
643 656
644 } 657 }
645 658
646 if ( found ) eventList.append( event ); 659 if ( found ) eventList.append( event );
647 } else { 660 } else {
648 QDate s = event->dtStart().date(); 661 QDate s = event->dtStart().date();
649 QDate e = event->dtEnd().date(); 662 QDate e = event->dtEnd().date();
650 663
651 if ( inclusive ) { 664 if ( inclusive ) {
652 if ( s >= start && e <= end ) { 665 if ( s >= start && e <= end ) {
653 eventList.append( event ); 666 eventList.append( event );
654 } 667 }
655 } else { 668 } else {
656 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { 669 if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) {
657 eventList.append( event ); 670 eventList.append( event );
658 } 671 }
659 } 672 }
660 } 673 }
661 } 674 }
662 675
663 return eventList; 676 return eventList;
664} 677}
665 678
666QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 679QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
667{ 680{
668 return rawEventsForDate( qdt.date() ); 681 return rawEventsForDate( qdt.date() );
669} 682}
670 683
671QPtrList<Event> CalendarLocal::rawEvents() 684QPtrList<Event> CalendarLocal::rawEvents()
672{ 685{
673 return mEventList; 686 QPtrList<Event> el;
687 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
688 if ( it->calEnabled() ) el.append( it );
689 return el;
674} 690}
675 691
676bool CalendarLocal::addJournal(Journal *journal) 692bool CalendarLocal::addJournal(Journal *journal)
677{ 693{
678 if ( journal->dtStart().isValid()) 694 if ( journal->dtStart().isValid())
679 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; 695 kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl;
680 else 696 else
681 kdDebug(5800) << "Adding Journal without a DTSTART" << endl; 697 kdDebug(5800) << "Adding Journal without a DTSTART" << endl;
682 698
683 mJournalList.append(journal); 699 mJournalList.append(journal);
684 700
685 journal->registerObserver( this ); 701 journal->registerObserver( this );
686 702
687 setModified( true ); 703 setModified( true );
688 704 journal->setCalID( mDefaultCalendar );
705 journal->setCalEnabled( true );
689 return true; 706 return true;
690} 707}
691 708
692void CalendarLocal::deleteJournal( Journal *journal ) 709void CalendarLocal::deleteJournal( Journal *journal )
693{ 710{
694 if ( mUndoIncidence ) delete mUndoIncidence; 711 if ( mUndoIncidence ) delete mUndoIncidence;
695 mUndoIncidence = journal->clone(); 712 mUndoIncidence = journal->clone();
696 mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); 713 mUndoIncidence->setSummary( mUndoIncidence->description().left(25));
697 if ( mJournalList.removeRef(journal) ) { 714 if ( mJournalList.removeRef(journal) ) {
698 setModified( true ); 715 setModified( true );
699 } 716 }
700} 717}
701 718
702Journal *CalendarLocal::journal( const QDate &date ) 719Journal *CalendarLocal::journal( const QDate &date )
703{ 720{
704// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 721// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
705 722
706 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 723 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
707 if ( it->dtStart().date() == date ) 724 if ( it->calEnabled() && it->dtStart().date() == date )
708 return it; 725 return it;
709 726
710 return 0; 727 return 0;
711} 728}
712 729
713Journal *CalendarLocal::journal( const QString &uid ) 730Journal *CalendarLocal::journal( const QString &uid )
714{ 731{
715 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 732 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
716 if ( it->uid() == uid ) 733 if ( it->calEnabled() && it->uid() == uid )
717 return it; 734 return it;
718 735
719 return 0; 736 return 0;
720} 737}
721 738
722QPtrList<Journal> CalendarLocal::journals() 739QPtrList<Journal> CalendarLocal::journals()
723{ 740{
724 return mJournalList; 741 QPtrList<Journal> el;
742 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
743 if ( it->calEnabled() ) el.append( it );
744 return el;
725} 745}
726 746
747void CalendarLocal::setCalendarEnabled( int id, bool enable )
748{
749 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
750 if ( it->calID() == id ) it->setCalEnabled( enable );
751
752 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
753 if ( it->calID() == id ) it->setCalEnabled( enable );
754
755 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
756 if ( it->calID() == id ) it->setCalEnabled( enable );
757
758}
759void CalendarLocal::setAlarmEnabled( int id, bool enable )
760{
761 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
762 if ( it->calID() == id ) it->setAlarmEnabled( enable );
763
764 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
765 if ( it->calID() == id ) it->setAlarmEnabled( enable );
766
767 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
768 if ( it->calID() == id ) it->setAlarmEnabled( enable );
769
770}
771void CalendarLocal::setDefaultCalendarEnabledOnly()
772{
773 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
774 it->setCalEnabled( it->calID() == mDefaultCalendar );
775
776 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
777 it->setCalEnabled( it->calID() == mDefaultCalendar);
778
779 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
780 it->setCalEnabled( it->calID() == mDefaultCalendar);
781
782}