-rw-r--r-- | libkcal/calendar.cpp | 42 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 26 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 1 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 6 | ||||
-rw-r--r-- | libkcal/incidence.h | 1 |
6 files changed, 50 insertions, 27 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index b7990d4..b1806ee 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp @@ -105,19 +105,38 @@ void Calendar::init() #endif // KOPrefs::instance()->writeConfig(); } Calendar::~Calendar() { delete mDefaultFilter; - if ( mUndoIncidence ) - delete mUndoIncidence; -} + clearUndo( 0 ); +} +void Calendar::clearUndo( Incidence * newUndo ) +{ + + if ( mUndoIncidence ) { + if ( mUndoIncidence->typeID() == eventID ) + delete ((Event*) mUndoIncidence) ; + else if ( mUndoIncidence->typeID() == todoID ) + delete ( (Todo*) mUndoIncidence ); + else if ( mUndoIncidence->typeID() == journalID ) + delete ( (Journal*) mUndoIncidence ); + else + delete mUndoIncidence; + } + mUndoIncidence = newUndo; + if ( mUndoIncidence ) { + mUndoIncidence->clearRelations(); + } + +} + void Calendar::setDontDeleteIncidencesOnClose () { mDeleteIncidencesOnClose = false; } void Calendar::setDefaultCalendar( int d ) { mDefaultCalendar = d; } @@ -442,27 +461,42 @@ void Calendar::removeRelations( Incidence *incidence ) i->setRelatedToUid( uid ); } // If this incidence is related to something else, tell that about it if( incidence->relatedTo() ) incidence->relatedTo()->removeRelation( incidence ); // Remove this one from the orphans list - if( mOrphanUids.remove( uid ) ) + if( mOrphanUids.remove( uid ) ) { + QString r2uid = incidence->relatedToUid(); + QPtrList<Incidence> tempList; + while( Incidence* i = mOrphans[ r2uid ] ) { + mOrphans.remove( r2uid ); + if ( i != incidence ) tempList.append( i ); + } + Incidence* inc = tempList.first(); + while ( inc ) { + mOrphans.insert( r2uid, inc ); + inc = tempList.next(); + } + } + // LR: and another big bad bug found +#if 0 // This incidence is located in the orphans list - it should be removed if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { // Removing wasn't that easy for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { if( it.current()->uid() == uid ) { mOrphans.remove( it.currentKey() ); break; } } } +#endif } void Calendar::registerObserver( Observer *observer ) { mObserver = observer; mNewObserver = true; } diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 95477cd..3f6895d 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h @@ -75,16 +75,17 @@ 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 Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0; virtual void setSyncEventsReadOnly() = 0; virtual void stopAllTodos() = 0; + virtual void clearUndo( Incidence * newUndo ); /** 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 e8c969f..1a1c6be 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp @@ -263,30 +263,17 @@ void CalendarLocal::close() mJournalList.clear(); mEventList.setAutoDelete( false ); mTodoList.setAutoDelete( false ); mJournalList.setAutoDelete( false ); setModified( false ); } - void CalendarLocal::clearUndo() -{ - if ( mUndoIncidence ) { - if ( mUndoIncidence->typeID() == eventID ) - delete ((Event*) mUndoIncidence) ; - else if ( mUndoIncidence->typeID() == todoID ) - delete ( (Todo*) mUndoIncidence ); - else if ( mUndoIncidence->typeID() == journalID ) - delete ( (Journal*) mUndoIncidence ); - else - delete mUndoIncidence; - } - mUndoIncidence = 0; -} + bool CalendarLocal::addAnniversaryNoDup( Event *event ) { QString cat; bool isBirthday = true; if( event->categoriesStr() == i18n( "Anniversary" ) ) { isBirthday = false; cat = i18n( "Anniversary" ); } else if( event->categoriesStr() == i18n( "Birthday" ) ) { @@ -335,18 +322,17 @@ bool CalendarLocal::addEvent( Event *event ) event->setCalID( mDefaultCalendar ); event->setCalEnabled( true ); return true; } void CalendarLocal::deleteEvent( Event *event ) { - clearUndo(); - mUndoIncidence = event; + clearUndo(event); if ( mEventList.removeRef( event ) ) { setModified( true ); } } Event *CalendarLocal::event( const QString &uid ) { @@ -390,19 +376,18 @@ bool CalendarLocal::addTodo( Todo *todo ) todo->setCalID( mDefaultCalendar ); todo->setCalEnabled( true ); return true; } void CalendarLocal::deleteTodo( Todo *todo ) { // Handle orphaned children - clearUndo(); removeRelations( todo ); - mUndoIncidence = todo; + clearUndo(todo); if ( mTodoList.removeRef( todo ) ) { setModified( true ); } } QPtrList<Todo> CalendarLocal::rawTodos() { @@ -894,18 +879,17 @@ bool CalendarLocal::addJournal(Journal *journal) if ( journal->calID() == 0 ) journal->setCalID( mDefaultCalendar ); journal->setCalEnabled( true ); return true; } void CalendarLocal::deleteJournal( Journal *journal ) { - clearUndo(); - mUndoIncidence = journal; + clearUndo(journal); if ( mJournalList.removeRef(journal) ) { setModified( true ); } } QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) { QPtrList<Journal> el; @@ -974,17 +958,17 @@ void CalendarLocal::setCalendarRemove( int id ) Journal * ev = JournalList.first(); while ( ev ) { if ( ev->calID() == id ) deleteJournal( ev ); ev = JournalList.next(); } } - clearUndo(); + clearUndo(0); } void CalendarLocal::setCalendarEnabled( int id, bool enable ) { for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) if ( it->calID() == id ) it->setCalEnabled( enable ); diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index ae7e30c..a7a85c8 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h @@ -64,17 +64,16 @@ class CalendarLocal : public Calendar @param fileName the name of the file */ bool save( const QString &fileName, CalFormat *format = 0 ); /** Clears out the current calendar, freeing all used memory etc. etc. */ void close(); - void clearUndo(); void save() {} /** Add Event to calendar. */ void removeSyncInfo( QString syncProfile); bool addAnniversaryNoDup( Event *event ); diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 52d94fb..549014e 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp @@ -486,17 +486,21 @@ QString Incidence::categoriesStrWithSpace() return mCategories.join(", "); } void Incidence::setRelatedToUid(const QString &relatedToUid) { if (mReadOnly) return; mRelatedToUid = relatedToUid; } - +void Incidence::clearRelations() +{ + mRelatedTo = 0; + mRelations.clear(); +} QString Incidence::relatedToUid() const { return mRelatedToUid; } void Incidence::setRelatedTo(Incidence *relatedTo) { //qDebug("Incidence::setRelatedTo %d ", relatedTo); diff --git a/libkcal/incidence.h b/libkcal/incidence.h index 88df217..eef9e64 100644 --- a/libkcal/incidence.h +++ b/libkcal/incidence.h @@ -109,16 +109,17 @@ class Incidence : public IncidenceBase bool accept(Visitor &v) { return v.visit(this); } </pre> */ virtual bool accept(Visitor &) { return false; } virtual Incidence *clone() = 0; virtual void cloneRelations( Incidence * ); void addRelationsToList(QPtrList<Incidence> *rel); + void clearRelations(); virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; void setReadOnly( bool ); /** Recreate event. The event is made a new unique event, but already stored event information is preserved. Sets uniquie id, creation date, last modification date and revision number. */ |