summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp105
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
@@ -88,7 +88,7 @@ char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
88namespace { 88namespace {
89 time_t start, end, created, rp_end; 89 time_t start, end, created, rp_end;
90 OPimRecurrence* rec; 90 OPimRecurrence* rec;
91 OPimRecurrence* recur() { 91 static OPimRecurrence* recur() {
92 if (!rec) 92 if (!rec)
93 rec = new OPimRecurrence; 93 rec = new OPimRecurrence;
94 94
@@ -102,18 +102,18 @@ namespace {
102 FCategories, 102 FCategories,
103 FUid, 103 FUid,
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,
118 FRecParent, 118 FRecParent,
119 FRecChildren, 119 FRecChildren,
@@ -121,17 +121,19 @@ namespace {
121 }; 121 };
122 122
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;
126 buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; 126 buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\"";
127 if (!ev.location().isEmpty() ) 127 if (!ev.location().isEmpty() )
128 buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; 128 buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\"";
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() ) + "\"";
132 134
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
136 if (ev.hasNotifiers() ) { 138 if (ev.hasNotifiers() ) {
137 OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first 139 OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first
@@ -152,19 +154,26 @@ namespace {
152 * the QDateTime to a QDateTime in UTC time 154 * the QDateTime to a QDateTime in UTC time
153 * and then we'll create a nice time_t 155 * and then we'll create a nice time_t
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() ) {
159 buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; 161 buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\"";
160 } 162 }
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
169 if (ev.parent() != 0 ) { 178 if (ev.parent() != 0 ) {
170 buf += " recparent=\""+QString::number(ev.parent() )+"\""; 179 buf += " recparent=\""+QString::number(ev.parent() )+"\"";
@@ -183,7 +192,7 @@ namespace {
183 // skip custom writing 192 // skip custom writing
184 } 193 }
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;
188 QString buf; 197 QString buf;
189 QCString str; 198 QCString str;
@@ -238,12 +247,12 @@ bool ODateBookAccessBackend_XML::save() {
238 return false; 247 return false;
239 } 248 }
240 249
241 if (!forAll( m_raw, f ) ) { 250 if (!saveEachEvent( m_raw, f ) ) {
242 f.close(); 251 f.close();
243 QFile::remove( strFileNew ); 252 QFile::remove( strFileNew );
244 return false; 253 return false;
245 } 254 }
246 if (!forAll( m_rep, f ) ) { 255 if (!saveEachEvent( m_rep, f ) ) {
247 f.close(); 256 f.close();
248 QFile::remove( strFileNew ); 257 QFile::remove( strFileNew );
249 return false; 258 return false;
@@ -406,6 +415,10 @@ bool ODateBookAccessBackend_XML::loadFile() {
406 dict.insert( "exceptions", new int(FExceptions) ); 415 dict.insert( "exceptions", new int(FExceptions) );
407 dict.insert( "timezone", new int(FTimeZone) ); 416 dict.insert( "timezone", new int(FTimeZone) );
408 417
418
419 // initialiaze db hack
420 m_noTimeZone = true;
421
409 char* dt = (char*)map_addr; 422 char* dt = (char*)map_addr;
410 int len = attribute.st_size; 423 int len = attribute.st_size;
411 int i = 0; 424 int i = 0;
@@ -479,6 +492,7 @@ bool ODateBookAccessBackend_XML::loadFile() {
479 /* time to finalize */ 492 /* time to finalize */
480 finalizeRecord( ev ); 493 finalizeRecord( ev );
481 delete rec; 494 delete rec;
495 m_noTimeZone = true;
482 } 496 }
483 ::munmap(map_addr, attribute.st_size ); 497 ::munmap(map_addr, attribute.st_size );
484 m_changed = false; // changed during add 498 m_changed = false; // changed during add
@@ -488,28 +502,33 @@ bool ODateBookAccessBackend_XML::loadFile() {
488 502
489// FIXME: Use OPimEvent::fromMap() which makes this obsolete.. (eilers) 503// FIXME: Use OPimEvent::fromMap() which makes this obsolete.. (eilers)
490void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { 504void 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 */
492 if ( ev.isAllDay() ) { 516 if ( ev.isAllDay() ) {
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 }
508 if ( rec && rec->doesRecur() ) { 527 if ( rec && rec->doesRecur() ) {
509 OPimTimeZone utc = OPimTimeZone::utc(); 528 OPimTimeZone utc = OPimTimeZone::utc();
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() );
514 ev.setRecurrence( recu ); 533 ev.setRecurrence( recu );
515 } 534 }
@@ -523,7 +542,7 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) {
523 owarn << "already contains assign uid" << oendl; 542 owarn << "already contains assign uid" << oendl;
524 ev.setUid( 1 ); 543 ev.setUid( 1 );
525 } 544 }
526 owarn << "addind " << ev.uid() << " " << ev.description() << "" << oendl; 545
527 if ( ev.hasRecurrence() ) 546 if ( ev.hasRecurrence() )
528 m_rep.insert( ev.uid(), ev ); 547 m_rep.insert( ev.uid(), ev );
529 else 548 else
@@ -548,7 +567,6 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString&
548 case FType: 567 case FType:
549 if ( value == "AllDay" ) { 568 if ( value == "AllDay" ) {
550 e.setAllDay( true ); 569 e.setAllDay( true );
551 e.setTimeZone( "UTC" );
552 } 570 }
553 break; 571 break;
554 case FAlarm: 572 case FAlarm:
@@ -622,6 +640,7 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString&
622 } 640 }
623 break; 641 break;
624 case FTimeZone: 642 case FTimeZone:
643 m_noTimeZone = false;
625 if ( value != "None" ) 644 if ( value != "None" )
626 e.setTimeZone( value ); 645 e.setTimeZone( value );
627 break; 646 break;