summaryrefslogtreecommitdiffabout
path: root/libkcal/incidence.cpp
Unidiff
Diffstat (limited to 'libkcal/incidence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidence.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index a312ba5..6bca12c 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -1,697 +1,702 @@
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
30using namespace KCal; 30using namespace KCal;
31 31
32Incidence::Incidence() : 32Incidence::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; 43 mHoliday = false;
44 mBirthday = false; 44 mBirthday = false;
45 mAnniversary = false; 45 mAnniversary = false;
46 46
47} 47}
48 48
49Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) 49Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
50{ 50{
51// TODO: reenable attributes currently commented out. 51// TODO: reenable attributes currently commented out.
52 mRevision = i.mRevision; 52 mRevision = i.mRevision;
53 mCreated = i.mCreated; 53 mCreated = i.mCreated;
54 mDescription = i.mDescription; 54 mDescription = i.mDescription;
55 mSummary = i.mSummary; 55 mSummary = i.mSummary;
56 mCategories = i.mCategories; 56 mCategories = i.mCategories;
57// Incidence *mRelatedTo; Incidence *mRelatedTo; 57// Incidence *mRelatedTo; Incidence *mRelatedTo;
58 mRelatedTo = 0; 58 mRelatedTo = 0;
59 mRelatedToUid = i.mRelatedToUid; 59 mRelatedToUid = i.mRelatedToUid;
60// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; 60// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations;
61 mExDates = i.mExDates; 61 mExDates = i.mExDates;
62 mAttachments = i.mAttachments; 62 mAttachments = i.mAttachments;
63 mResources = i.mResources; 63 mResources = i.mResources;
64 mSecrecy = i.mSecrecy; 64 mSecrecy = i.mSecrecy;
65 mPriority = i.mPriority; 65 mPriority = i.mPriority;
66 mLocation = i.mLocation; 66 mLocation = i.mLocation;
67 mCancelled = i.mCancelled; 67 mCancelled = i.mCancelled;
68 mHasStartDate = i.mHasStartDate; 68 mHasStartDate = i.mHasStartDate;
69 QPtrListIterator<Alarm> it( i.mAlarms ); 69 QPtrListIterator<Alarm> it( i.mAlarms );
70 const Alarm *a; 70 const Alarm *a;
71 while( (a = it.current()) ) { 71 while( (a = it.current()) ) {
72 Alarm *b = new Alarm( *a ); 72 Alarm *b = new Alarm( *a );
73 b->setParent( this ); 73 b->setParent( this );
74 mAlarms.append( b ); 74 mAlarms.append( b );
75 75
76 ++it; 76 ++it;
77 } 77 }
78 mAlarms.setAutoDelete(true); 78 mAlarms.setAutoDelete(true);
79 mHasRecurrenceID = i.mHasRecurrenceID; 79 mHasRecurrenceID = i.mHasRecurrenceID;
80 mRecurrenceID = i.mRecurrenceID; 80 mRecurrenceID = i.mRecurrenceID;
81 mRecurrence = new Recurrence( *(i.mRecurrence), this ); 81 mRecurrence = new Recurrence( *(i.mRecurrence), this );
82 mHoliday = i.mHoliday ; 82 mHoliday = i.mHoliday ;
83 mBirthday = i.mBirthday; 83 mBirthday = i.mBirthday;
84 mAnniversary = i.mAnniversary; 84 mAnniversary = i.mAnniversary;
85} 85}
86 86
87Incidence::~Incidence() 87Incidence::~Incidence()
88{ 88{
89 89
90 Incidence *ev; 90 Incidence *ev;
91 QPtrList<Incidence> Relations = relations(); 91 QPtrList<Incidence> Relations = relations();
92 for (ev=Relations.first();ev;ev=Relations.next()) { 92 for (ev=Relations.first();ev;ev=Relations.next()) {
93 if (ev->relatedTo() == this) ev->setRelatedTo(0); 93 if (ev->relatedTo() == this) ev->setRelatedTo(0);
94 } 94 }
95 if (relatedTo()) relatedTo()->removeRelation(this); 95 if (relatedTo()) relatedTo()->removeRelation(this);
96 delete mRecurrence; 96 delete mRecurrence;
97 97
98} 98}
99 99
100bool Incidence::isHoliday() const 100bool Incidence::isHoliday() const
101{ 101{
102 return mHoliday; 102 return mHoliday;
103} 103}
104bool Incidence::isBirthday() const 104bool Incidence::isBirthday() const
105{ 105{
106 106
107 return mBirthday ; 107 return mBirthday ;
108} 108}
109bool Incidence::isAnniversary() const 109bool Incidence::isAnniversary() const
110{ 110{
111 return mAnniversary ; 111 return mAnniversary ;
112 112
113} 113}
114 114
115bool Incidence::hasRecurrenceID() const 115bool Incidence::hasRecurrenceID() const
116{ 116{
117 return mHasRecurrenceID; 117 return mHasRecurrenceID;
118} 118}
119 119
120void Incidence::setHasRecurrenceID( bool b ) 120void Incidence::setHasRecurrenceID( bool b )
121{ 121{
122 mHasRecurrenceID = b; 122 mHasRecurrenceID = b;
123} 123}
124 124
125void Incidence::setRecurrenceID(QDateTime d) 125void Incidence::setRecurrenceID(QDateTime d)
126{ 126{
127 mRecurrenceID = d; 127 mRecurrenceID = d;
128 mHasRecurrenceID = true; 128 mHasRecurrenceID = true;
129 updated(); 129 updated();
130} 130}
131QDateTime Incidence::recurrenceID () const 131QDateTime Incidence::recurrenceID () const
132{ 132{
133 return mRecurrenceID; 133 return mRecurrenceID;
134} 134}
135 135
136bool Incidence::cancelled() const 136bool Incidence::cancelled() const
137{ 137{
138 return mCancelled; 138 return mCancelled;
139} 139}
140void Incidence::setCancelled( bool b ) 140void Incidence::setCancelled( bool b )
141{ 141{
142 mCancelled = b; 142 mCancelled = b;
143 updated(); 143 updated();
144} 144}
145bool Incidence::hasStartDate() const 145bool Incidence::hasStartDate() const
146{ 146{
147 return mHasStartDate; 147 return mHasStartDate;
148} 148}
149 149
150void Incidence::setHasStartDate(bool f) 150void Incidence::setHasStartDate(bool f)
151{ 151{
152 if (mReadOnly) return; 152 if (mReadOnly) return;
153 mHasStartDate = f; 153 mHasStartDate = f;
154 updated(); 154 updated();
155} 155}
156 156
157// 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
158static bool stringCompare( const QString& s1, const QString& s2 ) 158static bool stringCompare( const QString& s1, const QString& s2 )
159{ 159{
160 if ( s1.isEmpty() && s2.isEmpty() ) 160 if ( s1.isEmpty() && s2.isEmpty() )
161 return true; 161 return true;
162 return s1 == s2; 162 return s1 == s2;
163} 163}
164 164
165bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 165bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
166{ 166{
167 167
168 if( i1.alarms().count() != i2.alarms().count() ) { 168 if( i1.alarms().count() != i2.alarms().count() ) {
169 return false; // no need to check further 169 return false; // no need to check further
170 } 170 }
171 if ( i1.alarms().count() > 0 ) { 171 if ( i1.alarms().count() > 0 ) {
172 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) 172 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) )
173 { 173 {
174 qDebug("alarm not equal "); 174 qDebug("alarm not equal ");
175 return false; 175 return false;
176 } 176 }
177 } 177 }
178#if 0 178#if 0
179 QPtrListIterator<Alarm> a1( i1.alarms() ); 179 QPtrListIterator<Alarm> a1( i1.alarms() );
180 QPtrListIterator<Alarm> a2( i2.alarms() ); 180 QPtrListIterator<Alarm> a2( i2.alarms() );
181 for( ; a1.current() && a2.current(); ++a1, ++a2 ) { 181 for( ; a1.current() && a2.current(); ++a1, ++a2 ) {
182 if( *a1.current() == *a2.current() ) { 182 if( *a1.current() == *a2.current() ) {
183 continue; 183 continue;
184 } 184 }
185 else { 185 else {
186 return false; 186 return false;
187 } 187 }
188 } 188 }
189#endif 189#endif
190 190
191 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { 191 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) {
192 if ( i1.hasRecurrenceID() ) { 192 if ( i1.hasRecurrenceID() ) {
193 if ( i1.recurrenceID() != i2.recurrenceID() ) 193 if ( i1.recurrenceID() != i2.recurrenceID() )
194 return false; 194 return false;
195 } 195 }
196 196
197 } else { 197 } else {
198 return false; 198 return false;
199 } 199 }
200 200
201 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) 201 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) )
202 return false; 202 return false;
203 if ( i1.hasStartDate() == i2.hasStartDate() ) { 203 if ( i1.hasStartDate() == i2.hasStartDate() ) {
204 if ( i1.hasStartDate() ) { 204 if ( i1.hasStartDate() ) {
205 if ( i1.dtStart() != i2.dtStart() ) 205 if ( i1.dtStart() != i2.dtStart() )
206 return false; 206 return false;
207 } 207 }
208 } else { 208 } else {
209 return false; 209 return false;
210 } 210 }
211 if (!( *i1.recurrence() == *i2.recurrence()) ) { 211 if (!( *i1.recurrence() == *i2.recurrence()) ) {
212 qDebug("recurrence is NOT equal "); 212 qDebug("recurrence is NOT equal ");
213 return false; 213 return false;
214 } 214 }
215 return 215 return
216 // i1.created() == i2.created() && 216 // i1.created() == i2.created() &&
217 stringCompare( i1.description(), i2.description() ) && 217 stringCompare( i1.description(), i2.description() ) &&
218 stringCompare( i1.summary(), i2.summary() ) && 218 stringCompare( i1.summary(), i2.summary() ) &&
219 i1.categories() == i2.categories() && 219 i1.categories() == i2.categories() &&
220 // no need to compare mRelatedTo 220 // no need to compare mRelatedTo
221 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && 221 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) &&
222 // i1.relations() == i2.relations() && 222 // i1.relations() == i2.relations() &&
223 i1.exDates() == i2.exDates() && 223 i1.exDates() == i2.exDates() &&
224 i1.attachments() == i2.attachments() && 224 i1.attachments() == i2.attachments() &&
225 i1.resources() == i2.resources() && 225 i1.resources() == i2.resources() &&
226 i1.secrecy() == i2.secrecy() && 226 i1.secrecy() == i2.secrecy() &&
227 i1.priority() == i2.priority() && 227 i1.priority() == i2.priority() &&
228 i1.cancelled() == i2.cancelled() && 228 i1.cancelled() == i2.cancelled() &&
229 stringCompare( i1.location(), i2.location() ); 229 stringCompare( i1.location(), i2.location() );
230} 230}
231 231
232Incidence* Incidence::recreateCloneException( QDate d ) 232Incidence* Incidence::recreateCloneException( QDate d )
233{ 233{
234 Incidence* newInc = clone(); 234 Incidence* newInc = clone();
235 newInc->recreate(); 235 newInc->recreate();
236 if ( doesRecur() ) { 236 if ( doesRecur() ) {
237 addExDate( d ); 237 addExDate( d );
238 newInc->recurrence()->unsetRecurs(); 238 newInc->recurrence()->unsetRecurs();
239 if ( type() == "Event") { 239 if ( type() == "Event") {
240 int len = dtStart().secsTo( ((Event*)this)->dtEnd()); 240 int len = dtStart().secsTo( ((Event*)this)->dtEnd());
241 QTime tim = dtStart().time(); 241 QTime tim = dtStart().time();
242 newInc->setDtStart( QDateTime(d, tim) ); 242 newInc->setDtStart( QDateTime(d, tim) );
243 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 243 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
244 } else { 244 } else {
245 int len = dtStart().secsTo( ((Todo*)this)->dtDue()); 245 int len = dtStart().secsTo( ((Todo*)this)->dtDue());
246 QTime tim = ((Todo*)this)->dtDue().time(); 246 QTime tim = ((Todo*)this)->dtDue().time();
247 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); 247 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) );
248 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); 248 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) );
249 ((Todo*)this)->setRecurDates(); 249 ((Todo*)this)->setRecurDates();
250 } 250 }
251 newInc->setExDates( DateList () ); 251 newInc->setExDates( DateList () );
252 } 252 }
253 return newInc; 253 return newInc;
254} 254}
255 255
256void Incidence::recreate() 256void Incidence::recreate()
257{ 257{
258 setCreated(QDateTime::currentDateTime()); 258 setCreated(QDateTime::currentDateTime());
259 259
260 setUid(CalFormat::createUniqueId()); 260 setUid(CalFormat::createUniqueId());
261 261
262 setRevision(0); 262 setRevision(0);
263 setIDStr( ":" ); 263 setIDStr( ":" );
264 setLastModified(QDateTime::currentDateTime()); 264 setLastModified(QDateTime::currentDateTime());
265} 265}
266 266
267void Incidence::setReadOnly( bool readOnly ) 267void Incidence::setReadOnly( bool readOnly )
268{ 268{
269 IncidenceBase::setReadOnly( readOnly ); 269 IncidenceBase::setReadOnly( readOnly );
270 recurrence()->setRecurReadOnly( readOnly); 270 recurrence()->setRecurReadOnly( readOnly);
271} 271}
272 272
273void Incidence::setCreated(QDateTime created) 273void Incidence::setCreated(QDateTime created)
274{ 274{
275 if (mReadOnly) return; 275 if (mReadOnly) return;
276 mCreated = getEvenTime(created); 276 mCreated = getEvenTime(created);
277} 277}
278 278
279QDateTime Incidence::created() const 279QDateTime Incidence::created() const
280{ 280{
281 return mCreated; 281 return mCreated;
282} 282}
283 283
284void Incidence::setRevision(int rev) 284void Incidence::setRevision(int rev)
285{ 285{
286 if (mReadOnly) return; 286 if (mReadOnly) return;
287 mRevision = rev; 287 mRevision = rev;
288 288
289 updated(); 289 updated();
290} 290}
291 291
292int Incidence::revision() const 292int Incidence::revision() const
293{ 293{
294 return mRevision; 294 return mRevision;
295} 295}
296 296
297void Incidence::setDtStart(const QDateTime &dtStart) 297void Incidence::setDtStart(const QDateTime &dtStart)
298{ 298{
299 299
300 QDateTime dt = getEvenTime(dtStart); 300 QDateTime dt = getEvenTime(dtStart);
301 recurrence()->setRecurStart( dt); 301 recurrence()->setRecurStart( dt);
302 IncidenceBase::setDtStart( dt ); 302 IncidenceBase::setDtStart( dt );
303} 303}
304 304
305void Incidence::setDescription(const QString &description) 305void Incidence::setDescription(const QString &description)
306{ 306{
307 if (mReadOnly) return; 307 if (mReadOnly) return;
308 mDescription = description; 308 mDescription = description;
309 updated(); 309 updated();
310} 310}
311 311
312QString Incidence::description() const 312QString Incidence::description() const
313{ 313{
314 return mDescription; 314 return mDescription;
315} 315}
316 316
317 317
318void Incidence::setSummary(const QString &summary) 318void Incidence::setSummary(const QString &summary)
319{ 319{
320 if (mReadOnly) return; 320 if (mReadOnly) return;
321 mSummary = summary; 321 mSummary = summary;
322 updated(); 322 updated();
323} 323}
324 324
325QString Incidence::summary() const 325QString Incidence::summary() const
326{ 326{
327 return mSummary; 327 return mSummary;
328} 328}
329void Incidence::checkCategories() 329void Incidence::checkCategories()
330{ 330{
331 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); 331 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday"));
332 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); 332 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday"));
333 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); 333 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary"));
334} 334}
335 335
336void Incidence::setCategories(const QStringList &categories) 336void Incidence::setCategories(const QStringList &categories)
337{ 337{
338 if (mReadOnly) return; 338 if (mReadOnly) return;
339 mCategories = categories; 339 mCategories = categories;
340 checkCategories(); 340 checkCategories();
341 updated(); 341 updated();
342} 342}
343 343
344// TODO: remove setCategories(QString) function 344// TODO: remove setCategories(QString) function
345void Incidence::setCategories(const QString &catStr) 345void Incidence::setCategories(const QString &catStr)
346{ 346{
347 if (mReadOnly) return; 347 if (mReadOnly) return;
348 mCategories.clear(); 348 mCategories.clear();
349 349
350 if (catStr.isEmpty()) return; 350 if (catStr.isEmpty()) return;
351 351
352 mCategories = QStringList::split(",",catStr); 352 mCategories = QStringList::split(",",catStr);
353 353
354 QStringList::Iterator it; 354 QStringList::Iterator it;
355 for(it = mCategories.begin();it != mCategories.end(); ++it) { 355 for(it = mCategories.begin();it != mCategories.end(); ++it) {
356 *it = (*it).stripWhiteSpace(); 356 *it = (*it).stripWhiteSpace();
357 } 357 }
358 checkCategories(); 358 checkCategories();
359 updated(); 359 updated();
360} 360}
361 361
362QStringList Incidence::categories() const 362QStringList Incidence::categories() const
363{ 363{
364 return mCategories; 364 return mCategories;
365} 365}
366 366
367QString Incidence::categoriesStr() 367QString Incidence::categoriesStr()
368{ 368{
369 return mCategories.join(","); 369 return mCategories.join(",");
370} 370}
371 371
372void Incidence::setRelatedToUid(const QString &relatedToUid) 372void Incidence::setRelatedToUid(const QString &relatedToUid)
373{ 373{
374 if (mReadOnly) return; 374 if (mReadOnly) return;
375 mRelatedToUid = relatedToUid; 375 mRelatedToUid = relatedToUid;
376} 376}
377 377
378QString Incidence::relatedToUid() const 378QString Incidence::relatedToUid() const
379{ 379{
380 return mRelatedToUid; 380 return mRelatedToUid;
381} 381}
382 382
383void Incidence::setRelatedTo(Incidence *relatedTo) 383void Incidence::setRelatedTo(Incidence *relatedTo)
384{ 384{
385 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 385 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
386 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 386 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
387 if (mReadOnly || mRelatedTo == relatedTo) return; 387 if (mReadOnly || mRelatedTo == relatedTo) return;
388 if(mRelatedTo) { 388 if(mRelatedTo) {
389 // updated(); 389 // updated();
390 mRelatedTo->removeRelation(this); 390 mRelatedTo->removeRelation(this);
391 } 391 }
392 mRelatedTo = relatedTo; 392 mRelatedTo = relatedTo;
393 if (mRelatedTo) mRelatedTo->addRelation(this); 393 if (mRelatedTo) {
394 mRelatedTo->addRelation(this);
395 mRelatedToUid = mRelatedTo->uid();
396 } else {
397 mRelatedToUid = "";
398 }
394} 399}
395 400
396Incidence *Incidence::relatedTo() const 401Incidence *Incidence::relatedTo() const
397{ 402{
398 return mRelatedTo; 403 return mRelatedTo;
399} 404}
400 405
401QPtrList<Incidence> Incidence::relations() const 406QPtrList<Incidence> Incidence::relations() const
402{ 407{
403 return mRelations; 408 return mRelations;
404} 409}
405 410
406void Incidence::addRelation(Incidence *event) 411void Incidence::addRelation(Incidence *event)
407{ 412{
408 if( mRelations.findRef( event ) == -1 ) { 413 if( mRelations.findRef( event ) == -1 ) {
409 mRelations.append(event); 414 mRelations.append(event);
410 //updated(); 415 //updated();
411 } 416 }
412} 417}
413 418
414void Incidence::removeRelation(Incidence *event) 419void Incidence::removeRelation(Incidence *event)
415{ 420{
416 421
417 mRelations.removeRef(event); 422 mRelations.removeRef(event);
418 423
419// if (event->getRelatedTo() == this) event->setRelatedTo(0); 424// if (event->getRelatedTo() == this) event->setRelatedTo(0);
420} 425}
421 426
422bool Incidence::recursOn(const QDate &qd) const 427bool Incidence::recursOn(const QDate &qd) const
423{ 428{
424 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; 429 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true;
425 else return false; 430 else return false;
426} 431}
427 432
428void Incidence::setExDates(const DateList &exDates) 433void Incidence::setExDates(const DateList &exDates)
429{ 434{
430 if (mReadOnly) return; 435 if (mReadOnly) return;
431 mExDates = exDates; 436 mExDates = exDates;
432 437
433 recurrence()->setRecurExDatesCount(mExDates.count()); 438 recurrence()->setRecurExDatesCount(mExDates.count());
434 439
435 updated(); 440 updated();
436} 441}
437 442
438void Incidence::addExDate(const QDate &date) 443void Incidence::addExDate(const QDate &date)
439{ 444{
440 if (mReadOnly) return; 445 if (mReadOnly) return;
441 mExDates.append(date); 446 mExDates.append(date);
442 447
443 recurrence()->setRecurExDatesCount(mExDates.count()); 448 recurrence()->setRecurExDatesCount(mExDates.count());
444 449
445 updated(); 450 updated();
446} 451}
447 452
448DateList Incidence::exDates() const 453DateList Incidence::exDates() const
449{ 454{
450 return mExDates; 455 return mExDates;
451} 456}
452 457
453bool Incidence::isException(const QDate &date) const 458bool Incidence::isException(const QDate &date) const
454{ 459{
455 DateList::ConstIterator it; 460 DateList::ConstIterator it;
456 for( it = mExDates.begin(); it != mExDates.end(); ++it ) { 461 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
457 if ( (*it) == date ) { 462 if ( (*it) == date ) {
458 return true; 463 return true;
459 } 464 }
460 } 465 }
461 466
462 return false; 467 return false;
463} 468}
464 469
465void Incidence::addAttachment(Attachment *attachment) 470void Incidence::addAttachment(Attachment *attachment)
466{ 471{
467 if (mReadOnly || !attachment) return; 472 if (mReadOnly || !attachment) return;
468 mAttachments.append(attachment); 473 mAttachments.append(attachment);
469 updated(); 474 updated();
470} 475}
471 476
472void Incidence::deleteAttachment(Attachment *attachment) 477void Incidence::deleteAttachment(Attachment *attachment)
473{ 478{
474 mAttachments.removeRef(attachment); 479 mAttachments.removeRef(attachment);
475} 480}
476 481
477void Incidence::deleteAttachments(const QString& mime) 482void Incidence::deleteAttachments(const QString& mime)
478{ 483{
479 Attachment *at = mAttachments.first(); 484 Attachment *at = mAttachments.first();
480 while (at) { 485 while (at) {
481 if (at->mimeType() == mime) 486 if (at->mimeType() == mime)
482 mAttachments.remove(); 487 mAttachments.remove();
483 else 488 else
484 at = mAttachments.next(); 489 at = mAttachments.next();
485 } 490 }
486} 491}
487 492
488QPtrList<Attachment> Incidence::attachments() const 493QPtrList<Attachment> Incidence::attachments() const
489{ 494{
490 return mAttachments; 495 return mAttachments;
491} 496}
492 497
493QPtrList<Attachment> Incidence::attachments(const QString& mime) const 498QPtrList<Attachment> Incidence::attachments(const QString& mime) const
494{ 499{
495 QPtrList<Attachment> attachments; 500 QPtrList<Attachment> attachments;
496 QPtrListIterator<Attachment> it( mAttachments ); 501 QPtrListIterator<Attachment> it( mAttachments );
497 Attachment *at; 502 Attachment *at;
498 while ( (at = it.current()) ) { 503 while ( (at = it.current()) ) {
499 if (at->mimeType() == mime) 504 if (at->mimeType() == mime)
500 attachments.append(at); 505 attachments.append(at);
501 ++it; 506 ++it;
502 } 507 }
503 508
504 return attachments; 509 return attachments;
505} 510}
506 511
507void Incidence::setResources(const QStringList &resources) 512void Incidence::setResources(const QStringList &resources)
508{ 513{
509 if (mReadOnly) return; 514 if (mReadOnly) return;
510 mResources = resources; 515 mResources = resources;
511 updated(); 516 updated();
512} 517}
513 518
514QStringList Incidence::resources() const 519QStringList Incidence::resources() const
515{ 520{
516 return mResources; 521 return mResources;
517} 522}
518 523
519 524
520void Incidence::setPriority(int priority) 525void Incidence::setPriority(int priority)
521{ 526{
522 if (mReadOnly) return; 527 if (mReadOnly) return;
523 mPriority = priority; 528 mPriority = priority;
524 updated(); 529 updated();
525} 530}
526 531
527int Incidence::priority() const 532int Incidence::priority() const
528{ 533{
529 return mPriority; 534 return mPriority;
530} 535}
531 536
532void Incidence::setSecrecy(int sec) 537void Incidence::setSecrecy(int sec)
533{ 538{
534 if (mReadOnly) return; 539 if (mReadOnly) return;
535 mSecrecy = sec; 540 mSecrecy = sec;
536 updated(); 541 updated();
537} 542}
538 543
539int Incidence::secrecy() const 544int Incidence::secrecy() const
540{ 545{
541 return mSecrecy; 546 return mSecrecy;
542} 547}
543 548
544QString Incidence::secrecyStr() const 549QString Incidence::secrecyStr() const
545{ 550{
546 return secrecyName(mSecrecy); 551 return secrecyName(mSecrecy);
547} 552}
548 553
549QString Incidence::secrecyName(int secrecy) 554QString Incidence::secrecyName(int secrecy)
550{ 555{
551 switch (secrecy) { 556 switch (secrecy) {
552 case SecrecyPublic: 557 case SecrecyPublic:
553 return i18n("Public"); 558 return i18n("Public");
554 break; 559 break;
555 case SecrecyPrivate: 560 case SecrecyPrivate:
556 return i18n("Private"); 561 return i18n("Private");
557 break; 562 break;
558 case SecrecyConfidential: 563 case SecrecyConfidential:
559 return i18n("Confidential"); 564 return i18n("Confidential");
560 break; 565 break;
561 default: 566 default:
562 return i18n("Undefined"); 567 return i18n("Undefined");
563 break; 568 break;
564 } 569 }
565} 570}
566 571
567QStringList Incidence::secrecyList() 572QStringList Incidence::secrecyList()
568{ 573{
569 QStringList list; 574 QStringList list;
570 list << secrecyName(SecrecyPublic); 575 list << secrecyName(SecrecyPublic);
571 list << secrecyName(SecrecyPrivate); 576 list << secrecyName(SecrecyPrivate);
572 list << secrecyName(SecrecyConfidential); 577 list << secrecyName(SecrecyConfidential);
573 578
574 return list; 579 return list;
575} 580}
576 581
577 582
578QPtrList<Alarm> Incidence::alarms() const 583QPtrList<Alarm> Incidence::alarms() const
579{ 584{
580 return mAlarms; 585 return mAlarms;
581} 586}
582 587
583Alarm* Incidence::newAlarm() 588Alarm* Incidence::newAlarm()
584{ 589{
585 Alarm* alarm = new Alarm(this); 590 Alarm* alarm = new Alarm(this);
586 mAlarms.append(alarm); 591 mAlarms.append(alarm);
587// updated(); 592// updated();
588 return alarm; 593 return alarm;
589} 594}
590 595
591void Incidence::addAlarm(Alarm *alarm) 596void Incidence::addAlarm(Alarm *alarm)
592{ 597{
593 mAlarms.append(alarm); 598 mAlarms.append(alarm);
594 updated(); 599 updated();
595} 600}
596 601
597void Incidence::removeAlarm(Alarm *alarm) 602void Incidence::removeAlarm(Alarm *alarm)
598{ 603{
599 mAlarms.removeRef(alarm); 604 mAlarms.removeRef(alarm);
600 updated(); 605 updated();
601} 606}
602 607
603void Incidence::clearAlarms() 608void Incidence::clearAlarms()
604{ 609{
605 mAlarms.clear(); 610 mAlarms.clear();
606 updated(); 611 updated();
607} 612}
608 613
609bool Incidence::isAlarmEnabled() const 614bool Incidence::isAlarmEnabled() const
610{ 615{
611 Alarm* alarm; 616 Alarm* alarm;
612 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 617 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
613 if (alarm->enabled()) 618 if (alarm->enabled())
614 return true; 619 return true;
615 } 620 }
616 return false; 621 return false;
617} 622}
618 623
619Recurrence *Incidence::recurrence() const 624Recurrence *Incidence::recurrence() const
620{ 625{
621 return mRecurrence; 626 return mRecurrence;
622} 627}
623void Incidence::setRecurrence( Recurrence * r) 628void Incidence::setRecurrence( Recurrence * r)
624{ 629{
625 delete mRecurrence; 630 delete mRecurrence;
626 mRecurrence = r; 631 mRecurrence = r;
627} 632}
628 633
629void Incidence::setLocation(const QString &location) 634void Incidence::setLocation(const QString &location)
630{ 635{
631 if (mReadOnly) return; 636 if (mReadOnly) return;
632 mLocation = location; 637 mLocation = location;
633 updated(); 638 updated();
634} 639}
635 640
636QString Incidence::location() const 641QString Incidence::location() const
637{ 642{
638 return mLocation; 643 return mLocation;
639} 644}
640 645
641ushort Incidence::doesRecur() const 646ushort Incidence::doesRecur() const
642{ 647{
643 if ( mRecurrence ) return mRecurrence->doesRecur(); 648 if ( mRecurrence ) return mRecurrence->doesRecur();
644 else return Recurrence::rNone; 649 else return Recurrence::rNone;
645} 650}
646 651
647QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const 652QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const
648{ 653{
649 QDateTime incidenceStart = dt; 654 QDateTime incidenceStart = dt;
650 *ok = false; 655 *ok = false;
651 if ( doesRecur() ) { 656 if ( doesRecur() ) {
652 bool last; 657 bool last;
653 recurrence()->getPreviousDateTime( incidenceStart , &last ); 658 recurrence()->getPreviousDateTime( incidenceStart , &last );
654 int count = 0; 659 int count = 0;
655 if ( !last ) { 660 if ( !last ) {
656 while ( !last ) { 661 while ( !last ) {
657 ++count; 662 ++count;
658 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); 663 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last );
659 if ( recursOn( incidenceStart.date() ) ) { 664 if ( recursOn( incidenceStart.date() ) ) {
660 last = true; // exit while llop 665 last = true; // exit while llop
661 } else { 666 } else {
662 if ( last ) { // no alarm on last recurrence 667 if ( last ) { // no alarm on last recurrence
663 return QDateTime (); 668 return QDateTime ();
664 } 669 }
665 int year = incidenceStart.date().year(); 670 int year = incidenceStart.date().year();
666 // workaround for bug in recurrence 671 // workaround for bug in recurrence
667 if ( count == 100 || year < 1000 || year > 5000 ) { 672 if ( count == 100 || year < 1000 || year > 5000 ) {
668 return QDateTime (); 673 return QDateTime ();
669 } 674 }
670 incidenceStart = incidenceStart.addSecs( 1 ); 675 incidenceStart = incidenceStart.addSecs( 1 );
671 } 676 }
672 } 677 }
673 } else { 678 } else {
674 return QDateTime (); 679 return QDateTime ();
675 } 680 }
676 } else { 681 } else {
677 if ( hasStartDate () ) { 682 if ( hasStartDate () ) {
678 incidenceStart = dtStart(); 683 incidenceStart = dtStart();
679 } 684 }
680 if ( type() =="Todo" ) { 685 if ( type() =="Todo" ) {
681 if ( ((Todo*)this)->hasDueDate() ) 686 if ( ((Todo*)this)->hasDueDate() )
682 incidenceStart = ((Todo*)this)->dtDue(); 687 incidenceStart = ((Todo*)this)->dtDue();
683 } 688 }
684 } 689 }
685 if ( incidenceStart > dt ) 690 if ( incidenceStart > dt )
686 *ok = true; 691 *ok = true;
687 return incidenceStart; 692 return incidenceStart;
688} 693}
689QDateTime Incidence::dtStart() const 694QDateTime Incidence::dtStart() const
690{ 695{
691 if ( doesRecur() ) { 696 if ( doesRecur() ) {
692 if ( type() == "Todo" ) { 697 if ( type() == "Todo" ) {
693 ((Todo*)this)->checkSetCompletedFalse(); 698 ((Todo*)this)->checkSetCompletedFalse();
694 } 699 }
695 } 700 }
696 return mDtStart; 701 return mDtStart;
697} 702}