author | zecke <zecke> | 2004-07-17 17:33:39 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-07-17 17:33:39 (UTC) |
commit | b822cb8e0f2b1adc970eee9e40935adaf530e41b (patch) (unidiff) | |
tree | f42fe5d6144df85b35a7e1c8d008f28ca2532b1f | |
parent | 0637a8d3c60bf4da6efb6c26edecfe613919c623 (diff) | |
download | opie-b822cb8e0f2b1adc970eee9e40935adaf530e41b.zip opie-b822cb8e0f2b1adc970eee9e40935adaf530e41b.tar.gz opie-b822cb8e0f2b1adc970eee9e40935adaf530e41b.tar.bz2 |
Allow the deletions of all events
This is the fix posted to the MailingList
-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 | |||
@@ -183,257 +183,257 @@ namespace { | |||
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 = |