-rw-r--r-- | libkcal/calendar.cpp | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index b7990d4..b1806ee 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -81,67 +81,86 @@ void Calendar::init() | |||
81 | int hourOff = - ((timezone / 60) / 60); | 81 | int hourOff = - ((timezone / 60) / 60); |
82 | if (now->tm_isdst) | 82 | if (now->tm_isdst) |
83 | hourOff += 1; | 83 | hourOff += 1; |
84 | QString tzStr; | 84 | QString tzStr; |
85 | tzStr.sprintf("%.2d%.2d", | 85 | tzStr.sprintf("%.2d%.2d", |
86 | hourOff, | 86 | hourOff, |
87 | abs((timezone / 60) % 60)); | 87 | abs((timezone / 60) % 60)); |
88 | 88 | ||
89 | // if no time zone was in the config file, write what we just discovered. | 89 | // if no time zone was in the config file, write what we just discovered. |
90 | if (tmpStr.isEmpty()) { | 90 | if (tmpStr.isEmpty()) { |
91 | // KOPrefs::instance()->mTimeZone = tzStr; | 91 | // KOPrefs::instance()->mTimeZone = tzStr; |
92 | } else { | 92 | } else { |
93 | tzStr = tmpStr; | 93 | tzStr = tmpStr; |
94 | } | 94 | } |
95 | 95 | ||
96 | // if daylight savings has changed since last load time, we need | 96 | // if daylight savings has changed since last load time, we need |
97 | // to rewrite these settings to the config file. | 97 | // to rewrite these settings to the config file. |
98 | if ((now->tm_isdst && !dstSetting) || | 98 | if ((now->tm_isdst && !dstSetting) || |
99 | (!now->tm_isdst && dstSetting)) { | 99 | (!now->tm_isdst && dstSetting)) { |
100 | KOPrefs::instance()->mTimeZone = tzStr; | 100 | KOPrefs::instance()->mTimeZone = tzStr; |
101 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; | 101 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; |
102 | } | 102 | } |
103 | 103 | ||
104 | setTimeZone(tzStr); | 104 | setTimeZone(tzStr); |
105 | #endif | 105 | #endif |
106 | 106 | ||
107 | // KOPrefs::instance()->writeConfig(); | 107 | // KOPrefs::instance()->writeConfig(); |
108 | } | 108 | } |
109 | 109 | ||
110 | Calendar::~Calendar() | 110 | Calendar::~Calendar() |
111 | { | 111 | { |
112 | delete mDefaultFilter; | 112 | delete mDefaultFilter; |
113 | if ( mUndoIncidence ) | 113 | clearUndo( 0 ); |
114 | delete mUndoIncidence; | 114 | } |
115 | } | 115 | void 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 | |||
116 | void Calendar::setDontDeleteIncidencesOnClose () | 135 | void Calendar::setDontDeleteIncidencesOnClose () |
117 | { | 136 | { |
118 | mDeleteIncidencesOnClose = false; | 137 | mDeleteIncidencesOnClose = false; |
119 | } | 138 | } |
120 | void Calendar::setDefaultCalendar( int d ) | 139 | void Calendar::setDefaultCalendar( int d ) |
121 | { | 140 | { |
122 | mDefaultCalendar = d; | 141 | mDefaultCalendar = d; |
123 | } | 142 | } |
124 | int Calendar::defaultCalendar() | 143 | int Calendar::defaultCalendar() |
125 | { | 144 | { |
126 | return mDefaultCalendar; | 145 | return mDefaultCalendar; |
127 | } | 146 | } |
128 | const QString &Calendar::getOwner() const | 147 | const QString &Calendar::getOwner() const |
129 | { | 148 | { |
130 | return mOwner; | 149 | return mOwner; |
131 | } | 150 | } |
132 | 151 | ||
133 | bool Calendar::undoDeleteIncidence() | 152 | bool Calendar::undoDeleteIncidence() |
134 | { | 153 | { |
135 | if (!mUndoIncidence) | 154 | if (!mUndoIncidence) |
136 | return false; | 155 | return false; |
137 | addIncidence(mUndoIncidence); | 156 | addIncidence(mUndoIncidence); |
138 | mUndoIncidence = 0; | 157 | mUndoIncidence = 0; |
139 | return true; | 158 | return true; |
140 | } | 159 | } |
141 | void Calendar::setOwner(const QString &os) | 160 | void Calendar::setOwner(const QString &os) |
142 | { | 161 | { |
143 | int i; | 162 | int i; |
144 | mOwner = os; | 163 | mOwner = os; |
145 | i = mOwner.find(','); | 164 | i = mOwner.find(','); |
146 | if (i != -1) | 165 | if (i != -1) |
147 | mOwner = mOwner.left(i); | 166 | mOwner = mOwner.left(i); |
@@ -418,72 +437,87 @@ void Calendar::setupRelations( Incidence *incidence ) | |||
418 | if( parent ) { | 437 | if( parent ) { |
419 | // Found it | 438 | // Found it |
420 | incidence->setRelatedTo( parent ); | 439 | incidence->setRelatedTo( parent ); |
421 | parent->addRelation( incidence ); | 440 | parent->addRelation( incidence ); |
422 | } else { | 441 | } else { |
423 | // Not found, put this in the mOrphans list | 442 | // Not found, put this in the mOrphans list |
424 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 443 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
425 | mOrphanUids.insert( incidence->uid(), incidence ); | 444 | mOrphanUids.insert( incidence->uid(), incidence ); |
426 | } | 445 | } |
427 | } | 446 | } |
428 | } | 447 | } |
429 | 448 | ||
430 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 449 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
431 | void Calendar::removeRelations( Incidence *incidence ) | 450 | void Calendar::removeRelations( Incidence *incidence ) |
432 | { | 451 | { |
433 | // qDebug("Calendar::removeRelations "); | 452 | // qDebug("Calendar::removeRelations "); |
434 | QString uid = incidence->uid(); | 453 | QString uid = incidence->uid(); |
435 | 454 | ||
436 | QPtrList<Incidence> relations = incidence->relations(); | 455 | QPtrList<Incidence> relations = incidence->relations(); |
437 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 456 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
438 | if( !mOrphanUids.find( i->uid() ) ) { | 457 | if( !mOrphanUids.find( i->uid() ) ) { |
439 | mOrphans.insert( uid, i ); | 458 | mOrphans.insert( uid, i ); |
440 | mOrphanUids.insert( i->uid(), i ); | 459 | mOrphanUids.insert( i->uid(), i ); |
441 | i->setRelatedTo( 0 ); | 460 | i->setRelatedTo( 0 ); |
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 | ||
463 | void Calendar::registerObserver( Observer *observer ) | 497 | void Calendar::registerObserver( Observer *observer ) |
464 | { | 498 | { |
465 | mObserver = observer; | 499 | mObserver = observer; |
466 | mNewObserver = true; | 500 | mNewObserver = true; |
467 | } | 501 | } |
468 | 502 | ||
469 | void Calendar::setModified( bool modified ) | 503 | void Calendar::setModified( bool modified ) |
470 | { | 504 | { |
471 | if ( mObserver ) mObserver->calendarModified( modified, this ); | 505 | if ( mObserver ) mObserver->calendarModified( modified, this ); |
472 | if ( modified != mModified || mNewObserver ) { | 506 | if ( modified != mModified || mNewObserver ) { |
473 | mNewObserver = false; | 507 | mNewObserver = false; |
474 | // if ( mObserver ) mObserver->calendarModified( modified, this ); | 508 | // if ( mObserver ) mObserver->calendarModified( modified, this ); |
475 | mModified = modified; | 509 | mModified = modified; |
476 | } | 510 | } |
477 | } | 511 | } |
478 | 512 | ||
479 | void Calendar::setLoadedProductId( const QString &id ) | 513 | void Calendar::setLoadedProductId( const QString &id ) |
480 | { | 514 | { |
481 | mLoadedProductId = id; | 515 | mLoadedProductId = id; |
482 | } | 516 | } |
483 | 517 | ||
484 | QString Calendar::loadedProductId() | 518 | QString Calendar::loadedProductId() |
485 | { | 519 | { |
486 | return mLoadedProductId; | 520 | return mLoadedProductId; |
487 | } | 521 | } |
488 | 522 | ||
489 | //#include "calendar.moc" | 523 | //#include "calendar.moc" |