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
@@ -1,176 +1,182 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) 3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
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
53using namespace Opie; 59using namespace Opie;
54 60
55namespace { 61namespace {
56 // FROM TT again 62 // FROM TT again
57char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) 63char *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
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}
80} 86}
81 87
82namespace { 88namespace {
83 time_t start, end, created, rp_end; 89 time_t start, end, created, rp_end;
84 OPimRecurrence* rec; 90 OPimRecurrence* rec;
85 OPimRecurrence* recur() { 91 OPimRecurrence* recur() {
86 if (!rec) 92 if (!rec)
87 rec = new OPimRecurrence; 93 rec = new OPimRecurrence;
88 94
89 return rec; 95 return rec;
90 } 96 }
91 int alarmTime; 97 int alarmTime;
92 int snd; 98 int snd;
93 enum Attribute{ 99 enum Attribute{
94 FDescription = 0, 100 FDescription = 0,
95 FLocation, 101 FLocation,
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,
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
132 int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; 138 int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60;
133 buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; 139 buf += " alarm=\"" + QString::number(minutes) + "\" sound=\"";
134 if ( alarm.sound() == OPimAlarm::Loud ) 140 if ( alarm.sound() == OPimAlarm::Loud )
135 buf += "loud"; 141 buf += "loud";
136 else 142 else
137 buf += "silent"; 143 buf += "silent";
138 buf += "\""; 144 buf += "\"";
139 } 145 }
140 if ( ev.hasRecurrence() ) { 146 if ( ev.hasRecurrence() ) {
141 buf += ev.recurrence().toString(); 147 buf += ev.recurrence().toString();
142 } 148 }
143 149
144 /* 150 /*
145 * fscking timezones :) well, we'll first convert 151 * fscking timezones :) well, we'll first convert
146 * the QDateTime to a QDateTime in UTC time 152 * the QDateTime to a QDateTime in UTC time
147 * and then we'll create a nice time_t 153 * and then we'll create a nice time_t
148 */ 154 */
149 OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() ); 155 OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() );
150 buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OPimTimeZone::utc() ) ) ) + "\""; 156 buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OPimTimeZone::utc() ) ) ) + "\"";
151 buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OPimTimeZone::utc() ) ) ) + "\""; 157 buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OPimTimeZone::utc() ) ) ) + "\"";
152 if (!ev.note().isEmpty() ) { 158 if (!ev.note().isEmpty() ) {
153 buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; 159 buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\"";
154 } 160 }
155 161
156 buf += " timezone=\""; 162 buf += " timezone=\"";
157 if ( ev.timeZone().isEmpty() ) 163 if ( ev.timeZone().isEmpty() )
158 buf += "None"; 164 buf += "None";
159 else 165 else
160 buf += ev.timeZone(); 166 buf += ev.timeZone();
161 buf += "\""; 167 buf += "\"";
162 168
163 if (ev.parent() != 0 ) { 169 if (ev.parent() != 0 ) {
164 buf += " recparent=\""+QString::number(ev.parent() )+"\""; 170 buf += " recparent=\""+QString::number(ev.parent() )+"\"";
165 } 171 }
166 172
167 if (ev.children().count() != 0 ) { 173 if (ev.children().count() != 0 ) {
168 QArray<int> children = ev.children(); 174 QArray<int> children = ev.children();
169 buf += " recchildren=\""; 175 buf += " recchildren=\"";
170 for ( uint i = 0; i < children.count(); i++ ) { 176 for ( uint i = 0; i < children.count(); i++ ) {
171 if ( i != 0 ) buf += " "; 177 if ( i != 0 ) buf += " ";
172 buf += QString::number( children[i] ); 178 buf += QString::number( children[i] );
173 } 179 }
174 buf+= "\""; 180 buf+= "\"";
175 } 181 }
176 182
@@ -374,272 +380,272 @@ bool ODateBookAccessBackend_XML::loadFile() {
374 } 380 }
375 381
376 ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); 382 ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL );
377 ::close( fd ); 383 ::close( fd );
378 384
379 QAsciiDict<int> dict(FExceptions+1); 385 QAsciiDict<int> dict(FExceptions+1);
380 dict.setAutoDelete( true ); 386 dict.setAutoDelete( true );
381 dict.insert( "description", new int(FDescription) ); 387 dict.insert( "description", new int(FDescription) );
382 dict.insert( "location", new int(FLocation) ); 388 dict.insert( "location", new int(FLocation) );
383 dict.insert( "categories", new int(FCategories) ); 389 dict.insert( "categories", new int(FCategories) );
384 dict.insert( "uid", new int(FUid) ); 390 dict.insert( "uid", new int(FUid) );
385 dict.insert( "type", new int(FType) ); 391 dict.insert( "type", new int(FType) );
386 dict.insert( "alarm", new int(FAlarm) ); 392 dict.insert( "alarm", new int(FAlarm) );
387 dict.insert( "sound", new int(FSound) ); 393 dict.insert( "sound", new int(FSound) );
388 dict.insert( "rtype", new int(FRType) ); 394 dict.insert( "rtype", new int(FRType) );
389 dict.insert( "rweekdays", new int(FRWeekdays) ); 395 dict.insert( "rweekdays", new int(FRWeekdays) );
390 dict.insert( "rposition", new int(FRPosition) ); 396 dict.insert( "rposition", new int(FRPosition) );
391 dict.insert( "rfreq", new int(FRFreq) ); 397 dict.insert( "rfreq", new int(FRFreq) );
392 dict.insert( "rhasenddate", new int(FRHasEndDate) ); 398 dict.insert( "rhasenddate", new int(FRHasEndDate) );
393 dict.insert( "enddt", new int(FREndDate) ); 399 dict.insert( "enddt", new int(FREndDate) );
394 dict.insert( "start", new int(FRStart) ); 400 dict.insert( "start", new int(FRStart) );
395 dict.insert( "end", new int(FREnd) ); 401 dict.insert( "end", new int(FREnd) );
396 dict.insert( "note", new int(FNote) ); 402 dict.insert( "note", new int(FNote) );
397 dict.insert( "created", new int(FCreated) ); // Shouldn't this be FRCreated ?? 403 dict.insert( "created", new int(FCreated) ); // Shouldn't this be FRCreated ??
398 dict.insert( "recparent", new int(FRecParent) ); 404 dict.insert( "recparent", new int(FRecParent) );
399 dict.insert( "recchildren", new int(FRecChildren) ); 405 dict.insert( "recchildren", new int(FRecChildren) );
400 dict.insert( "exceptions", new int(FExceptions) ); 406 dict.insert( "exceptions", new int(FExceptions) );
401 dict.insert( "timezone", new int(FTimeZone) ); 407 dict.insert( "timezone", new int(FTimeZone) );
402 408
403 char* dt = (char*)map_addr; 409 char* dt = (char*)map_addr;
404 int len = attribute.st_size; 410 int len = attribute.st_size;
405 int i = 0; 411 int i = 0;
406 char* point; 412 char* point;
407 const char* collectionString = "<event "; 413 const char* collectionString = "<event ";
408 int strLen = ::strlen(collectionString); 414 int strLen = ::strlen(collectionString);
409 int *find; 415 int *find;
410 while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { 416 while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) {
411 i = point -dt; 417 i = point -dt;
412 i+= strLen; 418 i+= strLen;
413 419
414 alarmTime = -1; 420 alarmTime = -1;
415 snd = 0; // silent 421 snd = 0; // silent
416 422
417 OPimEvent ev; 423 OPimEvent ev;
418 rec = 0; 424 rec = 0;
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
465 */ 471 */
466 find = dict[attr.data()]; 472 find = dict[attr.data()];
467 if (!find) 473 if (!find)
468 ev.setCustomField( attr, str ); 474 ev.setCustomField( attr, str );
469 else { 475 else {
470 setField( ev, *find, str ); 476 setField( ev, *find, str );
471 } 477 }
472 } 478 }
473 /* time to finalize */ 479 /* time to finalize */
474 finalizeRecord( ev ); 480 finalizeRecord( ev );
475 delete rec; 481 delete rec;
476 } 482 }
477 ::munmap(map_addr, attribute.st_size ); 483 ::munmap(map_addr, attribute.st_size );
478 m_changed = false; // changed during add 484 m_changed = false; // changed during add
479 485
480 return true; 486 return true;
481} 487}
482 488
483// FIXME: Use OPimEvent::fromMap() which makes this obsolete.. (eilers) 489// FIXME: Use OPimEvent::fromMap() which makes this obsolete.. (eilers)
484void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { 490void 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}
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 );
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() );
541 break; 547 break;
542 case FType: 548 case FType:
543 if ( value == "AllDay" ) { 549 if ( value == "AllDay" ) {
544 e.setAllDay( true ); 550 e.setAllDay( true );
545 e.setTimeZone( "UTC" ); 551 e.setTimeZone( "UTC" );
546 } 552 }
547 break; 553 break;
548 case FAlarm: 554 case FAlarm:
549 alarmTime = value.toInt(); 555 alarmTime = value.toInt();
550 break; 556 break;
551 case FSound: 557 case FSound:
552 snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; 558 snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent;
553 break; 559 break;
554 // recurrence stuff 560 // recurrence stuff
555 case FRType: 561 case FRType:
556 if ( value == "Daily" ) 562 if ( value == "Daily" )
557 recur()->setType( OPimRecurrence::Daily ); 563 recur()->setType( OPimRecurrence::Daily );
558 else if ( value == "Weekly" ) 564 else if ( value == "Weekly" )
559 recur()->setType( OPimRecurrence::Weekly); 565 recur()->setType( OPimRecurrence::Weekly);
560 else if ( value == "MonthlyDay" ) 566 else if ( value == "MonthlyDay" )
561 recur()->setType( OPimRecurrence::MonthlyDay ); 567 recur()->setType( OPimRecurrence::MonthlyDay );
562 else if ( value == "MonthlyDate" ) 568 else if ( value == "MonthlyDate" )
563 recur()->setType( OPimRecurrence::MonthlyDate ); 569 recur()->setType( OPimRecurrence::MonthlyDate );
564 else if ( value == "Yearly" ) 570 else if ( value == "Yearly" )
565 recur()->setType( OPimRecurrence::Yearly ); 571 recur()->setType( OPimRecurrence::Yearly );
566 else 572 else
567 recur()->setType( OPimRecurrence::NoRepeat ); 573 recur()->setType( OPimRecurrence::NoRepeat );
568 break; 574 break;
569 case FRWeekdays: 575 case FRWeekdays:
570 recur()->setDays( value.toInt() ); 576 recur()->setDays( value.toInt() );
571 break; 577 break;
572 case FRPosition: 578 case FRPosition:
573 recur()->setPosition( value.toInt() ); 579 recur()->setPosition( value.toInt() );
574 break; 580 break;
575 case FRFreq: 581 case FRFreq:
576 recur()->setFrequency( value.toInt() ); 582 recur()->setFrequency( value.toInt() );
577 break; 583 break;
578 case FRHasEndDate: 584 case FRHasEndDate:
579 recur()->setHasEndDate( value.toInt() ); 585 recur()->setHasEndDate( value.toInt() );
580 break; 586 break;
581 case FREndDate: { 587 case FREndDate: {
582 rp_end = (time_t) value.toLong(); 588 rp_end = (time_t) value.toLong();
583 break; 589 break;
584 } 590 }
585 case FRStart: { 591 case FRStart: {
586 start = (time_t) value.toLong(); 592 start = (time_t) value.toLong();
587 break; 593 break;
588 } 594 }
589 case FREnd: { 595 case FREnd: {
590 end = ( (time_t) value.toLong() ); 596 end = ( (time_t) value.toLong() );
591 break; 597 break;
592 } 598 }
593 case FNote: 599 case FNote:
594 e.setNote( value ); 600 e.setNote( value );
595 break; 601 break;
596 case FCreated: 602 case FCreated:
597 created = value.toInt(); 603 created = value.toInt();
598 break; 604 break;
599 case FRecParent: 605 case FRecParent:
600 e.setParent( value.toInt() ); 606 e.setParent( value.toInt() );
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}
626QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const 632QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const
627{ 633{
628 QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() ); 634 QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() );
629 uint arraycounter = 0; 635 uint arraycounter = 0;
630 QMap<int, OPimEvent>::ConstIterator it; 636 QMap<int, OPimEvent>::ConstIterator it;
631 637
632 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) 638 for ( it = m_raw.begin(); it != m_raw.end(); ++it )
633 if ( it.data().match( r ) ) 639 if ( it.data().match( r ) )
634 m_currentQuery[arraycounter++] = it.data().uid(); 640 m_currentQuery[arraycounter++] = it.data().uid();
635 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) 641 for ( it = m_rep.begin(); it != m_rep.end(); ++it )
636 if ( it.data().match( r ) ) 642 if ( it.data().match( r ) )
637 m_currentQuery[arraycounter++] = it.data().uid(); 643 m_currentQuery[arraycounter++] = it.data().uid();
638 644
639 // Shrink to fit.. 645 // Shrink to fit..
640 m_currentQuery.resize(arraycounter); 646 m_currentQuery.resize(arraycounter);
641 647
642 return m_currentQuery; 648 return m_currentQuery;
643} 649}
644 650
645} 651}