summaryrefslogtreecommitdiff
path: root/libopie/pim/odatebookaccessbackend_xml.cpp
Unidiff
Diffstat (limited to 'libopie/pim/odatebookaccessbackend_xml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/odatebookaccessbackend_xml.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/libopie/pim/odatebookaccessbackend_xml.cpp b/libopie/pim/odatebookaccessbackend_xml.cpp
index 39c43c5..929d004 100644
--- a/libopie/pim/odatebookaccessbackend_xml.cpp
+++ b/libopie/pim/odatebookaccessbackend_xml.cpp
@@ -1,542 +1,548 @@
1#include <errno.h> 1#include <errno.h>
2#include <fcntl.h> 2#include <fcntl.h>
3 3
4#include <stdio.h> 4#include <stdio.h>
5#include <stdlib.h> 5#include <stdlib.h>
6 6
7#include <sys/types.h> 7#include <sys/types.h>
8#include <sys/mman.h> 8#include <sys/mman.h>
9#include <sys/stat.h> 9#include <sys/stat.h>
10 10
11#include <unistd.h> 11#include <unistd.h>
12 12
13#include <qasciidict.h> 13#include <qasciidict.h>
14#include <qfile.h> 14#include <qfile.h>
15 15
16#include <qtopia/global.h> 16#include <qtopia/global.h>
17#include <qtopia/stringutil.h> 17#include <qtopia/stringutil.h>
18#include <qtopia/timeconversion.h> 18#include <qtopia/timeconversion.h>
19 19
20#include "opimnotifymanager.h" 20#include "opimnotifymanager.h"
21#include "orecur.h" 21#include "orecur.h"
22#include "otimezone.h" 22#include "otimezone.h"
23#include "odatebookaccessbackend_xml.h" 23#include "odatebookaccessbackend_xml.h"
24 24
25namespace { 25namespace {
26 // FROM TT again 26 // FROM TT again
27char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) 27char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
28{ 28{
29 char needleChar; 29 char needleChar;
30 char haystackChar; 30 char haystackChar;
31 if (!needle || !haystack || !hLen || !nLen) 31 if (!needle || !haystack || !hLen || !nLen)
32 return 0; 32 return 0;
33 33
34 const char* hsearch = haystack; 34 const char* hsearch = haystack;
35 35
36 if ((needleChar = *needle++) != 0) { 36 if ((needleChar = *needle++) != 0) {
37 nLen--; //(to make up for needle++) 37 nLen--; //(to make up for needle++)
38 do { 38 do {
39 do { 39 do {
40 if ((haystackChar = *hsearch++) == 0) 40 if ((haystackChar = *hsearch++) == 0)
41 return (0); 41 return (0);
42 if (hsearch >= haystack + hLen) 42 if (hsearch >= haystack + hLen)
43 return (0); 43 return (0);
44 } while (haystackChar != needleChar); 44 } while (haystackChar != needleChar);
45 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); 45 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
46 hsearch--; 46 hsearch--;
47 } 47 }
48 return ((char *)hsearch); 48 return ((char *)hsearch);
49} 49}
50} 50}
51 51
52namespace { 52namespace {
53 time_t start, end, created, rp_end; 53 time_t start, end, created, rp_end;
54 ORecur* rec; 54 ORecur* rec;
55 ORecur* recur() { 55 ORecur* recur() {
56 if (!rec) 56 if (!rec)
57 rec = new ORecur; 57 rec = new ORecur;
58 58
59 return rec; 59 return rec;
60 } 60 }
61 int alarmTime; 61 int alarmTime;
62 int snd; 62 int snd;
63 enum Attribute{ 63 enum Attribute{
64 FDescription = 0, 64 FDescription = 0,
65 FLocation, 65 FLocation,
66 FCategories, 66 FCategories,
67 FUid, 67 FUid,
68 FType, 68 FType,
69 FAlarm, 69 FAlarm,
70 FSound, 70 FSound,
71 FRType, 71 FRType,
72 FRWeekdays, 72 FRWeekdays,
73 FRPosition, 73 FRPosition,
74 FRFreq, 74 FRFreq,
75 FRHasEndDate, 75 FRHasEndDate,
76 FREndDate, 76 FREndDate,
77 FRStart, 77 FRStart,
78 FREnd, 78 FREnd,
79 FNote, 79 FNote,
80 FCreated, 80 FCreated, // Should't this be called FRCreated ?
81 FTimeZone, 81 FTimeZone,
82 FRecParent, 82 FRecParent,
83 FRecChildren, 83 FRecChildren,
84 FExceptions 84 FExceptions
85 }; 85 };
86
87 // FIXME: Use OEvent::toMap() here !! (eilers)
86 inline void save( const OEvent& ev, QString& buf ) { 88 inline void save( const OEvent& ev, QString& buf ) {
87 qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); 89 qWarning("Saving %d %s", ev.uid(), ev.description().latin1() );
88 buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; 90 buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\"";
89 if (!ev.location().isEmpty() ) 91 if (!ev.location().isEmpty() )
90 buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; 92 buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\"";
91 93
92 buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; 94 buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\"";
93 buf += " uid=\"" + QString::number( ev.uid() ) + "\""; 95 buf += " uid=\"" + QString::number( ev.uid() ) + "\"";
94 96
95 if (ev.isAllDay() ) 97 if (ev.isAllDay() )
96 buf += " type=\"AllDay\""; // is that all ?? (eilers) 98 buf += " type=\"AllDay\""; // is that all ?? (eilers)
97 99
98 if (ev.hasNotifiers() ) { 100 if (ev.hasNotifiers() ) {
99 OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first 101 OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first
100 int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; 102 int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60;
101 buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; 103 buf += " alarm=\"" + QString::number(minutes) + "\" sound=\"";
102 if ( alarm.sound() == OPimAlarm::Loud ) 104 if ( alarm.sound() == OPimAlarm::Loud )
103 buf += "loud"; 105 buf += "loud";
104 else 106 else
105 buf += "silent"; 107 buf += "silent";
106 buf += "\""; 108 buf += "\"";
107 } 109 }
108 if ( ev.hasRecurrence() ) { 110 if ( ev.hasRecurrence() ) {
109 buf += ev.recurrence().toString(); 111 buf += ev.recurrence().toString();
110 } 112 }
111 113
112 /* 114 /*
113 * fscking timezones :) well, we'll first convert 115 * fscking timezones :) well, we'll first convert
114 * the QDateTime to a QDateTime in UTC time 116 * the QDateTime to a QDateTime in UTC time
115 * and then we'll create a nice time_t 117 * and then we'll create a nice time_t
116 */ 118 */
117 OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); 119 OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() );
118 buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; 120 buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\"";
119 buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; 121 buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\"";
120 if (!ev.note().isEmpty() ) { 122 if (!ev.note().isEmpty() ) {
121 buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; 123 buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\"";
122 } 124 }
123 125
124 buf += " timezone=\""; 126 buf += " timezone=\"";
125 if ( ev.timeZone().isEmpty() ) 127 if ( ev.timeZone().isEmpty() )
126 buf += "None"; 128 buf += "None";
127 else 129 else
128 buf += ev.timeZone(); 130 buf += ev.timeZone();
129 buf += "\""; 131 buf += "\"";
130 132
131 if (ev.parent() != 0 ) { 133 if (ev.parent() != 0 ) {
132 buf += " recparent=\""+QString::number(ev.parent() )+"\""; 134 buf += " recparent=\""+QString::number(ev.parent() )+"\"";
133 } 135 }
134 136
135 if (ev.children().count() != 0 ) { 137 if (ev.children().count() != 0 ) {
136 QArray<int> children = ev.children(); 138 QArray<int> children = ev.children();
137 buf += " recchildren=\""; 139 buf += " recchildren=\"";
138 for ( uint i = 0; i < children.count(); i++ ) { 140 for ( uint i = 0; i < children.count(); i++ ) {
139 if ( i != 0 ) buf += " "; 141 if ( i != 0 ) buf += " ";
140 buf += QString::number( children[i] ); 142 buf += QString::number( children[i] );
141 } 143 }
142 buf+= "\""; 144 buf+= "\"";
143 } 145 }
144 146
145 // skip custom writing 147 // skip custom writing
146 } 148 }
147 149
148 inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { 150 inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) {
149 QMap<int, OEvent>::ConstIterator it; 151 QMap<int, OEvent>::ConstIterator it;
150 QString buf; 152 QString buf;
151 QCString str; 153 QCString str;
152 int total_written; 154 int total_written;
153 for ( it = list.begin(); it != list.end(); ++it ) { 155 for ( it = list.begin(); it != list.end(); ++it ) {
154 buf = "<event"; 156 buf = "<event";
155 save( it.data(), buf ); 157 save( it.data(), buf );
156 buf += " />\n"; 158 buf += " />\n";
157 str = buf.utf8(); 159 str = buf.utf8();
158 160
159 total_written = file.writeBlock(str.data(), str.length() ); 161 total_written = file.writeBlock(str.data(), str.length() );
160 if ( total_written != int(str.length() ) ) 162 if ( total_written != int(str.length() ) )
161 return false; 163 return false;
162 } 164 }
163 return true; 165 return true;
164 } 166 }
165} 167}
166 168
167ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , 169ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& ,
168 const QString& fileName ) 170 const QString& fileName )
169 : ODateBookAccessBackend() { 171 : ODateBookAccessBackend() {
170 m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; 172 m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName;
171 m_changed = false; 173 m_changed = false;
172} 174}
173ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { 175ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() {
174} 176}
175bool ODateBookAccessBackend_XML::load() { 177bool ODateBookAccessBackend_XML::load() {
176 return loadFile(); 178 return loadFile();
177} 179}
178bool ODateBookAccessBackend_XML::reload() { 180bool ODateBookAccessBackend_XML::reload() {
179 clear(); 181 clear();
180 return load(); 182 return load();
181} 183}
182bool ODateBookAccessBackend_XML::save() { 184bool ODateBookAccessBackend_XML::save() {
183 if (!m_changed) return true; 185 if (!m_changed) return true;
184 186
185 int total_written; 187 int total_written;
186 QString strFileNew = m_name + ".new"; 188 QString strFileNew = m_name + ".new";
187 189
188 QFile f( strFileNew ); 190 QFile f( strFileNew );
189 if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; 191 if (!f.open( IO_WriteOnly | IO_Raw ) ) return false;
190 192
191 QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); 193 QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
192 buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; 194 buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n";
193 buf += "<events>\n"; 195 buf += "<events>\n";
194 QCString str = buf.utf8(); 196 QCString str = buf.utf8();
195 total_written = f.writeBlock( str.data(), str.length() ); 197 total_written = f.writeBlock( str.data(), str.length() );
196 if ( total_written != int(str.length() ) ) { 198 if ( total_written != int(str.length() ) ) {
197 f.close(); 199 f.close();
198 QFile::remove( strFileNew ); 200 QFile::remove( strFileNew );
199 return false; 201 return false;
200 } 202 }
201 203
202 if (!forAll( m_raw, f ) ) { 204 if (!forAll( m_raw, f ) ) {
203 f.close(); 205 f.close();
204 QFile::remove( strFileNew ); 206 QFile::remove( strFileNew );
205 return false; 207 return false;
206 } 208 }
207 if (!forAll( m_rep, f ) ) { 209 if (!forAll( m_rep, f ) ) {
208 f.close(); 210 f.close();
209 QFile::remove( strFileNew ); 211 QFile::remove( strFileNew );
210 return false; 212 return false;
211 } 213 }
212 214
213 buf = "</events>\n</DATEBOOK>\n"; 215 buf = "</events>\n</DATEBOOK>\n";
214 str = buf.utf8(); 216 str = buf.utf8();
215 total_written = f.writeBlock( str.data(), str.length() ); 217 total_written = f.writeBlock( str.data(), str.length() );
216 if ( total_written != int(str.length() ) ) { 218 if ( total_written != int(str.length() ) ) {
217 f.close(); 219 f.close();
218 QFile::remove( strFileNew ); 220 QFile::remove( strFileNew );
219 return false; 221 return false;
220 } 222 }
221 f.close(); 223 f.close();
222 224
223 if ( ::rename( strFileNew, m_name ) < 0 ) { 225 if ( ::rename( strFileNew, m_name ) < 0 ) {
224 QFile::remove( strFileNew ); 226 QFile::remove( strFileNew );
225 return false; 227 return false;
226 } 228 }
227 229
228 m_changed = false; 230 m_changed = false;
229 return true; 231 return true;
230} 232}
231QArray<int> ODateBookAccessBackend_XML::allRecords()const { 233QArray<int> ODateBookAccessBackend_XML::allRecords()const {
232 QArray<int> ints( m_raw.count()+ m_rep.count() ); 234 QArray<int> ints( m_raw.count()+ m_rep.count() );
233 uint i = 0; 235 uint i = 0;
234 QMap<int, OEvent>::ConstIterator it; 236 QMap<int, OEvent>::ConstIterator it;
235 237
236 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { 238 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) {
237 ints[i] = it.key(); 239 ints[i] = it.key();
238 i++; 240 i++;
239 } 241 }
240 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { 242 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) {
241 ints[i] = it.key(); 243 ints[i] = it.key();
242 i++; 244 i++;
243 } 245 }
244 246
245 return ints; 247 return ints;
246} 248}
247QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { 249QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) {
248 return QArray<int>(); 250 return QArray<int>();
249} 251}
250void ODateBookAccessBackend_XML::clear() { 252void ODateBookAccessBackend_XML::clear() {
251 m_changed = true; 253 m_changed = true;
252 m_raw.clear(); 254 m_raw.clear();
253 m_rep.clear(); 255 m_rep.clear();
254} 256}
255OEvent ODateBookAccessBackend_XML::find( int uid ) const{ 257OEvent ODateBookAccessBackend_XML::find( int uid ) const{
256 if ( m_raw.contains( uid ) ) 258 if ( m_raw.contains( uid ) )
257 return m_raw[uid]; 259 return m_raw[uid];
258 else 260 else
259 return m_rep[uid]; 261 return m_rep[uid];
260} 262}
261bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { 263bool ODateBookAccessBackend_XML::add( const OEvent& ev ) {
262 m_changed = true; 264 m_changed = true;
263 if (ev.hasRecurrence() ) 265 if (ev.hasRecurrence() )
264 m_rep.insert( ev.uid(), ev ); 266 m_rep.insert( ev.uid(), ev );
265 else 267 else
266 m_raw.insert( ev.uid(), ev ); 268 m_raw.insert( ev.uid(), ev );
267 269
268 return true; 270 return true;
269} 271}
270bool ODateBookAccessBackend_XML::remove( int uid ) { 272bool ODateBookAccessBackend_XML::remove( int uid ) {
271 m_changed = true; 273 m_changed = true;
272 m_rep.remove( uid ); 274 m_rep.remove( uid );
273 m_rep.remove( uid ); 275 m_rep.remove( uid );
274 276
275 return true; 277 return true;
276} 278}
277bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { 279bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) {
278 replace( ev.uid() ); 280 replace( ev.uid() ); // ??? Shouldn't this be "remove( ev.uid() ) ??? (eilers)
279 return add( ev ); 281 return add( ev );
280} 282}
281QArray<int> ODateBookAccessBackend_XML::rawEvents()const { 283QArray<int> ODateBookAccessBackend_XML::rawEvents()const {
282 return allRecords(); 284 return allRecords();
283} 285}
284QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { 286QArray<int> ODateBookAccessBackend_XML::rawRepeats()const {
285 QArray<int> ints( m_rep.count() ); 287 QArray<int> ints( m_rep.count() );
286 uint i = 0; 288 uint i = 0;
287 QMap<int, OEvent>::ConstIterator it; 289 QMap<int, OEvent>::ConstIterator it;
288 290
289 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { 291 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) {
290 ints[i] = it.key(); 292 ints[i] = it.key();
291 i++; 293 i++;
292 } 294 }
293 295
294 return ints; 296 return ints;
295} 297}
296QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { 298QArray<int> ODateBookAccessBackend_XML::nonRepeats()const {
297 QArray<int> ints( m_raw.count() ); 299 QArray<int> ints( m_raw.count() );
298 uint i = 0; 300 uint i = 0;
299 QMap<int, OEvent>::ConstIterator it; 301 QMap<int, OEvent>::ConstIterator it;
300 302
301 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { 303 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) {
302 ints[i] = it.key(); 304 ints[i] = it.key();
303 i++; 305 i++;
304 } 306 }
305 307
306 return ints; 308 return ints;
307} 309}
308OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { 310OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() {
309 OEvent::ValueList list; 311 OEvent::ValueList list;
310 QMap<int, OEvent>::ConstIterator it; 312 QMap<int, OEvent>::ConstIterator it;
311 for (it = m_raw.begin(); it != m_raw.end(); ++it ) 313 for (it = m_raw.begin(); it != m_raw.end(); ++it )
312 list.append( it.data() ); 314 list.append( it.data() );
313 315
314 return list; 316 return list;
315} 317}
316OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { 318OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() {
317 OEvent::ValueList list; 319 OEvent::ValueList list;
318 QMap<int, OEvent>::ConstIterator it; 320 QMap<int, OEvent>::ConstIterator it;
319 for (it = m_rep.begin(); it != m_rep.end(); ++it ) 321 for (it = m_rep.begin(); it != m_rep.end(); ++it )
320 list.append( it.data() ); 322 list.append( it.data() );
321 323
322 return list; 324 return list;
323} 325}
326
327// FIXME: Use OEvent::fromMap() (eilers)
324bool ODateBookAccessBackend_XML::loadFile() { 328bool ODateBookAccessBackend_XML::loadFile() {
325 m_changed = false; 329 m_changed = false;
326 330
327 int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); 331 int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY );
328 if ( fd < 0 ) return false; 332 if ( fd < 0 ) return false;
329 333
330 struct stat attribute; 334 struct stat attribute;
331 if ( ::fstat(fd, &attribute ) == -1 ) { 335 if ( ::fstat(fd, &attribute ) == -1 ) {
332 ::close( fd ); 336 ::close( fd );
333 return false; 337 return false;
334 } 338 }
335 void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); 339 void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 );
336 if ( map_addr == ( (caddr_t)-1) ) { 340 if ( map_addr == ( (caddr_t)-1) ) {
337 ::close( fd ); 341 ::close( fd );
338 return false; 342 return false;
339 } 343 }
340 344
341 ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); 345 ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL );
342 ::close( fd ); 346 ::close( fd );
343 347
344 QAsciiDict<int> dict(FExceptions+1); 348 QAsciiDict<int> dict(FExceptions+1);
345 dict.setAutoDelete( true ); 349 dict.setAutoDelete( true );
346 dict.insert( "description", new int(FDescription) ); 350 dict.insert( "description", new int(FDescription) );
347 dict.insert( "location", new int(FLocation) ); 351 dict.insert( "location", new int(FLocation) );
348 dict.insert( "categories", new int(FCategories) ); 352 dict.insert( "categories", new int(FCategories) );
349 dict.insert( "uid", new int(FUid) ); 353 dict.insert( "uid", new int(FUid) );
350 dict.insert( "type", new int(FType) ); 354 dict.insert( "type", new int(FType) );
351 dict.insert( "alarm", new int(FAlarm) ); 355 dict.insert( "alarm", new int(FAlarm) );
352 dict.insert( "sound", new int(FSound) ); 356 dict.insert( "sound", new int(FSound) );
353 dict.insert( "rtype", new int(FRType) ); 357 dict.insert( "rtype", new int(FRType) );
354 dict.insert( "rweekdays", new int(FRWeekdays) ); 358 dict.insert( "rweekdays", new int(FRWeekdays) );
355 dict.insert( "rposition", new int(FRPosition) ); 359 dict.insert( "rposition", new int(FRPosition) );
356 dict.insert( "rfreq", new int(FRFreq) ); 360 dict.insert( "rfreq", new int(FRFreq) );
357 dict.insert( "rhasenddate", new int(FRHasEndDate) ); 361 dict.insert( "rhasenddate", new int(FRHasEndDate) );
358 dict.insert( "enddt", new int(FREndDate) ); 362 dict.insert( "enddt", new int(FREndDate) );
359 dict.insert( "start", new int(FRStart) ); 363 dict.insert( "start", new int(FRStart) );
360 dict.insert( "end", new int(FREnd) ); 364 dict.insert( "end", new int(FREnd) );
361 dict.insert( "note", new int(FNote) ); 365 dict.insert( "note", new int(FNote) );
362 dict.insert( "created", new int(FCreated) ); 366 dict.insert( "created", new int(FCreated) ); // Shouldn't this be FRCreated ??
363 dict.insert( "recparent", new int(FRecParent) ); 367 dict.insert( "recparent", new int(FRecParent) );
364 dict.insert( "recchildren", new int(FRecChildren) ); 368 dict.insert( "recchildren", new int(FRecChildren) );
365 dict.insert( "exceptions", new int(FExceptions) ); 369 dict.insert( "exceptions", new int(FExceptions) );
366 dict.insert( "timezone", new int(FTimeZone) ); 370 dict.insert( "timezone", new int(FTimeZone) );
367 371
368 char* dt = (char*)map_addr; 372 char* dt = (char*)map_addr;
369 int len = attribute.st_size; 373 int len = attribute.st_size;
370 int i = 0; 374 int i = 0;
371 char* point; 375 char* point;
372 const char* collectionString = "<event "; 376 const char* collectionString = "<event ";
373 int strLen = ::strlen(collectionString); 377 int strLen = ::strlen(collectionString);
374 int *find; 378 int *find;
375 while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { 379 while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) {
376 i = point -dt; 380 i = point -dt;
377 i+= strLen; 381 i+= strLen;
378 382
379 alarmTime = -1; 383 alarmTime = -1;
380 snd = 0; // silent 384 snd = 0; // silent
381 385
382 OEvent ev; 386 OEvent ev;
383 rec = 0; 387 rec = 0;
384 388
385 while ( TRUE ) { 389 while ( TRUE ) {
386 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 390 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
387 ++i; 391 ++i;
388 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 392 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
389 break; 393 break;
390 394
391 395
392 // we have another attribute, read it. 396 // we have another attribute, read it.
393 int j = i; 397 int j = i;
394 while ( j < len && dt[j] != '=' ) 398 while ( j < len && dt[j] != '=' )
395 ++j; 399 ++j;
396 QCString attr( dt+i, j-i+1); 400 QCString attr( dt+i, j-i+1);
397 401
398 i = ++j; // skip = 402 i = ++j; // skip =
399 403
400 // find the start of quotes 404 // find the start of quotes
401 while ( i < len && dt[i] != '"' ) 405 while ( i < len && dt[i] != '"' )
402 ++i; 406 ++i;
403 j = ++i; 407 j = ++i;
404 408
405 bool haveUtf = FALSE; 409 bool haveUtf = FALSE;
406 bool haveEnt = FALSE; 410 bool haveEnt = FALSE;
407 while ( j < len && dt[j] != '"' ) { 411 while ( j < len && dt[j] != '"' ) {
408 if ( ((unsigned char)dt[j]) > 0x7f ) 412 if ( ((unsigned char)dt[j]) > 0x7f )
409 haveUtf = TRUE; 413 haveUtf = TRUE;
410 if ( dt[j] == '&' ) 414 if ( dt[j] == '&' )
411 haveEnt = TRUE; 415 haveEnt = TRUE;
412 ++j; 416 ++j;
413 } 417 }
414 if ( i == j ) { 418 if ( i == j ) {
415 // empty value 419 // empty value
416 i = j + 1; 420 i = j + 1;
417 continue; 421 continue;
418 } 422 }
419 423
420 QCString value( dt+i, j-i+1 ); 424 QCString value( dt+i, j-i+1 );
421 i = j + 1; 425 i = j + 1;
422 426
423 QString str = (haveUtf ? QString::fromUtf8( value ) 427 QString str = (haveUtf ? QString::fromUtf8( value )
424 : QString::fromLatin1( value ) ); 428 : QString::fromLatin1( value ) );
425 if ( haveEnt ) 429 if ( haveEnt )
426 str = Qtopia::plainString( str ); 430 str = Qtopia::plainString( str );
427 431
428 /* 432 /*
429 * add key + value 433 * add key + value
430 */ 434 */
431 find = dict[attr.data()]; 435 find = dict[attr.data()];
432 if (!find) 436 if (!find)
433 ev.setCustomField( attr, str ); 437 ev.setCustomField( attr, str );
434 else { 438 else {
435 setField( ev, *find, str ); 439 setField( ev, *find, str );
436 } 440 }
437 } 441 }
438 /* time to finalize */ 442 /* time to finalize */
439 finalizeRecord( ev ); 443 finalizeRecord( ev );
440 delete rec; 444 delete rec;
441 } 445 }
442 ::munmap(map_addr, attribute.st_size ); 446 ::munmap(map_addr, attribute.st_size );
443 m_changed = false; // changed during add 447 m_changed = false; // changed during add
444 448
445 return true; 449 return true;
446} 450}
451
452// FIXME: Use OEvent::fromMap() which makes this obsolete.. (eilers)
447void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { 453void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) {
448 /* AllDay is alway in UTC */ 454 /* AllDay is alway in UTC */
449 if ( ev.isAllDay() ) { 455 if ( ev.isAllDay() ) {
450 OTimeZone utc = OTimeZone::utc(); 456 OTimeZone utc = OTimeZone::utc();
451 ev.setStartDateTime( utc.fromUTCDateTime( start ) ); 457 ev.setStartDateTime( utc.fromUTCDateTime( start ) );
452 ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); 458 ev.setEndDateTime ( utc.fromUTCDateTime( end ) );
453 ev.setTimeZone( "UTC"); // make sure it is really utc 459 ev.setTimeZone( "UTC"); // make sure it is really utc
454 }else { 460 }else {
455 /* to current date time */ 461 /* to current date time */
456 // qWarning(" Start is %d", start ); 462 // qWarning(" Start is %d", start );
457 OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); 463 OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() );
458 QDateTime date = zone.toDateTime( start ); 464 QDateTime date = zone.toDateTime( start );
459 qWarning(" Start is %s", date.toString().latin1() ); 465 qWarning(" Start is %s", date.toString().latin1() );
460 ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); 466 ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) );
461 467
462 date = zone.toDateTime( end ); 468 date = zone.toDateTime( end );
463 ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); 469 ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) );
464 } 470 }
465 if ( rec && rec->doesRecur() ) { 471 if ( rec && rec->doesRecur() ) {
466 OTimeZone utc = OTimeZone::utc(); 472 OTimeZone utc = OTimeZone::utc();
467 ORecur recu( *rec ); // call copy c'tor; 473 ORecur recu( *rec ); // call copy c'tor;
468 recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); 474 recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() );
469 recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); 475 recu.setCreatedDateTime( utc.fromUTCDateTime( created ) );
470 recu.setStart( ev.startDateTime().date() ); 476 recu.setStart( ev.startDateTime().date() );
471 ev.setRecurrence( recu ); 477 ev.setRecurrence( recu );
472 } 478 }
473 479
474 if (alarmTime != -1 ) { 480 if (alarmTime != -1 ) {
475 QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); 481 QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 );
476 OPimAlarm al( snd , dt ); 482 OPimAlarm al( snd , dt );
477 ev.notifiers().add( al ); 483 ev.notifiers().add( al );
478 } 484 }
479 if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { 485 if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) {
480 qWarning("already contains assign uid"); 486 qWarning("already contains assign uid");
481 ev.setUid( 1 ); 487 ev.setUid( 1 );
482 } 488 }
483 qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); 489 qWarning("addind %d %s", ev.uid(), ev.description().latin1() );
484 if ( ev.hasRecurrence() ) 490 if ( ev.hasRecurrence() )
485 m_rep.insert( ev.uid(), ev ); 491 m_rep.insert( ev.uid(), ev );
486 else 492 else
487 m_raw.insert( ev.uid(), ev ); 493 m_raw.insert( ev.uid(), ev );
488 494
489} 495}
490void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { 496void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) {
491// qWarning(" setting %s", value.latin1() ); 497// qWarning(" setting %s", value.latin1() );
492 switch( id ) { 498 switch( id ) {
493 case FDescription: 499 case FDescription:
494 e.setDescription( value ); 500 e.setDescription( value );
495 break; 501 break;
496 case FLocation: 502 case FLocation:
497 e.setLocation( value ); 503 e.setLocation( value );
498 break; 504 break;
499 case FCategories: 505 case FCategories:
500 e.setCategories( e.idsFromString( value ) ); 506 e.setCategories( e.idsFromString( value ) );
501 break; 507 break;
502 case FUid: 508 case FUid:
503 e.setUid( value.toInt() ); 509 e.setUid( value.toInt() );
504 break; 510 break;
505 case FType: 511 case FType:
506 if ( value == "AllDay" ) { 512 if ( value == "AllDay" ) {
507 e.setAllDay( true ); 513 e.setAllDay( true );
508 e.setTimeZone( "UTC" ); 514 e.setTimeZone( "UTC" );
509 } 515 }
510 break; 516 break;
511 case FAlarm: 517 case FAlarm:
512 alarmTime = value.toInt(); 518 alarmTime = value.toInt();
513 break; 519 break;
514 case FSound: 520 case FSound:
515 snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; 521 snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent;
516 break; 522 break;
517 // recurrence stuff 523 // recurrence stuff
518 case FRType: 524 case FRType:
519 if ( value == "Daily" ) 525 if ( value == "Daily" )
520 recur()->setType( ORecur::Daily ); 526 recur()->setType( ORecur::Daily );
521 else if ( value == "Weekly" ) 527 else if ( value == "Weekly" )
522 recur()->setType( ORecur::Weekly); 528 recur()->setType( ORecur::Weekly);
523 else if ( value == "MonthlyDay" ) 529 else if ( value == "MonthlyDay" )
524 recur()->setType( ORecur::MonthlyDay ); 530 recur()->setType( ORecur::MonthlyDay );
525 else if ( value == "MonthlyDate" ) 531 else if ( value == "MonthlyDate" )
526 recur()->setType( ORecur::MonthlyDate ); 532 recur()->setType( ORecur::MonthlyDate );
527 else if ( value == "Yearly" ) 533 else if ( value == "Yearly" )
528 recur()->setType( ORecur::Yearly ); 534 recur()->setType( ORecur::Yearly );
529 else 535 else
530 recur()->setType( ORecur::NoRepeat ); 536 recur()->setType( ORecur::NoRepeat );
531 break; 537 break;
532 case FRWeekdays: 538 case FRWeekdays:
533 recur()->setDays( value.toInt() ); 539 recur()->setDays( value.toInt() );
534 break; 540 break;
535 case FRPosition: 541 case FRPosition:
536 recur()->setPosition( value.toInt() ); 542 recur()->setPosition( value.toInt() );
537 break; 543 break;
538 case FRFreq: 544 case FRFreq:
539 recur()->setFrequency( value.toInt() ); 545 recur()->setFrequency( value.toInt() );
540 break; 546 break;
541 case FRHasEndDate: 547 case FRHasEndDate:
542 recur()->setHasEndDate( value.toInt() ); 548 recur()->setHasEndDate( value.toInt() );