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