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
@@ -150,6 +150,8 @@ bool CalendarLocal::addEvent( Event *event )
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}
@@ -170,7 +172,7 @@ Event *CalendarLocal::event( const QString &uid )
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 }
@@ -198,7 +200,8 @@ bool CalendarLocal::addTodo( Todo *todo )
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
@@ -216,13 +219,16 @@ void CalendarLocal::deleteTodo( Todo *todo )
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;
@@ -267,7 +273,7 @@ Event *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;
@@ -276,7 +282,7 @@ Todo *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;
@@ -389,6 +395,7 @@ QPtrList<Todo> CalendarLocal::todos( const QDate &date )
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 }
@@ -421,6 +428,7 @@ QDateTime CalendarLocal::nextAlarm( int daysTo )
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 ) {
@@ -434,6 +442,7 @@ QDateTime CalendarLocal::nextAlarm( int daysTo )
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 ) {
@@ -464,13 +473,15 @@ Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
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;
@@ -543,6 +554,7 @@ QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
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() );
@@ -595,6 +607,7 @@ QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
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;
@@ -670,7 +683,10 @@ QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
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)
@@ -685,7 +701,8 @@ bool CalendarLocal::addJournal(Journal *journal)
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
@@ -704,7 +721,7 @@ Journal *CalendarLocal::journal( const QDate &date )
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;
@@ -713,7 +730,7 @@ Journal *CalendarLocal::journal( const QDate &date )
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;
@@ -721,6 +738,45 @@ Journal *CalendarLocal::journal( const QString &uid )
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}