summaryrefslogtreecommitdiffabout
path: root/libkcal/recurrence.cpp
Side-by-side diff
Diffstat (limited to 'libkcal/recurrence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/recurrence.cpp56
1 files changed, 44 insertions, 12 deletions
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp
index dd74e10..e84f672 100644
--- a/libkcal/recurrence.cpp
+++ b/libkcal/recurrence.cpp
@@ -61,124 +61,156 @@ Recurrence::Recurrence(const Recurrence &r, Incidence *parent)
rDuration(r.rDuration),
rEndDateTime(r.rEndDateTime),
mRecurStart(r.mRecurStart),
mFloats(r.mFloats),
mRecurReadOnly(r.mRecurReadOnly),
mRecurExDatesCount(r.mRecurExDatesCount),
mFeb29YearlyType(r.mFeb29YearlyType),
mCompatVersion(r.mCompatVersion),
mCompatRecurs(r.mCompatRecurs),
mCompatDuration(r.mCompatDuration),
mParent(parent)
{
for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) {
rMonthPos *tmp = new rMonthPos;
tmp->rPos = mp.current()->rPos;
tmp->negative = mp.current()->negative;
tmp->rDays = mp.current()->rDays.copy();
rMonthPositions.append(tmp);
}
for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) {
int *tmp = new int;
*tmp = *md.current();
rMonthDays.append(tmp);
}
for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) {
int *tmp = new int;
*tmp = *yn.current();
rYearNums.append(tmp);
}
rMonthDays.setAutoDelete( true );
rMonthPositions.setAutoDelete( true );
rYearNums.setAutoDelete( true );
}
Recurrence::~Recurrence()
{
}
bool Recurrence::operator==( const Recurrence& r2 ) const
{
// the following line is obvious
if ( recurs == rNone && r2.recurs == rNone )
return true;
// we need the above line, because two non recurring events may
// differ in the other settings, because one (or both)
// may be not initialized properly
+
if ( recurs != r2.recurs
|| rFreq != r2.rFreq
|| rDuration != r2.rDuration
|| !rDuration && rEndDateTime != r2.rEndDateTime
|| mRecurStart != r2.mRecurStart
|| mFloats != r2.mFloats
|| mRecurReadOnly != r2.mRecurReadOnly
|| mRecurExDatesCount != r2.mRecurExDatesCount )
return false;
// no need to compare mCompat* and mParent
// OK to compare the pointers
switch ( recurs )
{
case rWeekly:
return rDays == r2.rDays
&& rWeekStart == r2.rWeekStart;
- case rMonthlyPos:
- return rMonthPositions.count() == r2.rMonthPositions.count();
- case rMonthlyDay:
- return rMonthDays.count() == r2.rMonthDays.count();
- case rYearlyPos:
- return rYearNums.count() == r2.rYearNums.count()
- && rMonthPositions.count() == r2.rMonthPositions.count();
- case rYearlyMonth:
- return rYearNums.count() == r2.rYearNums.count()
- && mFeb29YearlyType == r2.mFeb29YearlyType;
- case rYearlyDay:
- return rYearNums == r2.rYearNums;
+ case rMonthlyPos: {
+ QPtrList<rMonthPos> MonthPositions = rMonthPositions;
+ QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions;
+ if ( !MonthPositions.count() )
+ return false;
+ if ( !MonthPositions2.count() )
+ return false;
+ return MonthPositions.first()->rPos == MonthPositions2.first()->rPos;
+ }
+ case rMonthlyDay: {
+ QPtrList<int> MonthDays = rMonthDays ;
+ QPtrList<int> MonthDays2 = r2.rMonthDays ;
+ if ( !MonthDays.count() )
+ return false;
+ if ( !MonthDays2.count() )
+ return false;
+ return *MonthDays.first() == *MonthDays2.first() ;
+ }
+ case rYearlyPos: {
+
+ QPtrList<int> YearNums = rYearNums;
+ QPtrList<int> YearNums2 = r2.rYearNums;
+ if ( *YearNums.first() != *YearNums2.first() )
+ return false;
+ QPtrList<rMonthPos> MonthPositions = rMonthPositions;
+ QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions;
+ if ( !MonthPositions.count() )
+ return false;
+ if ( !MonthPositions2.count() )
+ return false;
+ return MonthPositions.first()->rPos == MonthPositions2.first()->rPos;
+
+ }
+ case rYearlyMonth: {
+ QPtrList<int> YearNums = rYearNums;
+ QPtrList<int> YearNums2 = r2.rYearNums;
+ return ( *YearNums.first() == *YearNums2.first() && mFeb29YearlyType == r2.mFeb29YearlyType);
+ }
+ case rYearlyDay: {
+ QPtrList<int> YearNums = rYearNums;
+ QPtrList<int> YearNums2 = r2.rYearNums;
+ return ( *YearNums.first() == *YearNums2.first() );
+ }
case rNone:
case rMinutely:
case rHourly:
case rDaily:
default:
return true;
}
}
/*
bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2)
{
if ( l1.count() != l2.count() )
return false;
int count = l1.count();
int i;
for ( i = 0; i < count ; ++i ) {
// if ( l1.at(i) != l2.at(i) )
return false;
qDebug("compüare ");
}
return true;
}
*/
QString Recurrence::recurrenceText() const
{
QString recurText = i18n("No");
if ( recurs == Recurrence::rMinutely )
recurText = i18n("minutely");
else if ( recurs == Recurrence::rHourly )
recurText = i18n("hourly");
else if ( recurs == Recurrence::rDaily )
recurText = i18n("daily");
else if ( recurs == Recurrence::rWeekly )
recurText = i18n("weekly");
else if ( recurs == Recurrence::rMonthlyPos )
recurText = i18n("monthly");
else if ( recurs == Recurrence::rMonthlyDay )
recurText = i18n("day-monthly");
else if ( recurs == Recurrence::rYearlyMonth )
recurText = i18n("month-yearly");
else if ( recurs == Recurrence::rYearlyDay )
recurText = i18n("day-yearly");
else if ( recurs == Recurrence::rYearlyPos )
recurText = i18n("position-yearly");
return recurText;
}
void Recurrence::setCompatVersion(int version)