-rw-r--r-- | libopie/pim/orecur.cpp | 147 |
1 files changed, 111 insertions, 36 deletions
diff --git a/libopie/pim/orecur.cpp b/libopie/pim/orecur.cpp index eae1fdc..8c9ad46 100644 --- a/libopie/pim/orecur.cpp +++ b/libopie/pim/orecur.cpp | |||
@@ -363,148 +363,223 @@ bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { | |||
363 | return FALSE; | 363 | return FALSE; |
364 | } | 364 | } |
365 | } | 365 | } |
366 | ORecur::RepeatType ORecur::type()const{ | 366 | ORecur::RepeatType ORecur::type()const{ |
367 | return data->type; | 367 | return data->type; |
368 | } | 368 | } |
369 | int ORecur::frequency()const { | 369 | int ORecur::frequency()const { |
370 | return data->freq; | 370 | return data->freq; |
371 | } | 371 | } |
372 | int ORecur::position()const { | 372 | int ORecur::position()const { |
373 | return data->pos; | 373 | return data->pos; |
374 | } | 374 | } |
375 | char ORecur::days() const{ | 375 | char ORecur::days() const{ |
376 | return data->days; | 376 | return data->days; |
377 | } | 377 | } |
378 | bool ORecur::hasEndDate()const { | 378 | bool ORecur::hasEndDate()const { |
379 | return data->hasEnd; | 379 | return data->hasEnd; |
380 | } | 380 | } |
381 | QDate ORecur::endDate()const { | 381 | QDate ORecur::endDate()const { |
382 | return data->end; | 382 | return data->end; |
383 | } | 383 | } |
384 | QDate ORecur::start()const{ | 384 | QDate ORecur::start()const{ |
385 | return data->start; | 385 | return data->start; |
386 | } | 386 | } |
387 | QDateTime ORecur::createdDateTime()const { | 387 | QDateTime ORecur::createdDateTime()const { |
388 | return data->create; | 388 | return data->create; |
389 | } | 389 | } |
390 | int ORecur::repetition()const { | 390 | int ORecur::repetition()const { |
391 | return data->rep; | 391 | return data->rep; |
392 | } | 392 | } |
393 | QString ORecur::service()const { | 393 | QString ORecur::service()const { |
394 | return data->app; | 394 | return data->app; |
395 | } | 395 | } |
396 | ORecur::ExceptionList& ORecur::exceptions() { | 396 | ORecur::ExceptionList& ORecur::exceptions() { |
397 | return data->list; | 397 | return data->list; |
398 | } | 398 | } |
399 | void ORecur::setType( const RepeatType& z) { | 399 | void ORecur::setType( const RepeatType& z) { |
400 | checkOrModify(); | 400 | checkOrModify(); |
401 | data->type = z; | 401 | data->type = z; |
402 | } | 402 | } |
403 | void ORecur::setFrequency( int freq ) { | 403 | void ORecur::setFrequency( int freq ) { |
404 | checkOrModify(); | 404 | checkOrModify(); |
405 | data->freq = freq; | 405 | data->freq = freq; |
406 | } | 406 | } |
407 | void ORecur::setPosition( int pos ) { | 407 | void ORecur::setPosition( int pos ) { |
408 | checkOrModify(); | 408 | checkOrModify(); |
409 | data->pos = pos; | 409 | data->pos = pos; |
410 | } | 410 | } |
411 | void ORecur::setDays( char c ) { | 411 | void ORecur::setDays( char c ) { |
412 | checkOrModify(); | 412 | checkOrModify(); |
413 | data->days = c; | 413 | data->days = c; |
414 | } | 414 | } |
415 | void ORecur::setEndDate( const QDate& dt) { | 415 | void ORecur::setEndDate( const QDate& dt) { |
416 | checkOrModify(); | 416 | checkOrModify(); |
417 | data->end = dt; | 417 | data->end = dt; |
418 | } | 418 | } |
419 | void ORecur::setCreatedDateTime( const QDateTime& t) { | 419 | void ORecur::setCreatedDateTime( const QDateTime& t) { |
420 | checkOrModify(); | 420 | checkOrModify(); |
421 | data->create = t; | 421 | data->create = t; |
422 | } | 422 | } |
423 | void ORecur::setHasEndDate( bool b) { | 423 | void ORecur::setHasEndDate( bool b) { |
424 | checkOrModify(); | 424 | checkOrModify(); |
425 | data->hasEnd = b; | 425 | data->hasEnd = b; |
426 | } | 426 | } |
427 | void ORecur::setRepitition( int rep ) { | 427 | void ORecur::setRepitition( int rep ) { |
428 | checkOrModify(); | 428 | checkOrModify(); |
429 | data->rep = rep; | 429 | data->rep = rep; |
430 | } | 430 | } |
431 | void ORecur::setService( const QString& app ) { | 431 | void ORecur::setService( const QString& app ) { |
432 | checkOrModify(); | 432 | checkOrModify(); |
433 | data->app = app; | 433 | data->app = app; |
434 | } | 434 | } |
435 | void ORecur::setStart( const QDate& dt ) { | 435 | void ORecur::setStart( const QDate& dt ) { |
436 | checkOrModify(); | 436 | checkOrModify(); |
437 | data->start = dt; | 437 | data->start = dt; |
438 | } | 438 | } |
439 | void ORecur::checkOrModify() { | 439 | void ORecur::checkOrModify() { |
440 | if ( data->count != 1 ) { | 440 | if ( data->count != 1 ) { |
441 | data->deref(); | 441 | data->deref(); |
442 | Data* d2 = new Data; | 442 | Data* d2 = new Data; |
443 | d2->days = data->days; | 443 | d2->days = data->days; |
444 | d2->type = data->type; | 444 | d2->type = data->type; |
445 | d2->freq = data->freq; | 445 | d2->freq = data->freq; |
446 | d2->pos = data->pos; | 446 | d2->pos = data->pos; |
447 | d2->hasEnd = data->hasEnd; | 447 | d2->hasEnd = data->hasEnd; |
448 | d2->end = data->end; | 448 | d2->end = data->end; |
449 | d2->create = data->create; | 449 | d2->create = data->create; |
450 | d2->rep = data->rep; | 450 | d2->rep = data->rep; |
451 | d2->app = data->app; | 451 | d2->app = data->app; |
452 | d2->list = data->list; | 452 | d2->list = data->list; |
453 | d2->start = data->start; | 453 | d2->start = data->start; |
454 | data = d2; | 454 | data = d2; |
455 | } | 455 | } |
456 | } | 456 | } |
457 | QString ORecur::toString()const { | 457 | QString ORecur::toString()const { |
458 | QString buf; | 458 | QString buf; |
459 | QMap<int, QString> recMap = toMap(); | ||
459 | 460 | ||
460 | buf += " rtype=\""; | 461 | buf += " rtype=\""; |
461 | switch ( data->type ) { | 462 | buf += recMap[ORecur::RType]; |
462 | case ORecur::Daily: | ||
463 | buf += "Daily"; | ||
464 | break; | ||
465 | case ORecur::Weekly: | ||
466 | buf += "Weekly"; | ||
467 | break; | ||
468 | case ORecur::MonthlyDay: | ||
469 | buf += "MonthlyDay"; | ||
470 | break; | ||
471 | case ORecur::MonthlyDate: | ||
472 | buf += "MonthlyDate"; | ||
473 | break; | ||
474 | case ORecur::Yearly: | ||
475 | buf += "Yearly"; | ||
476 | break; | ||
477 | default: | ||
478 | buf += "NoRepeat"; | ||
479 | break; | ||
480 | } | ||
481 | buf += "\""; | 463 | buf += "\""; |
482 | if (data->days > 0 ) | 464 | if (data->days > 0 ) |
483 | buf += " rweekdays=\"" + QString::number( static_cast<int>( data->days ) ) + "\""; | 465 | buf += " rweekdays=\"" + recMap[ORecur::RWeekdays] + "\""; |
484 | if ( data->pos != 0 ) | 466 | if ( data->pos != 0 ) |
485 | buf += " rposition=\"" + QString::number(data->pos ) + "\""; | 467 | buf += " rposition=\"" + recMap[ORecur::RPosition] + "\""; |
486 | 468 | ||
487 | buf += " rfreq=\"" + QString::number( data->freq ) + "\""; | 469 | buf += " rfreq=\"" + recMap[ORecur::RFreq] + "\""; |
488 | buf += " rhasenddate=\"" + QString::number( static_cast<int>( data->hasEnd ) ) + "\""; | 470 | buf += " rhasenddate=\"" + recMap[ORecur::RHasEndDate]+ "\""; |
489 | if ( data->hasEnd ) | 471 | if ( data->hasEnd ) |
490 | buf += " enddt=\"" | 472 | buf += " enddt=\"" |
491 | + QString::number( OTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) | 473 | + recMap[ORecur::EndDate] |
492 | + "\""; | 474 | + "\""; |
493 | buf += " created=\"" + QString::number( OTimeZone::utc().fromUTCDateTime( data->create ) ) + "\""; | 475 | buf += " created=\"" + recMap[ORecur::Created] + "\""; |
494 | 476 | ||
495 | if ( data->list.isEmpty() ) return buf; | 477 | if ( data->list.isEmpty() ) return buf; |
496 | // save exceptions list here!! | ||
497 | ExceptionList::ConstIterator it; | ||
498 | ExceptionList list = data->list; | ||
499 | buf += " exceptions=\""; | 478 | buf += " exceptions=\""; |
500 | QDate date; | 479 | buf += recMap[ORecur::Exceptions]; |
501 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
502 | date = (*it); | ||
503 | if ( it != list.begin() ) buf += " "; | ||
504 | |||
505 | buf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); | ||
506 | } | ||
507 | buf += "\" "; | 480 | buf += "\" "; |
508 | 481 | ||
509 | return buf; | 482 | return buf; |
510 | } | 483 | } |
484 | |||
485 | QString ORecur::rTypeString() const | ||
486 | { | ||
487 | QString retString; | ||
488 | switch ( data->type ) { | ||
489 | case ORecur::Daily: | ||
490 | retString = "Daily"; | ||
491 | break; | ||
492 | case ORecur::Weekly: | ||
493 | retString = "Weekly"; | ||
494 | break; | ||
495 | case ORecur::MonthlyDay: | ||
496 | retString = "MonthlyDay"; | ||
497 | break; | ||
498 | case ORecur::MonthlyDate: | ||
499 | retString = "MonthlyDate"; | ||
500 | break; | ||
501 | case ORecur::Yearly: | ||
502 | retString = "Yearly"; | ||
503 | break; | ||
504 | default: | ||
505 | retString = "NoRepeat"; | ||
506 | break; | ||
507 | |||
508 | } | ||
509 | |||
510 | return retString; | ||
511 | } | ||
512 | |||
513 | QMap<QString, ORecur::RepeatType> ORecur::rTypeValueConvertMap() const | ||
514 | { | ||
515 | QMap<QString, RepeatType> convertMap; | ||
516 | |||
517 | convertMap.insert( QString( "Daily" ), ORecur::Daily ); | ||
518 | convertMap.insert( QString( "Weekly" ), ORecur::Weekly ); | ||
519 | convertMap.insert( QString( "MonthlyDay" ), ORecur::MonthlyDay ); | ||
520 | convertMap.insert( QString( "MonthlyDate" ), ORecur::MonthlyDate ); | ||
521 | convertMap.insert( QString( "Yearly" ), ORecur::Yearly ); | ||
522 | convertMap.insert( QString( "NoRepeat" ), ORecur::NoRepeat ); | ||
523 | |||
524 | return convertMap; | ||
525 | } | ||
526 | |||
527 | |||
528 | QMap<int, QString> ORecur::toMap() const | ||
529 | { | ||
530 | QMap<int, QString> retMap; | ||
531 | |||
532 | retMap.insert( ORecur::RType, rTypeString() ); | ||
533 | retMap.insert( ORecur::RWeekdays, QString::number( static_cast<int>( data->days ) ) ); | ||
534 | retMap.insert( ORecur::RPosition, QString::number(data->pos ) ); | ||
535 | retMap.insert( ORecur::RFreq, QString::number( data->freq ) ); | ||
536 | retMap.insert( ORecur::RHasEndDate, QString::number( static_cast<int>( data->hasEnd ) ) ); | ||
537 | if( data -> hasEnd ) | ||
538 | retMap.insert( ORecur::EndDate, QString::number( OTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) ); | ||
539 | retMap.insert( ORecur::Created, QString::number( OTimeZone::utc().fromUTCDateTime( data->create ) ) ); | ||
540 | |||
541 | if ( data->list.isEmpty() ) return retMap; | ||
542 | |||
543 | // save exceptions list here!! | ||
544 | ExceptionList::ConstIterator it; | ||
545 | ExceptionList list = data->list; | ||
546 | QString exceptBuf; | ||
547 | QDate date; | ||
548 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
549 | date = (*it); | ||
550 | if ( it != list.begin() ) exceptBuf += " "; | ||
551 | |||
552 | exceptBuf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); | ||
553 | } | ||
554 | |||
555 | retMap.insert( ORecur::Exceptions, exceptBuf ); | ||
556 | |||
557 | return retMap; | ||
558 | } | ||
559 | |||
560 | void ORecur::fromMap( const QMap<int, QString>& map ) | ||
561 | { | ||
562 | QMap<QString, RepeatType> repTypeMap = rTypeValueConvertMap(); | ||
563 | |||
564 | data -> type = repTypeMap[ map [ORecur::RType] ]; | ||
565 | data -> days = (char) map[ ORecur::RWeekdays ].toInt(); | ||
566 | data -> pos = map[ ORecur::RPosition ].toInt(); | ||
567 | data -> freq = map[ ORecur::RFreq ].toInt(); | ||
568 | data -> hasEnd= map[ ORecur::RHasEndDate ].toInt() ? true : false; | ||
569 | OTimeZone utc = OTimeZone::utc(); | ||
570 | if ( data -> hasEnd ){ | ||
571 | data -> end = utc.fromUTCDateTime( (time_t) map[ ORecur::EndDate ].toLong() ).date(); | ||
572 | } | ||
573 | data -> create = utc.fromUTCDateTime( (time_t) map[ ORecur::Created ].toLong() ).date(); | ||
574 | |||
575 | #if 0 | ||
576 | // FIXME: Exceptions currently not supported... | ||
577 | // Convert the list of exceptions from QString into ExceptionList | ||
578 | data -> list.clear(); | ||
579 | QString exceptStr = map[ ORecur::Exceptions ]; | ||
580 | QStringList exceptList = QStringList::split( " ", exceptStr ); | ||
581 | ... | ||
582 | #endif | ||
583 | |||
584 | |||
585 | } | ||