Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | 42 |
1 files changed, 24 insertions, 18 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 | |||
@@ -17,47 +17,53 @@ | |||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
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 | ||
32 | #include <stdio.h> | 49 | #include <stdio.h> |
33 | #include <stdlib.h> | 50 | #include <stdlib.h> |
34 | 51 | ||
35 | #include <sys/types.h> | 52 | #include <sys/types.h> |
36 | #include <sys/mman.h> | 53 | #include <sys/mman.h> |
37 | #include <sys/stat.h> | 54 | #include <sys/stat.h> |
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 | ||
53 | using namespace Opie; | 59 | using namespace Opie; |
54 | 60 | ||
55 | namespace { | 61 | namespace { |
56 | // FROM TT again | 62 | // FROM TT again |
57 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 63 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
58 | { | 64 | { |
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 | ||
@@ -107,25 +113,25 @@ namespace { | |||
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, |
114 | FExceptions | 120 | FExceptions |
115 | }; | 121 | }; |
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() ) + "\""; |
123 | 129 | ||
124 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; | 130 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; |
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 |
@@ -481,60 +487,60 @@ bool ODateBookAccessBackend_XML::loadFile() { | |||
481 | } | 487 | } |
482 | 488 | ||
483 | // FIXME: Use OPimEvent::fromMap() which makes this obsolete.. (eilers) | 489 | // FIXME: Use OPimEvent::fromMap() which makes this obsolete.. (eilers) |
484 | void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { | 490 | void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { |
485 | /* AllDay is alway in UTC */ | 491 | /* AllDay is alway in UTC */ |
486 | if ( ev.isAllDay() ) { | 492 | if ( ev.isAllDay() ) { |
487 | OPimTimeZone utc = OPimTimeZone::utc(); | 493 | OPimTimeZone utc = OPimTimeZone::utc(); |
488 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); | 494 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); |
489 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); | 495 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); |
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 ); |
500 | ev.setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); | 506 | ev.setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); |
501 | } | 507 | } |
502 | if ( rec && rec->doesRecur() ) { | 508 | if ( rec && rec->doesRecur() ) { |
503 | OPimTimeZone utc = OPimTimeZone::utc(); | 509 | OPimTimeZone utc = OPimTimeZone::utc(); |
504 | OPimRecurrence recu( *rec ); // call copy c'tor; | 510 | OPimRecurrence recu( *rec ); // call copy c'tor; |
505 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); | 511 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); |
506 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); | 512 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); |
507 | recu.setStart( ev.startDateTime().date() ); | 513 | recu.setStart( ev.startDateTime().date() ); |
508 | ev.setRecurrence( recu ); | 514 | ev.setRecurrence( recu ); |
509 | } | 515 | } |
510 | 516 | ||
511 | if (alarmTime != -1 ) { | 517 | if (alarmTime != -1 ) { |
512 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); | 518 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); |
513 | OPimAlarm al( snd , dt ); | 519 | OPimAlarm al( snd , dt ); |
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 |
524 | m_raw.insert( ev.uid(), ev ); | 530 | m_raw.insert( ev.uid(), ev ); |
525 | 531 | ||
526 | } | 532 | } |
527 | void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) { | 533 | void 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 ); |
532 | break; | 538 | break; |
533 | case FLocation: | 539 | case FLocation: |
534 | e.setLocation( value ); | 540 | e.setLocation( value ); |
535 | break; | 541 | break; |
536 | case FCategories: | 542 | case FCategories: |
537 | e.setCategories( e.idsFromString( value ) ); | 543 | e.setCategories( e.idsFromString( value ) ); |
538 | break; | 544 | break; |
539 | case FUid: | 545 | case FUid: |
540 | e.setUid( value.toInt() ); | 546 | e.setUid( value.toInt() ); |
@@ -601,25 +607,25 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& | |||
601 | break; | 607 | break; |
602 | case FRecChildren:{ | 608 | case FRecChildren:{ |
603 | QStringList list = QStringList::split(' ', value ); | 609 | QStringList list = QStringList::split(' ', value ); |
604 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 610 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
605 | e.addChild( (*it).toInt() ); | 611 | e.addChild( (*it).toInt() ); |
606 | } | 612 | } |
607 | } | 613 | } |
608 | break; | 614 | break; |
609 | case FExceptions:{ | 615 | case FExceptions:{ |
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 | } |
617 | break; | 623 | break; |
618 | case FTimeZone: | 624 | case FTimeZone: |
619 | if ( value != "None" ) | 625 | if ( value != "None" ) |
620 | e.setTimeZone( value ); | 626 | e.setTimeZone( value ); |
621 | break; | 627 | break; |
622 | default: | 628 | default: |
623 | break; | 629 | break; |
624 | } | 630 | } |
625 | } | 631 | } |