summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp42
-rw-r--r--libkcal/calendar.h1
-rw-r--r--libkcal/calendarlocal.cpp26
-rw-r--r--libkcal/calendarlocal.h1
-rw-r--r--libkcal/incidence.cpp6
-rw-r--r--libkcal/incidence.h1
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()
105#endif 105#endif
106 106
107// KOPrefs::instance()->writeConfig(); 107// KOPrefs::instance()->writeConfig();
108} 108}
109 109
110Calendar::~Calendar() 110Calendar::~Calendar()
111{ 111{
112 delete mDefaultFilter; 112 delete mDefaultFilter;
113 if ( mUndoIncidence ) 113 clearUndo( 0 );
114 delete mUndoIncidence; 114}
115} 115void Calendar::clearUndo( Incidence * newUndo )
116{
117
118 if ( mUndoIncidence ) {
119 if ( mUndoIncidence->typeID() == eventID )
120 delete ((Event*) mUndoIncidence) ;
121 else if ( mUndoIncidence->typeID() == todoID )
122 delete ( (Todo*) mUndoIncidence );
123 else if ( mUndoIncidence->typeID() == journalID )
124 delete ( (Journal*) mUndoIncidence );
125 else
126 delete mUndoIncidence;
127 }
128 mUndoIncidence = newUndo;
129 if ( mUndoIncidence ) {
130 mUndoIncidence->clearRelations();
131 }
132
133}
134
116void Calendar::setDontDeleteIncidencesOnClose () 135void Calendar::setDontDeleteIncidencesOnClose ()
117{ 136{
118 mDeleteIncidencesOnClose = false; 137 mDeleteIncidencesOnClose = false;
119} 138}
120void Calendar::setDefaultCalendar( int d ) 139void Calendar::setDefaultCalendar( int d )
121{ 140{
122 mDefaultCalendar = d; 141 mDefaultCalendar = d;
123} 142}
@@ -442,27 +461,42 @@ void Calendar::removeRelations( Incidence *incidence )
442 i->setRelatedToUid( uid ); 461 i->setRelatedToUid( uid );
443 } 462 }
444 463
445 // If this incidence is related to something else, tell that about it 464 // If this incidence is related to something else, tell that about it
446 if( incidence->relatedTo() ) 465 if( incidence->relatedTo() )
447 incidence->relatedTo()->removeRelation( incidence ); 466 incidence->relatedTo()->removeRelation( incidence );
448 467
449 // Remove this one from the orphans list 468 // Remove this one from the orphans list
450 if( mOrphanUids.remove( uid ) ) 469 if( mOrphanUids.remove( uid ) ) {
470 QString r2uid = incidence->relatedToUid();
471 QPtrList<Incidence> tempList;
472 while( Incidence* i = mOrphans[ r2uid ] ) {
473 mOrphans.remove( r2uid );
474 if ( i != incidence ) tempList.append( i );
475 }
476 Incidence* inc = tempList.first();
477 while ( inc ) {
478 mOrphans.insert( r2uid, inc );
479 inc = tempList.next();
480 }
481 }
482 // LR: and another big bad bug found
483#if 0
451 // This incidence is located in the orphans list - it should be removed 484 // This incidence is located in the orphans list - it should be removed
452 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 485 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
453 // Removing wasn't that easy 486 // Removing wasn't that easy
454 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 487 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
455 if( it.current()->uid() == uid ) { 488 if( it.current()->uid() == uid ) {
456 mOrphans.remove( it.currentKey() ); 489 mOrphans.remove( it.currentKey() );
457 break; 490 break;
458 } 491 }
459 } 492 }
460 } 493 }
494#endif
461} 495}
462 496
463void Calendar::registerObserver( Observer *observer ) 497void Calendar::registerObserver( Observer *observer )
464{ 498{
465 mObserver = observer; 499 mObserver = observer;
466 mNewObserver = true; 500 mNewObserver = true;
467} 501}
468 502
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:
75 */ 75 */
76 virtual void close() = 0; 76 virtual void close() = 0;
77 virtual void addCalendar( Calendar* ) = 0; 77 virtual void addCalendar( Calendar* ) = 0;
78 virtual bool addCalendarFile( QString name, int id ) = 0; 78 virtual bool addCalendarFile( QString name, int id ) = 0;
79 virtual bool mergeCalendarFile( QString name ) = 0; 79 virtual bool mergeCalendarFile( QString name ) = 0;
80 virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0; 80 virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0;
81 virtual void setSyncEventsReadOnly() = 0; 81 virtual void setSyncEventsReadOnly() = 0;
82 virtual void stopAllTodos() = 0; 82 virtual void stopAllTodos() = 0;
83 virtual void clearUndo( Incidence * newUndo );
83 84
84 /** 85 /**
85 Sync changes in memory to persistant storage. 86 Sync changes in memory to persistant storage.
86 */ 87 */
87 virtual void save() = 0; 88 virtual void save() = 0;
88 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 89 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
89 virtual void removeSyncInfo( QString syncProfile) = 0; 90 virtual void removeSyncInfo( QString syncProfile) = 0;
90 virtual bool isSaving() { return false; } 91 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()
263 mJournalList.clear(); 263 mJournalList.clear();
264 264
265 mEventList.setAutoDelete( false ); 265 mEventList.setAutoDelete( false );
266 mTodoList.setAutoDelete( false ); 266 mTodoList.setAutoDelete( false );
267 mJournalList.setAutoDelete( false ); 267 mJournalList.setAutoDelete( false );
268 268
269 setModified( false ); 269 setModified( false );
270} 270}
271 void CalendarLocal::clearUndo() 271
272{
273 if ( mUndoIncidence ) {
274 if ( mUndoIncidence->typeID() == eventID )
275 delete ((Event*) mUndoIncidence) ;
276 else if ( mUndoIncidence->typeID() == todoID )
277 delete ( (Todo*) mUndoIncidence );
278 else if ( mUndoIncidence->typeID() == journalID )
279 delete ( (Journal*) mUndoIncidence );
280 else
281 delete mUndoIncidence;
282 }
283 mUndoIncidence = 0;
284}
285bool CalendarLocal::addAnniversaryNoDup( Event *event ) 272bool CalendarLocal::addAnniversaryNoDup( Event *event )
286{ 273{
287 QString cat; 274 QString cat;
288 bool isBirthday = true; 275 bool isBirthday = true;
289 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 276 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
290 isBirthday = false; 277 isBirthday = false;
291 cat = i18n( "Anniversary" ); 278 cat = i18n( "Anniversary" );
292 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 279 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
@@ -335,18 +322,17 @@ bool CalendarLocal::addEvent( Event *event )
335 event->setCalID( mDefaultCalendar ); 322 event->setCalID( mDefaultCalendar );
336 event->setCalEnabled( true ); 323 event->setCalEnabled( true );
337 324
338 return true; 325 return true;
339} 326}
340 327
341void CalendarLocal::deleteEvent( Event *event ) 328void CalendarLocal::deleteEvent( Event *event )
342{ 329{
343 clearUndo(); 330 clearUndo(event);
344 mUndoIncidence = event;
345 if ( mEventList.removeRef( event ) ) { 331 if ( mEventList.removeRef( event ) ) {
346 setModified( true ); 332 setModified( true );
347 } 333 }
348} 334}
349 335
350 336
351Event *CalendarLocal::event( const QString &uid ) 337Event *CalendarLocal::event( const QString &uid )
352{ 338{
@@ -390,19 +376,18 @@ bool CalendarLocal::addTodo( Todo *todo )
390 todo->setCalID( mDefaultCalendar ); 376 todo->setCalID( mDefaultCalendar );
391 todo->setCalEnabled( true ); 377 todo->setCalEnabled( true );
392 return true; 378 return true;
393} 379}
394 380
395void CalendarLocal::deleteTodo( Todo *todo ) 381void CalendarLocal::deleteTodo( Todo *todo )
396{ 382{
397 // Handle orphaned children 383 // Handle orphaned children
398 clearUndo();
399 removeRelations( todo ); 384 removeRelations( todo );
400 mUndoIncidence = todo; 385 clearUndo(todo);
401 386
402 if ( mTodoList.removeRef( todo ) ) { 387 if ( mTodoList.removeRef( todo ) ) {
403 setModified( true ); 388 setModified( true );
404 } 389 }
405} 390}
406 391
407QPtrList<Todo> CalendarLocal::rawTodos() 392QPtrList<Todo> CalendarLocal::rawTodos()
408{ 393{
@@ -894,18 +879,17 @@ bool CalendarLocal::addJournal(Journal *journal)
894 if ( journal->calID() == 0 ) 879 if ( journal->calID() == 0 )
895 journal->setCalID( mDefaultCalendar ); 880 journal->setCalID( mDefaultCalendar );
896 journal->setCalEnabled( true ); 881 journal->setCalEnabled( true );
897 return true; 882 return true;
898} 883}
899 884
900void CalendarLocal::deleteJournal( Journal *journal ) 885void CalendarLocal::deleteJournal( Journal *journal )
901{ 886{
902 clearUndo(); 887 clearUndo(journal);
903 mUndoIncidence = journal;
904 if ( mJournalList.removeRef(journal) ) { 888 if ( mJournalList.removeRef(journal) ) {
905 setModified( true ); 889 setModified( true );
906 } 890 }
907} 891}
908 892
909QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) 893QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date )
910{ 894{
911 QPtrList<Journal> el; 895 QPtrList<Journal> el;
@@ -974,17 +958,17 @@ void CalendarLocal::setCalendarRemove( int id )
974 Journal * ev = JournalList.first(); 958 Journal * ev = JournalList.first();
975 while ( ev ) { 959 while ( ev ) {
976 if ( ev->calID() == id ) 960 if ( ev->calID() == id )
977 deleteJournal( ev ); 961 deleteJournal( ev );
978 ev = JournalList.next(); 962 ev = JournalList.next();
979 } 963 }
980 } 964 }
981 965
982 clearUndo(); 966 clearUndo(0);
983 967
984} 968}
985 969
986void CalendarLocal::setCalendarEnabled( int id, bool enable ) 970void CalendarLocal::setCalendarEnabled( int id, bool enable )
987{ 971{
988 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 972 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
989 if ( it->calID() == id ) it->setCalEnabled( enable ); 973 if ( it->calID() == id ) it->setCalEnabled( enable );
990 974
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
64 @param fileName the name of the file 64 @param fileName the name of the file
65 */ 65 */
66 bool save( const QString &fileName, CalFormat *format = 0 ); 66 bool save( const QString &fileName, CalFormat *format = 0 );
67 67
68 /** 68 /**
69 Clears out the current calendar, freeing all used memory etc. etc. 69 Clears out the current calendar, freeing all used memory etc. etc.
70 */ 70 */
71 void close(); 71 void close();
72 void clearUndo();
73 72
74 void save() {} 73 void save() {}
75 74
76 /** 75 /**
77 Add Event to calendar. 76 Add Event to calendar.
78 */ 77 */
79 void removeSyncInfo( QString syncProfile); 78 void removeSyncInfo( QString syncProfile);
80 bool addAnniversaryNoDup( Event *event ); 79 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()
486 return mCategories.join(", "); 486 return mCategories.join(", ");
487} 487}
488 488
489void Incidence::setRelatedToUid(const QString &relatedToUid) 489void Incidence::setRelatedToUid(const QString &relatedToUid)
490{ 490{
491 if (mReadOnly) return; 491 if (mReadOnly) return;
492 mRelatedToUid = relatedToUid; 492 mRelatedToUid = relatedToUid;
493} 493}
494 494void Incidence::clearRelations()
495{
496 mRelatedTo = 0;
497 mRelations.clear();
498}
495QString Incidence::relatedToUid() const 499QString Incidence::relatedToUid() const
496{ 500{
497 return mRelatedToUid; 501 return mRelatedToUid;
498} 502}
499 503
500void Incidence::setRelatedTo(Incidence *relatedTo) 504void Incidence::setRelatedTo(Incidence *relatedTo)
501{ 505{
502 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 506 //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
109 bool accept(Visitor &v) { return v.visit(this); } 109 bool accept(Visitor &v) { return v.visit(this); }
110 </pre> 110 </pre>
111 */ 111 */
112 virtual bool accept(Visitor &) { return false; } 112 virtual bool accept(Visitor &) { return false; }
113 113
114 virtual Incidence *clone() = 0; 114 virtual Incidence *clone() = 0;
115 virtual void cloneRelations( Incidence * ); 115 virtual void cloneRelations( Incidence * );
116 void addRelationsToList(QPtrList<Incidence> *rel); 116 void addRelationsToList(QPtrList<Incidence> *rel);
117 void clearRelations();
117 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; 118 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0;
118 void setReadOnly( bool ); 119 void setReadOnly( bool );
119 120
120 /** 121 /**
121 Recreate event. The event is made a new unique event, but already stored 122 Recreate event. The event is made a new unique event, but already stored
122 event information is preserved. Sets uniquie id, creation date, last 123 event information is preserved. Sets uniquie id, creation date, last
123 modification date and revision number. 124 modification date and revision number.
124 */ 125 */