-rw-r--r-- | libkcal/calendar.cpp | 3 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 75 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 3 |
4 files changed, 81 insertions, 1 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index a662eeb..b7990d4 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp @@ -359,9 +359,10 @@ void Calendar::addIncidenceBranch(Incidence *i) bool Calendar::addIncidence(Incidence *i) { Incidence::AddVisitor<Calendar> v(this); - i->setCalID( mDefaultCalendar ); + if ( i->calID() == 0 ) + i->setCalID( mDefaultCalendar ); i->setCalEnabled( true ); return i->accept(v); } void Calendar::deleteIncidence(Incidence *in) diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 4652fe5..14a1a45 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h @@ -75,8 +75,9 @@ public: */ virtual void close() = 0; virtual void addCalendar( Calendar* ) = 0; virtual bool addCalendarFile( QString name, int id ) = 0; + virtual bool mergeCalendarFile( QString name ) = 0; virtual void setSyncEventsReadOnly() = 0; virtual void stopAllTodos() = 0; /** diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index cce798f..3e42ec0 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp @@ -67,8 +67,83 @@ CalendarLocal::~CalendarLocal() { if ( mDeleteIncidencesOnClose ) close(); } +bool CalendarLocal::mergeCalendarFile( QString name ) +{ + CalendarLocal calendar( timeZoneId() ); + calendar.setDefaultCalendar( 1 ); + if ( calendar.load( name ) ) { + mergeCalendar( &calendar ); + return true; + } + return false; +} + +Incidence* CalendarLocal::incidenceForUid( const QString& uid ) +{ + Todo *todo;; + Incidence *retVal = 0; + for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { + if ( todo->uid() == uid ) { + if ( retVal ) { + if ( retVal->calID() > todo->calID() ) { + retVal = todo; + } + } else { + retVal = todo; + } + } + } + if ( retVal ) return retVal; + Event *event; + for ( event = mEventList.first(); event; event = mEventList.next() ) { + if ( event->uid() == uid ) { + if ( retVal ) { + if ( retVal->calID() > event->calID() ) { + retVal = event; + } + } else { + retVal = event; + } + } + } + if ( retVal ) return retVal; + for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) + if ( it->uid() == uid ) { + if ( retVal ) { + if ( retVal->calID() > it->calID() ) { + retVal = it; + } + } else { + retVal = it; + } + } + return retVal; +} + +bool CalendarLocal::mergeCalendar( Calendar* remote ) +{ + QPtrList<Incidence> er = remote->rawIncidences(); + Incidence* inR = er.first(); + Incidence* inL; + while ( inR ) { + inL = incidenceForUid( inR->uid() ); + if ( inL ) { + int calID = inL->calID(); + deleteIncidence( inL ); + inL = inR->clone(); + inL->setCalID( calID ); + addIncidence( inL ); + } else { + inL = inR->clone(); + inL->setCalID( 0 );// add to default cal + addIncidence( inL ); + } + inR = er.next(); + } + return true; +} bool CalendarLocal::addCalendarFile( QString name, int id ) { CalendarLocal calendar( timeZoneId() ); calendar.setDefaultCalendar( id ); diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 98d16a3..23b0542 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h @@ -44,8 +44,11 @@ class CalendarLocal : public Calendar CalendarLocal( const QString &timeZoneId ); ~CalendarLocal(); void addCalendar( Calendar* ); bool addCalendarFile( QString name, int id ); + bool mergeCalendarFile( QString name ); + bool mergeCalendar( Calendar* cal ); + Incidence* incidenceForUid( const QString& uid ); void setSyncEventsReadOnly(); void stopAllTodos(); /** Loads a calendar on disk in vCalendar or iCalendar format into the current |