diff options
Diffstat (limited to 'libkcal/calendar.cpp')
-rw-r--r-- | libkcal/calendar.cpp | 185 |
1 files changed, 184 insertions, 1 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index c3c3a9e65..711cdc12a 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp @@ -50,6 +50,7 @@ Calendar::Calendar( const TQString &timeZoneId ) void Calendar::init() { + mException = 0; mNewObserver = false; mObserversEnabled = true; @@ -66,9 +67,27 @@ void Calendar::init() Calendar::~Calendar() { + clearException(); delete mDefaultFilter; } +void Calendar::clearException() +{ + delete mException; + mException = 0; +} + +ErrorFormat *Calendar::exception() const +{ + return mException; +} + +void Calendar::setException( ErrorFormat *e ) +{ + delete mException; + mException = e; +} + const Person &Calendar::getOwner() const { return mOwner; @@ -122,6 +141,16 @@ CalFilter *Calendar::filter() return mFilter; } +void Calendar::beginBatchAdding() +{ + emit batchAddingBegins(); +} + +void Calendar::endBatchAdding() +{ + emit batchAddingEnds(); +} + TQStringList Calendar::categories() { Incidence::List rawInc( rawIncidences() ); @@ -161,7 +190,7 @@ Event::List Calendar::sortEvents( Event::List *eventList, SortDirection sortDirection ) { Event::List eventListSorted; - Event::List tempList, t; + Event::List tempList; Event::List alphaList; Event::List::Iterator sortIt; Event::List::Iterator eit; @@ -177,6 +206,10 @@ Event::List Calendar::sortEvents( Event::List *eventList, case EventSortStartDate: alphaList = sortEvents( eventList, EventSortSummary, sortDirection ); for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) { + if ( (*eit)->doesFloat() ) { + tempList.append( *eit ); + continue; + } sortIt = eventListSorted.begin(); if ( sortDirection == SortDirectionAscending ) { while ( sortIt != eventListSorted.end() && @@ -191,6 +224,14 @@ Event::List Calendar::sortEvents( Event::List *eventList, } eventListSorted.insert( sortIt, *eit ); } + if ( sortDirection == SortDirectionAscending ) { + // Prepend the list of all-day Events + tempList += eventListSorted; + eventListSorted = tempList; + } else { + // Append the list of all-day Events + eventListSorted += tempList; + } break; case EventSortEndDate: @@ -245,7 +286,149 @@ Event::List Calendar::sortEvents( Event::List *eventList, } return eventListSorted; +} + +Event::List Calendar::sortEventsForDate( Event::List *eventList, + const TQDate &date, + EventSortField sortField, + SortDirection sortDirection ) +{ + Event::List eventListSorted; + Event::List tempList; + Event::List alphaList; + Event::List::Iterator sortIt; + Event::List::Iterator eit; + + switch( sortField ) { + case EventSortStartDate: + alphaList = sortEvents( eventList, EventSortSummary, sortDirection ); + for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) { + if ( (*eit)->doesFloat() ) { + tempList.append( *eit ); + continue; + } + sortIt = eventListSorted.begin(); + if ( sortDirection == SortDirectionAscending ) { + while ( sortIt != eventListSorted.end() ) { + if ( !(*eit)->doesRecur() ) { + if ( (*eit)->dtStart().time() >= (*sortIt)->dtStart().time() ) { + ++sortIt; + } else { + break; + } + } else { + if ( (*eit)->recursOn( date ) ) { + if ( (*eit)->dtStart().time() >= (*sortIt)->dtStart().time() ) { + ++sortIt; + } else { + break; + } + } else { + ++sortIt; + } + } + } + } else { // descending + while ( sortIt != eventListSorted.end() ) { + if ( !(*eit)->doesRecur() ) { + if ( (*eit)->dtStart().time() < (*sortIt)->dtStart().time() ) { + ++sortIt; + } else { + break; + } + } else { + if ( (*eit)->recursOn( date ) ) { + if ( (*eit)->dtStart().time() < (*sortIt)->dtStart().time() ) { + ++sortIt; + } else { + break; + } + } else { + ++sortIt; + } + } + } + } + eventListSorted.insert( sortIt, *eit ); + } + if ( sortDirection == SortDirectionAscending ) { + // Prepend the list of all-day Events + tempList += eventListSorted; + eventListSorted = tempList; + } else { + // Append the list of all-day Events + eventListSorted += tempList; + } + break; + case EventSortEndDate: + alphaList = sortEvents( eventList, EventSortSummary, sortDirection ); + for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) { + if ( (*eit)->hasEndDate() ) { + sortIt = eventListSorted.begin(); + if ( sortDirection == SortDirectionAscending ) { + while ( sortIt != eventListSorted.end() ) { + if ( !(*eit)->doesRecur() ) { + if ( (*eit)->dtEnd().time() >= (*sortIt)->dtEnd().time() ) { + ++sortIt; + } else { + break; + } + } else { + if ( (*eit)->recursOn( date ) ) { + if ( (*eit)->dtEnd().time() >= (*sortIt)->dtEnd().time() ) { + ++sortIt; + } else { + break; + } + } else { + ++sortIt; + } + } + } + } else { // descending + while ( sortIt != eventListSorted.end() ) { + if ( !(*eit)->doesRecur() ) { + if ( (*eit)->dtEnd().time() < (*sortIt)->dtEnd().time() ) { + ++sortIt; + } else { + break; + } + } else { + if ( (*eit)->recursOn( date ) ) { + if ( (*eit)->dtEnd().time() < (*sortIt)->dtEnd().time() ) { + ++sortIt; + } else { + break; + } + } else { + ++sortIt; + } + } + } + } + } else { + // Keep a list of the Events without End DateTimes + tempList.append( *eit ); + } + eventListSorted.insert( sortIt, *eit ); + } + if ( sortDirection == SortDirectionAscending ) { + // Prepend the list of Events without End DateTimes + tempList += eventListSorted; + eventListSorted = tempList; + } else { + // Append the list of Events without End DateTimes + eventListSorted += tempList; + } + break; + + default: + eventListSorted = sortEvents( eventList, sortField, sortDirection ); + break; + } + + return eventListSorted; } Event::List Calendar::events( const TQDate &date, |