summaryrefslogtreecommitdiffabout
path: root/libkcal/incidence.cpp
authorzautrix <zautrix>2005-06-08 10:34:22 (UTC)
committer zautrix <zautrix>2005-06-08 10:34:22 (UTC)
commit793d117812b4da36c9c11d90cccba347cbc6e208 (patch) (unidiff)
tree5bc77e2b7a32a541c2a3b3c3d6d50f873216deef /libkcal/incidence.cpp
parent39d84e2fc3099bd5d7596e8be5dc6783826cec01 (diff)
downloadkdepimpi-793d117812b4da36c9c11d90cccba347cbc6e208.zip
kdepimpi-793d117812b4da36c9c11d90cccba347cbc6e208.tar.gz
kdepimpi-793d117812b4da36c9c11d90cccba347cbc6e208.tar.bz2
changed incidence type to a faster access method
Diffstat (limited to 'libkcal/incidence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidence.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index 762103f..f446197 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -1,744 +1,744 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "calformat.h" 25#include "calformat.h"
26 26
27#include "incidence.h" 27#include "incidence.h"
28#include "todo.h" 28#include "todo.h"
29 29
30using namespace KCal; 30using namespace KCal;
31 31
32Incidence::Incidence() : 32Incidence::Incidence() :
33 IncidenceBase(), 33 IncidenceBase(),
34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) 34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3)
35{ 35{
36 mRecurrence = new Recurrence(this); 36 mRecurrence = new Recurrence(this);
37 mCancelled = false; 37 mCancelled = false;
38 recreate(); 38 recreate();
39 mHasStartDate = true; 39 mHasStartDate = true;
40 mAlarms.setAutoDelete(true); 40 mAlarms.setAutoDelete(true);
41 mAttachments.setAutoDelete(true); 41 mAttachments.setAutoDelete(true);
42 mHasRecurrenceID = false; 42 mHasRecurrenceID = false;
43 mHoliday = false; 43 mHoliday = false;
44 mBirthday = false; 44 mBirthday = false;
45 mAnniversary = false; 45 mAnniversary = false;
46 46
47} 47}
48 48
49Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) 49Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
50{ 50{
51// TODO: reenable attributes currently commented out. 51// TODO: reenable attributes currently commented out.
52 mRevision = i.mRevision; 52 mRevision = i.mRevision;
53 mCreated = i.mCreated; 53 mCreated = i.mCreated;
54 mDescription = i.mDescription; 54 mDescription = i.mDescription;
55 mSummary = i.mSummary; 55 mSummary = i.mSummary;
56 mCategories = i.mCategories; 56 mCategories = i.mCategories;
57// Incidence *mRelatedTo; Incidence *mRelatedTo; 57// Incidence *mRelatedTo; Incidence *mRelatedTo;
58 mRelatedTo = 0; 58 mRelatedTo = 0;
59 mRelatedToUid = i.mRelatedToUid; 59 mRelatedToUid = i.mRelatedToUid;
60// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; 60// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations;
61 mExDates = i.mExDates; 61 mExDates = i.mExDates;
62 mAttachments = i.mAttachments; 62 mAttachments = i.mAttachments;
63 mResources = i.mResources; 63 mResources = i.mResources;
64 mSecrecy = i.mSecrecy; 64 mSecrecy = i.mSecrecy;
65 mPriority = i.mPriority; 65 mPriority = i.mPriority;
66 mLocation = i.mLocation; 66 mLocation = i.mLocation;
67 mCancelled = i.mCancelled; 67 mCancelled = i.mCancelled;
68 mHasStartDate = i.mHasStartDate; 68 mHasStartDate = i.mHasStartDate;
69 QPtrListIterator<Alarm> it( i.mAlarms ); 69 QPtrListIterator<Alarm> it( i.mAlarms );
70 const Alarm *a; 70 const Alarm *a;
71 while( (a = it.current()) ) { 71 while( (a = it.current()) ) {
72 Alarm *b = new Alarm( *a ); 72 Alarm *b = new Alarm( *a );
73 b->setParent( this ); 73 b->setParent( this );
74 mAlarms.append( b ); 74 mAlarms.append( b );
75 75
76 ++it; 76 ++it;
77 } 77 }
78 mAlarms.setAutoDelete(true); 78 mAlarms.setAutoDelete(true);
79 mHasRecurrenceID = i.mHasRecurrenceID; 79 mHasRecurrenceID = i.mHasRecurrenceID;
80 mRecurrenceID = i.mRecurrenceID; 80 mRecurrenceID = i.mRecurrenceID;
81 mRecurrence = new Recurrence( *(i.mRecurrence), this ); 81 mRecurrence = new Recurrence( *(i.mRecurrence), this );
82 mHoliday = i.mHoliday ; 82 mHoliday = i.mHoliday ;
83 mBirthday = i.mBirthday; 83 mBirthday = i.mBirthday;
84 mAnniversary = i.mAnniversary; 84 mAnniversary = i.mAnniversary;
85} 85}
86 86
87Incidence::~Incidence() 87Incidence::~Incidence()
88{ 88{
89 89
90 Incidence *ev; 90 Incidence *ev;
91 QPtrList<Incidence> Relations = relations(); 91 QPtrList<Incidence> Relations = relations();
92 for (ev=Relations.first();ev;ev=Relations.next()) { 92 for (ev=Relations.first();ev;ev=Relations.next()) {
93 if (ev->relatedTo() == this) ev->setRelatedTo(0); 93 if (ev->relatedTo() == this) ev->setRelatedTo(0);
94 } 94 }
95 if (relatedTo()) relatedTo()->removeRelation(this); 95 if (relatedTo()) relatedTo()->removeRelation(this);
96 delete mRecurrence; 96 delete mRecurrence;
97 97
98} 98}
99 99
100bool Incidence::isHoliday() const 100bool Incidence::isHoliday() const
101{ 101{
102 return mHoliday; 102 return mHoliday;
103} 103}
104bool Incidence::isBirthday() const 104bool Incidence::isBirthday() const
105{ 105{
106 106
107 return mBirthday ; 107 return mBirthday ;
108} 108}
109bool Incidence::isAnniversary() const 109bool Incidence::isAnniversary() const
110{ 110{
111 return mAnniversary ; 111 return mAnniversary ;
112 112
113} 113}
114 114
115bool Incidence::hasRecurrenceID() const 115bool Incidence::hasRecurrenceID() const
116{ 116{
117 return mHasRecurrenceID; 117 return mHasRecurrenceID;
118} 118}
119 119
120void Incidence::setHasRecurrenceID( bool b ) 120void Incidence::setHasRecurrenceID( bool b )
121{ 121{
122 mHasRecurrenceID = b; 122 mHasRecurrenceID = b;
123} 123}
124 124
125void Incidence::setRecurrenceID(QDateTime d) 125void Incidence::setRecurrenceID(QDateTime d)
126{ 126{
127 mRecurrenceID = d; 127 mRecurrenceID = d;
128 mHasRecurrenceID = true; 128 mHasRecurrenceID = true;
129 updated(); 129 updated();
130} 130}
131QDateTime Incidence::recurrenceID () const 131QDateTime Incidence::recurrenceID () const
132{ 132{
133 return mRecurrenceID; 133 return mRecurrenceID;
134} 134}
135 135
136bool Incidence::cancelled() const 136bool Incidence::cancelled() const
137{ 137{
138 return mCancelled; 138 return mCancelled;
139} 139}
140void Incidence::setCancelled( bool b ) 140void Incidence::setCancelled( bool b )
141{ 141{
142 mCancelled = b; 142 mCancelled = b;
143 updated(); 143 updated();
144} 144}
145bool Incidence::hasStartDate() const 145bool Incidence::hasStartDate() const
146{ 146{
147 return mHasStartDate; 147 return mHasStartDate;
148} 148}
149 149
150void Incidence::setHasStartDate(bool f) 150void Incidence::setHasStartDate(bool f)
151{ 151{
152 if (mReadOnly) return; 152 if (mReadOnly) return;
153 mHasStartDate = f; 153 mHasStartDate = f;
154 updated(); 154 updated();
155} 155}
156 156
157// A string comparison that considers that null and empty are the same 157// A string comparison that considers that null and empty are the same
158static bool stringCompare( const QString& s1, const QString& s2 ) 158static bool stringCompare( const QString& s1, const QString& s2 )
159{ 159{
160 if ( s1.isEmpty() && s2.isEmpty() ) 160 if ( s1.isEmpty() && s2.isEmpty() )
161 return true; 161 return true;
162 return s1 == s2; 162 return s1 == s2;
163} 163}
164 164
165bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 165bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
166{ 166{
167 167
168 if( i1.alarms().count() != i2.alarms().count() ) { 168 if( i1.alarms().count() != i2.alarms().count() ) {
169 return false; // no need to check further 169 return false; // no need to check further
170 } 170 }
171 if ( i1.alarms().count() > 0 ) { 171 if ( i1.alarms().count() > 0 ) {
172 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) 172 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) )
173 { 173 {
174 qDebug("alarm not equal "); 174 qDebug("alarm not equal ");
175 return false; 175 return false;
176 } 176 }
177 } 177 }
178#if 0 178#if 0
179 QPtrListIterator<Alarm> a1( i1.alarms() ); 179 QPtrListIterator<Alarm> a1( i1.alarms() );
180 QPtrListIterator<Alarm> a2( i2.alarms() ); 180 QPtrListIterator<Alarm> a2( i2.alarms() );
181 for( ; a1.current() && a2.current(); ++a1, ++a2 ) { 181 for( ; a1.current() && a2.current(); ++a1, ++a2 ) {
182 if( *a1.current() == *a2.current() ) { 182 if( *a1.current() == *a2.current() ) {
183 continue; 183 continue;
184 } 184 }
185 else { 185 else {
186 return false; 186 return false;
187 } 187 }
188 } 188 }
189#endif 189#endif
190 190
191 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { 191 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) {
192 if ( i1.hasRecurrenceID() ) { 192 if ( i1.hasRecurrenceID() ) {
193 if ( i1.recurrenceID() != i2.recurrenceID() ) 193 if ( i1.recurrenceID() != i2.recurrenceID() )
194 return false; 194 return false;
195 } 195 }
196 196
197 } else { 197 } else {
198 return false; 198 return false;
199 } 199 }
200 200
201 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) 201 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) )
202 return false; 202 return false;
203 if ( i1.hasStartDate() == i2.hasStartDate() ) { 203 if ( i1.hasStartDate() == i2.hasStartDate() ) {
204 if ( i1.hasStartDate() ) { 204 if ( i1.hasStartDate() ) {
205 if ( i1.dtStart() != i2.dtStart() ) 205 if ( i1.dtStart() != i2.dtStart() )
206 return false; 206 return false;
207 } 207 }
208 } else { 208 } else {
209 return false; 209 return false;
210 } 210 }
211 if (!( *i1.recurrence() == *i2.recurrence()) ) { 211 if (!( *i1.recurrence() == *i2.recurrence()) ) {
212 qDebug("recurrence is NOT equal "); 212 qDebug("recurrence is NOT equal ");
213 return false; 213 return false;
214 } 214 }
215 return 215 return
216 // i1.created() == i2.created() && 216 // i1.created() == i2.created() &&
217 stringCompare( i1.description(), i2.description() ) && 217 stringCompare( i1.description(), i2.description() ) &&
218 stringCompare( i1.summary(), i2.summary() ) && 218 stringCompare( i1.summary(), i2.summary() ) &&
219 i1.categories() == i2.categories() && 219 i1.categories() == i2.categories() &&
220 // no need to compare mRelatedTo 220 // no need to compare mRelatedTo
221 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && 221 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) &&
222 // i1.relations() == i2.relations() && 222 // i1.relations() == i2.relations() &&
223 i1.exDates() == i2.exDates() && 223 i1.exDates() == i2.exDates() &&
224 i1.attachments() == i2.attachments() && 224 i1.attachments() == i2.attachments() &&
225 i1.resources() == i2.resources() && 225 i1.resources() == i2.resources() &&
226 i1.secrecy() == i2.secrecy() && 226 i1.secrecy() == i2.secrecy() &&
227 i1.priority() == i2.priority() && 227 i1.priority() == i2.priority() &&
228 i1.cancelled() == i2.cancelled() && 228 i1.cancelled() == i2.cancelled() &&
229 stringCompare( i1.location(), i2.location() ); 229 stringCompare( i1.location(), i2.location() );
230} 230}
231 231
232Incidence* Incidence::recreateCloneException( QDate d ) 232Incidence* Incidence::recreateCloneException( QDate d )
233{ 233{
234 Incidence* newInc = clone(); 234 Incidence* newInc = clone();
235 newInc->recreate(); 235 newInc->recreate();
236 if ( doesRecur() ) { 236 if ( doesRecur() ) {
237 addExDate( d ); 237 addExDate( d );
238 newInc->recurrence()->unsetRecurs(); 238 newInc->recurrence()->unsetRecurs();
239 if ( type() == "Event") { 239 if ( 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 284
285void Incidence::setCreated(QDateTime created) 285void Incidence::setCreated(QDateTime created)
286{ 286{
287 if (mReadOnly) return; 287 if (mReadOnly) return;
288 mCreated = getEvenTime(created); 288 mCreated = getEvenTime(created);
289} 289}
290 290
291QDateTime Incidence::created() const 291QDateTime Incidence::created() const
292{ 292{
293 return mCreated; 293 return mCreated;
294} 294}
295 295
296void Incidence::setRevision(int rev) 296void Incidence::setRevision(int rev)
297{ 297{
298 if (mReadOnly) return; 298 if (mReadOnly) return;
299 mRevision = rev; 299 mRevision = rev;
300 300
301 updated(); 301 updated();
302} 302}
303 303
304int Incidence::revision() const 304int Incidence::revision() const
305{ 305{
306 return mRevision; 306 return mRevision;
307} 307}
308 308
309void Incidence::setDtStart(const QDateTime &dtStart) 309void Incidence::setDtStart(const QDateTime &dtStart)
310{ 310{
311 311
312 QDateTime dt = getEvenTime(dtStart); 312 QDateTime dt = getEvenTime(dtStart);
313 recurrence()->setRecurStart( dt); 313 recurrence()->setRecurStart( dt);
314 IncidenceBase::setDtStart( dt ); 314 IncidenceBase::setDtStart( dt );
315} 315}
316 316
317void Incidence::setDescription(const QString &description) 317void Incidence::setDescription(const QString &description)
318{ 318{
319 if (mReadOnly) return; 319 if (mReadOnly) return;
320 mDescription = description; 320 mDescription = description;
321 updated(); 321 updated();
322} 322}
323 323
324QString Incidence::description() const 324QString Incidence::description() const
325{ 325{
326 return mDescription; 326 return mDescription;
327} 327}
328 328
329 329
330void Incidence::setSummary(const QString &summary) 330void Incidence::setSummary(const QString &summary)
331{ 331{
332 if (mReadOnly) return; 332 if (mReadOnly) return;
333 mSummary = summary; 333 mSummary = summary;
334 updated(); 334 updated();
335} 335}
336 336
337QString Incidence::summary() const 337QString Incidence::summary() const
338{ 338{
339 return mSummary; 339 return mSummary;
340} 340}
341void Incidence::checkCategories() 341void Incidence::checkCategories()
342{ 342{
343 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); 343 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday"));
344 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); 344 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday"));
345 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); 345 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary"));
346} 346}
347 347
348void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false 348void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false
349{ 349{
350 if (mReadOnly) return; 350 if (mReadOnly) return;
351 int i; 351 int i;
352 for( i = 0; i < categories.count(); ++i ) { 352 for( i = 0; i < categories.count(); ++i ) {
353 if ( !mCategories.contains (categories[i])) 353 if ( !mCategories.contains (categories[i]))
354 mCategories.append( categories[i] ); 354 mCategories.append( categories[i] );
355 } 355 }
356 checkCategories(); 356 checkCategories();
357 updated(); 357 updated();
358 if ( addToRelations ) { 358 if ( addToRelations ) {
359 Incidence * inc; 359 Incidence * inc;
360 QPtrList<Incidence> Relations = relations(); 360 QPtrList<Incidence> Relations = relations();
361 for (inc=Relations.first();inc;inc=Relations.next()) { 361 for (inc=Relations.first();inc;inc=Relations.next()) {
362 inc->addCategories( categories, true ); 362 inc->addCategories( categories, true );
363 } 363 }
364 } 364 }
365} 365}
366 366
367void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false 367void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false
368{ 368{
369 if (mReadOnly) return; 369 if (mReadOnly) return;
370 mCategories = categories; 370 mCategories = categories;
371 checkCategories(); 371 checkCategories();
372 updated(); 372 updated();
373 if ( setForRelations ) { 373 if ( setForRelations ) {
374 Incidence * inc; 374 Incidence * inc;
375 QPtrList<Incidence> Relations = relations(); 375 QPtrList<Incidence> Relations = relations();
376 for (inc=Relations.first();inc;inc=Relations.next()) { 376 for (inc=Relations.first();inc;inc=Relations.next()) {
377 inc->setCategories( categories, true ); 377 inc->setCategories( categories, true );
378 } 378 }
379 } 379 }
380} 380}
381 381
382// TODO: remove setCategories(QString) function 382// TODO: remove setCategories(QString) function
383void Incidence::setCategories(const QString &catStr) 383void Incidence::setCategories(const QString &catStr)
384{ 384{
385 if (mReadOnly) return; 385 if (mReadOnly) return;
386 mCategories.clear(); 386 mCategories.clear();
387 387
388 if (catStr.isEmpty()) return; 388 if (catStr.isEmpty()) return;
389 389
390 mCategories = QStringList::split(",",catStr); 390 mCategories = QStringList::split(",",catStr);
391 391
392 QStringList::Iterator it; 392 QStringList::Iterator it;
393 for(it = mCategories.begin();it != mCategories.end(); ++it) { 393 for(it = mCategories.begin();it != mCategories.end(); ++it) {
394 *it = (*it).stripWhiteSpace(); 394 *it = (*it).stripWhiteSpace();
395 } 395 }
396 checkCategories(); 396 checkCategories();
397 updated(); 397 updated();
398} 398}
399 399
400QStringList Incidence::categories() const 400QStringList Incidence::categories() const
401{ 401{
402 return mCategories; 402 return mCategories;
403} 403}
404 404
405QString Incidence::categoriesStr() 405QString Incidence::categoriesStr()
406{ 406{
407 return mCategories.join(","); 407 return mCategories.join(",");
408} 408}
409QString Incidence::categoriesStrWithSpace() 409QString Incidence::categoriesStrWithSpace()
410{ 410{
411 return mCategories.join(", "); 411 return mCategories.join(", ");
412} 412}
413 413
414void Incidence::setRelatedToUid(const QString &relatedToUid) 414void Incidence::setRelatedToUid(const QString &relatedToUid)
415{ 415{
416 if (mReadOnly) return; 416 if (mReadOnly) return;
417 mRelatedToUid = relatedToUid; 417 mRelatedToUid = relatedToUid;
418} 418}
419 419
420QString Incidence::relatedToUid() const 420QString Incidence::relatedToUid() const
421{ 421{
422 return mRelatedToUid; 422 return mRelatedToUid;
423} 423}
424 424
425void Incidence::setRelatedTo(Incidence *relatedTo) 425void Incidence::setRelatedTo(Incidence *relatedTo)
426{ 426{
427 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 427 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
428 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 428 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
429 if (mReadOnly || mRelatedTo == relatedTo) return; 429 if (mReadOnly || mRelatedTo == relatedTo) return;
430 if(mRelatedTo) { 430 if(mRelatedTo) {
431 // updated(); 431 // updated();
432 mRelatedTo->removeRelation(this); 432 mRelatedTo->removeRelation(this);
433 } 433 }
434 mRelatedTo = relatedTo; 434 mRelatedTo = relatedTo;
435 if (mRelatedTo) { 435 if (mRelatedTo) {
436 mRelatedTo->addRelation(this); 436 mRelatedTo->addRelation(this);
437 mRelatedToUid = mRelatedTo->uid(); 437 mRelatedToUid = mRelatedTo->uid();
438 } else { 438 } else {
439 mRelatedToUid = ""; 439 mRelatedToUid = "";
440 } 440 }
441} 441}
442 442
443Incidence *Incidence::relatedTo() const 443Incidence *Incidence::relatedTo() const
444{ 444{
445 return mRelatedTo; 445 return mRelatedTo;
446} 446}
447 447
448QPtrList<Incidence> Incidence::relations() const 448QPtrList<Incidence> Incidence::relations() const
449{ 449{
450 return mRelations; 450 return mRelations;
451} 451}
452 452
453void Incidence::addRelation(Incidence *event) 453void Incidence::addRelation(Incidence *event)
454{ 454{
455 if( mRelations.findRef( event ) == -1 ) { 455 if( mRelations.findRef( event ) == -1 ) {
456 mRelations.append(event); 456 mRelations.append(event);
457 //updated(); 457 //updated();
458 } 458 }
459} 459}
460 460
461void Incidence::removeRelation(Incidence *event) 461void Incidence::removeRelation(Incidence *event)
462{ 462{
463 463
464 mRelations.removeRef(event); 464 mRelations.removeRef(event);
465 465
466// if (event->getRelatedTo() == this) event->setRelatedTo(0); 466// if (event->getRelatedTo() == this) event->setRelatedTo(0);
467} 467}
468 468
469bool Incidence::recursOn(const QDate &qd) const 469bool Incidence::recursOn(const QDate &qd) const
470{ 470{
471 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; 471 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true;
472 else return false; 472 else return false;
473} 473}
474 474
475void Incidence::setExDates(const DateList &exDates) 475void Incidence::setExDates(const DateList &exDates)
476{ 476{
477 if (mReadOnly) return; 477 if (mReadOnly) return;
478 mExDates = exDates; 478 mExDates = exDates;
479 479
480 recurrence()->setRecurExDatesCount(mExDates.count()); 480 recurrence()->setRecurExDatesCount(mExDates.count());
481 481
482 updated(); 482 updated();
483} 483}
484 484
485void Incidence::addExDate(const QDate &date) 485void Incidence::addExDate(const QDate &date)
486{ 486{
487 if (mReadOnly) return; 487 if (mReadOnly) return;
488 mExDates.append(date); 488 mExDates.append(date);
489 489
490 recurrence()->setRecurExDatesCount(mExDates.count()); 490 recurrence()->setRecurExDatesCount(mExDates.count());
491 491
492 updated(); 492 updated();
493} 493}
494 494
495DateList Incidence::exDates() const 495DateList Incidence::exDates() const
496{ 496{
497 return mExDates; 497 return mExDates;
498} 498}
499 499
500bool Incidence::isException(const QDate &date) const 500bool Incidence::isException(const QDate &date) const
501{ 501{
502 DateList::ConstIterator it; 502 DateList::ConstIterator it;
503 for( it = mExDates.begin(); it != mExDates.end(); ++it ) { 503 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
504 if ( (*it) == date ) { 504 if ( (*it) == date ) {
505 return true; 505 return true;
506 } 506 }
507 } 507 }
508 508
509 return false; 509 return false;
510} 510}
511 511
512void Incidence::addAttachment(Attachment *attachment) 512void Incidence::addAttachment(Attachment *attachment)
513{ 513{
514 if (mReadOnly || !attachment) return; 514 if (mReadOnly || !attachment) return;
515 mAttachments.append(attachment); 515 mAttachments.append(attachment);
516 updated(); 516 updated();
517} 517}
518 518
519void Incidence::deleteAttachment(Attachment *attachment) 519void Incidence::deleteAttachment(Attachment *attachment)
520{ 520{
521 mAttachments.removeRef(attachment); 521 mAttachments.removeRef(attachment);
522} 522}
523 523
524void Incidence::deleteAttachments(const QString& mime) 524void Incidence::deleteAttachments(const QString& mime)
525{ 525{
526 Attachment *at = mAttachments.first(); 526 Attachment *at = mAttachments.first();
527 while (at) { 527 while (at) {
528 if (at->mimeType() == mime) 528 if (at->mimeType() == mime)
529 mAttachments.remove(); 529 mAttachments.remove();
530 else 530 else
531 at = mAttachments.next(); 531 at = mAttachments.next();
532 } 532 }
533} 533}
534 534
535QPtrList<Attachment> Incidence::attachments() const 535QPtrList<Attachment> Incidence::attachments() const
536{ 536{
537 return mAttachments; 537 return mAttachments;
538} 538}
539 539
540QPtrList<Attachment> Incidence::attachments(const QString& mime) const 540QPtrList<Attachment> Incidence::attachments(const QString& mime) const
541{ 541{
542 QPtrList<Attachment> attachments; 542 QPtrList<Attachment> attachments;
543 QPtrListIterator<Attachment> it( mAttachments ); 543 QPtrListIterator<Attachment> it( mAttachments );
544 Attachment *at; 544 Attachment *at;
545 while ( (at = it.current()) ) { 545 while ( (at = it.current()) ) {
546 if (at->mimeType() == mime) 546 if (at->mimeType() == mime)
547 attachments.append(at); 547 attachments.append(at);
548 ++it; 548 ++it;
549 } 549 }
550 550
551 return attachments; 551 return attachments;
552} 552}
553 553
554void Incidence::setResources(const QStringList &resources) 554void Incidence::setResources(const QStringList &resources)
555{ 555{
556 if (mReadOnly) return; 556 if (mReadOnly) return;
557 mResources = resources; 557 mResources = resources;
558 updated(); 558 updated();
559} 559}
560 560
561QStringList Incidence::resources() const 561QStringList Incidence::resources() const
562{ 562{
563 return mResources; 563 return mResources;
564} 564}
565 565
566 566
567void Incidence::setPriority(int priority) 567void Incidence::setPriority(int priority)
568{ 568{
569 if (mReadOnly) return; 569 if (mReadOnly) return;
570 mPriority = priority; 570 mPriority = priority;
571 updated(); 571 updated();
572} 572}
573 573
574int Incidence::priority() const 574int Incidence::priority() const
575{ 575{
576 return mPriority; 576 return mPriority;
577} 577}
578 578
579void Incidence::setSecrecy(int sec) 579void Incidence::setSecrecy(int sec)
580{ 580{
581 if (mReadOnly) return; 581 if (mReadOnly) return;
582 mSecrecy = sec; 582 mSecrecy = sec;
583 updated(); 583 updated();
584} 584}
585 585
586int Incidence::secrecy() const 586int Incidence::secrecy() const
587{ 587{
588 return mSecrecy; 588 return mSecrecy;
589} 589}
590 590
591QString Incidence::secrecyStr() const 591QString Incidence::secrecyStr() const
592{ 592{
593 return secrecyName(mSecrecy); 593 return secrecyName(mSecrecy);
594} 594}
595 595
596QString Incidence::secrecyName(int secrecy) 596QString Incidence::secrecyName(int secrecy)
597{ 597{
598 switch (secrecy) { 598 switch (secrecy) {
599 case SecrecyPublic: 599 case SecrecyPublic:
600 return i18n("Public"); 600 return i18n("Public");
601 break; 601 break;
602 case SecrecyPrivate: 602 case SecrecyPrivate:
603 return i18n("Private"); 603 return i18n("Private");
604 break; 604 break;
605 case SecrecyConfidential: 605 case SecrecyConfidential:
606 return i18n("Confidential"); 606 return i18n("Confidential");
607 break; 607 break;
608 default: 608 default:
609 return i18n("Undefined"); 609 return i18n("Undefined");
610 break; 610 break;
611 } 611 }
612} 612}
613 613
614QStringList Incidence::secrecyList() 614QStringList Incidence::secrecyList()
615{ 615{
616 QStringList list; 616 QStringList list;
617 list << secrecyName(SecrecyPublic); 617 list << secrecyName(SecrecyPublic);
618 list << secrecyName(SecrecyPrivate); 618 list << secrecyName(SecrecyPrivate);
619 list << secrecyName(SecrecyConfidential); 619 list << secrecyName(SecrecyConfidential);
620 620
621 return list; 621 return list;
622} 622}
623 623
624 624
625QPtrList<Alarm> Incidence::alarms() const 625QPtrList<Alarm> Incidence::alarms() const
626{ 626{
627 return mAlarms; 627 return mAlarms;
628} 628}
629 629
630Alarm* Incidence::newAlarm() 630Alarm* Incidence::newAlarm()
631{ 631{
632 Alarm* alarm = new Alarm(this); 632 Alarm* alarm = new Alarm(this);
633 mAlarms.append(alarm); 633 mAlarms.append(alarm);
634// updated(); 634// updated();
635 return alarm; 635 return alarm;
636} 636}
637 637
638void Incidence::addAlarm(Alarm *alarm) 638void Incidence::addAlarm(Alarm *alarm)
639{ 639{
640 mAlarms.append(alarm); 640 mAlarms.append(alarm);
641 updated(); 641 updated();
642} 642}
643 643
644void Incidence::removeAlarm(Alarm *alarm) 644void Incidence::removeAlarm(Alarm *alarm)
645{ 645{
646 mAlarms.removeRef(alarm); 646 mAlarms.removeRef(alarm);
647 updated(); 647 updated();
648} 648}
649 649
650void Incidence::clearAlarms() 650void Incidence::clearAlarms()
651{ 651{
652 mAlarms.clear(); 652 mAlarms.clear();
653 updated(); 653 updated();
654} 654}
655 655
656bool Incidence::isAlarmEnabled() const 656bool Incidence::isAlarmEnabled() const
657{ 657{
658 Alarm* alarm; 658 Alarm* alarm;
659 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 659 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
660 if (alarm->enabled()) 660 if (alarm->enabled())
661 return true; 661 return true;
662 } 662 }
663 return false; 663 return false;
664} 664}
665 665
666Recurrence *Incidence::recurrence() const 666Recurrence *Incidence::recurrence() const
667{ 667{
668 return mRecurrence; 668 return mRecurrence;
669} 669}
670void Incidence::setRecurrence( Recurrence * r) 670void Incidence::setRecurrence( Recurrence * r)
671{ 671{
672 delete mRecurrence; 672 delete mRecurrence;
673 mRecurrence = r; 673 mRecurrence = r;
674} 674}
675 675
676void Incidence::setLocation(const QString &location) 676void Incidence::setLocation(const QString &location)
677{ 677{
678 if (mReadOnly) return; 678 if (mReadOnly) return;
679 mLocation = location; 679 mLocation = location;
680 updated(); 680 updated();
681} 681}
682 682
683QString Incidence::location() const 683QString Incidence::location() const
684{ 684{
685 return mLocation; 685 return mLocation;
686} 686}
687 687
688ushort Incidence::doesRecur() const 688ushort Incidence::doesRecur() const
689{ 689{
690 if ( mRecurrence ) return mRecurrence->doesRecur(); 690 if ( mRecurrence ) return mRecurrence->doesRecur();
691 else return Recurrence::rNone; 691 else return Recurrence::rNone;
692} 692}
693 693
694QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const 694QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const
695{ 695{
696 QDateTime incidenceStart = dt; 696 QDateTime incidenceStart = dt;
697 *ok = false; 697 *ok = false;
698 if ( doesRecur() ) { 698 if ( doesRecur() ) {
699 bool last; 699 bool last;
700 recurrence()->getPreviousDateTime( incidenceStart , &last ); 700 recurrence()->getPreviousDateTime( incidenceStart , &last );
701 int count = 0; 701 int count = 0;
702 if ( !last ) { 702 if ( !last ) {
703 while ( !last ) { 703 while ( !last ) {
704 ++count; 704 ++count;
705 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); 705 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last );
706 if ( recursOn( incidenceStart.date() ) ) { 706 if ( recursOn( incidenceStart.date() ) ) {
707 last = true; // exit while llop 707 last = true; // exit while llop
708 } else { 708 } else {
709 if ( last ) { // no alarm on last recurrence 709 if ( last ) { // no alarm on last recurrence
710 return QDateTime (); 710 return QDateTime ();
711 } 711 }
712 int year = incidenceStart.date().year(); 712 int year = incidenceStart.date().year();
713 // workaround for bug in recurrence 713 // workaround for bug in recurrence
714 if ( count == 100 || year < 1000 || year > 5000 ) { 714 if ( count == 100 || year < 1000 || year > 5000 ) {
715 return QDateTime (); 715 return QDateTime ();
716 } 716 }
717 incidenceStart = incidenceStart.addSecs( 1 ); 717 incidenceStart = incidenceStart.addSecs( 1 );
718 } 718 }
719 } 719 }
720 } else { 720 } else {
721 return QDateTime (); 721 return QDateTime ();
722 } 722 }
723 } else { 723 } else {
724 if ( hasStartDate () ) { 724 if ( hasStartDate () ) {
725 incidenceStart = dtStart(); 725 incidenceStart = dtStart();
726 } 726 }
727 if ( type() =="Todo" ) { 727 if ( typeID() == todoID ) {
728 if ( ((Todo*)this)->hasDueDate() ) 728 if ( ((Todo*)this)->hasDueDate() )
729 incidenceStart = ((Todo*)this)->dtDue(); 729 incidenceStart = ((Todo*)this)->dtDue();
730 } 730 }
731 } 731 }
732 if ( incidenceStart > dt ) 732 if ( incidenceStart > dt )
733 *ok = true; 733 *ok = true;
734 return incidenceStart; 734 return incidenceStart;
735} 735}
736QDateTime Incidence::dtStart() const 736QDateTime Incidence::dtStart() const
737{ 737{
738 if ( doesRecur() ) { 738 if ( doesRecur() ) {
739 if ( type() == "Todo" ) { 739 if ( typeID() == todoID ) {
740 ((Todo*)this)->checkSetCompletedFalse(); 740 ((Todo*)this)->checkSetCompletedFalse();
741 } 741 }
742 } 742 }
743 return mDtStart; 743 return mDtStart;
744} 744}