-rw-r--r-- | libkcal/todo.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 5260051..4ada2d8 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -348,254 +348,268 @@ int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) | |||
348 | if ( dtDue().date() == date ) | 348 | if ( dtDue().date() == date ) |
349 | retval = 1; | 349 | retval = 1; |
350 | } | 350 | } |
351 | if ( checkSubtodos ) { | 351 | if ( checkSubtodos ) { |
352 | Incidence *aTodo; | 352 | Incidence *aTodo; |
353 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 353 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
354 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); | 354 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); |
355 | if ( ret == 2 ) | 355 | if ( ret == 2 ) |
356 | return 2; | 356 | return 2; |
357 | if ( ret == 1) | 357 | if ( ret == 1) |
358 | retval = 1; | 358 | retval = 1; |
359 | } | 359 | } |
360 | } | 360 | } |
361 | return retval; | 361 | return retval; |
362 | } | 362 | } |
363 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true | 363 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true |
364 | { | 364 | { |
365 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); | 365 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); |
366 | } | 366 | } |
367 | bool Todo::hasDueDate() const | 367 | bool Todo::hasDueDate() const |
368 | { | 368 | { |
369 | return mHasDueDate; | 369 | return mHasDueDate; |
370 | } | 370 | } |
371 | 371 | ||
372 | void Todo::setHasDueDate(bool f) | 372 | void Todo::setHasDueDate(bool f) |
373 | { | 373 | { |
374 | if (mReadOnly) return; | 374 | if (mReadOnly) return; |
375 | mHasDueDate = f; | 375 | mHasDueDate = f; |
376 | updated(); | 376 | updated(); |
377 | } | 377 | } |
378 | 378 | ||
379 | 379 | ||
380 | #if 0 | 380 | #if 0 |
381 | void Todo::setStatus(const QString &statStr) | 381 | void Todo::setStatus(const QString &statStr) |
382 | { | 382 | { |
383 | if (mReadOnly) return; | 383 | if (mReadOnly) return; |
384 | QString ss(statStr.upper()); | 384 | QString ss(statStr.upper()); |
385 | 385 | ||
386 | if (ss == "X-ACTION") | 386 | if (ss == "X-ACTION") |
387 | mStatus = NEEDS_ACTION; | 387 | mStatus = NEEDS_ACTION; |
388 | else if (ss == "NEEDS ACTION") | 388 | else if (ss == "NEEDS ACTION") |
389 | mStatus = NEEDS_ACTION; | 389 | mStatus = NEEDS_ACTION; |
390 | else if (ss == "ACCEPTED") | 390 | else if (ss == "ACCEPTED") |
391 | mStatus = ACCEPTED; | 391 | mStatus = ACCEPTED; |
392 | else if (ss == "SENT") | 392 | else if (ss == "SENT") |
393 | mStatus = SENT; | 393 | mStatus = SENT; |
394 | else if (ss == "TENTATIVE") | 394 | else if (ss == "TENTATIVE") |
395 | mStatus = TENTATIVE; | 395 | mStatus = TENTATIVE; |
396 | else if (ss == "CONFIRMED") | 396 | else if (ss == "CONFIRMED") |
397 | mStatus = CONFIRMED; | 397 | mStatus = CONFIRMED; |
398 | else if (ss == "DECLINED") | 398 | else if (ss == "DECLINED") |
399 | mStatus = DECLINED; | 399 | mStatus = DECLINED; |
400 | else if (ss == "COMPLETED") | 400 | else if (ss == "COMPLETED") |
401 | mStatus = COMPLETED; | 401 | mStatus = COMPLETED; |
402 | else if (ss == "DELEGATED") | 402 | else if (ss == "DELEGATED") |
403 | mStatus = DELEGATED; | 403 | mStatus = DELEGATED; |
404 | 404 | ||
405 | updated(); | 405 | updated(); |
406 | } | 406 | } |
407 | 407 | ||
408 | void Todo::setStatus(int status) | 408 | void Todo::setStatus(int status) |
409 | { | 409 | { |
410 | if (mReadOnly) return; | 410 | if (mReadOnly) return; |
411 | mStatus = status; | 411 | mStatus = status; |
412 | updated(); | 412 | updated(); |
413 | } | 413 | } |
414 | 414 | ||
415 | int Todo::status() const | 415 | int Todo::status() const |
416 | { | 416 | { |
417 | return mStatus; | 417 | return mStatus; |
418 | } | 418 | } |
419 | 419 | ||
420 | QString Todo::statusStr() const | 420 | QString Todo::statusStr() const |
421 | { | 421 | { |
422 | switch(mStatus) { | 422 | switch(mStatus) { |
423 | case NEEDS_ACTION: | 423 | case NEEDS_ACTION: |
424 | return QString("NEEDS ACTION"); | 424 | return QString("NEEDS ACTION"); |
425 | break; | 425 | break; |
426 | case ACCEPTED: | 426 | case ACCEPTED: |
427 | return QString("ACCEPTED"); | 427 | return QString("ACCEPTED"); |
428 | break; | 428 | break; |
429 | case SENT: | 429 | case SENT: |
430 | return QString("SENT"); | 430 | return QString("SENT"); |
431 | break; | 431 | break; |
432 | case TENTATIVE: | 432 | case TENTATIVE: |
433 | return QString("TENTATIVE"); | 433 | return QString("TENTATIVE"); |
434 | break; | 434 | break; |
435 | case CONFIRMED: | 435 | case CONFIRMED: |
436 | return QString("CONFIRMED"); | 436 | return QString("CONFIRMED"); |
437 | break; | 437 | break; |
438 | case DECLINED: | 438 | case DECLINED: |
439 | return QString("DECLINED"); | 439 | return QString("DECLINED"); |
440 | break; | 440 | break; |
441 | case COMPLETED: | 441 | case COMPLETED: |
442 | return QString("COMPLETED"); | 442 | return QString("COMPLETED"); |
443 | break; | 443 | break; |
444 | case DELEGATED: | 444 | case DELEGATED: |
445 | return QString("DELEGATED"); | 445 | return QString("DELEGATED"); |
446 | break; | 446 | break; |
447 | } | 447 | } |
448 | return QString(""); | 448 | return QString(""); |
449 | } | 449 | } |
450 | #endif | 450 | #endif |
451 | 451 | ||
452 | bool Todo::isCompleted() const | 452 | bool Todo::isCompleted() const |
453 | { | 453 | { |
454 | if (mPercentComplete == 100) { | 454 | if (mPercentComplete == 100) { |
455 | return true; | 455 | return true; |
456 | } | 456 | } |
457 | else return false; | 457 | else return false; |
458 | } | 458 | } |
459 | 459 | ||
460 | void Todo::setCompleted(bool completed) | 460 | void Todo::setCompleted(bool completed) |
461 | { | 461 | { |
462 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { | 462 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { |
463 | if ( !setRecurDates() ) | 463 | if ( !setRecurDates() ) |
464 | completed = false; | 464 | completed = false; |
465 | } | 465 | } |
466 | if (completed) mPercentComplete = 100; | 466 | if (completed) mPercentComplete = 100; |
467 | else { | 467 | else { |
468 | mPercentComplete = 0; | 468 | mPercentComplete = 0; |
469 | mHasCompletedDate = false; | 469 | mHasCompletedDate = false; |
470 | } | 470 | } |
471 | updated(); | 471 | updated(); |
472 | } | 472 | } |
473 | 473 | ||
474 | QDateTime Todo::completed() const | 474 | QDateTime Todo::completed() const |
475 | { | 475 | { |
476 | return mCompleted; | 476 | return mCompleted; |
477 | } | 477 | } |
478 | 478 | ||
479 | QString Todo::completedStr( bool shortF ) const | 479 | QString Todo::completedStr( bool shortF ) const |
480 | { | 480 | { |
481 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); | 481 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); |
482 | } | 482 | } |
483 | 483 | ||
484 | void Todo::setCompleted(const QDateTime &completed) | 484 | void Todo::setCompleted(const QDateTime &completed) |
485 | { | 485 | { |
486 | //qDebug("Todo::setCompleted "); | 486 | //qDebug("Todo::setCompleted "); |
487 | if ( mHasCompletedDate ) { | 487 | if ( mHasCompletedDate ) { |
488 | // qDebug("has completed data - return "); | 488 | // qDebug("has completed data - return "); |
489 | return; | 489 | return; |
490 | } | 490 | } |
491 | mHasCompletedDate = true; | 491 | mHasCompletedDate = true; |
492 | mPercentComplete = 100; | 492 | mPercentComplete = 100; |
493 | mCompleted = getEvenTime(completed); | 493 | mCompleted = getEvenTime(completed); |
494 | updated(); | 494 | updated(); |
495 | } | 495 | } |
496 | 496 | ||
497 | bool Todo::hasCompletedDate() const | 497 | bool Todo::hasCompletedDate() const |
498 | { | 498 | { |
499 | return mHasCompletedDate; | 499 | return mHasCompletedDate; |
500 | } | 500 | } |
501 | 501 | ||
502 | int Todo::percentComplete() const | 502 | int Todo::percentComplete() const |
503 | { | 503 | { |
504 | return mPercentComplete; | 504 | return mPercentComplete; |
505 | } | 505 | } |
506 | bool Todo::setRecurDates() | 506 | bool Todo::setRecurDates() |
507 | { | 507 | { |
508 | if ( !mHasRecurrenceID ) | 508 | if ( !mHasRecurrenceID ) |
509 | return true; | 509 | return true; |
510 | int secs = mDtStart.secsTo( dtDue() ); | 510 | int secs = mDtStart.secsTo( dtDue() ); |
511 | bool ok; | 511 | bool ok; |
512 | qDebug("T:setRecurDates() "); | 512 | qDebug("T:setRecurDates() "); |
513 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 513 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
514 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); | 514 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); |
515 | if ( ok ) { | 515 | if ( ok ) { |
516 | mRecurrenceID = next; | 516 | mRecurrenceID = next; |
517 | mDtStart = next; | 517 | mDtStart = next; |
518 | setDtDue( next.addSecs( secs ) ); | 518 | setDtDue( next.addSecs( secs ) ); |
519 | if ( QDateTime::currentDateTime() > next) | 519 | if ( QDateTime::currentDateTime() > next) |
520 | return false; | 520 | return false; |
521 | } else { | 521 | } else { |
522 | setHasRecurrenceID( false ); | 522 | setHasRecurrenceID( false ); |
523 | recurrence()->unsetRecurs(); | 523 | recurrence()->unsetRecurs(); |
524 | } | 524 | } |
525 | return true; | 525 | return true; |
526 | } | 526 | } |
527 | void Todo::setPercentComplete(int v) | 527 | void Todo::setPercentComplete(int v) |
528 | { | 528 | { |
529 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { | 529 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { |
530 | if ( !setRecurDates() ) | 530 | if ( !setRecurDates() ) |
531 | v = 0; | 531 | v = 0; |
532 | } | 532 | } |
533 | mPercentComplete = v; | 533 | mPercentComplete = v; |
534 | if ( v != 100 ) | 534 | if ( v != 100 ) |
535 | mHasCompletedDate = false; | 535 | mHasCompletedDate = false; |
536 | updated(); | 536 | updated(); |
537 | } | 537 | } |
538 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const | 538 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const |
539 | { | 539 | { |
540 | if ( isCompleted() || ! hasDueDate() || cancelled() || !alarmEnabled() ) { | 540 | *ok = false; |
541 | *ok = false; | 541 | if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) { |
542 | return QDateTime (); | 542 | return QDateTime (); |
543 | } | 543 | } |
544 | // if the recurring todo is set to complete and requested time < start time of todo | ||
545 | // we want to get the alarm. | ||
546 | bool iscompleted = isCompleted(); | ||
547 | if ( iscompleted && doesRecur() ) { | ||
548 | Todo * to = (Todo*) this; | ||
549 | to->checkSetCompletedFalse(); | ||
550 | iscompleted = isCompleted(); | ||
551 | if ( hasStartDate() && start_dt < dtStart() ){ | ||
552 | iscompleted = false; | ||
553 | } | ||
554 | } | ||
555 | if ( iscompleted ) { | ||
556 | return QDateTime (); | ||
557 | } | ||
544 | QDateTime incidenceStart; | 558 | QDateTime incidenceStart; |
545 | incidenceStart = dtDue(); | 559 | incidenceStart = dtDue(); |
546 | bool enabled = false; | 560 | bool enabled = false; |
547 | Alarm* alarm; | 561 | Alarm* alarm; |
548 | int off = 0; | 562 | int off = 0; |
549 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 563 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
550 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 564 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
551 | // *ok = false; | 565 | // *ok = false; |
552 | // return incidenceStart; | 566 | // return incidenceStart; |
553 | // } | 567 | // } |
554 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 568 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
555 | if (alarm->enabled()) { | 569 | if (alarm->enabled()) { |
556 | if ( alarm->hasTime () ) { | 570 | if ( alarm->hasTime () ) { |
557 | if ( alarm->time() < alarmStart ) { | 571 | if ( alarm->time() < alarmStart ) { |
558 | alarmStart = alarm->time(); | 572 | alarmStart = alarm->time(); |
559 | enabled = true; | 573 | enabled = true; |
560 | off = alarmStart.secsTo( incidenceStart ); | 574 | off = alarmStart.secsTo( incidenceStart ); |
561 | } | 575 | } |
562 | 576 | ||
563 | } else { | 577 | } else { |
564 | int secs = alarm->startOffset().asSeconds(); | 578 | int secs = alarm->startOffset().asSeconds(); |
565 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | 579 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { |
566 | alarmStart = incidenceStart.addSecs( secs ); | 580 | alarmStart = incidenceStart.addSecs( secs ); |
567 | enabled = true; | 581 | enabled = true; |
568 | off = -secs; | 582 | off = -secs; |
569 | } | 583 | } |
570 | } | 584 | } |
571 | } | 585 | } |
572 | } | 586 | } |
573 | if ( enabled ) { | 587 | if ( enabled ) { |
574 | if ( alarmStart > start_dt ) { | 588 | if ( alarmStart > start_dt ) { |
575 | *ok = true; | 589 | *ok = true; |
576 | * offset = off; | 590 | * offset = off; |
577 | return alarmStart; | 591 | return alarmStart; |
578 | } | 592 | } |
579 | } | 593 | } |
580 | *ok = false; | 594 | *ok = false; |
581 | return QDateTime (); | 595 | return QDateTime (); |
582 | 596 | ||
583 | } | 597 | } |
584 | 598 | ||
585 | void Todo::checkSetCompletedFalse() | 599 | void Todo::checkSetCompletedFalse() |
586 | { | 600 | { |
587 | if ( !mHasRecurrenceID ) { | 601 | if ( !mHasRecurrenceID ) { |
588 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); | 602 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); |
589 | return; | 603 | return; |
590 | } | 604 | } |
591 | // qDebug("Todo::checkSetCompletedFalse()"); | 605 | // qDebug("Todo::checkSetCompletedFalse()"); |
592 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 606 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
593 | if ( mPercentComplete == 100 ) { | 607 | if ( mPercentComplete == 100 ) { |
594 | QDateTime dt = QDateTime::currentDateTime(); | 608 | QDateTime dt = QDateTime::currentDateTime(); |
595 | if ( dt > mDtStart && dt > mRecurrenceID ) { | 609 | if ( dt > mDtStart && dt > mRecurrenceID ) { |
596 | qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 610 | qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
597 | setCompleted( false ); | 611 | setCompleted( false ); |
598 | qDebug("Todo::checkSetCompletedFalse "); | 612 | qDebug("Todo::checkSetCompletedFalse "); |
599 | } | 613 | } |
600 | } | 614 | } |
601 | } | 615 | } |