-rw-r--r-- | libopie2/opiepim/oevent.cpp | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp index 71b9441..aaae3b2 100644 --- a/libopie2/opiepim/oevent.cpp +++ b/libopie2/opiepim/oevent.cpp @@ -1,181 +1,180 @@ #include <qshared.h> #include <qpe/palmtopuidgen.h> #include <qpe/categories.h> #include "orecur.h" #include "opimresolver.h" #include "opimnotifymanager.h" #include "oevent.h" -namespace OCalendarHelper { - static int week( const QDate& date) { - // Calculates the week this date is in within that - // month. Equals the "row" is is in in the month view - int week = 1; - QDate tmp( date.year(), date.month(), 1 ); - if ( date.dayOfWeek() < tmp.dayOfWeek() ) - ++week; +int OCalendarHelper::week( const QDate& date) { + // Calculates the week this date is in within that + // month. Equals the "row" is is in in the month view + int week = 1; + QDate tmp( date.year(), date.month(), 1 ); + if ( date.dayOfWeek() < tmp.dayOfWeek() ) + ++week; - week += ( date.day() - 1 ) / 7; + week += ( date.day() - 1 ) / 7; - return week; - } - static int occurence( const QDate& date) { - // calculates the number of occurrances of this day of the - // week till the given date (e.g 3rd Wednesday of the month) - return ( date.day() - 1 ) / 7 + 1; - } - static int dayOfWeek( char day ) { - int dayOfWeek = 1; - char i = ORecur::MON; - while ( !( i & day ) && i <= ORecur::SUN ) { - i <<= 1; - ++dayOfWeek; - } - return dayOfWeek; - } - static int monthDiff( const QDate& first, const QDate& second ) { - return ( second.year() - first.year() ) * 12 + - second.month() - first.month(); + return week; +} +int OCalendarHelper::ocurrence( const QDate& date) { + // calculates the number of occurrances of this day of the + // week till the given date (e.g 3rd Wednesday of the month) + return ( date.day() - 1 ) / 7 + 1; +} +int OCalendarHelper::dayOfWeek( char day ) { + int dayOfWeek = 1; + char i = ORecur::MON; + while ( !( i & day ) && i <= ORecur::SUN ) { + i <<= 1; + ++dayOfWeek; } + return dayOfWeek; +} +int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { + return ( second.year() - first.year() ) * 12 + + second.month() - first.month(); } struct OEvent::Data : public QShared { Data() : QShared() { recur = 0; manager = 0; isAllDay = false; } ~Data() { delete manager; delete recur; } QString description; QString location; OPimNotifyManager* manager; ORecur* recur; QString note; QDateTime created; QDateTime start; QDateTime end; bool isAllDay : 1; QString timezone; }; OEvent::OEvent( int uid ) : OPimRecord( uid ) { data = new Data; } OEvent::OEvent( const OEvent& ev) : OPimRecord( ev ), data( ev.data ) { data->ref(); } OEvent::~OEvent() { if ( data->deref() ) { delete data; data = 0; } } OEvent& OEvent::operator=( const OEvent& ev) { if ( *this == ev ) return *this; OPimRecord::operator=( ev ); ev.data->ref(); deref(); data = ev.data; return *this; } QString OEvent::description()const { return data->description; } void OEvent::setDescription( const QString& description ) { changeOrModify(); data->description = description; } void OEvent::setLocation( const QString& loc ) { changeOrModify(); data->location = loc; } QString OEvent::location()const { return data->location; } OPimNotifyManager &OEvent::notifiers() { // I hope we can skip the changeOrModify here // the notifier should take care of it // and OPimNotify is shared too if (!data->manager ) data->manager = new OPimNotifyManager; return *data->manager; } bool OEvent::hasNotifiers()const { return ( data->manager); } ORecur OEvent::recurrence()const { if (!data->recur) data->recur = new ORecur; return *data->recur; } void OEvent::setRecurrence( const ORecur& rec) { changeOrModify(); if (data->recur ) (*data->recur) = rec; else data->recur = new ORecur( rec ); } bool OEvent::hasRecurrence()const { - return data->recur; + if (!data->recur ) return false; + return data->recur->doesRecur(); } QString OEvent::note()const { return data->note; } void OEvent::setNote( const QString& note ) { changeOrModify(); data->note = note; } QDateTime OEvent::createdDateTime()const { return data->created; } void OEvent::setCreatedDateTime( const QDateTime& time ) { changeOrModify(); data->created = time; } QDateTime OEvent::startDateTime()const { if ( data->isAllDay ) return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); return data->start; } QDateTime OEvent::startDateTimeInZone()const { /* if no timezone, or all day event or if the current and this timeZone match... */ if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); OTimeZone zone(data->timezone ); return zone.toDateTime( data->start, OTimeZone::current() ); } void OEvent::setStartDateTime( const QDateTime& dt ) { changeOrModify(); data->start = dt; } QDateTime OEvent::endDateTime()const { /* * if all Day event the end time needs * to be on the same day as the start */ if ( data->isAllDay ) return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); return data->end; } QDateTime OEvent::endDateTimeInZone()const { /* if no timezone, or all day event or if the current and this timeZone match... */ if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); OTimeZone zone(data->timezone ); return zone.toDateTime( data->end, OTimeZone::current() ); } void OEvent::setEndDateTime( const QDateTime& dt ) { |