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