author | zautrix <zautrix> | 2005-02-13 17:05:02 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-13 17:05:02 (UTC) |
commit | 293271fe9e6a9061da329183f8f488d79580f7da (patch) (side-by-side diff) | |
tree | 3a0234eabdf58440a484e960b5eef912a63d0056 /libkcal | |
parent | 0a33f91e166747406ca2ccb5819881feeecfdb40 (diff) | |
download | kdepimpi-293271fe9e6a9061da329183f8f488d79580f7da.zip kdepimpi-293271fe9e6a9061da329183f8f488d79580f7da.tar.gz kdepimpi-293271fe9e6a9061da329183f8f488d79580f7da.tar.bz2 |
todo rec fixes
-rw-r--r-- | libkcal/incidence.cpp | 9 | ||||
-rw-r--r-- | libkcal/incidence.h | 5 | ||||
-rw-r--r-- | libkcal/incidencebase.cpp | 1 | ||||
-rw-r--r-- | libkcal/incidencebase.h | 4 | ||||
-rw-r--r-- | libkcal/todo.cpp | 47 | ||||
-rw-r--r-- | libkcal/todo.h | 2 |
6 files changed, 62 insertions, 6 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index dbc159c..0684af2 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp @@ -626,24 +626,33 @@ QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const int year = incidenceStart.date().year(); // workaround for bug in recurrence if ( count == 100 || year < 1000 || year > 5000 ) { return QDateTime (); } incidenceStart = incidenceStart.addSecs( 1 ); } } } else { return QDateTime (); } } else { if ( hasStartDate () ) { incidenceStart = dtStart(); } if ( type() =="Todo" ) { if ( ((Todo*)this)->hasDueDate() ) incidenceStart = ((Todo*)this)->dtDue(); } } if ( incidenceStart > dt ) *ok = true; return incidenceStart; } +QDateTime Incidence::dtStart() const +{ + if ( doesRecur() ) { + if ( type() == "Todo" ) { + ((Todo*)this)->checkSetCompletedFalse(); + } + } + return mDtStart; +} diff --git a/libkcal/incidence.h b/libkcal/incidence.h index 38d2aaa..0ae9656 100644 --- a/libkcal/incidence.h +++ b/libkcal/incidence.h @@ -248,60 +248,61 @@ class Incidence : public IncidenceBase Recurrence *recurrence() const; void setRecurrence(Recurrence * r); /** Forward to Recurrence::doesRecur(). */ ushort doesRecur() const; /** set the event's/todo's location. Do _not_ use it with journal */ void setLocation(const QString &location); /** return the event's/todo's location. Do _not_ use it with journal */ QString location() const; /** returns TRUE or FALSE depending on whether the todo has a start date */ bool hasStartDate() const; /** sets the event's hasStartDate value. */ void setHasStartDate(bool f); QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; bool cancelled() const; void setCancelled( bool b ); bool hasRecurrenceID() const; void setHasRecurrenceID( bool b ); void setRecurrenceID(QDateTime); QDateTime recurrenceID () const; + QDateTime dtStart() const; protected: QPtrList<Alarm> mAlarms; QPtrList<Incidence> mRelations; + QDateTime mRecurrenceID; + bool mHasRecurrenceID; private: int mRevision; bool mCancelled; // base components of jounal, event and todo - QDateTime mRecurrenceID; - bool mHasRecurrenceID; QDateTime mCreated; QString mDescription; QString mSummary; QStringList mCategories; Incidence *mRelatedTo; QString mRelatedToUid; DateList mExDates; QPtrList<Attachment> mAttachments; QStringList mResources; bool mHasStartDate; // if todo has associated start date int mSecrecy; int mPriority; // 1 = highest, 2 = less, etc. //QPtrList<Alarm> mAlarms; Recurrence *mRecurrence; QString mLocation; }; bool operator==( const Incidence&, const Incidence& ); } diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp index 7525a4a..51f2e9d 100644 --- a/libkcal/incidencebase.cpp +++ b/libkcal/incidencebase.cpp @@ -158,48 +158,49 @@ void IncidenceBase::setOrganizer(const QString &o) mOrganizer = o; if (mOrganizer.left(7).upper() == "MAILTO:") mOrganizer = mOrganizer.remove(0,7); updated(); } QString IncidenceBase::organizer() const { return mOrganizer; } void IncidenceBase::setReadOnly( bool readOnly ) { mReadOnly = readOnly; } void IncidenceBase::setDtStart(const QDateTime &dtStart) { // if (mReadOnly) return; mDtStart = getEvenTime(dtStart); updated(); } + QDateTime IncidenceBase::dtStart() const { return mDtStart; } QString IncidenceBase::dtStartTimeStr() const { return KGlobal::locale()->formatTime(dtStart().time()); } QString IncidenceBase::dtStartDateStr(bool shortfmt) const { return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); } QString IncidenceBase::dtStartStr(bool shortfmt) const { return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); } bool IncidenceBase::doesFloat() const { return mFloats; diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h index f9a6558..8624786 100644 --- a/libkcal/incidencebase.h +++ b/libkcal/incidencebase.h @@ -53,49 +53,49 @@ class IncidenceBase : public CustomProperties virtual QCString type() const = 0; /** Set the unique id for the event */ void setUid(const QString &); /** Return the unique id for the event */ QString uid() const; /** Sets the time the incidence was last modified. */ void setLastModified(const QDateTime &lm); /** Return the time the incidence was last modified. */ QDateTime lastModified() const; /** sets the organizer for the event */ void setOrganizer(const QString &o); QString organizer() const; /** Set readonly status. */ virtual void setReadOnly( bool ); /** Return if the object is read-only. */ bool isReadOnly() const { return mReadOnly; } /** for setting the event's starting date/time with a QDateTime. */ virtual void setDtStart(const QDateTime &dtStart); /** returns an event's starting date/time as a QDateTime. */ - QDateTime dtStart() const; + virtual QDateTime dtStart() const; /** returns an event's starting time as a string formatted according to the users locale settings */ QString dtStartTimeStr() const; /** returns an event's starting date as a string formatted according to the users locale settings */ QString dtStartDateStr(bool shortfmt=true) const; /** returns an event's starting date and time as a string formatted according to the users locale settings */ QString dtStartStr(bool shortfmt=true) const; virtual void setDuration(int seconds); int duration() const; void setHasDuration(bool); bool hasDuration() const; /** Return true or false depending on whether the incidence "floats," * i.e. has a date but no time attached to it. */ bool doesFloat() const; /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ void setFloats(bool f); /** Add Attendee to this incidence. IncidenceBase takes ownership of the Attendee object. @@ -120,53 +120,53 @@ class IncidenceBase : public CustomProperties void setSyncStatus(int stat); /** Return synchronisation status. */ int syncStatus() const; /** Set Pilot Id. */ void setPilotId(int id); /** Return Pilot Id. */ int pilotId() const; void setTempSyncStat(int id); int tempSyncStat() const; void setIDStr( const QString & ); QString IDStr() const; void setID( const QString &, const QString & ); QString getID( const QString & ); void setCsum( const QString &, const QString & ); QString getCsum( const QString & ); void removeID(const QString &); void registerObserver( Observer * ); void unRegisterObserver( Observer * ); void updated(); protected: + QDateTime mDtStart; bool mReadOnly; QDateTime getEvenTime( QDateTime ); private: // base components - QDateTime mDtStart; QString mOrganizer; QString mUid; QDateTime mLastModified; QPtrList<Attendee> mAttendees; bool mFloats; int mDuration; bool mHasDuration; QString mExternalId; int mTempSyncStat; // PILOT SYNCHRONIZATION STUFF int mPilotId; // unique id for pilot sync int mSyncStatus; // status (for sync) QPtrList<Observer> mObservers; }; bool operator==( const IncidenceBase&, const IncidenceBase& ); } #endif diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 9c04a7e..1f54c2f 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp @@ -290,97 +290,127 @@ QString Todo::statusStr() const return QString("SENT"); break; case TENTATIVE: return QString("TENTATIVE"); break; case CONFIRMED: return QString("CONFIRMED"); break; case DECLINED: return QString("DECLINED"); break; case COMPLETED: return QString("COMPLETED"); break; case DELEGATED: return QString("DELEGATED"); break; } return QString(""); } #endif bool Todo::isCompleted() const { - if (mPercentComplete == 100) return true; + if (mPercentComplete == 100) { + return true; + } else return false; } void Todo::setCompleted(bool completed) { + if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { + if ( !setRecurDates() ) + completed = false; + } if (completed) mPercentComplete = 100; else { mPercentComplete = 0; mHasCompletedDate = false; } updated(); } QDateTime Todo::completed() const { return mCompleted; } QString Todo::completedStr( bool shortF ) const { return KGlobal::locale()->formatDateTime(mCompleted, shortF); } void Todo::setCompleted(const QDateTime &completed) { //qDebug("Todo::setCompleted "); if ( mHasCompletedDate ) { // qDebug("has completed data - return "); return; } mHasCompletedDate = true; mPercentComplete = 100; mCompleted = getEvenTime(completed); updated(); } bool Todo::hasCompletedDate() const { return mHasCompletedDate; } int Todo::percentComplete() const { return mPercentComplete; } - +bool Todo::setRecurDates() +{ + if ( !mHasRecurrenceID ) + return true; + int secs = mDtStart.secsTo( dtDue() ); + bool ok; + qDebug("--------------------setRecurDates() "); + //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); + QDateTime next = getNextOccurence( mRecurrenceID, &ok ); + if ( ok ) { + mRecurrenceID = next; + mDtStart = next; + setDtDue( next.addSecs( secs ) ); + if ( QDateTime::currentDateTime() > next) + return false; + } else { + setHasRecurrenceID( false ); + recurrence()->unsetRecurs(); + } + return true; +} void Todo::setPercentComplete(int v) { + if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { + if ( !setRecurDates() ) + v = 0; + } mPercentComplete = v; if ( v != 100 ) mHasCompletedDate = false; updated(); } QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const { if ( isCompleted() || ! hasDueDate() || cancelled() ) { *ok = false; return QDateTime (); } QDateTime incidenceStart; incidenceStart = dtDue(); bool enabled = false; Alarm* alarm; int off = 0; QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; // if ( QDateTime::currentDateTime() > incidenceStart ){ // *ok = false; // return incidenceStart; // } for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { if (alarm->enabled()) { if ( alarm->hasTime () ) { @@ -391,24 +421,37 @@ QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const } } else { int secs = alarm->startOffset().asSeconds(); if ( incidenceStart.addSecs( secs ) < alarmStart ) { alarmStart = incidenceStart.addSecs( secs ); enabled = true; off = -secs; } } } } if ( enabled ) { if ( alarmStart > QDateTime::currentDateTime() ) { *ok = true; * offset = off; return alarmStart; } } *ok = false; return QDateTime (); } +void Todo::checkSetCompletedFalse() +{ + if ( !hasRecurrenceID() ) { + qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); + } + // qDebug("Todo::checkSetCompletedFalse()"); + //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); + if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) { + qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); + setCompleted( false ); + qDebug("Todo::checkSetCompletedFalse++++++++++++++++++++++++++++ "); + } +} diff --git a/libkcal/todo.h b/libkcal/todo.h index 137b252..a22d4b7 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h @@ -91,44 +91,46 @@ class Todo : public Incidence bool isCompleted() const; /** set completed state of this todo */ void setCompleted(bool); /** Return how many percent of the task are completed. Returns a value between 0 and 100. */ int percentComplete() const; /** Set how many percent of the task are completed. Valid values are in the range from 0 to 100. */ void setPercentComplete(int); /** return date and time when todo was completed */ QDateTime completed() const; QString completedStr(bool shortF = true) const; /** set date and time of completion */ void setCompleted(const QDateTime &completed); /** Return true, if todo has a date associated with completion */ bool hasCompletedDate() const; bool contains ( Todo*); + void checkSetCompletedFalse(); + bool setRecurDates(); private: bool accept(Visitor &v) { return v.visit(this); } QDateTime mDtDue; // due date of todo bool mHasDueDate; // if todo has associated due date // int mStatus; // confirmed/delegated/tentative/etc QDateTime mCompleted; bool mHasCompletedDate; int mPercentComplete; }; bool operator==( const Todo&, const Todo& ); } #endif |