author | zecke <zecke> | 2004-07-29 19:42:59 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-07-29 19:42:59 (UTC) |
commit | 52b1ae9281920cf5a40fe543112d8b00e7699ef6 (patch) (unidiff) | |
tree | 0b0a79ff9a45a66f32fe555ee662b4acc8f6eff9 | |
parent | c170d1f931ae03c2ec917b7abf4bd5d0e94a3760 (diff) | |
download | opie-52b1ae9281920cf5a40fe543112d8b00e7699ef6.zip opie-52b1ae9281920cf5a40fe543112d8b00e7699ef6.tar.gz opie-52b1ae9281920cf5a40fe543112d8b00e7699ef6.tar.bz2 |
-UTC -> Europe/London when referring to no timezone
-special handling for allDay Event in OPImEvent, avoid setting timezone
as it is by default UTC
-No timezone set by default for an Event
-Recurrence is UTC (no timezone)
-Provide upgrade path from DateBook as by default events were in the current timezone but didn't have the timezone attribute
-unified handling of timezones, compatible with QtopiaDesktop
-do less conversions
-...
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | 105 | ||||
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_xml.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimevent.cpp | 38 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecurrence.cpp | 22 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimtimezone.cpp | 12 |
5 files changed, 99 insertions, 80 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp index 107c178..0f99d50 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | |||
@@ -90,3 +90,3 @@ namespace { | |||
90 | OPimRecurrence* rec; | 90 | OPimRecurrence* rec; |
91 | OPimRecurrence* recur() { | 91 | static OPimRecurrence* recur() { |
92 | if (!rec) | 92 | if (!rec) |
@@ -104,14 +104,14 @@ namespace { | |||
104 | FType, | 104 | FType, |
105 | FAlarm, | 105 | FAlarm, |
106 | FSound, | 106 | FSound, |
107 | FRType, | 107 | FRType, |
108 | FRWeekdays, | 108 | FRWeekdays, |
109 | FRPosition, | 109 | FRPosition, |
110 | FRFreq, | 110 | FRFreq, |
111 | FRHasEndDate, | 111 | FRHasEndDate, |
112 | FREndDate, | 112 | FREndDate, |
113 | FRStart, | 113 | FRStart, |
114 | FREnd, | 114 | FREnd, |
115 | FNote, | 115 | FNote, |
116 | FCreated, // Should't this be called FRCreated ? | 116 | FCreated, // Should't this be called FRCreated ? |
117 | FTimeZone, | 117 | FTimeZone, |
@@ -123,3 +123,3 @@ namespace { | |||
123 | // FIXME: Use OPimEvent::toMap() here !! (eilers) | 123 | // FIXME: Use OPimEvent::toMap() here !! (eilers) |
124 | inline void save( const OPimEvent& ev, QString& buf ) { | 124 | static void save( const OPimEvent& ev, QString& buf ) { |
125 | owarn << "Saving " << ev.uid() << " " << ev.description() << "" << oendl; | 125 | owarn << "Saving " << ev.uid() << " " << ev.description() << "" << oendl; |
@@ -129,3 +129,5 @@ namespace { | |||
129 | 129 | ||
130 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; | 130 | if (!ev.categories().isEmpty() ) |
131 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; | ||
132 | |||
131 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; | 133 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; |
@@ -133,3 +135,3 @@ namespace { | |||
133 | if (ev.isAllDay() ) | 135 | if (ev.isAllDay() ) |
134 | buf += " type=\"AllDay\""; // is that all ?? (eilers) | 136 | buf += " type=\"AllDay\""; // is that all ?? (eilers) |
135 | 137 | ||
@@ -154,5 +156,5 @@ namespace { | |||
154 | */ | 156 | */ |
155 | OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() ); | 157 | OPimTimeZone zone( (ev.timeZone().isEmpty()||ev.isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() ); |
156 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OPimTimeZone::utc() ) ) ) + "\""; | 158 | buf += " start=\"" + QString::number( zone.fromDateTime( ev.startDateTime())) + "\""; |
157 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OPimTimeZone::utc() ) ) ) + "\""; | 159 | buf += " end=\"" + QString::number( zone.fromDateTime( ev.endDateTime() )) + "\""; |
158 | if (!ev.note().isEmpty() ) { | 160 | if (!ev.note().isEmpty() ) { |
@@ -161,8 +163,15 @@ namespace { | |||
161 | 163 | ||
162 | buf += " timezone=\""; | 164 | /* |
163 | if ( ev.timeZone().isEmpty() ) | 165 | * Don't save a timezone if AllDay Events |
164 | buf += "None"; | 166 | * as they're UTC only anyway |
165 | else | 167 | */ |
166 | buf += ev.timeZone(); | 168 | if (!ev.isAllDay() ) { |
167 | buf += "\""; | 169 | |
170 | buf += " timezone=\""; | ||
171 | if ( ev.timeZone().isEmpty() ) | ||
172 | buf += "None"; | ||
173 | else | ||
174 | buf += ev.timeZone(); | ||
175 | buf += "\""; | ||
176 | } | ||
168 | 177 | ||
@@ -185,3 +194,3 @@ namespace { | |||
185 | 194 | ||
186 | inline bool forAll( const QMap<int, OPimEvent>& list, QFile& file ) { | 195 | static bool saveEachEvent( const QMap<int, OPimEvent>& list, QFile& file ) { |
187 | QMap<int, OPimEvent>::ConstIterator it; | 196 | QMap<int, OPimEvent>::ConstIterator it; |
@@ -240,3 +249,3 @@ bool ODateBookAccessBackend_XML::save() { | |||
240 | 249 | ||
241 | if (!forAll( m_raw, f ) ) { | 250 | if (!saveEachEvent( m_raw, f ) ) { |
242 | f.close(); | 251 | f.close(); |
@@ -245,3 +254,3 @@ bool ODateBookAccessBackend_XML::save() { | |||
245 | } | 254 | } |
246 | if (!forAll( m_rep, f ) ) { | 255 | if (!saveEachEvent( m_rep, f ) ) { |
247 | f.close(); | 256 | f.close(); |
@@ -408,2 +417,6 @@ bool ODateBookAccessBackend_XML::loadFile() { | |||
408 | 417 | ||
418 | |||
419 | // initialiaze db hack | ||
420 | m_noTimeZone = true; | ||
421 | |||
409 | char* dt = (char*)map_addr; | 422 | char* dt = (char*)map_addr; |
@@ -481,2 +494,3 @@ bool ODateBookAccessBackend_XML::loadFile() { | |||
481 | delete rec; | 494 | delete rec; |
495 | m_noTimeZone = true; | ||
482 | } | 496 | } |
@@ -490,2 +504,12 @@ bool ODateBookAccessBackend_XML::loadFile() { | |||
490 | void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { | 504 | void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { |
505 | |||
506 | /* | ||
507 | * quirk to import datebook files. They normally don't have a | ||
508 | * timeZone attribute and we treat this as to use OPimTimeZone::current() | ||
509 | */ | ||
510 | if (m_noTimeZone ) | ||
511 | ev.setTimeZone( OPimTimeZone::current().timeZone() ); | ||
512 | |||
513 | |||
514 | |||
491 | /* AllDay is alway in UTC */ | 515 | /* AllDay is alway in UTC */ |
@@ -493,15 +517,10 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { | |||
493 | OPimTimeZone utc = OPimTimeZone::utc(); | 517 | OPimTimeZone utc = OPimTimeZone::utc(); |
494 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); | 518 | ev.setStartDateTime( utc.toDateTime( start ) ); |
495 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); | 519 | ev.setEndDateTime ( utc.toDateTime( end ) ); |
496 | ev.setTimeZone( "UTC"); // make sure it is really utc | ||
497 | }else { | 520 | }else { |
498 | /* to current date time */ | 521 | /* to current date time */ |
499 | // owarn << " Start is " << start << "" << oendl; | 522 | OPimTimeZone to_zone( ev.timeZone().isEmpty() ? OPimTimeZone::utc() : OPimTimeZone::current() ); |
500 | OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() ); | 523 | |
501 | QDateTime date = zone.toDateTime( start ); | 524 | ev.setStartDateTime(to_zone.toDateTime( start)); |
502 | owarn << " Start is " << date.toString() << "" << oendl; | 525 | ev.setEndDateTime (to_zone.toDateTime( end)); |
503 | ev.setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); | ||
504 | |||
505 | date = zone.toDateTime( end ); | ||
506 | ev.setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); | ||
507 | } | 526 | } |
@@ -510,4 +529,4 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { | |||
510 | OPimRecurrence recu( *rec ); // call copy c'tor; | 529 | OPimRecurrence recu( *rec ); // call copy c'tor; |
511 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); | 530 | recu.setEndDate ( utc.toDateTime( rp_end ).date() ); |
512 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); | 531 | recu.setCreatedDateTime( utc.toDateTime( created ) ); |
513 | recu.setStart( ev.startDateTime().date() ); | 532 | recu.setStart( ev.startDateTime().date() ); |
@@ -525,3 +544,3 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { | |||
525 | } | 544 | } |
526 | owarn << "addind " << ev.uid() << " " << ev.description() << "" << oendl; | 545 | |
527 | if ( ev.hasRecurrence() ) | 546 | if ( ev.hasRecurrence() ) |
@@ -550,3 +569,2 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& | |||
550 | e.setAllDay( true ); | 569 | e.setAllDay( true ); |
551 | e.setTimeZone( "UTC" ); | ||
552 | } | 570 | } |
@@ -624,2 +642,3 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& | |||
624 | case FTimeZone: | 642 | case FTimeZone: |
643 | m_noTimeZone = false; | ||
625 | if ( value != "None" ) | 644 | if ( value != "None" ) |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h index 6823ce6..af5b114 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h +++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h | |||
@@ -70,2 +70,4 @@ private: | |||
70 | bool m_changed :1 ; | 70 | bool m_changed :1 ; |
71 | bool m_noTimeZone : 1; | ||
72 | |||
71 | bool loadFile(); | 73 | bool loadFile(); |
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp index 8752fce..739cb6f 100644 --- a/libopie2/opiepim/core/opimevent.cpp +++ b/libopie2/opiepim/core/opimevent.cpp | |||
@@ -298,4 +298,6 @@ QDateTime OPimEvent::endDateTime() const | |||
298 | */ | 298 | */ |
299 | if ( data->isAllDay ) | 299 | if ( data->isAllDay ) { |
300 | return QDateTime( data->start.date(), QTime( 23, 59, 59 ) ); | 300 | QDate end = data->end.isValid() ? data->end.date() : data->start.date() ; |
301 | return QDateTime( end, QTime( 23, 59, 59 ) ); | ||
302 | } | ||
301 | return data->end; | 303 | return data->end; |
@@ -337,3 +339,2 @@ void OPimEvent::setAllDay( bool allDay ) | |||
337 | data->isAllDay = allDay; | 339 | data->isAllDay = allDay; |
338 | if ( allDay ) data->timezone = "UTC"; | ||
339 | } | 340 | } |
@@ -350,3 +351,3 @@ QString OPimEvent::timeZone() const | |||
350 | { | 351 | { |
351 | if ( data->isAllDay ) return QString::fromLatin1( "UTC" ); | 352 | if ( data->isAllDay ) return QString::fromLatin1( "Europe/London" ); |
352 | return data->timezone; | 353 | return data->timezone; |
@@ -566,5 +567,6 @@ QMap<int, QString> OPimEvent::toMap() const | |||
566 | 567 | ||
567 | OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); | 568 | /* either use UTC timeZone or current() if there is was a timezone set */ |
568 | retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) ); | 569 | OPimTimeZone zone( (timeZone().isEmpty()||isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() ); |
569 | retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) ); | 570 | retMap.insert( OPimEvent::FStart, QString::number( zone.fromDateTime( startDateTime()))); |
571 | retMap.insert( OPimEvent::FEnd, QString::number( zone.fromDateTime( endDateTime() ))); | ||
570 | retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) ); | 572 | retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) ); |
@@ -632,3 +634,3 @@ void OPimEvent::fromMap( const QMap<int, QString>& map ) | |||
632 | time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong(); | 634 | time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong(); |
633 | time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong(); | 635 | time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong(); |
634 | 636 | ||
@@ -638,17 +640,11 @@ void OPimEvent::fromMap( const QMap<int, QString>& map ) | |||
638 | OPimTimeZone utc = OPimTimeZone::utc(); | 640 | OPimTimeZone utc = OPimTimeZone::utc(); |
639 | setStartDateTime( utc.fromUTCDateTime( start ) ); | 641 | setStartDateTime(utc.toDateTime( start ) ); |
640 | setEndDateTime ( utc.fromUTCDateTime( end ) ); | 642 | setEndDateTime ( utc.toDateTime( end ) ); |
641 | setTimeZone( "UTC" ); // make sure it is really utc | ||
642 | } | 643 | } |
643 | else | 644 | else { |
644 | { | ||
645 | /* to current date time */ | 645 | /* to current date time */ |
646 | // owarn << " Start is " << start << "" << oendl; | 646 | OPimTimeZone to_zone( ev.timeZone().isEmpty() ? OPimTimeZone::utc() : OPimTimeZone::current() ); |
647 | OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); | 647 | |
648 | QDateTime date = zone.toDateTime( start ); | 648 | ev.setStartDateTime(to_zone.toDateTime( start)); |
649 | owarn << " Start is " << date.toString() << "" << oendl; | 649 | ev.setEndDateTime (to_zone.toDateTime( end)); |
650 | setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); | ||
651 | |||
652 | date = zone.toDateTime( end ); | ||
653 | setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); | ||
654 | } | 650 | } |
diff --git a/libopie2/opiepim/core/opimrecurrence.cpp b/libopie2/opiepim/core/opimrecurrence.cpp index 4b1d886..c3ae350 100644 --- a/libopie2/opiepim/core/opimrecurrence.cpp +++ b/libopie2/opiepim/core/opimrecurrence.cpp | |||
@@ -634,3 +634,3 @@ QMap<int, QString> OPimRecurrence::toMap() const | |||
634 | QMap<int, QString> retMap; | 634 | QMap<int, QString> retMap; |
635 | 635 | ||
636 | retMap.insert( OPimRecurrence::RType, rTypeString() ); | 636 | retMap.insert( OPimRecurrence::RType, rTypeString() ); |
@@ -641,5 +641,5 @@ QMap<int, QString> OPimRecurrence::toMap() const | |||
641 | if( data -> hasEnd ) | 641 | if( data -> hasEnd ) |
642 | retMap.insert( OPimRecurrence::EndDate, QString::number( OPimTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) ); | 642 | retMap.insert( OPimRecurrence::EndDate, QString::number( OPimTimeZone::current().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) ); |
643 | retMap.insert( OPimRecurrence::Created, QString::number( OPimTimeZone::utc().fromUTCDateTime( data->create ) ) ); | 643 | retMap.insert( OPimRecurrence::Created, QString::number( OPimTimeZone::current().fromUTCDateTime( data->create ) ) ); |
644 | 644 | ||
645 | if ( data->list.isEmpty() ) return retMap; | 645 | if ( data->list.isEmpty() ) return retMap; |
@@ -654,3 +654,3 @@ QMap<int, QString> OPimRecurrence::toMap() const | |||
654 | if ( it != list.begin() ) exceptBuf += " "; | 654 | if ( it != list.begin() ) exceptBuf += " "; |
655 | 655 | ||
656 | exceptBuf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); | 656 | exceptBuf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); |
@@ -665,3 +665,3 @@ void OPimRecurrence::fromMap( const QMap<int, QString>& map ) | |||
665 | { | 665 | { |
666 | QMap<QString, RepeatType> repTypeMap = rTypeValueConvertMap(); | 666 | QMap<QString, RepeatType> repTypeMap = rTypeValueConvertMap(); |
667 | 667 | ||
@@ -672,7 +672,7 @@ void OPimRecurrence::fromMap( const QMap<int, QString>& map ) | |||
672 | data -> hasEnd= map[ OPimRecurrence::RHasEndDate ].toInt() ? true : false; | 672 | data -> hasEnd= map[ OPimRecurrence::RHasEndDate ].toInt() ? true : false; |
673 | OPimTimeZone utc = OPimTimeZone::utc(); | 673 | OPimTimeZone cur = OPimTimeZone::current(); |
674 | if ( data -> hasEnd ){ | 674 | if ( data -> hasEnd ){ |
675 | data -> end = utc.fromUTCDateTime( (time_t) map[ OPimRecurrence::EndDate ].toLong() ).date(); | 675 | data -> end = cur.fromUTCDateTime( (time_t) map[ OPimRecurrence::EndDate ].toLong() ).date(); |
676 | } | 676 | } |
677 | data -> create = utc.fromUTCDateTime( (time_t) map[ OPimRecurrence::Created ].toLong() ).date(); | 677 | data -> create = cur.fromUTCDateTime( (time_t) map[ OPimRecurrence::Created ].toLong() ).date(); |
678 | 678 | ||
@@ -686,4 +686,4 @@ void OPimRecurrence::fromMap( const QMap<int, QString>& map ) | |||
686 | #endif | 686 | #endif |
687 | 687 | ||
688 | 688 | ||
689 | } | 689 | } |
diff --git a/libopie2/opiepim/core/opimtimezone.cpp b/libopie2/opiepim/core/opimtimezone.cpp index fefceb5..5b32b1f 100644 --- a/libopie2/opiepim/core/opimtimezone.cpp +++ b/libopie2/opiepim/core/opimtimezone.cpp | |||
@@ -50,2 +50,3 @@ QDateTime utcTime( time_t t ) | |||
50 | } | 50 | } |
51 | |||
51 | QDateTime utcTime( time_t t, const QString& zone ) | 52 | QDateTime utcTime( time_t t, const QString& zone ) |
@@ -72,2 +73,4 @@ QDateTime utcTime( time_t t, const QString& zone ) | |||
72 | } | 73 | } |
74 | |||
75 | |||
73 | time_t to_Time_t( const QDateTime& utc, const QString& str ) | 76 | time_t to_Time_t( const QDateTime& utc, const QString& str ) |
@@ -153,5 +156,4 @@ QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zon | |||
153 | { | 156 | { |
154 | time_t utc = to_Time_t( dt, zone.m_name ); | 157 | time_t utc = to_Time_t( dt, m_name ); |
155 | owarn << "" << utc << " " << zone.m_name << "" << oendl; | 158 | return utcTime( utc, zone.m_name ); |
156 | return utcTime( utc, m_name ); | ||
157 | } | 159 | } |
@@ -167,3 +169,3 @@ time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time ) | |||
167 | { | 169 | { |
168 | return to_Time_t( time, "UTC" ); | 170 | return to_Time_t( time, "Europe/London" ); |
169 | } | 171 | } |
@@ -181,3 +183,3 @@ OPimTimeZone OPimTimeZone::utc() | |||
181 | { | 183 | { |
182 | return OPimTimeZone( "UTC" ); | 184 | return OPimTimeZone( "Europe/London" ); |
183 | } | 185 | } |