40 #include <ksystemtimezone.h>
49 class KCal::Todo::Private
53 : mPercentComplete( 0 ),
55 mHasStartDate( false ),
56 mHasCompletedDate( false )
58 Private(
const KCal::Todo::Private &other )
61 void init(
const KCal::Todo::Private &other );
65 KDateTime mDtRecurrence;
70 bool mHasCompletedDate;
75 bool recurTodo(
Todo *todo );
78 void KCal::Todo::Private::init(
const KCal::Todo::Private &other )
80 mDtDue = other.mDtDue;
81 mDtRecurrence = other.mDtRecurrence;
82 mCompleted = other.mCompleted;
83 mPercentComplete = other.mPercentComplete;
84 mHasDueDate = other.mHasDueDate;
85 mHasStartDate = other.mHasStartDate;
86 mHasCompletedDate = other.mHasCompletedDate;
92 : d( new KCal::
Todo::Private )
98 d( new KCal::
Todo::Private( *other.d ) )
109 return new Todo( *
this );
115 if ( &other ==
this ) {
159 d->mHasDueDate =
true;
160 if (
recurs() && !first ) {
161 d->mDtRecurrence =
dtDue;
185 if (
recurs() && !first && d->mDtRecurrence.isValid() ) {
186 return d->mDtRecurrence;
194 if ( spec.isValid() ) {
197 if ( spec.timeZone() != KSystemTimeZones::local() ) {
198 timeZone =
' ' + spec.timeZone().name();
201 return KGlobal::locale()->formatTime(
202 dtDue( !
recurs() ).toTimeSpec( spec ).time(), !shortfmt ) + timeZone;
204 return KGlobal::locale()->formatTime(
211 if ( spec.isValid() ) {
214 if ( spec.timeZone() != KSystemTimeZones::local() ) {
215 timeZone =
' ' + spec.timeZone().name();
218 return KGlobal::locale()->formatDate(
220 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
222 return KGlobal::locale()->formatDate(
224 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
234 if ( spec.isValid() ) {
237 if ( spec.timeZone() != KSystemTimeZones::local() ) {
238 timeZone =
' ' + spec.timeZone().name();
241 return KGlobal::locale()->formatDateTime(
243 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
245 return KGlobal::locale()->formatDateTime(
247 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
253 return d->mHasDueDate;
267 return d->mHasStartDate;
277 if ( !
comments().filter(
"NoStartDate" ).count() ) {
281 QString s(
"NoStartDate" );
284 d->mHasStartDate = f;
298 if (
recurs() && !first ) {
314 d->mHasStartDate =
true;
320 if ( spec.isValid() ) {
323 if ( spec.timeZone() != KSystemTimeZones::local() ) {
324 timeZone =
' ' + spec.timeZone().name();
327 return KGlobal::locale()->formatTime(
328 dtStart( first ).toTimeSpec( spec ).time(), !shortfmt ) + timeZone;
330 return KGlobal::locale()->formatTime(
331 dtStart( first ).time(), !shortfmt );
342 if ( spec.isValid() ) {
345 if ( spec.timeZone() != KSystemTimeZones::local() ) {
346 timeZone =
' ' + spec.timeZone().name();
349 return KGlobal::locale()->formatDate(
350 dtStart( first ).toTimeSpec( spec ).date(),
351 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
353 return KGlobal::locale()->formatDate(
355 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
370 if ( spec.isValid() ) {
373 if ( spec.timeZone() != KSystemTimeZones::local() ) {
374 timeZone =
' ' + spec.timeZone().name();
377 return KGlobal::locale()->formatDateTime(
378 dtStart( first ).toTimeSpec( spec ).dateTime(),
379 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
381 return KGlobal::locale()->formatDateTime(
383 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
393 if ( spec.isValid() ) {
396 if ( spec.timeZone() != KSystemTimeZones::local() ) {
397 timeZone =
' ' + spec.timeZone().name();
400 return KGlobal::locale()->formatDateTime(
401 dtStart().toTimeSpec( spec ).dateTime(),
402 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
404 return KGlobal::locale()->formatDateTime(
406 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
412 if ( d->mPercentComplete == 100 ) {
422 d->mPercentComplete = 100;
424 d->mPercentComplete = 0;
425 d->mHasCompletedDate =
false;
426 d->mCompleted = KDateTime();
434 return d->mCompleted;
443 KGlobal::locale()->formatDateTime( d->mCompleted.dateTime(),
444 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
449 if ( !d->recurTodo(
this ) ) {
450 d->mHasCompletedDate =
true;
451 d->mPercentComplete = 100;
452 d->mCompleted = completed.toUtc();
459 return d->mHasCompletedDate;
464 return d->mPercentComplete;
470 d->mPercentComplete = percent;
471 if ( percent != 100 ) {
472 d->mHasCompletedDate =
false;
483 if ( d->mPercentComplete > 0 ) {
487 if ( d->mHasStartDate && d->mHasDueDate ) {
489 QDate currDate = QDate::currentDate();
490 if (
dtStart( first ).date() <= currDate && currDate <
dtDue( first ).date() ) {
494 KDateTime currDate = KDateTime::currentUtcDateTime();
495 if (
dtStart( first ) <= currDate && currDate <
dtDue( first ) ) {
515 if ( d->mPercentComplete > 0 ) {
519 if ( !d->mHasStartDate ) {
524 if (
dtStart( first ).date() >= QDate::currentDate() ) {
528 if (
dtStart( first ) >= KDateTime::currentUtcDateTime() ) {
536 const KDateTime::Spec &newSpec )
539 d->mDtDue = d->mDtDue.toTimeSpec( oldSpec );
540 d->mDtDue.setTimeSpec( newSpec );
542 d->mDtRecurrence = d->mDtRecurrence.toTimeSpec( oldSpec );
543 d->mDtRecurrence.setTimeSpec( newSpec );
545 if ( d->mHasCompletedDate ) {
546 d->mCompleted = d->mCompleted.toTimeSpec( oldSpec );
547 d->mCompleted.setTimeSpec( newSpec );
553 d->mDtRecurrence = dt;
558 return d->mDtRecurrence.isValid() ? d->mDtRecurrence : d->mDtDue;
563 QDate today = QDate::currentDate();
566 !( date < today && d->mDtRecurrence.date() < today &&
572 if ( !
dtDue().isValid() ) {
577 dtDue().date() < QDate::currentDate() :
578 dtDue() < KDateTime::currentUtcDateTime();
588 bool Todo::Private::recurTodo(
Todo *todo )
596 ( nextDate.isValid() && endDateTime.isValid() &&
597 nextDate <= endDateTime ) ) ) {
599 while ( !todo->
recursAt( nextDate ) ||
600 nextDate <= KDateTime::currentUtcDateTime() ) {
602 if ( !nextDate.isValid() ||
603 ( nextDate > endDateTime && r->
duration() != -1 ) ) {