-rw-r--r-- | libkcal/incidence.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 39c14f5..fe9f854 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -217,269 +217,282 @@ bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | |||
217 | } | 217 | } |
218 | #if 0 | 218 | #if 0 |
219 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 219 | QPtrListIterator<Alarm> a1( i1.alarms() ); |
220 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 220 | QPtrListIterator<Alarm> a2( i2.alarms() ); |
221 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 221 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
222 | if( *a1.current() == *a2.current() ) { | 222 | if( *a1.current() == *a2.current() ) { |
223 | continue; | 223 | continue; |
224 | } | 224 | } |
225 | else { | 225 | else { |
226 | return false; | 226 | return false; |
227 | } | 227 | } |
228 | } | 228 | } |
229 | #endif | 229 | #endif |
230 | 230 | ||
231 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { | 231 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { |
232 | if ( i1.hasRecurrenceID() ) { | 232 | if ( i1.hasRecurrenceID() ) { |
233 | if ( i1.recurrenceID() != i2.recurrenceID() ) | 233 | if ( i1.recurrenceID() != i2.recurrenceID() ) |
234 | return false; | 234 | return false; |
235 | } | 235 | } |
236 | 236 | ||
237 | } else { | 237 | } else { |
238 | return false; | 238 | return false; |
239 | } | 239 | } |
240 | 240 | ||
241 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 241 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
242 | return false; | 242 | return false; |
243 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 243 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
244 | if ( i1.hasStartDate() ) { | 244 | if ( i1.hasStartDate() ) { |
245 | if ( i1.dtStart() != i2.dtStart() ) | 245 | if ( i1.dtStart() != i2.dtStart() ) |
246 | return false; | 246 | return false; |
247 | } | 247 | } |
248 | } else { | 248 | } else { |
249 | return false; | 249 | return false; |
250 | } | 250 | } |
251 | if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { | 251 | if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { |
252 | if (!( *i1.mRecurrence == *i2.mRecurrence) ) { | 252 | if (!( *i1.mRecurrence == *i2.mRecurrence) ) { |
253 | //qDebug("recurrence is NOT equal "); | 253 | //qDebug("recurrence is NOT equal "); |
254 | return false; | 254 | return false; |
255 | } | 255 | } |
256 | } else { | 256 | } else { |
257 | // one ( or both ) recurrence is 0 | 257 | // one ( or both ) recurrence is 0 |
258 | if ( i1.mRecurrence == 0 ) { | 258 | if ( i1.mRecurrence == 0 ) { |
259 | if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) | 259 | if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) |
260 | return false; | 260 | return false; |
261 | } else { | 261 | } else { |
262 | // i1.mRecurrence != 0 | 262 | // i1.mRecurrence != 0 |
263 | // i2.mRecurrence == 0 | 263 | // i2.mRecurrence == 0 |
264 | if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) | 264 | if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) |
265 | return false; | 265 | return false; |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | return | 269 | return |
270 | // i1.created() == i2.created() && | 270 | // i1.created() == i2.created() && |
271 | stringCompare( i1.description(), i2.description() ) && | 271 | stringCompare( i1.description(), i2.description() ) && |
272 | stringCompare( i1.summary(), i2.summary() ) && | 272 | stringCompare( i1.summary(), i2.summary() ) && |
273 | i1.categories() == i2.categories() && | 273 | i1.categories() == i2.categories() && |
274 | // no need to compare mRelatedTo | 274 | // no need to compare mRelatedTo |
275 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 275 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
276 | // i1.relations() == i2.relations() && | 276 | // i1.relations() == i2.relations() && |
277 | i1.exDates() == i2.exDates() && | 277 | i1.exDates() == i2.exDates() && |
278 | i1.attachments() == i2.attachments() && | 278 | i1.attachments() == i2.attachments() && |
279 | i1.resources() == i2.resources() && | 279 | i1.resources() == i2.resources() && |
280 | i1.secrecy() == i2.secrecy() && | 280 | i1.secrecy() == i2.secrecy() && |
281 | i1.priority() == i2.priority() && | 281 | i1.priority() == i2.priority() && |
282 | i1.cancelled() == i2.cancelled() && | 282 | i1.cancelled() == i2.cancelled() && |
283 | stringCompare( i1.location(), i2.location() ); | 283 | stringCompare( i1.location(), i2.location() ); |
284 | } | 284 | } |
285 | 285 | ||
286 | Incidence* Incidence::recreateCloneException( QDate d ) | 286 | Incidence* Incidence::recreateCloneException( QDate d ) |
287 | { | 287 | { |
288 | Incidence* newInc = clone(); | 288 | Incidence* newInc = clone(); |
289 | newInc->recreate(); | 289 | newInc->recreate(); |
290 | if ( doesRecur() ) { | 290 | if ( doesRecur() ) { |
291 | addExDate( d ); | 291 | addExDate( d ); |
292 | newInc->recurrence()->unsetRecurs(); | 292 | newInc->recurrence()->unsetRecurs(); |
293 | if ( typeID() == eventID ) { | 293 | if ( typeID() == eventID ) { |
294 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); | 294 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); |
295 | QTime tim = dtStart().time(); | 295 | QTime tim = dtStart().time(); |
296 | newInc->setDtStart( QDateTime(d, tim) ); | 296 | newInc->setDtStart( QDateTime(d, tim) ); |
297 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | 297 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); |
298 | } else { | 298 | } else { |
299 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); | 299 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); |
300 | QTime tim = ((Todo*)this)->dtDue().time(); | 300 | QTime tim = ((Todo*)this)->dtDue().time(); |
301 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); | 301 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); |
302 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); | 302 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); |
303 | ((Todo*)this)->setRecurDates(); | 303 | ((Todo*)this)->setRecurDates(); |
304 | } | 304 | } |
305 | newInc->setExDates( DateList () ); | 305 | newInc->setExDates( DateList () ); |
306 | } | 306 | } |
307 | return newInc; | 307 | return newInc; |
308 | } | 308 | } |
309 | 309 | ||
310 | void Incidence::recreate() | 310 | void Incidence::recreate() |
311 | { | 311 | { |
312 | setCreated(QDateTime::currentDateTime()); | 312 | setCreated(QDateTime::currentDateTime()); |
313 | 313 | ||
314 | setUid(CalFormat::createUniqueId()); | 314 | setUid(CalFormat::createUniqueId()); |
315 | 315 | ||
316 | setRevision(0); | 316 | setRevision(0); |
317 | setIDStr( ":" ); | 317 | setIDStr( ":" ); |
318 | setLastModified(QDateTime::currentDateTime()); | 318 | setLastModified(QDateTime::currentDateTime()); |
319 | } | 319 | } |
320 | void Incidence::cloneRelations( Incidence * newInc ) | 320 | void Incidence::cloneRelations( Incidence * newInc ) |
321 | { | 321 | { |
322 | // newInc is already a clone of this incidence | 322 | // newInc is already a clone of this incidence |
323 | Incidence * inc; | 323 | Incidence * inc; |
324 | Incidence * cloneInc; | 324 | Incidence * cloneInc; |
325 | QPtrList<Incidence> Relations = relations(); | 325 | QPtrList<Incidence> Relations = relations(); |
326 | for (inc=Relations.first();inc;inc=Relations.next()) { | 326 | for (inc=Relations.first();inc;inc=Relations.next()) { |
327 | cloneInc = inc->clone(); | 327 | cloneInc = inc->clone(); |
328 | cloneInc->recreate(); | 328 | cloneInc->recreate(); |
329 | cloneInc->setRelatedTo( newInc ); | 329 | cloneInc->setRelatedTo( newInc ); |
330 | inc->cloneRelations( cloneInc ); | 330 | inc->cloneRelations( cloneInc ); |
331 | } | 331 | } |
332 | } | 332 | } |
333 | void Incidence::setReadOnly( bool readOnly ) | 333 | void Incidence::setReadOnly( bool readOnly ) |
334 | { | 334 | { |
335 | IncidenceBase::setReadOnly( readOnly ); | 335 | IncidenceBase::setReadOnly( readOnly ); |
336 | if ( mRecurrence ) | 336 | if ( mRecurrence ) |
337 | mRecurrence->setRecurReadOnly( readOnly); | 337 | mRecurrence->setRecurReadOnly( readOnly); |
338 | } | 338 | } |
339 | void Incidence::setLastModifiedSubInvalid() | 339 | void Incidence::setLastModifiedSubInvalid() |
340 | { | 340 | { |
341 | mLastModifiedSub = QDateTime(); | 341 | mLastModifiedSub = QDateTime(); |
342 | if ( mRelatedTo ) | 342 | if ( mRelatedTo ) |
343 | mRelatedTo->setLastModifiedSubInvalid(); | 343 | mRelatedTo->setLastModifiedSubInvalid(); |
344 | } | 344 | } |
345 | QString Incidence::lastModifiedSubSortKey() const | ||
346 | { | ||
347 | if ( mLastModifiedSubSortKey.isEmpty() ) | ||
348 | return lastModifiedSortKey(); | ||
349 | return mLastModifiedSubSortKey; | ||
350 | } | ||
345 | QDateTime Incidence::lastModifiedSub() | 351 | QDateTime Incidence::lastModifiedSub() |
346 | { | 352 | { |
347 | if ( !mRelations.count() ) | 353 | if ( !mRelations.count() ) |
348 | return lastModified(); | 354 | return lastModified(); |
349 | if ( mLastModifiedSub.isValid() ) | 355 | if ( mLastModifiedSub.isValid() ) |
350 | return mLastModifiedSub; | 356 | return mLastModifiedSub; |
351 | mLastModifiedSub = lastModified(); | 357 | mLastModifiedSub = lastModified(); |
352 | Incidence * inc; | 358 | Incidence * inc; |
353 | QPtrList<Incidence> Relations = relations(); | 359 | QPtrList<Incidence> Relations = relations(); |
354 | for (inc=Relations.first();inc;inc=Relations.next()) { | 360 | for (inc=Relations.first();inc;inc=Relations.next()) { |
355 | if ( inc->lastModifiedSub() > mLastModifiedSub ) | 361 | if ( inc->lastModifiedSub() > mLastModifiedSub ) |
356 | mLastModifiedSub = inc->lastModifiedSub(); | 362 | mLastModifiedSub = inc->lastModifiedSub(); |
357 | } | 363 | } |
364 | mLastModifiedSubSortKey.sprintf("%04d%02d%02d%02d%02d%02d", | ||
365 | mLastModifiedSub.date().year(), | ||
366 | mLastModifiedSub.date().month(), | ||
367 | mLastModifiedSub.date().day(), | ||
368 | mLastModifiedSub.time().hour(), | ||
369 | mLastModifiedSub.time().minute(), | ||
370 | mLastModifiedSub.time().second() ); | ||
358 | return mLastModifiedSub; | 371 | return mLastModifiedSub; |
359 | } | 372 | } |
360 | void Incidence::setCreated(QDateTime created) | 373 | void Incidence::setCreated(QDateTime created) |
361 | { | 374 | { |
362 | if (mReadOnly) return; | 375 | if (mReadOnly) return; |
363 | mCreated = getEvenTime(created); | 376 | mCreated = getEvenTime(created); |
364 | } | 377 | } |
365 | 378 | ||
366 | QDateTime Incidence::created() const | 379 | QDateTime Incidence::created() const |
367 | { | 380 | { |
368 | return mCreated; | 381 | return mCreated; |
369 | } | 382 | } |
370 | 383 | ||
371 | void Incidence::setRevision(int rev) | 384 | void Incidence::setRevision(int rev) |
372 | { | 385 | { |
373 | if (mReadOnly) return; | 386 | if (mReadOnly) return; |
374 | mRevision = rev; | 387 | mRevision = rev; |
375 | 388 | ||
376 | updated(); | 389 | updated(); |
377 | } | 390 | } |
378 | 391 | ||
379 | int Incidence::revision() const | 392 | int Incidence::revision() const |
380 | { | 393 | { |
381 | return mRevision; | 394 | return mRevision; |
382 | } | 395 | } |
383 | 396 | ||
384 | void Incidence::setDtStart(const QDateTime &dtStart) | 397 | void Incidence::setDtStart(const QDateTime &dtStart) |
385 | { | 398 | { |
386 | 399 | ||
387 | QDateTime dt = getEvenTime(dtStart); | 400 | QDateTime dt = getEvenTime(dtStart); |
388 | 401 | ||
389 | if ( mRecurrence ) | 402 | if ( mRecurrence ) |
390 | mRecurrence->setRecurStart( dt); | 403 | mRecurrence->setRecurStart( dt); |
391 | IncidenceBase::setDtStart( dt ); | 404 | IncidenceBase::setDtStart( dt ); |
392 | } | 405 | } |
393 | 406 | ||
394 | void Incidence::setDescription(const QString &description) | 407 | void Incidence::setDescription(const QString &description) |
395 | { | 408 | { |
396 | if (mReadOnly) return; | 409 | if (mReadOnly) return; |
397 | mDescription = description; | 410 | mDescription = description; |
398 | updated(); | 411 | updated(); |
399 | } | 412 | } |
400 | 413 | ||
401 | QString Incidence::description() const | 414 | QString Incidence::description() const |
402 | { | 415 | { |
403 | return mDescription; | 416 | return mDescription; |
404 | } | 417 | } |
405 | 418 | ||
406 | 419 | ||
407 | void Incidence::setSummary(const QString &summary) | 420 | void Incidence::setSummary(const QString &summary) |
408 | { | 421 | { |
409 | if (mReadOnly) return; | 422 | if (mReadOnly) return; |
410 | mSummary = summary; | 423 | mSummary = summary; |
411 | updated(); | 424 | updated(); |
412 | } | 425 | } |
413 | 426 | ||
414 | QString Incidence::summary() const | 427 | QString Incidence::summary() const |
415 | { | 428 | { |
416 | return mSummary; | 429 | return mSummary; |
417 | } | 430 | } |
418 | void Incidence::checkCategories() | 431 | void Incidence::checkCategories() |
419 | { | 432 | { |
420 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); | 433 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); |
421 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); | 434 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); |
422 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); | 435 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); |
423 | } | 436 | } |
424 | 437 | ||
425 | void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false | 438 | void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false |
426 | { | 439 | { |
427 | if (mReadOnly) return; | 440 | if (mReadOnly) return; |
428 | int i; | 441 | int i; |
429 | for( i = 0; i < categories.count(); ++i ) { | 442 | for( i = 0; i < categories.count(); ++i ) { |
430 | if ( !mCategories.contains (categories[i])) | 443 | if ( !mCategories.contains (categories[i])) |
431 | mCategories.append( categories[i] ); | 444 | mCategories.append( categories[i] ); |
432 | } | 445 | } |
433 | checkCategories(); | 446 | checkCategories(); |
434 | updated(); | 447 | updated(); |
435 | if ( addToRelations ) { | 448 | if ( addToRelations ) { |
436 | Incidence * inc; | 449 | Incidence * inc; |
437 | QPtrList<Incidence> Relations = relations(); | 450 | QPtrList<Incidence> Relations = relations(); |
438 | for (inc=Relations.first();inc;inc=Relations.next()) { | 451 | for (inc=Relations.first();inc;inc=Relations.next()) { |
439 | inc->addCategories( categories, true ); | 452 | inc->addCategories( categories, true ); |
440 | } | 453 | } |
441 | } | 454 | } |
442 | } | 455 | } |
443 | 456 | ||
444 | void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false | 457 | void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false |
445 | { | 458 | { |
446 | if (mReadOnly) return; | 459 | if (mReadOnly) return; |
447 | mCategories = categories; | 460 | mCategories = categories; |
448 | checkCategories(); | 461 | checkCategories(); |
449 | updated(); | 462 | updated(); |
450 | if ( setForRelations ) { | 463 | if ( setForRelations ) { |
451 | Incidence * inc; | 464 | Incidence * inc; |
452 | QPtrList<Incidence> Relations = relations(); | 465 | QPtrList<Incidence> Relations = relations(); |
453 | for (inc=Relations.first();inc;inc=Relations.next()) { | 466 | for (inc=Relations.first();inc;inc=Relations.next()) { |
454 | inc->setCategories( categories, true ); | 467 | inc->setCategories( categories, true ); |
455 | } | 468 | } |
456 | } | 469 | } |
457 | } | 470 | } |
458 | 471 | ||
459 | // TODO: remove setCategories(QString) function | 472 | // TODO: remove setCategories(QString) function |
460 | void Incidence::setCategories(const QString &catStr) | 473 | void Incidence::setCategories(const QString &catStr) |
461 | { | 474 | { |
462 | if (mReadOnly) return; | 475 | if (mReadOnly) return; |
463 | mCategories.clear(); | 476 | mCategories.clear(); |
464 | 477 | ||
465 | if (catStr.isEmpty()) return; | 478 | if (catStr.isEmpty()) return; |
466 | 479 | ||
467 | mCategories = QStringList::split(",",catStr); | 480 | mCategories = QStringList::split(",",catStr); |
468 | 481 | ||
469 | QStringList::Iterator it; | 482 | QStringList::Iterator it; |
470 | for(it = mCategories.begin();it != mCategories.end(); ++it) { | 483 | for(it = mCategories.begin();it != mCategories.end(); ++it) { |
471 | *it = (*it).stripWhiteSpace(); | 484 | *it = (*it).stripWhiteSpace(); |
472 | } | 485 | } |
473 | checkCategories(); | 486 | checkCategories(); |
474 | updated(); | 487 | updated(); |
475 | } | 488 | } |
476 | // using this makes filtering 3 times faster | 489 | // using this makes filtering 3 times faster |
477 | QStringList* Incidence::categoriesP() | 490 | QStringList* Incidence::categoriesP() |
478 | { | 491 | { |
479 | return &mCategories; | 492 | return &mCategories; |
480 | } | 493 | } |
481 | 494 | ||
482 | QStringList Incidence::categories() const | 495 | QStringList Incidence::categories() const |
483 | { | 496 | { |
484 | return mCategories; | 497 | return mCategories; |
485 | } | 498 | } |