-rw-r--r-- | libopie2/opiepim/backend/otodoaccessxml.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp index a8e1503..285d2b8 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.cpp +++ b/libopie2/opiepim/backend/otodoaccessxml.cpp | |||
@@ -1,66 +1,67 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <fcntl.h> | 2 | #include <fcntl.h> |
3 | 3 | ||
4 | #include <sys/mman.h> | 4 | #include <sys/mman.h> |
5 | #include <sys/stat.h> | 5 | #include <sys/stat.h> |
6 | #include <sys/types.h> | 6 | #include <sys/types.h> |
7 | 7 | ||
8 | #include <unistd.h> | 8 | #include <unistd.h> |
9 | 9 | ||
10 | 10 | ||
11 | #include <qfile.h> | 11 | #include <qfile.h> |
12 | #include <qvector.h> | 12 | #include <qvector.h> |
13 | 13 | ||
14 | #include <qpe/global.h> | 14 | #include <qpe/global.h> |
15 | #include <qpe/stringutil.h> | 15 | #include <qpe/stringutil.h> |
16 | #include <qpe/timeconversion.h> | 16 | #include <qpe/timeconversion.h> |
17 | 17 | ||
18 | #include "oconversion.h" | 18 | #include "oconversion.h" |
19 | #include "opimstate.h" | ||
19 | #include "otimezone.h" | 20 | #include "otimezone.h" |
20 | #include "orecur.h" | 21 | #include "orecur.h" |
21 | #include "otodoaccessxml.h" | 22 | #include "otodoaccessxml.h" |
22 | 23 | ||
23 | namespace { | 24 | namespace { |
24 | time_t rp_end; | 25 | time_t rp_end; |
25 | ORecur* rec; | 26 | ORecur* rec; |
26 | ORecur *recur() { | 27 | ORecur *recur() { |
27 | if (!rec ) rec = new ORecur; | 28 | if (!rec ) rec = new ORecur; |
28 | return rec; | 29 | return rec; |
29 | } | 30 | } |
30 | int snd; | 31 | int snd; |
31 | enum MoreAttributes { | 32 | enum MoreAttributes { |
32 | FRType = OTodo::CompletedDate + 2, | 33 | FRType = OTodo::CompletedDate + 2, |
33 | FRWeekdays, | 34 | FRWeekdays, |
34 | FRPosition, | 35 | FRPosition, |
35 | FRFreq, | 36 | FRFreq, |
36 | FRHasEndDate, | 37 | FRHasEndDate, |
37 | FREndDate, | 38 | FREndDate, |
38 | FRStart, | 39 | FRStart, |
39 | FREnd | 40 | FREnd |
40 | }; | 41 | }; |
41 | // FROM TT again | 42 | // FROM TT again |
42 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 43 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
43 | { | 44 | { |
44 | char needleChar; | 45 | char needleChar; |
45 | char haystackChar; | 46 | char haystackChar; |
46 | if (!needle || !haystack || !hLen || !nLen) | 47 | if (!needle || !haystack || !hLen || !nLen) |
47 | return 0; | 48 | return 0; |
48 | 49 | ||
49 | const char* hsearch = haystack; | 50 | const char* hsearch = haystack; |
50 | 51 | ||
51 | if ((needleChar = *needle++) != 0) { | 52 | if ((needleChar = *needle++) != 0) { |
52 | nLen--; //(to make up for needle++) | 53 | nLen--; //(to make up for needle++) |
53 | do { | 54 | do { |
54 | do { | 55 | do { |
55 | if ((haystackChar = *hsearch++) == 0) | 56 | if ((haystackChar = *hsearch++) == 0) |
56 | return (0); | 57 | return (0); |
57 | if (hsearch >= haystack + hLen) | 58 | if (hsearch >= haystack + hLen) |
58 | return (0); | 59 | return (0); |
59 | } while (haystackChar != needleChar); | 60 | } while (haystackChar != needleChar); |
60 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); | 61 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); |
61 | hsearch--; | 62 | hsearch--; |
62 | } | 63 | } |
63 | return ((char *)hsearch); | 64 | return ((char *)hsearch); |
64 | } | 65 | } |
65 | } | 66 | } |
66 | 67 | ||
@@ -377,189 +378,194 @@ void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, | |||
377 | 378 | ||
378 | find = (*dict)[ attr.data() ]; | 379 | find = (*dict)[ attr.data() ]; |
379 | if (!find ) { | 380 | if (!find ) { |
380 | // qWarning("Unknown option" + it.key() ); | 381 | // qWarning("Unknown option" + it.key() ); |
381 | ev.setCustomField( attr, val ); | 382 | ev.setCustomField( attr, val ); |
382 | return; | 383 | return; |
383 | } | 384 | } |
384 | 385 | ||
385 | switch( *find ) { | 386 | switch( *find ) { |
386 | case OTodo::Uid: | 387 | case OTodo::Uid: |
387 | ev.setUid( val.toInt() ); | 388 | ev.setUid( val.toInt() ); |
388 | break; | 389 | break; |
389 | case OTodo::Category: | 390 | case OTodo::Category: |
390 | ev.setCategories( ev.idsFromString( val ) ); | 391 | ev.setCategories( ev.idsFromString( val ) ); |
391 | break; | 392 | break; |
392 | case OTodo::HasDate: | 393 | case OTodo::HasDate: |
393 | ev.setHasDueDate( val.toInt() ); | 394 | ev.setHasDueDate( val.toInt() ); |
394 | break; | 395 | break; |
395 | case OTodo::Completed: | 396 | case OTodo::Completed: |
396 | ev.setCompleted( val.toInt() ); | 397 | ev.setCompleted( val.toInt() ); |
397 | break; | 398 | break; |
398 | case OTodo::Description: | 399 | case OTodo::Description: |
399 | ev.setDescription( val ); | 400 | ev.setDescription( val ); |
400 | break; | 401 | break; |
401 | case OTodo::Summary: | 402 | case OTodo::Summary: |
402 | ev.setSummary( val ); | 403 | ev.setSummary( val ); |
403 | break; | 404 | break; |
404 | case OTodo::Priority: | 405 | case OTodo::Priority: |
405 | ev.setPriority( val.toInt() ); | 406 | ev.setPriority( val.toInt() ); |
406 | break; | 407 | break; |
407 | case OTodo::DateDay: | 408 | case OTodo::DateDay: |
408 | m_day = val.toInt(); | 409 | m_day = val.toInt(); |
409 | break; | 410 | break; |
410 | case OTodo::DateMonth: | 411 | case OTodo::DateMonth: |
411 | m_month = val.toInt(); | 412 | m_month = val.toInt(); |
412 | break; | 413 | break; |
413 | case OTodo::DateYear: | 414 | case OTodo::DateYear: |
414 | m_year = val.toInt(); | 415 | m_year = val.toInt(); |
415 | break; | 416 | break; |
416 | case OTodo::Progress: | 417 | case OTodo::Progress: |
417 | ev.setProgress( val.toInt() ); | 418 | ev.setProgress( val.toInt() ); |
418 | break; | 419 | break; |
419 | case OTodo::CompletedDate: | 420 | case OTodo::CompletedDate: |
420 | ev.setCompletedDate( OConversion::dateFromString( val ) ); | 421 | ev.setCompletedDate( OConversion::dateFromString( val ) ); |
421 | break; | 422 | break; |
422 | case OTodo::StartDate: | 423 | case OTodo::StartDate: |
423 | ev.setStartDate( OConversion::dateFromString( val ) ); | 424 | ev.setStartDate( OConversion::dateFromString( val ) ); |
424 | break; | 425 | break; |
426 | case OTodo::State: | ||
427 | ev.setState( val.toInt() ); | ||
428 | break; | ||
425 | case OTodo::CrossReference: | 429 | case OTodo::CrossReference: |
426 | { | 430 | { |
427 | /* | 431 | /* |
428 | * A cross refernce looks like | 432 | * A cross refernce looks like |
429 | * appname,id;appname,id | 433 | * appname,id;appname,id |
430 | * we need to split it up | 434 | * we need to split it up |
431 | */ | 435 | */ |
432 | QStringList refs = QStringList::split(';', val ); | 436 | QStringList refs = QStringList::split(';', val ); |
433 | QStringList::Iterator strIt; | 437 | QStringList::Iterator strIt; |
434 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { | 438 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { |
435 | int pos = (*strIt).find(','); | 439 | int pos = (*strIt).find(','); |
436 | if ( pos > -1 ) | 440 | if ( pos > -1 ) |
437 | ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); | 441 | ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); |
438 | 442 | ||
439 | } | 443 | } |
440 | break; | 444 | break; |
441 | } | 445 | } |
442 | /* Recurrence stuff below + post processing later */ | 446 | /* Recurrence stuff below + post processing later */ |
443 | case FRType: | 447 | case FRType: |
444 | if ( val == "Daily" ) | 448 | if ( val == "Daily" ) |
445 | recur()->setType( ORecur::Daily ); | 449 | recur()->setType( ORecur::Daily ); |
446 | else if ( val == "Weekly" ) | 450 | else if ( val == "Weekly" ) |
447 | recur()->setType( ORecur::Weekly); | 451 | recur()->setType( ORecur::Weekly); |
448 | else if ( val == "MonthlyDay" ) | 452 | else if ( val == "MonthlyDay" ) |
449 | recur()->setType( ORecur::MonthlyDay ); | 453 | recur()->setType( ORecur::MonthlyDay ); |
450 | else if ( val == "MonthlyDate" ) | 454 | else if ( val == "MonthlyDate" ) |
451 | recur()->setType( ORecur::MonthlyDate ); | 455 | recur()->setType( ORecur::MonthlyDate ); |
452 | else if ( val == "Yearly" ) | 456 | else if ( val == "Yearly" ) |
453 | recur()->setType( ORecur::Yearly ); | 457 | recur()->setType( ORecur::Yearly ); |
454 | else | 458 | else |
455 | recur()->setType( ORecur::NoRepeat ); | 459 | recur()->setType( ORecur::NoRepeat ); |
456 | break; | 460 | break; |
457 | case FRWeekdays: | 461 | case FRWeekdays: |
458 | recur()->setDays( val.toInt() ); | 462 | recur()->setDays( val.toInt() ); |
459 | break; | 463 | break; |
460 | case FRPosition: | 464 | case FRPosition: |
461 | recur()->setPosition( val.toInt() ); | 465 | recur()->setPosition( val.toInt() ); |
462 | break; | 466 | break; |
463 | case FRFreq: | 467 | case FRFreq: |
464 | recur()->setFrequency( val.toInt() ); | 468 | recur()->setFrequency( val.toInt() ); |
465 | break; | 469 | break; |
466 | case FRHasEndDate: | 470 | case FRHasEndDate: |
467 | recur()->setHasEndDate( val.toInt() ); | 471 | recur()->setHasEndDate( val.toInt() ); |
468 | break; | 472 | break; |
469 | case FREndDate: { | 473 | case FREndDate: { |
470 | rp_end = (time_t) val.toLong(); | 474 | rp_end = (time_t) val.toLong(); |
471 | break; | 475 | break; |
472 | } | 476 | } |
473 | default: | 477 | default: |
474 | break; | 478 | break; |
475 | } | 479 | } |
476 | } | 480 | } |
477 | QString OTodoAccessXML::toString( const OTodo& ev )const { | 481 | QString OTodoAccessXML::toString( const OTodo& ev )const { |
478 | QString str; | 482 | QString str; |
479 | 483 | ||
480 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; | 484 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; |
481 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; | 485 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; |
482 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; | 486 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; |
483 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; | 487 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; |
484 | 488 | ||
485 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; | 489 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; |
486 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; | 490 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; |
487 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; | 491 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; |
488 | 492 | ||
489 | if ( ev.hasDueDate() ) { | 493 | if ( ev.hasDueDate() ) { |
490 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; | 494 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; |
491 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; | 495 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; |
492 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; | 496 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; |
493 | } | 497 | } |
494 | // qWarning( "Uid %d", ev.uid() ); | 498 | // qWarning( "Uid %d", ev.uid() ); |
495 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; | 499 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; |
496 | 500 | ||
497 | // append the extra options | 501 | // append the extra options |
498 | /* FIXME Qtopia::Record this is currently not | 502 | /* FIXME Qtopia::Record this is currently not |
499 | * possible you can set custom fields | 503 | * possible you can set custom fields |
500 | * but don' iterate over the list | 504 | * but don' iterate over the list |
501 | * I may do #define private protected | 505 | * I may do #define private protected |
502 | * for this case - cough --zecke | 506 | * for this case - cough --zecke |
503 | */ | 507 | */ |
504 | /* | 508 | /* |
505 | QMap<QString, QString> extras = ev.extras(); | 509 | QMap<QString, QString> extras = ev.extras(); |
506 | QMap<QString, QString>::Iterator extIt; | 510 | QMap<QString, QString>::Iterator extIt; |
507 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) | 511 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) |
508 | str += extIt.key() + "=\"" + extIt.data() + "\" "; | 512 | str += extIt.key() + "=\"" + extIt.data() + "\" "; |
509 | */ | 513 | */ |
510 | // cross refernce | 514 | // cross refernce |
511 | if ( ev.hasRecurrence() ) { | 515 | if ( ev.hasRecurrence() ) { |
512 | str += ev.recurrence().toString(); | 516 | str += ev.recurrence().toString(); |
513 | } | 517 | } |
514 | if ( ev.hasStartDate() ) | 518 | if ( ev.hasStartDate() ) |
515 | str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" "; | 519 | str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" "; |
516 | if ( ev.hasCompletedDate() ) | 520 | if ( ev.hasCompletedDate() ) |
517 | str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" "; | 521 | str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" "; |
522 | if ( ev.hasState() ) | ||
523 | str += "State=\""+QString::number( ev.state().state() )+"\" "; | ||
518 | 524 | ||
519 | 525 | ||
520 | return str; | 526 | return str; |
521 | } | 527 | } |
522 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { | 528 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { |
523 | return Qtopia::Record::idsToString( ints ); | 529 | return Qtopia::Record::idsToString( ints ); |
524 | } | 530 | } |
525 | 531 | ||
526 | /* internal class for sorting | 532 | /* internal class for sorting |
527 | * | 533 | * |
528 | * Inspired by todoxmlio.cpp from TT | 534 | * Inspired by todoxmlio.cpp from TT |
529 | */ | 535 | */ |
530 | 536 | ||
531 | struct OTodoXMLContainer { | 537 | struct OTodoXMLContainer { |
532 | OTodo todo; | 538 | OTodo todo; |
533 | }; | 539 | }; |
534 | 540 | ||
535 | namespace { | 541 | namespace { |
536 | inline QString string( const OTodo& todo) { | 542 | inline QString string( const OTodo& todo) { |
537 | return todo.summary().isEmpty() ? | 543 | return todo.summary().isEmpty() ? |
538 | todo.description().left(20 ) : | 544 | todo.description().left(20 ) : |
539 | todo.summary(); | 545 | todo.summary(); |
540 | } | 546 | } |
541 | inline int completed( const OTodo& todo1, const OTodo& todo2) { | 547 | inline int completed( const OTodo& todo1, const OTodo& todo2) { |
542 | int ret = 0; | 548 | int ret = 0; |
543 | if ( todo1.isCompleted() ) ret++; | 549 | if ( todo1.isCompleted() ) ret++; |
544 | if ( todo2.isCompleted() ) ret--; | 550 | if ( todo2.isCompleted() ) ret--; |
545 | return ret; | 551 | return ret; |
546 | } | 552 | } |
547 | inline int priority( const OTodo& t1, const OTodo& t2) { | 553 | inline int priority( const OTodo& t1, const OTodo& t2) { |
548 | return ( t1.priority() - t2.priority() ); | 554 | return ( t1.priority() - t2.priority() ); |
549 | } | 555 | } |
550 | inline int description( const OTodo& t1, const OTodo& t2) { | 556 | inline int description( const OTodo& t1, const OTodo& t2) { |
551 | return QString::compare( string(t1), string(t2) ); | 557 | return QString::compare( string(t1), string(t2) ); |
552 | } | 558 | } |
553 | inline int deadline( const OTodo& t1, const OTodo& t2) { | 559 | inline int deadline( const OTodo& t1, const OTodo& t2) { |
554 | int ret = 0; | 560 | int ret = 0; |
555 | if ( t1.hasDueDate() && | 561 | if ( t1.hasDueDate() && |
556 | t2.hasDueDate() ) | 562 | t2.hasDueDate() ) |
557 | ret = t2.dueDate().daysTo( t1.dueDate() ); | 563 | ret = t2.dueDate().daysTo( t1.dueDate() ); |
558 | else if ( t1.hasDueDate() ) | 564 | else if ( t1.hasDueDate() ) |
559 | ret = -1; | 565 | ret = -1; |
560 | else if ( t2.hasDueDate() ) | 566 | else if ( t2.hasDueDate() ) |
561 | ret = 1; | 567 | ret = 1; |
562 | else | 568 | else |
563 | ret = 0; | 569 | ret = 0; |
564 | 570 | ||
565 | return ret; | 571 | return ret; |