-rw-r--r-- | libkcal/calendar.cpp | 9 | ||||
-rw-r--r-- | libkcal/calendar.h | 3 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 81 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 3 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 6 | ||||
-rw-r--r-- | libkcal/incidence.h | 1 |
6 files changed, 83 insertions, 20 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index 8535191..1350f6d 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp @@ -8,5 +8,4 @@ License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -421,9 +420,10 @@ void Calendar::setupRelations( Incidence *incidence ) { QString uid = incidence->uid(); - //qDebug("Calendar::setupRelations "); + //qDebug("Calendar::setupRelations %s", incidence->summary().latin1()); // First, go over the list of orphans and see if this is their parent while( Incidence* i = mOrphans[ uid ] ) { mOrphans.remove( uid ); i->setRelatedTo( incidence ); + //qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1()); incidence->addRelation( i ); mOrphanUids.remove( i->uid() ); @@ -434,10 +434,13 @@ void Calendar::setupRelations( Incidence *incidence ) // This incidence has a uid it is related to, but is not registered to it yet // Try to find it - Incidence* parent = this->incidence( incidence->relatedToUid() ); + //qDebug("Test parent for %s", incidence->summary().latin1()); + Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true ); if( parent ) { // Found it + // qDebug("parent found for for %s", incidence->summary().latin1()); incidence->setRelatedTo( parent ); parent->addRelation( incidence ); } else { + // qDebug("NO parent found for for %s", incidence->summary().latin1()); // Not found, put this in the mOrphans list mOrphans.insert( incidence->relatedToUid(), incidence ); diff --git a/libkcal/calendar.h b/libkcal/calendar.h index f301768..fbc40ad 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h @@ -78,5 +78,6 @@ public: virtual bool addCalendarFile( QString name, int id ) = 0; virtual bool mergeCalendarFile( QString name ) = 0; - virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ) = 0; + virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ,int * isDup = 0 ) = 0; + virtual Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0) = 0; virtual void setSyncEventsReadOnly() = 0; virtual void setSyncEventsEnabled() = 0; diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index ad8ace3..980663f 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp @@ -80,17 +80,33 @@ bool CalendarLocal::mergeCalendarFile( QString name ) return false; } - -Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly ) + +Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup ) { + + int calID = 0; + if ( isDup && *isDup > 0 ) + calID = *isDup; Todo *todo;; - Incidence *retVal = 0; + Todo *retVal = 0; for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { if ( todo->uid() == uid ) { - if ( enabledOnly ) - if ( !todo->calEnabled() ) + if( calID ) { + if ( todo->calID() != calID ) continue; + } + else { + if ( enabledOnly ) { + if ( !todo->calEnabled() ) { + if ( isDup ) + *isDup = todo->calID(); + continue; + } + } + } if ( doNotCheckDuplicates ) return todo; if ( retVal ) { if ( retVal->calID() > todo->calID() ) { + if ( isDup ) + *isDup = retVal->calID(); retVal = todo; } @@ -100,14 +116,37 @@ Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckD } } + return retVal; +} +//if ( isDup) and * isDup == 0: store duplicate found cal id in isDup +//if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly + +Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup ) +{ + int calID = 0; + if ( isDup && *isDup > 0 ) + calID = *isDup; + Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup ); if ( retVal ) return retVal; Event *event; for ( event = mEventList.first(); event; event = mEventList.next() ) { if ( event->uid() == uid ) { - if ( enabledOnly ) - if ( !event->calEnabled() ) + if( calID ) { + if ( event->calID() != calID ) continue; + } + else { + if ( enabledOnly ) { + if ( !event->calEnabled() ) { + if ( isDup ) + *isDup =event->calID() ; + continue; + } + } + } if ( doNotCheckDuplicates ) return event; if ( retVal ) { if ( retVal->calID() > event->calID() ) { + if ( isDup ) + *isDup = retVal->calID(); retVal = event; } @@ -120,10 +159,22 @@ Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckD for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) if ( it->uid() == uid ) { - if ( enabledOnly ) - if ( !it->calEnabled() ) + if( calID ) { + if ( event->calID() != calID ) continue; + } + else { + if ( enabledOnly ) { + if ( !it->calEnabled() ) { + if ( isDup ) + *isDup = it->calID(); + continue; + } + } + } if ( doNotCheckDuplicates ) return it; if ( retVal ) { - if ( retVal->calID() > it->calID() ) { + if ( retVal->calID() > it->calID() ) { + if ( isDup ) + *isDup = retVal->calID(); retVal = it; } @@ -234,9 +285,5 @@ void CalendarLocal::addCalendar( Calendar* cal ) Todo * ev = TodoList.first(); while ( ev ) { - QString rel = ev->relatedToUid(); - if ( !rel.isEmpty() ){ - ev->setRelatedTo ( 0 ); - ev->setRelatedToUid( rel ); - } + ev->resetRelatedTo(); ev = TodoList.next(); } @@ -413,4 +460,5 @@ bool CalendarLocal::addTodo( Todo *todo ) void CalendarLocal::deleteTodo( Todo *todo ) { + QString uid = todo->uid(); // Handle orphaned children removeRelations( todo ); @@ -420,4 +468,7 @@ void CalendarLocal::deleteTodo( Todo *todo ) setModified( true ); } + Todo* dup = todoForUid( uid ); + if ( dup ) + setupRelations( dup ); } diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index b611704..1ceabce 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h @@ -48,5 +48,6 @@ class CalendarLocal : public Calendar bool mergeCalendarFile( QString name ); bool mergeCalendar( Calendar* cal ); - Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly = false ); + Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly = false,int * isDup = 0 ); + Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0 ); void setSyncEventsReadOnly(); void setSyncEventsEnabled(); diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index fe9f854..7dd9bd2 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp @@ -521,4 +521,10 @@ QString Incidence::relatedToUid() const return mRelatedToUid; } +void Incidence::resetRelatedTo() +{ + QString store = mRelatedToUid; + setRelatedTo( 0 ); + mRelatedToUid = store; +} void Incidence::setRelatedTo(Incidence *relatedTo) diff --git a/libkcal/incidence.h b/libkcal/incidence.h index dc49640..f89942f 100644 --- a/libkcal/incidence.h +++ b/libkcal/incidence.h @@ -174,4 +174,5 @@ class Incidence : public IncidenceBase /** point at some other event to which the event relates */ void setRelatedTo(Incidence *relatedTo); + void resetRelatedTo(); /** what event does this one relate to? */ Incidence *relatedTo() const; |