libkcal

incidence.h

Go to the documentation of this file.
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 <qdatetime.h>
00026 #include <qstringlist.h>
00027 #include <qvaluelist.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 <kdepimmacros.h>
00036 
00037 namespace KCal {
00038 
00039 
00043 class LIBKCAL_EXPORT Incidence : public IncidenceBase, public Recurrence::Observer
00044 {
00045   public:
00050     template<class T>
00051     class AddVisitor : public IncidenceBase::Visitor
00052     {
00053       public:
00054         AddVisitor( T *r ) : mResource( r ) {}
00055 
00056         bool visit( Event *e ) { return mResource->addEvent( e ); }
00057         bool visit( Todo *t ) { return mResource->addTodo( t ); }
00058         bool visit( Journal *j ) { return mResource->addJournal( j ); }
00059 
00060       private:
00061         T *mResource;
00062     };
00063 
00068     template<class T>
00069     class DeleteVisitor : public IncidenceBase::Visitor
00070     {
00071       public:
00072         DeleteVisitor( T *r ) : mResource( r ) {}
00073 
00074         bool visit( Event *e ) { mResource->deleteEvent( e ); return true; }
00075         bool visit( Todo *t ) { mResource->deleteTodo( t ); return true; }
00076         bool visit( Journal *j ) { mResource->deleteJournal( j ); return true; }
00077 
00078       private:
00079         T *mResource;
00080     };
00081 
00083     enum Status {
00084         StatusNone, StatusTentative, StatusConfirmed, StatusCompleted,
00085         StatusNeedsAction, StatusCanceled, StatusInProcess, StatusDraft,
00086         StatusFinal,
00087         StatusX   // indicates a non-standard status string
00088     };
00089 
00091     enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 };
00092 
00093     typedef ListBase<Incidence> List;
00094 
00095     Incidence();
00096     Incidence( const Incidence & );
00097     ~Incidence();
00098 
00099     Incidence& operator=( const Incidence &i );
00100     bool operator==( const Incidence & ) const;
00101 
00105     virtual Incidence *clone() = 0;
00106 
00113     void setReadOnly( bool readonly );
00114 
00116     void setFloats( bool f );
00117 
00123     void recreate();
00124 
00128     void setCreated( const QDateTime & );
00132     QDateTime created() const;
00133 
00137     void setRevision( int rev );
00141     int revision() const;
00142 
00146     virtual void setDtStart( const QDateTime &dtStart );
00150     virtual QDateTime dtEnd() const  { return QDateTime(); }
00151 
00155     void setDescription( const QString &description );
00159     QString description() const;
00160 
00164     void setSummary( const QString &summary );
00168     QString summary() const;
00169 
00173     void setCategories( const QStringList &categories );
00177     void setCategories(const QString &catStr);
00181     QStringList categories() const;
00185     QString categoriesStr() const;
00186 
00192     void setRelatedToUid(const QString &);
00198     QString relatedToUid() const;
00202     void setRelatedTo(Incidence *relatedTo);
00206     Incidence *relatedTo() const;
00210     Incidence::List relations() const;
00214     void addRelation(Incidence *);
00218     void removeRelation(Incidence *);
00219 
00220 
00221 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00222 // %%%%%  Recurrence-related methods
00223 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00224 
00229     Recurrence *recurrence() const;
00230 
00232     void clearRecurrence();
00233 
00237     bool doesRecur() const;
00238     uint recurrenceType() const;
00239 
00244     virtual bool recursOn( const QDate &qd ) const;
00249     bool recursAt( const QDateTime &qdt ) const;
00250 
00259     virtual QValueList<QDateTime> startDateTimesForDate( const QDate &date ) const;
00260 
00269     virtual QValueList<QDateTime> startDateTimesForDateTime( const QDateTime &datetime ) const;
00270 
00272     virtual QDateTime endDateForStart( const QDateTime &startDt ) const;
00273 
00274 
00275 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00276 // %%%%%  Attachment-related methods
00277 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00278 
00282     void addAttachment( Attachment *attachment );
00286     void deleteAttachment( Attachment *attachment );
00290     void deleteAttachments( const QString &mime );
00294     Attachment::List attachments() const;
00298     Attachment::List attachments( const QString &mime ) const;
00302     void clearAttachments();
00303 
00304 
00305 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00306 // %%%%%  Secrecy and Status methods
00307 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00308 
00313     void setSecrecy( int );
00317     int secrecy() const;
00321     QString secrecyStr() const;
00325     static QStringList secrecyList();
00329     static QString secrecyName( int );
00330 
00335     void setStatus( Status status );
00341     void setCustomStatus( const QString &status );
00345     Status status() const;
00349     QString statusStr() const;
00353     static QString statusName( Status );
00354 
00355 
00356 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00357 // %%%%%  Other methods
00358 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00359 
00363     void setResources( const QStringList &resources );
00367     QStringList resources() const;
00368 
00374     void setPriority( int priority );
00379     int priority() const;
00380 
00381 
00382 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00383 // %%%%%  Alarm-related methods
00384 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00385 
00389     const Alarm::List &alarms() const;
00393     Alarm *newAlarm();
00397     void addAlarm( Alarm * );
00401     void removeAlarm( Alarm * );
00405     void clearAlarms();
00409     bool isAlarmEnabled() const;
00410 
00411 
00412 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00413 // %%%%%  Other methods
00414 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00415 
00416 
00417 
00421     void setLocation(const QString &location);
00425     QString location() const;
00426 
00436     void setSchedulingID( const QString& sid );
00441     QString schedulingID() const;
00442 
00446     virtual void recurrenceUpdated( Recurrence * );
00447   protected:
00451     virtual QDateTime endDateRecurrenceBase() const { return dtStart(); }
00452 
00453   private:
00454     int mRevision;
00455 
00456     // base components of jounal, event and todo
00457     QDateTime mCreated;
00458     QString mDescription;
00459     QString mSummary;
00460     QStringList mCategories;
00461     Incidence *mRelatedTo;
00462     QString mRelatedToUid;
00463     Incidence::List mRelations;
00464     Attachment::List mAttachments;
00465     QStringList mResources;
00466 
00467     QString mStatusString;
00468     Status  mStatus;
00469     int mSecrecy;
00470     int mPriority;                        // 1 = highest, 2 = less, etc.
00471 
00472     Alarm::List mAlarms;
00473     Recurrence *mRecurrence;
00474 
00475     QString mLocation;
00476 
00477     // Scheduling ID - used only to identify between scheduling mails
00478     QString mSchedulingID;
00479 
00480     class Private;
00481     Private *d;
00482 };
00483 
00484 }
00485 
00486 #endif