39 #include <klocalizedstring.h>
41 #include <ksystemtimezone.h>
50 class KCal::Todo::Private
54 : mPercentComplete( 0 ),
56 mHasStartDate( false ),
57 mHasCompletedDate( false )
59 Private(
const KCal::Todo::Private &other )
62 void init(
const KCal::Todo::Private &other );
66 KDateTime mDtRecurrence;
71 bool mHasCompletedDate;
76 bool recurTodo(
Todo *todo );
79 void KCal::Todo::Private::init(
const KCal::Todo::Private &other )
81 mDtDue = other.mDtDue;
82 mDtRecurrence = other.mDtRecurrence;
83 mCompleted = other.mCompleted;
84 mPercentComplete = other.mPercentComplete;
85 mHasDueDate = other.mHasDueDate;
86 mHasStartDate = other.mHasStartDate;
87 mHasCompletedDate = other.mHasCompletedDate;
93 : d( new KCal::
Todo::Private )
99 d( new KCal::
Todo::Private( *other.d ) )
110 return new Todo( *
this );
116 if ( &other ==
this ) {
160 d->mHasDueDate =
true;
161 if (
recurs() && !first ) {
162 d->mDtRecurrence =
dtDue;
186 if (
recurs() && !first && d->mDtRecurrence.isValid() ) {
187 return d->mDtRecurrence;
195 if ( spec.isValid() ) {
198 if ( spec.timeZone() != KSystemTimeZones::local() ) {
199 timeZone =
' ' + spec.timeZone().name();
202 return KGlobal::locale()->formatTime(
203 dtDue( !
recurs() ).toTimeSpec( spec ).time(), !shortfmt ) + timeZone;
205 return KGlobal::locale()->formatTime(
212 if ( spec.isValid() ) {
215 if ( spec.timeZone() != KSystemTimeZones::local() ) {
216 timeZone =
' ' + spec.timeZone().name();
219 return KGlobal::locale()->formatDate(
221 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
223 return KGlobal::locale()->formatDate(
225 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
235 if ( spec.isValid() ) {
238 if ( spec.timeZone() != KSystemTimeZones::local() ) {
239 timeZone =
' ' + spec.timeZone().name();
242 return KGlobal::locale()->formatDateTime(
244 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
246 return KGlobal::locale()->formatDateTime(
248 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
254 return d->mHasDueDate;
268 return d->mHasStartDate;
278 if ( !
comments().filter(
"NoStartDate" ).count() ) {
282 QString s(
"NoStartDate" );
285 d->mHasStartDate = f;
299 if (
recurs() && !first ) {
315 d->mHasStartDate =
true;
321 if ( spec.isValid() ) {
324 if ( spec.timeZone() != KSystemTimeZones::local() ) {
325 timeZone =
' ' + spec.timeZone().name();
328 return KGlobal::locale()->formatTime(
329 dtStart( first ).toTimeSpec( spec ).time(), !shortfmt ) + timeZone;
331 return KGlobal::locale()->formatTime(
332 dtStart( first ).time(), !shortfmt );
343 if ( spec.isValid() ) {
346 if ( spec.timeZone() != KSystemTimeZones::local() ) {
347 timeZone =
' ' + spec.timeZone().name();
350 return KGlobal::locale()->formatDate(
351 dtStart( first ).toTimeSpec( spec ).date(),
352 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
354 return KGlobal::locale()->formatDate(
356 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
371 if ( spec.isValid() ) {
374 if ( spec.timeZone() != KSystemTimeZones::local() ) {
375 timeZone =
' ' + spec.timeZone().name();
378 return KGlobal::locale()->formatDateTime(
379 dtStart( first ).toTimeSpec( spec ).dateTime(),
380 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
382 return KGlobal::locale()->formatDateTime(
384 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
394 if ( spec.isValid() ) {
397 if ( spec.timeZone() != KSystemTimeZones::local() ) {
398 timeZone =
' ' + spec.timeZone().name();
401 return KGlobal::locale()->formatDateTime(
402 dtStart().toTimeSpec( spec ).dateTime(),
403 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
405 return KGlobal::locale()->formatDateTime(
407 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
413 if ( d->mPercentComplete == 100 ) {
423 d->mPercentComplete = 100;
425 d->mPercentComplete = 0;
426 d->mHasCompletedDate =
false;
427 d->mCompleted = KDateTime();
435 return d->mCompleted;
444 KGlobal::locale()->formatDateTime( d->mCompleted.dateTime(),
445 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
450 if ( !d->recurTodo(
this ) ) {
451 d->mHasCompletedDate =
true;
452 d->mPercentComplete = 100;
453 d->mCompleted = completed.toUtc();
460 return d->mHasCompletedDate;
465 return d->mPercentComplete;
471 d->mPercentComplete = percent;
472 if ( percent != 100 ) {
473 d->mHasCompletedDate =
false;
484 if ( d->mPercentComplete > 0 ) {
488 if ( d->mHasStartDate && d->mHasDueDate ) {
490 QDate currDate = QDate::currentDate();
491 if (
dtStart( first ).date() <= currDate && currDate <
dtDue( first ).date() ) {
495 KDateTime currDate = KDateTime::currentUtcDateTime();
496 if (
dtStart( first ) <= currDate && currDate <
dtDue( first ) ) {
516 if ( d->mPercentComplete > 0 ) {
520 if ( !d->mHasStartDate ) {
525 if (
dtStart( first ).date() >= QDate::currentDate() ) {
529 if (
dtStart( first ) >= KDateTime::currentUtcDateTime() ) {
537 const KDateTime::Spec &newSpec )
540 d->mDtDue = d->mDtDue.toTimeSpec( oldSpec );
541 d->mDtDue.setTimeSpec( newSpec );
543 d->mDtRecurrence = d->mDtRecurrence.toTimeSpec( oldSpec );
544 d->mDtRecurrence.setTimeSpec( newSpec );
546 if ( d->mHasCompletedDate ) {
547 d->mCompleted = d->mCompleted.toTimeSpec( oldSpec );
548 d->mCompleted.setTimeSpec( newSpec );
554 d->mDtRecurrence = dt;
559 return d->mDtRecurrence.isValid() ? d->mDtRecurrence : d->mDtDue;
564 QDate today = QDate::currentDate();
567 !( date < today && d->mDtRecurrence.date() < today &&
573 if ( !
dtDue().isValid() ) {
578 dtDue().date() < QDate::currentDate() :
579 dtDue() < KDateTime::currentUtcDateTime();
589 bool Todo::Private::recurTodo(
Todo *todo )
597 ( nextDate.isValid() && endDateTime.isValid() &&
598 nextDate <= endDateTime ) ) ) {
600 while ( !todo->
recursAt( nextDate ) ||
601 nextDate <= KDateTime::currentUtcDateTime() ) {
603 if ( !nextDate.isValid() ||
604 ( nextDate > endDateTime && r->
duration() != -1 ) ) {