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.cpp170
1 files changed, 88 insertions, 82 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
index 77c0253..2ff36e3 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
@@ -26,6 +26,23 @@
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29
30/* OPIE */
31#include <opie2/opimnotifymanager.h>
32#include <opie2/opimrecurrence.h>
33#include <opie2/opimtimezone.h>
34#include <opie2/odatebookaccessbackend_xml.h>
35#include <opie2/odebug.h>
36
37#include <qtopia/global.h>
38#include <qtopia/stringutil.h>
39#include <qtopia/timeconversion.h>
40
41/* QT */
42#include <qasciidict.h>
43#include <qfile.h>
44
45/* STD */
29#include <errno.h> 46#include <errno.h>
30#include <fcntl.h> 47#include <fcntl.h>
31 48
@@ -38,17 +55,6 @@
38 55
39#include <unistd.h> 56#include <unistd.h>
40 57
41#include <qasciidict.h>
42#include <qfile.h>
43
44#include <qtopia/global.h>
45#include <qtopia/stringutil.h>
46#include <qtopia/timeconversion.h>
47
48#include <opie2/opimnotifymanager.h>
49#include <opie2/opimrecurrence.h>
50#include <opie2/opimtimezone.h>
51#include <opie2/odatebookaccessbackend_xml.h>
52 58
53using namespace Opie; 59using namespace Opie;
54 60
@@ -59,21 +65,21 @@ char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
59 char needleChar; 65 char needleChar;
60 char haystackChar; 66 char haystackChar;
61 if (!needle || !haystack || !hLen || !nLen) 67 if (!needle || !haystack || !hLen || !nLen)
62 return 0; 68 return 0;
63 69
64 const char* hsearch = haystack; 70 const char* hsearch = haystack;
65 71
66 if ((needleChar = *needle++) != 0) { 72 if ((needleChar = *needle++) != 0) {
67 nLen--; //(to make up for needle++) 73 nLen--; //(to make up for needle++)
68 do { 74 do {
69 do { 75 do {
70 if ((haystackChar = *hsearch++) == 0) 76 if ((haystackChar = *hsearch++) == 0)
71 return (0); 77 return (0);
72 if (hsearch >= haystack + hLen) 78 if (hsearch >= haystack + hLen)
73 return (0); 79 return (0);
74 } while (haystackChar != needleChar); 80 } while (haystackChar != needleChar);
75 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); 81 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
76 hsearch--; 82 hsearch--;
77 } 83 }
78 return ((char *)hsearch); 84 return ((char *)hsearch);
79} 85}
@@ -96,18 +102,18 @@ namespace {
96 FCategories, 102 FCategories,
97 FUid, 103 FUid,
98 FType, 104 FType,
99 FAlarm, 105 FAlarm,
100 FSound, 106 FSound,
101 FRType, 107 FRType,
102 FRWeekdays, 108 FRWeekdays,
103 FRPosition, 109 FRPosition,
104 FRFreq, 110 FRFreq,
105 FRHasEndDate, 111 FRHasEndDate,
106 FREndDate, 112 FREndDate,
107 FRStart, 113 FRStart,
108 FREnd, 114 FREnd,
109 FNote, 115 FNote,
110 FCreated, // Should't this be called FRCreated ? 116 FCreated, // Should't this be called FRCreated ?
111 FTimeZone, 117 FTimeZone,
112 FRecParent, 118 FRecParent,
113 FRecChildren, 119 FRecChildren,
@@ -116,7 +122,7 @@ namespace {
116 122
117 // FIXME: Use OPimEvent::toMap() here !! (eilers) 123 // FIXME: Use OPimEvent::toMap() here !! (eilers)
118 inline void save( const OPimEvent& ev, QString& buf ) { 124 inline void save( const OPimEvent& ev, QString& buf ) {
119 qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); 125 owarn << "Saving " << ev.uid() << " " << ev.description() << "" << oendl;
120 buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; 126 buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\"";
121 if (!ev.location().isEmpty() ) 127 if (!ev.location().isEmpty() )
122 buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; 128 buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\"";
@@ -125,7 +131,7 @@ namespace {
125 buf += " uid=\"" + QString::number( ev.uid() ) + "\""; 131 buf += " uid=\"" + QString::number( ev.uid() ) + "\"";
126 132
127 if (ev.isAllDay() ) 133 if (ev.isAllDay() )
128 buf += " type=\"AllDay\""; // is that all ?? (eilers) 134 buf += " type=\"AllDay\""; // is that all ?? (eilers)
129 135
130 if (ev.hasNotifiers() ) { 136 if (ev.hasNotifiers() ) {
131 OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first 137 OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first
@@ -419,46 +425,46 @@ bool ODateBookAccessBackend_XML::loadFile() {
419 425
420 while ( TRUE ) { 426 while ( TRUE ) {
421 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 427 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
422 ++i; 428 ++i;
423 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 429 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
424 break; 430 break;
425 431
426 432
427 // we have another attribute, read it. 433 // we have another attribute, read it.
428 int j = i; 434 int j = i;
429 while ( j < len && dt[j] != '=' ) 435 while ( j < len && dt[j] != '=' )
430 ++j; 436 ++j;
431 QCString attr( dt+i, j-i+1); 437 QCString attr( dt+i, j-i+1);
432 438
433 i = ++j; // skip = 439 i = ++j; // skip =
434 440
435 // find the start of quotes 441 // find the start of quotes
436 while ( i < len && dt[i] != '"' ) 442 while ( i < len && dt[i] != '"' )
437 ++i; 443 ++i;
438 j = ++i; 444 j = ++i;
439 445
440 bool haveUtf = FALSE; 446 bool haveUtf = FALSE;
441 bool haveEnt = FALSE; 447 bool haveEnt = FALSE;
442 while ( j < len && dt[j] != '"' ) { 448 while ( j < len && dt[j] != '"' ) {
443 if ( ((unsigned char)dt[j]) > 0x7f ) 449 if ( ((unsigned char)dt[j]) > 0x7f )
444 haveUtf = TRUE; 450 haveUtf = TRUE;
445 if ( dt[j] == '&' ) 451 if ( dt[j] == '&' )
446 haveEnt = TRUE; 452 haveEnt = TRUE;
447 ++j; 453 ++j;
448 } 454 }
449 if ( i == j ) { 455 if ( i == j ) {
450 // empty value 456 // empty value
451 i = j + 1; 457 i = j + 1;
452 continue; 458 continue;
453 } 459 }
454 460
455 QCString value( dt+i, j-i+1 ); 461 QCString value( dt+i, j-i+1 );
456 i = j + 1; 462 i = j + 1;
457 463
458 QString str = (haveUtf ? QString::fromUtf8( value ) 464 QString str = (haveUtf ? QString::fromUtf8( value )
459 : QString::fromLatin1( value ) ); 465 : QString::fromLatin1( value ) );
460 if ( haveEnt ) 466 if ( haveEnt )
461 str = Qtopia::plainString( str ); 467 str = Qtopia::plainString( str );
462 468
463 /* 469 /*
464 * add key + value 470 * add key + value
@@ -490,10 +496,10 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) {
490 ev.setTimeZone( "UTC"); // make sure it is really utc 496 ev.setTimeZone( "UTC"); // make sure it is really utc
491 }else { 497 }else {
492 /* to current date time */ 498 /* to current date time */
493 // qWarning(" Start is %d", start ); 499 // owarn << " Start is " << start << "" << oendl;
494 OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() ); 500 OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() );
495 QDateTime date = zone.toDateTime( start ); 501 QDateTime date = zone.toDateTime( start );
496 qWarning(" Start is %s", date.toString().latin1() ); 502 owarn << " Start is " << date.toString() << "" << oendl;
497 ev.setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); 503 ev.setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) );
498 504
499 date = zone.toDateTime( end ); 505 date = zone.toDateTime( end );
@@ -514,10 +520,10 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) {
514 ev.notifiers().add( al ); 520 ev.notifiers().add( al );
515 } 521 }
516 if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { 522 if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) {
517 qWarning("already contains assign uid"); 523 owarn << "already contains assign uid" << oendl;
518 ev.setUid( 1 ); 524 ev.setUid( 1 );
519 } 525 }
520 qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); 526 owarn << "addind " << ev.uid() << " " << ev.description() << "" << oendl;
521 if ( ev.hasRecurrence() ) 527 if ( ev.hasRecurrence() )
522 m_rep.insert( ev.uid(), ev ); 528 m_rep.insert( ev.uid(), ev );
523 else 529 else
@@ -525,7 +531,7 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) {
525 531
526} 532}
527void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) { 533void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) {
528// qWarning(" setting %s", value.latin1() ); 534// owarn << " setting " << value << "" << oendl;
529 switch( id ) { 535 switch( id ) {
530 case FDescription: 536 case FDescription:
531 e.setDescription( value ); 537 e.setDescription( value );
@@ -610,7 +616,7 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString&
610 QStringList list = QStringList::split(' ', value ); 616 QStringList list = QStringList::split(' ', value );
611 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 617 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
612 QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); 618 QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() );
613 qWarning("adding exception %s", date.toString().latin1() ); 619 owarn << "adding exception " << date.toString() << "" << oendl;
614 recur()->exceptions().append( date ); 620 recur()->exceptions().append( date );
615 } 621 }
616 } 622 }