author | zecke <zecke> | 2004-07-29 19:42:59 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-07-29 19:42:59 (UTC) |
commit | 52b1ae9281920cf5a40fe543112d8b00e7699ef6 (patch) (side-by-side diff) | |
tree | 0b0a79ff9a45a66f32fe555ee662b4acc8f6eff9 /libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | |
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
-...
Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | 105 |
1 files changed, 62 insertions, 43 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 @@ -85,13 +85,13 @@ char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) } } namespace { time_t start, end, created, rp_end; OPimRecurrence* rec; - OPimRecurrence* recur() { + static OPimRecurrence* recur() { if (!rec) rec = new OPimRecurrence; return rec; } int alarmTime; @@ -99,42 +99,44 @@ namespace { enum Attribute{ FDescription = 0, FLocation, FCategories, FUid, FType, - FAlarm, - FSound, - FRType, - FRWeekdays, - FRPosition, - FRFreq, - FRHasEndDate, - FREndDate, - FRStart, - FREnd, - FNote, - FCreated, // Should't this be called FRCreated ? + FAlarm, + FSound, + FRType, + FRWeekdays, + FRPosition, + FRFreq, + FRHasEndDate, + FREndDate, + FRStart, + FREnd, + FNote, + FCreated, // Should't this be called FRCreated ? FTimeZone, FRecParent, FRecChildren, FExceptions }; // FIXME: Use OPimEvent::toMap() here !! (eilers) - inline void save( const OPimEvent& ev, QString& buf ) { + static void save( const OPimEvent& ev, QString& buf ) { owarn << "Saving " << ev.uid() << " " << ev.description() << "" << oendl; buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; if (!ev.location().isEmpty() ) buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; - buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; + if (!ev.categories().isEmpty() ) + buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; + buf += " uid=\"" + QString::number( ev.uid() ) + "\""; if (ev.isAllDay() ) - buf += " type=\"AllDay\""; // is that all ?? (eilers) + buf += " type=\"AllDay\""; // is that all ?? (eilers) if (ev.hasNotifiers() ) { OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; if ( alarm.sound() == OPimAlarm::Loud ) @@ -149,25 +151,32 @@ namespace { /* * fscking timezones :) well, we'll first convert * the QDateTime to a QDateTime in UTC time * and then we'll create a nice time_t */ - OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() ); - buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OPimTimeZone::utc() ) ) ) + "\""; - buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OPimTimeZone::utc() ) ) ) + "\""; + OPimTimeZone zone( (ev.timeZone().isEmpty()||ev.isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() ); + buf += " start=\"" + QString::number( zone.fromDateTime( ev.startDateTime())) + "\""; + buf += " end=\"" + QString::number( zone.fromDateTime( ev.endDateTime() )) + "\""; if (!ev.note().isEmpty() ) { buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; } - buf += " timezone=\""; - if ( ev.timeZone().isEmpty() ) - buf += "None"; - else - buf += ev.timeZone(); - buf += "\""; + /* + * Don't save a timezone if AllDay Events + * as they're UTC only anyway + */ + if (!ev.isAllDay() ) { + + buf += " timezone=\""; + if ( ev.timeZone().isEmpty() ) + buf += "None"; + else + buf += ev.timeZone(); + buf += "\""; + } if (ev.parent() != 0 ) { buf += " recparent=\""+QString::number(ev.parent() )+"\""; } if (ev.children().count() != 0 ) { @@ -180,13 +189,13 @@ namespace { buf+= "\""; } // skip custom writing } - inline bool forAll( const QMap<int, OPimEvent>& list, QFile& file ) { + static bool saveEachEvent( const QMap<int, OPimEvent>& list, QFile& file ) { QMap<int, OPimEvent>::ConstIterator it; QString buf; QCString str; int total_written; for ( it = list.begin(); it != list.end(); ++it ) { buf = "<event"; @@ -235,18 +244,18 @@ bool ODateBookAccessBackend_XML::save() { if ( total_written != int(str.length() ) ) { f.close(); QFile::remove( strFileNew ); return false; } - if (!forAll( m_raw, f ) ) { + if (!saveEachEvent( m_raw, f ) ) { f.close(); QFile::remove( strFileNew ); return false; } - if (!forAll( m_rep, f ) ) { + if (!saveEachEvent( m_rep, f ) ) { f.close(); QFile::remove( strFileNew ); return false; } buf = "</events>\n</DATEBOOK>\n"; @@ -403,12 +412,16 @@ bool ODateBookAccessBackend_XML::loadFile() { dict.insert( "created", new int(FCreated) ); // Shouldn't this be FRCreated ?? dict.insert( "recparent", new int(FRecParent) ); dict.insert( "recchildren", new int(FRecChildren) ); dict.insert( "exceptions", new int(FExceptions) ); dict.insert( "timezone", new int(FTimeZone) ); + + // initialiaze db hack + m_noTimeZone = true; + char* dt = (char*)map_addr; int len = attribute.st_size; int i = 0; char* point; const char* collectionString = "<event "; int strLen = ::strlen(collectionString); @@ -476,43 +489,49 @@ bool ODateBookAccessBackend_XML::loadFile() { setField( ev, *find, str ); } } /* time to finalize */ finalizeRecord( ev ); delete rec; + m_noTimeZone = true; } ::munmap(map_addr, attribute.st_size ); m_changed = false; // changed during add return true; } // FIXME: Use OPimEvent::fromMap() which makes this obsolete.. (eilers) void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { + + /* + * quirk to import datebook files. They normally don't have a + * timeZone attribute and we treat this as to use OPimTimeZone::current() + */ + if (m_noTimeZone ) + ev.setTimeZone( OPimTimeZone::current().timeZone() ); + + + /* AllDay is alway in UTC */ if ( ev.isAllDay() ) { OPimTimeZone utc = OPimTimeZone::utc(); - ev.setStartDateTime( utc.fromUTCDateTime( start ) ); - ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); - ev.setTimeZone( "UTC"); // make sure it is really utc + ev.setStartDateTime( utc.toDateTime( start ) ); + ev.setEndDateTime ( utc.toDateTime( end ) ); }else { /* to current date time */ - // owarn << " Start is " << start << "" << oendl; - OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() ); - QDateTime date = zone.toDateTime( start ); - owarn << " Start is " << date.toString() << "" << oendl; - ev.setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); - - date = zone.toDateTime( end ); - ev.setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); + OPimTimeZone to_zone( ev.timeZone().isEmpty() ? OPimTimeZone::utc() : OPimTimeZone::current() ); + + ev.setStartDateTime(to_zone.toDateTime( start)); + ev.setEndDateTime (to_zone.toDateTime( end)); } if ( rec && rec->doesRecur() ) { OPimTimeZone utc = OPimTimeZone::utc(); OPimRecurrence recu( *rec ); // call copy c'tor; - recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); - recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); + recu.setEndDate ( utc.toDateTime( rp_end ).date() ); + recu.setCreatedDateTime( utc.toDateTime( created ) ); recu.setStart( ev.startDateTime().date() ); ev.setRecurrence( recu ); } if (alarmTime != -1 ) { QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); @@ -520,13 +539,13 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { ev.notifiers().add( al ); } if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { owarn << "already contains assign uid" << oendl; ev.setUid( 1 ); } - owarn << "addind " << ev.uid() << " " << ev.description() << "" << oendl; + if ( ev.hasRecurrence() ) m_rep.insert( ev.uid(), ev ); else m_raw.insert( ev.uid(), ev ); } @@ -545,13 +564,12 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& case FUid: e.setUid( value.toInt() ); break; case FType: if ( value == "AllDay" ) { e.setAllDay( true ); - e.setTimeZone( "UTC" ); } break; case FAlarm: alarmTime = value.toInt(); break; case FSound: @@ -619,12 +637,13 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& owarn << "adding exception " << date.toString() << "" << oendl; recur()->exceptions().append( date ); } } break; case FTimeZone: + m_noTimeZone = false; if ( value != "None" ) e.setTimeZone( value ); break; default: break; } |