summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp63
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.h2
2 files changed, 43 insertions, 22 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
@@ -67,144 +67,153 @@ char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
67 if (!needle || !haystack || !hLen || !nLen) 67 if (!needle || !haystack || !hLen || !nLen)
68 return 0; 68 return 0;
69 69
70 const char* hsearch = haystack; 70 const char* hsearch = haystack;
71 71
72 if ((needleChar = *needle++) != 0) { 72 if ((needleChar = *needle++) != 0) {
73 nLen--; //(to make up for needle++) 73 nLen--; //(to make up for needle++)
74 do { 74 do {
75 do { 75 do {
76 if ((haystackChar = *hsearch++) == 0) 76 if ((haystackChar = *hsearch++) == 0)
77 return (0); 77 return (0);
78 if (hsearch >= haystack + hLen) 78 if (hsearch >= haystack + hLen)
79 return (0); 79 return (0);
80 } while (haystackChar != needleChar); 80 } while (haystackChar != needleChar);
81 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); 81 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
82 hsearch--; 82 hsearch--;
83 } 83 }
84 return ((char *)hsearch); 84 return ((char *)hsearch);
85} 85}
86} 86}
87 87
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
95 return rec; 95 return rec;
96 } 96 }
97 int alarmTime; 97 int alarmTime;
98 int snd; 98 int snd;
99 enum Attribute{ 99 enum Attribute{
100 FDescription = 0, 100 FDescription = 0,
101 FLocation, 101 FLocation,
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,
120 FExceptions 120 FExceptions
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 if (!ev.categories().isEmpty() )
130 buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; 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
138 int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; 140 int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60;
139 buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; 141 buf += " alarm=\"" + QString::number(minutes) + "\" sound=\"";
140 if ( alarm.sound() == OPimAlarm::Loud ) 142 if ( alarm.sound() == OPimAlarm::Loud )
141 buf += "loud"; 143 buf += "loud";
142 else 144 else
143 buf += "silent"; 145 buf += "silent";
144 buf += "\""; 146 buf += "\"";
145 } 147 }
146 if ( ev.hasRecurrence() ) { 148 if ( ev.hasRecurrence() ) {
147 buf += ev.recurrence().toString(); 149 buf += ev.recurrence().toString();
148 } 150 }
149 151
150 /* 152 /*
151 * fscking timezones :) well, we'll first convert 153 * fscking timezones :) well, we'll first convert
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
164 /*
165 * Don't save a timezone if AllDay Events
166 * as they're UTC only anyway
167 */
168 if (!ev.isAllDay() ) {
169
162 buf += " timezone=\""; 170 buf += " timezone=\"";
163 if ( ev.timeZone().isEmpty() ) 171 if ( ev.timeZone().isEmpty() )
164 buf += "None"; 172 buf += "None";
165 else 173 else
166 buf += ev.timeZone(); 174 buf += ev.timeZone();
167 buf += "\""; 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() )+"\"";
171 } 180 }
172 181
173 if (ev.children().count() != 0 ) { 182 if (ev.children().count() != 0 ) {
174 QArray<int> children = ev.children(); 183 QArray<int> children = ev.children();
175 buf += " recchildren=\""; 184 buf += " recchildren=\"";
176 for ( uint i = 0; i < children.count(); i++ ) { 185 for ( uint i = 0; i < children.count(); i++ ) {
177 if ( i != 0 ) buf += " "; 186 if ( i != 0 ) buf += " ";
178 buf += QString::number( children[i] ); 187 buf += QString::number( children[i] );
179 } 188 }
180 buf+= "\""; 189 buf+= "\"";
181 } 190 }
182 191
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;
190 int total_written; 199 int total_written;
191 for ( it = list.begin(); it != list.end(); ++it ) { 200 for ( it = list.begin(); it != list.end(); ++it ) {
192 buf = "<event"; 201 buf = "<event";
193 save( it.data(), buf ); 202 save( it.data(), buf );
194 buf += " />\n"; 203 buf += " />\n";
195 str = buf.utf8(); 204 str = buf.utf8();
196 205
197 total_written = file.writeBlock(str.data(), str.length() ); 206 total_written = file.writeBlock(str.data(), str.length() );
198 if ( total_written != int(str.length() ) ) 207 if ( total_written != int(str.length() ) )
199 return false; 208 return false;
200 } 209 }
201 return true; 210 return true;
202 } 211 }
203} 212}
204 213
205namespace Opie { 214namespace Opie {
206ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , 215ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& ,
207 const QString& fileName ) 216 const QString& fileName )
208 : ODateBookAccessBackend() { 217 : ODateBookAccessBackend() {
209 m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; 218 m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName;
210 m_changed = false; 219 m_changed = false;
@@ -217,54 +226,54 @@ bool ODateBookAccessBackend_XML::load() {
217bool ODateBookAccessBackend_XML::reload() { 226bool ODateBookAccessBackend_XML::reload() {
218 clear(); 227 clear();
219 return load(); 228 return load();
220} 229}
221bool ODateBookAccessBackend_XML::save() { 230bool ODateBookAccessBackend_XML::save() {
222 if (!m_changed) return true; 231 if (!m_changed) return true;
223 232
224 int total_written; 233 int total_written;
225 QString strFileNew = m_name + ".new"; 234 QString strFileNew = m_name + ".new";
226 235
227 QFile f( strFileNew ); 236 QFile f( strFileNew );
228 if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; 237 if (!f.open( IO_WriteOnly | IO_Raw ) ) return false;
229 238
230 QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); 239 QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
231 buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; 240 buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n";
232 buf += "<events>\n"; 241 buf += "<events>\n";
233 QCString str = buf.utf8(); 242 QCString str = buf.utf8();
234 total_written = f.writeBlock( str.data(), str.length() ); 243 total_written = f.writeBlock( str.data(), str.length() );
235 if ( total_written != int(str.length() ) ) { 244 if ( total_written != int(str.length() ) ) {
236 f.close(); 245 f.close();
237 QFile::remove( strFileNew ); 246 QFile::remove( strFileNew );
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;
250 } 259 }
251 260
252 buf = "</events>\n</DATEBOOK>\n"; 261 buf = "</events>\n</DATEBOOK>\n";
253 str = buf.utf8(); 262 str = buf.utf8();
254 total_written = f.writeBlock( str.data(), str.length() ); 263 total_written = f.writeBlock( str.data(), str.length() );
255 if ( total_written != int(str.length() ) ) { 264 if ( total_written != int(str.length() ) ) {
256 f.close(); 265 f.close();
257 QFile::remove( strFileNew ); 266 QFile::remove( strFileNew );
258 return false; 267 return false;
259 } 268 }
260 f.close(); 269 f.close();
261 270
262 if ( ::rename( strFileNew, m_name ) < 0 ) { 271 if ( ::rename( strFileNew, m_name ) < 0 ) {
263 QFile::remove( strFileNew ); 272 QFile::remove( strFileNew );
264 return false; 273 return false;
265 } 274 }
266 275
267 m_changed = false; 276 m_changed = false;
268 return true; 277 return true;
269} 278}
270QArray<int> ODateBookAccessBackend_XML::allRecords()const { 279QArray<int> ODateBookAccessBackend_XML::allRecords()const {
@@ -385,48 +394,52 @@ bool ODateBookAccessBackend_XML::loadFile() {
385 QAsciiDict<int> dict(FExceptions+1); 394 QAsciiDict<int> dict(FExceptions+1);
386 dict.setAutoDelete( true ); 395 dict.setAutoDelete( true );
387 dict.insert( "description", new int(FDescription) ); 396 dict.insert( "description", new int(FDescription) );
388 dict.insert( "location", new int(FLocation) ); 397 dict.insert( "location", new int(FLocation) );
389 dict.insert( "categories", new int(FCategories) ); 398 dict.insert( "categories", new int(FCategories) );
390 dict.insert( "uid", new int(FUid) ); 399 dict.insert( "uid", new int(FUid) );
391 dict.insert( "type", new int(FType) ); 400 dict.insert( "type", new int(FType) );
392 dict.insert( "alarm", new int(FAlarm) ); 401 dict.insert( "alarm", new int(FAlarm) );
393 dict.insert( "sound", new int(FSound) ); 402 dict.insert( "sound", new int(FSound) );
394 dict.insert( "rtype", new int(FRType) ); 403 dict.insert( "rtype", new int(FRType) );
395 dict.insert( "rweekdays", new int(FRWeekdays) ); 404 dict.insert( "rweekdays", new int(FRWeekdays) );
396 dict.insert( "rposition", new int(FRPosition) ); 405 dict.insert( "rposition", new int(FRPosition) );
397 dict.insert( "rfreq", new int(FRFreq) ); 406 dict.insert( "rfreq", new int(FRFreq) );
398 dict.insert( "rhasenddate", new int(FRHasEndDate) ); 407 dict.insert( "rhasenddate", new int(FRHasEndDate) );
399 dict.insert( "enddt", new int(FREndDate) ); 408 dict.insert( "enddt", new int(FREndDate) );
400 dict.insert( "start", new int(FRStart) ); 409 dict.insert( "start", new int(FRStart) );
401 dict.insert( "end", new int(FREnd) ); 410 dict.insert( "end", new int(FREnd) );
402 dict.insert( "note", new int(FNote) ); 411 dict.insert( "note", new int(FNote) );
403 dict.insert( "created", new int(FCreated) ); // Shouldn't this be FRCreated ?? 412 dict.insert( "created", new int(FCreated) ); // Shouldn't this be FRCreated ??
404 dict.insert( "recparent", new int(FRecParent) ); 413 dict.insert( "recparent", new int(FRecParent) );
405 dict.insert( "recchildren", new int(FRecChildren) ); 414 dict.insert( "recchildren", new int(FRecChildren) );
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;
412 char* point; 425 char* point;
413 const char* collectionString = "<event "; 426 const char* collectionString = "<event ";
414 int strLen = ::strlen(collectionString); 427 int strLen = ::strlen(collectionString);
415 int *find; 428 int *find;
416 while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { 429 while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) {
417 i = point -dt; 430 i = point -dt;
418 i+= strLen; 431 i+= strLen;
419 432
420 alarmTime = -1; 433 alarmTime = -1;
421 snd = 0; // silent 434 snd = 0; // silent
422 435
423 OPimEvent ev; 436 OPimEvent ev;
424 rec = 0; 437 rec = 0;
425 438
426 while ( TRUE ) { 439 while ( TRUE ) {
427 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 440 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
428 ++i; 441 ++i;
429 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 442 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
430 break; 443 break;
431 444
432 445
@@ -458,118 +471,123 @@ bool ODateBookAccessBackend_XML::loadFile() {
458 continue; 471 continue;
459 } 472 }
460 473
461 QCString value( dt+i, j-i+1 ); 474 QCString value( dt+i, j-i+1 );
462 i = j + 1; 475 i = j + 1;
463 476
464 QString str = (haveUtf ? QString::fromUtf8( value ) 477 QString str = (haveUtf ? QString::fromUtf8( value )
465 : QString::fromLatin1( value ) ); 478 : QString::fromLatin1( value ) );
466 if ( haveEnt ) 479 if ( haveEnt )
467 str = Qtopia::plainString( str ); 480 str = Qtopia::plainString( str );
468 481
469 /* 482 /*
470 * add key + value 483 * add key + value
471 */ 484 */
472 find = dict[attr.data()]; 485 find = dict[attr.data()];
473 if (!find) 486 if (!find)
474 ev.setCustomField( attr, str ); 487 ev.setCustomField( attr, str );
475 else { 488 else {
476 setField( ev, *find, str ); 489 setField( ev, *find, str );
477 } 490 }
478 } 491 }
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
485 499
486 return true; 500 return true;
487} 501}
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() );
501 QDateTime date = zone.toDateTime( start );
502 owarn << " Start is " << date.toString() << "" << oendl;
503 ev.setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) );
504 523
505 date = zone.toDateTime( end ); 524 ev.setStartDateTime(to_zone.toDateTime( start));
506 ev.setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); 525 ev.setEndDateTime (to_zone.toDateTime( end));
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 }
516 535
517 if (alarmTime != -1 ) { 536 if (alarmTime != -1 ) {
518 QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); 537 QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 );
519 OPimAlarm al( snd , dt ); 538 OPimAlarm al( snd , dt );
520 ev.notifiers().add( al ); 539 ev.notifiers().add( al );
521 } 540 }
522 if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { 541 if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) {
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
530 m_raw.insert( ev.uid(), ev ); 549 m_raw.insert( ev.uid(), ev );
531 550
532} 551}
533void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) { 552void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) {
534// owarn << " setting " << value << "" << oendl; 553// owarn << " setting " << value << "" << oendl;
535 switch( id ) { 554 switch( id ) {
536 case FDescription: 555 case FDescription:
537 e.setDescription( value ); 556 e.setDescription( value );
538 break; 557 break;
539 case FLocation: 558 case FLocation:
540 e.setLocation( value ); 559 e.setLocation( value );
541 break; 560 break;
542 case FCategories: 561 case FCategories:
543 e.setCategories( e.idsFromString( value ) ); 562 e.setCategories( e.idsFromString( value ) );
544 break; 563 break;
545 case FUid: 564 case FUid:
546 e.setUid( value.toInt() ); 565 e.setUid( value.toInt() );
547 break; 566 break;
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:
555 alarmTime = value.toInt(); 573 alarmTime = value.toInt();
556 break; 574 break;
557 case FSound: 575 case FSound:
558 snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; 576 snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent;
559 break; 577 break;
560 // recurrence stuff 578 // recurrence stuff
561 case FRType: 579 case FRType:
562 if ( value == "Daily" ) 580 if ( value == "Daily" )
563 recur()->setType( OPimRecurrence::Daily ); 581 recur()->setType( OPimRecurrence::Daily );
564 else if ( value == "Weekly" ) 582 else if ( value == "Weekly" )
565 recur()->setType( OPimRecurrence::Weekly); 583 recur()->setType( OPimRecurrence::Weekly);
566 else if ( value == "MonthlyDay" ) 584 else if ( value == "MonthlyDay" )
567 recur()->setType( OPimRecurrence::MonthlyDay ); 585 recur()->setType( OPimRecurrence::MonthlyDay );
568 else if ( value == "MonthlyDate" ) 586 else if ( value == "MonthlyDate" )
569 recur()->setType( OPimRecurrence::MonthlyDate ); 587 recur()->setType( OPimRecurrence::MonthlyDate );
570 else if ( value == "Yearly" ) 588 else if ( value == "Yearly" )
571 recur()->setType( OPimRecurrence::Yearly ); 589 recur()->setType( OPimRecurrence::Yearly );
572 else 590 else
573 recur()->setType( OPimRecurrence::NoRepeat ); 591 recur()->setType( OPimRecurrence::NoRepeat );
574 break; 592 break;
575 case FRWeekdays: 593 case FRWeekdays:
@@ -601,48 +619,49 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString&
601 break; 619 break;
602 case FCreated: 620 case FCreated:
603 created = value.toInt(); 621 created = value.toInt();
604 break; 622 break;
605 case FRecParent: 623 case FRecParent:
606 e.setParent( value.toInt() ); 624 e.setParent( value.toInt() );
607 break; 625 break;
608 case FRecChildren:{ 626 case FRecChildren:{
609 QStringList list = QStringList::split(' ', value ); 627 QStringList list = QStringList::split(' ', value );
610 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 628 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
611 e.addChild( (*it).toInt() ); 629 e.addChild( (*it).toInt() );
612 } 630 }
613 } 631 }
614 break; 632 break;
615 case FExceptions:{ 633 case FExceptions:{
616 QStringList list = QStringList::split(' ', value ); 634 QStringList list = QStringList::split(' ', value );
617 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 635 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
618 QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); 636 QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() );
619 owarn << "adding exception " << date.toString() << "" << oendl; 637 owarn << "adding exception " << date.toString() << "" << oendl;
620 recur()->exceptions().append( date ); 638 recur()->exceptions().append( date );
621 } 639 }
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;
628 default: 647 default:
629 break; 648 break;
630 } 649 }
631} 650}
632QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const 651QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const
633{ 652{
634 QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() ); 653 QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() );
635 uint arraycounter = 0; 654 uint arraycounter = 0;
636 QMap<int, OPimEvent>::ConstIterator it; 655 QMap<int, OPimEvent>::ConstIterator it;
637 656
638 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) 657 for ( it = m_raw.begin(); it != m_raw.end(); ++it )
639 if ( it.data().match( r ) ) 658 if ( it.data().match( r ) )
640 m_currentQuery[arraycounter++] = it.data().uid(); 659 m_currentQuery[arraycounter++] = it.data().uid();
641 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) 660 for ( it = m_rep.begin(); it != m_rep.end(); ++it )
642 if ( it.data().match( r ) ) 661 if ( it.data().match( r ) )
643 m_currentQuery[arraycounter++] = it.data().uid(); 662 m_currentQuery[arraycounter++] = it.data().uid();
644 663
645 // Shrink to fit.. 664 // Shrink to fit..
646 m_currentQuery.resize(arraycounter); 665 m_currentQuery.resize(arraycounter);
647 666
648 return m_currentQuery; 667 return m_currentQuery;
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
@@ -47,40 +47,42 @@ public:
47 ~ODateBookAccessBackend_XML(); 47 ~ODateBookAccessBackend_XML();
48 48
49 bool load(); 49 bool load();
50 bool reload(); 50 bool reload();
51 bool save(); 51 bool save();
52 52
53 QArray<int> allRecords()const; 53 QArray<int> allRecords()const;
54 QArray<int> matchRegexp(const QRegExp &r) const; 54 QArray<int> matchRegexp(const QRegExp &r) const;
55 QArray<int> queryByExample( const OPimEvent&, int, const QDateTime& d = QDateTime() ); 55 QArray<int> queryByExample( const OPimEvent&, int, const QDateTime& d = QDateTime() );
56 OPimEvent find( int uid )const; 56 OPimEvent find( int uid )const;
57 void clear(); 57 void clear();
58 bool add( const OPimEvent& ev ); 58 bool add( const OPimEvent& ev );
59 bool remove( int uid ); 59 bool remove( int uid );
60 bool replace( const OPimEvent& ev ); 60 bool replace( const OPimEvent& ev );
61 61
62 QArray<UID> rawEvents()const; 62 QArray<UID> rawEvents()const;
63 QArray<UID> rawRepeats()const; 63 QArray<UID> rawRepeats()const;
64 QArray<UID> nonRepeats()const; 64 QArray<UID> nonRepeats()const;
65 65
66 OPimEvent::ValueList directNonRepeats(); 66 OPimEvent::ValueList directNonRepeats();
67 OPimEvent::ValueList directRawRepeats(); 67 OPimEvent::ValueList directRawRepeats();
68 68
69private: 69private:
70 bool m_changed :1 ; 70 bool m_changed :1 ;
71 bool m_noTimeZone : 1;
72
71 bool loadFile(); 73 bool loadFile();
72 inline void finalizeRecord( OPimEvent& ev ); 74 inline void finalizeRecord( OPimEvent& ev );
73 inline void setField( OPimEvent&, int field, const QString& val ); 75 inline void setField( OPimEvent&, int field, const QString& val );
74 QString m_name; 76 QString m_name;
75 QMap<int, OPimEvent> m_raw; 77 QMap<int, OPimEvent> m_raw;
76 QMap<int, OPimEvent> m_rep; 78 QMap<int, OPimEvent> m_rep;
77 79
78 struct Data; 80 struct Data;
79 Data* data; 81 Data* data;
80 class Private; 82 class Private;
81 Private *d; 83 Private *d;
82}; 84};
83 85
84} 86}
85 87
86#endif 88#endif