summaryrefslogtreecommitdiffabout
path: root/libkcal/incidence.cpp
Unidiff
Diffstat (limited to 'libkcal/incidence.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/incidence.cpp53
1 files changed, 42 insertions, 11 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index e4bcc5e..4643a3a 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -32,9 +32,9 @@ using namespace KCal;
32Incidence::Incidence() : 32Incidence::Incidence() :
33 IncidenceBase(), 33 IncidenceBase(),
34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) 34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3)
35{ 35{
36 mRecurrence = new Recurrence(this); 36 mRecurrence = 0;//new Recurrence(this);
37 mCancelled = false; 37 mCancelled = false;
38 recreate(); 38 recreate();
39 mHasStartDate = true; 39 mHasStartDate = true;
40 mAlarms.setAutoDelete(true); 40 mAlarms.setAutoDelete(true);
@@ -77,9 +77,12 @@ Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
77 } 77 }
78 mAlarms.setAutoDelete(true); 78 mAlarms.setAutoDelete(true);
79 mHasRecurrenceID = i.mHasRecurrenceID; 79 mHasRecurrenceID = i.mHasRecurrenceID;
80 mRecurrenceID = i.mRecurrenceID; 80 mRecurrenceID = i.mRecurrenceID;
81 if ( i.mRecurrence )
81 mRecurrence = new Recurrence( *(i.mRecurrence), this ); 82 mRecurrence = new Recurrence( *(i.mRecurrence), this );
83 else
84 mRecurrence = 0;
82 mHoliday = i.mHoliday ; 85 mHoliday = i.mHoliday ;
83 mBirthday = i.mBirthday; 86 mBirthday = i.mBirthday;
84 mAnniversary = i.mAnniversary; 87 mAnniversary = i.mAnniversary;
85} 88}
@@ -92,8 +95,9 @@ Incidence::~Incidence()
92 for (ev=Relations.first();ev;ev=Relations.next()) { 95 for (ev=Relations.first();ev;ev=Relations.next()) {
93 if (ev->relatedTo() == this) ev->setRelatedTo(0); 96 if (ev->relatedTo() == this) ev->setRelatedTo(0);
94 } 97 }
95 if (relatedTo()) relatedTo()->removeRelation(this); 98 if (relatedTo()) relatedTo()->removeRelation(this);
99 if ( mRecurrence )
96 delete mRecurrence; 100 delete mRecurrence;
97 101
98} 102}
99 103
@@ -207,12 +211,26 @@ bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
207 } 211 }
208 } else { 212 } else {
209 return false; 213 return false;
210 } 214 }
211 if (!( *i1.recurrence() == *i2.recurrence()) ) { 215 if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) {
212 qDebug("recurrence is NOT equal "); 216 if (!( *i1.mRecurrence == *i2.mRecurrence) ) {
217 //qDebug("recurrence is NOT equal ");
218 return false;
219 }
220 } else {
221 // one ( or both ) recurrence is 0
222 if ( i1.mRecurrence == 0 ) {
223 if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone )
224 return false;
225 } else {
226 // i1.mRecurrence != 0
227 // i2.mRecurrence == 0
228 if ( i1.mRecurrence->doesRecur() != Recurrence::rNone )
213 return false; 229 return false;
214 } 230 }
231 }
232
215 return 233 return
216 // i1.created() == i2.created() && 234 // i1.created() == i2.created() &&
217 stringCompare( i1.description(), i2.description() ) && 235 stringCompare( i1.description(), i2.description() ) &&
218 stringCompare( i1.summary(), i2.summary() ) && 236 stringCompare( i1.summary(), i2.summary() ) &&
@@ -278,9 +296,10 @@ void Incidence::cloneRelations( Incidence * newInc )
278} 296}
279void Incidence::setReadOnly( bool readOnly ) 297void Incidence::setReadOnly( bool readOnly )
280{ 298{
281 IncidenceBase::setReadOnly( readOnly ); 299 IncidenceBase::setReadOnly( readOnly );
282 recurrence()->setRecurReadOnly( readOnly); 300 if ( mRecurrence )
301 mRecurrence->setRecurReadOnly( readOnly);
283} 302}
284void Incidence::setLastModifiedSubInvalid() 303void Incidence::setLastModifiedSubInvalid()
285{ 304{
286 mLastModifiedSub = QDateTime(); 305 mLastModifiedSub = QDateTime();
@@ -329,9 +348,11 @@ int Incidence::revision() const
329void Incidence::setDtStart(const QDateTime &dtStart) 348void Incidence::setDtStart(const QDateTime &dtStart)
330{ 349{
331 350
332 QDateTime dt = getEvenTime(dtStart); 351 QDateTime dt = getEvenTime(dtStart);
333 recurrence()->setRecurStart( dt); 352
353 if ( mRecurrence )
354 mRecurrence->setRecurStart( dt);
334 IncidenceBase::setDtStart( dt ); 355 IncidenceBase::setDtStart( dt );
335} 356}
336 357
337void Incidence::setDescription(const QString &description) 358void Incidence::setDescription(const QString &description)
@@ -503,17 +524,16 @@ void Incidence::removeRelation(Incidence *event)
503} 524}
504 525
505bool Incidence::recursOn(const QDate &qd) const 526bool Incidence::recursOn(const QDate &qd) const
506{ 527{
507 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; 528 if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true;
508 else return false; 529 else return false;
509} 530}
510 531
511void Incidence::setExDates(const DateList &exDates) 532void Incidence::setExDates(const DateList &exDates)
512{ 533{
513 if (mReadOnly) return; 534 if (mReadOnly) return;
514 mExDates = exDates; 535 mExDates = exDates;
515
516 recurrence()->setRecurExDatesCount(mExDates.count()); 536 recurrence()->setRecurExDatesCount(mExDates.count());
517 537
518 updated(); 538 updated();
519} 539}
@@ -697,15 +717,21 @@ bool Incidence::isAlarmEnabled() const
697 return true; 717 return true;
698 } 718 }
699 return false; 719 return false;
700} 720}
701 721#include <stdlib.h>
702Recurrence *Incidence::recurrence() const 722Recurrence *Incidence::recurrence()
703{ 723{
724 if ( ! mRecurrence ) {
725 mRecurrence = new Recurrence(this);
726 qDebug("creating new recurence ");
727 //abort();
728 }
704 return mRecurrence; 729 return mRecurrence;
705} 730}
706void Incidence::setRecurrence( Recurrence * r) 731void Incidence::setRecurrence( Recurrence * r)
707{ 732{
733 if ( mRecurrence )
708 delete mRecurrence; 734 delete mRecurrence;
709 mRecurrence = r; 735 mRecurrence = r;
710} 736}
711 737
@@ -719,8 +745,13 @@ void Incidence::setLocation(const QString &location)
719QString Incidence::location() const 745QString Incidence::location() const
720{ 746{
721 return mLocation; 747 return mLocation;
722} 748}
749QString Incidence::recurrenceText() const
750{
751 if ( mRecurrence ) return mRecurrence->recurrenceText();
752 return i18n("No");
753}
723 754
724ushort Incidence::doesRecur() const 755ushort Incidence::doesRecur() const
725{ 756{
726 if ( mRecurrence ) return mRecurrence->doesRecur(); 757 if ( mRecurrence ) return mRecurrence->doesRecur();
@@ -732,14 +763,14 @@ QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const
732 QDateTime incidenceStart = dt; 763 QDateTime incidenceStart = dt;
733 *ok = false; 764 *ok = false;
734 if ( doesRecur() ) { 765 if ( doesRecur() ) {
735 bool last; 766 bool last;
736 recurrence()->getPreviousDateTime( incidenceStart , &last ); 767 mRecurrence->getPreviousDateTime( incidenceStart , &last );
737 int count = 0; 768 int count = 0;
738 if ( !last ) { 769 if ( !last ) {
739 while ( !last ) { 770 while ( !last ) {
740 ++count; 771 ++count;
741 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); 772 incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last );
742 if ( recursOn( incidenceStart.date() ) ) { 773 if ( recursOn( incidenceStart.date() ) ) {
743 last = true; // exit while llop 774 last = true; // exit while llop
744 } else { 775 } else {
745 if ( last ) { // no alarm on last recurrence 776 if ( last ) { // no alarm on last recurrence