-rw-r--r-- | libkcal/incidence.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index dbc159c..0684af2 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,649 +1,658 @@ | |||
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 = 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 | } | 43 | } |
44 | 44 | ||
45 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 45 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
46 | { | 46 | { |
47 | // TODO: reenable attributes currently commented out. | 47 | // TODO: reenable attributes currently commented out. |
48 | mRevision = i.mRevision; | 48 | mRevision = i.mRevision; |
49 | mCreated = i.mCreated; | 49 | mCreated = i.mCreated; |
50 | mDescription = i.mDescription; | 50 | mDescription = i.mDescription; |
51 | mSummary = i.mSummary; | 51 | mSummary = i.mSummary; |
52 | mCategories = i.mCategories; | 52 | mCategories = i.mCategories; |
53 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 53 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
54 | mRelatedTo = 0; | 54 | mRelatedTo = 0; |
55 | mRelatedToUid = i.mRelatedToUid; | 55 | mRelatedToUid = i.mRelatedToUid; |
56 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 56 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
57 | mExDates = i.mExDates; | 57 | mExDates = i.mExDates; |
58 | mAttachments = i.mAttachments; | 58 | mAttachments = i.mAttachments; |
59 | mResources = i.mResources; | 59 | mResources = i.mResources; |
60 | mSecrecy = i.mSecrecy; | 60 | mSecrecy = i.mSecrecy; |
61 | mPriority = i.mPriority; | 61 | mPriority = i.mPriority; |
62 | mLocation = i.mLocation; | 62 | mLocation = i.mLocation; |
63 | mCancelled = i.mCancelled; | 63 | mCancelled = i.mCancelled; |
64 | mHasStartDate = i.mHasStartDate; | 64 | mHasStartDate = i.mHasStartDate; |
65 | QPtrListIterator<Alarm> it( i.mAlarms ); | 65 | QPtrListIterator<Alarm> it( i.mAlarms ); |
66 | const Alarm *a; | 66 | const Alarm *a; |
67 | while( (a = it.current()) ) { | 67 | while( (a = it.current()) ) { |
68 | Alarm *b = new Alarm( *a ); | 68 | Alarm *b = new Alarm( *a ); |
69 | b->setParent( this ); | 69 | b->setParent( this ); |
70 | mAlarms.append( b ); | 70 | mAlarms.append( b ); |
71 | 71 | ||
72 | ++it; | 72 | ++it; |
73 | } | 73 | } |
74 | mAlarms.setAutoDelete(true); | 74 | mAlarms.setAutoDelete(true); |
75 | mHasRecurrenceID = i.mHasRecurrenceID; | 75 | mHasRecurrenceID = i.mHasRecurrenceID; |
76 | mRecurrenceID = i.mRecurrenceID; | 76 | mRecurrenceID = i.mRecurrenceID; |
77 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 77 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); |
78 | } | 78 | } |
79 | 79 | ||
80 | Incidence::~Incidence() | 80 | Incidence::~Incidence() |
81 | { | 81 | { |
82 | 82 | ||
83 | Incidence *ev; | 83 | Incidence *ev; |
84 | QPtrList<Incidence> Relations = relations(); | 84 | QPtrList<Incidence> Relations = relations(); |
85 | for (ev=Relations.first();ev;ev=Relations.next()) { | 85 | for (ev=Relations.first();ev;ev=Relations.next()) { |
86 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 86 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
87 | } | 87 | } |
88 | if (relatedTo()) relatedTo()->removeRelation(this); | 88 | if (relatedTo()) relatedTo()->removeRelation(this); |
89 | delete mRecurrence; | 89 | delete mRecurrence; |
90 | 90 | ||
91 | } | 91 | } |
92 | bool Incidence::hasRecurrenceID() const | 92 | bool Incidence::hasRecurrenceID() const |
93 | { | 93 | { |
94 | return mHasRecurrenceID; | 94 | return mHasRecurrenceID; |
95 | } | 95 | } |
96 | 96 | ||
97 | void Incidence::setHasRecurrenceID( bool b ) | 97 | void Incidence::setHasRecurrenceID( bool b ) |
98 | { | 98 | { |
99 | mHasRecurrenceID = b; | 99 | mHasRecurrenceID = b; |
100 | } | 100 | } |
101 | 101 | ||
102 | void Incidence::setRecurrenceID(QDateTime d) | 102 | void Incidence::setRecurrenceID(QDateTime d) |
103 | { | 103 | { |
104 | mRecurrenceID = d; | 104 | mRecurrenceID = d; |
105 | mHasRecurrenceID = true; | 105 | mHasRecurrenceID = true; |
106 | updated(); | 106 | updated(); |
107 | } | 107 | } |
108 | QDateTime Incidence::recurrenceID () const | 108 | QDateTime Incidence::recurrenceID () const |
109 | { | 109 | { |
110 | return mRecurrenceID; | 110 | return mRecurrenceID; |
111 | } | 111 | } |
112 | 112 | ||
113 | bool Incidence::cancelled() const | 113 | bool Incidence::cancelled() const |
114 | { | 114 | { |
115 | return mCancelled; | 115 | return mCancelled; |
116 | } | 116 | } |
117 | void Incidence::setCancelled( bool b ) | 117 | void Incidence::setCancelled( bool b ) |
118 | { | 118 | { |
119 | mCancelled = b; | 119 | mCancelled = b; |
120 | updated(); | 120 | updated(); |
121 | } | 121 | } |
122 | bool Incidence::hasStartDate() const | 122 | bool Incidence::hasStartDate() const |
123 | { | 123 | { |
124 | return mHasStartDate; | 124 | return mHasStartDate; |
125 | } | 125 | } |
126 | 126 | ||
127 | void Incidence::setHasStartDate(bool f) | 127 | void Incidence::setHasStartDate(bool f) |
128 | { | 128 | { |
129 | if (mReadOnly) return; | 129 | if (mReadOnly) return; |
130 | mHasStartDate = f; | 130 | mHasStartDate = f; |
131 | updated(); | 131 | updated(); |
132 | } | 132 | } |
133 | 133 | ||
134 | // A string comparison that considers that null and empty are the same | 134 | // A string comparison that considers that null and empty are the same |
135 | static bool stringCompare( const QString& s1, const QString& s2 ) | 135 | static bool stringCompare( const QString& s1, const QString& s2 ) |
136 | { | 136 | { |
137 | if ( s1.isEmpty() && s2.isEmpty() ) | 137 | if ( s1.isEmpty() && s2.isEmpty() ) |
138 | return true; | 138 | return true; |
139 | return s1 == s2; | 139 | return s1 == s2; |
140 | } | 140 | } |
141 | 141 | ||
142 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | 142 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) |
143 | { | 143 | { |
144 | 144 | ||
145 | if( i1.alarms().count() != i2.alarms().count() ) { | 145 | if( i1.alarms().count() != i2.alarms().count() ) { |
146 | return false; // no need to check further | 146 | return false; // no need to check further |
147 | } | 147 | } |
148 | if ( i1.alarms().count() > 0 ) { | 148 | if ( i1.alarms().count() > 0 ) { |
149 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) | 149 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) |
150 | { | 150 | { |
151 | qDebug("alarm not equal "); | 151 | qDebug("alarm not equal "); |
152 | return false; | 152 | return false; |
153 | } | 153 | } |
154 | } | 154 | } |
155 | #if 0 | 155 | #if 0 |
156 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 156 | QPtrListIterator<Alarm> a1( i1.alarms() ); |
157 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 157 | QPtrListIterator<Alarm> a2( i2.alarms() ); |
158 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 158 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
159 | if( *a1.current() == *a2.current() ) { | 159 | if( *a1.current() == *a2.current() ) { |
160 | continue; | 160 | continue; |
161 | } | 161 | } |
162 | else { | 162 | else { |
163 | return false; | 163 | return false; |
164 | } | 164 | } |
165 | } | 165 | } |
166 | #endif | 166 | #endif |
167 | 167 | ||
168 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { | 168 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { |
169 | if ( i1.hasRecurrenceID() ) { | 169 | if ( i1.hasRecurrenceID() ) { |
170 | if ( i1.recurrenceID() != i2.recurrenceID() ) | 170 | if ( i1.recurrenceID() != i2.recurrenceID() ) |
171 | return false; | 171 | return false; |
172 | } | 172 | } |
173 | 173 | ||
174 | } else { | 174 | } else { |
175 | return false; | 175 | return false; |
176 | } | 176 | } |
177 | 177 | ||
178 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 178 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
179 | return false; | 179 | return false; |
180 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 180 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
181 | if ( i1.hasStartDate() ) { | 181 | if ( i1.hasStartDate() ) { |
182 | if ( i1.dtStart() != i2.dtStart() ) | 182 | if ( i1.dtStart() != i2.dtStart() ) |
183 | return false; | 183 | return false; |
184 | } | 184 | } |
185 | } else { | 185 | } else { |
186 | return false; | 186 | return false; |
187 | } | 187 | } |
188 | if (!( *i1.recurrence() == *i2.recurrence()) ) { | 188 | if (!( *i1.recurrence() == *i2.recurrence()) ) { |
189 | qDebug("recurrence is NOT equal "); | 189 | qDebug("recurrence is NOT equal "); |
190 | return false; | 190 | return false; |
191 | } | 191 | } |
192 | return | 192 | return |
193 | // i1.created() == i2.created() && | 193 | // i1.created() == i2.created() && |
194 | stringCompare( i1.description(), i2.description() ) && | 194 | stringCompare( i1.description(), i2.description() ) && |
195 | stringCompare( i1.summary(), i2.summary() ) && | 195 | stringCompare( i1.summary(), i2.summary() ) && |
196 | i1.categories() == i2.categories() && | 196 | i1.categories() == i2.categories() && |
197 | // no need to compare mRelatedTo | 197 | // no need to compare mRelatedTo |
198 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 198 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
199 | // i1.relations() == i2.relations() && | 199 | // i1.relations() == i2.relations() && |
200 | i1.exDates() == i2.exDates() && | 200 | i1.exDates() == i2.exDates() && |
201 | i1.attachments() == i2.attachments() && | 201 | i1.attachments() == i2.attachments() && |
202 | i1.resources() == i2.resources() && | 202 | i1.resources() == i2.resources() && |
203 | i1.secrecy() == i2.secrecy() && | 203 | i1.secrecy() == i2.secrecy() && |
204 | i1.priority() == i2.priority() && | 204 | i1.priority() == i2.priority() && |
205 | i1.cancelled() == i2.cancelled() && | 205 | i1.cancelled() == i2.cancelled() && |
206 | stringCompare( i1.location(), i2.location() ); | 206 | stringCompare( i1.location(), i2.location() ); |
207 | } | 207 | } |
208 | 208 | ||
209 | Incidence* Incidence::recreateCloneException( QDate d ) | 209 | Incidence* Incidence::recreateCloneException( QDate d ) |
210 | { | 210 | { |
211 | Incidence* newInc = clone(); | 211 | Incidence* newInc = clone(); |
212 | newInc->recreate(); | 212 | newInc->recreate(); |
213 | if ( doesRecur() ) { | 213 | if ( doesRecur() ) { |
214 | addExDate( d ); | 214 | addExDate( d ); |
215 | newInc->recurrence()->unsetRecurs(); | 215 | newInc->recurrence()->unsetRecurs(); |
216 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); | 216 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); |
217 | QTime tim = dtStart().time(); | 217 | QTime tim = dtStart().time(); |
218 | newInc->setDtStart( QDateTime(d, tim) ); | 218 | newInc->setDtStart( QDateTime(d, tim) ); |
219 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | 219 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); |
220 | } | 220 | } |
221 | return newInc; | 221 | return newInc; |
222 | } | 222 | } |
223 | 223 | ||
224 | void Incidence::recreate() | 224 | void Incidence::recreate() |
225 | { | 225 | { |
226 | setCreated(QDateTime::currentDateTime()); | 226 | setCreated(QDateTime::currentDateTime()); |
227 | 227 | ||
228 | setUid(CalFormat::createUniqueId()); | 228 | setUid(CalFormat::createUniqueId()); |
229 | 229 | ||
230 | setRevision(0); | 230 | setRevision(0); |
231 | setIDStr( ":" ); | 231 | setIDStr( ":" ); |
232 | setLastModified(QDateTime::currentDateTime()); | 232 | setLastModified(QDateTime::currentDateTime()); |
233 | } | 233 | } |
234 | 234 | ||
235 | void Incidence::setReadOnly( bool readOnly ) | 235 | void Incidence::setReadOnly( bool readOnly ) |
236 | { | 236 | { |
237 | IncidenceBase::setReadOnly( readOnly ); | 237 | IncidenceBase::setReadOnly( readOnly ); |
238 | recurrence()->setRecurReadOnly( readOnly); | 238 | recurrence()->setRecurReadOnly( readOnly); |
239 | } | 239 | } |
240 | 240 | ||
241 | void Incidence::setCreated(QDateTime created) | 241 | void Incidence::setCreated(QDateTime created) |
242 | { | 242 | { |
243 | if (mReadOnly) return; | 243 | if (mReadOnly) return; |
244 | mCreated = getEvenTime(created); | 244 | mCreated = getEvenTime(created); |
245 | } | 245 | } |
246 | 246 | ||
247 | QDateTime Incidence::created() const | 247 | QDateTime Incidence::created() const |
248 | { | 248 | { |
249 | return mCreated; | 249 | return mCreated; |
250 | } | 250 | } |
251 | 251 | ||
252 | void Incidence::setRevision(int rev) | 252 | void Incidence::setRevision(int rev) |
253 | { | 253 | { |
254 | if (mReadOnly) return; | 254 | if (mReadOnly) return; |
255 | mRevision = rev; | 255 | mRevision = rev; |
256 | 256 | ||
257 | updated(); | 257 | updated(); |
258 | } | 258 | } |
259 | 259 | ||
260 | int Incidence::revision() const | 260 | int Incidence::revision() const |
261 | { | 261 | { |
262 | return mRevision; | 262 | return mRevision; |
263 | } | 263 | } |
264 | 264 | ||
265 | void Incidence::setDtStart(const QDateTime &dtStart) | 265 | void Incidence::setDtStart(const QDateTime &dtStart) |
266 | { | 266 | { |
267 | 267 | ||
268 | QDateTime dt = getEvenTime(dtStart); | 268 | QDateTime dt = getEvenTime(dtStart); |
269 | recurrence()->setRecurStart( dt); | 269 | recurrence()->setRecurStart( dt); |
270 | IncidenceBase::setDtStart( dt ); | 270 | IncidenceBase::setDtStart( dt ); |
271 | } | 271 | } |
272 | 272 | ||
273 | void Incidence::setDescription(const QString &description) | 273 | void Incidence::setDescription(const QString &description) |
274 | { | 274 | { |
275 | if (mReadOnly) return; | 275 | if (mReadOnly) return; |
276 | mDescription = description; | 276 | mDescription = description; |
277 | updated(); | 277 | updated(); |
278 | } | 278 | } |
279 | 279 | ||
280 | QString Incidence::description() const | 280 | QString Incidence::description() const |
281 | { | 281 | { |
282 | return mDescription; | 282 | return mDescription; |
283 | } | 283 | } |
284 | 284 | ||
285 | 285 | ||
286 | void Incidence::setSummary(const QString &summary) | 286 | void Incidence::setSummary(const QString &summary) |
287 | { | 287 | { |
288 | if (mReadOnly) return; | 288 | if (mReadOnly) return; |
289 | mSummary = summary; | 289 | mSummary = summary; |
290 | updated(); | 290 | updated(); |
291 | } | 291 | } |
292 | 292 | ||
293 | QString Incidence::summary() const | 293 | QString Incidence::summary() const |
294 | { | 294 | { |
295 | return mSummary; | 295 | return mSummary; |
296 | } | 296 | } |
297 | 297 | ||
298 | void Incidence::setCategories(const QStringList &categories) | 298 | void Incidence::setCategories(const QStringList &categories) |
299 | { | 299 | { |
300 | if (mReadOnly) return; | 300 | if (mReadOnly) return; |
301 | mCategories = categories; | 301 | mCategories = categories; |
302 | updated(); | 302 | updated(); |
303 | } | 303 | } |
304 | 304 | ||
305 | // TODO: remove setCategories(QString) function | 305 | // TODO: remove setCategories(QString) function |
306 | void Incidence::setCategories(const QString &catStr) | 306 | void Incidence::setCategories(const QString &catStr) |
307 | { | 307 | { |
308 | if (mReadOnly) return; | 308 | if (mReadOnly) return; |
309 | mCategories.clear(); | 309 | mCategories.clear(); |
310 | 310 | ||
311 | if (catStr.isEmpty()) return; | 311 | if (catStr.isEmpty()) return; |
312 | 312 | ||
313 | mCategories = QStringList::split(",",catStr); | 313 | mCategories = QStringList::split(",",catStr); |
314 | 314 | ||
315 | QStringList::Iterator it; | 315 | QStringList::Iterator it; |
316 | for(it = mCategories.begin();it != mCategories.end(); ++it) { | 316 | for(it = mCategories.begin();it != mCategories.end(); ++it) { |
317 | *it = (*it).stripWhiteSpace(); | 317 | *it = (*it).stripWhiteSpace(); |
318 | } | 318 | } |
319 | 319 | ||
320 | updated(); | 320 | updated(); |
321 | } | 321 | } |
322 | 322 | ||
323 | QStringList Incidence::categories() const | 323 | QStringList Incidence::categories() const |
324 | { | 324 | { |
325 | return mCategories; | 325 | return mCategories; |
326 | } | 326 | } |
327 | 327 | ||
328 | QString Incidence::categoriesStr() | 328 | QString Incidence::categoriesStr() |
329 | { | 329 | { |
330 | return mCategories.join(","); | 330 | return mCategories.join(","); |
331 | } | 331 | } |
332 | 332 | ||
333 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 333 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
334 | { | 334 | { |
335 | if (mReadOnly) return; | 335 | if (mReadOnly) return; |
336 | mRelatedToUid = relatedToUid; | 336 | mRelatedToUid = relatedToUid; |
337 | } | 337 | } |
338 | 338 | ||
339 | QString Incidence::relatedToUid() const | 339 | QString Incidence::relatedToUid() const |
340 | { | 340 | { |
341 | return mRelatedToUid; | 341 | return mRelatedToUid; |
342 | } | 342 | } |
343 | 343 | ||
344 | void Incidence::setRelatedTo(Incidence *relatedTo) | 344 | void Incidence::setRelatedTo(Incidence *relatedTo) |
345 | { | 345 | { |
346 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 346 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
347 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 347 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
348 | if (mReadOnly || mRelatedTo == relatedTo) return; | 348 | if (mReadOnly || mRelatedTo == relatedTo) return; |
349 | if(mRelatedTo) { | 349 | if(mRelatedTo) { |
350 | // updated(); | 350 | // updated(); |
351 | mRelatedTo->removeRelation(this); | 351 | mRelatedTo->removeRelation(this); |
352 | } | 352 | } |
353 | mRelatedTo = relatedTo; | 353 | mRelatedTo = relatedTo; |
354 | if (mRelatedTo) mRelatedTo->addRelation(this); | 354 | if (mRelatedTo) mRelatedTo->addRelation(this); |
355 | } | 355 | } |
356 | 356 | ||
357 | Incidence *Incidence::relatedTo() const | 357 | Incidence *Incidence::relatedTo() const |
358 | { | 358 | { |
359 | return mRelatedTo; | 359 | return mRelatedTo; |
360 | } | 360 | } |
361 | 361 | ||
362 | QPtrList<Incidence> Incidence::relations() const | 362 | QPtrList<Incidence> Incidence::relations() const |
363 | { | 363 | { |
364 | return mRelations; | 364 | return mRelations; |
365 | } | 365 | } |
366 | 366 | ||
367 | void Incidence::addRelation(Incidence *event) | 367 | void Incidence::addRelation(Incidence *event) |
368 | { | 368 | { |
369 | if( mRelations.findRef( event ) == -1 ) { | 369 | if( mRelations.findRef( event ) == -1 ) { |
370 | mRelations.append(event); | 370 | mRelations.append(event); |
371 | //updated(); | 371 | //updated(); |
372 | } | 372 | } |
373 | } | 373 | } |
374 | 374 | ||
375 | void Incidence::removeRelation(Incidence *event) | 375 | void Incidence::removeRelation(Incidence *event) |
376 | { | 376 | { |
377 | 377 | ||
378 | mRelations.removeRef(event); | 378 | mRelations.removeRef(event); |
379 | 379 | ||
380 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 380 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
381 | } | 381 | } |
382 | 382 | ||
383 | bool Incidence::recursOn(const QDate &qd) const | 383 | bool Incidence::recursOn(const QDate &qd) const |
384 | { | 384 | { |
385 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; | 385 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; |
386 | else return false; | 386 | else return false; |
387 | } | 387 | } |
388 | 388 | ||
389 | void Incidence::setExDates(const DateList &exDates) | 389 | void Incidence::setExDates(const DateList &exDates) |
390 | { | 390 | { |
391 | if (mReadOnly) return; | 391 | if (mReadOnly) return; |
392 | mExDates = exDates; | 392 | mExDates = exDates; |
393 | 393 | ||
394 | recurrence()->setRecurExDatesCount(mExDates.count()); | 394 | recurrence()->setRecurExDatesCount(mExDates.count()); |
395 | 395 | ||
396 | updated(); | 396 | updated(); |
397 | } | 397 | } |
398 | 398 | ||
399 | void Incidence::addExDate(const QDate &date) | 399 | void Incidence::addExDate(const QDate &date) |
400 | { | 400 | { |
401 | if (mReadOnly) return; | 401 | if (mReadOnly) return; |
402 | mExDates.append(date); | 402 | mExDates.append(date); |
403 | 403 | ||
404 | recurrence()->setRecurExDatesCount(mExDates.count()); | 404 | recurrence()->setRecurExDatesCount(mExDates.count()); |
405 | 405 | ||
406 | updated(); | 406 | updated(); |
407 | } | 407 | } |
408 | 408 | ||
409 | DateList Incidence::exDates() const | 409 | DateList Incidence::exDates() const |
410 | { | 410 | { |
411 | return mExDates; | 411 | return mExDates; |
412 | } | 412 | } |
413 | 413 | ||
414 | bool Incidence::isException(const QDate &date) const | 414 | bool Incidence::isException(const QDate &date) const |
415 | { | 415 | { |
416 | DateList::ConstIterator it; | 416 | DateList::ConstIterator it; |
417 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 417 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
418 | if ( (*it) == date ) { | 418 | if ( (*it) == date ) { |
419 | return true; | 419 | return true; |
420 | } | 420 | } |
421 | } | 421 | } |
422 | 422 | ||
423 | return false; | 423 | return false; |
424 | } | 424 | } |
425 | 425 | ||
426 | void Incidence::addAttachment(Attachment *attachment) | 426 | void Incidence::addAttachment(Attachment *attachment) |
427 | { | 427 | { |
428 | if (mReadOnly || !attachment) return; | 428 | if (mReadOnly || !attachment) return; |
429 | mAttachments.append(attachment); | 429 | mAttachments.append(attachment); |
430 | updated(); | 430 | updated(); |
431 | } | 431 | } |
432 | 432 | ||
433 | void Incidence::deleteAttachment(Attachment *attachment) | 433 | void Incidence::deleteAttachment(Attachment *attachment) |
434 | { | 434 | { |
435 | mAttachments.removeRef(attachment); | 435 | mAttachments.removeRef(attachment); |
436 | } | 436 | } |
437 | 437 | ||
438 | void Incidence::deleteAttachments(const QString& mime) | 438 | void Incidence::deleteAttachments(const QString& mime) |
439 | { | 439 | { |
440 | Attachment *at = mAttachments.first(); | 440 | Attachment *at = mAttachments.first(); |
441 | while (at) { | 441 | while (at) { |
442 | if (at->mimeType() == mime) | 442 | if (at->mimeType() == mime) |
443 | mAttachments.remove(); | 443 | mAttachments.remove(); |
444 | else | 444 | else |
445 | at = mAttachments.next(); | 445 | at = mAttachments.next(); |
446 | } | 446 | } |
447 | } | 447 | } |
448 | 448 | ||
449 | QPtrList<Attachment> Incidence::attachments() const | 449 | QPtrList<Attachment> Incidence::attachments() const |
450 | { | 450 | { |
451 | return mAttachments; | 451 | return mAttachments; |
452 | } | 452 | } |
453 | 453 | ||
454 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const | 454 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const |
455 | { | 455 | { |
456 | QPtrList<Attachment> attachments; | 456 | QPtrList<Attachment> attachments; |
457 | QPtrListIterator<Attachment> it( mAttachments ); | 457 | QPtrListIterator<Attachment> it( mAttachments ); |
458 | Attachment *at; | 458 | Attachment *at; |
459 | while ( (at = it.current()) ) { | 459 | while ( (at = it.current()) ) { |
460 | if (at->mimeType() == mime) | 460 | if (at->mimeType() == mime) |
461 | attachments.append(at); | 461 | attachments.append(at); |
462 | ++it; | 462 | ++it; |
463 | } | 463 | } |
464 | 464 | ||
465 | return attachments; | 465 | return attachments; |
466 | } | 466 | } |
467 | 467 | ||
468 | void Incidence::setResources(const QStringList &resources) | 468 | void Incidence::setResources(const QStringList &resources) |
469 | { | 469 | { |
470 | if (mReadOnly) return; | 470 | if (mReadOnly) return; |
471 | mResources = resources; | 471 | mResources = resources; |
472 | updated(); | 472 | updated(); |
473 | } | 473 | } |
474 | 474 | ||
475 | QStringList Incidence::resources() const | 475 | QStringList Incidence::resources() const |
476 | { | 476 | { |
477 | return mResources; | 477 | return mResources; |
478 | } | 478 | } |
479 | 479 | ||
480 | 480 | ||
481 | void Incidence::setPriority(int priority) | 481 | void Incidence::setPriority(int priority) |
482 | { | 482 | { |
483 | if (mReadOnly) return; | 483 | if (mReadOnly) return; |
484 | mPriority = priority; | 484 | mPriority = priority; |
485 | updated(); | 485 | updated(); |
486 | } | 486 | } |
487 | 487 | ||
488 | int Incidence::priority() const | 488 | int Incidence::priority() const |
489 | { | 489 | { |
490 | return mPriority; | 490 | return mPriority; |
491 | } | 491 | } |
492 | 492 | ||
493 | void Incidence::setSecrecy(int sec) | 493 | void Incidence::setSecrecy(int sec) |
494 | { | 494 | { |
495 | if (mReadOnly) return; | 495 | if (mReadOnly) return; |
496 | mSecrecy = sec; | 496 | mSecrecy = sec; |
497 | updated(); | 497 | updated(); |
498 | } | 498 | } |
499 | 499 | ||
500 | int Incidence::secrecy() const | 500 | int Incidence::secrecy() const |
501 | { | 501 | { |
502 | return mSecrecy; | 502 | return mSecrecy; |
503 | } | 503 | } |
504 | 504 | ||
505 | QString Incidence::secrecyStr() const | 505 | QString Incidence::secrecyStr() const |
506 | { | 506 | { |
507 | return secrecyName(mSecrecy); | 507 | return secrecyName(mSecrecy); |
508 | } | 508 | } |
509 | 509 | ||
510 | QString Incidence::secrecyName(int secrecy) | 510 | QString Incidence::secrecyName(int secrecy) |
511 | { | 511 | { |
512 | switch (secrecy) { | 512 | switch (secrecy) { |
513 | case SecrecyPublic: | 513 | case SecrecyPublic: |
514 | return i18n("Public"); | 514 | return i18n("Public"); |
515 | break; | 515 | break; |
516 | case SecrecyPrivate: | 516 | case SecrecyPrivate: |
517 | return i18n("Private"); | 517 | return i18n("Private"); |
518 | break; | 518 | break; |
519 | case SecrecyConfidential: | 519 | case SecrecyConfidential: |
520 | return i18n("Confidential"); | 520 | return i18n("Confidential"); |
521 | break; | 521 | break; |
522 | default: | 522 | default: |
523 | return i18n("Undefined"); | 523 | return i18n("Undefined"); |
524 | break; | 524 | break; |
525 | } | 525 | } |
526 | } | 526 | } |
527 | 527 | ||
528 | QStringList Incidence::secrecyList() | 528 | QStringList Incidence::secrecyList() |
529 | { | 529 | { |
530 | QStringList list; | 530 | QStringList list; |
531 | list << secrecyName(SecrecyPublic); | 531 | list << secrecyName(SecrecyPublic); |
532 | list << secrecyName(SecrecyPrivate); | 532 | list << secrecyName(SecrecyPrivate); |
533 | list << secrecyName(SecrecyConfidential); | 533 | list << secrecyName(SecrecyConfidential); |
534 | 534 | ||
535 | return list; | 535 | return list; |
536 | } | 536 | } |
537 | 537 | ||
538 | 538 | ||
539 | QPtrList<Alarm> Incidence::alarms() const | 539 | QPtrList<Alarm> Incidence::alarms() const |
540 | { | 540 | { |
541 | return mAlarms; | 541 | return mAlarms; |
542 | } | 542 | } |
543 | 543 | ||
544 | Alarm* Incidence::newAlarm() | 544 | Alarm* Incidence::newAlarm() |
545 | { | 545 | { |
546 | Alarm* alarm = new Alarm(this); | 546 | Alarm* alarm = new Alarm(this); |
547 | mAlarms.append(alarm); | 547 | mAlarms.append(alarm); |
548 | // updated(); | 548 | // updated(); |
549 | return alarm; | 549 | return alarm; |
550 | } | 550 | } |
551 | 551 | ||
552 | void Incidence::addAlarm(Alarm *alarm) | 552 | void Incidence::addAlarm(Alarm *alarm) |
553 | { | 553 | { |
554 | mAlarms.append(alarm); | 554 | mAlarms.append(alarm); |
555 | updated(); | 555 | updated(); |
556 | } | 556 | } |
557 | 557 | ||
558 | void Incidence::removeAlarm(Alarm *alarm) | 558 | void Incidence::removeAlarm(Alarm *alarm) |
559 | { | 559 | { |
560 | mAlarms.removeRef(alarm); | 560 | mAlarms.removeRef(alarm); |
561 | updated(); | 561 | updated(); |
562 | } | 562 | } |
563 | 563 | ||
564 | void Incidence::clearAlarms() | 564 | void Incidence::clearAlarms() |
565 | { | 565 | { |
566 | mAlarms.clear(); | 566 | mAlarms.clear(); |
567 | updated(); | 567 | updated(); |
568 | } | 568 | } |
569 | 569 | ||
570 | bool Incidence::isAlarmEnabled() const | 570 | bool Incidence::isAlarmEnabled() const |
571 | { | 571 | { |
572 | Alarm* alarm; | 572 | Alarm* alarm; |
573 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 573 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
574 | if (alarm->enabled()) | 574 | if (alarm->enabled()) |
575 | return true; | 575 | return true; |
576 | } | 576 | } |
577 | return false; | 577 | return false; |
578 | } | 578 | } |
579 | 579 | ||
580 | Recurrence *Incidence::recurrence() const | 580 | Recurrence *Incidence::recurrence() const |
581 | { | 581 | { |
582 | return mRecurrence; | 582 | return mRecurrence; |
583 | } | 583 | } |
584 | void Incidence::setRecurrence( Recurrence * r) | 584 | void Incidence::setRecurrence( Recurrence * r) |
585 | { | 585 | { |
586 | delete mRecurrence; | 586 | delete mRecurrence; |
587 | mRecurrence = r; | 587 | mRecurrence = r; |
588 | } | 588 | } |
589 | 589 | ||
590 | void Incidence::setLocation(const QString &location) | 590 | void Incidence::setLocation(const QString &location) |
591 | { | 591 | { |
592 | if (mReadOnly) return; | 592 | if (mReadOnly) return; |
593 | mLocation = location; | 593 | mLocation = location; |
594 | updated(); | 594 | updated(); |
595 | } | 595 | } |
596 | 596 | ||
597 | QString Incidence::location() const | 597 | QString Incidence::location() const |
598 | { | 598 | { |
599 | return mLocation; | 599 | return mLocation; |
600 | } | 600 | } |
601 | 601 | ||
602 | ushort Incidence::doesRecur() const | 602 | ushort Incidence::doesRecur() const |
603 | { | 603 | { |
604 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 604 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
605 | else return Recurrence::rNone; | 605 | else return Recurrence::rNone; |
606 | } | 606 | } |
607 | 607 | ||
608 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 608 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
609 | { | 609 | { |
610 | QDateTime incidenceStart = dt; | 610 | QDateTime incidenceStart = dt; |
611 | *ok = false; | 611 | *ok = false; |
612 | if ( doesRecur() ) { | 612 | if ( doesRecur() ) { |
613 | bool last; | 613 | bool last; |
614 | recurrence()->getPreviousDateTime( incidenceStart , &last ); | 614 | recurrence()->getPreviousDateTime( incidenceStart , &last ); |
615 | int count = 0; | 615 | int count = 0; |
616 | if ( !last ) { | 616 | if ( !last ) { |
617 | while ( !last ) { | 617 | while ( !last ) { |
618 | ++count; | 618 | ++count; |
619 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); | 619 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); |
620 | if ( recursOn( incidenceStart.date() ) ) { | 620 | if ( recursOn( incidenceStart.date() ) ) { |
621 | last = true; // exit while llop | 621 | last = true; // exit while llop |
622 | } else { | 622 | } else { |
623 | if ( last ) { // no alarm on last recurrence | 623 | if ( last ) { // no alarm on last recurrence |
624 | return QDateTime (); | 624 | return QDateTime (); |
625 | } | 625 | } |
626 | int year = incidenceStart.date().year(); | 626 | int year = incidenceStart.date().year(); |
627 | // workaround for bug in recurrence | 627 | // workaround for bug in recurrence |
628 | if ( count == 100 || year < 1000 || year > 5000 ) { | 628 | if ( count == 100 || year < 1000 || year > 5000 ) { |
629 | return QDateTime (); | 629 | return QDateTime (); |
630 | } | 630 | } |
631 | incidenceStart = incidenceStart.addSecs( 1 ); | 631 | incidenceStart = incidenceStart.addSecs( 1 ); |
632 | } | 632 | } |
633 | } | 633 | } |
634 | } else { | 634 | } else { |
635 | return QDateTime (); | 635 | return QDateTime (); |
636 | } | 636 | } |
637 | } else { | 637 | } else { |
638 | if ( hasStartDate () ) { | 638 | if ( hasStartDate () ) { |
639 | incidenceStart = dtStart(); | 639 | incidenceStart = dtStart(); |
640 | } | 640 | } |
641 | if ( type() =="Todo" ) { | 641 | if ( type() =="Todo" ) { |
642 | if ( ((Todo*)this)->hasDueDate() ) | 642 | if ( ((Todo*)this)->hasDueDate() ) |
643 | incidenceStart = ((Todo*)this)->dtDue(); | 643 | incidenceStart = ((Todo*)this)->dtDue(); |
644 | } | 644 | } |
645 | } | 645 | } |
646 | if ( incidenceStart > dt ) | 646 | if ( incidenceStart > dt ) |
647 | *ok = true; | 647 | *ok = true; |
648 | return incidenceStart; | 648 | return incidenceStart; |
649 | } | 649 | } |
650 | QDateTime Incidence::dtStart() const | ||
651 | { | ||
652 | if ( doesRecur() ) { | ||
653 | if ( type() == "Todo" ) { | ||
654 | ((Todo*)this)->checkSetCompletedFalse(); | ||
655 | } | ||
656 | } | ||
657 | return mDtStart; | ||
658 | } | ||