24 #include <tqdatetime.h>
26 #include <tqptrlist.h>
29 #include <tdelocale.h>
30 #include <tdemessagebox.h>
33 #include "vcalformat.h"
34 #include "icalformat.h"
35 #include "exceptions.h"
36 #include "incidence.h"
38 #include "filestorage.h"
40 #include "calendarlocal.h"
45 :
Calendar( timeZoneId ), mEvents( 47 )
50 void CalendarLocal::init()
52 mDeletedIncidences.setAutoDelete(
true );
53 mFileName = TQString();
57 CalendarLocal::~CalendarLocal()
66 return storage.load();
71 const TQString filename = mFileName;
77 return storage.load();
86 return storage.save();
95 mFileName = TQString();
101 mDeletedIncidences.clear();
110 mFileName = TQString();
114 mDeletedIncidences.clear();
123 mFileName = TQString();
127 mDeletedIncidences.clear();
136 mFileName = TQString();
140 mDeletedIncidences.clear();
151 event->registerObserver(
this );
164 if ( mEvents.remove( event->
uid() ) ) {
167 mDeletedIncidences.append( event );
174 kdWarning() <<
"CalendarLocal::deleteEvent(): Event not found." << endl;
181 EventDictIterator it( mEvents );
182 for( ; it.current(); ++it ) {
184 if (e->
uid() ==
event->uid()) {
197 TQDictIterator<Event> it( mEvents );
198 while( it.current() ) {
203 mEvents.setAutoDelete(
true );
205 mEvents.setAutoDelete(
false );
211 return mEvents[ uid ];
216 mTodoList.append( todo );
235 if ( mTodoList.removeRef( todo ) ) {
238 mDeletedIncidences.append( todo );
245 kdWarning() <<
"CalendarLocal::deleteTodo(): Todo not found." << endl;
252 Todo::List::ConstIterator it;
253 for( it = mTodoList.begin(); it != mTodoList.end(); ++it ) {
255 if (t->
uid() == todo->
uid()) {
268 Todo::List::ConstIterator it;
269 for( it = mTodoList.begin(); it != mTodoList.end(); ++it ) {
273 mTodoList.setAutoDelete(
true );
274 mTodoList.clearAll();
275 mTodoList.setAutoDelete(
false );
281 return sortTodos( &mTodoList, sortField, sortDirection );
286 Todo::List::ConstIterator it;
287 for ( it = mTodoList.begin(); it != mTodoList.end(); ++it ) {
288 if ( (*it)->uid() == uid )
return *it;
298 Todo::List::ConstIterator it;
299 for ( it = mTodoList.begin(); it != mTodoList.end(); ++it ) {
302 todos.append( todo );
311 return alarms( TQDateTime( TQDate( 1900, 1, 1 ) ), to );
321 EventDictIterator it( mEvents );
322 for( ; it.current(); ++it ) {
328 Todo::List::ConstIterator it2;
329 for( it2 = mTodoList.begin(); it2 != mTodoList.end(); ++it2 ) {
342 const TQDateTime &from,
const TQDateTime &to )
344 TQDateTime preTime = from.addSecs(-1);
345 Alarm::List::ConstIterator it;
346 for( it = incidence->
alarms().begin(); it != incidence->
alarms().end();
351 if ( dt.isValid() && dt <= to ) {
352 kdDebug(5800) <<
"CalendarLocal::appendAlarms() '"
353 << incidence->
summary() <<
"': "
354 << dt.toString() << endl;
355 alarms.append( alarm );
363 const TQDateTime &from,
364 const TQDateTime &to )
368 bool endOffsetValid =
false;
374 Alarm::List::ConstIterator it;
375 for( it = incidence->
alarms().begin(); it != incidence->
alarms().end();
382 if ( !dt.isValid() || dt > to ) {
394 if ( !endOffsetValid ) {
395 if ( incidence->type() ==
"Event" ) {
397 endOffsetValid =
true;
398 }
else if ( incidence->type() ==
"Todo" &&
401 endOffsetValid =
true;
407 TQDateTime alarmStart;
408 if ( incidence->type() ==
"Event" ) {
411 }
else if ( incidence->type() ==
"Todo" ) {
416 if ( alarmStart.isValid() && alarmStart > to ) {
420 TQDateTime baseStart;
421 if ( incidence->type() ==
"Event" ) {
423 }
else if ( incidence->type() ==
"Todo" ) {
424 baseStart = t->
dtDue();
426 if ( alarmStart.isValid() && from > alarmStart ) {
428 baseStart = (-offset).end( (-endOffset).end( alarmStart ) );
435 if ( !dt.isValid() ||
436 ( dt = endOffset.
end( offset.
end( dt ) ) ) > to )
447 for ( TQDateTime base = baseStart;
459 Duration toFromDuration( dt, base );
460 int toFrom = toFromDuration.
asDays();
462 ( toFromDuration.
isDaily() && toFrom % snooze == 0 ) ||
463 ( toFrom / snooze + 1 ) * snooze <= toFrom + period.
asDays() ) {
467 dt = offset.
end( dt ).addDays( ( ( toFrom - 1 ) / snooze + 1 ) * snooze );
472 int toFrom = dt.secsTo( base );
474 toFrom % snooze == 0 ||
475 ( toFrom / snooze + 1 ) * snooze <= toFrom + period.
asSeconds() )
480 dt = offset.
end( dt ).addSecs( ( ( toFrom - 1 ) / snooze + 1 ) * snooze );
491 kdDebug(5800) <<
"CalendarLocal::appendAlarms() '" << incidence->
summary()
492 <<
"': " << dt.toString() << endl;
493 alarms.append( alarm );
501 incidence->setSyncStatusSilent( Event::SYNCMOD );
515 TQString uid =
event->uid();
516 if ( mEvents[ uid ] == 0 ) {
517 mEvents.insert( uid, event );
522 Q_ASSERT( mEvents[uid] == event );
532 EventDictIterator it( mEvents );
533 for( ; it.current(); ++it ) {
540 for ( i = 0; i <= extraDays; i++ ) {
542 eventList.append(
event );
548 eventList.append(
event );
551 if (
event->
dtStart().date() <= qd &&
event->dateEnd() >= qd ) {
552 eventList.append(
event );
564 TQDate yesterStart = start.addDays(-1);
567 EventDictIterator it( mEvents );
568 for( ; it.current(); ++it ) {
571 TQDate rStart =
event->
dtStart().date();
576 if ( inclusive && rStart < start) {
582 TQDate rEnd =
event->dtEnd().date();
587 if ( inclusive && end < rEnd ) {
601 TQDate rEnd =
event->recurrence()->endDate();
602 if ( ! rEnd.isValid() ) {
606 if ( rEnd < start ) {
610 if ( inclusive && end < rEnd ) {
621 int durationBeforeStart =
event->recurrence()->durationTo(yesterStart);
622 int durationUntilEnd =
event->recurrence()->durationTo(end);
623 if (durationBeforeStart == durationUntilEnd) {
624 kdDebug(5800) <<
"Skipping recurring event without occurences in TOI" << endl;
632 eventList.append(
event );
646 EventDictIterator it( mEvents );
647 for( ; it.current(); ++it )
648 eventList.append( *it );
649 return sortEvents( &eventList, sortField, sortDirection );
659 mJournalList.append(journal);
672 if ( mJournalList.removeRef( journal ) ) {
675 mDeletedIncidences.append( journal );
682 kdWarning() <<
"CalendarLocal::deleteJournal(): Journal not found." << endl;
689 Journal::List::ConstIterator it;
690 for( it = mJournalList.begin(); it != mJournalList.end(); ++it ) {
692 if (j->
uid() == journal->
uid()) {
704 Journal::List::ConstIterator it;
705 for( it = mJournalList.begin(); it != mJournalList.end(); ++it ) {
709 mJournalList.setAutoDelete(
true );
710 mJournalList.clearAll();
711 mJournalList.setAutoDelete(
false );
716 Journal::List::ConstIterator it;
717 for ( it = mJournalList.begin(); it != mJournalList.end(); ++it )
718 if ( (*it)->uid() == uid )
726 return sortJournals( &mJournalList, sortField, sortDirection );
733 Journal::List::ConstIterator it;
734 for ( it = mJournalList.begin(); it != mJournalList.end(); ++it ) {
736 if ( journal->
dtStart().date() == date ) {
737 journals.append( journal );
746 const TQString question( i18n(
"The timezone setting was changed. In order to display the calendar "
747 "you are looking at in the new timezone, it needs to be saved. Do you want to save the pending "
748 "changes or rather wait and apply the new timezone on the next reload?" ) );
749 int rc = KMessageBox::Yes;
751 rc = KMessageBox::questionYesNo( 0, question,
752 i18n(
"Save before applying timezones?"),
754 KGuiItem(i18n(
"Apply Timezone Change on Next Reload")),
755 "calendarLocalSaveBeforeTimezoneShift");
757 if ( rc == KMessageBox::Yes ) {