-rw-r--r-- | libopie2/opiepim/core/orecur.cpp | 121 | ||||
-rw-r--r-- | libopie2/opiepim/core/orecur.h | 12 |
2 files changed, 109 insertions, 24 deletions
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp index eae1fdc..8c9ad46 100644 --- a/libopie2/opiepim/core/orecur.cpp +++ b/libopie2/opiepim/core/orecur.cpp | |||
@@ -456,55 +456,130 @@ void ORecur::checkOrModify() { | |||
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=\""; |
462 | buf += recMap[ORecur::RType]; | ||
463 | buf += "\""; | ||
464 | if (data->days > 0 ) | ||
465 | buf += " rweekdays=\"" + recMap[ORecur::RWeekdays] + "\""; | ||
466 | if ( data->pos != 0 ) | ||
467 | buf += " rposition=\"" + recMap[ORecur::RPosition] + "\""; | ||
468 | |||
469 | buf += " rfreq=\"" + recMap[ORecur::RFreq] + "\""; | ||
470 | buf += " rhasenddate=\"" + recMap[ORecur::RHasEndDate]+ "\""; | ||
471 | if ( data->hasEnd ) | ||
472 | buf += " enddt=\"" | ||
473 | + recMap[ORecur::EndDate] | ||
474 | + "\""; | ||
475 | buf += " created=\"" + recMap[ORecur::Created] + "\""; | ||
476 | |||
477 | if ( data->list.isEmpty() ) return buf; | ||
478 | buf += " exceptions=\""; | ||
479 | buf += recMap[ORecur::Exceptions]; | ||
480 | buf += "\" "; | ||
481 | |||
482 | return buf; | ||
483 | } | ||
484 | |||
485 | QString ORecur::rTypeString() const | ||
486 | { | ||
487 | QString retString; | ||
461 | switch ( data->type ) { | 488 | switch ( data->type ) { |
462 | case ORecur::Daily: | 489 | case ORecur::Daily: |
463 | buf += "Daily"; | 490 | retString = "Daily"; |
464 | break; | 491 | break; |
465 | case ORecur::Weekly: | 492 | case ORecur::Weekly: |
466 | buf += "Weekly"; | 493 | retString = "Weekly"; |
467 | break; | 494 | break; |
468 | case ORecur::MonthlyDay: | 495 | case ORecur::MonthlyDay: |
469 | buf += "MonthlyDay"; | 496 | retString = "MonthlyDay"; |
470 | break; | 497 | break; |
471 | case ORecur::MonthlyDate: | 498 | case ORecur::MonthlyDate: |
472 | buf += "MonthlyDate"; | 499 | retString = "MonthlyDate"; |
473 | break; | 500 | break; |
474 | case ORecur::Yearly: | 501 | case ORecur::Yearly: |
475 | buf += "Yearly"; | 502 | retString = "Yearly"; |
476 | break; | 503 | break; |
477 | default: | 504 | default: |
478 | buf += "NoRepeat"; | 505 | retString = "NoRepeat"; |
479 | break; | 506 | break; |
507 | |||
480 | } | 508 | } |
481 | buf += "\""; | ||
482 | if (data->days > 0 ) | ||
483 | buf += " rweekdays=\"" + QString::number( static_cast<int>( data->days ) ) + "\""; | ||
484 | if ( data->pos != 0 ) | ||
485 | buf += " rposition=\"" + QString::number(data->pos ) + "\""; | ||
486 | 509 | ||
487 | buf += " rfreq=\"" + QString::number( data->freq ) + "\""; | 510 | return retString; |
488 | buf += " rhasenddate=\"" + QString::number( static_cast<int>( data->hasEnd ) ) + "\""; | 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 ) ) ); | ||
489 | if ( data->hasEnd ) | 537 | if ( data->hasEnd ) |
490 | buf += " enddt=\"" | 538 | retMap.insert( ORecur::EndDate, QString::number( OTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) ); |
491 | + QString::number( OTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) | 539 | retMap.insert( ORecur::Created, QString::number( OTimeZone::utc().fromUTCDateTime( data->create ) ) ); |
492 | + "\""; | 540 | |
493 | buf += " created=\"" + QString::number( OTimeZone::utc().fromUTCDateTime( data->create ) ) + "\""; | 541 | if ( data->list.isEmpty() ) return retMap; |
494 | 542 | ||
495 | if ( data->list.isEmpty() ) return buf; | ||
496 | // save exceptions list here!! | 543 | // save exceptions list here!! |
497 | ExceptionList::ConstIterator it; | 544 | ExceptionList::ConstIterator it; |
498 | ExceptionList list = data->list; | 545 | ExceptionList list = data->list; |
499 | buf += " exceptions=\""; | 546 | QString exceptBuf; |
500 | QDate date; | 547 | QDate date; |
501 | for ( it = list.begin(); it != list.end(); ++it ) { | 548 | for ( it = list.begin(); it != list.end(); ++it ) { |
502 | date = (*it); | 549 | date = (*it); |
503 | if ( it != list.begin() ) buf += " "; | 550 | if ( it != list.begin() ) exceptBuf += " "; |
504 | 551 | ||
505 | buf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); | 552 | exceptBuf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); |
506 | } | 553 | } |
507 | buf += "\" "; | ||
508 | 554 | ||
509 | return buf; | 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 | |||
510 | } | 585 | } |
diff --git a/libopie2/opiepim/core/orecur.h b/libopie2/opiepim/core/orecur.h index b214b3f..47901b0 100644 --- a/libopie2/opiepim/core/orecur.h +++ b/libopie2/opiepim/core/orecur.h | |||
@@ -9,7 +9,7 @@ | |||
9 | 9 | ||
10 | #include <qdatetime.h> | 10 | #include <qdatetime.h> |
11 | #include <qvaluelist.h> | 11 | #include <qvaluelist.h> |
12 | 12 | #include <qmap.h> | |
13 | 13 | ||
14 | class ORecur { | 14 | class ORecur { |
15 | public: | 15 | public: |
@@ -18,6 +18,9 @@ public: | |||
18 | MonthlyDate, Yearly }; | 18 | MonthlyDate, Yearly }; |
19 | enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, | 19 | enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, |
20 | FRI = 0x10, SAT = 0x20, SUN = 0x40 }; | 20 | FRI = 0x10, SAT = 0x20, SUN = 0x40 }; |
21 | enum Fields{ RType = 0, RWeekdays, RPosition, RFreq, RHasEndDate, | ||
22 | EndDate, Created, Exceptions }; | ||
23 | |||
21 | ORecur(); | 24 | ORecur(); |
22 | ORecur( const ORecur& ); | 25 | ORecur( const ORecur& ); |
23 | ~ORecur(); | 26 | ~ORecur(); |
@@ -74,6 +77,9 @@ public: | |||
74 | 77 | ||
75 | void setService( const QString& ser ); | 78 | void setService( const QString& ser ); |
76 | 79 | ||
80 | QMap<int, QString> toMap() const; | ||
81 | void fromMap( const QMap<int, QString>& map ); | ||
82 | |||
77 | /* almost internal */ | 83 | /* almost internal */ |
78 | QString toString()const; | 84 | QString toString()const; |
79 | private: | 85 | private: |
@@ -81,6 +87,10 @@ private: | |||
81 | void deref(); | 87 | void deref(); |
82 | inline void checkOrModify(); | 88 | inline void checkOrModify(); |
83 | 89 | ||
90 | /* Converts rType to String */ | ||
91 | QString rTypeString() const; | ||
92 | /* Returns a map to convert Stringname for RType to RepeatType */ | ||
93 | QMap<QString, RepeatType> rTypeValueConvertMap() const; | ||
84 | 94 | ||
85 | class Data; | 95 | class Data; |
86 | Data* data; | 96 | Data* data; |