incidence.h
00001 /* 00002 This file is part of libkcal. 00003 00004 Copyright (c) 2001-2003 Cornelius Schumacher <schumacher@kde.org> 00005 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 #ifndef INCIDENCE_H 00023 #define INCIDENCE_H 00024 00025 #include <tqdatetime.h> 00026 #include <tqstringlist.h> 00027 #include <tqvaluelist.h> 00028 00029 #include "recurrence.h" 00030 #include "alarm.h" 00031 #include "attachment.h" 00032 #include "libkcal_export.h" 00033 00034 #include "incidencebase.h" 00035 #include <tdepimmacros.h> 00036 00037 namespace KCal { 00038 00039 class Calendar; 00040 00041 typedef TQStringList IncidenceList; 00042 typedef TQStringList::iterator IncidenceListIterator; 00043 00047 class LIBKCAL_EXPORT Incidence : public IncidenceBase, public Recurrence::Observer 00048 { 00049 public: 00054 template<class T> 00055 class AddVisitor : public IncidenceBase::Visitor 00056 { 00057 public: 00058 AddVisitor( T *r ) : mResource( r ) {} 00059 00060 bool visit( Event *e ) { return mResource->addEvent( e ); } 00061 bool visit( Todo *t ) { return mResource->addTodo( t ); } 00062 bool visit( Journal *j ) { return mResource->addJournal( j ); } 00063 00064 private: 00065 T *mResource; 00066 }; 00067 00072 template<class T> 00073 class AddSubResourceVisitor : public IncidenceBase::Visitor 00074 { 00075 public: 00076 AddSubResourceVisitor( T *r, const TQString &subResource ) 00077 : mResource( r ), mSubResource( subResource ) {} 00078 00079 protected: 00080 bool visit( Event *e ) 00081 { 00082 return mResource->addEvent( e, mSubResource ); 00083 } 00084 bool visit( Todo *t ) 00085 { 00086 return mResource->addTodo( t, mSubResource ); 00087 } 00088 bool visit( Journal *j ) 00089 { 00090 return mResource->addJournal( j, mSubResource ); 00091 } 00092 00093 private: 00094 T *mResource; 00095 TQString mSubResource; 00096 }; 00097 00102 template<class T> 00103 class DeleteVisitor : public IncidenceBase::Visitor 00104 { 00105 public: 00106 DeleteVisitor( T *r ) : mResource( r ) {} 00107 00108 bool visit( Event *e ) { mResource->deleteEvent( e ); return true; } 00109 bool visit( Todo *t ) { mResource->deleteTodo( t ); return true; } 00110 bool visit( Journal *j ) { mResource->deleteJournal( j ); return true; } 00111 00112 private: 00113 T *mResource; 00114 }; 00115 00117 enum Status { 00118 StatusNone, StatusTentative, StatusConfirmed, StatusCompleted, 00119 StatusNeedsAction, StatusCanceled, StatusInProcess, StatusDraft, 00120 StatusFinal, 00121 StatusX // indicates a non-standard status string 00122 }; 00123 00125 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; 00126 00127 typedef ListBase<Incidence> List; 00128 00129 Incidence(); 00130 Incidence( const Incidence & ); 00131 ~Incidence(); 00132 00133 Incidence& operator=( const Incidence &i ); 00134 bool operator==( const Incidence & ) const; 00135 00139 virtual Incidence *clone() = 0; 00140 00147 void setReadOnly( bool readonly ); 00148 00150 void setFloats( bool f ); 00151 00157 void recreate(); 00158 00162 void setCreated( const TQDateTime & ); 00166 TQDateTime created() const; 00167 00171 void setRevision( int rev ); 00175 int revision() const; 00176 00180 virtual void setDtStart( const TQDateTime &dtStart ); 00184 virtual TQDateTime dtEnd() const { return TQDateTime(); } 00185 00189 void setDescription( const TQString &description ); 00193 TQString description() const; 00194 00198 void setSummary( const TQString &summary ); 00202 TQString summary() const; 00203 00207 void setCategories( const TQStringList &categories ); 00211 void setCategories(const TQString &catStr); 00215 TQStringList categories() const; 00219 TQString categoriesStr() const; 00220 00226 void setRelatedToUid(const TQString &); 00232 TQString relatedToUid() const; 00236 void setRelatedTo(Incidence *relatedTo); 00240 Incidence *relatedTo() const; 00244 Incidence::List relations() const; 00248 void addRelation(Incidence *); 00252 void removeRelation(Incidence *); 00253 00254 00255 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00256 // %%%%% Recurrence-related methods 00257 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00258 00263 Recurrence *recurrence() const; 00264 00266 void clearRecurrence(); 00267 00271 bool doesRecur() const; 00272 uint recurrenceType() const; 00273 00278 virtual bool recursOn( const TQDate &qd ) const; 00283 bool recursAt( const TQDateTime &qdt ) const; 00284 00291 virtual bool recursOn( const TQDate &qd, Calendar *cal ) const; 00298 bool recursAt( const TQDateTime &qdt, Calendar *cal ) const; 00299 00308 virtual TQValueList<TQDateTime> startDateTimesForDate( const TQDate &date ) const; 00309 00318 virtual TQValueList<TQDateTime> startDateTimesForDateTime( const TQDateTime &datetime ) const; 00319 00321 virtual TQDateTime endDateForStart( const TQDateTime &startDt ) const; 00322 00323 00324 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00325 // %%%%% Attachment-related methods 00326 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00327 00331 void addAttachment( Attachment *attachment ); 00335 void deleteAttachment( Attachment *attachment ); 00339 void deleteAttachments( const TQString &mime ); 00343 Attachment::List attachments() const; 00347 Attachment::List attachments( const TQString &mime ) const; 00351 void clearAttachments(); 00352 00353 00354 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00355 // %%%%% Secrecy and Status methods 00356 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00357 00362 void setSecrecy( int ); 00366 int secrecy() const; 00370 TQString secrecyStr() const; 00374 static TQStringList secrecyList(); 00378 static TQString secrecyName( int ); 00379 00384 void setStatus( Status status ); 00390 void setCustomStatus( const TQString &status ); 00394 Status status() const; 00398 TQString statusStr() const; 00402 static TQString statusName( Status ); 00403 00404 00405 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00406 // %%%%% Other methods 00407 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00408 00412 void setResources( const TQStringList &resources ); 00416 TQStringList resources() const; 00417 00423 void setPriority( int priority ); 00428 int priority() const; 00429 00435 bool hasRecurrenceID() const; 00436 00443 void setHasRecurrenceID( bool hasRecurrenceID ); 00444 00451 void setRecurrenceID( const TQDateTime &recurrenceID ); 00452 00459 TQDateTime recurrenceID() const; 00460 00466 void addChildIncidence( TQString childIncidence ); 00467 00473 void deleteChildIncidence( TQString childIncidence ); 00474 00480 IncidenceList childIncidences() const; 00481 00482 00483 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00484 // %%%%% Alarm-related methods 00485 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00486 00490 const Alarm::List &alarms() const; 00494 Alarm *newAlarm(); 00498 void addAlarm( Alarm * ); 00502 void removeAlarm( Alarm * ); 00506 void clearAlarms(); 00510 bool isAlarmEnabled() const; 00511 00512 00513 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00514 // %%%%% Other methods 00515 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00516 00517 00518 00522 void setLocation(const TQString &location); 00526 TQString location() const; 00527 00537 void setSchedulingID( const TQString& sid ); 00542 TQString schedulingID() const; 00543 00547 virtual void recurrenceUpdated( Recurrence * ); 00548 protected: 00552 virtual TQDateTime endDateRecurrenceBase() const { return dtStart(); } 00553 00554 private: 00555 int mRevision; 00556 00557 // base components of jounal, event and todo 00558 TQDateTime mCreated; 00559 TQString mDescription; 00560 TQString mSummary; 00561 TQStringList mCategories; 00562 Incidence *mRelatedTo; 00563 TQString mRelatedToUid; 00564 Incidence::List mRelations; 00565 Attachment::List mAttachments; 00566 TQStringList mResources; 00567 00568 TQString mStatusString; 00569 Status mStatus; 00570 int mSecrecy; 00571 int mPriority; // 1 = highest, 2 = less, etc. 00572 00573 Alarm::List mAlarms; 00574 Recurrence *mRecurrence; 00575 00576 TQString mLocation; 00577 00578 // Scheduling ID - used only to identify between scheduling mails 00579 TQString mSchedulingID; 00580 00581 TQDateTime mRecurrenceID; // recurrenceID 00582 bool mHasRecurrenceID; // if incidence has recurrenceID 00583 00584 IncidenceList mChildRecurrenceEvents; 00585 00586 class Private; 00587 Private *d; 00588 }; 00589 00590 } 00591 00592 #endif