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