34 #include <tdelocale.h>
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;
482 if (it != il.end()) {
490 IncidenceListIterator it;
491 for ( it = il.begin(); it != il.end(); ++it ) {
498 bool result = incidence->
accept( v );
511 if ( !incidence || !incidence->
doesRecur() )
527 if ( duration > 0 ) {
528 int doneduration = recur->
durationTo( date.addDays(-1) );
529 if ( doneduration >= duration ) {
530 kdDebug(5850) <<
"The dissociated event already occurred more often "
531 <<
"than it was supposed to ever occur. ERROR!" << endl;
539 if ( incidence->type() ==
"Event" ) {
541 TQDateTime start( ev->
dtStart() );
542 int daysTo = start.date().daysTo( date );
545 }
else if ( incidence->type() ==
"Todo" ) {
546 Todo *td =
static_cast<Todo *
>( newInc );
547 bool haveOffset =
false;
550 TQDateTime due( td->
dtDue() );
551 daysTo = due.date().daysTo( date );
552 td->
setDtDue( due.addDays( daysTo ), true );
556 TQDateTime start( td->
dtStart() );
558 daysTo = start.date().daysTo( date );
566 recur->addExDate( date );
592 Incidence::List::iterator it = incidences.begin();
593 for ( ; it != incidences.end(); ++it )
594 if ( (*it)->schedulingID() == UID )
595 result.append( *it );
602 Incidence::List::iterator it = incidences.begin();
603 for ( ; it != incidences.end(); ++it )
604 if ( (*it)->schedulingID() == UID )
618 Todo::List::Iterator sortIt;
619 Todo::List::Iterator eit;
626 switch( sortField ) {
628 todoListSorted = *todoList;
633 for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) {
634 if ( (*eit)->hasStartDate() ) {
635 sortIt = todoListSorted.begin();
637 while ( sortIt != todoListSorted.end() &&
638 (*eit)->dtStart() >= (*sortIt)->dtStart() ) {
642 while ( sortIt != todoListSorted.end() &&
643 (*eit)->dtStart() < (*sortIt)->dtStart() ) {
647 todoListSorted.insert( sortIt, *eit );
650 tempList.append( *eit );
655 todoListSorted += tempList;
658 tempList += todoListSorted;
659 todoListSorted = tempList;
665 for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) {
666 if ( (*eit)->hasDueDate() ) {
667 sortIt = todoListSorted.begin();
669 while ( sortIt != todoListSorted.end() &&
670 (*eit)->dtDue() >= (*sortIt)->dtDue() ) {
674 while ( sortIt != todoListSorted.end() &&
675 (*eit)->dtDue() < (*sortIt)->dtDue() ) {
679 todoListSorted.insert( sortIt, *eit );
682 tempList.append( *eit );
687 todoListSorted += tempList;
690 tempList += todoListSorted;
691 todoListSorted = tempList;
697 for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) {
698 sortIt = todoListSorted.begin();
700 while ( sortIt != todoListSorted.end() &&
701 (*eit)->priority() >= (*sortIt)->priority() ) {
705 while ( sortIt != todoListSorted.end() &&
706 (*eit)->priority() < (*sortIt)->priority() ) {
710 todoListSorted.insert( sortIt, *eit );
716 for ( eit = alphaList.begin(); eit != alphaList.end(); ++eit ) {
717 sortIt = todoListSorted.begin();
719 while ( sortIt != todoListSorted.end() &&
720 (*eit)->percentComplete() >= (*sortIt)->percentComplete() ) {
724 while ( sortIt != todoListSorted.end() &&
725 (*eit)->percentComplete() < (*sortIt)->percentComplete() ) {
729 todoListSorted.insert( sortIt, *eit );
734 for ( eit = todoList->begin(); eit != todoList->end(); ++eit ) {
735 sortIt = todoListSorted.begin();
737 while ( sortIt != todoListSorted.end() &&
738 (*eit)->summary() >= (*sortIt)->summary() ) {
742 while ( sortIt != todoListSorted.end() &&
743 (*eit)->summary() < (*sortIt)->summary() ) {
747 todoListSorted.insert( sortIt, *eit );
752 return todoListSorted;
759 mFilter->
apply( &tl );
766 mFilter->
apply( &el );
775 Journal::List::Iterator sortIt;
776 Journal::List::Iterator eit;
778 switch( sortField ) {
780 journalListSorted = *journalList;
784 for ( eit = journalList->begin(); eit != journalList->end(); ++eit ) {
785 sortIt = journalListSorted.begin();
787 while ( sortIt != journalListSorted.end() &&
788 (*eit)->dtStart() >= (*sortIt)->dtStart() ) {
792 while ( sortIt != journalListSorted.end() &&
793 (*eit)->dtStart() < (*sortIt)->dtStart() ) {
797 journalListSorted.insert( sortIt, *eit );
802 for ( eit = journalList->begin(); eit != journalList->end(); ++eit ) {
803 sortIt = journalListSorted.begin();
805 while ( sortIt != journalListSorted.end() &&
806 (*eit)->summary() >= (*sortIt)->summary() ) {
810 while ( sortIt != journalListSorted.end() &&
811 (*eit)->summary() < (*sortIt)->summary() ) {
815 journalListSorted.insert( sortIt, *eit );
820 return journalListSorted;
827 mFilter->
apply( &jl );
834 mFilter->
apply( &el );
842 if ( !forincidence )
return;
844 TQString uid = forincidence->
uid();
847 while (
Incidence* i = mOrphans[ uid ] ) {
848 mOrphans.remove( uid );
849 i->setRelatedTo( forincidence );
851 mOrphanUids.remove( i->uid() );
867 mOrphans.insert( forincidence->
relatedToUid(), forincidence );
868 mOrphanUids.insert( forincidence->
uid(), forincidence );
877 kdDebug(5800) <<
"Warning: Calendar::removeRelations( 0 )!\n";
882 TQString uid = incidence->
uid();
885 Incidence::List::ConstIterator it;
886 for ( it = relations.begin(); it != relations.end(); ++it ) {
888 if ( !mOrphanUids.find( i->
uid() ) ) {
889 mOrphans.insert( uid, i );
890 mOrphanUids.insert( i->
uid(), i );
901 if ( mOrphanUids.remove( uid ) ) {
911 TQStringList relatedToUids;
914 for ( TQDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
915 if ( it.current()->uid() == uid ) {
916 relatedToUids << it.currentKey();
921 for ( TQStringList::Iterator uidit = relatedToUids.begin();
922 uidit != relatedToUids.end(); ++uidit ) {
925 while(
Incidence* i = mOrphans[ *uidit ] ) {
926 mOrphans.remove( *uidit );
927 if ( i != incidence ) tempList.append( i );
930 for ( Incidence::List::Iterator incit = tempList.begin();
931 incit != tempList.end(); ++incit ) {
932 mOrphans.insert( *uidit, *incit );
940 if( !mObservers.contains( observer ) )
941 mObservers.append( observer );
947 mObservers.remove( observer );
952 if ( modified != mModified || mNewObserver ) {
953 mNewObserver =
false;
955 for ( observer = mObservers.first(); observer;
956 observer = mObservers.next() ) {
959 mModified = modified;
979 if ( !mObserversEnabled )
983 for ( observer = mObservers.first(); observer;
984 observer = mObservers.next() ) {
991 if ( !mObserversEnabled )
995 for ( observer = mObservers.first(); observer;
996 observer = mObservers.next() ) {
1003 if ( !mObserversEnabled )
1007 for ( observer = mObservers.first(); observer;
1008 observer = mObservers.next() ) {
1034 Event::List::ConstIterator it1;
1035 for ( it1 = events.begin(); it1 != events.end(); ++it1 )
1036 incidences.append( *it1 );
1038 Todo::List::ConstIterator it2;
1039 for ( it2 = todos.begin(); it2 != todos.end(); ++it2 )
1040 incidences.append( *it2 );
1042 Journal::List::ConstIterator it3;
1043 for ( it3 = journals.begin(); it3 != journals.end(); ++it3 )
1044 incidences.append( *it3 );
1061 mObserversEnabled = enabled;
1064 #include "calendar.moc"