-rw-r--r-- | korganizer/kotodoeditor.cpp | 29 | ||||
-rw-r--r-- | korganizer/kotodoviewitem.cpp | 40 | ||||
-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 |
8 files changed, 130 insertions, 7 deletions
diff --git a/korganizer/kotodoeditor.cpp b/korganizer/kotodoeditor.cpp index 069dda8..9232e09 100644 --- a/korganizer/kotodoeditor.cpp +++ b/korganizer/kotodoeditor.cpp @@ -312,24 +312,26 @@ void KOTodoEditor::checkRecurrence() if ( mTodo ) mRecurrence->readEvent( mTodo ); else { bool time = mGeneral->mTimeButton->isChecked(); QDateTime from,to; if ( time ) { to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ; from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ; } else { to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ; from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ; } + if ( to < from ) + to = from; mRecurrence->setDefaults(from,to,!time); } } else { tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); } } void KOTodoEditor::readTodo(Todo *todo) { mGeneral->readTodo(todo); mDetails->readEvent(todo); mRelatedTodo = 0;//todo->relatedTo(); @@ -341,24 +343,51 @@ void KOTodoEditor::readTodo(Todo *todo) void KOTodoEditor::writeTodo(Todo *event) { mGeneral->writeTodo(event); mDetails->writeEvent(event); // set related event, i.e. parent to-do in this case. if (mRelatedTodo) { event->setRelatedTo(mRelatedTodo); } if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { mRecurrence->writeEvent(event); + event->setRecurrenceID( event->dtStart().addSecs(-1) ); + event->setRecurDates(); +#if 0 + bool ok; + QDateTime next = event->getNextOccurence( event->dtStart().addSecs(-1), &ok ); + if ( ok ) { + QDateTime from,to; + bool time = mGeneral->mTimeButton->isChecked(); + if ( time ) { + to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ; + from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ; + } else { + to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ; + from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ; + } + if ( to < from ) + to = from; + int secs = from.secsTo( to ); + event->setRecurrenceID( next ); + event->setDtStart( next ); + event->setDtDue( next.addSecs( secs ) ); + } + else { + event->setHasRecurrenceID( false ); + event->recurrence()->unsetRecurs(); + } +#endif } else event->recurrence()->unsetRecurs(); } bool KOTodoEditor::validateInput() { if (!mGeneral->validateInput()) return false; if (!mDetails->validateInput()) return false; return true; } int KOTodoEditor::msgItemDelete() diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp index 0e847c2..70f00c6 100644 --- a/korganizer/kotodoviewitem.cpp +++ b/korganizer/kotodoviewitem.cpp @@ -182,66 +182,104 @@ void KOTodoViewItem::setMyPixmap() p. drawPixmap ( 0, pixSize, pPix); p.end(); pixSize += size; } if ( mTodo->isAlarmEnabled() ) { pixi.resize(size, pixSize+size); pPix.fill( Qt::red ); p.begin( &pixi ); p. drawPixmap ( 0, pixSize, pPix); p.end(); pixSize += size; } + if ( mTodo->doesRecur() ) { + pixi.resize(size, pixSize+size); + pPix.fill( Qt::blue ); + p.begin( &pixi ); + p. drawPixmap ( 0, pixSize, pPix); + p.end(); + pixSize += size; + } // } if ( pixi.width() > 1 ) { setPixmap ( 0,pixi ) ; } else { setPixmap ( 0,QPixmap() ) ; } } void KOTodoViewItem::stateChange(bool state) { - // qDebug("KOTodoViewItem::stateChange "); + // qDebug("KOTodoViewItem::stateChange %d ", state); // do not change setting on startup if ( m_init ) return; if (isOn()!=state) { setOn(state); //qDebug("SETON "); return; } if ( mTodo->isCompleted() == state ) { //qDebug("STATECHANGE:nothing to do "); return; } QString keyd = "=="; QString keyt = "=="; //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1()); + if ( mTodo->doesRecur() ){ + QDateTime start = mTodo->dtStart(); mTodo->setCompleted(state); + if ( start != mTodo->dtStart() ) { + if ( state && !mTodo->isCompleted() ) { + setOn( false ); + state = false; + } + } + } else + mTodo->setCompleted(state); + if (state) mTodo->setCompleted(QDateTime::currentDateTime()); if (mTodo->hasDueDate()) { setText(3, mTodo->dtDueDateStr()); QDate d = mTodo->dtDue().date(); keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); setSortKey(3,keyd); if (mTodo->doesFloat()) { setText(4,""); } else { setText(4,mTodo->dtDueTimeStr()); QTime t = mTodo->dtDue().time(); keyt.sprintf("%02d%02d",t.hour(),t.minute()); setSortKey(4,keyt); } } + if (mTodo->hasStartDate()) { + QString skeyt = "=="; + QString skeyd = "=="; + setText(5, mTodo->dtStartDateStr()); + QDate d = mTodo->dtStart().date(); + skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); + + if (mTodo->doesFloat()) { + setText(6,""); + } + else { + setText(6,mTodo->dtStartTimeStr()); + QTime t = mTodo->dtStart().time(); + skeyt.sprintf("%02d%02d",t.hour(),t.minute()); + + } + setSortKey(5,skeyd); + setSortKey(6,skeyt); + } if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt); else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); if (mTodo->percentComplete()<100) { if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); else setSortKey(2,QString::number(mTodo->percentComplete())); } else { if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); else setSortKey(2,QString::number(99)); } diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index dbc159c..0684af2 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp @@ -638,12 +638,21 @@ QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const 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 @@ -260,36 +260,37 @@ class Incidence : public IncidenceBase 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; diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp index 7525a4a..51f2e9d 100644 --- a/libkcal/incidencebase.cpp +++ b/libkcal/incidencebase.cpp @@ -170,24 +170,25 @@ QString IncidenceBase::organizer() const 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 { diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h index f9a6558..8624786 100644 --- a/libkcal/incidencebase.h +++ b/libkcal/incidencebase.h @@ -65,25 +65,25 @@ class IncidenceBase : public CustomProperties /** 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; @@ -132,30 +132,30 @@ class IncidenceBase : public CustomProperties 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; diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 9c04a7e..1f54c2f 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp @@ -302,30 +302,36 @@ QString Todo::statusStr() const 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; } @@ -348,27 +354,51 @@ void Todo::setCompleted(const QDateTime &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; @@ -403,12 +433,25 @@ QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const 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 @@ -103,24 +103,26 @@ class Todo : public Incidence */ 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; |