-rw-r--r-- | libkcal/calendarlocal.cpp | 80 |
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 @@ -145,16 +145,18 @@ bool CalendarLocal::addEventNoDup( Event *event ) bool CalendarLocal::addEvent( Event *event ) { insertEvent( event ); event->registerObserver( this ); setModified( true ); + event->setCalID( mDefaultCalendar ); + event->setCalEnabled( true ); return true; } void CalendarLocal::deleteEvent( Event *event ) { if ( mUndoIncidence ) delete mUndoIncidence; mUndoIncidence = event->clone(); @@ -165,17 +167,17 @@ void CalendarLocal::deleteEvent( Event *event ) Event *CalendarLocal::event( const QString &uid ) { Event *event; for ( event = mEventList.first(); event; event = mEventList.next() ) { - if ( event->uid() == uid ) { + if ( event->uid() == uid && event->calEnabled() ) { return event; } } return 0; } bool CalendarLocal::addTodoNoDup( Todo *todo ) { @@ -193,17 +195,18 @@ bool CalendarLocal::addTodo( Todo *todo ) mTodoList.append( todo ); todo->registerObserver( this ); // Set up subtask relations setupRelations( todo ); setModified( true ); - + todo->setCalID( mDefaultCalendar ); + todo->setCalEnabled( true ); return true; } void CalendarLocal::deleteTodo( Todo *todo ) { // Handle orphaned children if ( mUndoIncidence ) delete mUndoIncidence; removeRelations( todo ); @@ -211,23 +214,26 @@ void CalendarLocal::deleteTodo( Todo *todo ) if ( mTodoList.removeRef( todo ) ) { setModified( true ); } } QPtrList<Todo> CalendarLocal::rawTodos() { - return mTodoList; + QPtrList<Todo> el; + for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) + if ( it->calEnabled() ) el.append( it ); + return el; } Todo *CalendarLocal::todo( QString syncProf, QString id ) { Todo *todo; for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { - if ( todo->getID( syncProf ) == id ) return todo; + if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; } return 0; } void CalendarLocal::removeSyncInfo( QString syncProfile) { QPtrList<Incidence> all = rawIncidences() ; Incidence *inc; @@ -262,26 +268,26 @@ QPtrList<Event> CalendarLocal::getExternLastSyncEvents() return el; } Event *CalendarLocal::event( QString syncProf, QString id ) { Event *todo; for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { - if ( todo->getID( syncProf ) == id ) return todo; + if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; } return 0; } Todo *CalendarLocal::todo( const QString &uid ) { Todo *todo; for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { - if ( todo->uid() == uid ) return todo; + if ( todo->calEnabled() && todo->uid() == uid ) return todo; } return 0; } QString CalendarLocal::nextSummary() const { return mNextSummary; } @@ -384,16 +390,17 @@ void CalendarLocal::deRegisterAlarm() } QPtrList<Todo> CalendarLocal::todos( const QDate &date ) { QPtrList<Todo> todos; Todo *todo; for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { + if ( !todo->calEnabled() ) continue; if ( todo->hasDueDate() && todo->dtDue().date() == date ) { todos.append( todo ); } } filter()->apply( &todos ); return todos; } @@ -416,29 +423,31 @@ QDateTime CalendarLocal::nextAlarm( int daysTo ) QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); QDateTime next; Event *e; bool ok; bool found = false; int offset; mNextAlarmIncidence = 0; for( e = mEventList.first(); e; e = mEventList.next() ) { + if ( !e->calEnabled() ) continue; next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; if ( ok ) { if ( next < nextA ) { nextA = next; found = true; mNextSummary = e->summary(); mNextAlarmEventDateTime = next.addSecs(offset ) ; mNextAlarmIncidence = (Incidence *) e; } } } Todo *t; for( t = mTodoList.first(); t; t = mTodoList.next() ) { + if ( !t->calEnabled() ) continue; next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; if ( ok ) { if ( next < nextA ) { nextA = next; found = true; mNextSummary = t->summary(); mNextAlarmEventDateTime = next.addSecs(offset ); mNextAlarmIncidence = (Incidence *) t; @@ -459,23 +468,25 @@ Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) { Alarm::List alarms; Event *e; for( e = mEventList.first(); e; e = mEventList.next() ) { + if ( !e->calEnabled() ) continue; if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); else appendAlarms( alarms, e, from, to ); } Todo *t; for( t = mTodoList.first(); t; t = mTodoList.next() ) { - appendAlarms( alarms, t, from, to ); + if ( !t->calEnabled() ) continue; + appendAlarms( alarms, t, from, to ); } return alarms; } void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, const QDateTime &from, const QDateTime &to ) { @@ -538,16 +549,17 @@ void CalendarLocal::insertEvent( Event *event ) QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) { QPtrList<Event> eventList; Event *event; for( event = mEventList.first(); event; event = mEventList.next() ) { + if ( !event->calEnabled() ) continue; if ( event->doesRecur() ) { if ( event->isMultiDay() ) { int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); int i; for ( i = 0; i <= extraDays; i++ ) { if ( event->recursOn( qd.addDays( -i ) ) ) { eventList.append( event ); break; @@ -590,16 +602,17 @@ QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, bool inclusive ) { Event *event = 0; QPtrList<Event> eventList; // Get non-recurring events for( event = mEventList.first(); event; event = mEventList.next() ) { + if ( !event->calEnabled() ) continue; if ( event->doesRecur() ) { QDate rStart = event->dtStart().date(); bool found = false; if ( inclusive ) { if ( rStart >= start && rStart <= end ) { // Start date of event is in range. Now check for end date. // if duration is negative, event recurs forever, so do not include it. if ( event->recurrence()->duration() == 0 ) { // End date set @@ -665,32 +678,36 @@ QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) { return rawEventsForDate( qdt.date() ); } QPtrList<Event> CalendarLocal::rawEvents() { - return mEventList; + QPtrList<Event> el; + for ( Event *it = mEventList.first(); it; it = mEventList.next() ) + if ( it->calEnabled() ) el.append( it ); + return el; } bool CalendarLocal::addJournal(Journal *journal) { if ( journal->dtStart().isValid()) kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; else kdDebug(5800) << "Adding Journal without a DTSTART" << endl; mJournalList.append(journal); journal->registerObserver( this ); setModified( true ); - + journal->setCalID( mDefaultCalendar ); + journal->setCalEnabled( true ); return true; } void CalendarLocal::deleteJournal( Journal *journal ) { if ( mUndoIncidence ) delete mUndoIncidence; mUndoIncidence = journal->clone(); mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); @@ -699,28 +716,67 @@ void CalendarLocal::deleteJournal( Journal *journal ) } } Journal *CalendarLocal::journal( const QDate &date ) { // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) - if ( it->dtStart().date() == date ) + if ( it->calEnabled() && it->dtStart().date() == date ) return it; return 0; } Journal *CalendarLocal::journal( const QString &uid ) { for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) - if ( it->uid() == uid ) + if ( it->calEnabled() && it->uid() == uid ) return it; return 0; } QPtrList<Journal> CalendarLocal::journals() { - return mJournalList; + QPtrList<Journal> el; + for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) + if ( it->calEnabled() ) el.append( it ); + return el; } +void CalendarLocal::setCalendarEnabled( int id, bool enable ) +{ + for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) + if ( it->calID() == id ) it->setCalEnabled( enable ); + + for ( Event *it = mEventList.first(); it; it = mEventList.next() ) + if ( it->calID() == id ) it->setCalEnabled( enable ); + + for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) + if ( it->calID() == id ) it->setCalEnabled( enable ); + +} +void CalendarLocal::setAlarmEnabled( int id, bool enable ) +{ + for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) + if ( it->calID() == id ) it->setAlarmEnabled( enable ); + + for ( Event *it = mEventList.first(); it; it = mEventList.next() ) + if ( it->calID() == id ) it->setAlarmEnabled( enable ); + + for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) + if ( it->calID() == id ) it->setAlarmEnabled( enable ); + +} +void CalendarLocal::setDefaultCalendarEnabledOnly() +{ + for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) + it->setCalEnabled( it->calID() == mDefaultCalendar ); + + for ( Event *it = mEventList.first(); it; it = mEventList.next() ) + it->setCalEnabled( it->calID() == mDefaultCalendar); + + for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) + it->setCalEnabled( it->calID() == mDefaultCalendar); + +} |