summaryrefslogtreecommitdiffabout
path: root/libkcal/incidence.cpp
Side-by-side diff
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;
Incidence::Incidence() :
IncidenceBase(),
mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3)
{
- mRecurrence = new Recurrence(this);
+ mRecurrence = 0;//new Recurrence(this);
mCancelled = false;
recreate();
mHasStartDate = true;
mAlarms.setAutoDelete(true);
@@ -77,9 +77,12 @@ Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
}
mAlarms.setAutoDelete(true);
mHasRecurrenceID = i.mHasRecurrenceID;
mRecurrenceID = i.mRecurrenceID;
+ if ( i.mRecurrence )
mRecurrence = new Recurrence( *(i.mRecurrence), this );
+ else
+ mRecurrence = 0;
mHoliday = i.mHoliday ;
mBirthday = i.mBirthday;
mAnniversary = i.mAnniversary;
}
@@ -92,8 +95,9 @@ Incidence::~Incidence()
for (ev=Relations.first();ev;ev=Relations.next()) {
if (ev->relatedTo() == this) ev->setRelatedTo(0);
}
if (relatedTo()) relatedTo()->removeRelation(this);
+ if ( mRecurrence )
delete mRecurrence;
}
@@ -207,12 +211,26 @@ bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
}
} else {
return false;
}
- if (!( *i1.recurrence() == *i2.recurrence()) ) {
- qDebug("recurrence is NOT equal ");
+ if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) {
+ if (!( *i1.mRecurrence == *i2.mRecurrence) ) {
+ //qDebug("recurrence is NOT equal ");
+ return false;
+ }
+ } else {
+ // one ( or both ) recurrence is 0
+ if ( i1.mRecurrence == 0 ) {
+ if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone )
+ return false;
+ } else {
+ // i1.mRecurrence != 0
+ // i2.mRecurrence == 0
+ if ( i1.mRecurrence->doesRecur() != Recurrence::rNone )
return false;
}
+ }
+
return
// i1.created() == i2.created() &&
stringCompare( i1.description(), i2.description() ) &&
stringCompare( i1.summary(), i2.summary() ) &&
@@ -278,9 +296,10 @@ void Incidence::cloneRelations( Incidence * newInc )
}
void Incidence::setReadOnly( bool readOnly )
{
IncidenceBase::setReadOnly( readOnly );
- recurrence()->setRecurReadOnly( readOnly);
+ if ( mRecurrence )
+ mRecurrence->setRecurReadOnly( readOnly);
}
void Incidence::setLastModifiedSubInvalid()
{
mLastModifiedSub = QDateTime();
@@ -329,9 +348,11 @@ int Incidence::revision() const
void Incidence::setDtStart(const QDateTime &dtStart)
{
QDateTime dt = getEvenTime(dtStart);
- recurrence()->setRecurStart( dt);
+
+ if ( mRecurrence )
+ mRecurrence->setRecurStart( dt);
IncidenceBase::setDtStart( dt );
}
void Incidence::setDescription(const QString &description)
@@ -503,17 +524,16 @@ void Incidence::removeRelation(Incidence *event)
}
bool Incidence::recursOn(const QDate &qd) const
{
- if (recurrence()->recursOnPure(qd) && !isException(qd)) return true;
+ if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true;
else return false;
}
void Incidence::setExDates(const DateList &exDates)
{
if (mReadOnly) return;
mExDates = exDates;
-
recurrence()->setRecurExDatesCount(mExDates.count());
updated();
}
@@ -697,15 +717,21 @@ bool Incidence::isAlarmEnabled() const
return true;
}
return false;
}
-
-Recurrence *Incidence::recurrence() const
+#include <stdlib.h>
+Recurrence *Incidence::recurrence()
{
+ if ( ! mRecurrence ) {
+ mRecurrence = new Recurrence(this);
+ qDebug("creating new recurence ");
+ //abort();
+ }
return mRecurrence;
}
void Incidence::setRecurrence( Recurrence * r)
{
+ if ( mRecurrence )
delete mRecurrence;
mRecurrence = r;
}
@@ -719,8 +745,13 @@ void Incidence::setLocation(const QString &location)
QString Incidence::location() const
{
return mLocation;
}
+QString Incidence::recurrenceText() const
+{
+ if ( mRecurrence ) return mRecurrence->recurrenceText();
+ return i18n("No");
+}
ushort Incidence::doesRecur() const
{
if ( mRecurrence ) return mRecurrence->doesRecur();
@@ -732,14 +763,14 @@ QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const
QDateTime incidenceStart = dt;
*ok = false;
if ( doesRecur() ) {
bool last;
- recurrence()->getPreviousDateTime( incidenceStart , &last );
+ mRecurrence->getPreviousDateTime( incidenceStart , &last );
int count = 0;
if ( !last ) {
while ( !last ) {
++count;
- incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last );
+ incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last );
if ( recursOn( incidenceStart.date() ) ) {
last = true; // exit while llop
} else {
if ( last ) { // no alarm on last recurrence