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