summaryrefslogtreecommitdiffabout
path: root/libkcal/incidence.h
blob: 29401298f45b29439a1a4d24e7efbbc3279adcef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
    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 INCIDENCE_H
#define INCIDENCE_H
//
// Incidence - base class of calendaring components
//

#include <qdatetime.h>
#include <qstringlist.h>
#include <q3valuelist.h>
//Added by qt3to4:
#include <Q3PtrList>

#include "recurrence.h"
#include "alarm.h"
#include "attachment.h"
#include "listbase.h"
#include "incidencebase.h"

namespace KCal {

class Event;
class Todo;
class Journal;

/**
  This class provides the base class common to all calendar components.
*/
class Incidence : public IncidenceBase
{
  public:
    /**
      This class provides the interface for a visitor of calendar components. It
      serves as base class for concrete visitors, which implement certain actions on
      calendar components. It allows to add functions, which operate on the concrete
      types of calendar components, without changing the calendar component classes.
    */
    class Visitor
    {
      public:
        /** Destruct Incidence::Visitor */
        virtual ~Visitor() {}

        /**
          Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
          on an Event object.
        */
        virtual bool visit(Event *) { return false; }
        /**
          Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
          on an Todo object.
        */
        virtual bool visit(Todo *) { return false; }
        /**
          Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
          on an Journal object.
        */
        virtual bool visit(Journal *) { return false; }

      protected:
        /** Constructor is protected to prevent direct creation of visitor base class. */
        Visitor() {}
    };

    /**
      This class implements a visitor for adding an Incidence to a resource
      supporting addEvent(), addTodo() and addJournal() calls.
    */
    template<class T>
    class AddVisitor : public Visitor
    {
      public:
        AddVisitor( T *r ) : mResource( r ) {}
        bool visit( Event *e ) { return mResource->addEvent( e ); }
        bool visit( Todo *t ) { return mResource->addTodo( t ); }
        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(Q3PtrList<Incidence> *rel);
    void clearRelations();
    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);
    void resetRelatedTo();
    /** what event does this one relate to? */
    Incidence *relatedTo() const;
    /** All events that are related to this event */
    Q3PtrList<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 */
    Q3PtrList<Attachment> attachments() const;
    /** find a list of attachments with this mime type */
    Q3PtrList<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 */
    Q3PtrList<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 lastModifiedSubSortKey() const;
    QString recurrenceText() const;
    void setLastModifiedSubInvalid();
    
    virtual QString durationText();
    QString durationText4Time( int secs );
    Recurrence *mRecurrence;
protected:
    Q3PtrList<Alarm> mAlarms;
    Q3PtrList<Incidence> mRelations;
    QDateTime mRecurrenceID;
    bool mHasRecurrenceID;
  private:
    void checkCategories();
    QString mLastModifiedSubSortKey;
    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;
    Q3PtrList<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