-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp index 2ff36e3..107c178 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | |||
@@ -55,513 +55,513 @@ | |||
55 | 55 | ||
56 | #include <unistd.h> | 56 | #include <unistd.h> |
57 | 57 | ||
58 | 58 | ||
59 | using namespace Opie; | 59 | using namespace Opie; |
60 | 60 | ||
61 | namespace { | 61 | namespace { |
62 | // FROM TT again | 62 | // FROM TT again |
63 | 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) |
64 | { | 64 | { |
65 | char needleChar; | 65 | char needleChar; |
66 | char haystackChar; | 66 | char haystackChar; |
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 | ||
88 | namespace { | 88 | namespace { |
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 | 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 | inline 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 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; | 130 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; |
131 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; | 131 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; |
132 | 132 | ||
133 | if (ev.isAllDay() ) | 133 | if (ev.isAllDay() ) |
134 | buf += " type=\"AllDay\""; // is that all ?? (eilers) | 134 | buf += " type=\"AllDay\""; // is that all ?? (eilers) |
135 | 135 | ||
136 | if (ev.hasNotifiers() ) { | 136 | if (ev.hasNotifiers() ) { |
137 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first | 137 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first |
138 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; | 138 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; |
139 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; | 139 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; |
140 | if ( alarm.sound() == OPimAlarm::Loud ) | 140 | if ( alarm.sound() == OPimAlarm::Loud ) |
141 | buf += "loud"; | 141 | buf += "loud"; |
142 | else | 142 | else |
143 | buf += "silent"; | 143 | buf += "silent"; |
144 | buf += "\""; | 144 | buf += "\""; |
145 | } | 145 | } |
146 | if ( ev.hasRecurrence() ) { | 146 | if ( ev.hasRecurrence() ) { |
147 | buf += ev.recurrence().toString(); | 147 | buf += ev.recurrence().toString(); |
148 | } | 148 | } |
149 | 149 | ||
150 | /* | 150 | /* |
151 | * fscking timezones :) well, we'll first convert | 151 | * fscking timezones :) well, we'll first convert |
152 | * the QDateTime to a QDateTime in UTC time | 152 | * the QDateTime to a QDateTime in UTC time |
153 | * and then we'll create a nice time_t | 153 | * and then we'll create a nice time_t |
154 | */ | 154 | */ |
155 | OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() ); | 155 | OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() ); |
156 | 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() ) ) ) + "\""; |
157 | 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() ) ) ) + "\""; |
158 | if (!ev.note().isEmpty() ) { | 158 | if (!ev.note().isEmpty() ) { |
159 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; | 159 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; |
160 | } | 160 | } |
161 | 161 | ||
162 | buf += " timezone=\""; | 162 | buf += " timezone=\""; |
163 | if ( ev.timeZone().isEmpty() ) | 163 | if ( ev.timeZone().isEmpty() ) |
164 | buf += "None"; | 164 | buf += "None"; |
165 | else | 165 | else |
166 | buf += ev.timeZone(); | 166 | buf += ev.timeZone(); |
167 | buf += "\""; | 167 | buf += "\""; |
168 | 168 | ||
169 | if (ev.parent() != 0 ) { | 169 | if (ev.parent() != 0 ) { |
170 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; | 170 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; |
171 | } | 171 | } |
172 | 172 | ||
173 | if (ev.children().count() != 0 ) { | 173 | if (ev.children().count() != 0 ) { |
174 | QArray<int> children = ev.children(); | 174 | QArray<int> children = ev.children(); |
175 | buf += " recchildren=\""; | 175 | buf += " recchildren=\""; |
176 | for ( uint i = 0; i < children.count(); i++ ) { | 176 | for ( uint i = 0; i < children.count(); i++ ) { |
177 | if ( i != 0 ) buf += " "; | 177 | if ( i != 0 ) buf += " "; |
178 | buf += QString::number( children[i] ); | 178 | buf += QString::number( children[i] ); |
179 | } | 179 | } |
180 | buf+= "\""; | 180 | buf+= "\""; |
181 | } | 181 | } |
182 | 182 | ||
183 | // skip custom writing | 183 | // skip custom writing |
184 | } | 184 | } |
185 | 185 | ||
186 | inline bool forAll( const QMap<int, OPimEvent>& list, QFile& file ) { | 186 | inline bool forAll( const QMap<int, OPimEvent>& list, QFile& file ) { |
187 | QMap<int, OPimEvent>::ConstIterator it; | 187 | QMap<int, OPimEvent>::ConstIterator it; |
188 | QString buf; | 188 | QString buf; |
189 | QCString str; | 189 | QCString str; |
190 | int total_written; | 190 | int total_written; |
191 | for ( it = list.begin(); it != list.end(); ++it ) { | 191 | for ( it = list.begin(); it != list.end(); ++it ) { |
192 | buf = "<event"; | 192 | buf = "<event"; |
193 | save( it.data(), buf ); | 193 | save( it.data(), buf ); |
194 | buf += " />\n"; | 194 | buf += " />\n"; |
195 | str = buf.utf8(); | 195 | str = buf.utf8(); |
196 | 196 | ||
197 | total_written = file.writeBlock(str.data(), str.length() ); | 197 | total_written = file.writeBlock(str.data(), str.length() ); |
198 | if ( total_written != int(str.length() ) ) | 198 | if ( total_written != int(str.length() ) ) |
199 | return false; | 199 | return false; |
200 | } | 200 | } |
201 | return true; | 201 | return true; |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | namespace Opie { | 205 | namespace Opie { |
206 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , | 206 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , |
207 | const QString& fileName ) | 207 | const QString& fileName ) |
208 | : ODateBookAccessBackend() { | 208 | : ODateBookAccessBackend() { |
209 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; | 209 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; |
210 | m_changed = false; | 210 | m_changed = false; |
211 | } | 211 | } |
212 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { | 212 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { |
213 | } | 213 | } |
214 | bool ODateBookAccessBackend_XML::load() { | 214 | bool ODateBookAccessBackend_XML::load() { |
215 | return loadFile(); | 215 | return loadFile(); |
216 | } | 216 | } |
217 | bool ODateBookAccessBackend_XML::reload() { | 217 | bool ODateBookAccessBackend_XML::reload() { |
218 | clear(); | 218 | clear(); |
219 | return load(); | 219 | return load(); |
220 | } | 220 | } |
221 | bool ODateBookAccessBackend_XML::save() { | 221 | bool ODateBookAccessBackend_XML::save() { |
222 | if (!m_changed) return true; | 222 | if (!m_changed) return true; |
223 | 223 | ||
224 | int total_written; | 224 | int total_written; |
225 | QString strFileNew = m_name + ".new"; | 225 | QString strFileNew = m_name + ".new"; |
226 | 226 | ||
227 | QFile f( strFileNew ); | 227 | QFile f( strFileNew ); |
228 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; | 228 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; |
229 | 229 | ||
230 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); | 230 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
231 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; | 231 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; |
232 | buf += "<events>\n"; | 232 | buf += "<events>\n"; |
233 | QCString str = buf.utf8(); | 233 | QCString str = buf.utf8(); |
234 | total_written = f.writeBlock( str.data(), str.length() ); | 234 | total_written = f.writeBlock( str.data(), str.length() ); |
235 | if ( total_written != int(str.length() ) ) { | 235 | if ( total_written != int(str.length() ) ) { |
236 | f.close(); | 236 | f.close(); |
237 | QFile::remove( strFileNew ); | 237 | QFile::remove( strFileNew ); |
238 | return false; | 238 | return false; |
239 | } | 239 | } |
240 | 240 | ||
241 | if (!forAll( m_raw, f ) ) { | 241 | if (!forAll( m_raw, f ) ) { |
242 | f.close(); | 242 | f.close(); |
243 | QFile::remove( strFileNew ); | 243 | QFile::remove( strFileNew ); |
244 | return false; | 244 | return false; |
245 | } | 245 | } |
246 | if (!forAll( m_rep, f ) ) { | 246 | if (!forAll( m_rep, f ) ) { |
247 | f.close(); | 247 | f.close(); |
248 | QFile::remove( strFileNew ); | 248 | QFile::remove( strFileNew ); |
249 | return false; | 249 | return false; |
250 | } | 250 | } |
251 | 251 | ||
252 | buf = "</events>\n</DATEBOOK>\n"; | 252 | buf = "</events>\n</DATEBOOK>\n"; |
253 | str = buf.utf8(); | 253 | str = buf.utf8(); |
254 | total_written = f.writeBlock( str.data(), str.length() ); | 254 | total_written = f.writeBlock( str.data(), str.length() ); |
255 | if ( total_written != int(str.length() ) ) { | 255 | if ( total_written != int(str.length() ) ) { |
256 | f.close(); | 256 | f.close(); |
257 | QFile::remove( strFileNew ); | 257 | QFile::remove( strFileNew ); |
258 | return false; | 258 | return false; |
259 | } | 259 | } |
260 | f.close(); | 260 | f.close(); |
261 | 261 | ||
262 | if ( ::rename( strFileNew, m_name ) < 0 ) { | 262 | if ( ::rename( strFileNew, m_name ) < 0 ) { |
263 | QFile::remove( strFileNew ); | 263 | QFile::remove( strFileNew ); |
264 | return false; | 264 | return false; |
265 | } | 265 | } |
266 | 266 | ||
267 | m_changed = false; | 267 | m_changed = false; |
268 | return true; | 268 | return true; |
269 | } | 269 | } |
270 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { | 270 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { |
271 | QArray<int> ints( m_raw.count()+ m_rep.count() ); | 271 | QArray<int> ints( m_raw.count()+ m_rep.count() ); |
272 | uint i = 0; | 272 | uint i = 0; |
273 | QMap<int, OPimEvent>::ConstIterator it; | 273 | QMap<int, OPimEvent>::ConstIterator it; |
274 | 274 | ||
275 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 275 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
276 | ints[i] = it.key(); | 276 | ints[i] = it.key(); |
277 | i++; | 277 | i++; |
278 | } | 278 | } |
279 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 279 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
280 | ints[i] = it.key(); | 280 | ints[i] = it.key(); |
281 | i++; | 281 | i++; |
282 | } | 282 | } |
283 | 283 | ||
284 | return ints; | 284 | return ints; |
285 | } | 285 | } |
286 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OPimEvent&, int, const QDateTime& ) { | 286 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OPimEvent&, int, const QDateTime& ) { |
287 | return QArray<int>(); | 287 | return QArray<int>(); |
288 | } | 288 | } |
289 | void ODateBookAccessBackend_XML::clear() { | 289 | void ODateBookAccessBackend_XML::clear() { |
290 | m_changed = true; | 290 | m_changed = true; |
291 | m_raw.clear(); | 291 | m_raw.clear(); |
292 | m_rep.clear(); | 292 | m_rep.clear(); |
293 | } | 293 | } |
294 | OPimEvent ODateBookAccessBackend_XML::find( int uid ) const{ | 294 | OPimEvent ODateBookAccessBackend_XML::find( int uid ) const{ |
295 | if ( m_raw.contains( uid ) ) | 295 | if ( m_raw.contains( uid ) ) |
296 | return m_raw[uid]; | 296 | return m_raw[uid]; |
297 | else | 297 | else |
298 | return m_rep[uid]; | 298 | return m_rep[uid]; |
299 | } | 299 | } |
300 | bool ODateBookAccessBackend_XML::add( const OPimEvent& ev ) { | 300 | bool ODateBookAccessBackend_XML::add( const OPimEvent& ev ) { |
301 | m_changed = true; | 301 | m_changed = true; |
302 | if (ev.hasRecurrence() ) | 302 | if (ev.hasRecurrence() ) |
303 | m_rep.insert( ev.uid(), ev ); | 303 | m_rep.insert( ev.uid(), ev ); |
304 | else | 304 | else |
305 | m_raw.insert( ev.uid(), ev ); | 305 | m_raw.insert( ev.uid(), ev ); |
306 | 306 | ||
307 | return true; | 307 | return true; |
308 | } | 308 | } |
309 | bool ODateBookAccessBackend_XML::remove( int uid ) { | 309 | bool ODateBookAccessBackend_XML::remove( int uid ) { |
310 | m_changed = true; | 310 | m_changed = true; |
311 | m_rep.remove( uid ); | 311 | m_raw.remove( uid ); |
312 | m_rep.remove( uid ); | 312 | m_rep.remove( uid ); |
313 | 313 | ||
314 | return true; | 314 | return true; |
315 | } | 315 | } |
316 | bool ODateBookAccessBackend_XML::replace( const OPimEvent& ev ) { | 316 | bool ODateBookAccessBackend_XML::replace( const OPimEvent& ev ) { |
317 | replace( ev.uid() ); // ??? Shouldn't this be "remove( ev.uid() ) ??? (eilers) | 317 | replace( ev.uid() ); // ??? Shouldn't this be "remove( ev.uid() ) ??? (eilers) |
318 | return add( ev ); | 318 | return add( ev ); |
319 | } | 319 | } |
320 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { | 320 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { |
321 | return allRecords(); | 321 | return allRecords(); |
322 | } | 322 | } |
323 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { | 323 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { |
324 | QArray<int> ints( m_rep.count() ); | 324 | QArray<int> ints( m_rep.count() ); |
325 | uint i = 0; | 325 | uint i = 0; |
326 | QMap<int, OPimEvent>::ConstIterator it; | 326 | QMap<int, OPimEvent>::ConstIterator it; |
327 | 327 | ||
328 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 328 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
329 | ints[i] = it.key(); | 329 | ints[i] = it.key(); |
330 | i++; | 330 | i++; |
331 | } | 331 | } |
332 | 332 | ||
333 | return ints; | 333 | return ints; |
334 | } | 334 | } |
335 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { | 335 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { |
336 | QArray<int> ints( m_raw.count() ); | 336 | QArray<int> ints( m_raw.count() ); |
337 | uint i = 0; | 337 | uint i = 0; |
338 | QMap<int, OPimEvent>::ConstIterator it; | 338 | QMap<int, OPimEvent>::ConstIterator it; |
339 | 339 | ||
340 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 340 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
341 | ints[i] = it.key(); | 341 | ints[i] = it.key(); |
342 | i++; | 342 | i++; |
343 | } | 343 | } |
344 | 344 | ||
345 | return ints; | 345 | return ints; |
346 | } | 346 | } |
347 | OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { | 347 | OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { |
348 | OPimEvent::ValueList list; | 348 | OPimEvent::ValueList list; |
349 | QMap<int, OPimEvent>::ConstIterator it; | 349 | QMap<int, OPimEvent>::ConstIterator it; |
350 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) | 350 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) |
351 | list.append( it.data() ); | 351 | list.append( it.data() ); |
352 | 352 | ||
353 | return list; | 353 | return list; |
354 | } | 354 | } |
355 | OPimEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { | 355 | OPimEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { |
356 | OPimEvent::ValueList list; | 356 | OPimEvent::ValueList list; |
357 | QMap<int, OPimEvent>::ConstIterator it; | 357 | QMap<int, OPimEvent>::ConstIterator it; |
358 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) | 358 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) |
359 | list.append( it.data() ); | 359 | list.append( it.data() ); |
360 | 360 | ||
361 | return list; | 361 | return list; |
362 | } | 362 | } |
363 | 363 | ||
364 | // FIXME: Use OPimEvent::fromMap() (eilers) | 364 | // FIXME: Use OPimEvent::fromMap() (eilers) |
365 | bool ODateBookAccessBackend_XML::loadFile() { | 365 | bool ODateBookAccessBackend_XML::loadFile() { |
366 | m_changed = false; | 366 | m_changed = false; |
367 | 367 | ||
368 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); | 368 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); |
369 | if ( fd < 0 ) return false; | 369 | if ( fd < 0 ) return false; |
370 | 370 | ||
371 | struct stat attribute; | 371 | struct stat attribute; |
372 | if ( ::fstat(fd, &attribute ) == -1 ) { | 372 | if ( ::fstat(fd, &attribute ) == -1 ) { |
373 | ::close( fd ); | 373 | ::close( fd ); |
374 | return false; | 374 | return false; |
375 | } | 375 | } |
376 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | 376 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); |
377 | if ( map_addr == ( (caddr_t)-1) ) { | 377 | if ( map_addr == ( (caddr_t)-1) ) { |
378 | ::close( fd ); | 378 | ::close( fd ); |
379 | return false; | 379 | return false; |
380 | } | 380 | } |
381 | 381 | ||
382 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); | 382 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); |
383 | ::close( fd ); | 383 | ::close( fd ); |
384 | 384 | ||
385 | QAsciiDict<int> dict(FExceptions+1); | 385 | QAsciiDict<int> dict(FExceptions+1); |
386 | dict.setAutoDelete( true ); | 386 | dict.setAutoDelete( true ); |
387 | dict.insert( "description", new int(FDescription) ); | 387 | dict.insert( "description", new int(FDescription) ); |
388 | dict.insert( "location", new int(FLocation) ); | 388 | dict.insert( "location", new int(FLocation) ); |
389 | dict.insert( "categories", new int(FCategories) ); | 389 | dict.insert( "categories", new int(FCategories) ); |
390 | dict.insert( "uid", new int(FUid) ); | 390 | dict.insert( "uid", new int(FUid) ); |
391 | dict.insert( "type", new int(FType) ); | 391 | dict.insert( "type", new int(FType) ); |
392 | dict.insert( "alarm", new int(FAlarm) ); | 392 | dict.insert( "alarm", new int(FAlarm) ); |
393 | dict.insert( "sound", new int(FSound) ); | 393 | dict.insert( "sound", new int(FSound) ); |
394 | dict.insert( "rtype", new int(FRType) ); | 394 | dict.insert( "rtype", new int(FRType) ); |
395 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 395 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
396 | dict.insert( "rposition", new int(FRPosition) ); | 396 | dict.insert( "rposition", new int(FRPosition) ); |
397 | dict.insert( "rfreq", new int(FRFreq) ); | 397 | dict.insert( "rfreq", new int(FRFreq) ); |
398 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); | 398 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); |
399 | dict.insert( "enddt", new int(FREndDate) ); | 399 | dict.insert( "enddt", new int(FREndDate) ); |
400 | dict.insert( "start", new int(FRStart) ); | 400 | dict.insert( "start", new int(FRStart) ); |
401 | dict.insert( "end", new int(FREnd) ); | 401 | dict.insert( "end", new int(FREnd) ); |
402 | dict.insert( "note", new int(FNote) ); | 402 | dict.insert( "note", new int(FNote) ); |
403 | dict.insert( "created", new int(FCreated) ); // Shouldn't this be FRCreated ?? | 403 | dict.insert( "created", new int(FCreated) ); // Shouldn't this be FRCreated ?? |
404 | dict.insert( "recparent", new int(FRecParent) ); | 404 | dict.insert( "recparent", new int(FRecParent) ); |
405 | dict.insert( "recchildren", new int(FRecChildren) ); | 405 | dict.insert( "recchildren", new int(FRecChildren) ); |
406 | dict.insert( "exceptions", new int(FExceptions) ); | 406 | dict.insert( "exceptions", new int(FExceptions) ); |
407 | dict.insert( "timezone", new int(FTimeZone) ); | 407 | dict.insert( "timezone", new int(FTimeZone) ); |
408 | 408 | ||
409 | char* dt = (char*)map_addr; | 409 | char* dt = (char*)map_addr; |
410 | int len = attribute.st_size; | 410 | int len = attribute.st_size; |
411 | int i = 0; | 411 | int i = 0; |
412 | char* point; | 412 | char* point; |
413 | const char* collectionString = "<event "; | 413 | const char* collectionString = "<event "; |
414 | int strLen = ::strlen(collectionString); | 414 | int strLen = ::strlen(collectionString); |
415 | int *find; | 415 | int *find; |
416 | while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { | 416 | while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { |
417 | i = point -dt; | 417 | i = point -dt; |
418 | i+= strLen; | 418 | i+= strLen; |
419 | 419 | ||
420 | alarmTime = -1; | 420 | alarmTime = -1; |
421 | snd = 0; // silent | 421 | snd = 0; // silent |
422 | 422 | ||
423 | OPimEvent ev; | 423 | OPimEvent ev; |
424 | rec = 0; | 424 | rec = 0; |
425 | 425 | ||
426 | while ( TRUE ) { | 426 | while ( TRUE ) { |
427 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 427 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
428 | ++i; | 428 | ++i; |
429 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 429 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
430 | break; | 430 | break; |
431 | 431 | ||
432 | 432 | ||
433 | // we have another attribute, read it. | 433 | // we have another attribute, read it. |
434 | int j = i; | 434 | int j = i; |
435 | while ( j < len && dt[j] != '=' ) | 435 | while ( j < len && dt[j] != '=' ) |
436 | ++j; | 436 | ++j; |
437 | QCString attr( dt+i, j-i+1); | 437 | QCString attr( dt+i, j-i+1); |
438 | 438 | ||
439 | i = ++j; // skip = | 439 | i = ++j; // skip = |
440 | 440 | ||
441 | // find the start of quotes | 441 | // find the start of quotes |
442 | while ( i < len && dt[i] != '"' ) | 442 | while ( i < len && dt[i] != '"' ) |
443 | ++i; | 443 | ++i; |
444 | j = ++i; | 444 | j = ++i; |
445 | 445 | ||
446 | bool haveUtf = FALSE; | 446 | bool haveUtf = FALSE; |
447 | bool haveEnt = FALSE; | 447 | bool haveEnt = FALSE; |
448 | while ( j < len && dt[j] != '"' ) { | 448 | while ( j < len && dt[j] != '"' ) { |
449 | if ( ((unsigned char)dt[j]) > 0x7f ) | 449 | if ( ((unsigned char)dt[j]) > 0x7f ) |
450 | haveUtf = TRUE; | 450 | haveUtf = TRUE; |
451 | if ( dt[j] == '&' ) | 451 | if ( dt[j] == '&' ) |
452 | haveEnt = TRUE; | 452 | haveEnt = TRUE; |
453 | ++j; | 453 | ++j; |
454 | } | 454 | } |
455 | if ( i == j ) { | 455 | if ( i == j ) { |
456 | // empty value | 456 | // empty value |
457 | i = j + 1; | 457 | i = j + 1; |
458 | continue; | 458 | continue; |
459 | } | 459 | } |
460 | 460 | ||
461 | QCString value( dt+i, j-i+1 ); | 461 | QCString value( dt+i, j-i+1 ); |
462 | i = j + 1; | 462 | i = j + 1; |
463 | 463 | ||
464 | QString str = (haveUtf ? QString::fromUtf8( value ) | 464 | QString str = (haveUtf ? QString::fromUtf8( value ) |
465 | : QString::fromLatin1( value ) ); | 465 | : QString::fromLatin1( value ) ); |
466 | if ( haveEnt ) | 466 | if ( haveEnt ) |
467 | str = Qtopia::plainString( str ); | 467 | str = Qtopia::plainString( str ); |
468 | 468 | ||
469 | /* | 469 | /* |
470 | * add key + value | 470 | * add key + value |
471 | */ | 471 | */ |
472 | find = dict[attr.data()]; | 472 | find = dict[attr.data()]; |
473 | if (!find) | 473 | if (!find) |
474 | ev.setCustomField( attr, str ); | 474 | ev.setCustomField( attr, str ); |
475 | else { | 475 | else { |
476 | setField( ev, *find, str ); | 476 | setField( ev, *find, str ); |
477 | } | 477 | } |
478 | } | 478 | } |
479 | /* time to finalize */ | 479 | /* time to finalize */ |
480 | finalizeRecord( ev ); | 480 | finalizeRecord( ev ); |
481 | delete rec; | 481 | delete rec; |
482 | } | 482 | } |
483 | ::munmap(map_addr, attribute.st_size ); | 483 | ::munmap(map_addr, attribute.st_size ); |
484 | m_changed = false; // changed during add | 484 | m_changed = false; // changed during add |
485 | 485 | ||
486 | return true; | 486 | return true; |
487 | } | 487 | } |
488 | 488 | ||
489 | // FIXME: Use OPimEvent::fromMap() which makes this obsolete.. (eilers) | 489 | // FIXME: Use OPimEvent::fromMap() which makes this obsolete.. (eilers) |
490 | void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { | 490 | void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { |
491 | /* AllDay is alway in UTC */ | 491 | /* AllDay is alway in UTC */ |
492 | if ( ev.isAllDay() ) { | 492 | if ( ev.isAllDay() ) { |
493 | OPimTimeZone utc = OPimTimeZone::utc(); | 493 | OPimTimeZone utc = OPimTimeZone::utc(); |
494 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); | 494 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); |
495 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); | 495 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); |
496 | ev.setTimeZone( "UTC"); // make sure it is really utc | 496 | ev.setTimeZone( "UTC"); // make sure it is really utc |
497 | }else { | 497 | }else { |
498 | /* to current date time */ | 498 | /* to current date time */ |
499 | // owarn << " Start is " << start << "" << oendl; | 499 | // owarn << " Start is " << start << "" << oendl; |
500 | OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() ); | 500 | OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() ); |
501 | QDateTime date = zone.toDateTime( start ); | 501 | QDateTime date = zone.toDateTime( start ); |
502 | owarn << " Start is " << date.toString() << "" << oendl; | 502 | owarn << " Start is " << date.toString() << "" << oendl; |
503 | ev.setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); | 503 | ev.setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); |
504 | 504 | ||
505 | date = zone.toDateTime( end ); | 505 | date = zone.toDateTime( end ); |
506 | ev.setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); | 506 | ev.setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); |
507 | } | 507 | } |
508 | if ( rec && rec->doesRecur() ) { | 508 | if ( rec && rec->doesRecur() ) { |
509 | OPimTimeZone utc = OPimTimeZone::utc(); | 509 | OPimTimeZone utc = OPimTimeZone::utc(); |
510 | OPimRecurrence recu( *rec ); // call copy c'tor; | 510 | OPimRecurrence recu( *rec ); // call copy c'tor; |
511 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); | 511 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); |
512 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); | 512 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); |
513 | recu.setStart( ev.startDateTime().date() ); | 513 | recu.setStart( ev.startDateTime().date() ); |
514 | ev.setRecurrence( recu ); | 514 | ev.setRecurrence( recu ); |
515 | } | 515 | } |
516 | 516 | ||
517 | if (alarmTime != -1 ) { | 517 | if (alarmTime != -1 ) { |
518 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); | 518 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); |
519 | OPimAlarm al( snd , dt ); | 519 | OPimAlarm al( snd , dt ); |
520 | ev.notifiers().add( al ); | 520 | ev.notifiers().add( al ); |
521 | } | 521 | } |
522 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { | 522 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { |
523 | owarn << "already contains assign uid" << oendl; | 523 | owarn << "already contains assign uid" << oendl; |
524 | ev.setUid( 1 ); | 524 | ev.setUid( 1 ); |
525 | } | 525 | } |
526 | owarn << "addind " << ev.uid() << " " << ev.description() << "" << oendl; | 526 | owarn << "addind " << ev.uid() << " " << ev.description() << "" << oendl; |
527 | if ( ev.hasRecurrence() ) | 527 | if ( ev.hasRecurrence() ) |
528 | m_rep.insert( ev.uid(), ev ); | 528 | m_rep.insert( ev.uid(), ev ); |
529 | else | 529 | else |
530 | m_raw.insert( ev.uid(), ev ); | 530 | m_raw.insert( ev.uid(), ev ); |
531 | 531 | ||
532 | } | 532 | } |
533 | void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) { | 533 | void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) { |
534 | // owarn << " setting " << value << "" << oendl; | 534 | // owarn << " setting " << value << "" << oendl; |
535 | switch( id ) { | 535 | switch( id ) { |
536 | case FDescription: | 536 | case FDescription: |
537 | e.setDescription( value ); | 537 | e.setDescription( value ); |
538 | break; | 538 | break; |
539 | case FLocation: | 539 | case FLocation: |
540 | e.setLocation( value ); | 540 | e.setLocation( value ); |
541 | break; | 541 | break; |
542 | case FCategories: | 542 | case FCategories: |
543 | e.setCategories( e.idsFromString( value ) ); | 543 | e.setCategories( e.idsFromString( value ) ); |
544 | break; | 544 | break; |
545 | case FUid: | 545 | case FUid: |
546 | e.setUid( value.toInt() ); | 546 | e.setUid( value.toInt() ); |
547 | break; | 547 | break; |
548 | case FType: | 548 | case FType: |
549 | if ( value == "AllDay" ) { | 549 | if ( value == "AllDay" ) { |
550 | e.setAllDay( true ); | 550 | e.setAllDay( true ); |
551 | e.setTimeZone( "UTC" ); | 551 | e.setTimeZone( "UTC" ); |
552 | } | 552 | } |
553 | break; | 553 | break; |
554 | case FAlarm: | 554 | case FAlarm: |
555 | alarmTime = value.toInt(); | 555 | alarmTime = value.toInt(); |
556 | break; | 556 | break; |
557 | case FSound: | 557 | case FSound: |
558 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; | 558 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; |
559 | break; | 559 | break; |
560 | // recurrence stuff | 560 | // recurrence stuff |
561 | case FRType: | 561 | case FRType: |
562 | if ( value == "Daily" ) | 562 | if ( value == "Daily" ) |
563 | recur()->setType( OPimRecurrence::Daily ); | 563 | recur()->setType( OPimRecurrence::Daily ); |
564 | else if ( value == "Weekly" ) | 564 | else if ( value == "Weekly" ) |
565 | recur()->setType( OPimRecurrence::Weekly); | 565 | recur()->setType( OPimRecurrence::Weekly); |
566 | else if ( value == "MonthlyDay" ) | 566 | else if ( value == "MonthlyDay" ) |
567 | recur()->setType( OPimRecurrence::MonthlyDay ); | 567 | recur()->setType( OPimRecurrence::MonthlyDay ); |