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