-rw-r--r-- | libopie/pim/orecur.cpp | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/libopie/pim/orecur.cpp b/libopie/pim/orecur.cpp index e6a4787..e3b45b4 100644 --- a/libopie/pim/orecur.cpp +++ b/libopie/pim/orecur.cpp @@ -1,28 +1,31 @@ +#include <time.h> + #include <qshared.h> #include <qtopia/timeconversion.h> +#include "otimezone.h" #include "orecur.h" struct ORecur::Data : public QShared { Data() : QShared() { type = ORecur::NoRepeat; freq = -1; days = 0; pos = 0; create = QDateTime::currentDateTime(); hasEnd = FALSE; end = QDate::currentDate(); } char days; // Q_UINT8 for 8 seven days;) ORecur::RepeatType type; int freq; int pos; bool hasEnd : 1; QDate end; QDateTime create; int rep; QString app; ExceptionList list; QDate start; }; @@ -60,63 +63,71 @@ ORecur &ORecur::operator=( const ORecur& re) { return *this; } bool ORecur::doesRecur()const { return !( type() == NoRepeat ); } /* * we try to be smart here * */ bool ORecur::doesRecur( const QDate& date ) { /* the day before the recurrance */ QDate da = date.addDays(-1); QDate recur; if (!nextOcurrence( da, recur ) ) return false; return (recur == date); } // FIXME unuglify! // GPL from Datebookdb.cpp // FIXME exception list! bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { + bool stillLooking; + stillLooking = p_nextOccurrence( from, next ); + while ( stillLooking && data->list.contains(next) ) + stillLooking = p_nextOccurrence( next.addDays(1), next ); + + return stillLooking; +} +bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { // easy checks, first are we too far in the future or too far in the past? QDate tmpDate; int freq = frequency(); int diff, diff2, a; int iday, imonth, iyear; int dayOfWeek = 0; int firstOfWeek = 0; int weekOfMonth; if (hasEndDate() && endDate() < from) return FALSE; - if (start() >= from) { + if (start() >= from ) { next = start(); return TRUE; } switch ( type() ) { case Weekly: /* weekly is just daily by 7 */ /* first convert the repeatPattern.Days() mask to the next day of week valid after from */ dayOfWeek = from.dayOfWeek(); dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ /* this is done in case freq > 1 and from in week not for this round */ // firstOfWeek = 0; this is already done at decl. while(!((1 << firstOfWeek) & days() )) firstOfWeek++; /* there is at least one 'day', or there would be no event */ while(!((1 << (dayOfWeek % 7)) & days() )) dayOfWeek++; dayOfWeek = dayOfWeek % 7; /* the actual day of week */ dayOfWeek -= start().dayOfWeek() -1; @@ -422,25 +433,78 @@ void ORecur::setService( const QString& app ) { data->app = app; } void ORecur::setStart( const QDate& dt ) { checkOrModify(); data->start = dt; } void ORecur::checkOrModify() { if ( data->count != 1 ) { data->deref(); Data* d2 = new Data; d2->days = data->days; d2->type = data->type; d2->freq = data->freq; d2->pos = data->pos; d2->hasEnd = data->hasEnd; d2->end = data->end; d2->create = data->create; d2->rep = data->rep; d2->app = data->app; d2->list = data->list; d2->start = data->start; data = d2; } } +QString ORecur::toString()const { + QString buf; + + buf += " rtype=\""; + switch ( data->type ) { + case ORecur::Daily: + buf += "Daily"; + break; + case ORecur::Weekly: + buf += "Weekly"; + break; + case ORecur::MonthlyDay: + buf += "MonthlyDay"; + break; + case ORecur::MonthlyDate: + buf += "MonthlyDate"; + break; + case ORecur::Yearly: + buf += "Yearly"; + break; + default: + buf += "NoRepeat"; + break; + } + buf += "\""; + if (data->days > 0 ) + buf += " rweekdays=\"" + QString::number( static_cast<int>( data->days ) ) + "\""; + if ( data->pos != 0 ) + buf += " rposition=\"" + QString::number(data->pos ) + "\""; + + buf += " rfreq=\"" + QString::number( data->freq ) + "\""; + buf += " rhasenddate=\"" + QString::number( static_cast<int>( data->hasEnd ) ) + "\""; + if ( data->hasEnd ) + buf += " enddt=\"" + + QString::number( OTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) + + "\""; + buf += " created=\"" + QString::number( OTimeZone::utc().fromUTCDateTime( data->create ) ) + "\""; + + if ( data->list.isEmpty() ) return buf; + // save exceptions list here!! + ExceptionList::ConstIterator it; + ExceptionList list = data->list; + buf += " exceptions=\""; + QDate date; + for ( it = list.begin(); it != list.end(); ++it ) { + date = (*it); + if ( it != list.begin() ) buf += " "; + + buf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); + } + buf += "\""; + return buf; +} |