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
@@ -147,12 +147,14 @@ bool 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{
@@ -167,13 +169,13 @@ void CalendarLocal::deleteEvent( Event *event )
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}
@@ -195,13 +197,14 @@ bool CalendarLocal::addTodo( Todo *todo )
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
@@ -213,19 +216,22 @@ void CalendarLocal::deleteTodo( Todo *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{
@@ -264,22 +270,22 @@ QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
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{
@@ -386,12 +392,13 @@ void CalendarLocal::deRegisterAlarm()
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 );
@@ -418,12 +425,13 @@ QDateTime CalendarLocal::nextAlarm( int daysTo )
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();
@@ -431,12 +439,13 @@ QDateTime CalendarLocal::nextAlarm( int daysTo )
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();
@@ -461,19 +470,21 @@ Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
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,
@@ -540,12 +551,13 @@ void CalendarLocal::insertEvent( Event *event )
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 ) ) ) {
@@ -592,12 +604,13 @@ QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
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.
@@ -667,13 +680,16 @@ QPtrList<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;
@@ -682,13 +698,14 @@ bool CalendarLocal::addJournal(Journal *journal)
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;
@@ -701,26 +718,65 @@ void CalendarLocal::deleteJournal( Journal *journal )
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}