summaryrefslogtreecommitdiffabout
path: root/libkcal/incidence.cpp
Unidiff
Diffstat (limited to 'libkcal/incidence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidence.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index 549014e..39c14f5 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -1,845 +1,853 @@
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 = 0;//new Recurrence(this); 36 mRecurrence = 0;//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 QPtrListIterator<Attachment> itat( i.mAttachments );
63 Attachment *at;
64 while( (at = itat.current()) ) {
65 Attachment *a = new Attachment( *at );
66 mAttachments.append( a );
67 ++itat;
68 }
69 mAttachments.setAutoDelete( true );
63 mResources = i.mResources; 70 mResources = i.mResources;
64 mSecrecy = i.mSecrecy; 71 mSecrecy = i.mSecrecy;
65 mPriority = i.mPriority; 72 mPriority = i.mPriority;
66 mLocation = i.mLocation; 73 mLocation = i.mLocation;
67 mCancelled = i.mCancelled; 74 mCancelled = i.mCancelled;
68 mHasStartDate = i.mHasStartDate; 75 mHasStartDate = i.mHasStartDate;
69 QPtrListIterator<Alarm> it( i.mAlarms ); 76 QPtrListIterator<Alarm> it( i.mAlarms );
70 const Alarm *a; 77 const Alarm *a;
71 while( (a = it.current()) ) { 78 while( (a = it.current()) ) {
72 Alarm *b = new Alarm( *a ); 79 Alarm *b = new Alarm( *a );
73 b->setParent( this ); 80 b->setParent( this );
74 mAlarms.append( b ); 81 mAlarms.append( b );
75 82
76 ++it; 83 ++it;
77 } 84 }
78 mAlarms.setAutoDelete(true); 85 mAlarms.setAutoDelete(true);
79 mHasRecurrenceID = i.mHasRecurrenceID; 86 mHasRecurrenceID = i.mHasRecurrenceID;
80 mRecurrenceID = i.mRecurrenceID; 87 mRecurrenceID = i.mRecurrenceID;
81 if ( i.mRecurrence ) 88 if ( i.mRecurrence )
82 mRecurrence = new Recurrence( *(i.mRecurrence), this ); 89 mRecurrence = new Recurrence( *(i.mRecurrence), this );
83 else 90 else
84 mRecurrence = 0; 91 mRecurrence = 0;
85 mHoliday = i.mHoliday ; 92 mHoliday = i.mHoliday ;
86 mBirthday = i.mBirthday; 93 mBirthday = i.mBirthday;
87 mAnniversary = i.mAnniversary; 94 mAnniversary = i.mAnniversary;
88} 95}
89 96
90Incidence::~Incidence() 97Incidence::~Incidence()
91{ 98{
92 99
93 Incidence *ev; 100 Incidence *ev;
94 QPtrList<Incidence> Relations = relations(); 101 QPtrList<Incidence> Relations = relations();
95 for (ev=Relations.first();ev;ev=Relations.next()) { 102 for (ev=Relations.first();ev;ev=Relations.next()) {
96 if (ev->relatedTo() == this) ev->setRelatedTo(0); 103 if (ev->relatedTo() == this) ev->setRelatedTo(0);
97 } 104 }
98 if (relatedTo()) relatedTo()->removeRelation(this); 105 if (relatedTo()) relatedTo()->removeRelation(this);
99 if ( mRecurrence ) 106 if ( mRecurrence )
100 delete mRecurrence; 107 delete mRecurrence;
101 108
102} 109}
103QString Incidence::durationText() 110QString Incidence::durationText()
104{ 111{
105 return "---"; 112 return "---";
106} 113}
107QString Incidence::durationText4Time( int offset ) 114QString Incidence::durationText4Time( int offset )
108{ 115{
109 int min = offset/60; 116 int min = offset/60;
110 int hours = min /60; 117 int hours = min /60;
111 min = min % 60; 118 min = min % 60;
112 int days = hours /24; 119 int days = hours /24;
113 hours = hours % 24; 120 hours = hours % 24;
114 121
115 if ( doesFloat() || ( min == 0 && hours == 0 ) ) { 122 if ( doesFloat() || ( min == 0 && hours == 0 ) ) {
116 if ( days == 1 ) 123 if ( days == 1 )
117 return "1" + i18n(" day"); 124 return "1" + i18n(" day");
118 else 125 else
119 return QString::number( days )+ i18n(" days"); 126 return QString::number( days )+ i18n(" days");
120 127
121 } 128 }
122 QString message = QString::number ( hours ) +":"; 129 QString message = QString::number ( hours ) +":";
123 if ( min < 10 ) message += "0"; 130 if ( min < 10 ) message += "0";
124 message += QString::number ( min ); 131 message += QString::number ( min );
125 if ( days > 0 ) { 132 if ( days > 0 ) {
126 if ( days == 1 ) 133 if ( days == 1 )
127 message = "1" + i18n(" day") + " "+message; 134 message = "1" + i18n(" day") + " "+message;
128 else 135 else
129 message = QString::number( days )+ i18n(" days") + " "+message; 136 message = QString::number( days )+ i18n(" days") + " "+message;
130 } 137 }
131 return message; 138 return message;
132} 139}
133bool Incidence::isHoliday() const 140bool Incidence::isHoliday() const
134{ 141{
135 return mHoliday; 142 return mHoliday;
136} 143}
137bool Incidence::isBirthday() const 144bool Incidence::isBirthday() const
138{ 145{
139 146
140 return mBirthday ; 147 return mBirthday ;
141} 148}
142bool Incidence::isAnniversary() const 149bool Incidence::isAnniversary() const
143{ 150{
144 return mAnniversary ; 151 return mAnniversary ;
145 152
146} 153}
147 154
148bool Incidence::hasRecurrenceID() const 155bool Incidence::hasRecurrenceID() const
149{ 156{
150 return mHasRecurrenceID; 157 return mHasRecurrenceID;
151} 158}
152 159
153void Incidence::setHasRecurrenceID( bool b ) 160void Incidence::setHasRecurrenceID( bool b )
154{ 161{
155 mHasRecurrenceID = b; 162 mHasRecurrenceID = b;
156} 163}
157 164
158void Incidence::setRecurrenceID(QDateTime d) 165void Incidence::setRecurrenceID(QDateTime d)
159{ 166{
160 mRecurrenceID = d; 167 mRecurrenceID = d;
161 mHasRecurrenceID = true; 168 mHasRecurrenceID = true;
162 updated(); 169 updated();
163} 170}
164QDateTime Incidence::recurrenceID () const 171QDateTime Incidence::recurrenceID () const
165{ 172{
166 return mRecurrenceID; 173 return mRecurrenceID;
167} 174}
168 175
169bool Incidence::cancelled() const 176bool Incidence::cancelled() const
170{ 177{
171 return mCancelled; 178 return mCancelled;
172} 179}
173void Incidence::setCancelled( bool b ) 180void Incidence::setCancelled( bool b )
174{ 181{
175 mCancelled = b; 182 mCancelled = b;
176 updated(); 183 updated();
177} 184}
178bool Incidence::hasStartDate() const 185bool Incidence::hasStartDate() const
179{ 186{
180 return mHasStartDate; 187 return mHasStartDate;
181} 188}
182 189
183void Incidence::setHasStartDate(bool f) 190void Incidence::setHasStartDate(bool f)
184{ 191{
185 if (mReadOnly) return; 192 if (mReadOnly) return;
186 mHasStartDate = f; 193 mHasStartDate = f;
187 updated(); 194 updated();
188} 195}
189 196
190// A string comparison that considers that null and empty are the same 197// A string comparison that considers that null and empty are the same
191static bool stringCompare( const QString& s1, const QString& s2 ) 198static bool stringCompare( const QString& s1, const QString& s2 )
192{ 199{
193 if ( s1.isEmpty() && s2.isEmpty() ) 200 if ( s1.isEmpty() && s2.isEmpty() )
194 return true; 201 return true;
195 return s1 == s2; 202 return s1 == s2;
196} 203}
197 204
198bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 205bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
199{ 206{
200 207
201 if( i1.alarms().count() != i2.alarms().count() ) { 208 if( i1.alarms().count() != i2.alarms().count() ) {
202 return false; // no need to check further 209 return false; // no need to check further
203 } 210 }
204 if ( i1.alarms().count() > 0 ) { 211 if ( i1.alarms().count() > 0 ) {
205 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) 212 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) )
206 { 213 {
207 qDebug("alarm not equal "); 214 qDebug("alarm not equal ");
208 return false; 215 return false;
209 } 216 }
210 } 217 }
211#if 0 218#if 0
212 QPtrListIterator<Alarm> a1( i1.alarms() ); 219 QPtrListIterator<Alarm> a1( i1.alarms() );
213 QPtrListIterator<Alarm> a2( i2.alarms() ); 220 QPtrListIterator<Alarm> a2( i2.alarms() );
214 for( ; a1.current() && a2.current(); ++a1, ++a2 ) { 221 for( ; a1.current() && a2.current(); ++a1, ++a2 ) {
215 if( *a1.current() == *a2.current() ) { 222 if( *a1.current() == *a2.current() ) {
216 continue; 223 continue;
217 } 224 }
218 else { 225 else {
219 return false; 226 return false;
220 } 227 }
221 } 228 }
222#endif 229#endif
223 230
224 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { 231 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) {
225 if ( i1.hasRecurrenceID() ) { 232 if ( i1.hasRecurrenceID() ) {
226 if ( i1.recurrenceID() != i2.recurrenceID() ) 233 if ( i1.recurrenceID() != i2.recurrenceID() )
227 return false; 234 return false;
228 } 235 }
229 236
230 } else { 237 } else {
231 return false; 238 return false;
232 } 239 }
233 240
234 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) 241 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) )
235 return false; 242 return false;
236 if ( i1.hasStartDate() == i2.hasStartDate() ) { 243 if ( i1.hasStartDate() == i2.hasStartDate() ) {
237 if ( i1.hasStartDate() ) { 244 if ( i1.hasStartDate() ) {
238 if ( i1.dtStart() != i2.dtStart() ) 245 if ( i1.dtStart() != i2.dtStart() )
239 return false; 246 return false;
240 } 247 }
241 } else { 248 } else {
242 return false; 249 return false;
243 } 250 }
244 if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { 251 if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) {
245 if (!( *i1.mRecurrence == *i2.mRecurrence) ) { 252 if (!( *i1.mRecurrence == *i2.mRecurrence) ) {
246 //qDebug("recurrence is NOT equal "); 253 //qDebug("recurrence is NOT equal ");
247 return false; 254 return false;
248 } 255 }
249 } else { 256 } else {
250 // one ( or both ) recurrence is 0 257 // one ( or both ) recurrence is 0
251 if ( i1.mRecurrence == 0 ) { 258 if ( i1.mRecurrence == 0 ) {
252 if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) 259 if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone )
253 return false; 260 return false;
254 } else { 261 } else {
255 // i1.mRecurrence != 0 262 // i1.mRecurrence != 0
256 // i2.mRecurrence == 0 263 // i2.mRecurrence == 0
257 if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) 264 if ( i1.mRecurrence->doesRecur() != Recurrence::rNone )
258 return false; 265 return false;
259 } 266 }
260 } 267 }
261 268
262 return 269 return
263 // i1.created() == i2.created() && 270 // i1.created() == i2.created() &&
264 stringCompare( i1.description(), i2.description() ) && 271 stringCompare( i1.description(), i2.description() ) &&
265 stringCompare( i1.summary(), i2.summary() ) && 272 stringCompare( i1.summary(), i2.summary() ) &&
266 i1.categories() == i2.categories() && 273 i1.categories() == i2.categories() &&
267 // no need to compare mRelatedTo 274 // no need to compare mRelatedTo
268 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && 275 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) &&
269 // i1.relations() == i2.relations() && 276 // i1.relations() == i2.relations() &&
270 i1.exDates() == i2.exDates() && 277 i1.exDates() == i2.exDates() &&
271 i1.attachments() == i2.attachments() && 278 i1.attachments() == i2.attachments() &&
272 i1.resources() == i2.resources() && 279 i1.resources() == i2.resources() &&
273 i1.secrecy() == i2.secrecy() && 280 i1.secrecy() == i2.secrecy() &&
274 i1.priority() == i2.priority() && 281 i1.priority() == i2.priority() &&
275 i1.cancelled() == i2.cancelled() && 282 i1.cancelled() == i2.cancelled() &&
276 stringCompare( i1.location(), i2.location() ); 283 stringCompare( i1.location(), i2.location() );
277} 284}
278 285
279Incidence* Incidence::recreateCloneException( QDate d ) 286Incidence* Incidence::recreateCloneException( QDate d )
280{ 287{
281 Incidence* newInc = clone(); 288 Incidence* newInc = clone();
282 newInc->recreate(); 289 newInc->recreate();
283 if ( doesRecur() ) { 290 if ( doesRecur() ) {
284 addExDate( d ); 291 addExDate( d );
285 newInc->recurrence()->unsetRecurs(); 292 newInc->recurrence()->unsetRecurs();
286 if ( typeID() == eventID ) { 293 if ( typeID() == eventID ) {
287 int len = dtStart().secsTo( ((Event*)this)->dtEnd()); 294 int len = dtStart().secsTo( ((Event*)this)->dtEnd());
288 QTime tim = dtStart().time(); 295 QTime tim = dtStart().time();
289 newInc->setDtStart( QDateTime(d, tim) ); 296 newInc->setDtStart( QDateTime(d, tim) );
290 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 297 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
291 } else { 298 } else {
292 int len = dtStart().secsTo( ((Todo*)this)->dtDue()); 299 int len = dtStart().secsTo( ((Todo*)this)->dtDue());
293 QTime tim = ((Todo*)this)->dtDue().time(); 300 QTime tim = ((Todo*)this)->dtDue().time();
294 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); 301 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) );
295 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); 302 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) );
296 ((Todo*)this)->setRecurDates(); 303 ((Todo*)this)->setRecurDates();
297 } 304 }
298 newInc->setExDates( DateList () ); 305 newInc->setExDates( DateList () );
299 } 306 }
300 return newInc; 307 return newInc;
301} 308}
302 309
303void Incidence::recreate() 310void Incidence::recreate()
304{ 311{
305 setCreated(QDateTime::currentDateTime()); 312 setCreated(QDateTime::currentDateTime());
306 313
307 setUid(CalFormat::createUniqueId()); 314 setUid(CalFormat::createUniqueId());
308 315
309 setRevision(0); 316 setRevision(0);
310 setIDStr( ":" ); 317 setIDStr( ":" );
311 setLastModified(QDateTime::currentDateTime()); 318 setLastModified(QDateTime::currentDateTime());
312} 319}
313void Incidence::cloneRelations( Incidence * newInc ) 320void Incidence::cloneRelations( Incidence * newInc )
314{ 321{
315 // newInc is already a clone of this incidence 322 // newInc is already a clone of this incidence
316 Incidence * inc; 323 Incidence * inc;
317 Incidence * cloneInc; 324 Incidence * cloneInc;
318 QPtrList<Incidence> Relations = relations(); 325 QPtrList<Incidence> Relations = relations();
319 for (inc=Relations.first();inc;inc=Relations.next()) { 326 for (inc=Relations.first();inc;inc=Relations.next()) {
320 cloneInc = inc->clone(); 327 cloneInc = inc->clone();
321 cloneInc->recreate(); 328 cloneInc->recreate();
322 cloneInc->setRelatedTo( newInc ); 329 cloneInc->setRelatedTo( newInc );
323 inc->cloneRelations( cloneInc ); 330 inc->cloneRelations( cloneInc );
324 } 331 }
325} 332}
326void Incidence::setReadOnly( bool readOnly ) 333void Incidence::setReadOnly( bool readOnly )
327{ 334{
328 IncidenceBase::setReadOnly( readOnly ); 335 IncidenceBase::setReadOnly( readOnly );
329 if ( mRecurrence ) 336 if ( mRecurrence )
330 mRecurrence->setRecurReadOnly( readOnly); 337 mRecurrence->setRecurReadOnly( readOnly);
331} 338}
332void Incidence::setLastModifiedSubInvalid() 339void Incidence::setLastModifiedSubInvalid()
333{ 340{
334 mLastModifiedSub = QDateTime(); 341 mLastModifiedSub = QDateTime();
335 if ( mRelatedTo ) 342 if ( mRelatedTo )
336 mRelatedTo->setLastModifiedSubInvalid(); 343 mRelatedTo->setLastModifiedSubInvalid();
337} 344}
338QDateTime Incidence::lastModifiedSub() 345QDateTime Incidence::lastModifiedSub()
339{ 346{
340 if ( !mRelations.count() ) 347 if ( !mRelations.count() )
341 return lastModified(); 348 return lastModified();
342 if ( mLastModifiedSub.isValid() ) 349 if ( mLastModifiedSub.isValid() )
343 return mLastModifiedSub; 350 return mLastModifiedSub;
344 mLastModifiedSub = lastModified(); 351 mLastModifiedSub = lastModified();
345 Incidence * inc; 352 Incidence * inc;
346 QPtrList<Incidence> Relations = relations(); 353 QPtrList<Incidence> Relations = relations();
347 for (inc=Relations.first();inc;inc=Relations.next()) { 354 for (inc=Relations.first();inc;inc=Relations.next()) {
348 if ( inc->lastModifiedSub() > mLastModifiedSub ) 355 if ( inc->lastModifiedSub() > mLastModifiedSub )
349 mLastModifiedSub = inc->lastModifiedSub(); 356 mLastModifiedSub = inc->lastModifiedSub();
350 } 357 }
351 return mLastModifiedSub; 358 return mLastModifiedSub;
352} 359}
353void Incidence::setCreated(QDateTime created) 360void Incidence::setCreated(QDateTime created)
354{ 361{
355 if (mReadOnly) return; 362 if (mReadOnly) return;
356 mCreated = getEvenTime(created); 363 mCreated = getEvenTime(created);
357} 364}
358 365
359QDateTime Incidence::created() const 366QDateTime Incidence::created() const
360{ 367{
361 return mCreated; 368 return mCreated;
362} 369}
363 370
364void Incidence::setRevision(int rev) 371void Incidence::setRevision(int rev)
365{ 372{
366 if (mReadOnly) return; 373 if (mReadOnly) return;
367 mRevision = rev; 374 mRevision = rev;
368 375
369 updated(); 376 updated();
370} 377}
371 378
372int Incidence::revision() const 379int Incidence::revision() const
373{ 380{
374 return mRevision; 381 return mRevision;
375} 382}
376 383
377void Incidence::setDtStart(const QDateTime &dtStart) 384void Incidence::setDtStart(const QDateTime &dtStart)
378{ 385{
379 386
380 QDateTime dt = getEvenTime(dtStart); 387 QDateTime dt = getEvenTime(dtStart);
381 388
382 if ( mRecurrence ) 389 if ( mRecurrence )
383 mRecurrence->setRecurStart( dt); 390 mRecurrence->setRecurStart( dt);
384 IncidenceBase::setDtStart( dt ); 391 IncidenceBase::setDtStart( dt );
385} 392}
386 393
387void Incidence::setDescription(const QString &description) 394void Incidence::setDescription(const QString &description)
388{ 395{
389 if (mReadOnly) return; 396 if (mReadOnly) return;
390 mDescription = description; 397 mDescription = description;
391 updated(); 398 updated();
392} 399}
393 400
394QString Incidence::description() const 401QString Incidence::description() const
395{ 402{
396 return mDescription; 403 return mDescription;
397} 404}
398 405
399 406
400void Incidence::setSummary(const QString &summary) 407void Incidence::setSummary(const QString &summary)
401{ 408{
402 if (mReadOnly) return; 409 if (mReadOnly) return;
403 mSummary = summary; 410 mSummary = summary;
404 updated(); 411 updated();
405} 412}
406 413
407QString Incidence::summary() const 414QString Incidence::summary() const
408{ 415{
409 return mSummary; 416 return mSummary;
410} 417}
411void Incidence::checkCategories() 418void Incidence::checkCategories()
412{ 419{
413 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); 420 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday"));
414 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); 421 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday"));
415 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); 422 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary"));
416} 423}
417 424
418void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false 425void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false
419{ 426{
420 if (mReadOnly) return; 427 if (mReadOnly) return;
421 int i; 428 int i;
422 for( i = 0; i < categories.count(); ++i ) { 429 for( i = 0; i < categories.count(); ++i ) {
423 if ( !mCategories.contains (categories[i])) 430 if ( !mCategories.contains (categories[i]))
424 mCategories.append( categories[i] ); 431 mCategories.append( categories[i] );
425 } 432 }
426 checkCategories(); 433 checkCategories();
427 updated(); 434 updated();
428 if ( addToRelations ) { 435 if ( addToRelations ) {
429 Incidence * inc; 436 Incidence * inc;
430 QPtrList<Incidence> Relations = relations(); 437 QPtrList<Incidence> Relations = relations();
431 for (inc=Relations.first();inc;inc=Relations.next()) { 438 for (inc=Relations.first();inc;inc=Relations.next()) {
432 inc->addCategories( categories, true ); 439 inc->addCategories( categories, true );
433 } 440 }
434 } 441 }
435} 442}
436 443
437void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false 444void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false
438{ 445{
439 if (mReadOnly) return; 446 if (mReadOnly) return;
440 mCategories = categories; 447 mCategories = categories;
441 checkCategories(); 448 checkCategories();
442 updated(); 449 updated();
443 if ( setForRelations ) { 450 if ( setForRelations ) {
444 Incidence * inc; 451 Incidence * inc;
445 QPtrList<Incidence> Relations = relations(); 452 QPtrList<Incidence> Relations = relations();
446 for (inc=Relations.first();inc;inc=Relations.next()) { 453 for (inc=Relations.first();inc;inc=Relations.next()) {
447 inc->setCategories( categories, true ); 454 inc->setCategories( categories, true );
448 } 455 }
449 } 456 }
450} 457}
451 458
452// TODO: remove setCategories(QString) function 459// TODO: remove setCategories(QString) function
453void Incidence::setCategories(const QString &catStr) 460void Incidence::setCategories(const QString &catStr)
454{ 461{
455 if (mReadOnly) return; 462 if (mReadOnly) return;
456 mCategories.clear(); 463 mCategories.clear();
457 464
458 if (catStr.isEmpty()) return; 465 if (catStr.isEmpty()) return;
459 466
460 mCategories = QStringList::split(",",catStr); 467 mCategories = QStringList::split(",",catStr);
461 468
462 QStringList::Iterator it; 469 QStringList::Iterator it;
463 for(it = mCategories.begin();it != mCategories.end(); ++it) { 470 for(it = mCategories.begin();it != mCategories.end(); ++it) {
464 *it = (*it).stripWhiteSpace(); 471 *it = (*it).stripWhiteSpace();
465 } 472 }
466 checkCategories(); 473 checkCategories();
467 updated(); 474 updated();
468} 475}
469// using this makes filtering 3 times faster 476// using this makes filtering 3 times faster
470QStringList* Incidence::categoriesP() 477QStringList* Incidence::categoriesP()
471{ 478{
472 return &mCategories; 479 return &mCategories;
473} 480}
474 481
475QStringList Incidence::categories() const 482QStringList Incidence::categories() const
476{ 483{
477 return mCategories; 484 return mCategories;
478} 485}
479 486
480QString Incidence::categoriesStr() 487QString Incidence::categoriesStr()
481{ 488{
482 return mCategories.join(","); 489 return mCategories.join(",");
483} 490}
484QString Incidence::categoriesStrWithSpace() 491QString Incidence::categoriesStrWithSpace()
485{ 492{
486 return mCategories.join(", "); 493 return mCategories.join(", ");
487} 494}
488 495
489void Incidence::setRelatedToUid(const QString &relatedToUid) 496void Incidence::setRelatedToUid(const QString &relatedToUid)
490{ 497{
491 if (mReadOnly) return; 498 if (mReadOnly) return;
492 mRelatedToUid = relatedToUid; 499 mRelatedToUid = relatedToUid;
493} 500}
494void Incidence::clearRelations() 501void Incidence::clearRelations()
495{ 502{
496 mRelatedTo = 0; 503 mRelatedTo = 0;
497 mRelations.clear(); 504 mRelations.clear();
498} 505}
499QString Incidence::relatedToUid() const 506QString Incidence::relatedToUid() const
500{ 507{
501 return mRelatedToUid; 508 return mRelatedToUid;
502} 509}
503 510
504void Incidence::setRelatedTo(Incidence *relatedTo) 511void Incidence::setRelatedTo(Incidence *relatedTo)
505{ 512{
506 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 513 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
507 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 514 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
508 if (mReadOnly || mRelatedTo == relatedTo) return; 515 if (mReadOnly || mRelatedTo == relatedTo) return;
509 if(mRelatedTo) { 516 if(mRelatedTo) {
510 // updated(); 517 // updated();
511 mRelatedTo->removeRelation(this); 518 mRelatedTo->removeRelation(this);
512 } 519 }
513 mRelatedTo = relatedTo; 520 mRelatedTo = relatedTo;
514 if (mRelatedTo) { 521 if (mRelatedTo) {
515 mRelatedTo->addRelation(this); 522 mRelatedTo->addRelation(this);
516 mRelatedToUid = mRelatedTo->uid(); 523 mRelatedToUid = mRelatedTo->uid();
517 } else { 524 } else {
518 mRelatedToUid = ""; 525 mRelatedToUid = "";
519 } 526 }
520} 527}
521 528
522Incidence *Incidence::relatedTo() const 529Incidence *Incidence::relatedTo() const
523{ 530{
524 return mRelatedTo; 531 return mRelatedTo;
525} 532}
526 533
527QPtrList<Incidence> Incidence::relations() const 534QPtrList<Incidence> Incidence::relations() const
528{ 535{
529 return mRelations; 536 return mRelations;
530} 537}
531 538
532void Incidence::addRelationsToList(QPtrList<Incidence> *rel) 539void Incidence::addRelationsToList(QPtrList<Incidence> *rel)
533{ 540{
534 Incidence* inc; 541 Incidence* inc;
535 QPtrList<Incidence> Relations = relations(); 542 QPtrList<Incidence> Relations = relations();
536 for (inc=Relations.first();inc;inc=Relations.next()) { 543 for (inc=Relations.first();inc;inc=Relations.next()) {
537 inc->addRelationsToList( rel ); 544 inc->addRelationsToList( rel );
538 } 545 }
539 if ( rel->findRef( this ) == -1 ) 546 if ( rel->findRef( this ) == -1 )
540 rel->append( this ); 547 rel->append( this );
541} 548}
542 549
543void Incidence::addRelation(Incidence *event) 550void Incidence::addRelation(Incidence *event)
544{ 551{
545 setLastModifiedSubInvalid(); 552 setLastModifiedSubInvalid();
546 if( mRelations.findRef( event ) == -1 ) { 553 if( mRelations.findRef( event ) == -1 ) {
547 mRelations.append(event); 554 mRelations.append(event);
548 //updated(); 555 //updated();
549 } 556 }
550} 557}
551 558
552void Incidence::removeRelation(Incidence *event) 559void Incidence::removeRelation(Incidence *event)
553{ 560{
554 setLastModifiedSubInvalid(); 561 setLastModifiedSubInvalid();
555 mRelations.removeRef(event); 562 mRelations.removeRef(event);
556// if (event->getRelatedTo() == this) event->setRelatedTo(0); 563// if (event->getRelatedTo() == this) event->setRelatedTo(0);
557} 564}
558 565
559bool Incidence::recursOn(const QDate &qd) const 566bool Incidence::recursOn(const QDate &qd) const
560{ 567{
561 if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true; 568 if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true;
562 else return false; 569 else return false;
563} 570}
564 571
565void Incidence::setExDates(const DateList &exDates) 572void Incidence::setExDates(const DateList &exDates)
566{ 573{
567 if (mReadOnly) return; 574 if (mReadOnly) return;
568 mExDates = exDates; 575 mExDates = exDates;
569 recurrence()->setRecurExDatesCount(mExDates.count()); 576 recurrence()->setRecurExDatesCount(mExDates.count());
570 577
571 updated(); 578 updated();
572} 579}
573 580
574void Incidence::addExDate(const QDate &date) 581void Incidence::addExDate(const QDate &date)
575{ 582{
576 if (mReadOnly) return; 583 if (mReadOnly) return;
577 mExDates.append(date); 584 mExDates.append(date);
578 585
579 recurrence()->setRecurExDatesCount(mExDates.count()); 586 recurrence()->setRecurExDatesCount(mExDates.count());
580 587
581 updated(); 588 updated();
582} 589}
583 590
584DateList Incidence::exDates() const 591DateList Incidence::exDates() const
585{ 592{
586 return mExDates; 593 return mExDates;
587} 594}
588 595
589bool Incidence::isException(const QDate &date) const 596bool Incidence::isException(const QDate &date) const
590{ 597{
591 DateList::ConstIterator it; 598 DateList::ConstIterator it;
592 for( it = mExDates.begin(); it != mExDates.end(); ++it ) { 599 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
593 if ( (*it) == date ) { 600 if ( (*it) == date ) {
594 return true; 601 return true;
595 } 602 }
596 } 603 }
597 604
598 return false; 605 return false;
599} 606}
600 607
601void Incidence::addAttachment(Attachment *attachment) 608void Incidence::addAttachment(Attachment *attachment)
602{ 609{
603 if (mReadOnly || !attachment) return; 610 if (mReadOnly || !attachment) return;
604 mAttachments.append(attachment); 611 mAttachments.append(attachment);
605 updated(); 612 updated();
606} 613}
607 614
608void Incidence::deleteAttachment(Attachment *attachment) 615void Incidence::deleteAttachment(Attachment *attachment)
609{ 616{
610 mAttachments.removeRef(attachment); 617 mAttachments.removeRef(attachment);
611} 618}
612 619
613void Incidence::deleteAttachments(const QString& mime) 620void Incidence::deleteAttachments(const QString& mime)
614{ 621{
615 Attachment *at = mAttachments.first(); 622 Attachment *at = mAttachments.first();
616 while (at) { 623 while (at) {
617 if (at->mimeType() == mime) 624 if (at->mimeType() == mime)
618 mAttachments.remove(); 625 mAttachments.remove();
619 else 626 else
620 at = mAttachments.next(); 627 at = mAttachments.next();
621 } 628 }
622} 629}
623 630
624QPtrList<Attachment> Incidence::attachments() const 631QPtrList<Attachment> Incidence::attachments() const
625{ 632{
626 return mAttachments; 633 return mAttachments;
627} 634}
628 635
629QPtrList<Attachment> Incidence::attachments(const QString& mime) const 636QPtrList<Attachment> Incidence::attachments(const QString& mime) const
630{ 637{
631 QPtrList<Attachment> attachments; 638 QPtrList<Attachment> attachments;
632 QPtrListIterator<Attachment> it( mAttachments ); 639 QPtrListIterator<Attachment> it( mAttachments );
633 Attachment *at; 640 Attachment *at;
634 while ( (at = it.current()) ) { 641 while ( (at = it.current()) ) {
635 if (at->mimeType() == mime) 642 if (at->mimeType() == mime)
636 attachments.append(at); 643 attachments.append(at);
637 ++it; 644 ++it;
638 } 645 }
639 646
640 return attachments; 647 return attachments;
641} 648}
642 649
643void Incidence::setResources(const QStringList &resources) 650void Incidence::setResources(const QStringList &resources)
644{ 651{
645 if (mReadOnly) return; 652 if (mReadOnly) return;
646 mResources = resources; 653 mResources = resources;
647 updated(); 654 updated();
648} 655}
649 656
650QStringList Incidence::resources() const 657QStringList Incidence::resources() const
651{ 658{
652 return mResources; 659 return mResources;
653} 660}
654 661
655 662
656void Incidence::setPriority(int priority) 663void Incidence::setPriority(int priority)
657{ 664{
658 if (mReadOnly) return; 665 if (mReadOnly) return;
659 mPriority = priority; 666 mPriority = priority;
660 updated(); 667 updated();
661} 668}
662 669
663int Incidence::priority() const 670int Incidence::priority() const
664{ 671{
665 return mPriority; 672 return mPriority;
666} 673}
667 674
668void Incidence::setSecrecy(int sec) 675void Incidence::setSecrecy(int sec)
669{ 676{
670 if (mReadOnly) return; 677 if (mReadOnly) return;
671 mSecrecy = sec; 678 mSecrecy = sec;
672 updated(); 679 updated();
673} 680}
674 681
675int Incidence::secrecy() const 682int Incidence::secrecy() const
676{ 683{
677 return mSecrecy; 684 return mSecrecy;
678} 685}
679 686
680QString Incidence::secrecyStr() const 687QString Incidence::secrecyStr() const
681{ 688{
682 return secrecyName(mSecrecy); 689 return secrecyName(mSecrecy);
683} 690}
684 691
685QString Incidence::secrecyName(int secrecy) 692QString Incidence::secrecyName(int secrecy)
686{ 693{
687 switch (secrecy) { 694 switch (secrecy) {
688 case SecrecyPublic: 695 case SecrecyPublic:
689 return i18n("Public"); 696 return i18n("Public");
690 break; 697 break;
691 case SecrecyPrivate: 698 case SecrecyPrivate:
692 return i18n("Private"); 699 return i18n("Private");
693 break; 700 break;
694 case SecrecyConfidential: 701 case SecrecyConfidential:
695 return i18n("Confidential"); 702 return i18n("Confidential");
696 break; 703 break;
697 default: 704 default:
698 return i18n("Undefined"); 705 return i18n("Undefined");
699 break; 706 break;
700 } 707 }
701} 708}
702 709
703QStringList Incidence::secrecyList() 710QStringList Incidence::secrecyList()
704{ 711{
705 QStringList list; 712 QStringList list;
706 list << secrecyName(SecrecyPublic); 713 list << secrecyName(SecrecyPublic);
707 list << secrecyName(SecrecyPrivate); 714 list << secrecyName(SecrecyPrivate);
708 list << secrecyName(SecrecyConfidential); 715 list << secrecyName(SecrecyConfidential);
709 716
710 return list; 717 return list;
711} 718}
712 719
713 720
714QPtrList<Alarm> Incidence::alarms() const 721QPtrList<Alarm> Incidence::alarms() const
715{ 722{
716 return mAlarms; 723 return mAlarms;
717} 724}
718 725
719Alarm* Incidence::newAlarm() 726Alarm* Incidence::newAlarm()
720{ 727{
721 Alarm* alarm = new Alarm(this); 728 Alarm* alarm = new Alarm(this);
722 mAlarms.append(alarm); 729 mAlarms.append(alarm);
723// updated(); 730// updated();
724 return alarm; 731 return alarm;
725} 732}
726 733
727void Incidence::addAlarm(Alarm *alarm) 734void Incidence::addAlarm(Alarm *alarm)
728{ 735{
729 mAlarms.append(alarm); 736 mAlarms.append(alarm);
730 updated(); 737 updated();
731} 738}
732 739
733void Incidence::removeAlarm(Alarm *alarm) 740void Incidence::removeAlarm(Alarm *alarm)
734{ 741{
735 mAlarms.removeRef(alarm); 742 mAlarms.removeRef(alarm);
736 updated(); 743 updated();
737} 744}
738 745
739void Incidence::clearAlarms() 746void Incidence::clearAlarms()
740{ 747{
741 mAlarms.clear(); 748 mAlarms.clear();
742 updated(); 749 updated();
743} 750}
744 751
745bool Incidence::isAlarmEnabled() const 752bool Incidence::isAlarmEnabled() const
746{ 753{
747 Alarm* alarm; 754 Alarm* alarm;
748 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 755 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
749 if (alarm->enabled()) 756 if (alarm->enabled())
750 return true; 757 return true;
751 } 758 }
752 return false; 759 return false;
753} 760}
754#include <stdlib.h> 761#include <stdlib.h>
755Recurrence *Incidence::recurrence() 762Recurrence *Incidence::recurrence()
756{ 763{
757 if ( ! mRecurrence ) { 764 if ( ! mRecurrence ) {
758 mRecurrence = new Recurrence(this); 765 mRecurrence = new Recurrence(this);
759 mRecurrence->setRecurStart( dtStart() ); 766 mRecurrence->setRecurStart( dtStart() );
767 mRecurrence->setRecurReadOnly( isReadOnly());
760 //qDebug("creating new recurence "); 768 //qDebug("creating new recurence ");
761 //abort(); 769 //abort();
762 } 770 }
763 return mRecurrence; 771 return mRecurrence;
764} 772}
765void Incidence::setRecurrence( Recurrence * r) 773void Incidence::setRecurrence( Recurrence * r)
766{ 774{
767 if ( mRecurrence ) 775 if ( mRecurrence )
768 delete mRecurrence; 776 delete mRecurrence;
769 mRecurrence = r; 777 mRecurrence = r;
770} 778}
771 779
772void Incidence::setLocation(const QString &location) 780void Incidence::setLocation(const QString &location)
773{ 781{
774 if (mReadOnly) return; 782 if (mReadOnly) return;
775 mLocation = location; 783 mLocation = location;
776 updated(); 784 updated();
777} 785}
778 786
779QString Incidence::location() const 787QString Incidence::location() const
780{ 788{
781 return mLocation; 789 return mLocation;
782} 790}
783QString Incidence::recurrenceText() const 791QString Incidence::recurrenceText() const
784{ 792{
785 if ( mRecurrence ) return mRecurrence->recurrenceText(); 793 if ( mRecurrence ) return mRecurrence->recurrenceText();
786 return i18n("No"); 794 return i18n("No");
787} 795}
788 796
789ushort Incidence::doesRecur() const 797ushort Incidence::doesRecur() const
790{ 798{
791 if ( mRecurrence ) return mRecurrence->doesRecur(); 799 if ( mRecurrence ) return mRecurrence->doesRecur();
792 else return Recurrence::rNone; 800 else return Recurrence::rNone;
793} 801}
794 802
795QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const 803QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const
796{ 804{
797 QDateTime incidenceStart = dt; 805 QDateTime incidenceStart = dt;
798 *ok = false; 806 *ok = false;
799 if ( doesRecur() ) { 807 if ( doesRecur() ) {
800 bool last; 808 bool last;
801 mRecurrence->getPreviousDateTime( incidenceStart , &last ); 809 mRecurrence->getPreviousDateTime( incidenceStart , &last );
802 int count = 0; 810 int count = 0;
803 if ( !last ) { 811 if ( !last ) {
804 while ( !last ) { 812 while ( !last ) {
805 ++count; 813 ++count;
806 incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); 814 incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last );
807 if ( recursOn( incidenceStart.date() ) ) { 815 if ( recursOn( incidenceStart.date() ) ) {
808 last = true; // exit while llop 816 last = true; // exit while llop
809 } else { 817 } else {
810 if ( last ) { // no alarm on last recurrence 818 if ( last ) { // no alarm on last recurrence
811 return QDateTime (); 819 return QDateTime ();
812 } 820 }
813 int year = incidenceStart.date().year(); 821 int year = incidenceStart.date().year();
814 // workaround for bug in recurrence 822 // workaround for bug in recurrence
815 if ( count == 100 || year < 1000 || year > 5000 ) { 823 if ( count == 100 || year < 1000 || year > 5000 ) {
816 return QDateTime (); 824 return QDateTime ();
817 } 825 }
818 incidenceStart = incidenceStart.addSecs( 1 ); 826 incidenceStart = incidenceStart.addSecs( 1 );
819 } 827 }
820 } 828 }
821 } else { 829 } else {
822 return QDateTime (); 830 return QDateTime ();
823 } 831 }
824 } else { 832 } else {
825 if ( hasStartDate () ) { 833 if ( hasStartDate () ) {
826 incidenceStart = dtStart(); 834 incidenceStart = dtStart();
827 } 835 }
828 if ( typeID() == todoID ) { 836 if ( typeID() == todoID ) {
829 if ( ((Todo*)this)->hasDueDate() ) 837 if ( ((Todo*)this)->hasDueDate() )
830 incidenceStart = ((Todo*)this)->dtDue(); 838 incidenceStart = ((Todo*)this)->dtDue();
831 } 839 }
832 } 840 }
833 if ( incidenceStart > dt ) 841 if ( incidenceStart > dt )
834 *ok = true; 842 *ok = true;
835 return incidenceStart; 843 return incidenceStart;
836} 844}
837QDateTime Incidence::dtStart() const 845QDateTime Incidence::dtStart() const
838{ 846{
839 if ( doesRecur() ) { 847 if ( doesRecur() ) {
840 if ( typeID() == todoID ) { 848 if ( typeID() == todoID ) {
841 ((Todo*)this)->checkSetCompletedFalse(); 849 ((Todo*)this)->checkSetCompletedFalse();
842 } 850 }
843 } 851 }
844 return mDtStart; 852 return mDtStart;
845} 853}