summaryrefslogtreecommitdiffabout
path: root/libkcal/calendar.cpp
authorzautrix <zautrix>2005-07-30 14:43:57 (UTC)
committer zautrix <zautrix>2005-07-30 14:43:57 (UTC)
commit9ca2cd947f22d33543e065f54c6487e86d80befa (patch) (unidiff)
tree549192e9e27e8972e2b48cf40e1599118df12da5 /libkcal/calendar.cpp
parent055928e26613f4ab249bd82be86890ed278372f6 (diff)
downloadkdepimpi-9ca2cd947f22d33543e065f54c6487e86d80befa.zip
kdepimpi-9ca2cd947f22d33543e065f54c6487e86d80befa.tar.gz
kdepimpi-9ca2cd947f22d33543e065f54c6487e86d80befa.tar.bz2
fixxx
Diffstat (limited to 'libkcal/calendar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp42
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
@@ -65,99 +65,118 @@ void Calendar::init()
65 // even that good of one at that. 65 // even that good of one at that.
66// srandom(time(0)); 66// srandom(time(0));
67 67
68 // user information... 68 // user information...
69 setOwner(i18n("Unknown Name")); 69 setOwner(i18n("Unknown Name"));
70 setEmail(i18n("unknown@nowhere")); 70 setEmail(i18n("unknown@nowhere"));
71 71
72#if 0 72#if 0
73 tmpStr = KOPrefs::instance()->mTimeZone; 73 tmpStr = KOPrefs::instance()->mTimeZone;
74// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; 74// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
75 int dstSetting = KOPrefs::instance()->mDaylightSavings; 75 int dstSetting = KOPrefs::instance()->mDaylightSavings;
76 extern long int timezone; 76 extern long int timezone;
77 struct tm *now; 77 struct tm *now;
78 time_t curtime; 78 time_t curtime;
79 curtime = time(0); 79 curtime = time(0);
80 now = localtime(&curtime); 80 now = localtime(&curtime);
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
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}
124int Calendar::defaultCalendar() 143int Calendar::defaultCalendar()
125{ 144{
126 return mDefaultCalendar; 145 return mDefaultCalendar;
127} 146}
128const QString &Calendar::getOwner() const 147const QString &Calendar::getOwner() const
129{ 148{
130 return mOwner; 149 return mOwner;
131} 150}
132 151
133bool Calendar::undoDeleteIncidence() 152bool 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}
141void Calendar::setOwner(const QString &os) 160void 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);
148 167
149 setModified( true ); 168 setModified( true );
150} 169}
151 170
152void Calendar::setTimeZone(const QString & tz) 171void Calendar::setTimeZone(const QString & tz)
153{ 172{
154 bool neg = FALSE; 173 bool neg = FALSE;
155 int hours, minutes; 174 int hours, minutes;
156 QString tmpStr(tz); 175 QString tmpStr(tz);
157 176
158 if (tmpStr.left(1) == "-") 177 if (tmpStr.left(1) == "-")
159 neg = TRUE; 178 neg = TRUE;
160 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 179 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
161 tmpStr.remove(0, 1); 180 tmpStr.remove(0, 1);
162 hours = tmpStr.left(2).toInt(); 181 hours = tmpStr.left(2).toInt();
163 if (tmpStr.length() > 2) 182 if (tmpStr.length() > 2)
@@ -402,88 +421,103 @@ void Calendar::setupRelations( Incidence *incidence )
402{ 421{
403 QString uid = incidence->uid(); 422 QString uid = incidence->uid();
404 //qDebug("Calendar::setupRelations "); 423 //qDebug("Calendar::setupRelations ");
405 // First, go over the list of orphans and see if this is their parent 424 // First, go over the list of orphans and see if this is their parent
406 while( Incidence* i = mOrphans[ uid ] ) { 425 while( Incidence* i = mOrphans[ uid ] ) {
407 mOrphans.remove( uid ); 426 mOrphans.remove( uid );
408 i->setRelatedTo( incidence ); 427 i->setRelatedTo( incidence );
409 incidence->addRelation( i ); 428 incidence->addRelation( i );
410 mOrphanUids.remove( i->uid() ); 429 mOrphanUids.remove( i->uid() );
411 } 430 }
412 431
413 // Now see about this incidences parent 432 // Now see about this incidences parent
414 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 433 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
415 // This incidence has a uid it is related to, but is not registered to it yet 434 // This incidence has a uid it is related to, but is not registered to it yet
416 // Try to find it 435 // Try to find it
417 Incidence* parent = this->incidence( incidence->relatedToUid() ); 436 Incidence* parent = this->incidence( incidence->relatedToUid() );
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
431void Calendar::removeRelations( Incidence *incidence ) 450void 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
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
469void Calendar::setModified( bool modified ) 503void 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
479void Calendar::setLoadedProductId( const QString &id ) 513void Calendar::setLoadedProductId( const QString &id )
480{ 514{
481 mLoadedProductId = id; 515 mLoadedProductId = id;
482} 516}
483 517
484QString Calendar::loadedProductId() 518QString Calendar::loadedProductId()
485{ 519{
486 return mLoadedProductId; 520 return mLoadedProductId;
487} 521}
488 522
489//#include "calendar.moc" 523//#include "calendar.moc"