-rw-r--r-- | libkcal/incidence.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 708ee6b..9a36939 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,139 +1,162 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "calformat.h" | 25 | #include "calformat.h" |
26 | 26 | ||
27 | #include "incidence.h" | 27 | #include "incidence.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | 29 | ||
30 | using namespace KCal; | 30 | using namespace KCal; |
31 | 31 | ||
32 | Incidence::Incidence() : | 32 | Incidence::Incidence() : |
33 | IncidenceBase(), | 33 | IncidenceBase(), |
34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) | 34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) |
35 | { | 35 | { |
36 | mRecurrence = new Recurrence(this); | 36 | mRecurrence = new Recurrence(this); |
37 | mCancelled = false; | 37 | mCancelled = false; |
38 | recreate(); | 38 | recreate(); |
39 | mHasStartDate = true; | 39 | mHasStartDate = true; |
40 | mAlarms.setAutoDelete(true); | 40 | mAlarms.setAutoDelete(true); |
41 | mAttachments.setAutoDelete(true); | 41 | mAttachments.setAutoDelete(true); |
42 | mHasRecurrenceID = false; | 42 | mHasRecurrenceID = false; |
43 | mHoliday = false; | ||
44 | mBirthday = false; | ||
45 | mAnniversary = false; | ||
46 | |||
43 | } | 47 | } |
44 | 48 | ||
45 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
46 | { | 50 | { |
47 | // TODO: reenable attributes currently commented out. | 51 | // TODO: reenable attributes currently commented out. |
48 | mRevision = i.mRevision; | 52 | mRevision = i.mRevision; |
49 | mCreated = i.mCreated; | 53 | mCreated = i.mCreated; |
50 | mDescription = i.mDescription; | 54 | mDescription = i.mDescription; |
51 | mSummary = i.mSummary; | 55 | mSummary = i.mSummary; |
52 | mCategories = i.mCategories; | 56 | mCategories = i.mCategories; |
53 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
54 | mRelatedTo = 0; | 58 | mRelatedTo = 0; |
55 | mRelatedToUid = i.mRelatedToUid; | 59 | mRelatedToUid = i.mRelatedToUid; |
56 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
57 | mExDates = i.mExDates; | 61 | mExDates = i.mExDates; |
58 | mAttachments = i.mAttachments; | 62 | mAttachments = i.mAttachments; |
59 | mResources = i.mResources; | 63 | mResources = i.mResources; |
60 | mSecrecy = i.mSecrecy; | 64 | mSecrecy = i.mSecrecy; |
61 | mPriority = i.mPriority; | 65 | mPriority = i.mPriority; |
62 | mLocation = i.mLocation; | 66 | mLocation = i.mLocation; |
63 | mCancelled = i.mCancelled; | 67 | mCancelled = i.mCancelled; |
64 | mHasStartDate = i.mHasStartDate; | 68 | mHasStartDate = i.mHasStartDate; |
65 | QPtrListIterator<Alarm> it( i.mAlarms ); | 69 | QPtrListIterator<Alarm> it( i.mAlarms ); |
66 | const Alarm *a; | 70 | const Alarm *a; |
67 | while( (a = it.current()) ) { | 71 | while( (a = it.current()) ) { |
68 | Alarm *b = new Alarm( *a ); | 72 | Alarm *b = new Alarm( *a ); |
69 | b->setParent( this ); | 73 | b->setParent( this ); |
70 | mAlarms.append( b ); | 74 | mAlarms.append( b ); |
71 | 75 | ||
72 | ++it; | 76 | ++it; |
73 | } | 77 | } |
74 | mAlarms.setAutoDelete(true); | 78 | mAlarms.setAutoDelete(true); |
75 | mHasRecurrenceID = i.mHasRecurrenceID; | 79 | mHasRecurrenceID = i.mHasRecurrenceID; |
76 | mRecurrenceID = i.mRecurrenceID; | 80 | mRecurrenceID = i.mRecurrenceID; |
77 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 81 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); |
82 | mHoliday = i.mHoliday ; | ||
83 | mBirthday = i.mBirthday; | ||
84 | mAnniversary = i.mAnniversary; | ||
78 | } | 85 | } |
79 | 86 | ||
80 | Incidence::~Incidence() | 87 | Incidence::~Incidence() |
81 | { | 88 | { |
82 | 89 | ||
83 | Incidence *ev; | 90 | Incidence *ev; |
84 | QPtrList<Incidence> Relations = relations(); | 91 | QPtrList<Incidence> Relations = relations(); |
85 | for (ev=Relations.first();ev;ev=Relations.next()) { | 92 | for (ev=Relations.first();ev;ev=Relations.next()) { |
86 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 93 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
87 | } | 94 | } |
88 | if (relatedTo()) relatedTo()->removeRelation(this); | 95 | if (relatedTo()) relatedTo()->removeRelation(this); |
89 | delete mRecurrence; | 96 | delete mRecurrence; |
90 | 97 | ||
91 | } | 98 | } |
99 | |||
100 | bool Incidence::isHoliday() const | ||
101 | { | ||
102 | return mHoliday; | ||
103 | } | ||
104 | bool Incidence::isBirthday() const | ||
105 | { | ||
106 | |||
107 | return mBirthday ; | ||
108 | } | ||
109 | bool Incidence::isAnniversary() const | ||
110 | { | ||
111 | return mAnniversary ; | ||
112 | |||
113 | } | ||
114 | |||
92 | bool Incidence::hasRecurrenceID() const | 115 | bool Incidence::hasRecurrenceID() const |
93 | { | 116 | { |
94 | return mHasRecurrenceID; | 117 | return mHasRecurrenceID; |
95 | } | 118 | } |
96 | 119 | ||
97 | void Incidence::setHasRecurrenceID( bool b ) | 120 | void Incidence::setHasRecurrenceID( bool b ) |
98 | { | 121 | { |
99 | mHasRecurrenceID = b; | 122 | mHasRecurrenceID = b; |
100 | } | 123 | } |
101 | 124 | ||
102 | void Incidence::setRecurrenceID(QDateTime d) | 125 | void Incidence::setRecurrenceID(QDateTime d) |
103 | { | 126 | { |
104 | mRecurrenceID = d; | 127 | mRecurrenceID = d; |
105 | mHasRecurrenceID = true; | 128 | mHasRecurrenceID = true; |
106 | updated(); | 129 | updated(); |
107 | } | 130 | } |
108 | QDateTime Incidence::recurrenceID () const | 131 | QDateTime Incidence::recurrenceID () const |
109 | { | 132 | { |
110 | return mRecurrenceID; | 133 | return mRecurrenceID; |
111 | } | 134 | } |
112 | 135 | ||
113 | bool Incidence::cancelled() const | 136 | bool Incidence::cancelled() const |
114 | { | 137 | { |
115 | return mCancelled; | 138 | return mCancelled; |
116 | } | 139 | } |
117 | void Incidence::setCancelled( bool b ) | 140 | void Incidence::setCancelled( bool b ) |
118 | { | 141 | { |
119 | mCancelled = b; | 142 | mCancelled = b; |
120 | updated(); | 143 | updated(); |
121 | } | 144 | } |
122 | bool Incidence::hasStartDate() const | 145 | bool Incidence::hasStartDate() const |
123 | { | 146 | { |
124 | return mHasStartDate; | 147 | return mHasStartDate; |
125 | } | 148 | } |
126 | 149 | ||
127 | void Incidence::setHasStartDate(bool f) | 150 | void Incidence::setHasStartDate(bool f) |
128 | { | 151 | { |
129 | if (mReadOnly) return; | 152 | if (mReadOnly) return; |
130 | mHasStartDate = f; | 153 | mHasStartDate = f; |
131 | updated(); | 154 | updated(); |
132 | } | 155 | } |
133 | 156 | ||
134 | // A string comparison that considers that null and empty are the same | 157 | // A string comparison that considers that null and empty are the same |
135 | static bool stringCompare( const QString& s1, const QString& s2 ) | 158 | static bool stringCompare( const QString& s1, const QString& s2 ) |
136 | { | 159 | { |
137 | if ( s1.isEmpty() && s2.isEmpty() ) | 160 | if ( s1.isEmpty() && s2.isEmpty() ) |
138 | return true; | 161 | return true; |
139 | return s1 == s2; | 162 | return s1 == s2; |
@@ -257,119 +280,126 @@ QDateTime Incidence::created() const | |||
257 | return mCreated; | 280 | return mCreated; |
258 | } | 281 | } |
259 | 282 | ||
260 | void Incidence::setRevision(int rev) | 283 | void Incidence::setRevision(int rev) |
261 | { | 284 | { |
262 | if (mReadOnly) return; | 285 | if (mReadOnly) return; |
263 | mRevision = rev; | 286 | mRevision = rev; |
264 | 287 | ||
265 | updated(); | 288 | updated(); |
266 | } | 289 | } |
267 | 290 | ||
268 | int Incidence::revision() const | 291 | int Incidence::revision() const |
269 | { | 292 | { |
270 | return mRevision; | 293 | return mRevision; |
271 | } | 294 | } |
272 | 295 | ||
273 | void Incidence::setDtStart(const QDateTime &dtStart) | 296 | void Incidence::setDtStart(const QDateTime &dtStart) |
274 | { | 297 | { |
275 | 298 | ||
276 | QDateTime dt = getEvenTime(dtStart); | 299 | QDateTime dt = getEvenTime(dtStart); |
277 | recurrence()->setRecurStart( dt); | 300 | recurrence()->setRecurStart( dt); |
278 | IncidenceBase::setDtStart( dt ); | 301 | IncidenceBase::setDtStart( dt ); |
279 | } | 302 | } |
280 | 303 | ||
281 | void Incidence::setDescription(const QString &description) | 304 | void Incidence::setDescription(const QString &description) |
282 | { | 305 | { |
283 | if (mReadOnly) return; | 306 | if (mReadOnly) return; |
284 | mDescription = description; | 307 | mDescription = description; |
285 | updated(); | 308 | updated(); |
286 | } | 309 | } |
287 | 310 | ||
288 | QString Incidence::description() const | 311 | QString Incidence::description() const |
289 | { | 312 | { |
290 | return mDescription; | 313 | return mDescription; |
291 | } | 314 | } |
292 | 315 | ||
293 | 316 | ||
294 | void Incidence::setSummary(const QString &summary) | 317 | void Incidence::setSummary(const QString &summary) |
295 | { | 318 | { |
296 | if (mReadOnly) return; | 319 | if (mReadOnly) return; |
297 | mSummary = summary; | 320 | mSummary = summary; |
298 | updated(); | 321 | updated(); |
299 | } | 322 | } |
300 | 323 | ||
301 | QString Incidence::summary() const | 324 | QString Incidence::summary() const |
302 | { | 325 | { |
303 | return mSummary; | 326 | return mSummary; |
304 | } | 327 | } |
328 | void Incidence::checkCategories() | ||
329 | { | ||
330 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); | ||
331 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); | ||
332 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); | ||
333 | } | ||
305 | 334 | ||
306 | void Incidence::setCategories(const QStringList &categories) | 335 | void Incidence::setCategories(const QStringList &categories) |
307 | { | 336 | { |
308 | if (mReadOnly) return; | 337 | if (mReadOnly) return; |
309 | mCategories = categories; | 338 | mCategories = categories; |
339 | checkCategories(); | ||
310 | updated(); | 340 | updated(); |
311 | } | 341 | } |
312 | 342 | ||
313 | // TODO: remove setCategories(QString) function | 343 | // TODO: remove setCategories(QString) function |
314 | void Incidence::setCategories(const QString &catStr) | 344 | void Incidence::setCategories(const QString &catStr) |
315 | { | 345 | { |
316 | if (mReadOnly) return; | 346 | if (mReadOnly) return; |
317 | mCategories.clear(); | 347 | mCategories.clear(); |
318 | 348 | ||
319 | if (catStr.isEmpty()) return; | 349 | if (catStr.isEmpty()) return; |
320 | 350 | ||
321 | mCategories = QStringList::split(",",catStr); | 351 | mCategories = QStringList::split(",",catStr); |
322 | 352 | ||
323 | QStringList::Iterator it; | 353 | QStringList::Iterator it; |
324 | for(it = mCategories.begin();it != mCategories.end(); ++it) { | 354 | for(it = mCategories.begin();it != mCategories.end(); ++it) { |
325 | *it = (*it).stripWhiteSpace(); | 355 | *it = (*it).stripWhiteSpace(); |
326 | } | 356 | } |
327 | 357 | checkCategories(); | |
328 | updated(); | 358 | updated(); |
329 | } | 359 | } |
330 | 360 | ||
331 | QStringList Incidence::categories() const | 361 | QStringList Incidence::categories() const |
332 | { | 362 | { |
333 | return mCategories; | 363 | return mCategories; |
334 | } | 364 | } |
335 | 365 | ||
336 | QString Incidence::categoriesStr() | 366 | QString Incidence::categoriesStr() |
337 | { | 367 | { |
338 | return mCategories.join(","); | 368 | return mCategories.join(","); |
339 | } | 369 | } |
340 | 370 | ||
341 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 371 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
342 | { | 372 | { |
343 | if (mReadOnly) return; | 373 | if (mReadOnly) return; |
344 | mRelatedToUid = relatedToUid; | 374 | mRelatedToUid = relatedToUid; |
345 | } | 375 | } |
346 | 376 | ||
347 | QString Incidence::relatedToUid() const | 377 | QString Incidence::relatedToUid() const |
348 | { | 378 | { |
349 | return mRelatedToUid; | 379 | return mRelatedToUid; |
350 | } | 380 | } |
351 | 381 | ||
352 | void Incidence::setRelatedTo(Incidence *relatedTo) | 382 | void Incidence::setRelatedTo(Incidence *relatedTo) |
353 | { | 383 | { |
354 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 384 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
355 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 385 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
356 | if (mReadOnly || mRelatedTo == relatedTo) return; | 386 | if (mReadOnly || mRelatedTo == relatedTo) return; |
357 | if(mRelatedTo) { | 387 | if(mRelatedTo) { |
358 | // updated(); | 388 | // updated(); |
359 | mRelatedTo->removeRelation(this); | 389 | mRelatedTo->removeRelation(this); |
360 | } | 390 | } |
361 | mRelatedTo = relatedTo; | 391 | mRelatedTo = relatedTo; |
362 | if (mRelatedTo) mRelatedTo->addRelation(this); | 392 | if (mRelatedTo) mRelatedTo->addRelation(this); |
363 | } | 393 | } |
364 | 394 | ||
365 | Incidence *Incidence::relatedTo() const | 395 | Incidence *Incidence::relatedTo() const |
366 | { | 396 | { |
367 | return mRelatedTo; | 397 | return mRelatedTo; |
368 | } | 398 | } |
369 | 399 | ||
370 | QPtrList<Incidence> Incidence::relations() const | 400 | QPtrList<Incidence> Incidence::relations() const |
371 | { | 401 | { |
372 | return mRelations; | 402 | return mRelations; |
373 | } | 403 | } |
374 | 404 | ||
375 | void Incidence::addRelation(Incidence *event) | 405 | void Incidence::addRelation(Incidence *event) |