summaryrefslogtreecommitdiffabout
path: root/libkcal/incidence.cpp
Unidiff
Diffstat (limited to 'libkcal/incidence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidence.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index 4382416..11f7ecc 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -15,741 +15,746 @@
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "calformat.h" 25#include "calformat.h"
26 26
27#include "incidence.h" 27#include "incidence.h"
28#include "todo.h" 28#include "todo.h"
29 29
30using namespace KCal; 30using namespace KCal;
31 31
32Incidence::Incidence() : 32Incidence::Incidence() :
33 IncidenceBase(), 33 IncidenceBase(),
34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) 34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3)
35{ 35{
36 mRecurrence = new Recurrence(this); 36 mRecurrence = new Recurrence(this);
37 mCancelled = false; 37 mCancelled = false;
38 recreate(); 38 recreate();
39 mHasStartDate = true; 39 mHasStartDate = true;
40 mAlarms.setAutoDelete(true); 40 mAlarms.setAutoDelete(true);
41 mAttachments.setAutoDelete(true); 41 mAttachments.setAutoDelete(true);
42 mHasRecurrenceID = false; 42 mHasRecurrenceID = false;
43 mHoliday = false; 43 mHoliday = false;
44 mBirthday = false; 44 mBirthday = false;
45 mAnniversary = false; 45 mAnniversary = false;
46 46
47} 47}
48 48
49Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) 49Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
50{ 50{
51// TODO: reenable attributes currently commented out. 51// TODO: reenable attributes currently commented out.
52 mRevision = i.mRevision; 52 mRevision = i.mRevision;
53 mCreated = i.mCreated; 53 mCreated = i.mCreated;
54 mDescription = i.mDescription; 54 mDescription = i.mDescription;
55 mSummary = i.mSummary; 55 mSummary = i.mSummary;
56 mCategories = i.mCategories; 56 mCategories = i.mCategories;
57// Incidence *mRelatedTo; Incidence *mRelatedTo; 57// Incidence *mRelatedTo; Incidence *mRelatedTo;
58 mRelatedTo = 0; 58 mRelatedTo = 0;
59 mRelatedToUid = i.mRelatedToUid; 59 mRelatedToUid = i.mRelatedToUid;
60// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; 60// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations;
61 mExDates = i.mExDates; 61 mExDates = i.mExDates;
62 mAttachments = i.mAttachments; 62 mAttachments = i.mAttachments;
63 mResources = i.mResources; 63 mResources = i.mResources;
64 mSecrecy = i.mSecrecy; 64 mSecrecy = i.mSecrecy;
65 mPriority = i.mPriority; 65 mPriority = i.mPriority;
66 mLocation = i.mLocation; 66 mLocation = i.mLocation;
67 mCancelled = i.mCancelled; 67 mCancelled = i.mCancelled;
68 mHasStartDate = i.mHasStartDate; 68 mHasStartDate = i.mHasStartDate;
69 QPtrListIterator<Alarm> it( i.mAlarms ); 69 QPtrListIterator<Alarm> it( i.mAlarms );
70 const Alarm *a; 70 const Alarm *a;
71 while( (a = it.current()) ) { 71 while( (a = it.current()) ) {
72 Alarm *b = new Alarm( *a ); 72 Alarm *b = new Alarm( *a );
73 b->setParent( this ); 73 b->setParent( this );
74 mAlarms.append( b ); 74 mAlarms.append( b );
75 75
76 ++it; 76 ++it;
77 } 77 }
78 mAlarms.setAutoDelete(true); 78 mAlarms.setAutoDelete(true);
79 mHasRecurrenceID = i.mHasRecurrenceID; 79 mHasRecurrenceID = i.mHasRecurrenceID;
80 mRecurrenceID = i.mRecurrenceID; 80 mRecurrenceID = i.mRecurrenceID;
81 mRecurrence = new Recurrence( *(i.mRecurrence), this ); 81 mRecurrence = new Recurrence( *(i.mRecurrence), this );
82 mHoliday = i.mHoliday ; 82 mHoliday = i.mHoliday ;
83 mBirthday = i.mBirthday; 83 mBirthday = i.mBirthday;
84 mAnniversary = i.mAnniversary; 84 mAnniversary = i.mAnniversary;
85} 85}
86 86
87Incidence::~Incidence() 87Incidence::~Incidence()
88{ 88{
89 89
90 Incidence *ev; 90 Incidence *ev;
91 QPtrList<Incidence> Relations = relations(); 91 QPtrList<Incidence> Relations = relations();
92 for (ev=Relations.first();ev;ev=Relations.next()) { 92 for (ev=Relations.first();ev;ev=Relations.next()) {
93 if (ev->relatedTo() == this) ev->setRelatedTo(0); 93 if (ev->relatedTo() == this) ev->setRelatedTo(0);
94 } 94 }
95 if (relatedTo()) relatedTo()->removeRelation(this); 95 if (relatedTo()) relatedTo()->removeRelation(this);
96 delete mRecurrence; 96 delete mRecurrence;
97 97
98} 98}
99 99
100bool Incidence::isHoliday() const 100bool Incidence::isHoliday() const
101{ 101{
102 return mHoliday; 102 return mHoliday;
103} 103}
104bool Incidence::isBirthday() const 104bool Incidence::isBirthday() const
105{ 105{
106 106
107 return mBirthday ; 107 return mBirthday ;
108} 108}
109bool Incidence::isAnniversary() const 109bool Incidence::isAnniversary() const
110{ 110{
111 return mAnniversary ; 111 return mAnniversary ;
112 112
113} 113}
114 114
115bool Incidence::hasRecurrenceID() const 115bool Incidence::hasRecurrenceID() const
116{ 116{
117 return mHasRecurrenceID; 117 return mHasRecurrenceID;
118} 118}
119 119
120void Incidence::setHasRecurrenceID( bool b ) 120void Incidence::setHasRecurrenceID( bool b )
121{ 121{
122 mHasRecurrenceID = b; 122 mHasRecurrenceID = b;
123} 123}
124 124
125void Incidence::setRecurrenceID(QDateTime d) 125void Incidence::setRecurrenceID(QDateTime d)
126{ 126{
127 mRecurrenceID = d; 127 mRecurrenceID = d;
128 mHasRecurrenceID = true; 128 mHasRecurrenceID = true;
129 updated(); 129 updated();
130} 130}
131QDateTime Incidence::recurrenceID () const 131QDateTime Incidence::recurrenceID () const
132{ 132{
133 return mRecurrenceID; 133 return mRecurrenceID;
134} 134}
135 135
136bool Incidence::cancelled() const 136bool Incidence::cancelled() const
137{ 137{
138 return mCancelled; 138 return mCancelled;
139} 139}
140void Incidence::setCancelled( bool b ) 140void Incidence::setCancelled( bool b )
141{ 141{
142 mCancelled = b; 142 mCancelled = b;
143 updated(); 143 updated();
144} 144}
145bool Incidence::hasStartDate() const 145bool Incidence::hasStartDate() const
146{ 146{
147 return mHasStartDate; 147 return mHasStartDate;
148} 148}
149 149
150void Incidence::setHasStartDate(bool f) 150void Incidence::setHasStartDate(bool f)
151{ 151{
152 if (mReadOnly) return; 152 if (mReadOnly) return;
153 mHasStartDate = f; 153 mHasStartDate = f;
154 updated(); 154 updated();
155} 155}
156 156
157// A string comparison that considers that null and empty are the same 157// A string comparison that considers that null and empty are the same
158static bool stringCompare( const QString& s1, const QString& s2 ) 158static bool stringCompare( const QString& s1, const QString& s2 )
159{ 159{
160 if ( s1.isEmpty() && s2.isEmpty() ) 160 if ( s1.isEmpty() && s2.isEmpty() )
161 return true; 161 return true;
162 return s1 == s2; 162 return s1 == s2;
163} 163}
164 164
165bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 165bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
166{ 166{
167 167
168 if( i1.alarms().count() != i2.alarms().count() ) { 168 if( i1.alarms().count() != i2.alarms().count() ) {
169 return false; // no need to check further 169 return false; // no need to check further
170 } 170 }
171 if ( i1.alarms().count() > 0 ) { 171 if ( i1.alarms().count() > 0 ) {
172 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) 172 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) )
173 { 173 {
174 qDebug("alarm not equal "); 174 qDebug("alarm not equal ");
175 return false; 175 return false;
176 } 176 }
177 } 177 }
178#if 0 178#if 0
179 QPtrListIterator<Alarm> a1( i1.alarms() ); 179 QPtrListIterator<Alarm> a1( i1.alarms() );
180 QPtrListIterator<Alarm> a2( i2.alarms() ); 180 QPtrListIterator<Alarm> a2( i2.alarms() );
181 for( ; a1.current() && a2.current(); ++a1, ++a2 ) { 181 for( ; a1.current() && a2.current(); ++a1, ++a2 ) {
182 if( *a1.current() == *a2.current() ) { 182 if( *a1.current() == *a2.current() ) {
183 continue; 183 continue;
184 } 184 }
185 else { 185 else {
186 return false; 186 return false;
187 } 187 }
188 } 188 }
189#endif 189#endif
190 190
191 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { 191 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) {
192 if ( i1.hasRecurrenceID() ) { 192 if ( i1.hasRecurrenceID() ) {
193 if ( i1.recurrenceID() != i2.recurrenceID() ) 193 if ( i1.recurrenceID() != i2.recurrenceID() )
194 return false; 194 return false;
195 } 195 }
196 196
197 } else { 197 } else {
198 return false; 198 return false;
199 } 199 }
200 200
201 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) 201 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) )
202 return false; 202 return false;
203 if ( i1.hasStartDate() == i2.hasStartDate() ) { 203 if ( i1.hasStartDate() == i2.hasStartDate() ) {
204 if ( i1.hasStartDate() ) { 204 if ( i1.hasStartDate() ) {
205 if ( i1.dtStart() != i2.dtStart() ) 205 if ( i1.dtStart() != i2.dtStart() )
206 return false; 206 return false;
207 } 207 }
208 } else { 208 } else {
209 return false; 209 return false;
210 } 210 }
211 if (!( *i1.recurrence() == *i2.recurrence()) ) { 211 if (!( *i1.recurrence() == *i2.recurrence()) ) {
212 qDebug("recurrence is NOT equal "); 212 qDebug("recurrence is NOT equal ");
213 return false; 213 return false;
214 } 214 }
215 return 215 return
216 // i1.created() == i2.created() && 216 // i1.created() == i2.created() &&
217 stringCompare( i1.description(), i2.description() ) && 217 stringCompare( i1.description(), i2.description() ) &&
218 stringCompare( i1.summary(), i2.summary() ) && 218 stringCompare( i1.summary(), i2.summary() ) &&
219 i1.categories() == i2.categories() && 219 i1.categories() == i2.categories() &&
220 // no need to compare mRelatedTo 220 // no need to compare mRelatedTo
221 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && 221 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) &&
222 // i1.relations() == i2.relations() && 222 // i1.relations() == i2.relations() &&
223 i1.exDates() == i2.exDates() && 223 i1.exDates() == i2.exDates() &&
224 i1.attachments() == i2.attachments() && 224 i1.attachments() == i2.attachments() &&
225 i1.resources() == i2.resources() && 225 i1.resources() == i2.resources() &&
226 i1.secrecy() == i2.secrecy() && 226 i1.secrecy() == i2.secrecy() &&
227 i1.priority() == i2.priority() && 227 i1.priority() == i2.priority() &&
228 i1.cancelled() == i2.cancelled() && 228 i1.cancelled() == i2.cancelled() &&
229 stringCompare( i1.location(), i2.location() ); 229 stringCompare( i1.location(), i2.location() );
230} 230}
231 231
232Incidence* Incidence::recreateCloneException( QDate d ) 232Incidence* Incidence::recreateCloneException( QDate d )
233{ 233{
234 Incidence* newInc = clone(); 234 Incidence* newInc = clone();
235 newInc->recreate(); 235 newInc->recreate();
236 if ( doesRecur() ) { 236 if ( doesRecur() ) {
237 addExDate( d ); 237 addExDate( d );
238 newInc->recurrence()->unsetRecurs(); 238 newInc->recurrence()->unsetRecurs();
239 if ( typeID() == eventID ) { 239 if ( typeID() == eventID ) {
240 int len = dtStart().secsTo( ((Event*)this)->dtEnd()); 240 int len = dtStart().secsTo( ((Event*)this)->dtEnd());
241 QTime tim = dtStart().time(); 241 QTime tim = dtStart().time();
242 newInc->setDtStart( QDateTime(d, tim) ); 242 newInc->setDtStart( QDateTime(d, tim) );
243 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 243 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
244 } else { 244 } else {
245 int len = dtStart().secsTo( ((Todo*)this)->dtDue()); 245 int len = dtStart().secsTo( ((Todo*)this)->dtDue());
246 QTime tim = ((Todo*)this)->dtDue().time(); 246 QTime tim = ((Todo*)this)->dtDue().time();
247 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); 247 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) );
248 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); 248 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) );
249 ((Todo*)this)->setRecurDates(); 249 ((Todo*)this)->setRecurDates();
250 } 250 }
251 newInc->setExDates( DateList () ); 251 newInc->setExDates( DateList () );
252 } 252 }
253 return newInc; 253 return newInc;
254} 254}
255 255
256void Incidence::recreate() 256void Incidence::recreate()
257{ 257{
258 setCreated(QDateTime::currentDateTime()); 258 setCreated(QDateTime::currentDateTime());
259 259
260 setUid(CalFormat::createUniqueId()); 260 setUid(CalFormat::createUniqueId());
261 261
262 setRevision(0); 262 setRevision(0);
263 setIDStr( ":" ); 263 setIDStr( ":" );
264 setLastModified(QDateTime::currentDateTime()); 264 setLastModified(QDateTime::currentDateTime());
265} 265}
266void Incidence::cloneRelations( Incidence * newInc ) 266void Incidence::cloneRelations( Incidence * newInc )
267{ 267{
268 // newInc is already a clone of this incidence 268 // newInc is already a clone of this incidence
269 Incidence * inc; 269 Incidence * inc;
270 Incidence * cloneInc; 270 Incidence * cloneInc;
271 QPtrList<Incidence> Relations = relations(); 271 QPtrList<Incidence> Relations = relations();
272 for (inc=Relations.first();inc;inc=Relations.next()) { 272 for (inc=Relations.first();inc;inc=Relations.next()) {
273 cloneInc = inc->clone(); 273 cloneInc = inc->clone();
274 cloneInc->recreate(); 274 cloneInc->recreate();
275 cloneInc->setRelatedTo( newInc ); 275 cloneInc->setRelatedTo( newInc );
276 inc->cloneRelations( cloneInc ); 276 inc->cloneRelations( cloneInc );
277 } 277 }
278} 278}
279void Incidence::setReadOnly( bool readOnly ) 279void Incidence::setReadOnly( bool readOnly )
280{ 280{
281 IncidenceBase::setReadOnly( readOnly ); 281 IncidenceBase::setReadOnly( readOnly );
282 recurrence()->setRecurReadOnly( readOnly); 282 recurrence()->setRecurReadOnly( readOnly);
283} 283}
284 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// using this makes filtering 3 times faster
400QStringList* Incidence::categoriesP()
401{
402 return &mCategories;
403}
399 404
400QStringList Incidence::categories() const 405QStringList Incidence::categories() const
401{ 406{
402 return mCategories; 407 return mCategories;
403} 408}
404 409
405QString Incidence::categoriesStr() 410QString Incidence::categoriesStr()
406{ 411{
407 return mCategories.join(","); 412 return mCategories.join(",");
408} 413}
409QString Incidence::categoriesStrWithSpace() 414QString Incidence::categoriesStrWithSpace()
410{ 415{
411 return mCategories.join(", "); 416 return mCategories.join(", ");
412} 417}
413 418
414void Incidence::setRelatedToUid(const QString &relatedToUid) 419void Incidence::setRelatedToUid(const QString &relatedToUid)
415{ 420{
416 if (mReadOnly) return; 421 if (mReadOnly) return;
417 mRelatedToUid = relatedToUid; 422 mRelatedToUid = relatedToUid;
418} 423}
419 424
420QString Incidence::relatedToUid() const 425QString Incidence::relatedToUid() const
421{ 426{
422 return mRelatedToUid; 427 return mRelatedToUid;
423} 428}
424 429
425void Incidence::setRelatedTo(Incidence *relatedTo) 430void Incidence::setRelatedTo(Incidence *relatedTo)
426{ 431{
427 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 432 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
428 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 433 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
429 if (mReadOnly || mRelatedTo == relatedTo) return; 434 if (mReadOnly || mRelatedTo == relatedTo) return;
430 if(mRelatedTo) { 435 if(mRelatedTo) {
431 // updated(); 436 // updated();
432 mRelatedTo->removeRelation(this); 437 mRelatedTo->removeRelation(this);
433 } 438 }
434 mRelatedTo = relatedTo; 439 mRelatedTo = relatedTo;
435 if (mRelatedTo) { 440 if (mRelatedTo) {
436 mRelatedTo->addRelation(this); 441 mRelatedTo->addRelation(this);
437 mRelatedToUid = mRelatedTo->uid(); 442 mRelatedToUid = mRelatedTo->uid();
438 } else { 443 } else {
439 mRelatedToUid = ""; 444 mRelatedToUid = "";
440 } 445 }
441} 446}
442 447
443Incidence *Incidence::relatedTo() const 448Incidence *Incidence::relatedTo() const
444{ 449{
445 return mRelatedTo; 450 return mRelatedTo;
446} 451}
447 452
448QPtrList<Incidence> Incidence::relations() const 453QPtrList<Incidence> Incidence::relations() const
449{ 454{
450 return mRelations; 455 return mRelations;
451} 456}
452 457
453void Incidence::addRelationsToList(QPtrList<Incidence> *rel) 458void Incidence::addRelationsToList(QPtrList<Incidence> *rel)
454{ 459{
455 Incidence* inc; 460 Incidence* inc;
456 QPtrList<Incidence> Relations = relations(); 461 QPtrList<Incidence> Relations = relations();
457 for (inc=Relations.first();inc;inc=Relations.next()) { 462 for (inc=Relations.first();inc;inc=Relations.next()) {
458 inc->addRelationsToList( rel ); 463 inc->addRelationsToList( rel );
459 } 464 }
460 if ( rel->findRef( this ) == -1 ) 465 if ( rel->findRef( this ) == -1 )
461 rel->append( this ); 466 rel->append( this );
462} 467}
463 468
464void Incidence::addRelation(Incidence *event) 469void Incidence::addRelation(Incidence *event)
465{ 470{
466 if( mRelations.findRef( event ) == -1 ) { 471 if( mRelations.findRef( event ) == -1 ) {
467 mRelations.append(event); 472 mRelations.append(event);
468 //updated(); 473 //updated();
469 } 474 }
470} 475}
471 476
472void Incidence::removeRelation(Incidence *event) 477void Incidence::removeRelation(Incidence *event)
473{ 478{
474 479
475 mRelations.removeRef(event); 480 mRelations.removeRef(event);
476 481
477// if (event->getRelatedTo() == this) event->setRelatedTo(0); 482// if (event->getRelatedTo() == this) event->setRelatedTo(0);
478} 483}
479 484
480bool Incidence::recursOn(const QDate &qd) const 485bool Incidence::recursOn(const QDate &qd) const
481{ 486{
482 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; 487 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true;
483 else return false; 488 else return false;
484} 489}
485 490
486void Incidence::setExDates(const DateList &exDates) 491void Incidence::setExDates(const DateList &exDates)
487{ 492{
488 if (mReadOnly) return; 493 if (mReadOnly) return;
489 mExDates = exDates; 494 mExDates = exDates;
490 495
491 recurrence()->setRecurExDatesCount(mExDates.count()); 496 recurrence()->setRecurExDatesCount(mExDates.count());
492 497
493 updated(); 498 updated();
494} 499}
495 500
496void Incidence::addExDate(const QDate &date) 501void Incidence::addExDate(const QDate &date)
497{ 502{
498 if (mReadOnly) return; 503 if (mReadOnly) return;
499 mExDates.append(date); 504 mExDates.append(date);
500 505
501 recurrence()->setRecurExDatesCount(mExDates.count()); 506 recurrence()->setRecurExDatesCount(mExDates.count());
502 507
503 updated(); 508 updated();
504} 509}
505 510
506DateList Incidence::exDates() const 511DateList Incidence::exDates() const
507{ 512{
508 return mExDates; 513 return mExDates;
509} 514}
510 515
511bool Incidence::isException(const QDate &date) const 516bool Incidence::isException(const QDate &date) const
512{ 517{
513 DateList::ConstIterator it; 518 DateList::ConstIterator it;
514 for( it = mExDates.begin(); it != mExDates.end(); ++it ) { 519 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
515 if ( (*it) == date ) { 520 if ( (*it) == date ) {
516 return true; 521 return true;
517 } 522 }
518 } 523 }
519 524
520 return false; 525 return false;
521} 526}
522 527
523void Incidence::addAttachment(Attachment *attachment) 528void Incidence::addAttachment(Attachment *attachment)
524{ 529{
525 if (mReadOnly || !attachment) return; 530 if (mReadOnly || !attachment) return;
526 mAttachments.append(attachment); 531 mAttachments.append(attachment);
527 updated(); 532 updated();
528} 533}
529 534
530void Incidence::deleteAttachment(Attachment *attachment) 535void Incidence::deleteAttachment(Attachment *attachment)
531{ 536{
532 mAttachments.removeRef(attachment); 537 mAttachments.removeRef(attachment);
533} 538}
534 539
535void Incidence::deleteAttachments(const QString& mime) 540void Incidence::deleteAttachments(const QString& mime)
536{ 541{
537 Attachment *at = mAttachments.first(); 542 Attachment *at = mAttachments.first();
538 while (at) { 543 while (at) {
539 if (at->mimeType() == mime) 544 if (at->mimeType() == mime)
540 mAttachments.remove(); 545 mAttachments.remove();
541 else 546 else
542 at = mAttachments.next(); 547 at = mAttachments.next();
543 } 548 }
544} 549}
545 550
546QPtrList<Attachment> Incidence::attachments() const 551QPtrList<Attachment> Incidence::attachments() const
547{ 552{
548 return mAttachments; 553 return mAttachments;
549} 554}
550 555
551QPtrList<Attachment> Incidence::attachments(const QString& mime) const 556QPtrList<Attachment> Incidence::attachments(const QString& mime) const
552{ 557{
553 QPtrList<Attachment> attachments; 558 QPtrList<Attachment> attachments;
554 QPtrListIterator<Attachment> it( mAttachments ); 559 QPtrListIterator<Attachment> it( mAttachments );
555 Attachment *at; 560 Attachment *at;
556 while ( (at = it.current()) ) { 561 while ( (at = it.current()) ) {
557 if (at->mimeType() == mime) 562 if (at->mimeType() == mime)
558 attachments.append(at); 563 attachments.append(at);
559 ++it; 564 ++it;
560 } 565 }
561 566
562 return attachments; 567 return attachments;
563} 568}
564 569
565void Incidence::setResources(const QStringList &resources) 570void Incidence::setResources(const QStringList &resources)
566{ 571{
567 if (mReadOnly) return; 572 if (mReadOnly) return;
568 mResources = resources; 573 mResources = resources;
569 updated(); 574 updated();
570} 575}
571 576
572QStringList Incidence::resources() const 577QStringList Incidence::resources() const
573{ 578{
574 return mResources; 579 return mResources;
575} 580}
576 581
577 582
578void Incidence::setPriority(int priority) 583void Incidence::setPriority(int priority)
579{ 584{
580 if (mReadOnly) return; 585 if (mReadOnly) return;
581 mPriority = priority; 586 mPriority = priority;
582 updated(); 587 updated();
583} 588}
584 589
585int Incidence::priority() const 590int Incidence::priority() const
586{ 591{
587 return mPriority; 592 return mPriority;
588} 593}
589 594
590void Incidence::setSecrecy(int sec) 595void Incidence::setSecrecy(int sec)
591{ 596{
592 if (mReadOnly) return; 597 if (mReadOnly) return;
593 mSecrecy = sec; 598 mSecrecy = sec;
594 updated(); 599 updated();
595} 600}
596 601
597int Incidence::secrecy() const 602int Incidence::secrecy() const
598{ 603{
599 return mSecrecy; 604 return mSecrecy;
600} 605}
601 606
602QString Incidence::secrecyStr() const 607QString Incidence::secrecyStr() const
603{ 608{
604 return secrecyName(mSecrecy); 609 return secrecyName(mSecrecy);
605} 610}
606 611
607QString Incidence::secrecyName(int secrecy) 612QString Incidence::secrecyName(int secrecy)
608{ 613{
609 switch (secrecy) { 614 switch (secrecy) {
610 case SecrecyPublic: 615 case SecrecyPublic:
611 return i18n("Public"); 616 return i18n("Public");
612 break; 617 break;
613 case SecrecyPrivate: 618 case SecrecyPrivate:
614 return i18n("Private"); 619 return i18n("Private");
615 break; 620 break;
616 case SecrecyConfidential: 621 case SecrecyConfidential:
617 return i18n("Confidential"); 622 return i18n("Confidential");
618 break; 623 break;
619 default: 624 default:
620 return i18n("Undefined"); 625 return i18n("Undefined");
621 break; 626 break;
622 } 627 }
623} 628}
624 629
625QStringList Incidence::secrecyList() 630QStringList Incidence::secrecyList()
626{ 631{
627 QStringList list; 632 QStringList list;
628 list << secrecyName(SecrecyPublic); 633 list << secrecyName(SecrecyPublic);
629 list << secrecyName(SecrecyPrivate); 634 list << secrecyName(SecrecyPrivate);
630 list << secrecyName(SecrecyConfidential); 635 list << secrecyName(SecrecyConfidential);
631 636
632 return list; 637 return list;
633} 638}
634 639
635 640
636QPtrList<Alarm> Incidence::alarms() const 641QPtrList<Alarm> Incidence::alarms() const
637{ 642{
638 return mAlarms; 643 return mAlarms;
639} 644}
640 645
641Alarm* Incidence::newAlarm() 646Alarm* Incidence::newAlarm()
642{ 647{
643 Alarm* alarm = new Alarm(this); 648 Alarm* alarm = new Alarm(this);
644 mAlarms.append(alarm); 649 mAlarms.append(alarm);
645// updated(); 650// updated();
646 return alarm; 651 return alarm;
647} 652}
648 653
649void Incidence::addAlarm(Alarm *alarm) 654void Incidence::addAlarm(Alarm *alarm)
650{ 655{
651 mAlarms.append(alarm); 656 mAlarms.append(alarm);
652 updated(); 657 updated();
653} 658}
654 659
655void Incidence::removeAlarm(Alarm *alarm) 660void Incidence::removeAlarm(Alarm *alarm)
656{ 661{
657 mAlarms.removeRef(alarm); 662 mAlarms.removeRef(alarm);
658 updated(); 663 updated();
659} 664}
660 665
661void Incidence::clearAlarms() 666void Incidence::clearAlarms()
662{ 667{
663 mAlarms.clear(); 668 mAlarms.clear();
664 updated(); 669 updated();
665} 670}
666 671
667bool Incidence::isAlarmEnabled() const 672bool Incidence::isAlarmEnabled() const
668{ 673{
669 Alarm* alarm; 674 Alarm* alarm;
670 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 675 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
671 if (alarm->enabled()) 676 if (alarm->enabled())
672 return true; 677 return true;
673 } 678 }
674 return false; 679 return false;
675} 680}
676 681
677Recurrence *Incidence::recurrence() const 682Recurrence *Incidence::recurrence() const
678{ 683{
679 return mRecurrence; 684 return mRecurrence;
680} 685}
681void Incidence::setRecurrence( Recurrence * r) 686void Incidence::setRecurrence( Recurrence * r)
682{ 687{
683 delete mRecurrence; 688 delete mRecurrence;
684 mRecurrence = r; 689 mRecurrence = r;
685} 690}
686 691
687void Incidence::setLocation(const QString &location) 692void Incidence::setLocation(const QString &location)
688{ 693{
689 if (mReadOnly) return; 694 if (mReadOnly) return;
690 mLocation = location; 695 mLocation = location;
691 updated(); 696 updated();
692} 697}
693 698
694QString Incidence::location() const 699QString Incidence::location() const
695{ 700{
696 return mLocation; 701 return mLocation;
697} 702}
698 703
699ushort Incidence::doesRecur() const 704ushort Incidence::doesRecur() const
700{ 705{
701 if ( mRecurrence ) return mRecurrence->doesRecur(); 706 if ( mRecurrence ) return mRecurrence->doesRecur();
702 else return Recurrence::rNone; 707 else return Recurrence::rNone;
703} 708}
704 709
705QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const 710QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const
706{ 711{
707 QDateTime incidenceStart = dt; 712 QDateTime incidenceStart = dt;
708 *ok = false; 713 *ok = false;
709 if ( doesRecur() ) { 714 if ( doesRecur() ) {
710 bool last; 715 bool last;
711 recurrence()->getPreviousDateTime( incidenceStart , &last ); 716 recurrence()->getPreviousDateTime( incidenceStart , &last );
712 int count = 0; 717 int count = 0;
713 if ( !last ) { 718 if ( !last ) {
714 while ( !last ) { 719 while ( !last ) {
715 ++count; 720 ++count;
716 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); 721 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last );
717 if ( recursOn( incidenceStart.date() ) ) { 722 if ( recursOn( incidenceStart.date() ) ) {
718 last = true; // exit while llop 723 last = true; // exit while llop
719 } else { 724 } else {
720 if ( last ) { // no alarm on last recurrence 725 if ( last ) { // no alarm on last recurrence
721 return QDateTime (); 726 return QDateTime ();
722 } 727 }
723 int year = incidenceStart.date().year(); 728 int year = incidenceStart.date().year();
724 // workaround for bug in recurrence 729 // workaround for bug in recurrence
725 if ( count == 100 || year < 1000 || year > 5000 ) { 730 if ( count == 100 || year < 1000 || year > 5000 ) {
726 return QDateTime (); 731 return QDateTime ();
727 } 732 }
728 incidenceStart = incidenceStart.addSecs( 1 ); 733 incidenceStart = incidenceStart.addSecs( 1 );
729 } 734 }
730 } 735 }
731 } else { 736 } else {
732 return QDateTime (); 737 return QDateTime ();
733 } 738 }
734 } else { 739 } else {
735 if ( hasStartDate () ) { 740 if ( hasStartDate () ) {
736 incidenceStart = dtStart(); 741 incidenceStart = dtStart();
737 } 742 }
738 if ( typeID() == todoID ) { 743 if ( typeID() == todoID ) {
739 if ( ((Todo*)this)->hasDueDate() ) 744 if ( ((Todo*)this)->hasDueDate() )
740 incidenceStart = ((Todo*)this)->dtDue(); 745 incidenceStart = ((Todo*)this)->dtDue();
741 } 746 }
742 } 747 }
743 if ( incidenceStart > dt ) 748 if ( incidenceStart > dt )
744 *ok = true; 749 *ok = true;
745 return incidenceStart; 750 return incidenceStart;
746} 751}
747QDateTime Incidence::dtStart() const 752QDateTime Incidence::dtStart() const
748{ 753{
749 if ( doesRecur() ) { 754 if ( doesRecur() ) {
750 if ( typeID() == todoID ) { 755 if ( typeID() == todoID ) {
751 ((Todo*)this)->checkSetCompletedFalse(); 756 ((Todo*)this)->checkSetCompletedFalse();
752 } 757 }
753 } 758 }
754 return mDtStart; 759 return mDtStart;
755} 760}