summaryrefslogtreecommitdiffabout
path: root/libkcal/incidence.cpp
Unidiff
Diffstat (limited to 'libkcal/incidence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidence.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index 6bca12c..78fa24f 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -1,702 +1,714 @@
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 266void Incidence::cloneRelations( Incidence * newInc )
267{
268 // newInc is already a clone of this incidence
269 Incidence * inc;
270 Incidence * cloneInc;
271 QPtrList<Incidence> Relations = relations();
272 for (inc=Relations.first();inc;inc=Relations.next()) {
273 cloneInc = inc->clone();
274 cloneInc->recreate();
275 cloneInc->setRelatedTo( newInc );
276 inc->cloneRelations( cloneInc );
277 }
278}
267void Incidence::setReadOnly( bool readOnly ) 279void Incidence::setReadOnly( bool readOnly )
268{ 280{
269 IncidenceBase::setReadOnly( readOnly ); 281 IncidenceBase::setReadOnly( readOnly );
270 recurrence()->setRecurReadOnly( readOnly); 282 recurrence()->setRecurReadOnly( readOnly);
271} 283}
272 284
273void Incidence::setCreated(QDateTime created) 285void Incidence::setCreated(QDateTime created)
274{ 286{
275 if (mReadOnly) return; 287 if (mReadOnly) return;
276 mCreated = getEvenTime(created); 288 mCreated = getEvenTime(created);
277} 289}
278 290
279QDateTime Incidence::created() const 291QDateTime Incidence::created() const
280{ 292{
281 return mCreated; 293 return mCreated;
282} 294}
283 295
284void Incidence::setRevision(int rev) 296void Incidence::setRevision(int rev)
285{ 297{
286 if (mReadOnly) return; 298 if (mReadOnly) return;
287 mRevision = rev; 299 mRevision = rev;
288 300
289 updated(); 301 updated();
290} 302}
291 303
292int Incidence::revision() const 304int Incidence::revision() const
293{ 305{
294 return mRevision; 306 return mRevision;
295} 307}
296 308
297void Incidence::setDtStart(const QDateTime &dtStart) 309void Incidence::setDtStart(const QDateTime &dtStart)
298{ 310{
299 311
300 QDateTime dt = getEvenTime(dtStart); 312 QDateTime dt = getEvenTime(dtStart);
301 recurrence()->setRecurStart( dt); 313 recurrence()->setRecurStart( dt);
302 IncidenceBase::setDtStart( dt ); 314 IncidenceBase::setDtStart( dt );
303} 315}
304 316
305void Incidence::setDescription(const QString &description) 317void Incidence::setDescription(const QString &description)
306{ 318{
307 if (mReadOnly) return; 319 if (mReadOnly) return;
308 mDescription = description; 320 mDescription = description;
309 updated(); 321 updated();
310} 322}
311 323
312QString Incidence::description() const 324QString Incidence::description() const
313{ 325{
314 return mDescription; 326 return mDescription;
315} 327}
316 328
317 329
318void Incidence::setSummary(const QString &summary) 330void Incidence::setSummary(const QString &summary)
319{ 331{
320 if (mReadOnly) return; 332 if (mReadOnly) return;
321 mSummary = summary; 333 mSummary = summary;
322 updated(); 334 updated();
323} 335}
324 336
325QString Incidence::summary() const 337QString Incidence::summary() const
326{ 338{
327 return mSummary; 339 return mSummary;
328} 340}
329void Incidence::checkCategories() 341void Incidence::checkCategories()
330{ 342{
331 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); 343 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday"));
332 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); 344 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday"));
333 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); 345 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary"));
334} 346}
335 347
336void Incidence::setCategories(const QStringList &categories) 348void Incidence::setCategories(const QStringList &categories)
337{ 349{
338 if (mReadOnly) return; 350 if (mReadOnly) return;
339 mCategories = categories; 351 mCategories = categories;
340 checkCategories(); 352 checkCategories();
341 updated(); 353 updated();
342} 354}
343 355
344// TODO: remove setCategories(QString) function 356// TODO: remove setCategories(QString) function
345void Incidence::setCategories(const QString &catStr) 357void Incidence::setCategories(const QString &catStr)
346{ 358{
347 if (mReadOnly) return; 359 if (mReadOnly) return;
348 mCategories.clear(); 360 mCategories.clear();
349 361
350 if (catStr.isEmpty()) return; 362 if (catStr.isEmpty()) return;
351 363
352 mCategories = QStringList::split(",",catStr); 364 mCategories = QStringList::split(",",catStr);
353 365
354 QStringList::Iterator it; 366 QStringList::Iterator it;
355 for(it = mCategories.begin();it != mCategories.end(); ++it) { 367 for(it = mCategories.begin();it != mCategories.end(); ++it) {
356 *it = (*it).stripWhiteSpace(); 368 *it = (*it).stripWhiteSpace();
357 } 369 }
358 checkCategories(); 370 checkCategories();
359 updated(); 371 updated();
360} 372}
361 373
362QStringList Incidence::categories() const 374QStringList Incidence::categories() const
363{ 375{
364 return mCategories; 376 return mCategories;
365} 377}
366 378
367QString Incidence::categoriesStr() 379QString Incidence::categoriesStr()
368{ 380{
369 return mCategories.join(","); 381 return mCategories.join(",");
370} 382}
371 383
372void Incidence::setRelatedToUid(const QString &relatedToUid) 384void Incidence::setRelatedToUid(const QString &relatedToUid)
373{ 385{
374 if (mReadOnly) return; 386 if (mReadOnly) return;
375 mRelatedToUid = relatedToUid; 387 mRelatedToUid = relatedToUid;
376} 388}
377 389
378QString Incidence::relatedToUid() const 390QString Incidence::relatedToUid() const
379{ 391{
380 return mRelatedToUid; 392 return mRelatedToUid;
381} 393}
382 394
383void Incidence::setRelatedTo(Incidence *relatedTo) 395void Incidence::setRelatedTo(Incidence *relatedTo)
384{ 396{
385 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 397 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
386 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 398 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
387 if (mReadOnly || mRelatedTo == relatedTo) return; 399 if (mReadOnly || mRelatedTo == relatedTo) return;
388 if(mRelatedTo) { 400 if(mRelatedTo) {
389 // updated(); 401 // updated();
390 mRelatedTo->removeRelation(this); 402 mRelatedTo->removeRelation(this);
391 } 403 }
392 mRelatedTo = relatedTo; 404 mRelatedTo = relatedTo;
393 if (mRelatedTo) { 405 if (mRelatedTo) {
394 mRelatedTo->addRelation(this); 406 mRelatedTo->addRelation(this);
395 mRelatedToUid = mRelatedTo->uid(); 407 mRelatedToUid = mRelatedTo->uid();
396 } else { 408 } else {
397 mRelatedToUid = ""; 409 mRelatedToUid = "";
398 } 410 }
399} 411}
400 412
401Incidence *Incidence::relatedTo() const 413Incidence *Incidence::relatedTo() const
402{ 414{
403 return mRelatedTo; 415 return mRelatedTo;
404} 416}
405 417
406QPtrList<Incidence> Incidence::relations() const 418QPtrList<Incidence> Incidence::relations() const
407{ 419{
408 return mRelations; 420 return mRelations;
409} 421}
410 422
411void Incidence::addRelation(Incidence *event) 423void Incidence::addRelation(Incidence *event)
412{ 424{
413 if( mRelations.findRef( event ) == -1 ) { 425 if( mRelations.findRef( event ) == -1 ) {
414 mRelations.append(event); 426 mRelations.append(event);
415 //updated(); 427 //updated();
416 } 428 }
417} 429}
418 430
419void Incidence::removeRelation(Incidence *event) 431void Incidence::removeRelation(Incidence *event)
420{ 432{
421 433
422 mRelations.removeRef(event); 434 mRelations.removeRef(event);
423 435
424// if (event->getRelatedTo() == this) event->setRelatedTo(0); 436// if (event->getRelatedTo() == this) event->setRelatedTo(0);
425} 437}
426 438
427bool Incidence::recursOn(const QDate &qd) const 439bool Incidence::recursOn(const QDate &qd) const
428{ 440{
429 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; 441 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true;
430 else return false; 442 else return false;
431} 443}
432 444
433void Incidence::setExDates(const DateList &exDates) 445void Incidence::setExDates(const DateList &exDates)
434{ 446{
435 if (mReadOnly) return; 447 if (mReadOnly) return;
436 mExDates = exDates; 448 mExDates = exDates;
437 449
438 recurrence()->setRecurExDatesCount(mExDates.count()); 450 recurrence()->setRecurExDatesCount(mExDates.count());
439 451
440 updated(); 452 updated();
441} 453}
442 454
443void Incidence::addExDate(const QDate &date) 455void Incidence::addExDate(const QDate &date)
444{ 456{
445 if (mReadOnly) return; 457 if (mReadOnly) return;
446 mExDates.append(date); 458 mExDates.append(date);
447 459
448 recurrence()->setRecurExDatesCount(mExDates.count()); 460 recurrence()->setRecurExDatesCount(mExDates.count());
449 461
450 updated(); 462 updated();
451} 463}
452 464
453DateList Incidence::exDates() const 465DateList Incidence::exDates() const
454{ 466{
455 return mExDates; 467 return mExDates;
456} 468}
457 469
458bool Incidence::isException(const QDate &date) const 470bool Incidence::isException(const QDate &date) const
459{ 471{
460 DateList::ConstIterator it; 472 DateList::ConstIterator it;
461 for( it = mExDates.begin(); it != mExDates.end(); ++it ) { 473 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
462 if ( (*it) == date ) { 474 if ( (*it) == date ) {
463 return true; 475 return true;
464 } 476 }
465 } 477 }
466 478
467 return false; 479 return false;
468} 480}
469 481
470void Incidence::addAttachment(Attachment *attachment) 482void Incidence::addAttachment(Attachment *attachment)
471{ 483{
472 if (mReadOnly || !attachment) return; 484 if (mReadOnly || !attachment) return;
473 mAttachments.append(attachment); 485 mAttachments.append(attachment);
474 updated(); 486 updated();
475} 487}
476 488
477void Incidence::deleteAttachment(Attachment *attachment) 489void Incidence::deleteAttachment(Attachment *attachment)
478{ 490{
479 mAttachments.removeRef(attachment); 491 mAttachments.removeRef(attachment);
480} 492}
481 493
482void Incidence::deleteAttachments(const QString& mime) 494void Incidence::deleteAttachments(const QString& mime)
483{ 495{
484 Attachment *at = mAttachments.first(); 496 Attachment *at = mAttachments.first();
485 while (at) { 497 while (at) {
486 if (at->mimeType() == mime) 498 if (at->mimeType() == mime)
487 mAttachments.remove(); 499 mAttachments.remove();
488 else 500 else
489 at = mAttachments.next(); 501 at = mAttachments.next();
490 } 502 }
491} 503}
492 504
493QPtrList<Attachment> Incidence::attachments() const 505QPtrList<Attachment> Incidence::attachments() const
494{ 506{
495 return mAttachments; 507 return mAttachments;
496} 508}
497 509
498QPtrList<Attachment> Incidence::attachments(const QString& mime) const 510QPtrList<Attachment> Incidence::attachments(const QString& mime) const
499{ 511{
500 QPtrList<Attachment> attachments; 512 QPtrList<Attachment> attachments;
501 QPtrListIterator<Attachment> it( mAttachments ); 513 QPtrListIterator<Attachment> it( mAttachments );
502 Attachment *at; 514 Attachment *at;
503 while ( (at = it.current()) ) { 515 while ( (at = it.current()) ) {
504 if (at->mimeType() == mime) 516 if (at->mimeType() == mime)
505 attachments.append(at); 517 attachments.append(at);
506 ++it; 518 ++it;
507 } 519 }
508 520
509 return attachments; 521 return attachments;
510} 522}
511 523
512void Incidence::setResources(const QStringList &resources) 524void Incidence::setResources(const QStringList &resources)
513{ 525{
514 if (mReadOnly) return; 526 if (mReadOnly) return;
515 mResources = resources; 527 mResources = resources;
516 updated(); 528 updated();
517} 529}
518 530
519QStringList Incidence::resources() const 531QStringList Incidence::resources() const
520{ 532{
521 return mResources; 533 return mResources;
522} 534}
523 535
524 536
525void Incidence::setPriority(int priority) 537void Incidence::setPriority(int priority)
526{ 538{
527 if (mReadOnly) return; 539 if (mReadOnly) return;
528 mPriority = priority; 540 mPriority = priority;
529 updated(); 541 updated();
530} 542}
531 543
532int Incidence::priority() const 544int Incidence::priority() const
533{ 545{
534 return mPriority; 546 return mPriority;
535} 547}
536 548
537void Incidence::setSecrecy(int sec) 549void Incidence::setSecrecy(int sec)
538{ 550{
539 if (mReadOnly) return; 551 if (mReadOnly) return;
540 mSecrecy = sec; 552 mSecrecy = sec;
541 updated(); 553 updated();
542} 554}
543 555
544int Incidence::secrecy() const 556int Incidence::secrecy() const
545{ 557{
546 return mSecrecy; 558 return mSecrecy;
547} 559}
548 560
549QString Incidence::secrecyStr() const 561QString Incidence::secrecyStr() const
550{ 562{
551 return secrecyName(mSecrecy); 563 return secrecyName(mSecrecy);
552} 564}
553 565
554QString Incidence::secrecyName(int secrecy) 566QString Incidence::secrecyName(int secrecy)
555{ 567{
556 switch (secrecy) { 568 switch (secrecy) {
557 case SecrecyPublic: 569 case SecrecyPublic:
558 return i18n("Public"); 570 return i18n("Public");
559 break; 571 break;
560 case SecrecyPrivate: 572 case SecrecyPrivate:
561 return i18n("Private"); 573 return i18n("Private");
562 break; 574 break;
563 case SecrecyConfidential: 575 case SecrecyConfidential:
564 return i18n("Confidential"); 576 return i18n("Confidential");
565 break; 577 break;
566 default: 578 default:
567 return i18n("Undefined"); 579 return i18n("Undefined");
568 break; 580 break;
569 } 581 }
570} 582}
571 583
572QStringList Incidence::secrecyList() 584QStringList Incidence::secrecyList()
573{ 585{
574 QStringList list; 586 QStringList list;
575 list << secrecyName(SecrecyPublic); 587 list << secrecyName(SecrecyPublic);
576 list << secrecyName(SecrecyPrivate); 588 list << secrecyName(SecrecyPrivate);
577 list << secrecyName(SecrecyConfidential); 589 list << secrecyName(SecrecyConfidential);
578 590
579 return list; 591 return list;
580} 592}
581 593
582 594
583QPtrList<Alarm> Incidence::alarms() const 595QPtrList<Alarm> Incidence::alarms() const
584{ 596{
585 return mAlarms; 597 return mAlarms;
586} 598}
587 599
588Alarm* Incidence::newAlarm() 600Alarm* Incidence::newAlarm()
589{ 601{
590 Alarm* alarm = new Alarm(this); 602 Alarm* alarm = new Alarm(this);
591 mAlarms.append(alarm); 603 mAlarms.append(alarm);
592// updated(); 604// updated();
593 return alarm; 605 return alarm;
594} 606}
595 607
596void Incidence::addAlarm(Alarm *alarm) 608void Incidence::addAlarm(Alarm *alarm)
597{ 609{
598 mAlarms.append(alarm); 610 mAlarms.append(alarm);
599 updated(); 611 updated();
600} 612}
601 613
602void Incidence::removeAlarm(Alarm *alarm) 614void Incidence::removeAlarm(Alarm *alarm)
603{ 615{
604 mAlarms.removeRef(alarm); 616 mAlarms.removeRef(alarm);
605 updated(); 617 updated();
606} 618}
607 619
608void Incidence::clearAlarms() 620void Incidence::clearAlarms()
609{ 621{
610 mAlarms.clear(); 622 mAlarms.clear();
611 updated(); 623 updated();
612} 624}
613 625
614bool Incidence::isAlarmEnabled() const 626bool Incidence::isAlarmEnabled() const
615{ 627{
616 Alarm* alarm; 628 Alarm* alarm;
617 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 629 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
618 if (alarm->enabled()) 630 if (alarm->enabled())
619 return true; 631 return true;
620 } 632 }
621 return false; 633 return false;
622} 634}
623 635
624Recurrence *Incidence::recurrence() const 636Recurrence *Incidence::recurrence() const
625{ 637{
626 return mRecurrence; 638 return mRecurrence;
627} 639}
628void Incidence::setRecurrence( Recurrence * r) 640void Incidence::setRecurrence( Recurrence * r)
629{ 641{
630 delete mRecurrence; 642 delete mRecurrence;
631 mRecurrence = r; 643 mRecurrence = r;
632} 644}
633 645
634void Incidence::setLocation(const QString &location) 646void Incidence::setLocation(const QString &location)
635{ 647{
636 if (mReadOnly) return; 648 if (mReadOnly) return;
637 mLocation = location; 649 mLocation = location;
638 updated(); 650 updated();
639} 651}
640 652
641QString Incidence::location() const 653QString Incidence::location() const
642{ 654{
643 return mLocation; 655 return mLocation;
644} 656}
645 657
646ushort Incidence::doesRecur() const 658ushort Incidence::doesRecur() const
647{ 659{
648 if ( mRecurrence ) return mRecurrence->doesRecur(); 660 if ( mRecurrence ) return mRecurrence->doesRecur();
649 else return Recurrence::rNone; 661 else return Recurrence::rNone;
650} 662}
651 663
652QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const 664QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const
653{ 665{
654 QDateTime incidenceStart = dt; 666 QDateTime incidenceStart = dt;
655 *ok = false; 667 *ok = false;
656 if ( doesRecur() ) { 668 if ( doesRecur() ) {
657 bool last; 669 bool last;
658 recurrence()->getPreviousDateTime( incidenceStart , &last ); 670 recurrence()->getPreviousDateTime( incidenceStart , &last );
659 int count = 0; 671 int count = 0;
660 if ( !last ) { 672 if ( !last ) {
661 while ( !last ) { 673 while ( !last ) {
662 ++count; 674 ++count;
663 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); 675 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last );
664 if ( recursOn( incidenceStart.date() ) ) { 676 if ( recursOn( incidenceStart.date() ) ) {
665 last = true; // exit while llop 677 last = true; // exit while llop
666 } else { 678 } else {
667 if ( last ) { // no alarm on last recurrence 679 if ( last ) { // no alarm on last recurrence
668 return QDateTime (); 680 return QDateTime ();
669 } 681 }
670 int year = incidenceStart.date().year(); 682 int year = incidenceStart.date().year();
671 // workaround for bug in recurrence 683 // workaround for bug in recurrence
672 if ( count == 100 || year < 1000 || year > 5000 ) { 684 if ( count == 100 || year < 1000 || year > 5000 ) {
673 return QDateTime (); 685 return QDateTime ();
674 } 686 }
675 incidenceStart = incidenceStart.addSecs( 1 ); 687 incidenceStart = incidenceStart.addSecs( 1 );
676 } 688 }
677 } 689 }
678 } else { 690 } else {
679 return QDateTime (); 691 return QDateTime ();
680 } 692 }
681 } else { 693 } else {
682 if ( hasStartDate () ) { 694 if ( hasStartDate () ) {
683 incidenceStart = dtStart(); 695 incidenceStart = dtStart();
684 } 696 }
685 if ( type() =="Todo" ) { 697 if ( type() =="Todo" ) {
686 if ( ((Todo*)this)->hasDueDate() ) 698 if ( ((Todo*)this)->hasDueDate() )
687 incidenceStart = ((Todo*)this)->dtDue(); 699 incidenceStart = ((Todo*)this)->dtDue();
688 } 700 }
689 } 701 }
690 if ( incidenceStart > dt ) 702 if ( incidenceStart > dt )
691 *ok = true; 703 *ok = true;
692 return incidenceStart; 704 return incidenceStart;
693} 705}
694QDateTime Incidence::dtStart() const 706QDateTime Incidence::dtStart() const
695{ 707{
696 if ( doesRecur() ) { 708 if ( doesRecur() ) {
697 if ( type() == "Todo" ) { 709 if ( type() == "Todo" ) {
698 ((Todo*)this)->checkSetCompletedFalse(); 710 ((Todo*)this)->checkSetCompletedFalse();
699 } 711 }
700 } 712 }
701 return mDtStart; 713 return mDtStart;
702} 714}