author | zautrix <zautrix> | 2005-06-08 10:34:22 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-08 10:34:22 (UTC) |
commit | 793d117812b4da36c9c11d90cccba347cbc6e208 (patch) (side-by-side diff) | |
tree | 5bc77e2b7a32a541c2a3b3c3d6d50f873216deef /libkcal | |
parent | 39d84e2fc3099bd5d7596e8be5dc6783826cec01 (diff) | |
download | kdepimpi-793d117812b4da36c9c11d90cccba347cbc6e208.zip kdepimpi-793d117812b4da36c9c11d90cccba347cbc6e208.tar.gz kdepimpi-793d117812b4da36c9c11d90cccba347cbc6e208.tar.bz2 |
changed incidence type to a faster access method
-rw-r--r-- | libkcal/calendar.cpp | 6 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 6 | ||||
-rw-r--r-- | libkcal/calfilter.cpp | 6 | ||||
-rw-r--r-- | libkcal/event.h | 1 | ||||
-rw-r--r-- | libkcal/freebusy.h | 1 | ||||
-rw-r--r-- | libkcal/icalformat.cpp | 4 | ||||
-rw-r--r-- | libkcal/icalformatimpl.cpp | 6 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 6 | ||||
-rw-r--r-- | libkcal/incidencebase.h | 2 | ||||
-rw-r--r-- | libkcal/journal.h | 1 | ||||
-rw-r--r-- | libkcal/kincidenceformatter.cpp | 4 | ||||
-rw-r--r-- | libkcal/todo.cpp | 5 | ||||
-rw-r--r-- | libkcal/todo.h | 1 |
13 files changed, 26 insertions, 23 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index ed39ddb..7e8e2c5 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp @@ -344,29 +344,29 @@ void Calendar::addIncidenceBranch(Incidence *i) addIncidenceBranch( inc ); } } bool Calendar::addIncidence(Incidence *i) { Incidence::AddVisitor<Calendar> v(this); return i->accept(v); } void Calendar::deleteIncidence(Incidence *in) { - if ( in->type() == "Event" ) + if ( in->typeID() == eventID ) deleteEvent( (Event*) in ); - else if ( in->type() =="Todo" ) + else if ( in->typeID() == todoID ) deleteTodo( (Todo*) in); - else if ( in->type() =="Journal" ) + else if ( in->typeID() == journalID ) deleteJournal( (Journal*) in ); } Incidence* Calendar::incidence( const QString& uid ) { Incidence* i; if( (i = todo( uid )) != 0 ) return i; if( (i = event( uid )) != 0 ) return i; if( (i = journal( uid )) != 0 ) diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index bc76c0b..fe74052 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp @@ -449,27 +449,25 @@ QDateTime CalendarLocal::nextAlarm( int daysTo ) mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); mNextAlarmDateTime = nextA; } return nextA; } Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) { return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); } Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) { - kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " - << to.toString() << ")\n"; - + Alarm::List alarms; Event *e; for( e = mEventList.first(); e; e = mEventList.next() ) { if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); else appendAlarms( alarms, e, from, to ); } Todo *t; for( t = mTodoList.first(); t; t = mTodoList.next() ) { appendAlarms( alarms, t, from, to ); @@ -479,26 +477,24 @@ Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) } void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, const QDateTime &from, const QDateTime &to ) { QPtrList<Alarm> alarmList = incidence->alarms(); Alarm *alarm; for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; if ( alarm->enabled() ) { if ( alarm->time() >= from && alarm->time() <= to ) { - kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() - << "': " << alarm->time().toString() << endl; alarms.append( alarm ); } } } } void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, const QDateTime &from, const QDateTime &to ) { diff --git a/libkcal/calfilter.cpp b/libkcal/calfilter.cpp index c425dfc..20078a7 100644 --- a/libkcal/calfilter.cpp +++ b/libkcal/calfilter.cpp @@ -69,29 +69,29 @@ void CalFilter::apply(QPtrList<Todo> *eventlist) if (!filterTodo(event)) { eventlist->remove(); event = eventlist->current(); } else { event = eventlist->next(); } } // kdDebug(5800) << "CalFilter::apply() done" << endl; } bool CalFilter::filterCalendarItem(Incidence *in) { - if ( in->type() == "Event" ) + if ( in->typeID() == eventID ) return filterEvent( (Event*) in ); - else if ( in->type() =="Todo" ) + else if ( in->typeID() == todoID ) return filterTodo( (Todo*) in); - else if ( in->type() =="Journal" ) + else if ( in->typeID () == journalID ) return filterJournal( (Journal*) in ); return false; } bool CalFilter::filterEvent(Event *event) { if (mCriteria & HideEvents) return false; if (mCriteria & HideRecurring) { if (event->recurrence()->doesRecur()) return false; } return filterIncidence(event); diff --git a/libkcal/event.h b/libkcal/event.h index 8729956..287d403 100644 --- a/libkcal/event.h +++ b/libkcal/event.h @@ -31,24 +31,25 @@ 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(); 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 diff --git a/libkcal/freebusy.h b/libkcal/freebusy.h index 054feda..d741c72 100644 --- a/libkcal/freebusy.h +++ b/libkcal/freebusy.h @@ -39,24 +39,25 @@ namespace KCal { */ class FreeBusy : public IncidenceBase { public: FreeBusy(); FreeBusy(const QDateTime &start, const QDateTime &end); FreeBusy(Calendar *calendar, const QDateTime &start, const QDateTime &end); FreeBusy(QValueList<Period> busyPeriods); ~FreeBusy(); QCString type() const { return "FreeBusy"; } + IncTypeID typeID() const { return freebusyID; } virtual QDateTime dtEnd() const; bool setDtEnd( const QDateTime &end ); QValueList<Period> busyPeriods() const; void addPeriod(const QDateTime &start, const QDateTime &end); void sortList(); private: //This is used for creating a freebusy object for the current user diff --git a/libkcal/icalformat.cpp b/libkcal/icalformat.cpp index 3a2aac6..d9fe40b 100644 --- a/libkcal/icalformat.cpp +++ b/libkcal/icalformat.cpp @@ -375,30 +375,30 @@ ScheduleMessage *ICalFormat::parseScheduleMessage( Calendar *cal, if (!icalrestriction_check(message)) { setException(new ErrorFormat(ErrorFormat::Restriction, Scheduler::translatedMethodName(method) + ": " + mImpl->extractErrorProperty(c))); return 0; } icalcomponent *calendarComponent = mImpl->createCalendarComponent(cal); Incidence *existingIncidence = cal->event(incidence->uid()); if (existingIncidence) { // TODO: check, if cast is required, or if it can be done by virtual funcs. - if (existingIncidence->type() == "Todo") { + if (existingIncidence->typeID() == todoID ) { Todo *todo = static_cast<Todo *>(existingIncidence); icalcomponent_add_component(calendarComponent, mImpl->writeTodo(todo)); } - if (existingIncidence->type() == "Event") { + if (existingIncidence->typeID() == eventID ) { Event *event = static_cast<Event *>(existingIncidence); icalcomponent_add_component(calendarComponent, mImpl->writeEvent(event)); } } else { calendarComponent = 0; } qDebug("icalclassify commented out "); ScheduleMessage::Status status; #if 0 icalclass result = icalclassify(message,calendarComponent,(char *)""); diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp index 2405682..3e28714 100644 --- a/libkcal/icalformatimpl.cpp +++ b/libkcal/icalformatimpl.cpp @@ -2146,27 +2146,27 @@ icalcomponent *ICalFormatImpl::createScheduleComponent(IncidenceBase *incidence, break; case Scheduler::Declinecounter: icalmethod = ICAL_METHOD_DECLINECOUNTER; break; default: return message; } icalcomponent_add_property(message,icalproperty_new_method(icalmethod)); // TODO: check, if dynamic cast is required - if(incidence->type() == "Todo") { + if(incidence->typeID() == todoID ) { Todo *todo = static_cast<Todo *>(incidence); icalcomponent_add_component(message,writeTodo(todo)); } - if(incidence->type() == "Event") { + if(incidence->typeID() == eventID ) { Event *event = static_cast<Event *>(incidence); icalcomponent_add_component(message,writeEvent(event)); } - if(incidence->type() == "FreeBusy") { + if(incidence->typeID() == freebusyID) { FreeBusy *freebusy = static_cast<FreeBusy *>(incidence); icalcomponent_add_component(message,writeFreeBusy(freebusy, method)); } return message; } diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 762103f..f446197 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp @@ -227,25 +227,25 @@ bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 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 ( type() == "Event") { + 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 () ); @@ -715,30 +715,30 @@ QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const return QDateTime (); } incidenceStart = incidenceStart.addSecs( 1 ); } } } else { return QDateTime (); } } else { if ( hasStartDate () ) { incidenceStart = dtStart(); } - if ( type() =="Todo" ) { + if ( typeID() == todoID ) { if ( ((Todo*)this)->hasDueDate() ) incidenceStart = ((Todo*)this)->dtDue(); } } if ( incidenceStart > dt ) *ok = true; return incidenceStart; } QDateTime Incidence::dtStart() const { if ( doesRecur() ) { - if ( type() == "Todo" ) { + if ( typeID() == todoID ) { ((Todo*)this)->checkSetCompletedFalse(); } } return mDtStart; } diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h index 8624786..05209e0 100644 --- a/libkcal/incidencebase.h +++ b/libkcal/incidencebase.h @@ -25,41 +25,43 @@ #include <qdatetime.h> #include <qstringlist.h> #include <qvaluelist.h> #include <qptrlist.h> #include "customproperties.h" #include "attendee.h" namespace KCal { typedef QValueList<QDate> DateList; + enum IncTypeID { eventID,todoID,journalID,freebusyID }; /** This class provides the base class common to all calendar components. */ class IncidenceBase : public CustomProperties { public: class Observer { public: virtual void incidenceUpdated( IncidenceBase * ) = 0; }; IncidenceBase(); IncidenceBase(const IncidenceBase &); virtual ~IncidenceBase(); virtual QCString type() const = 0; + virtual IncTypeID typeID() 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 */ diff --git a/libkcal/journal.h b/libkcal/journal.h index 2c1d7ea..1cd0a22 100644 --- a/libkcal/journal.h +++ b/libkcal/journal.h @@ -28,23 +28,24 @@ namespace KCal { /** This class provides a Journal in the sense of RFC2445. */ class Journal : public Incidence { public: Journal(); ~Journal(); QCString type() const { return "Journal"; } + IncTypeID typeID() const { return journalID; } Incidence *clone(); QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; private: bool accept(Visitor &v) { return v.visit(this); } }; bool operator==( const Journal&, const Journal& ); } #endif diff --git a/libkcal/kincidenceformatter.cpp b/libkcal/kincidenceformatter.cpp index 7d61b7f..d1ace4f 100644 --- a/libkcal/kincidenceformatter.cpp +++ b/libkcal/kincidenceformatter.cpp @@ -12,27 +12,27 @@ static KStaticDeleter<KIncidenceFormatter> insd; QString KIncidenceFormatter::getFormattedText( Incidence * inc, bool details, bool created , bool modified ) { // #ifndef QT_NO_INPUTDIALOG // return QInputDialog::getItem( caption, label, items, current, editable ); // #else // return QString::null; // #endif mDetails = details; mCreated = created ; mModified = modified; mText = ""; - if ( inc->type() == "Event" ) + if ( inc->typeID() == eventID ) setEvent((Event *) inc ); - else if ( inc->type() == "Todo" ) + else if ( inc->typeID() == todoID ) setTodo((Todo *) inc ); return mText; } KIncidenceFormatter* KIncidenceFormatter::instance() { if (!mInstance) { mInstance = insd.setObject(new KIncidenceFormatter()); } return mInstance; } KIncidenceFormatter::~KIncidenceFormatter() diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 38ba2c7..c97a61e 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp @@ -121,25 +121,25 @@ void Todo::saveRunningInfoToFile( QString comment ) cal.addIncidence( to ); ICalFormat format; file = dir +"/" +file +".ics"; format.save( &cal, file ); saveParents(); } void Todo::saveParents() { if (!relatedTo() ) return; Incidence * inc = relatedTo(); - if ( inc->type() != "Todo" ) + if ( inc->typeID() != todoID ) return; Todo* to = (Todo*)inc; bool saveTodo = false; QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; QFileInfo fi ( file ); if ( fi.exists() ) { if ( fi.lastModified () < to->lastModified ()) saveTodo = true; } else { saveTodo = true; } if ( saveTodo ) { @@ -555,26 +555,27 @@ QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_d *ok = true; * offset = off; return alarmStart; } } *ok = false; return QDateTime (); } void Todo::checkSetCompletedFalse() { - if ( !hasRecurrenceID() ) { + 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 "); } } } diff --git a/libkcal/todo.h b/libkcal/todo.h index ab8fdf1..501c2ba 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h @@ -32,24 +32,25 @@ 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; |