36 #include "exceptions.h"
37 #include "calfilter.h"
55 mObserversEnabled =
true;
61 mFilter = mDefaultFilter;
65 setOwner(
Person( i18n(
"Unknown Name" ), i18n(
"unknown@nowhere" ) ) );
71 delete mDefaultFilter;
135 mFilter = mDefaultFilter;
157 TQStringList cats, thisCats;
160 for ( Incidence::List::ConstIterator i = rawInc.constBegin();
161 i != rawInc.constEnd(); ++i ) {
162 thisCats = (*i)->categories();
163 for ( TQStringList::ConstIterator si = thisCats.constBegin();
164 si != thisCats.constEnd(); ++si ) {
165 if ( cats.find( *si ) == cats.end() ) {
195 Event::List::Iterator sortIt;
196 Event::List::Iterator eit;
201 switch( sortField ) {
203 eventListSorted = *eventList;
208 for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) {
209 if ( (*eit)->doesFloat() ) {
210 tempList.append( *eit );
213 sortIt = eventListSorted.begin();
215 while ( sortIt != eventListSorted.end() &&
216 (*eit)->dtStart() >= (*sortIt)->dtStart() ) {
220 while ( sortIt != eventListSorted.end() &&
221 (*eit)->dtStart() < (*sortIt)->dtStart() ) {
225 eventListSorted.insert( sortIt, *eit );
229 tempList += eventListSorted;
230 eventListSorted = tempList;
233 eventListSorted += tempList;
239 for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) {
240 if ( (*eit)->hasEndDate() ) {
241 sortIt = eventListSorted.begin();
243 while ( sortIt != eventListSorted.end() &&
244 (*eit)->dtEnd() >= (*sortIt)->dtEnd() ) {
248 while ( sortIt != eventListSorted.end() &&
249 (*eit)->dtEnd() < (*sortIt)->dtEnd() ) {
255 tempList.append( *eit );
257 eventListSorted.insert( sortIt, *eit );
261 eventListSorted += tempList;
264 tempList += eventListSorted;
265 eventListSorted = tempList;
270 for ( eit = eventList->begin(); eit != eventList->end(); ++eit ) {
271 sortIt = eventListSorted.begin();
273 while ( sortIt != eventListSorted.end() &&
274 (*eit)->summary() >= (*sortIt)->summary() ) {
278 while ( sortIt != eventListSorted.end() &&
279 (*eit)->summary() < (*sortIt)->summary() ) {
283 eventListSorted.insert( sortIt, *eit );
288 return eventListSorted;
299 Event::List::Iterator sortIt;
300 Event::List::Iterator eit;
302 switch( sortField ) {
305 for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) {
306 if ( (*eit)->doesFloat() ) {
307 tempList.append( *eit );
310 sortIt = eventListSorted.begin();
312 while ( sortIt != eventListSorted.end() ) {
313 if ( !(*eit)->doesRecur() ) {
314 if ( (*eit)->dtStart().time() >= (*sortIt)->dtStart().time() ) {
320 if ( (*eit)->recursOn( date ) ) {
321 if ( (*eit)->dtStart().time() >= (*sortIt)->dtStart().time() ) {
332 while ( sortIt != eventListSorted.end() ) {
333 if ( !(*eit)->doesRecur() ) {
334 if ( (*eit)->dtStart().time() < (*sortIt)->dtStart().time() ) {
340 if ( (*eit)->recursOn( date ) ) {
341 if ( (*eit)->dtStart().time() < (*sortIt)->dtStart().time() ) {
352 eventListSorted.insert( sortIt, *eit );
356 tempList += eventListSorted;
357 eventListSorted = tempList;
360 eventListSorted += tempList;
366 for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) {
367 if ( (*eit)->hasEndDate() ) {
368 sortIt = eventListSorted.begin();
370 while ( sortIt != eventListSorted.end() ) {
371 if ( !(*eit)->doesRecur() ) {
372 if ( (*eit)->dtEnd().time() >= (*sortIt)->dtEnd().time() ) {
378 if ( (*eit)->recursOn( date ) ) {
379 if ( (*eit)->dtEnd().time() >= (*sortIt)->dtEnd().time() ) {
390 while ( sortIt != eventListSorted.end() ) {
391 if ( !(*eit)->doesRecur() ) {
392 if ( (*eit)->dtEnd().time() < (*sortIt)->dtEnd().time() ) {
398 if ( (*eit)->recursOn( date ) ) {
399 if ( (*eit)->dtEnd().time() < (*sortIt)->dtEnd().time() ) {
412 tempList.append( *eit );
414 eventListSorted.insert( sortIt, *eit );
418 tempList += eventListSorted;
419 eventListSorted = tempList;
422 eventListSorted += tempList;
427 eventListSorted =
sortEvents( eventList, sortField, sortDirection );
431 return eventListSorted;
439 mFilter->
apply( &el );
446 mFilter->
apply( &el );
454 mFilter->
apply( &el );
462 mFilter->
apply( &el );
470 return incidence->
accept(v);
480 IncidenceListIterator it;
488 IncidenceListIterator it;
489 for ( it = il.begin(); it != il.end(); ++it ) {
496 bool result = incidence->
accept( v );
509 if ( !incidence || !incidence->
doesRecur() )
525 if ( duration > 0 ) {
526 int doneduration = recur->
durationTo( date.addDays(-1) );
527 if ( doneduration >= duration ) {
528 kdDebug(5850) <<
"The dissociated event already occurred more often "
529 <<
"than it was supposed to ever occur. ERROR!" << endl;
537 if ( incidence->type() ==
"Event" ) {
539 TQDateTime start( ev->
dtStart() );
540 int daysTo = start.date().daysTo( date );
543 }
else if ( incidence->type() ==
"Todo" ) {
544 Todo *td =
static_cast<Todo *
>( newInc );
545 bool haveOffset =
false;
548 TQDateTime due( td->
dtDue() );
549 daysTo = due.date().daysTo( date );
550 td->
setDtDue( due.addDays( daysTo ), true );
554 TQDateTime start( td->
dtStart() );
556 daysTo = start.date().daysTo( date );
564 recur->addExDate( date );
590 Incidence::List::iterator it = incidences.begin();
591 for ( ; it != incidences.end(); ++it )
592 if ( (*it)->schedulingID() == UID )
593 result.append( *it );
600 Incidence::List::iterator it = incidences.begin();
601 for ( ; it != incidences.end(); ++it )
602 if ( (*it)->schedulingID() == UID )
616 Todo::List::Iterator sortIt;
617 Todo::List::Iterator eit;
624 switch( sortField ) {
626 todoListSorted = *todoList;
631 for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) {
632 if ( (*eit)->hasStartDate() ) {
633 sortIt = todoListSorted.begin();
635 while ( sortIt != todoListSorted.end() &&
636 (*eit)->dtStart() >= (*sortIt)->dtStart() ) {
640 while ( sortIt != todoListSorted.end() &&
641 (*eit)->dtStart() < (*sortIt)->dtStart() ) {
645 todoListSorted.insert( sortIt, *eit );
648 tempList.append( *eit );
653 todoListSorted += tempList;
656 tempList += todoListSorted;
657 todoListSorted = tempList;
663 for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) {
664 if ( (*eit)->hasDueDate() ) {
665 sortIt = todoListSorted.begin();
667 while ( sortIt != todoListSorted.end() &&
668 (*eit)->dtDue() >= (*sortIt)->dtDue() ) {
672 while ( sortIt != todoListSorted.end() &&
673 (*eit)->dtDue() < (*sortIt)->dtDue() ) {
677 todoListSorted.insert( sortIt, *eit );
680 tempList.append( *eit );
685 todoListSorted += tempList;
688 tempList += todoListSorted;
689 todoListSorted = tempList;
695 for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) {
696 sortIt = todoListSorted.begin();
698 while ( sortIt != todoListSorted.end() &&
699 (*eit)->priority() >= (*sortIt)->priority() ) {
703 while ( sortIt != todoListSorted.end() &&
704 (*eit)->priority() < (*sortIt)->priority() ) {
708 todoListSorted.insert( sortIt, *eit );
714 for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) {
715 sortIt = todoListSorted.begin();
717 while ( sortIt != todoListSorted.end() &&
718 (*eit)->percentComplete() >= (*sortIt)->percentComplete() ) {
722 while ( sortIt != todoListSorted.end() &&
723 (*eit)->percentComplete() < (*sortIt)->percentComplete() ) {
727 todoListSorted.insert( sortIt, *eit );
732 for ( eit = todoList->begin(); eit != todoList->end(); ++eit ) {
733 sortIt = todoListSorted.begin();
735 while ( sortIt != todoListSorted.end() &&
736 (*eit)->summary() >= (*sortIt)->summary() ) {
740 while ( sortIt != todoListSorted.end() &&
741 (*eit)->summary() < (*sortIt)->summary() ) {
745 todoListSorted.insert( sortIt, *eit );
750 return todoListSorted;
757 mFilter->
apply( &tl );
764 mFilter->
apply( &el );
773 Journal::List::Iterator sortIt;
774 Journal::List::Iterator eit;
776 switch( sortField ) {
778 journalListSorted = *journalList;
782 for ( eit = journalList->begin(); eit != journalList->end(); ++eit ) {
783 sortIt = journalListSorted.begin();
785 while ( sortIt != journalListSorted.end() &&
786 (*eit)->dtStart() >= (*sortIt)->dtStart() ) {
790 while ( sortIt != journalListSorted.end() &&
791 (*eit)->dtStart() < (*sortIt)->dtStart() ) {
795 journalListSorted.insert( sortIt, *eit );
800 for ( eit = journalList->begin(); eit != journalList->end(); ++eit ) {
801 sortIt = journalListSorted.begin();
803 while ( sortIt != journalListSorted.end() &&
804 (*eit)->summary() >= (*sortIt)->summary() ) {
808 while ( sortIt != journalListSorted.end() &&
809 (*eit)->summary() < (*sortIt)->summary() ) {
813 journalListSorted.insert( sortIt, *eit );
818 return journalListSorted;
825 mFilter->
apply( &jl );
832 mFilter->
apply( &el );
840 if ( !forincidence )
return;
842 TQString uid = forincidence->
uid();
845 while (
Incidence* i = mOrphans[ uid ] ) {
846 mOrphans.remove( uid );
847 i->setRelatedTo( forincidence );
849 mOrphanUids.remove( i->uid() );
865 mOrphans.insert( forincidence->
relatedToUid(), forincidence );
866 mOrphanUids.insert( forincidence->
uid(), forincidence );
875 kdDebug(5800) <<
"Warning: Calendar::removeRelations( 0 )!\n";
880 TQString uid = incidence->
uid();
883 Incidence::List::ConstIterator it;
884 for ( it = relations.begin(); it != relations.end(); ++it ) {
886 if ( !mOrphanUids.find( i->
uid() ) ) {
887 mOrphans.insert( uid, i );
888 mOrphanUids.insert( i->
uid(), i );
899 if ( mOrphanUids.remove( uid ) ) {
909 TQStringList relatedToUids;
912 for ( TQDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
913 if ( it.current()->uid() == uid ) {
914 relatedToUids << it.currentKey();
919 for ( TQStringList::Iterator uidit = relatedToUids.begin();
920 uidit != relatedToUids.end(); ++uidit ) {
923 while(
Incidence* i = mOrphans[ *uidit ] ) {
924 mOrphans.remove( *uidit );
925 if ( i != incidence ) tempList.append( i );
928 for ( Incidence::List::Iterator incit = tempList.begin();
929 incit != tempList.end(); ++incit ) {
930 mOrphans.insert( *uidit, *incit );
938 if( !mObservers.contains( observer ) )
939 mObservers.append( observer );
945 mObservers.remove( observer );
950 if ( modified != mModified || mNewObserver ) {
951 mNewObserver =
false;
953 for ( observer = mObservers.first(); observer;
954 observer = mObservers.next() ) {
957 mModified = modified;
977 if ( !mObserversEnabled )
981 for ( observer = mObservers.first(); observer;
982 observer = mObservers.next() ) {
989 if ( !mObserversEnabled )
993 for ( observer = mObservers.first(); observer;
994 observer = mObservers.next() ) {
1001 if ( !mObserversEnabled )
1005 for ( observer = mObservers.first(); observer;
1006 observer = mObservers.next() ) {
1032 Event::List::ConstIterator it1;
1033 for ( it1 = events.begin(); it1 != events.end(); ++it1 )
1034 incidences.append( *it1 );
1036 Todo::List::ConstIterator it2;
1037 for ( it2 = todos.begin(); it2 != todos.end(); ++it2 )
1038 incidences.append( *it2 );
1040 Journal::List::ConstIterator it3;
1041 for ( it3 = journals.begin(); it3 != journals.end(); ++it3 )
1042 incidences.append( *it3 );
1059 mObserversEnabled = enabled;
1062 #include "calendar.moc"