-rw-r--r-- | libkcal/incidence.cpp | 63 |
1 files changed, 47 insertions, 16 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index e4bcc5e..4643a3a 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,144 +1,148 @@ | |||
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 | ||
30 | using namespace KCal; | 30 | using namespace KCal; |
31 | 31 | ||
32 | Incidence::Incidence() : | 32 | Incidence::Incidence() : |
33 | IncidenceBase(), | 33 | IncidenceBase(), |
34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) | 34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) |
35 | { | 35 | { |
36 | mRecurrence = new Recurrence(this); | 36 | mRecurrence = 0;//new Recurrence(this); |
37 | mCancelled = false; | 37 | mCancelled = false; |
38 | recreate(); | 38 | recreate(); |
39 | mHasStartDate = true; | 39 | mHasStartDate = true; |
40 | mAlarms.setAutoDelete(true); | 40 | mAlarms.setAutoDelete(true); |
41 | mAttachments.setAutoDelete(true); | 41 | mAttachments.setAutoDelete(true); |
42 | mHasRecurrenceID = false; | 42 | mHasRecurrenceID = false; |
43 | mHoliday = false; | 43 | mHoliday = false; |
44 | mBirthday = false; | 44 | mBirthday = false; |
45 | mAnniversary = false; | 45 | mAnniversary = false; |
46 | 46 | ||
47 | } | 47 | } |
48 | 48 | ||
49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
50 | { | 50 | { |
51 | // TODO: reenable attributes currently commented out. | 51 | // TODO: reenable attributes currently commented out. |
52 | mRevision = i.mRevision; | 52 | mRevision = i.mRevision; |
53 | mCreated = i.mCreated; | 53 | mCreated = i.mCreated; |
54 | mDescription = i.mDescription; | 54 | mDescription = i.mDescription; |
55 | mSummary = i.mSummary; | 55 | mSummary = i.mSummary; |
56 | mCategories = i.mCategories; | 56 | mCategories = i.mCategories; |
57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
58 | mRelatedTo = 0; | 58 | mRelatedTo = 0; |
59 | mRelatedToUid = i.mRelatedToUid; | 59 | mRelatedToUid = i.mRelatedToUid; |
60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
61 | mExDates = i.mExDates; | 61 | mExDates = i.mExDates; |
62 | mAttachments = i.mAttachments; | 62 | mAttachments = i.mAttachments; |
63 | mResources = i.mResources; | 63 | mResources = i.mResources; |
64 | mSecrecy = i.mSecrecy; | 64 | mSecrecy = i.mSecrecy; |
65 | mPriority = i.mPriority; | 65 | mPriority = i.mPriority; |
66 | mLocation = i.mLocation; | 66 | mLocation = i.mLocation; |
67 | mCancelled = i.mCancelled; | 67 | mCancelled = i.mCancelled; |
68 | mHasStartDate = i.mHasStartDate; | 68 | mHasStartDate = i.mHasStartDate; |
69 | QPtrListIterator<Alarm> it( i.mAlarms ); | 69 | QPtrListIterator<Alarm> it( i.mAlarms ); |
70 | const Alarm *a; | 70 | const Alarm *a; |
71 | while( (a = it.current()) ) { | 71 | while( (a = it.current()) ) { |
72 | Alarm *b = new Alarm( *a ); | 72 | Alarm *b = new Alarm( *a ); |
73 | b->setParent( this ); | 73 | b->setParent( this ); |
74 | mAlarms.append( b ); | 74 | mAlarms.append( b ); |
75 | 75 | ||
76 | ++it; | 76 | ++it; |
77 | } | 77 | } |
78 | mAlarms.setAutoDelete(true); | 78 | mAlarms.setAutoDelete(true); |
79 | mHasRecurrenceID = i.mHasRecurrenceID; | 79 | mHasRecurrenceID = i.mHasRecurrenceID; |
80 | mRecurrenceID = i.mRecurrenceID; | 80 | mRecurrenceID = i.mRecurrenceID; |
81 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 81 | if ( i.mRecurrence ) |
82 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | ||
83 | else | ||
84 | mRecurrence = 0; | ||
82 | mHoliday = i.mHoliday ; | 85 | mHoliday = i.mHoliday ; |
83 | mBirthday = i.mBirthday; | 86 | mBirthday = i.mBirthday; |
84 | mAnniversary = i.mAnniversary; | 87 | mAnniversary = i.mAnniversary; |
85 | } | 88 | } |
86 | 89 | ||
87 | Incidence::~Incidence() | 90 | Incidence::~Incidence() |
88 | { | 91 | { |
89 | 92 | ||
90 | Incidence *ev; | 93 | Incidence *ev; |
91 | QPtrList<Incidence> Relations = relations(); | 94 | QPtrList<Incidence> Relations = relations(); |
92 | for (ev=Relations.first();ev;ev=Relations.next()) { | 95 | for (ev=Relations.first();ev;ev=Relations.next()) { |
93 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 96 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
94 | } | 97 | } |
95 | if (relatedTo()) relatedTo()->removeRelation(this); | 98 | if (relatedTo()) relatedTo()->removeRelation(this); |
96 | delete mRecurrence; | 99 | if ( mRecurrence ) |
100 | delete mRecurrence; | ||
97 | 101 | ||
98 | } | 102 | } |
99 | 103 | ||
100 | bool Incidence::isHoliday() const | 104 | bool Incidence::isHoliday() const |
101 | { | 105 | { |
102 | return mHoliday; | 106 | return mHoliday; |
103 | } | 107 | } |
104 | bool Incidence::isBirthday() const | 108 | bool Incidence::isBirthday() const |
105 | { | 109 | { |
106 | 110 | ||
107 | return mBirthday ; | 111 | return mBirthday ; |
108 | } | 112 | } |
109 | bool Incidence::isAnniversary() const | 113 | bool Incidence::isAnniversary() const |
110 | { | 114 | { |
111 | return mAnniversary ; | 115 | return mAnniversary ; |
112 | 116 | ||
113 | } | 117 | } |
114 | 118 | ||
115 | bool Incidence::hasRecurrenceID() const | 119 | bool Incidence::hasRecurrenceID() const |
116 | { | 120 | { |
117 | return mHasRecurrenceID; | 121 | return mHasRecurrenceID; |
118 | } | 122 | } |
119 | 123 | ||
120 | void Incidence::setHasRecurrenceID( bool b ) | 124 | void Incidence::setHasRecurrenceID( bool b ) |
121 | { | 125 | { |
122 | mHasRecurrenceID = b; | 126 | mHasRecurrenceID = b; |
123 | } | 127 | } |
124 | 128 | ||
125 | void Incidence::setRecurrenceID(QDateTime d) | 129 | void Incidence::setRecurrenceID(QDateTime d) |
126 | { | 130 | { |
127 | mRecurrenceID = d; | 131 | mRecurrenceID = d; |
128 | mHasRecurrenceID = true; | 132 | mHasRecurrenceID = true; |
129 | updated(); | 133 | updated(); |
130 | } | 134 | } |
131 | QDateTime Incidence::recurrenceID () const | 135 | QDateTime Incidence::recurrenceID () const |
132 | { | 136 | { |
133 | return mRecurrenceID; | 137 | return mRecurrenceID; |
134 | } | 138 | } |
135 | 139 | ||
136 | bool Incidence::cancelled() const | 140 | bool Incidence::cancelled() const |
137 | { | 141 | { |
138 | return mCancelled; | 142 | return mCancelled; |
139 | } | 143 | } |
140 | void Incidence::setCancelled( bool b ) | 144 | void Incidence::setCancelled( bool b ) |
141 | { | 145 | { |
142 | mCancelled = b; | 146 | mCancelled = b; |
143 | updated(); | 147 | updated(); |
144 | } | 148 | } |
@@ -163,219 +167,236 @@ static bool stringCompare( const QString& s1, const QString& s2 ) | |||
163 | } | 167 | } |
164 | 168 | ||
165 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | 169 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) |
166 | { | 170 | { |
167 | 171 | ||
168 | if( i1.alarms().count() != i2.alarms().count() ) { | 172 | if( i1.alarms().count() != i2.alarms().count() ) { |
169 | return false; // no need to check further | 173 | return false; // no need to check further |
170 | } | 174 | } |
171 | if ( i1.alarms().count() > 0 ) { | 175 | if ( i1.alarms().count() > 0 ) { |
172 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) | 176 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) |
173 | { | 177 | { |
174 | qDebug("alarm not equal "); | 178 | qDebug("alarm not equal "); |
175 | return false; | 179 | return false; |
176 | } | 180 | } |
177 | } | 181 | } |
178 | #if 0 | 182 | #if 0 |
179 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 183 | QPtrListIterator<Alarm> a1( i1.alarms() ); |
180 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 184 | QPtrListIterator<Alarm> a2( i2.alarms() ); |
181 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 185 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
182 | if( *a1.current() == *a2.current() ) { | 186 | if( *a1.current() == *a2.current() ) { |
183 | continue; | 187 | continue; |
184 | } | 188 | } |
185 | else { | 189 | else { |
186 | return false; | 190 | return false; |
187 | } | 191 | } |
188 | } | 192 | } |
189 | #endif | 193 | #endif |
190 | 194 | ||
191 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { | 195 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { |
192 | if ( i1.hasRecurrenceID() ) { | 196 | if ( i1.hasRecurrenceID() ) { |
193 | if ( i1.recurrenceID() != i2.recurrenceID() ) | 197 | if ( i1.recurrenceID() != i2.recurrenceID() ) |
194 | return false; | 198 | return false; |
195 | } | 199 | } |
196 | 200 | ||
197 | } else { | 201 | } else { |
198 | return false; | 202 | return false; |
199 | } | 203 | } |
200 | 204 | ||
201 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 205 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
202 | return false; | 206 | return false; |
203 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 207 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
204 | if ( i1.hasStartDate() ) { | 208 | if ( i1.hasStartDate() ) { |
205 | if ( i1.dtStart() != i2.dtStart() ) | 209 | if ( i1.dtStart() != i2.dtStart() ) |
206 | return false; | 210 | return false; |
207 | } | 211 | } |
208 | } else { | 212 | } else { |
209 | return false; | 213 | return false; |
210 | } | 214 | } |
211 | if (!( *i1.recurrence() == *i2.recurrence()) ) { | 215 | if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { |
212 | qDebug("recurrence is NOT equal "); | 216 | if (!( *i1.mRecurrence == *i2.mRecurrence) ) { |
213 | return false; | 217 | //qDebug("recurrence is NOT equal "); |
218 | return false; | ||
219 | } | ||
220 | } else { | ||
221 | // one ( or both ) recurrence is 0 | ||
222 | if ( i1.mRecurrence == 0 ) { | ||
223 | if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) | ||
224 | return false; | ||
225 | } else { | ||
226 | // i1.mRecurrence != 0 | ||
227 | // i2.mRecurrence == 0 | ||
228 | if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) | ||
229 | return false; | ||
230 | } | ||
214 | } | 231 | } |
232 | |||
215 | return | 233 | return |
216 | // i1.created() == i2.created() && | 234 | // i1.created() == i2.created() && |
217 | stringCompare( i1.description(), i2.description() ) && | 235 | stringCompare( i1.description(), i2.description() ) && |
218 | stringCompare( i1.summary(), i2.summary() ) && | 236 | stringCompare( i1.summary(), i2.summary() ) && |
219 | i1.categories() == i2.categories() && | 237 | i1.categories() == i2.categories() && |
220 | // no need to compare mRelatedTo | 238 | // no need to compare mRelatedTo |
221 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 239 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
222 | // i1.relations() == i2.relations() && | 240 | // i1.relations() == i2.relations() && |
223 | i1.exDates() == i2.exDates() && | 241 | i1.exDates() == i2.exDates() && |
224 | i1.attachments() == i2.attachments() && | 242 | i1.attachments() == i2.attachments() && |
225 | i1.resources() == i2.resources() && | 243 | i1.resources() == i2.resources() && |
226 | i1.secrecy() == i2.secrecy() && | 244 | i1.secrecy() == i2.secrecy() && |
227 | i1.priority() == i2.priority() && | 245 | i1.priority() == i2.priority() && |
228 | i1.cancelled() == i2.cancelled() && | 246 | i1.cancelled() == i2.cancelled() && |
229 | stringCompare( i1.location(), i2.location() ); | 247 | stringCompare( i1.location(), i2.location() ); |
230 | } | 248 | } |
231 | 249 | ||
232 | Incidence* Incidence::recreateCloneException( QDate d ) | 250 | Incidence* Incidence::recreateCloneException( QDate d ) |
233 | { | 251 | { |
234 | Incidence* newInc = clone(); | 252 | Incidence* newInc = clone(); |
235 | newInc->recreate(); | 253 | newInc->recreate(); |
236 | if ( doesRecur() ) { | 254 | if ( doesRecur() ) { |
237 | addExDate( d ); | 255 | addExDate( d ); |
238 | newInc->recurrence()->unsetRecurs(); | 256 | newInc->recurrence()->unsetRecurs(); |
239 | if ( typeID() == eventID ) { | 257 | if ( typeID() == eventID ) { |
240 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); | 258 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); |
241 | QTime tim = dtStart().time(); | 259 | QTime tim = dtStart().time(); |
242 | newInc->setDtStart( QDateTime(d, tim) ); | 260 | newInc->setDtStart( QDateTime(d, tim) ); |
243 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | 261 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); |
244 | } else { | 262 | } else { |
245 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); | 263 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); |
246 | QTime tim = ((Todo*)this)->dtDue().time(); | 264 | QTime tim = ((Todo*)this)->dtDue().time(); |
247 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); | 265 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); |
248 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); | 266 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); |
249 | ((Todo*)this)->setRecurDates(); | 267 | ((Todo*)this)->setRecurDates(); |
250 | } | 268 | } |
251 | newInc->setExDates( DateList () ); | 269 | newInc->setExDates( DateList () ); |
252 | } | 270 | } |
253 | return newInc; | 271 | return newInc; |
254 | } | 272 | } |
255 | 273 | ||
256 | void Incidence::recreate() | 274 | void Incidence::recreate() |
257 | { | 275 | { |
258 | setCreated(QDateTime::currentDateTime()); | 276 | setCreated(QDateTime::currentDateTime()); |
259 | 277 | ||
260 | setUid(CalFormat::createUniqueId()); | 278 | setUid(CalFormat::createUniqueId()); |
261 | 279 | ||
262 | setRevision(0); | 280 | setRevision(0); |
263 | setIDStr( ":" ); | 281 | setIDStr( ":" ); |
264 | setLastModified(QDateTime::currentDateTime()); | 282 | setLastModified(QDateTime::currentDateTime()); |
265 | } | 283 | } |
266 | void Incidence::cloneRelations( Incidence * newInc ) | 284 | void Incidence::cloneRelations( Incidence * newInc ) |
267 | { | 285 | { |
268 | // newInc is already a clone of this incidence | 286 | // newInc is already a clone of this incidence |
269 | Incidence * inc; | 287 | Incidence * inc; |
270 | Incidence * cloneInc; | 288 | Incidence * cloneInc; |
271 | QPtrList<Incidence> Relations = relations(); | 289 | QPtrList<Incidence> Relations = relations(); |
272 | for (inc=Relations.first();inc;inc=Relations.next()) { | 290 | for (inc=Relations.first();inc;inc=Relations.next()) { |
273 | cloneInc = inc->clone(); | 291 | cloneInc = inc->clone(); |
274 | cloneInc->recreate(); | 292 | cloneInc->recreate(); |
275 | cloneInc->setRelatedTo( newInc ); | 293 | cloneInc->setRelatedTo( newInc ); |
276 | inc->cloneRelations( cloneInc ); | 294 | inc->cloneRelations( cloneInc ); |
277 | } | 295 | } |
278 | } | 296 | } |
279 | void Incidence::setReadOnly( bool readOnly ) | 297 | void Incidence::setReadOnly( bool readOnly ) |
280 | { | 298 | { |
281 | IncidenceBase::setReadOnly( readOnly ); | 299 | IncidenceBase::setReadOnly( readOnly ); |
282 | recurrence()->setRecurReadOnly( readOnly); | 300 | if ( mRecurrence ) |
301 | mRecurrence->setRecurReadOnly( readOnly); | ||
283 | } | 302 | } |
284 | void Incidence::setLastModifiedSubInvalid() | 303 | void Incidence::setLastModifiedSubInvalid() |
285 | { | 304 | { |
286 | mLastModifiedSub = QDateTime(); | 305 | mLastModifiedSub = QDateTime(); |
287 | if ( mRelatedTo ) | 306 | if ( mRelatedTo ) |
288 | mRelatedTo->setLastModifiedSubInvalid(); | 307 | mRelatedTo->setLastModifiedSubInvalid(); |
289 | } | 308 | } |
290 | QDateTime Incidence::lastModifiedSub() | 309 | QDateTime Incidence::lastModifiedSub() |
291 | { | 310 | { |
292 | if ( !mRelations.count() ) | 311 | if ( !mRelations.count() ) |
293 | return lastModified(); | 312 | return lastModified(); |
294 | if ( mLastModifiedSub.isValid() ) | 313 | if ( mLastModifiedSub.isValid() ) |
295 | return mLastModifiedSub; | 314 | return mLastModifiedSub; |
296 | mLastModifiedSub = lastModified(); | 315 | mLastModifiedSub = lastModified(); |
297 | Incidence * inc; | 316 | Incidence * inc; |
298 | QPtrList<Incidence> Relations = relations(); | 317 | QPtrList<Incidence> Relations = relations(); |
299 | for (inc=Relations.first();inc;inc=Relations.next()) { | 318 | for (inc=Relations.first();inc;inc=Relations.next()) { |
300 | if ( inc->lastModifiedSub() > mLastModifiedSub ) | 319 | if ( inc->lastModifiedSub() > mLastModifiedSub ) |
301 | mLastModifiedSub = inc->lastModifiedSub(); | 320 | mLastModifiedSub = inc->lastModifiedSub(); |
302 | } | 321 | } |
303 | return mLastModifiedSub; | 322 | return mLastModifiedSub; |
304 | } | 323 | } |
305 | void Incidence::setCreated(QDateTime created) | 324 | void Incidence::setCreated(QDateTime created) |
306 | { | 325 | { |
307 | if (mReadOnly) return; | 326 | if (mReadOnly) return; |
308 | mCreated = getEvenTime(created); | 327 | mCreated = getEvenTime(created); |
309 | } | 328 | } |
310 | 329 | ||
311 | QDateTime Incidence::created() const | 330 | QDateTime Incidence::created() const |
312 | { | 331 | { |
313 | return mCreated; | 332 | return mCreated; |
314 | } | 333 | } |
315 | 334 | ||
316 | void Incidence::setRevision(int rev) | 335 | void Incidence::setRevision(int rev) |
317 | { | 336 | { |
318 | if (mReadOnly) return; | 337 | if (mReadOnly) return; |
319 | mRevision = rev; | 338 | mRevision = rev; |
320 | 339 | ||
321 | updated(); | 340 | updated(); |
322 | } | 341 | } |
323 | 342 | ||
324 | int Incidence::revision() const | 343 | int Incidence::revision() const |
325 | { | 344 | { |
326 | return mRevision; | 345 | return mRevision; |
327 | } | 346 | } |
328 | 347 | ||
329 | void Incidence::setDtStart(const QDateTime &dtStart) | 348 | void Incidence::setDtStart(const QDateTime &dtStart) |
330 | { | 349 | { |
331 | 350 | ||
332 | QDateTime dt = getEvenTime(dtStart); | 351 | QDateTime dt = getEvenTime(dtStart); |
333 | recurrence()->setRecurStart( dt); | 352 | |
353 | if ( mRecurrence ) | ||
354 | mRecurrence->setRecurStart( dt); | ||
334 | IncidenceBase::setDtStart( dt ); | 355 | IncidenceBase::setDtStart( dt ); |
335 | } | 356 | } |
336 | 357 | ||
337 | void Incidence::setDescription(const QString &description) | 358 | void Incidence::setDescription(const QString &description) |
338 | { | 359 | { |
339 | if (mReadOnly) return; | 360 | if (mReadOnly) return; |
340 | mDescription = description; | 361 | mDescription = description; |
341 | updated(); | 362 | updated(); |
342 | } | 363 | } |
343 | 364 | ||
344 | QString Incidence::description() const | 365 | QString Incidence::description() const |
345 | { | 366 | { |
346 | return mDescription; | 367 | return mDescription; |
347 | } | 368 | } |
348 | 369 | ||
349 | 370 | ||
350 | void Incidence::setSummary(const QString &summary) | 371 | void Incidence::setSummary(const QString &summary) |
351 | { | 372 | { |
352 | if (mReadOnly) return; | 373 | if (mReadOnly) return; |
353 | mSummary = summary; | 374 | mSummary = summary; |
354 | updated(); | 375 | updated(); |
355 | } | 376 | } |
356 | 377 | ||
357 | QString Incidence::summary() const | 378 | QString Incidence::summary() const |
358 | { | 379 | { |
359 | return mSummary; | 380 | return mSummary; |
360 | } | 381 | } |
361 | void Incidence::checkCategories() | 382 | void Incidence::checkCategories() |
362 | { | 383 | { |
363 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); | 384 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); |
364 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); | 385 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); |
365 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); | 386 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); |
366 | } | 387 | } |
367 | 388 | ||
368 | void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false | 389 | void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false |
369 | { | 390 | { |
370 | if (mReadOnly) return; | 391 | if (mReadOnly) return; |
371 | int i; | 392 | int i; |
372 | for( i = 0; i < categories.count(); ++i ) { | 393 | for( i = 0; i < categories.count(); ++i ) { |
373 | if ( !mCategories.contains (categories[i])) | 394 | if ( !mCategories.contains (categories[i])) |
374 | mCategories.append( categories[i] ); | 395 | mCategories.append( categories[i] ); |
375 | } | 396 | } |
376 | checkCategories(); | 397 | checkCategories(); |
377 | updated(); | 398 | updated(); |
378 | if ( addToRelations ) { | 399 | if ( addToRelations ) { |
379 | Incidence * inc; | 400 | Incidence * inc; |
380 | QPtrList<Incidence> Relations = relations(); | 401 | QPtrList<Incidence> Relations = relations(); |
381 | for (inc=Relations.first();inc;inc=Relations.next()) { | 402 | for (inc=Relations.first();inc;inc=Relations.next()) { |
@@ -459,105 +480,104 @@ void Incidence::setRelatedTo(Incidence *relatedTo) | |||
459 | mRelatedTo = relatedTo; | 480 | mRelatedTo = relatedTo; |
460 | if (mRelatedTo) { | 481 | if (mRelatedTo) { |
461 | mRelatedTo->addRelation(this); | 482 | mRelatedTo->addRelation(this); |
462 | mRelatedToUid = mRelatedTo->uid(); | 483 | mRelatedToUid = mRelatedTo->uid(); |
463 | } else { | 484 | } else { |
464 | mRelatedToUid = ""; | 485 | mRelatedToUid = ""; |
465 | } | 486 | } |
466 | } | 487 | } |
467 | 488 | ||
468 | Incidence *Incidence::relatedTo() const | 489 | Incidence *Incidence::relatedTo() const |
469 | { | 490 | { |
470 | return mRelatedTo; | 491 | return mRelatedTo; |
471 | } | 492 | } |
472 | 493 | ||
473 | QPtrList<Incidence> Incidence::relations() const | 494 | QPtrList<Incidence> Incidence::relations() const |
474 | { | 495 | { |
475 | return mRelations; | 496 | return mRelations; |
476 | } | 497 | } |
477 | 498 | ||
478 | void Incidence::addRelationsToList(QPtrList<Incidence> *rel) | 499 | void Incidence::addRelationsToList(QPtrList<Incidence> *rel) |
479 | { | 500 | { |
480 | Incidence* inc; | 501 | Incidence* inc; |
481 | QPtrList<Incidence> Relations = relations(); | 502 | QPtrList<Incidence> Relations = relations(); |
482 | for (inc=Relations.first();inc;inc=Relations.next()) { | 503 | for (inc=Relations.first();inc;inc=Relations.next()) { |
483 | inc->addRelationsToList( rel ); | 504 | inc->addRelationsToList( rel ); |
484 | } | 505 | } |
485 | if ( rel->findRef( this ) == -1 ) | 506 | if ( rel->findRef( this ) == -1 ) |
486 | rel->append( this ); | 507 | rel->append( this ); |
487 | } | 508 | } |
488 | 509 | ||
489 | void Incidence::addRelation(Incidence *event) | 510 | void Incidence::addRelation(Incidence *event) |
490 | { | 511 | { |
491 | setLastModifiedSubInvalid(); | 512 | setLastModifiedSubInvalid(); |
492 | if( mRelations.findRef( event ) == -1 ) { | 513 | if( mRelations.findRef( event ) == -1 ) { |
493 | mRelations.append(event); | 514 | mRelations.append(event); |
494 | //updated(); | 515 | //updated(); |
495 | } | 516 | } |
496 | } | 517 | } |
497 | 518 | ||
498 | void Incidence::removeRelation(Incidence *event) | 519 | void Incidence::removeRelation(Incidence *event) |
499 | { | 520 | { |
500 | setLastModifiedSubInvalid(); | 521 | setLastModifiedSubInvalid(); |
501 | mRelations.removeRef(event); | 522 | mRelations.removeRef(event); |
502 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 523 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
503 | } | 524 | } |
504 | 525 | ||
505 | bool Incidence::recursOn(const QDate &qd) const | 526 | bool Incidence::recursOn(const QDate &qd) const |
506 | { | 527 | { |
507 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; | 528 | if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true; |
508 | else return false; | 529 | else return false; |
509 | } | 530 | } |
510 | 531 | ||
511 | void Incidence::setExDates(const DateList &exDates) | 532 | void Incidence::setExDates(const DateList &exDates) |
512 | { | 533 | { |
513 | if (mReadOnly) return; | 534 | if (mReadOnly) return; |
514 | mExDates = exDates; | 535 | mExDates = exDates; |
515 | |||
516 | recurrence()->setRecurExDatesCount(mExDates.count()); | 536 | recurrence()->setRecurExDatesCount(mExDates.count()); |
517 | 537 | ||
518 | updated(); | 538 | updated(); |
519 | } | 539 | } |
520 | 540 | ||
521 | void Incidence::addExDate(const QDate &date) | 541 | void Incidence::addExDate(const QDate &date) |
522 | { | 542 | { |
523 | if (mReadOnly) return; | 543 | if (mReadOnly) return; |
524 | mExDates.append(date); | 544 | mExDates.append(date); |
525 | 545 | ||
526 | recurrence()->setRecurExDatesCount(mExDates.count()); | 546 | recurrence()->setRecurExDatesCount(mExDates.count()); |
527 | 547 | ||
528 | updated(); | 548 | updated(); |
529 | } | 549 | } |
530 | 550 | ||
531 | DateList Incidence::exDates() const | 551 | DateList Incidence::exDates() const |
532 | { | 552 | { |
533 | return mExDates; | 553 | return mExDates; |
534 | } | 554 | } |
535 | 555 | ||
536 | bool Incidence::isException(const QDate &date) const | 556 | bool Incidence::isException(const QDate &date) const |
537 | { | 557 | { |
538 | DateList::ConstIterator it; | 558 | DateList::ConstIterator it; |
539 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 559 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
540 | if ( (*it) == date ) { | 560 | if ( (*it) == date ) { |
541 | return true; | 561 | return true; |
542 | } | 562 | } |
543 | } | 563 | } |
544 | 564 | ||
545 | return false; | 565 | return false; |
546 | } | 566 | } |
547 | 567 | ||
548 | void Incidence::addAttachment(Attachment *attachment) | 568 | void Incidence::addAttachment(Attachment *attachment) |
549 | { | 569 | { |
550 | if (mReadOnly || !attachment) return; | 570 | if (mReadOnly || !attachment) return; |
551 | mAttachments.append(attachment); | 571 | mAttachments.append(attachment); |
552 | updated(); | 572 | updated(); |
553 | } | 573 | } |
554 | 574 | ||
555 | void Incidence::deleteAttachment(Attachment *attachment) | 575 | void Incidence::deleteAttachment(Attachment *attachment) |
556 | { | 576 | { |
557 | mAttachments.removeRef(attachment); | 577 | mAttachments.removeRef(attachment); |
558 | } | 578 | } |
559 | 579 | ||
560 | void Incidence::deleteAttachments(const QString& mime) | 580 | void Incidence::deleteAttachments(const QString& mime) |
561 | { | 581 | { |
562 | Attachment *at = mAttachments.first(); | 582 | Attachment *at = mAttachments.first(); |
563 | while (at) { | 583 | while (at) { |
@@ -653,128 +673,139 @@ QStringList Incidence::secrecyList() | |||
653 | list << secrecyName(SecrecyPublic); | 673 | list << secrecyName(SecrecyPublic); |
654 | list << secrecyName(SecrecyPrivate); | 674 | list << secrecyName(SecrecyPrivate); |
655 | list << secrecyName(SecrecyConfidential); | 675 | list << secrecyName(SecrecyConfidential); |
656 | 676 | ||
657 | return list; | 677 | return list; |
658 | } | 678 | } |
659 | 679 | ||
660 | 680 | ||
661 | QPtrList<Alarm> Incidence::alarms() const | 681 | QPtrList<Alarm> Incidence::alarms() const |
662 | { | 682 | { |
663 | return mAlarms; | 683 | return mAlarms; |
664 | } | 684 | } |
665 | 685 | ||
666 | Alarm* Incidence::newAlarm() | 686 | Alarm* Incidence::newAlarm() |
667 | { | 687 | { |
668 | Alarm* alarm = new Alarm(this); | 688 | Alarm* alarm = new Alarm(this); |
669 | mAlarms.append(alarm); | 689 | mAlarms.append(alarm); |
670 | // updated(); | 690 | // updated(); |
671 | return alarm; | 691 | return alarm; |
672 | } | 692 | } |
673 | 693 | ||
674 | void Incidence::addAlarm(Alarm *alarm) | 694 | void Incidence::addAlarm(Alarm *alarm) |
675 | { | 695 | { |
676 | mAlarms.append(alarm); | 696 | mAlarms.append(alarm); |
677 | updated(); | 697 | updated(); |
678 | } | 698 | } |
679 | 699 | ||
680 | void Incidence::removeAlarm(Alarm *alarm) | 700 | void Incidence::removeAlarm(Alarm *alarm) |
681 | { | 701 | { |
682 | mAlarms.removeRef(alarm); | 702 | mAlarms.removeRef(alarm); |
683 | updated(); | 703 | updated(); |
684 | } | 704 | } |
685 | 705 | ||
686 | void Incidence::clearAlarms() | 706 | void Incidence::clearAlarms() |
687 | { | 707 | { |
688 | mAlarms.clear(); | 708 | mAlarms.clear(); |
689 | updated(); | 709 | updated(); |
690 | } | 710 | } |
691 | 711 | ||
692 | bool Incidence::isAlarmEnabled() const | 712 | bool Incidence::isAlarmEnabled() const |
693 | { | 713 | { |
694 | Alarm* alarm; | 714 | Alarm* alarm; |
695 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 715 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
696 | if (alarm->enabled()) | 716 | if (alarm->enabled()) |
697 | return true; | 717 | return true; |
698 | } | 718 | } |
699 | return false; | 719 | return false; |
700 | } | 720 | } |
701 | 721 | #include <stdlib.h> | |
702 | Recurrence *Incidence::recurrence() const | 722 | Recurrence *Incidence::recurrence() |
703 | { | 723 | { |
724 | if ( ! mRecurrence ) { | ||
725 | mRecurrence = new Recurrence(this); | ||
726 | qDebug("creating new recurence "); | ||
727 | //abort(); | ||
728 | } | ||
704 | return mRecurrence; | 729 | return mRecurrence; |
705 | } | 730 | } |
706 | void Incidence::setRecurrence( Recurrence * r) | 731 | void Incidence::setRecurrence( Recurrence * r) |
707 | { | 732 | { |
708 | delete mRecurrence; | 733 | if ( mRecurrence ) |
709 | mRecurrence = r; | 734 | delete mRecurrence; |
735 | mRecurrence = r; | ||
710 | } | 736 | } |
711 | 737 | ||
712 | void Incidence::setLocation(const QString &location) | 738 | void Incidence::setLocation(const QString &location) |
713 | { | 739 | { |
714 | if (mReadOnly) return; | 740 | if (mReadOnly) return; |
715 | mLocation = location; | 741 | mLocation = location; |
716 | updated(); | 742 | updated(); |
717 | } | 743 | } |
718 | 744 | ||
719 | QString Incidence::location() const | 745 | QString Incidence::location() const |
720 | { | 746 | { |
721 | return mLocation; | 747 | return mLocation; |
722 | } | 748 | } |
749 | QString Incidence::recurrenceText() const | ||
750 | { | ||
751 | if ( mRecurrence ) return mRecurrence->recurrenceText(); | ||
752 | return i18n("No"); | ||
753 | } | ||
723 | 754 | ||
724 | ushort Incidence::doesRecur() const | 755 | ushort Incidence::doesRecur() const |
725 | { | 756 | { |
726 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 757 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
727 | else return Recurrence::rNone; | 758 | else return Recurrence::rNone; |
728 | } | 759 | } |
729 | 760 | ||
730 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 761 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
731 | { | 762 | { |
732 | QDateTime incidenceStart = dt; | 763 | QDateTime incidenceStart = dt; |
733 | *ok = false; | 764 | *ok = false; |
734 | if ( doesRecur() ) { | 765 | if ( doesRecur() ) { |
735 | bool last; | 766 | bool last; |
736 | recurrence()->getPreviousDateTime( incidenceStart , &last ); | 767 | mRecurrence->getPreviousDateTime( incidenceStart , &last ); |
737 | int count = 0; | 768 | int count = 0; |
738 | if ( !last ) { | 769 | if ( !last ) { |
739 | while ( !last ) { | 770 | while ( !last ) { |
740 | ++count; | 771 | ++count; |
741 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); | 772 | incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); |
742 | if ( recursOn( incidenceStart.date() ) ) { | 773 | if ( recursOn( incidenceStart.date() ) ) { |
743 | last = true; // exit while llop | 774 | last = true; // exit while llop |
744 | } else { | 775 | } else { |
745 | if ( last ) { // no alarm on last recurrence | 776 | if ( last ) { // no alarm on last recurrence |
746 | return QDateTime (); | 777 | return QDateTime (); |
747 | } | 778 | } |
748 | int year = incidenceStart.date().year(); | 779 | int year = incidenceStart.date().year(); |
749 | // workaround for bug in recurrence | 780 | // workaround for bug in recurrence |
750 | if ( count == 100 || year < 1000 || year > 5000 ) { | 781 | if ( count == 100 || year < 1000 || year > 5000 ) { |
751 | return QDateTime (); | 782 | return QDateTime (); |
752 | } | 783 | } |
753 | incidenceStart = incidenceStart.addSecs( 1 ); | 784 | incidenceStart = incidenceStart.addSecs( 1 ); |
754 | } | 785 | } |
755 | } | 786 | } |
756 | } else { | 787 | } else { |
757 | return QDateTime (); | 788 | return QDateTime (); |
758 | } | 789 | } |
759 | } else { | 790 | } else { |
760 | if ( hasStartDate () ) { | 791 | if ( hasStartDate () ) { |
761 | incidenceStart = dtStart(); | 792 | incidenceStart = dtStart(); |
762 | } | 793 | } |
763 | if ( typeID() == todoID ) { | 794 | if ( typeID() == todoID ) { |
764 | if ( ((Todo*)this)->hasDueDate() ) | 795 | if ( ((Todo*)this)->hasDueDate() ) |
765 | incidenceStart = ((Todo*)this)->dtDue(); | 796 | incidenceStart = ((Todo*)this)->dtDue(); |
766 | } | 797 | } |
767 | } | 798 | } |
768 | if ( incidenceStart > dt ) | 799 | if ( incidenceStart > dt ) |
769 | *ok = true; | 800 | *ok = true; |
770 | return incidenceStart; | 801 | return incidenceStart; |
771 | } | 802 | } |
772 | QDateTime Incidence::dtStart() const | 803 | QDateTime Incidence::dtStart() const |
773 | { | 804 | { |
774 | if ( doesRecur() ) { | 805 | if ( doesRecur() ) { |
775 | if ( typeID() == todoID ) { | 806 | if ( typeID() == todoID ) { |
776 | ((Todo*)this)->checkSetCompletedFalse(); | 807 | ((Todo*)this)->checkSetCompletedFalse(); |
777 | } | 808 | } |
778 | } | 809 | } |
779 | return mDtStart; | 810 | return mDtStart; |
780 | } | 811 | } |