summaryrefslogtreecommitdiffabout
path: root/libkcal/incidence.cpp
Unidiff
Diffstat (limited to 'libkcal/incidence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidence.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index 6bca12c..78fa24f 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -138,257 +138,269 @@ bool Incidence::cancelled() const
138 return mCancelled; 138 return mCancelled;
139} 139}
140void Incidence::setCancelled( bool b ) 140void Incidence::setCancelled( bool b )
141{ 141{
142 mCancelled = b; 142 mCancelled = b;
143 updated(); 143 updated();
144} 144}
145bool Incidence::hasStartDate() const 145bool Incidence::hasStartDate() const
146{ 146{
147 return mHasStartDate; 147 return mHasStartDate;
148} 148}
149 149
150void Incidence::setHasStartDate(bool f) 150void Incidence::setHasStartDate(bool f)
151{ 151{
152 if (mReadOnly) return; 152 if (mReadOnly) return;
153 mHasStartDate = f; 153 mHasStartDate = f;
154 updated(); 154 updated();
155} 155}
156 156
157// A string comparison that considers that null and empty are the same 157// A string comparison that considers that null and empty are the same
158static bool stringCompare( const QString& s1, const QString& s2 ) 158static bool stringCompare( const QString& s1, const QString& s2 )
159{ 159{
160 if ( s1.isEmpty() && s2.isEmpty() ) 160 if ( s1.isEmpty() && s2.isEmpty() )
161 return true; 161 return true;
162 return s1 == s2; 162 return s1 == s2;
163} 163}
164 164
165bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 165bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
166{ 166{
167 167
168 if( i1.alarms().count() != i2.alarms().count() ) { 168 if( i1.alarms().count() != i2.alarms().count() ) {
169 return false; // no need to check further 169 return false; // no need to check further
170 } 170 }
171 if ( i1.alarms().count() > 0 ) { 171 if ( i1.alarms().count() > 0 ) {
172 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) 172 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) )
173 { 173 {
174 qDebug("alarm not equal "); 174 qDebug("alarm not equal ");
175 return false; 175 return false;
176 } 176 }
177 } 177 }
178#if 0 178#if 0
179 QPtrListIterator<Alarm> a1( i1.alarms() ); 179 QPtrListIterator<Alarm> a1( i1.alarms() );
180 QPtrListIterator<Alarm> a2( i2.alarms() ); 180 QPtrListIterator<Alarm> a2( i2.alarms() );
181 for( ; a1.current() && a2.current(); ++a1, ++a2 ) { 181 for( ; a1.current() && a2.current(); ++a1, ++a2 ) {
182 if( *a1.current() == *a2.current() ) { 182 if( *a1.current() == *a2.current() ) {
183 continue; 183 continue;
184 } 184 }
185 else { 185 else {
186 return false; 186 return false;
187 } 187 }
188 } 188 }
189#endif 189#endif
190 190
191 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { 191 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) {
192 if ( i1.hasRecurrenceID() ) { 192 if ( i1.hasRecurrenceID() ) {
193 if ( i1.recurrenceID() != i2.recurrenceID() ) 193 if ( i1.recurrenceID() != i2.recurrenceID() )
194 return false; 194 return false;
195 } 195 }
196 196
197 } else { 197 } else {
198 return false; 198 return false;
199 } 199 }
200 200
201 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) 201 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) )
202 return false; 202 return false;
203 if ( i1.hasStartDate() == i2.hasStartDate() ) { 203 if ( i1.hasStartDate() == i2.hasStartDate() ) {
204 if ( i1.hasStartDate() ) { 204 if ( i1.hasStartDate() ) {
205 if ( i1.dtStart() != i2.dtStart() ) 205 if ( i1.dtStart() != i2.dtStart() )
206 return false; 206 return false;
207 } 207 }
208 } else { 208 } else {
209 return false; 209 return false;
210 } 210 }
211 if (!( *i1.recurrence() == *i2.recurrence()) ) { 211 if (!( *i1.recurrence() == *i2.recurrence()) ) {
212 qDebug("recurrence is NOT equal "); 212 qDebug("recurrence is NOT equal ");
213 return false; 213 return false;
214 } 214 }
215 return 215 return
216 // i1.created() == i2.created() && 216 // i1.created() == i2.created() &&
217 stringCompare( i1.description(), i2.description() ) && 217 stringCompare( i1.description(), i2.description() ) &&
218 stringCompare( i1.summary(), i2.summary() ) && 218 stringCompare( i1.summary(), i2.summary() ) &&
219 i1.categories() == i2.categories() && 219 i1.categories() == i2.categories() &&
220 // no need to compare mRelatedTo 220 // no need to compare mRelatedTo
221 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && 221 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) &&
222 // i1.relations() == i2.relations() && 222 // i1.relations() == i2.relations() &&
223 i1.exDates() == i2.exDates() && 223 i1.exDates() == i2.exDates() &&
224 i1.attachments() == i2.attachments() && 224 i1.attachments() == i2.attachments() &&
225 i1.resources() == i2.resources() && 225 i1.resources() == i2.resources() &&
226 i1.secrecy() == i2.secrecy() && 226 i1.secrecy() == i2.secrecy() &&
227 i1.priority() == i2.priority() && 227 i1.priority() == i2.priority() &&
228 i1.cancelled() == i2.cancelled() && 228 i1.cancelled() == i2.cancelled() &&
229 stringCompare( i1.location(), i2.location() ); 229 stringCompare( i1.location(), i2.location() );
230} 230}
231 231
232Incidence* Incidence::recreateCloneException( QDate d ) 232Incidence* Incidence::recreateCloneException( QDate d )
233{ 233{
234 Incidence* newInc = clone(); 234 Incidence* newInc = clone();
235 newInc->recreate(); 235 newInc->recreate();
236 if ( doesRecur() ) { 236 if ( doesRecur() ) {
237 addExDate( d ); 237 addExDate( d );
238 newInc->recurrence()->unsetRecurs(); 238 newInc->recurrence()->unsetRecurs();
239 if ( type() == "Event") { 239 if ( type() == "Event") {
240 int len = dtStart().secsTo( ((Event*)this)->dtEnd()); 240 int len = dtStart().secsTo( ((Event*)this)->dtEnd());
241 QTime tim = dtStart().time(); 241 QTime tim = dtStart().time();
242 newInc->setDtStart( QDateTime(d, tim) ); 242 newInc->setDtStart( QDateTime(d, tim) );
243 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 243 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
244 } else { 244 } else {
245 int len = dtStart().secsTo( ((Todo*)this)->dtDue()); 245 int len = dtStart().secsTo( ((Todo*)this)->dtDue());
246 QTime tim = ((Todo*)this)->dtDue().time(); 246 QTime tim = ((Todo*)this)->dtDue().time();
247 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); 247 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) );
248 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); 248 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) );
249 ((Todo*)this)->setRecurDates(); 249 ((Todo*)this)->setRecurDates();
250 } 250 }
251 newInc->setExDates( DateList () ); 251 newInc->setExDates( DateList () );
252 } 252 }
253 return newInc; 253 return newInc;
254} 254}
255 255
256void Incidence::recreate() 256void Incidence::recreate()
257{ 257{
258 setCreated(QDateTime::currentDateTime()); 258 setCreated(QDateTime::currentDateTime());
259 259
260 setUid(CalFormat::createUniqueId()); 260 setUid(CalFormat::createUniqueId());
261 261
262 setRevision(0); 262 setRevision(0);
263 setIDStr( ":" ); 263 setIDStr( ":" );
264 setLastModified(QDateTime::currentDateTime()); 264 setLastModified(QDateTime::currentDateTime());
265} 265}
266 266void Incidence::cloneRelations( Incidence * newInc )
267{
268 // newInc is already a clone of this incidence
269 Incidence * inc;
270 Incidence * cloneInc;
271 QPtrList<Incidence> Relations = relations();
272 for (inc=Relations.first();inc;inc=Relations.next()) {
273 cloneInc = inc->clone();
274 cloneInc->recreate();
275 cloneInc->setRelatedTo( newInc );
276 inc->cloneRelations( cloneInc );
277 }
278}
267void Incidence::setReadOnly( bool readOnly ) 279void Incidence::setReadOnly( bool readOnly )
268{ 280{
269 IncidenceBase::setReadOnly( readOnly ); 281 IncidenceBase::setReadOnly( readOnly );
270 recurrence()->setRecurReadOnly( readOnly); 282 recurrence()->setRecurReadOnly( readOnly);
271} 283}
272 284
273void Incidence::setCreated(QDateTime created) 285void Incidence::setCreated(QDateTime created)
274{ 286{
275 if (mReadOnly) return; 287 if (mReadOnly) return;
276 mCreated = getEvenTime(created); 288 mCreated = getEvenTime(created);
277} 289}
278 290
279QDateTime Incidence::created() const 291QDateTime Incidence::created() const
280{ 292{
281 return mCreated; 293 return mCreated;
282} 294}
283 295
284void Incidence::setRevision(int rev) 296void Incidence::setRevision(int rev)
285{ 297{
286 if (mReadOnly) return; 298 if (mReadOnly) return;
287 mRevision = rev; 299 mRevision = rev;
288 300
289 updated(); 301 updated();
290} 302}
291 303
292int Incidence::revision() const 304int Incidence::revision() const
293{ 305{
294 return mRevision; 306 return mRevision;
295} 307}
296 308
297void Incidence::setDtStart(const QDateTime &dtStart) 309void Incidence::setDtStart(const QDateTime &dtStart)
298{ 310{
299 311
300 QDateTime dt = getEvenTime(dtStart); 312 QDateTime dt = getEvenTime(dtStart);
301 recurrence()->setRecurStart( dt); 313 recurrence()->setRecurStart( dt);
302 IncidenceBase::setDtStart( dt ); 314 IncidenceBase::setDtStart( dt );
303} 315}
304 316
305void Incidence::setDescription(const QString &description) 317void Incidence::setDescription(const QString &description)
306{ 318{
307 if (mReadOnly) return; 319 if (mReadOnly) return;
308 mDescription = description; 320 mDescription = description;
309 updated(); 321 updated();
310} 322}
311 323
312QString Incidence::description() const 324QString Incidence::description() const
313{ 325{
314 return mDescription; 326 return mDescription;
315} 327}
316 328
317 329
318void Incidence::setSummary(const QString &summary) 330void Incidence::setSummary(const QString &summary)
319{ 331{
320 if (mReadOnly) return; 332 if (mReadOnly) return;
321 mSummary = summary; 333 mSummary = summary;
322 updated(); 334 updated();
323} 335}
324 336
325QString Incidence::summary() const 337QString Incidence::summary() const
326{ 338{
327 return mSummary; 339 return mSummary;
328} 340}
329void Incidence::checkCategories() 341void Incidence::checkCategories()
330{ 342{
331 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); 343 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday"));
332 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); 344 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday"));
333 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); 345 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary"));
334} 346}
335 347
336void Incidence::setCategories(const QStringList &categories) 348void Incidence::setCategories(const QStringList &categories)
337{ 349{
338 if (mReadOnly) return; 350 if (mReadOnly) return;
339 mCategories = categories; 351 mCategories = categories;
340 checkCategories(); 352 checkCategories();
341 updated(); 353 updated();
342} 354}
343 355
344// TODO: remove setCategories(QString) function 356// TODO: remove setCategories(QString) function
345void Incidence::setCategories(const QString &catStr) 357void Incidence::setCategories(const QString &catStr)
346{ 358{
347 if (mReadOnly) return; 359 if (mReadOnly) return;
348 mCategories.clear(); 360 mCategories.clear();
349 361
350 if (catStr.isEmpty()) return; 362 if (catStr.isEmpty()) return;
351 363
352 mCategories = QStringList::split(",",catStr); 364 mCategories = QStringList::split(",",catStr);
353 365
354 QStringList::Iterator it; 366 QStringList::Iterator it;
355 for(it = mCategories.begin();it != mCategories.end(); ++it) { 367 for(it = mCategories.begin();it != mCategories.end(); ++it) {
356 *it = (*it).stripWhiteSpace(); 368 *it = (*it).stripWhiteSpace();
357 } 369 }
358 checkCategories(); 370 checkCategories();
359 updated(); 371 updated();
360} 372}
361 373
362QStringList Incidence::categories() const 374QStringList Incidence::categories() const
363{ 375{
364 return mCategories; 376 return mCategories;
365} 377}
366 378
367QString Incidence::categoriesStr() 379QString Incidence::categoriesStr()
368{ 380{
369 return mCategories.join(","); 381 return mCategories.join(",");
370} 382}
371 383
372void Incidence::setRelatedToUid(const QString &relatedToUid) 384void Incidence::setRelatedToUid(const QString &relatedToUid)
373{ 385{
374 if (mReadOnly) return; 386 if (mReadOnly) return;
375 mRelatedToUid = relatedToUid; 387 mRelatedToUid = relatedToUid;
376} 388}
377 389
378QString Incidence::relatedToUid() const 390QString Incidence::relatedToUid() const
379{ 391{
380 return mRelatedToUid; 392 return mRelatedToUid;
381} 393}
382 394
383void Incidence::setRelatedTo(Incidence *relatedTo) 395void Incidence::setRelatedTo(Incidence *relatedTo)
384{ 396{
385 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 397 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
386 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 398 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
387 if (mReadOnly || mRelatedTo == relatedTo) return; 399 if (mReadOnly || mRelatedTo == relatedTo) return;
388 if(mRelatedTo) { 400 if(mRelatedTo) {
389 // updated(); 401 // updated();
390 mRelatedTo->removeRelation(this); 402 mRelatedTo->removeRelation(this);
391 } 403 }
392 mRelatedTo = relatedTo; 404 mRelatedTo = relatedTo;
393 if (mRelatedTo) { 405 if (mRelatedTo) {
394 mRelatedTo->addRelation(this); 406 mRelatedTo->addRelation(this);