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