-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 @@ -351,25 +351,26 @@ void Calendar::addIncidenceBranch(Incidence *i) { addIncidence( i ); Incidence * inc; QPtrList<Incidence> Relations = i->relations(); for (inc=Relations.first();inc;inc=Relations.next()) { addIncidenceBranch( inc ); } } 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) { if ( in->typeID() == eventID ) deleteEvent( (Event*) in ); else if ( in->typeID() == todoID ) deleteTodo( (Todo*) in); else if ( in->typeID() == journalID ) deleteJournal( (Journal*) in ); } diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 4652fe5..14a1a45 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h @@ -67,24 +67,25 @@ public: virtual ~Calendar(); Incidence * undoIncidence() { return mUndoIncidence; }; bool undoDeleteIncidence(); void deleteIncidence(Incidence *in); void resetTempSyncStat(); void resetPilotStat(int id); /** Clears out the current calendar, freeing all used memory etc. */ 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; /** Sync changes in memory to persistant storage. */ virtual void save() = 0; virtual QPtrList<Event> getExternLastSyncEvents() = 0; virtual void removeSyncInfo( QString syncProfile) = 0; virtual bool isSaving() { return false; } /** diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index cce798f..3e42ec0 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp @@ -59,24 +59,99 @@ CalendarLocal::CalendarLocal(const QString &timeZoneId) void CalendarLocal::init() { mNextAlarmIncidence = 0; } 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 ); if ( calendar.load( name ) ) { addCalendar( &calendar ); return true; } return false; } void CalendarLocal::setSyncEventsReadOnly() { diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 98d16a3..23b0542 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h @@ -36,24 +36,27 @@ class CalendarLocal : public Calendar public: /** Constructs a new calendar, with variables initialized to sane values. */ CalendarLocal(); /** Constructs a new calendar, with variables initialized to sane values. */ 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 calendar. Any information already present is lost. @return true, if successfull, false on error. @param fileName the name of the calendar on disk. */ bool load( const QString &fileName ); /** Writes out the calendar to disk in the specified \a format. CalendarLocal takes ownership of the CalFormat object. |