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