-rw-r--r-- | libkcal/alarm.cpp | 2 | ||||
-rw-r--r-- | libkcal/event.cpp | 8 | ||||
-rw-r--r-- | libkcal/event.h | 1 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 29 | ||||
-rw-r--r-- | libkcal/incidence.h | 3 | ||||
-rw-r--r-- | libkcal/todo.cpp | 10 | ||||
-rw-r--r-- | libkcal/todo.h | 1 |
7 files changed, 52 insertions, 2 deletions
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp index 79e0464..3157214 100644 --- a/libkcal/alarm.cpp +++ b/libkcal/alarm.cpp @@ -161,323 +161,323 @@ void Alarm::setAudioAlarm(const QString &audioFile) { mType = Audio; mFile = audioFile; mParent->updated(); } void Alarm::setAudioFile(const QString &audioFile) { if (mType == Audio) { mFile = audioFile; mParent->updated(); } } QString Alarm::audioFile() const { return (mType == Audio) ? mFile : QString::null; } void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) { mType = Procedure; mFile = programFile; mDescription = arguments; mParent->updated(); } void Alarm::setProgramFile(const QString &programFile) { if (mType == Procedure) { mFile = programFile; mParent->updated(); } } QString Alarm::programFile() const { return (mType == Procedure) ? mFile : QString::null; } void Alarm::setProgramArguments(const QString &arguments) { if (mType == Procedure) { mDescription = arguments; mParent->updated(); } } QString Alarm::programArguments() const { return (mType == Procedure) ? mDescription : QString::null; } void Alarm::setEmailAlarm(const QString &subject, const QString &text, const QValueList<Person> &addressees, const QStringList &attachments) { mType = Email; mMailSubject = subject; mDescription = text; mMailAddresses = addressees; mMailAttachFiles = attachments; mParent->updated(); } void Alarm::setMailAddress(const Person &mailAddress) { if (mType == Email) { mMailAddresses.clear(); mMailAddresses += mailAddress; mParent->updated(); } } void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) { if (mType == Email) { mMailAddresses = mailAddresses; mParent->updated(); } } void Alarm::addMailAddress(const Person &mailAddress) { if (mType == Email) { mMailAddresses += mailAddress; mParent->updated(); } } QValueList<Person> Alarm::mailAddresses() const { return (mType == Email) ? mMailAddresses : QValueList<Person>(); } void Alarm::setMailSubject(const QString &mailAlarmSubject) { if (mType == Email) { mMailSubject = mailAlarmSubject; mParent->updated(); } } QString Alarm::mailSubject() const { return (mType == Email) ? mMailSubject : QString::null; } void Alarm::setMailAttachment(const QString &mailAttachFile) { if (mType == Email) { mMailAttachFiles.clear(); mMailAttachFiles += mailAttachFile; mParent->updated(); } } void Alarm::setMailAttachments(const QStringList &mailAttachFiles) { if (mType == Email) { mMailAttachFiles = mailAttachFiles; mParent->updated(); } } void Alarm::addMailAttachment(const QString &mailAttachFile) { if (mType == Email) { mMailAttachFiles += mailAttachFile; mParent->updated(); } } QStringList Alarm::mailAttachments() const { return (mType == Email) ? mMailAttachFiles : QStringList(); } void Alarm::setMailText(const QString &text) { if (mType == Email) { mDescription = text; mParent->updated(); } } QString Alarm::mailText() const { return (mType == Email) ? mDescription : QString::null; } void Alarm::setDisplayAlarm(const QString &text) { mType = Display; mDescription = text; mParent->updated(); } void Alarm::setText(const QString &text) { if (mType == Display) { mDescription = text; mParent->updated(); } } QString Alarm::text() const { return (mType == Display) ? mDescription : QString::null; } void Alarm::setTime(const QDateTime &alarmTime) { mAlarmTime = alarmTime; mHasTime = true; mParent->updated(); } int Alarm::offset() { if ( hasTime() ) { if (mParent->typeID() == todoID ) { Todo *t = static_cast<Todo*>(mParent); return t->dtDue().secsTo( mAlarmTime ) ; } else return mParent->dtStart().secsTo( mAlarmTime ) ; } else { return mOffset.asSeconds(); } } -QString Alarm::offsetText() +QString Alarm::offsetText() { int min = -offset()/60; int hours = min /60; min = min % 60; int days = hours /24; hours = hours % 24; QString message; //qDebug("%d %d %d ", days, hours, min ); if ( days > 0 ) message += i18n("%1d").arg( days ); if ( hours > 0 ) { if ( !message.isEmpty() ) message += "/"; message += i18n("%1h").arg( hours ); } if ( min > 0 ) { if ( !message.isEmpty() ) message += "/"; message += i18n("%1min").arg( min ); } if ( message.isEmpty() ) message = i18n("%1min").arg( 0 ); if ( !mParent->alarmEnabled() ) return "!"+message + i18n("(disabled)"); return message; } QDateTime Alarm::time() const { if ( hasTime() ) return mAlarmTime; else { if (mParent->typeID() == todoID ) { Todo *t = static_cast<Todo*>(mParent); return mOffset.end( t->dtDue() ); } else if (mEndOffset) { return mOffset.end( mParent->dtEnd() ); } else { return mOffset.end( mParent->dtStart() ); } } } bool Alarm::hasTime() const { return mHasTime; } void Alarm::setSnoozeTime(int alarmSnoozeTime) { mAlarmSnoozeTime = alarmSnoozeTime; mParent->updated(); } int Alarm::snoozeTime() const { return mAlarmSnoozeTime; } void Alarm::setRepeatCount(int alarmRepeatCount) { kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; mAlarmRepeatCount = alarmRepeatCount; mParent->updated(); } int Alarm::repeatCount() const { kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; return mAlarmRepeatCount; } void Alarm::toggleAlarm() { mAlarmEnabled = !mAlarmEnabled; mParent->updated(); } void Alarm::setEnabled(bool enable) { mAlarmEnabled = enable; mParent->updated(); } bool Alarm::enabled() const { return mAlarmEnabled; } void Alarm::setStartOffset( const Duration &offset ) { mOffset = offset; mEndOffset = false; mHasTime = false; mParent->updated(); } Duration Alarm::startOffset() const { return (mHasTime || mEndOffset) ? 0 : mOffset; } bool Alarm::hasStartOffset() const { return !mHasTime && !mEndOffset; } bool Alarm::hasEndOffset() const { return !mHasTime && mEndOffset; } void Alarm::setEndOffset( const Duration &offset ) { mOffset = offset; mEndOffset = true; mHasTime = false; mParent->updated(); } Duration Alarm::endOffset() const { return (mHasTime || !mEndOffset) ? 0 : mOffset; } void Alarm::setParent( Incidence *parent ) { mParent = parent; } diff --git a/libkcal/event.cpp b/libkcal/event.cpp index 0766fd9..fdf5657 100644 --- a/libkcal/event.cpp +++ b/libkcal/event.cpp @@ -225,192 +225,200 @@ bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* return false; } } Event *nonRecur = 0; Event *recurEvent = 0; if ( ! doesRecur() ) { nonRecur = this; recurEvent = testEvent; } else if ( !testEvent->doesRecur() ) { nonRecur = testEvent; recurEvent = this; } if ( nonRecur ) { QDateTime enr; if ( nonRecur->doesFloat() ) enr = nonRecur->mDtEnd.addDays( 1 ); else enr = nonRecur->mDtEnd; if ( enr < recurEvent->mDtStart ) return false; if ( startDT && enr < *startDT ) return false; int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd ); if ( recurEvent->doesFloat() ) recDuration += 86400; bool ok = false; QDateTime recStart; if ( startDT ) { recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); } if ( recStart.isValid() ) { //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1()); recStart = recStart.addSecs( -300); } else recStart = recurEvent->mDtStart.addSecs( -300); ok = true; while ( ok ) { recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok ); if ( ok ) { if ( recStart > enr ) return false; QDateTime recEnd = recStart.addSecs( recDuration ); if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) { if ( nonRecur->mDtStart < recStart ) *overlapDT = recStart; else *overlapDT = nonRecur->mDtStart; if ( startDT ) { if ( *overlapDT >= *startDT ) return true; } else return true; } } } return false; } if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) { bool found = false; uint i; for ( i=0; i< recurrence()->days().size();++i ) { found = found || (recurrence()->days().testBit( i ) && testEvent->recurrence()->days().testBit( i ) ); } if ( ! found ) { //qDebug("recurring days mismatch %s -- %s", summary().latin1(),testEvent->summary().latin1()); return false; } } } bool ok = true; QDateTime incidenceStart;// = mDtStart; QDateTime testincidenceStart;// = testEvent->mDtStart; if ( startDT ) { incidenceStart = recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); testincidenceStart = testEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); } if ( !testincidenceStart.isValid() ) testincidenceStart = testEvent->mDtStart; if ( !incidenceStart.isValid() ) incidenceStart = mDtStart; int duration = mDtStart.secsTo( mDtEnd ); if ( doesFloat() ) duration += 86400; int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd ); if ( testEvent->doesFloat() ) testduration += 86400; bool computeThis = false; if ( incidenceStart < testincidenceStart ) computeThis = true; if ( computeThis ) incidenceStart = incidenceStart.addSecs( -300 ); else testincidenceStart = testincidenceStart.addSecs( -300 ); int count = 0; ok = true; int countbreak = 2000; QDateTime stopSearch; bool testStop = false; if ( startDT ) { stopSearch = startDT->addDays( 365*3 ); testStop = true; } while ( ok ) { ++count; if ( count > countbreak ) break; if ( computeThis ) { if ( testStop ) if ( testincidenceStart > stopSearch ) break; incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok ); } else { if ( testStop ) if ( incidenceStart > stopSearch ) break; testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok ); } if ( ok ) { if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) { if ( incidenceStart < testincidenceStart ) *overlapDT = testincidenceStart; else *overlapDT = incidenceStart; if ( startDT ) { if ( *overlapDT >= *startDT ) return true; } else return true; } computeThis = ( incidenceStart < testincidenceStart ); } } //qDebug("%d rec counter stopped at %d - %s %s", ok ,count, summary().latin1(),testEvent->summary().latin1() ); return false; } QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const { *ok = false; if ( !alarmEnabled() ) return QDateTime (); bool yes; QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); if ( ! yes || cancelled() ) { *ok = false; return QDateTime (); } 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 () ) { if ( alarm->time() < alarmStart ) { alarmStart = alarm->time(); enabled = true; off = alarmStart.secsTo( incidenceStart ); } } else { int secs = alarm->startOffset().asSeconds(); if ( incidenceStart.addSecs( secs ) < alarmStart ) { alarmStart = incidenceStart.addSecs( secs ); enabled = true; off = -secs; } } } } if ( enabled ) { if ( alarmStart > start_dt ) { *ok = true; * offset = off; return alarmStart; } } *ok = false; return QDateTime (); } + +QString Event::durationText() +{ + int sec = mDtStart.secsTo( mDtEnd ); + if ( doesFloat() ) + sec += 86400; + return durationText4Time( sec ); +} diff --git a/libkcal/event.h b/libkcal/event.h index 2da9770..6a58618 100644 --- a/libkcal/event.h +++ b/libkcal/event.h @@ -1,94 +1,95 @@ /* This file is part of libkcal. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef EVENT_H #define EVENT_H // // Event component, representing a VEVENT object // #include "incidence.h" namespace KCal { /** This class provides an Event in the sense of RFC2445. */ class Event : public Incidence { public: enum Transparency { Opaque, Transparent }; typedef ListBase<Event> List; Event(); Event(const Event &); ~Event(); bool matchTime(QDateTime*startDT, QDateTime* endDT); QCString type() const { return "Event"; } IncTypeID typeID() const { return eventID; } Incidence *clone(); QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; /** for setting an event's ending date/time with a QDateTime. */ void setDtEnd(const QDateTime &dtEnd); /** Return the event's ending date/time as a QDateTime. */ virtual QDateTime dtEnd() const; /** returns an event's end time as a string formatted according to the users locale settings */ QString dtEndTimeStr() const; /** returns an event's end date as a string formatted according to the users locale settings */ QString dtEndDateStr(bool shortfmt=true) const; /** returns an event's end date and time as a string formatted according to the users locale settings */ QString dtEndStr(bool shortfmt=true) const; void setHasEndDate(bool); /** Return whether the event has an end date/time. */ bool hasEndDate() const; /** Return true if the event spans multiple days, otherwise return false. */ bool isMultiDay() const; /** set the event's time transparency level. */ void setTransparency(Transparency transparency); /** get the event's time transparency level. */ Transparency transparency() const; void setDuration(int seconds); bool contains ( Event*); bool isOverlapping ( Event*, QDateTime*, QDateTime* ); + QString durationText(); private: bool accept(Visitor &v) { return v.visit(this); } QDateTime mDtEnd; bool mHasEndDate; Transparency mTransparency; }; bool operator==( const Event&, const Event& ); } #endif diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 4643a3a..201f593 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp @@ -1,295 +1,324 @@ /* This file is part of libkcal. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <kglobal.h> #include <klocale.h> #include <kdebug.h> #include "calformat.h" #include "incidence.h" #include "todo.h" using namespace KCal; Incidence::Incidence() : IncidenceBase(), mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) { mRecurrence = 0;//new Recurrence(this); mCancelled = false; recreate(); mHasStartDate = true; mAlarms.setAutoDelete(true); mAttachments.setAutoDelete(true); mHasRecurrenceID = false; mHoliday = false; mBirthday = false; mAnniversary = false; } Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) { // TODO: reenable attributes currently commented out. mRevision = i.mRevision; mCreated = i.mCreated; mDescription = i.mDescription; mSummary = i.mSummary; mCategories = i.mCategories; // Incidence *mRelatedTo; Incidence *mRelatedTo; mRelatedTo = 0; mRelatedToUid = i.mRelatedToUid; // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; mExDates = i.mExDates; mAttachments = i.mAttachments; mResources = i.mResources; mSecrecy = i.mSecrecy; mPriority = i.mPriority; mLocation = i.mLocation; mCancelled = i.mCancelled; mHasStartDate = i.mHasStartDate; QPtrListIterator<Alarm> it( i.mAlarms ); const Alarm *a; while( (a = it.current()) ) { Alarm *b = new Alarm( *a ); b->setParent( this ); mAlarms.append( b ); ++it; } mAlarms.setAutoDelete(true); mHasRecurrenceID = i.mHasRecurrenceID; mRecurrenceID = i.mRecurrenceID; if ( i.mRecurrence ) mRecurrence = new Recurrence( *(i.mRecurrence), this ); else mRecurrence = 0; mHoliday = i.mHoliday ; mBirthday = i.mBirthday; mAnniversary = i.mAnniversary; } Incidence::~Incidence() { Incidence *ev; QPtrList<Incidence> Relations = relations(); for (ev=Relations.first();ev;ev=Relations.next()) { if (ev->relatedTo() == this) ev->setRelatedTo(0); } if (relatedTo()) relatedTo()->removeRelation(this); if ( mRecurrence ) delete mRecurrence; } +QString Incidence::durationText() +{ + return "---"; +} +QString Incidence::durationText4Time( int offset ) +{ + int min = offset/60; + int hours = min /60; + min = min % 60; + int days = hours /24; + hours = hours % 24; + + if ( doesFloat() || ( min == 0 && hours == 0 ) ) { + if ( days == 1 ) + return "1" + i18n(" day"); + else + return QString::number( days )+ i18n(" days"); + } + QString message = QString::number ( hours ) +":"; + if ( min < 10 ) message += "0"; + message += QString::number ( min ); + if ( days > 0 ) { + if ( days == 1 ) + message = "1" + i18n(" day") + " "+message; + else + message = QString::number( days )+ i18n(" days") + " "+message; + } + return message; +} bool Incidence::isHoliday() const { return mHoliday; } bool Incidence::isBirthday() const { return mBirthday ; } bool Incidence::isAnniversary() const { return mAnniversary ; } bool Incidence::hasRecurrenceID() const { return mHasRecurrenceID; } void Incidence::setHasRecurrenceID( bool b ) { mHasRecurrenceID = b; } void Incidence::setRecurrenceID(QDateTime d) { mRecurrenceID = d; mHasRecurrenceID = true; updated(); } QDateTime Incidence::recurrenceID () const { return mRecurrenceID; } bool Incidence::cancelled() const { return mCancelled; } void Incidence::setCancelled( bool b ) { mCancelled = b; updated(); } bool Incidence::hasStartDate() const { return mHasStartDate; } void Incidence::setHasStartDate(bool f) { if (mReadOnly) return; mHasStartDate = f; updated(); } // A string comparison that considers that null and empty are the same static bool stringCompare( const QString& s1, const QString& s2 ) { if ( s1.isEmpty() && s2.isEmpty() ) return true; return s1 == s2; } bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) { if( i1.alarms().count() != i2.alarms().count() ) { return false; // no need to check further } if ( i1.alarms().count() > 0 ) { if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) { qDebug("alarm not equal "); return false; } } #if 0 QPtrListIterator<Alarm> a1( i1.alarms() ); QPtrListIterator<Alarm> a2( i2.alarms() ); for( ; a1.current() && a2.current(); ++a1, ++a2 ) { if( *a1.current() == *a2.current() ) { continue; } else { return false; } } #endif if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { if ( i1.hasRecurrenceID() ) { if ( i1.recurrenceID() != i2.recurrenceID() ) return false; } } else { return false; } if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) return false; if ( i1.hasStartDate() == i2.hasStartDate() ) { if ( i1.hasStartDate() ) { if ( i1.dtStart() != i2.dtStart() ) return false; } } else { return false; } if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { if (!( *i1.mRecurrence == *i2.mRecurrence) ) { //qDebug("recurrence is NOT equal "); return false; } } else { // one ( or both ) recurrence is 0 if ( i1.mRecurrence == 0 ) { if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) return false; } else { // i1.mRecurrence != 0 // i2.mRecurrence == 0 if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) return false; } } return // i1.created() == i2.created() && stringCompare( i1.description(), i2.description() ) && stringCompare( i1.summary(), i2.summary() ) && i1.categories() == i2.categories() && // no need to compare mRelatedTo stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && // i1.relations() == i2.relations() && i1.exDates() == i2.exDates() && i1.attachments() == i2.attachments() && i1.resources() == i2.resources() && i1.secrecy() == i2.secrecy() && i1.priority() == i2.priority() && i1.cancelled() == i2.cancelled() && stringCompare( i1.location(), i2.location() ); } Incidence* Incidence::recreateCloneException( QDate d ) { Incidence* newInc = clone(); newInc->recreate(); if ( doesRecur() ) { addExDate( d ); newInc->recurrence()->unsetRecurs(); if ( typeID() == eventID ) { int len = dtStart().secsTo( ((Event*)this)->dtEnd()); QTime tim = dtStart().time(); newInc->setDtStart( QDateTime(d, tim) ); ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); } else { int len = dtStart().secsTo( ((Todo*)this)->dtDue()); QTime tim = ((Todo*)this)->dtDue().time(); ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); ((Todo*)this)->setRecurDates(); } newInc->setExDates( DateList () ); } return newInc; } void Incidence::recreate() { setCreated(QDateTime::currentDateTime()); setUid(CalFormat::createUniqueId()); setRevision(0); setIDStr( ":" ); setLastModified(QDateTime::currentDateTime()); } void Incidence::cloneRelations( Incidence * newInc ) { // newInc is already a clone of this incidence Incidence * inc; Incidence * cloneInc; QPtrList<Incidence> Relations = relations(); for (inc=Relations.first();inc;inc=Relations.next()) { cloneInc = inc->clone(); cloneInc->recreate(); cloneInc->setRelatedTo( newInc ); inc->cloneRelations( cloneInc ); } diff --git a/libkcal/incidence.h b/libkcal/incidence.h index 8519f01..88df217 100644 --- a/libkcal/incidence.h +++ b/libkcal/incidence.h @@ -92,231 +92,232 @@ class Incidence : public IncidenceBase bool visit( Journal *j ) { return mResource->addJournal( j ); } private: T *mResource; }; /** enumeration for describing an event's secrecy. */ enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; typedef ListBase<Incidence> List; Incidence(); Incidence(const Incidence &); ~Incidence(); /** Accept IncidenceVisitor. A class taking part in the visitor mechanism has to provide this implementation: <pre> bool accept(Visitor &v) { return v.visit(this); } </pre> */ virtual bool accept(Visitor &) { return false; } virtual Incidence *clone() = 0; virtual void cloneRelations( Incidence * ); void addRelationsToList(QPtrList<Incidence> *rel); virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; void setReadOnly( bool ); /** Recreate event. The event is made a new unique event, but already stored event information is preserved. Sets uniquie id, creation date, last modification date and revision number. */ void recreate(); Incidence* recreateCloneException(QDate); /** set creation date */ void setCreated(QDateTime); /** return time and date of creation. */ QDateTime created() const; /** set the number of revisions this event has seen */ void setRevision(int rev); /** return the number of revisions this event has seen */ int revision() const; /** Set starting date/time. */ virtual void setDtStart(const QDateTime &dtStart); /** Return the incidence's ending date/time as a QDateTime. */ virtual QDateTime dtEnd() const { return QDateTime(); } /** sets the event's lengthy description. */ void setDescription(const QString &description); /** returns a reference to the event's description. */ QString description() const; /** sets the event's short summary. */ void setSummary(const QString &summary); /** returns a reference to the event's summary. */ QString summary() const; /** set event's applicable categories */ void setCategories(const QStringList &categories, bool setForRelations = false); void addCategories(const QStringList &categories, bool addToRelations = false); /** set event's categories based on a comma delimited string */ void setCategories(const QString &catStr); /** return categories in a list */ QStringList categories() const; QStringList* categoriesP(); /** return categories as a comma separated string */ QString categoriesStr(); QString categoriesStrWithSpace(); /** point at some other event to which the event relates. This function should * only be used when constructing a calendar before the related Event * exists. */ void setRelatedToUid(const QString &); /** what event does this one relate to? This function should * only be used when constructing a calendar before the related Event * exists. */ QString relatedToUid() const; /** point at some other event to which the event relates */ void setRelatedTo(Incidence *relatedTo); /** what event does this one relate to? */ Incidence *relatedTo() const; /** All events that are related to this event */ QPtrList<Incidence> relations() const; /** Add an event which is related to this event */ void addRelation(Incidence *); /** Remove event that is related to this event */ void removeRelation(Incidence *); /** returns the list of dates which are exceptions to the recurrence rule */ DateList exDates() const; /** sets the list of dates which are exceptions to the recurrence rule */ void setExDates(const DateList &_exDates); void setExDates(const char *dates); /** Add a date to the list of exceptions of the recurrence rule. */ void addExDate(const QDate &date); /** returns true if there is an exception for this date in the recurrence rule set, or false otherwise. */ bool isException(const QDate &qd) const; /** add attachment to this event */ void addAttachment(Attachment *attachment); /** remove and delete a specific attachment */ void deleteAttachment(Attachment *attachment); /** remove and delete all attachments with this mime type */ void deleteAttachments(const QString& mime); /** return list of all associated attachments */ QPtrList<Attachment> attachments() const; /** find a list of attachments with this mime type */ QPtrList<Attachment> attachments(const QString& mime) const; /** sets the event's status the value specified. See the enumeration * above for possible values. */ void setSecrecy(int); /** return the event's secrecy. */ int secrecy() const; /** return the event's secrecy in string format. */ QString secrecyStr() const; /** return list of all availbale secrecy classes */ static QStringList secrecyList(); /** return human-readable name of secrecy class */ static QString secrecyName(int); /** returns TRUE if the date specified is one on which the event will * recur. */ bool recursOn(const QDate &qd) const; // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): /** set resources used, such as Office, Car, etc. */ void setResources(const QStringList &resources); /** return list of current resources */ QStringList resources() const; /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ void setPriority(int priority); /** get the event's priority */ int priority() const; /** All alarms that are associated with this incidence */ QPtrList<Alarm> alarms() const; /** Create a new alarm which is associated with this incidence */ Alarm* newAlarm(); /** Add an alarm which is associated with this incidence */ void addAlarm(Alarm*); /** Remove an alarm that is associated with this incidence */ void removeAlarm(Alarm*); /** Remove all alarms that are associated with this incidence */ void clearAlarms(); /** return whether any alarm associated with this incidence is enabled */ bool isAlarmEnabled() const; /** Return the recurrence rule associated with this incidence. If there is none, returns an appropriate (non-0) object. */ Recurrence *recurrence(); 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; bool isHoliday() const; bool isBirthday() const; bool isAnniversary() const; QDateTime lastModifiedSub(); QString recurrenceText() const; void setLastModifiedSubInvalid(); - + virtual QString durationText(); + QString durationText4Time( int secs ); Recurrence *mRecurrence; protected: QPtrList<Alarm> mAlarms; QPtrList<Incidence> mRelations; QDateTime mRecurrenceID; bool mHasRecurrenceID; private: void checkCategories(); bool mHoliday, mBirthday, mAnniversary; int mRevision; bool mCancelled; // base components of jounal, event and todo QDateTime mCreated; QDateTime mLastModifiedSub; 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; QString mLocation; }; bool operator==( const Incidence&, const Incidence& ); } #endif diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 7bf756a..e4508a0 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp @@ -425,192 +425,202 @@ QString Todo::statusStr() const return QString("NEEDS ACTION"); break; case ACCEPTED: return QString("ACCEPTED"); break; case SENT: 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; } 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("T: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, QDateTime start_dt ) const { *ok = false; if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) { return QDateTime (); } // if the recurring todo is set to complete and requested time < start time of todo // we want to get the alarm. bool iscompleted = isCompleted(); if ( iscompleted && doesRecur() ) { Todo * to = (Todo*) this; to->checkSetCompletedFalse(); iscompleted = isCompleted(); if ( hasStartDate() && start_dt < dtStart() ){ iscompleted = false; } } if ( iscompleted ) { 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 () ) { if ( alarm->time() < alarmStart ) { alarmStart = alarm->time(); enabled = true; off = alarmStart.secsTo( incidenceStart ); } } else { int secs = alarm->startOffset().asSeconds(); if ( incidenceStart.addSecs( secs ) < alarmStart ) { alarmStart = incidenceStart.addSecs( secs ); enabled = true; off = -secs; } } } } if ( enabled ) { if ( alarmStart > start_dt ) { *ok = true; * offset = off; return alarmStart; } } *ok = false; return QDateTime (); } void Todo::checkSetCompletedFalse() { if ( !mHasRecurrenceID ) { qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); return; } // qDebug("Todo::checkSetCompletedFalse()"); //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); if ( mPercentComplete == 100 ) { QDateTime dt = QDateTime::currentDateTime(); if ( dt > mDtStart && dt > mRecurrenceID ) { qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); setCompleted( false ); qDebug("Todo::checkSetCompletedFalse "); } } } +QString Todo::durationText() +{ + if ( mHasDueDate && hasStartDate() ) { + int sec = dtStart().secsTo( dtDue() ); + if ( doesFloat() ) + sec += 86400; + return durationText4Time( sec ); + } + return "---"; +} diff --git a/libkcal/todo.h b/libkcal/todo.h index 425dfad..7feb32e 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h @@ -1,155 +1,156 @@ /* This file is part of libkcal. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef TODO_H #define TODO_H // // Todo component, representing a VTODO object // #include "incidence.h" #include <qtimer.h> namespace KCal { /** This class provides a Todo in the sense of RFC2445. */ class Todo : public QObject,public Incidence { Q_OBJECT public: Todo(); Todo(const Todo &); ~Todo(); typedef ListBase<Todo> List; QCString type() const { return "Todo"; } IncTypeID typeID() const { return todoID; } /** Return an exact copy of this todo. */ Incidence *clone(); QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const; /** for setting the todo's due date/time with a QDateTime. */ void setDtDue(const QDateTime &dtDue); /** returns an event's Due date/time as a QDateTime. */ QDateTime dtDue() const; /** returns an event's due time as a string formatted according to the users locale settings */ QString dtDueTimeStr() const; /** returns an event's due date as a string formatted according to the users locale settings */ QString dtDueDateStr(bool shortfmt=true) const; /** returns an event's due date and time as a string formatted according to the users locale settings */ QString dtDueStr(bool shortfmt=true) const; /** returns TRUE or FALSE depending on whether the todo has a due date */ bool hasDueDate() const; /** sets the event's hasDueDate value. */ void setHasDueDate(bool f); /* Looks for a subtodo (including itself ) which is not complete and is - overdue, or - due today. It returns 0 for nothing found, 1 for found a todo which is due today and no overdue found 2 for found a overdue todo */ int hasDueSubTodo( bool checkSubtodos = true ); /* same as above, but a specific date can be specified*/ int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); /** sets the event's status to the string specified. The string * must be a recognized value for the status field, i.e. a string * equivalent of the possible status enumerations previously described. */ // void setStatus(const QString &statStr); /** sets the event's status to the value specified. See the enumeration * above for possible values. */ // void setStatus(int); /** return the event's status. */ // int status() const; /** return the event's status in string format. */ // QString statusStr() const; /** return, if this todo is completed */ 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(); bool isRunning() {return mRunning;} bool hasRunningSub(); void setRunning( bool ); void setRunningFalse( QString ); void stopRunning(); int runTime(); QDateTime runStart () const { return mRunStart;} void saveRunningInfo( QString comment, QDateTime start, QDateTime end ); public slots: void saveRunningInfoToFile( QString st ); void saveRunningInfoToFile( ); void saveParents(); + QString durationText(); private: bool mRunning; QTimer * mRunSaveTimer; QDateTime mRunStart; QDateTime mRunEnd; 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 |