summaryrefslogtreecommitdiff
path: root/libopie/pim
authorzecke <zecke>2002-11-30 11:28:47 (UTC)
committer zecke <zecke>2002-11-30 11:28:47 (UTC)
commit9b8b30fa6cbdf1424b29cde21fae112e8bf96e6d (patch) (unidiff)
tree896dd858dc2ec2f0b7e1b265cae66ccceecc82da /libopie/pim
parent599c58c6ab2ab936890cbbfa4e6299493c141f8a (diff)
downloadopie-9b8b30fa6cbdf1424b29cde21fae112e8bf96e6d.zip
opie-9b8b30fa6cbdf1424b29cde21fae112e8bf96e6d.tar.gz
opie-9b8b30fa6cbdf1424b29cde21fae112e8bf96e6d.tar.bz2
More infrastructure
ORecur has now the nextOccurence function exceptions We've now Notifers like Alarms and DatebookEntries we may add to execute applications... AppName replaced with service cause it is a service Add rtti to OPimRecord as a static function This is used inside the BackEnd classes to static_cast... added removeAllCompleted to the todobackends... add a common Opie PIM mainwindow which takes care of some simple scripting enchangements.. much more
Diffstat (limited to 'libopie/pim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ABSTRACT18
-rw-r--r--libopie/pim/ocontact.cpp4
-rw-r--r--libopie/pim/ocontact.h3
-rw-r--r--libopie/pim/opimaccesstemplate.h10
-rw-r--r--libopie/pim/opimmaintainer.cpp6
-rw-r--r--libopie/pim/opimmaintainer.h16
-rw-r--r--libopie/pim/opimmainwindow.cpp71
-rw-r--r--libopie/pim/opimmainwindow.h79
-rw-r--r--libopie/pim/opimnotify.cpp227
-rw-r--r--libopie/pim/opimnotify.h142
-rw-r--r--libopie/pim/opimnotifymanager.cpp69
-rw-r--r--libopie/pim/opimnotifymanager.h51
-rw-r--r--libopie/pim/opimrecord.cpp3
-rw-r--r--libopie/pim/opimrecord.h10
-rw-r--r--libopie/pim/opimresolver.h56
-rw-r--r--libopie/pim/opimxref.cpp4
-rw-r--r--libopie/pim/opimxref.h2
-rw-r--r--libopie/pim/opimxrefmanager.cpp4
-rw-r--r--libopie/pim/opimxrefmanager.h2
-rw-r--r--libopie/pim/opimxrefpartner.cpp4
-rw-r--r--libopie/pim/opimxrefpartner.h6
-rw-r--r--libopie/pim/orecur.cpp315
-rw-r--r--libopie/pim/orecur.h29
-rw-r--r--libopie/pim/otodo.cpp72
-rw-r--r--libopie/pim/otodo.h59
-rw-r--r--libopie/pim/otodoaccess.cpp7
-rw-r--r--libopie/pim/otodoaccess.h17
-rw-r--r--libopie/pim/otodoaccessbackend.h1
-rw-r--r--libopie/pim/otodoaccessvcal.cpp6
-rw-r--r--libopie/pim/otodoaccessvcal.h2
-rw-r--r--libopie/pim/otodoaccessxml.cpp27
-rw-r--r--libopie/pim/otodoaccessxml.h1
32 files changed, 1225 insertions, 98 deletions
diff --git a/libopie/pim/ABSTRACT b/libopie/pim/ABSTRACT
new file mode 100644
index 0000000..5538d19
--- a/dev/null
+++ b/libopie/pim/ABSTRACT
@@ -0,0 +1,18 @@
1What is Opie PIM? Why is it special?
2Why do we need Opie PIM?
3
4The goal of OpiePIM is to be first of all
5extendable, light weight, scalable and fast.
6For the programmer we try to add a nice but
7powerful API to all classes.
8
9Memory is a costy resource on small and embedded
10devices. So we try to keep the memory usage as
11low as possible. Never the less we won't use structs
12and Pointers in the public API.
13The whole pim framework is value based. Internally we try
14to use implicit sharing as found in other Qt classes as well.
15This makes it possible to give 3rd party devels a nice
16API while keeping the memory usage as low as possible.
17
18We use C++ Templates
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp
index 917eb0a..efa2777 100644
--- a/libopie/pim/ocontact.cpp
+++ b/libopie/pim/ocontact.cpp
@@ -330,774 +330,776 @@ OContact::~OContact()
330/*! \fn QString OContact::manager() const 330/*! \fn QString OContact::manager() const
331 Returns the manager of the contact. 331 Returns the manager of the contact.
332*/ 332*/
333 333
334/*! \fn QString OContact::businessStreet() const 334/*! \fn QString OContact::businessStreet() const
335 Returns the business street address of the contact. 335 Returns the business street address of the contact.
336*/ 336*/
337 337
338/*! \fn QString OContact::businessCity() const 338/*! \fn QString OContact::businessCity() const
339 Returns the business city of the contact. 339 Returns the business city of the contact.
340*/ 340*/
341 341
342/*! \fn QString OContact::businessState() const 342/*! \fn QString OContact::businessState() const
343 Returns the business state of the contact. 343 Returns the business state of the contact.
344*/ 344*/
345 345
346/*! \fn QString OContact::businessZip() const 346/*! \fn QString OContact::businessZip() const
347 Returns the business zip of the contact. 347 Returns the business zip of the contact.
348*/ 348*/
349 349
350/*! \fn QString OContact::businessCountry() const 350/*! \fn QString OContact::businessCountry() const
351 Returns the business country of the contact. 351 Returns the business country of the contact.
352*/ 352*/
353 353
354/*! \fn QString OContact::businessPhone() const 354/*! \fn QString OContact::businessPhone() const
355 Returns the business phone number of the contact. 355 Returns the business phone number of the contact.
356*/ 356*/
357 357
358/*! \fn QString OContact::businessFax() const 358/*! \fn QString OContact::businessFax() const
359 Returns the business fax number of the contact. 359 Returns the business fax number of the contact.
360*/ 360*/
361 361
362/*! \fn QString OContact::businessMobile() const 362/*! \fn QString OContact::businessMobile() const
363 Returns the business mobile number of the contact. 363 Returns the business mobile number of the contact.
364*/ 364*/
365 365
366/*! \fn QString OContact::businessPager() const 366/*! \fn QString OContact::businessPager() const
367 Returns the business pager number of the contact. 367 Returns the business pager number of the contact.
368*/ 368*/
369 369
370/*! \fn QString OContact::businessWebpage() const 370/*! \fn QString OContact::businessWebpage() const
371 Returns the business webpage of the contact. 371 Returns the business webpage of the contact.
372*/ 372*/
373 373
374/*! \fn QString OContact::spouse() const 374/*! \fn QString OContact::spouse() const
375 Returns the spouse of the contact. 375 Returns the spouse of the contact.
376*/ 376*/
377 377
378/*! \fn QString OContact::gender() const 378/*! \fn QString OContact::gender() const
379 Returns the gender of the contact. 379 Returns the gender of the contact.
380*/ 380*/
381 381
382/*! \fn QString OContact::nickname() const 382/*! \fn QString OContact::nickname() const
383 Returns the nickname of the contact. 383 Returns the nickname of the contact.
384*/ 384*/
385 385
386/*! \fn QString OContact::children() const 386/*! \fn QString OContact::children() const
387 Returns the children of the contact. 387 Returns the children of the contact.
388*/ 388*/
389 389
390/*! \fn QString OContact::notes() const 390/*! \fn QString OContact::notes() const
391 Returns the notes relating to the the contact. 391 Returns the notes relating to the the contact.
392*/ 392*/
393 393
394/*! \fn QString OContact::groups() const 394/*! \fn QString OContact::groups() const
395 \internal 395 \internal
396 Returns the groups for the contact. 396 Returns the groups for the contact.
397*/ 397*/
398 398
399/*! \fn QStringList OContact::groupList() const 399/*! \fn QStringList OContact::groupList() const
400 \internal 400 \internal
401*/ 401*/
402 402
403/*! \fn QString OContact::field(int) const 403/*! \fn QString OContact::field(int) const
404 \internal 404 \internal
405*/ 405*/
406 406
407/*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null ) 407/*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null )
408 \internal 408 \internal
409*/ 409*/
410 410
411/*! \fn void OContact::setUid( int id ) 411/*! \fn void OContact::setUid( int id )
412 \internal 412 \internal
413 Sets the uid for this record to \a id. 413 Sets the uid for this record to \a id.
414*/ 414*/
415 415
416/*! \enum OContact::journal_action 416/*! \enum OContact::journal_action
417 \internal 417 \internal
418*/ 418*/
419 419
420/*! 420/*!
421 \internal 421 \internal
422*/ 422*/
423QMap<int, QString> OContact::toMap() const 423QMap<int, QString> OContact::toMap() const
424{ 424{
425 QMap<int, QString> map = mMap; 425 QMap<int, QString> map = mMap;
426 QString cats = idsToString( categories() ); 426 QString cats = idsToString( categories() );
427 if ( !cats.isEmpty() ) 427 if ( !cats.isEmpty() )
428 map.insert( Qtopia::AddressCategory, cats ); 428 map.insert( Qtopia::AddressCategory, cats );
429 return map; 429 return map;
430} 430}
431 431
432/*! 432/*!
433 Returns a rich text formatted QString representing the contents the contact. 433 Returns a rich text formatted QString representing the contents the contact.
434*/ 434*/
435QString OContact::toRichText() const 435QString OContact::toRichText() const
436{ 436{
437 QString text; 437 QString text;
438 QString value, comp, state; 438 QString value, comp, state;
439 439
440 // name, jobtitle and company 440 // name, jobtitle and company
441 if ( !(value = fullName()).isEmpty() ) 441 if ( !(value = fullName()).isEmpty() )
442 text += "<b>" + Qtopia::escapeString(value) + "</b><br>"; 442 text += "<b>" + Qtopia::escapeString(value) + "</b><br>";
443 if ( !(value = jobTitle()).isEmpty() ) 443 if ( !(value = jobTitle()).isEmpty() )
444 text += Qtopia::escapeString(value) + "<br>"; 444 text += Qtopia::escapeString(value) + "<br>";
445 445
446 comp = company(); 446 comp = company();
447 if ( !(value = department()).isEmpty() ) { 447 if ( !(value = department()).isEmpty() ) {
448 text += Qtopia::escapeString(value); 448 text += Qtopia::escapeString(value);
449 if ( comp ) 449 if ( comp )
450 text += ", "; 450 text += ", ";
451 else 451 else
452 text += "<br>"; 452 text += "<br>";
453 } 453 }
454 if ( !comp.isEmpty() ) 454 if ( !comp.isEmpty() )
455 text += Qtopia::escapeString(comp) + "<br>"; 455 text += Qtopia::escapeString(comp) + "<br>";
456 456
457 // business address 457 // business address
458 if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || 458 if ( !businessStreet().isEmpty() || !businessCity().isEmpty() ||
459 !businessZip().isEmpty() || !businessCountry().isEmpty() ) { 459 !businessZip().isEmpty() || !businessCountry().isEmpty() ) {
460 text += "<br>"; 460 text += "<br>";
461 text += QObject::tr( "<b>Work Address:</b>" ); 461 text += QObject::tr( "<b>Work Address:</b>" );
462 text += "<br>"; 462 text += "<br>";
463 } 463 }
464 464
465 if ( !(value = businessStreet()).isEmpty() ) 465 if ( !(value = businessStreet()).isEmpty() )
466 text += Qtopia::escapeString(value) + "<br>"; 466 text += Qtopia::escapeString(value) + "<br>";
467 state = businessState(); 467 state = businessState();
468 if ( !(value = businessCity()).isEmpty() ) { 468 if ( !(value = businessCity()).isEmpty() ) {
469 text += Qtopia::escapeString(value); 469 text += Qtopia::escapeString(value);
470 if ( state ) 470 if ( state )
471 text += ", " + Qtopia::escapeString(state); 471 text += ", " + Qtopia::escapeString(state);
472 text += "<br>"; 472 text += "<br>";
473 } else if ( !state.isEmpty() ) 473 } else if ( !state.isEmpty() )
474 text += Qtopia::escapeString(state) + "<br>"; 474 text += Qtopia::escapeString(state) + "<br>";
475 if ( !(value = businessZip()).isEmpty() ) 475 if ( !(value = businessZip()).isEmpty() )
476 text += Qtopia::escapeString(value) + "<br>"; 476 text += Qtopia::escapeString(value) + "<br>";
477 if ( !(value = businessCountry()).isEmpty() ) 477 if ( !(value = businessCountry()).isEmpty() )
478 text += Qtopia::escapeString(value) + "<br>"; 478 text += Qtopia::escapeString(value) + "<br>";
479 479
480 // home address 480 // home address
481 if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || 481 if ( !homeStreet().isEmpty() || !homeCity().isEmpty() ||
482 !homeZip().isEmpty() || !homeCountry().isEmpty() ) { 482 !homeZip().isEmpty() || !homeCountry().isEmpty() ) {
483 text += "<br>"; 483 text += "<br>";
484 text += QObject::tr( "<b>Home Address:</b>" ); 484 text += QObject::tr( "<b>Home Address:</b>" );
485 text += "<br>"; 485 text += "<br>";
486 } 486 }
487 487
488 if ( !(value = homeStreet()).isEmpty() ) 488 if ( !(value = homeStreet()).isEmpty() )
489 text += Qtopia::escapeString(value) + "<br>"; 489 text += Qtopia::escapeString(value) + "<br>";
490 state = homeState(); 490 state = homeState();
491 if ( !(value = homeCity()).isEmpty() ) { 491 if ( !(value = homeCity()).isEmpty() ) {
492 text += Qtopia::escapeString(value); 492 text += Qtopia::escapeString(value);
493 if ( !state.isEmpty() ) 493 if ( !state.isEmpty() )
494 text += ", " + Qtopia::escapeString(state); 494 text += ", " + Qtopia::escapeString(state);
495 text += "<br>"; 495 text += "<br>";
496 } else if (!state.isEmpty()) 496 } else if (!state.isEmpty())
497 text += Qtopia::escapeString(state) + "<br>"; 497 text += Qtopia::escapeString(state) + "<br>";
498 if ( !(value = homeZip()).isEmpty() ) 498 if ( !(value = homeZip()).isEmpty() )
499 text += Qtopia::escapeString(value) + "<br>"; 499 text += Qtopia::escapeString(value) + "<br>";
500 if ( !(value = homeCountry()).isEmpty() ) 500 if ( !(value = homeCountry()).isEmpty() )
501 text += Qtopia::escapeString(value) + "<br>"; 501 text += Qtopia::escapeString(value) + "<br>";
502 502
503 // the others... 503 // the others...
504 QString str; 504 QString str;
505 str = emails(); 505 str = emails();
506 if ( !str.isEmpty() ) 506 if ( !str.isEmpty() )
507 text += "<b>" + QObject::tr("Email Addresses: ") + "</b>" 507 text += "<b>" + QObject::tr("Email Addresses: ") + "</b>"
508 + Qtopia::escapeString(str) + "<br>"; 508 + Qtopia::escapeString(str) + "<br>";
509 str = homePhone(); 509 str = homePhone();
510 if ( !str.isEmpty() ) 510 if ( !str.isEmpty() )
511 text += "<b>" + QObject::tr("Home Phone: ") + "</b>" 511 text += "<b>" + QObject::tr("Home Phone: ") + "</b>"
512 + Qtopia::escapeString(str) + "<br>"; 512 + Qtopia::escapeString(str) + "<br>";
513 str = homeFax(); 513 str = homeFax();
514 if ( !str.isEmpty() ) 514 if ( !str.isEmpty() )
515 text += "<b>" + QObject::tr("Home Fax: ") + "</b>" 515 text += "<b>" + QObject::tr("Home Fax: ") + "</b>"
516 + Qtopia::escapeString(str) + "<br>"; 516 + Qtopia::escapeString(str) + "<br>";
517 str = homeMobile(); 517 str = homeMobile();
518 if ( !str.isEmpty() ) 518 if ( !str.isEmpty() )
519 text += "<b>" + QObject::tr("Home Mobile: ") + "</b>" 519 text += "<b>" + QObject::tr("Home Mobile: ") + "</b>"
520 + Qtopia::escapeString(str) + "<br>"; 520 + Qtopia::escapeString(str) + "<br>";
521 str = homeWebpage(); 521 str = homeWebpage();
522 if ( !str.isEmpty() ) 522 if ( !str.isEmpty() )
523 text += "<b>" + QObject::tr("Home Web Page: ") + "</b>" 523 text += "<b>" + QObject::tr("Home Web Page: ") + "</b>"
524 + Qtopia::escapeString(str) + "<br>"; 524 + Qtopia::escapeString(str) + "<br>";
525 str = businessWebpage(); 525 str = businessWebpage();
526 if ( !str.isEmpty() ) 526 if ( !str.isEmpty() )
527 text += "<b>" + QObject::tr("Business Web Page: ") + "</b>" 527 text += "<b>" + QObject::tr("Business Web Page: ") + "</b>"
528 + Qtopia::escapeString(str) + "<br>"; 528 + Qtopia::escapeString(str) + "<br>";
529 str = office(); 529 str = office();
530 if ( !str.isEmpty() ) 530 if ( !str.isEmpty() )
531 text += "<b>" + QObject::tr("Office: ") + "</b>" 531 text += "<b>" + QObject::tr("Office: ") + "</b>"
532 + Qtopia::escapeString(str) + "<br>"; 532 + Qtopia::escapeString(str) + "<br>";
533 str = businessPhone(); 533 str = businessPhone();
534 if ( !str.isEmpty() ) 534 if ( !str.isEmpty() )
535 text += "<b>" + QObject::tr("Business Phone: ") + "</b>" 535 text += "<b>" + QObject::tr("Business Phone: ") + "</b>"
536 + Qtopia::escapeString(str) + "<br>"; 536 + Qtopia::escapeString(str) + "<br>";
537 str = businessFax(); 537 str = businessFax();
538 if ( !str.isEmpty() ) 538 if ( !str.isEmpty() )
539 text += "<b>" + QObject::tr("Business Fax: ") + "</b>" 539 text += "<b>" + QObject::tr("Business Fax: ") + "</b>"
540 + Qtopia::escapeString(str) + "<br>"; 540 + Qtopia::escapeString(str) + "<br>";
541 str = businessMobile(); 541 str = businessMobile();
542 if ( !str.isEmpty() ) 542 if ( !str.isEmpty() )
543 text += "<b>" + QObject::tr("Business Mobile: ") + "</b>" 543 text += "<b>" + QObject::tr("Business Mobile: ") + "</b>"
544 + Qtopia::escapeString(str) + "<br>"; 544 + Qtopia::escapeString(str) + "<br>";
545 str = businessPager(); 545 str = businessPager();
546 if ( !str.isEmpty() ) 546 if ( !str.isEmpty() )
547 text += "<b>" + QObject::tr("Business Pager: ") + "</b>" 547 text += "<b>" + QObject::tr("Business Pager: ") + "</b>"
548 + Qtopia::escapeString(str) + "<br>"; 548 + Qtopia::escapeString(str) + "<br>";
549 str = profession(); 549 str = profession();
550 if ( !str.isEmpty() ) 550 if ( !str.isEmpty() )
551 text += "<b>" + QObject::tr("Profession: ") + "</b>" 551 text += "<b>" + QObject::tr("Profession: ") + "</b>"
552 + Qtopia::escapeString(str) + "<br>"; 552 + Qtopia::escapeString(str) + "<br>";
553 str = assistant(); 553 str = assistant();
554 if ( !str.isEmpty() ) 554 if ( !str.isEmpty() )
555 text += "<b>" + QObject::tr("Assistant: ") + "</b>" 555 text += "<b>" + QObject::tr("Assistant: ") + "</b>"
556 + Qtopia::escapeString(str) + "<br>"; 556 + Qtopia::escapeString(str) + "<br>";
557 str = manager(); 557 str = manager();
558 if ( !str.isEmpty() ) 558 if ( !str.isEmpty() )
559 text += "<b>" + QObject::tr("Manager: ") + "</b>" 559 text += "<b>" + QObject::tr("Manager: ") + "</b>"
560 + Qtopia::escapeString(str) + "<br>"; 560 + Qtopia::escapeString(str) + "<br>";
561 str = gender(); 561 str = gender();
562 if ( !str.isEmpty() && str.toInt() != 0 ) { 562 if ( !str.isEmpty() && str.toInt() != 0 ) {
563 if ( str.toInt() == 1 ) 563 if ( str.toInt() == 1 )
564 str = QObject::tr( "Male" ); 564 str = QObject::tr( "Male" );
565 else if ( str.toInt() == 2 ) 565 else if ( str.toInt() == 2 )
566 str = QObject::tr( "Female" ); 566 str = QObject::tr( "Female" );
567 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>"; 567 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>";
568 } 568 }
569 str = spouse(); 569 str = spouse();
570 if ( !str.isEmpty() ) 570 if ( !str.isEmpty() )
571 text += "<b>" + QObject::tr("Spouse: ") + "</b>" 571 text += "<b>" + QObject::tr("Spouse: ") + "</b>"
572 + Qtopia::escapeString(str) + "<br>"; 572 + Qtopia::escapeString(str) + "<br>";
573 if ( birthday().isValid() ){ 573 if ( birthday().isValid() ){
574 str = TimeString::numberDateString( birthday() ); 574 str = TimeString::numberDateString( birthday() );
575 text += "<b>" + QObject::tr("Birthday: ") + "</b>" 575 text += "<b>" + QObject::tr("Birthday: ") + "</b>"
576 + Qtopia::escapeString(str) + "<br>"; 576 + Qtopia::escapeString(str) + "<br>";
577 } 577 }
578 if ( anniversary().isValid() ){ 578 if ( anniversary().isValid() ){
579 str = TimeString::numberDateString( anniversary() ); 579 str = TimeString::numberDateString( anniversary() );
580 text += "<b>" + QObject::tr("Anniversary: ") + "</b>" 580 text += "<b>" + QObject::tr("Anniversary: ") + "</b>"
581 + Qtopia::escapeString(str) + "<br>"; 581 + Qtopia::escapeString(str) + "<br>";
582 } 582 }
583 str = nickname(); 583 str = nickname();
584 if ( !str.isEmpty() ) 584 if ( !str.isEmpty() )
585 text += "<b>" + QObject::tr("Nickname: ") + "</b>" 585 text += "<b>" + QObject::tr("Nickname: ") + "</b>"
586 + Qtopia::escapeString(str) + "<br>"; 586 + Qtopia::escapeString(str) + "<br>";
587 587
588 if ( categoryNames().count() ){ 588 if ( categoryNames().count() ){
589 text += "<b>" + QObject::tr( "Category:") + "</b> "; 589 text += "<b>" + QObject::tr( "Category:") + "</b> ";
590 text += categoryNames().join(", "); 590 text += categoryNames().join(", ");
591 text += "<br>"; 591 text += "<br>";
592 } 592 }
593 593
594 // notes last 594 // notes last
595 if ( (value = notes()) ) { 595 if ( (value = notes()) ) {
596 QRegExp reg("\n"); 596 QRegExp reg("\n");
597 597
598 //QString tmp = Qtopia::escapeString(value); 598 //QString tmp = Qtopia::escapeString(value);
599 QString tmp = QStyleSheet::convertFromPlainText(value); 599 QString tmp = QStyleSheet::convertFromPlainText(value);
600 //tmp.replace( reg, "<br>" ); 600 //tmp.replace( reg, "<br>" );
601 text += "<br>" + tmp + "<br>"; 601 text += "<br>" + tmp + "<br>";
602 } 602 }
603 return text; 603 return text;
604} 604}
605 605
606/*! 606/*!
607 \internal 607 \internal
608*/ 608*/
609void OContact::insert( int key, const QString &v ) 609void OContact::insert( int key, const QString &v )
610{ 610{
611 QString value = v.stripWhiteSpace(); 611 QString value = v.stripWhiteSpace();
612 if ( value.isEmpty() ) 612 if ( value.isEmpty() )
613 mMap.remove( key ); 613 mMap.remove( key );
614 else 614 else
615 mMap.insert( key, value ); 615 mMap.insert( key, value );
616} 616}
617 617
618/*! 618/*!
619 \internal 619 \internal
620*/ 620*/
621void OContact::replace( int key, const QString & v ) 621void OContact::replace( int key, const QString & v )
622{ 622{
623 QString value = v.stripWhiteSpace(); 623 QString value = v.stripWhiteSpace();
624 if ( value.isEmpty() ) 624 if ( value.isEmpty() )
625 mMap.remove( key ); 625 mMap.remove( key );
626 else 626 else
627 mMap.replace( key, value ); 627 mMap.replace( key, value );
628} 628}
629 629
630/*! 630/*!
631 \internal 631 \internal
632*/ 632*/
633QString OContact::find( int key ) const 633QString OContact::find( int key ) const
634{ 634{
635 return mMap[key]; 635 return mMap[key];
636} 636}
637 637
638/*! 638/*!
639 \internal 639 \internal
640*/ 640*/
641QString OContact::displayAddress( const QString &street, 641QString OContact::displayAddress( const QString &street,
642 const QString &city, 642 const QString &city,
643 const QString &state, 643 const QString &state,
644 const QString &zip, 644 const QString &zip,
645 const QString &country ) const 645 const QString &country ) const
646{ 646{
647 QString s = street; 647 QString s = street;
648 if ( !street.isEmpty() ) 648 if ( !street.isEmpty() )
649 s+= "\n"; 649 s+= "\n";
650 s += city; 650 s += city;
651 if ( !city.isEmpty() && !state.isEmpty() ) 651 if ( !city.isEmpty() && !state.isEmpty() )
652 s += ", "; 652 s += ", ";
653 s += state; 653 s += state;
654 if ( !state.isEmpty() && !zip.isEmpty() ) 654 if ( !state.isEmpty() && !zip.isEmpty() )
655 s += " "; 655 s += " ";
656 s += zip; 656 s += zip;
657 if ( !country.isEmpty() && !s.isEmpty() ) 657 if ( !country.isEmpty() && !s.isEmpty() )
658 s += "\n"; 658 s += "\n";
659 s += country; 659 s += country;
660 return s; 660 return s;
661} 661}
662 662
663/*! 663/*!
664 \internal 664 \internal
665*/ 665*/
666QString OContact::displayBusinessAddress() const 666QString OContact::displayBusinessAddress() const
667{ 667{
668 return displayAddress( businessStreet(), businessCity(), 668 return displayAddress( businessStreet(), businessCity(),
669 businessState(), businessZip(), 669 businessState(), businessZip(),
670 businessCountry() ); 670 businessCountry() );
671} 671}
672 672
673/*! 673/*!
674 \internal 674 \internal
675*/ 675*/
676QString OContact::displayHomeAddress() const 676QString OContact::displayHomeAddress() const
677{ 677{
678 return displayAddress( homeStreet(), homeCity(), 678 return displayAddress( homeStreet(), homeCity(),
679 homeState(), homeZip(), 679 homeState(), homeZip(),
680 homeCountry() ); 680 homeCountry() );
681} 681}
682 682
683/*! 683/*!
684 Returns the full name of the contact 684 Returns the full name of the contact
685*/ 685*/
686QString OContact::fullName() const 686QString OContact::fullName() const
687{ 687{
688 QString title = find( Qtopia::Title ); 688 QString title = find( Qtopia::Title );
689 QString firstName = find( Qtopia::FirstName ); 689 QString firstName = find( Qtopia::FirstName );
690 QString middleName = find( Qtopia::MiddleName ); 690 QString middleName = find( Qtopia::MiddleName );
691 QString lastName = find( Qtopia::LastName ); 691 QString lastName = find( Qtopia::LastName );
692 QString suffix = find( Qtopia::Suffix ); 692 QString suffix = find( Qtopia::Suffix );
693 693
694 QString name = title; 694 QString name = title;
695 if ( !firstName.isEmpty() ) { 695 if ( !firstName.isEmpty() ) {
696 if ( !name.isEmpty() ) 696 if ( !name.isEmpty() )
697 name += " "; 697 name += " ";
698 name += firstName; 698 name += firstName;
699 } 699 }
700 if ( !middleName.isEmpty() ) { 700 if ( !middleName.isEmpty() ) {
701 if ( !name.isEmpty() ) 701 if ( !name.isEmpty() )
702 name += " "; 702 name += " ";
703 name += middleName; 703 name += middleName;
704 } 704 }
705 if ( !lastName.isEmpty() ) { 705 if ( !lastName.isEmpty() ) {
706 if ( !name.isEmpty() ) 706 if ( !name.isEmpty() )
707 name += " "; 707 name += " ";
708 name += lastName; 708 name += lastName;
709 } 709 }
710 if ( !suffix.isEmpty() ) { 710 if ( !suffix.isEmpty() ) {
711 if ( !name.isEmpty() ) 711 if ( !name.isEmpty() )
712 name += " "; 712 name += " ";
713 name += suffix; 713 name += suffix;
714 } 714 }
715 return name.simplifyWhiteSpace(); 715 return name.simplifyWhiteSpace();
716} 716}
717 717
718/*! 718/*!
719 Returns a list of the names of the children of the contact. 719 Returns a list of the names of the children of the contact.
720*/ 720*/
721QStringList OContact::childrenList() const 721QStringList OContact::childrenList() const
722{ 722{
723 return QStringList::split( " ", find( Qtopia::Children ) ); 723 return QStringList::split( " ", find( Qtopia::Children ) );
724} 724}
725 725
726/*! \fn void OContact::insertEmail( const QString &email ) 726/*! \fn void OContact::insertEmail( const QString &email )
727 727
728 Insert \a email into the email list. Ensures \a email can only be added 728 Insert \a email into the email list. Ensures \a email can only be added
729 once. If there is no default email address set, it sets it to the \a email. 729 once. If there is no default email address set, it sets it to the \a email.
730*/ 730*/
731 731
732/*! \fn void OContact::removeEmail( const QString &email ) 732/*! \fn void OContact::removeEmail( const QString &email )
733 733
734 Removes the \a email from the email list. If the default email was \a email, 734 Removes the \a email from the email list. If the default email was \a email,
735 then the default email address is assigned to the first email in the 735 then the default email address is assigned to the first email in the
736 email list 736 email list
737*/ 737*/
738 738
739/*! \fn void OContact::clearEmails() 739/*! \fn void OContact::clearEmails()
740 740
741 Clears the email list. 741 Clears the email list.
742 */ 742 */
743 743
744/*! \fn void OContact::insertEmails( const QStringList &emailList ) 744/*! \fn void OContact::insertEmails( const QStringList &emailList )
745 745
746 Appends the \a emailList to the exiting email list 746 Appends the \a emailList to the exiting email list
747 */ 747 */
748 748
749/*! 749/*!
750 Returns a list of email addresses belonging to the contact, including 750 Returns a list of email addresses belonging to the contact, including
751 the default email address. 751 the default email address.
752*/ 752*/
753QStringList OContact::emailList() const 753QStringList OContact::emailList() const
754{ 754{
755 QString emailStr = emails(); 755 QString emailStr = emails();
756 756
757 QStringList r; 757 QStringList r;
758 if ( !emailStr.isEmpty() ) { 758 if ( !emailStr.isEmpty() ) {
759 qDebug(" emailstr "); 759 qDebug(" emailstr ");
760 QStringList l = QStringList::split( emailSeparator(), emailStr ); 760 QStringList l = QStringList::split( emailSeparator(), emailStr );
761 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) 761 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
762 r += (*it).simplifyWhiteSpace(); 762 r += (*it).simplifyWhiteSpace();
763 } 763 }
764 764
765 return r; 765 return r;
766} 766}
767 767
768/*! 768/*!
769 \overload 769 \overload
770 770
771 Generates the string for the contact to be filed as from the first, 771 Generates the string for the contact to be filed as from the first,
772 middle and last name of the contact. 772 middle and last name of the contact.
773*/ 773*/
774void OContact::setFileAs() 774void OContact::setFileAs()
775{ 775{
776 QString lastName, firstName, middleName, fileas; 776 QString lastName, firstName, middleName, fileas;
777 777
778 lastName = find( Qtopia::LastName ); 778 lastName = find( Qtopia::LastName );
779 firstName = find( Qtopia::FirstName ); 779 firstName = find( Qtopia::FirstName );
780 middleName = find( Qtopia::MiddleName ); 780 middleName = find( Qtopia::MiddleName );
781 if ( !lastName.isEmpty() && !firstName.isEmpty() 781 if ( !lastName.isEmpty() && !firstName.isEmpty()
782 && !middleName.isEmpty() ) 782 && !middleName.isEmpty() )
783 fileas = lastName + ", " + firstName + " " + middleName; 783 fileas = lastName + ", " + firstName + " " + middleName;
784 else if ( !lastName.isEmpty() && !firstName.isEmpty() ) 784 else if ( !lastName.isEmpty() && !firstName.isEmpty() )
785 fileas = lastName + ", " + firstName; 785 fileas = lastName + ", " + firstName;
786 else if ( !lastName.isEmpty() || !firstName.isEmpty() || 786 else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
787 !middleName.isEmpty() ) 787 !middleName.isEmpty() )
788 fileas = firstName + ( firstName.isEmpty() ? "" : " " ) 788 fileas = firstName + ( firstName.isEmpty() ? "" : " " )
789 + middleName + ( middleName.isEmpty() ? "" : " " ) 789 + middleName + ( middleName.isEmpty() ? "" : " " )
790 + lastName; 790 + lastName;
791 791
792 replace( Qtopia::FileAs, fileas ); 792 replace( Qtopia::FileAs, fileas );
793} 793}
794 794
795/*! 795/*!
796 \internal 796 \internal
797 Appends the contact information to \a buf. 797 Appends the contact information to \a buf.
798*/ 798*/
799void OContact::save( QString &buf ) const 799void OContact::save( QString &buf ) const
800{ 800{
801 static const QStringList SLFIELDS = fields(); 801 static const QStringList SLFIELDS = fields();
802 // I'm expecting "<Contact " in front of this... 802 // I'm expecting "<Contact " in front of this...
803 for ( QMap<int, QString>::ConstIterator it = mMap.begin(); 803 for ( QMap<int, QString>::ConstIterator it = mMap.begin();
804 it != mMap.end(); ++it ) { 804 it != mMap.end(); ++it ) {
805 const QString &value = it.data(); 805 const QString &value = it.data();
806 int key = it.key(); 806 int key = it.key();
807 if ( !value.isEmpty() ) { 807 if ( !value.isEmpty() ) {
808 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid) 808 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid)
809 continue; 809 continue;
810 810
811 key -= Qtopia::AddressCategory+1; 811 key -= Qtopia::AddressCategory+1;
812 buf += SLFIELDS[key]; 812 buf += SLFIELDS[key];
813 buf += "=\"" + Qtopia::escapeString(value) + "\" "; 813 buf += "=\"" + Qtopia::escapeString(value) + "\" ";
814 } 814 }
815 } 815 }
816 buf += customToXml(); 816 buf += customToXml();
817 if ( categories().count() > 0 ) 817 if ( categories().count() > 0 )
818 buf += "Categories=\"" + idsToString( categories() ) + "\" "; 818 buf += "Categories=\"" + idsToString( categories() ) + "\" ";
819 buf += "Uid=\"" + QString::number( uid() ) + "\" "; 819 buf += "Uid=\"" + QString::number( uid() ) + "\" ";
820 // You need to close this yourself 820 // You need to close this yourself
821} 821}
822 822
823 823
824/*! 824/*!
825 \internal 825 \internal
826 Returns the list of fields belonging to a contact 826 Returns the list of fields belonging to a contact
827 Never change order of this list ! It has to be regarding 827 Never change order of this list ! It has to be regarding
828 enum AddressBookFields !! 828 enum AddressBookFields !!
829*/ 829*/
830QStringList OContact::fields() 830QStringList OContact::fields()
831{ 831{
832 QStringList list; 832 QStringList list;
833 833
834 list.append( "Title" ); // Not Used! 834 list.append( "Title" ); // Not Used!
835 list.append( "FirstName" ); 835 list.append( "FirstName" );
836 list.append( "MiddleName" ); 836 list.append( "MiddleName" );
837 list.append( "LastName" ); 837 list.append( "LastName" );
838 list.append( "Suffix" ); 838 list.append( "Suffix" );
839 list.append( "FileAs" ); 839 list.append( "FileAs" );
840 840
841 list.append( "JobTitle" ); 841 list.append( "JobTitle" );
842 list.append( "Department" ); 842 list.append( "Department" );
843 list.append( "Company" ); 843 list.append( "Company" );
844 list.append( "BusinessPhone" ); 844 list.append( "BusinessPhone" );
845 list.append( "BusinessFax" ); 845 list.append( "BusinessFax" );
846 list.append( "BusinessMobile" ); 846 list.append( "BusinessMobile" );
847 847
848 list.append( "DefaultEmail" ); 848 list.append( "DefaultEmail" );
849 list.append( "Emails" ); 849 list.append( "Emails" );
850 850
851 list.append( "HomePhone" ); 851 list.append( "HomePhone" );
852 list.append( "HomeFax" ); 852 list.append( "HomeFax" );
853 list.append( "HomeMobile" ); 853 list.append( "HomeMobile" );
854 854
855 list.append( "BusinessStreet" ); 855 list.append( "BusinessStreet" );
856 list.append( "BusinessCity" ); 856 list.append( "BusinessCity" );
857 list.append( "BusinessState" ); 857 list.append( "BusinessState" );
858 list.append( "BusinessZip" ); 858 list.append( "BusinessZip" );
859 list.append( "BusinessCountry" ); 859 list.append( "BusinessCountry" );
860 list.append( "BusinessPager" ); 860 list.append( "BusinessPager" );
861 list.append( "BusinessWebPage" ); 861 list.append( "BusinessWebPage" );
862 862
863 list.append( "Office" ); 863 list.append( "Office" );
864 list.append( "Profession" ); 864 list.append( "Profession" );
865 list.append( "Assistant" ); 865 list.append( "Assistant" );
866 list.append( "Manager" ); 866 list.append( "Manager" );
867 867
868 list.append( "HomeStreet" ); 868 list.append( "HomeStreet" );
869 list.append( "HomeCity" ); 869 list.append( "HomeCity" );
870 list.append( "HomeState" ); 870 list.append( "HomeState" );
871 list.append( "HomeZip" ); 871 list.append( "HomeZip" );
872 list.append( "HomeCountry" ); 872 list.append( "HomeCountry" );
873 list.append( "HomeWebPage" ); 873 list.append( "HomeWebPage" );
874 874
875 list.append( "Spouse" ); 875 list.append( "Spouse" );
876 list.append( "Gender" ); 876 list.append( "Gender" );
877 list.append( "Birthday" ); 877 list.append( "Birthday" );
878 list.append( "Anniversary" ); 878 list.append( "Anniversary" );
879 list.append( "Nickname" ); 879 list.append( "Nickname" );
880 list.append( "Children" ); 880 list.append( "Children" );
881 881
882 list.append( "Notes" ); 882 list.append( "Notes" );
883 list.append( "Groups" ); 883 list.append( "Groups" );
884 884
885 return list; 885 return list;
886} 886}
887 887
888 888
889/*! 889/*!
890 Sets the list of email address for contact to those contained in \a str. 890 Sets the list of email address for contact to those contained in \a str.
891 Email address should be separated by ';'s. 891 Email address should be separated by ';'s.
892*/ 892*/
893void OContact::setEmails( const QString &str ) 893void OContact::setEmails( const QString &str )
894{ 894{
895 replace( Qtopia::Emails, str ); 895 replace( Qtopia::Emails, str );
896 if ( str.isEmpty() ) 896 if ( str.isEmpty() )
897 setDefaultEmail( QString::null ); 897 setDefaultEmail( QString::null );
898} 898}
899 899
900/*! 900/*!
901 Sets the list of children for the contact to those contained in \a str. 901 Sets the list of children for the contact to those contained in \a str.
902*/ 902*/
903void OContact::setChildren( const QString &str ) 903void OContact::setChildren( const QString &str )
904{ 904{
905 replace( Qtopia::Children, str ); 905 replace( Qtopia::Children, str );
906} 906}
907 907
908/*! 908/*!
909 Returns TRUE if the contact matches the regular expression \a regexp. 909 Returns TRUE if the contact matches the regular expression \a regexp.
910 Otherwise returns FALSE. 910 Otherwise returns FALSE.
911*/ 911*/
912bool OContact::match( const QString &regexp ) const 912bool OContact::match( const QString &regexp ) const
913{ 913{
914 return match(QRegExp(regexp)); 914 return match(QRegExp(regexp));
915} 915}
916 916
917/*! 917/*!
918 \overload 918 \overload
919 Returns TRUE if the contact matches the regular expression \a regexp. 919 Returns TRUE if the contact matches the regular expression \a regexp.
920 Otherwise returns FALSE. 920 Otherwise returns FALSE.
921*/ 921*/
922bool OContact::match( const QRegExp &r ) const 922bool OContact::match( const QRegExp &r ) const
923{ 923{
924 bool match; 924 bool match;
925 match = false; 925 match = false;
926 QMap<int, QString>::ConstIterator it; 926 QMap<int, QString>::ConstIterator it;
927 for ( it = mMap.begin(); it != mMap.end(); ++it ) { 927 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
928 if ( (*it).find( r ) > -1 ) { 928 if ( (*it).find( r ) > -1 ) {
929 match = true; 929 match = true;
930 break; 930 break;
931 } 931 }
932 } 932 }
933 return match; 933 return match;
934} 934}
935 935
936 936
937QString OContact::toShortText() const 937QString OContact::toShortText() const
938{ 938{
939 return ( fullName() ); 939 return ( fullName() );
940} 940}
941QString OContact::type() const 941QString OContact::type() const
942{ 942{
943 return QString::fromLatin1( "OContact" ); 943 return QString::fromLatin1( "OContact" );
944} 944}
945 945
946// Definition is missing ! (se) 946// Definition is missing ! (se)
947QMap<QString,QString> OContact::toExtraMap() const 947QMap<QString,QString> OContact::toExtraMap() const
948{ 948{
949 qWarning ("Function not implemented: OContact::toExtraMap()"); 949 qWarning ("Function not implemented: OContact::toExtraMap()");
950 QMap <QString,QString> useless; 950 QMap <QString,QString> useless;
951 return useless; 951 return useless;
952} 952}
953 953
954class QString OContact::recordField( int pos ) const 954class QString OContact::recordField( int pos ) const
955{ 955{
956 QStringList SLFIELDS = fields(); // ?? why this ? (se) 956 QStringList SLFIELDS = fields(); // ?? why this ? (se)
957 return SLFIELDS[pos]; 957 return SLFIELDS[pos];
958} 958}
959 959
960// In future releases, we should store birthday and anniversary 960// In future releases, we should store birthday and anniversary
961// internally as QDate instead of QString ! 961// internally as QDate instead of QString !
962// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 962// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
963 963
964/*! \fn void OContact::setBirthday( const QDate& date ) 964/*! \fn void OContact::setBirthday( const QDate& date )
965 Sets the birthday for the contact to \a date. If date is null 965 Sets the birthday for the contact to \a date. If date is null
966 the current stored date will be removed. 966 the current stored date will be removed.
967*/ 967*/
968void OContact::setBirthday( const QDate &v ) 968void OContact::setBirthday( const QDate &v )
969{ 969{
970 if ( v.isNull() ){ 970 if ( v.isNull() ){
971 qWarning( "Remove Birthday"); 971 qWarning( "Remove Birthday");
972 replace( Qtopia::Birthday, QString::null ); 972 replace( Qtopia::Birthday, QString::null );
973 return; 973 return;
974 } 974 }
975 975
976 if ( v.isValid() ) 976 if ( v.isValid() )
977 replace( Qtopia::Birthday, TimeConversion::toString( v ) ); 977 replace( Qtopia::Birthday, TimeConversion::toString( v ) );
978 978
979} 979}
980 980
981 981
982/*! \fn void OContact::setAnniversary( const QDate &date ) 982/*! \fn void OContact::setAnniversary( const QDate &date )
983 Sets the anniversary of the contact to \a date. If date is 983 Sets the anniversary of the contact to \a date. If date is
984 null, the current stored date will be removed. 984 null, the current stored date will be removed.
985*/ 985*/
986void OContact::setAnniversary( const QDate &v ) 986void OContact::setAnniversary( const QDate &v )
987{ 987{
988 if ( v.isNull() ){ 988 if ( v.isNull() ){
989 qWarning( "Remove Anniversary"); 989 qWarning( "Remove Anniversary");
990 replace( Qtopia::Anniversary, QString::null ); 990 replace( Qtopia::Anniversary, QString::null );
991 return; 991 return;
992 } 992 }
993 993
994 if ( v.isValid() ) 994 if ( v.isValid() )
995 replace( Qtopia::Anniversary, TimeConversion::toString( v ) ); 995 replace( Qtopia::Anniversary, TimeConversion::toString( v ) );
996} 996}
997 997
998/*! \fn QDate OContact::birthday() const 998/*! \fn QDate OContact::birthday() const
999 Returns the birthday of the contact. 999 Returns the birthday of the contact.
1000*/ 1000*/
1001QDate OContact::birthday() const 1001QDate OContact::birthday() const
1002{ 1002{
1003 QString str = find( Qtopia::Birthday ); 1003 QString str = find( Qtopia::Birthday );
1004 qWarning ("Birthday %s", str.latin1() ); 1004 qWarning ("Birthday %s", str.latin1() );
1005 if ( !str.isEmpty() ) 1005 if ( !str.isEmpty() )
1006 return TimeConversion::fromString ( str ); 1006 return TimeConversion::fromString ( str );
1007 else 1007 else
1008 return QDate(); 1008 return QDate();
1009} 1009}
1010 1010
1011 1011
1012/*! \fn QDate OContact::anniversary() const 1012/*! \fn QDate OContact::anniversary() const
1013 Returns the anniversary of the contact. 1013 Returns the anniversary of the contact.
1014*/ 1014*/
1015QDate OContact::anniversary() const 1015QDate OContact::anniversary() const
1016{ 1016{
1017 QDate empty; 1017 QDate empty;
1018 QString str = find( Qtopia::Anniversary ); 1018 QString str = find( Qtopia::Anniversary );
1019 qWarning ("Anniversary %s", str.latin1() ); 1019 qWarning ("Anniversary %s", str.latin1() );
1020 if ( !str.isEmpty() ) 1020 if ( !str.isEmpty() )
1021 return TimeConversion::fromString ( str ); 1021 return TimeConversion::fromString ( str );
1022 else 1022 else
1023 return empty; 1023 return empty;
1024} 1024}
1025 1025
1026 1026
1027void OContact::insertEmail( const QString &v ) 1027void OContact::insertEmail( const QString &v )
1028{ 1028{
1029 //qDebug("insertEmail %s", v.latin1()); 1029 //qDebug("insertEmail %s", v.latin1());
1030 QString e = v.simplifyWhiteSpace(); 1030 QString e = v.simplifyWhiteSpace();
1031 QString def = defaultEmail(); 1031 QString def = defaultEmail();
1032 1032
1033 // if no default, set it as the default email and don't insert 1033 // if no default, set it as the default email and don't insert
1034 if ( def.isEmpty() ) { 1034 if ( def.isEmpty() ) {
1035 setDefaultEmail( e ); // will insert into the list for us 1035 setDefaultEmail( e ); // will insert into the list for us
1036 return; 1036 return;
1037 } 1037 }
1038 1038
1039 // otherwise, insert assuming doesn't already exist 1039 // otherwise, insert assuming doesn't already exist
1040 QString emailsStr = find( Qtopia::Emails ); 1040 QString emailsStr = find( Qtopia::Emails );
1041 if ( emailsStr.contains( e )) 1041 if ( emailsStr.contains( e ))
1042 return; 1042 return;
1043 if ( !emailsStr.isEmpty() ) 1043 if ( !emailsStr.isEmpty() )
1044 emailsStr += emailSeparator(); 1044 emailsStr += emailSeparator();
1045 emailsStr += e; 1045 emailsStr += e;
1046 replace( Qtopia::Emails, emailsStr ); 1046 replace( Qtopia::Emails, emailsStr );
1047} 1047}
1048 1048
1049void OContact::removeEmail( const QString &v ) 1049void OContact::removeEmail( const QString &v )
1050{ 1050{
1051 QString e = v.simplifyWhiteSpace(); 1051 QString e = v.simplifyWhiteSpace();
1052 QString def = defaultEmail(); 1052 QString def = defaultEmail();
1053 QString emailsStr = find( Qtopia::Emails ); 1053 QString emailsStr = find( Qtopia::Emails );
1054 QStringList emails = emailList(); 1054 QStringList emails = emailList();
1055 1055
1056 // otherwise, must first contain it 1056 // otherwise, must first contain it
1057 if ( !emailsStr.contains( e ) ) 1057 if ( !emailsStr.contains( e ) )
1058 return; 1058 return;
1059 1059
1060 // remove it 1060 // remove it
1061 //qDebug(" removing email from list %s", e.latin1()); 1061 //qDebug(" removing email from list %s", e.latin1());
1062 emails.remove( e ); 1062 emails.remove( e );
1063 // reset the string 1063 // reset the string
1064 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator 1064 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
1065 replace( Qtopia::Emails, emailsStr ); 1065 replace( Qtopia::Emails, emailsStr );
1066 1066
1067 // if default, then replace the default email with the first one 1067 // if default, then replace the default email with the first one
1068 if ( def == e ) { 1068 if ( def == e ) {
1069 //qDebug("removeEmail is default; setting new default"); 1069 //qDebug("removeEmail is default; setting new default");
1070 if ( !emails.count() ) 1070 if ( !emails.count() )
1071 clearEmails(); 1071 clearEmails();
1072 else // setDefaultEmail will remove e from the list 1072 else // setDefaultEmail will remove e from the list
1073 setDefaultEmail( emails.first() ); 1073 setDefaultEmail( emails.first() );
1074 } 1074 }
1075} 1075}
1076void OContact::clearEmails() 1076void OContact::clearEmails()
1077{ 1077{
1078 mMap.remove( Qtopia::DefaultEmail ); 1078 mMap.remove( Qtopia::DefaultEmail );
1079 mMap.remove( Qtopia::Emails ); 1079 mMap.remove( Qtopia::Emails );
1080} 1080}
1081void OContact::setDefaultEmail( const QString &v ) 1081void OContact::setDefaultEmail( const QString &v )
1082{ 1082{
1083 QString e = v.simplifyWhiteSpace(); 1083 QString e = v.simplifyWhiteSpace();
1084 1084
1085 //qDebug("OContact::setDefaultEmail %s", e.latin1()); 1085 //qDebug("OContact::setDefaultEmail %s", e.latin1());
1086 replace( Qtopia::DefaultEmail, e ); 1086 replace( Qtopia::DefaultEmail, e );
1087 1087
1088 if ( !e.isEmpty() ) 1088 if ( !e.isEmpty() )
1089 insertEmail( e ); 1089 insertEmail( e );
1090 1090
1091} 1091}
1092 1092
1093void OContact::insertEmails( const QStringList &v ) 1093void OContact::insertEmails( const QStringList &v )
1094{ 1094{
1095 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1095 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1096 insertEmail( *it ); 1096 insertEmail( *it );
1097} 1097}
1098 1098int OContact::rtti() {
1099 return 2;
1100}
1099void OContact::setUid( int i ) 1101void OContact::setUid( int i )
1100{ 1102{
1101 OPimRecord::setUid(i); 1103 OPimRecord::setUid(i);
1102 replace( Qtopia::AddressUid , QString::number(i)); 1104 replace( Qtopia::AddressUid , QString::number(i));
1103} 1105}
diff --git a/libopie/pim/ocontact.h b/libopie/pim/ocontact.h
index d97af1c..65ba43e 100644
--- a/libopie/pim/ocontact.h
+++ b/libopie/pim/ocontact.h
@@ -1,238 +1,239 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) 3** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de)
4** 4**
5** This file is part of the Qtopia Environment. 5** This file is part of the Qtopia Environment.
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 14**
15** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
16** 16**
17** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you. 18** not clear to you.
19** 19**
20**********************************************************************/ 20**********************************************************************/
21 21
22#ifndef __OCONTACT_H__ 22#ifndef __OCONTACT_H__
23#define __OCONTACT_H__ 23#define __OCONTACT_H__
24 24
25#include <opie/opimrecord.h> 25#include <opie/opimrecord.h>
26#include <qpe/recordfields.h> 26#include <qpe/recordfields.h>
27 27
28#include <qdatetime.h> 28#include <qdatetime.h>
29#include <qstringlist.h> 29#include <qstringlist.h>
30 30
31#if defined(QPC_TEMPLATEDLL) 31#if defined(QPC_TEMPLATEDLL)
32// MOC_SKIP_BEGIN 32// MOC_SKIP_BEGIN
33QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; 33QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>;
34// MOC_SKIP_END 34// MOC_SKIP_END
35#endif 35#endif
36 36
37class ContactPrivate; 37class ContactPrivate;
38 38
39class QPC_EXPORT OContact : public OPimRecord 39class QPC_EXPORT OContact : public OPimRecord
40{ 40{
41 friend class DataSet; 41 friend class DataSet;
42public: 42public:
43 OContact(); 43 OContact();
44 OContact( const QMap<int, QString> &fromMap ); 44 OContact( const QMap<int, QString> &fromMap );
45 virtual ~OContact(); 45 virtual ~OContact();
46 46
47 enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; 47 enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
48 48
49 /* 49 /*
50 * do we need to inline them 50 * do we need to inline them
51 * if yes do we need to inline them this way? 51 * if yes do we need to inline them this way?
52 * -zecke 52 * -zecke
53 */ 53 */
54 void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } 54 void setTitle( const QString &v ) { replace( Qtopia::Title, v ); }
55 void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } 55 void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); }
56 void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } 56 void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); }
57 void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } 57 void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); }
58 void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } 58 void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); }
59 void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } 59 void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); }
60 void setFileAs(); 60 void setFileAs();
61 61
62 // default email address 62 // default email address
63 void setDefaultEmail( const QString &v ); 63 void setDefaultEmail( const QString &v );
64 // inserts email to list and ensure's doesn't already exist 64 // inserts email to list and ensure's doesn't already exist
65 void insertEmail( const QString &v ); 65 void insertEmail( const QString &v );
66 void removeEmail( const QString &v ); 66 void removeEmail( const QString &v );
67 void clearEmails(); 67 void clearEmails();
68 void insertEmails( const QStringList &v ); 68 void insertEmails( const QStringList &v );
69 69
70 // home 70 // home
71 void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } 71 void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); }
72 void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } 72 void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); }
73 void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } 73 void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); }
74 void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } 74 void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); }
75 void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } 75 void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); }
76 void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } 76 void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); }
77 void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } 77 void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); }
78 void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } 78 void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); }
79 void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } 79 void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); }
80 80
81 // business 81 // business
82 void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } 82 void setCompany( const QString &v ) { replace( Qtopia::Company, v ); }
83 void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } 83 void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); }
84 void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } 84 void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); }
85 void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } 85 void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); }
86 void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } 86 void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); }
87 void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } 87 void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); }
88 void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } 88 void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); }
89 void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } 89 void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); }
90 void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } 90 void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); }
91 void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } 91 void setOffice( const QString &v ) { replace( Qtopia::Office, v ); }
92 void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } 92 void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); }
93 void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } 93 void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); }
94 void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } 94 void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); }
95 void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } 95 void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); }
96 void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } 96 void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); }
97 void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } 97 void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); }
98 void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } 98 void setManager( const QString &v ) { replace( Qtopia::Manager, v ); }
99 99
100 // personal 100 // personal
101 void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } 101 void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); }
102 void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } 102 void setGender( const QString &v ) { replace( Qtopia::Gender, v ); }
103 void setBirthday( const QDate &v ); 103 void setBirthday( const QDate &v );
104 void setAnniversary( const QDate &v ); 104 void setAnniversary( const QDate &v );
105 void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } 105 void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); }
106 void setChildren( const QString &v ); 106 void setChildren( const QString &v );
107 107
108 // other 108 // other
109 void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } 109 void setNotes( const QString &v ) { replace( Qtopia::Notes, v); }
110 110
111 bool match( const QString &regexp ) const; 111 bool match( const QString &regexp ) const;
112 bool match( const QRegExp &regexp ) const; 112 bool match( const QRegExp &regexp ) const;
113 113
114// // custom 114// // custom
115// void setCustomField( const QString &key, const QString &v ) 115// void setCustomField( const QString &key, const QString &v )
116// { replace(Custom- + key, v ); } 116// { replace(Custom- + key, v ); }
117 117
118 // name 118 // name
119 QString fullName() const; 119 QString fullName() const;
120 QString title() const { return find( Qtopia::Title ); } 120 QString title() const { return find( Qtopia::Title ); }
121 QString firstName() const { return find( Qtopia::FirstName ); } 121 QString firstName() const { return find( Qtopia::FirstName ); }
122 QString middleName() const { return find( Qtopia::MiddleName ); } 122 QString middleName() const { return find( Qtopia::MiddleName ); }
123 QString lastName() const { return find( Qtopia::LastName ); } 123 QString lastName() const { return find( Qtopia::LastName ); }
124 QString suffix() const { return find( Qtopia::Suffix ); } 124 QString suffix() const { return find( Qtopia::Suffix ); }
125 QString fileAs() const { return find( Qtopia::FileAs ); } 125 QString fileAs() const { return find( Qtopia::FileAs ); }
126 126
127 // email 127 // email
128 QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } 128 QString defaultEmail() const { return find( Qtopia::DefaultEmail ); }
129 QStringList emailList() const; 129 QStringList emailList() const;
130 130
131 // home 131 // home
132 /* 132 /*
133 * OPimAddress address(enum Location)const; 133 * OPimAddress address(enum Location)const;
134 * would be some how nicer... 134 * would be some how nicer...
135 * -zecke 135 * -zecke
136 */ 136 */
137 QString homeStreet() const { return find( Qtopia::HomeStreet ); } 137 QString homeStreet() const { return find( Qtopia::HomeStreet ); }
138 QString homeCity() const { return find( Qtopia::HomeCity ); } 138 QString homeCity() const { return find( Qtopia::HomeCity ); }
139 QString homeState() const { return find( Qtopia::HomeState ); } 139 QString homeState() const { return find( Qtopia::HomeState ); }
140 QString homeZip() const { return find( Qtopia::HomeZip ); } 140 QString homeZip() const { return find( Qtopia::HomeZip ); }
141 QString homeCountry() const { return find( Qtopia::HomeCountry ); } 141 QString homeCountry() const { return find( Qtopia::HomeCountry ); }
142 QString homePhone() const { return find( Qtopia::HomePhone ); } 142 QString homePhone() const { return find( Qtopia::HomePhone ); }
143 QString homeFax() const { return find( Qtopia::HomeFax ); } 143 QString homeFax() const { return find( Qtopia::HomeFax ); }
144 QString homeMobile() const { return find( Qtopia::HomeMobile ); } 144 QString homeMobile() const { return find( Qtopia::HomeMobile ); }
145 QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } 145 QString homeWebpage() const { return find( Qtopia::HomeWebPage ); }
146 /** Multi line string containing all non-empty address info in the form 146 /** Multi line string containing all non-empty address info in the form
147 * Street 147 * Street
148 * City, State Zip 148 * City, State Zip
149 * Country 149 * Country
150 */ 150 */
151 QString displayHomeAddress() const; 151 QString displayHomeAddress() const;
152 152
153 // business 153 // business
154 QString company() const { return find( Qtopia::Company ); } 154 QString company() const { return find( Qtopia::Company ); }
155 QString businessStreet() const { return find( Qtopia::BusinessStreet ); } 155 QString businessStreet() const { return find( Qtopia::BusinessStreet ); }
156 QString businessCity() const { return find( Qtopia::BusinessCity ); } 156 QString businessCity() const { return find( Qtopia::BusinessCity ); }
157 QString businessState() const { return find( Qtopia::BusinessState ); } 157 QString businessState() const { return find( Qtopia::BusinessState ); }
158 QString businessZip() const { return find( Qtopia::BusinessZip ); } 158 QString businessZip() const { return find( Qtopia::BusinessZip ); }
159 QString businessCountry() const { return find( Qtopia::BusinessCountry ); } 159 QString businessCountry() const { return find( Qtopia::BusinessCountry ); }
160 QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } 160 QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); }
161 QString jobTitle() const { return find( Qtopia::JobTitle ); } 161 QString jobTitle() const { return find( Qtopia::JobTitle ); }
162 QString department() const { return find( Qtopia::Department ); } 162 QString department() const { return find( Qtopia::Department ); }
163 QString office() const { return find( Qtopia::Office ); } 163 QString office() const { return find( Qtopia::Office ); }
164 QString businessPhone() const { return find( Qtopia::BusinessPhone ); } 164 QString businessPhone() const { return find( Qtopia::BusinessPhone ); }
165 QString businessFax() const { return find( Qtopia::BusinessFax ); } 165 QString businessFax() const { return find( Qtopia::BusinessFax ); }
166 QString businessMobile() const { return find( Qtopia::BusinessMobile ); } 166 QString businessMobile() const { return find( Qtopia::BusinessMobile ); }
167 QString businessPager() const { return find( Qtopia::BusinessPager ); } 167 QString businessPager() const { return find( Qtopia::BusinessPager ); }
168 QString profession() const { return find( Qtopia::Profession ); } 168 QString profession() const { return find( Qtopia::Profession ); }
169 QString assistant() const { return find( Qtopia::Assistant ); } 169 QString assistant() const { return find( Qtopia::Assistant ); }
170 QString manager() const { return find( Qtopia::Manager ); } 170 QString manager() const { return find( Qtopia::Manager ); }
171 /** Multi line string containing all non-empty address info in the form 171 /** Multi line string containing all non-empty address info in the form
172 * Street 172 * Street
173 * City, State Zip 173 * City, State Zip
174 * Country 174 * Country
175 */ 175 */
176 QString displayBusinessAddress() const; 176 QString displayBusinessAddress() const;
177 177
178 //personal 178 //personal
179 QString spouse() const { return find( Qtopia::Spouse ); } 179 QString spouse() const { return find( Qtopia::Spouse ); }
180 QString gender() const { return find( Qtopia::Gender ); } 180 QString gender() const { return find( Qtopia::Gender ); }
181 QDate birthday() const; 181 QDate birthday() const;
182 QDate anniversary() const; 182 QDate anniversary() const;
183 QString nickname() const { return find( Qtopia::Nickname ); } 183 QString nickname() const { return find( Qtopia::Nickname ); }
184 QString children() const { return find( Qtopia::Children ); } 184 QString children() const { return find( Qtopia::Children ); }
185 QStringList childrenList() const; 185 QStringList childrenList() const;
186 186
187 // other 187 // other
188 QString notes() const { return find( Qtopia::Notes ); } 188 QString notes() const { return find( Qtopia::Notes ); }
189 QString groups() const { return find( Qtopia::Groups ); } 189 QString groups() const { return find( Qtopia::Groups ); }
190 QStringList groupList() const; 190 QStringList groupList() const;
191 191
192// // custom 192// // custom
193// const QString &customField( const QString &key ) 193// const QString &customField( const QString &key )
194// { return find( Custom- + key ); } 194// { return find( Custom- + key ); }
195 195
196 196
197 QString toRichText() const; 197 QString toRichText() const;
198 QMap<int, QString> toMap() const; 198 QMap<int, QString> toMap() const;
199 QString field( int key ) const { return find( key ); } 199 QString field( int key ) const { return find( key ); }
200 200
201 201
202 void setUid( int i ); 202 void setUid( int i );
203 203
204 QString toShortText()const; 204 QString toShortText()const;
205 QString OContact::type()const; 205 QString OContact::type()const;
206 QMap<QString,QString> OContact::toExtraMap() const; 206 QMap<QString,QString> OContact::toExtraMap() const;
207 class QString OContact::recordField(int) const; 207 class QString OContact::recordField(int) const;
208 208
209 // Why private ? (eilers,se) 209 // Why private ? (eilers,se)
210 QString emailSeparator() const { return " "; } 210 QString emailSeparator() const { return " "; }
211 // the emails should be seperated by a comma 211 // the emails should be seperated by a comma
212 void setEmails( const QString &v ); 212 void setEmails( const QString &v );
213 QString emails() const { return find( Qtopia::Emails ); } 213 QString emails() const { return find( Qtopia::Emails ); }
214 static int rtti();
214 215
215 216
216private: 217private:
217 // The XML-Backend needs some access to the private functions 218 // The XML-Backend needs some access to the private functions
218 friend class OContactAccessBackend_XML; 219 friend class OContactAccessBackend_XML;
219 220
220 void insert( int key, const QString &value ); 221 void insert( int key, const QString &value );
221 void replace( int key, const QString &value ); 222 void replace( int key, const QString &value );
222 QString find( int key ) const; 223 QString find( int key ) const;
223 static QStringList fields(); 224 static QStringList fields();
224 225
225 void save( QString &buf ) const; 226 void save( QString &buf ) const;
226 227
227 QString displayAddress( const QString &street, 228 QString displayAddress( const QString &street,
228 const QString &city, 229 const QString &city,
229 const QString &state, 230 const QString &state,
230 const QString &zip, 231 const QString &zip,
231 const QString &country ) const; 232 const QString &country ) const;
232 233
233 QMap<int, QString> mMap; 234 QMap<int, QString> mMap;
234 ContactPrivate *d; 235 ContactPrivate *d;
235}; 236};
236 237
237 238
238#endif 239#endif
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h
index 6de68b1..8cf81c8 100644
--- a/libopie/pim/opimaccesstemplate.h
+++ b/libopie/pim/opimaccesstemplate.h
@@ -1,259 +1,269 @@
1#ifndef OPIE_PIM_ACCESS_TEMPLATE_H 1#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
2#define OPIE_PIM_ACCESS_TEMPLATE_H 2#define OPIE_PIM_ACCESS_TEMPLATE_H
3 3
4#include <qarray.h> 4#include <qarray.h>
5 5
6#include <opie/opimrecord.h> 6#include <opie/opimrecord.h>
7#include <opie/opimaccessbackend.h> 7#include <opie/opimaccessbackend.h>
8#include <opie/orecordlist.h> 8#include <opie/orecordlist.h>
9 9
10#include "opimcache.h" 10#include "opimcache.h"
11#include "otemplatebase.h" 11#include "otemplatebase.h"
12 12
13/** 13/**
14 * Thats the frontend to our OPIE PIM 14 * Thats the frontend to our OPIE PIM
15 * Library. Either you want to use it's 15 * Library. Either you want to use it's
16 * interface or you want to implement 16 * interface or you want to implement
17 * your own Access lib 17 * your own Access lib
18 * Just create a OPimRecord and inherit from 18 * Just create a OPimRecord and inherit from
19 * the plugins 19 * the plugins
20 */ 20 */
21 21
22template <class T = OPimRecord > 22template <class T = OPimRecord >
23class OPimAccessTemplate : public OTemplateBase<T> { 23class OPimAccessTemplate : public OTemplateBase<T> {
24public: 24public:
25 typedef ORecordList<T> List; 25 typedef ORecordList<T> List;
26 typedef OPimAccessBackend<T> BackEnd; 26 typedef OPimAccessBackend<T> BackEnd;
27 typedef OPimCache<T> Cache; 27 typedef OPimCache<T> Cache;
28 28
29 /** 29 /**
30 * c'tor BackEnd 30 * c'tor BackEnd
31 */ 31 */
32 OPimAccessTemplate( BackEnd* end); 32 OPimAccessTemplate( BackEnd* end);
33 virtual ~OPimAccessTemplate(); 33 virtual ~OPimAccessTemplate();
34 34
35 /** 35 /**
36 * load from the backend 36 * load from the backend
37 */ 37 */
38 virtual bool load(); 38 virtual bool load();
39 39
40 /** Reload database. 40 /** Reload database.
41 * You should execute this function if the external database 41 * You should execute this function if the external database
42 * was changed. 42 * was changed.
43 * This function will load the external database and afterwards 43 * This function will load the external database and afterwards
44 * rejoin the local changes. Therefore the local database will be set consistent. 44 * rejoin the local changes. Therefore the local database will be set consistent.
45 */ 45 */
46 virtual bool reload(); 46 virtual bool reload();
47 47
48 /** Save contacts database. 48 /** Save contacts database.
49 * Save is more a "commit". After calling this function, all changes are public available. 49 * Save is more a "commit". After calling this function, all changes are public available.
50 * @return true if successful 50 * @return true if successful
51 */ 51 */
52 virtual bool save(); 52 virtual bool save();
53 53
54 /** 54 /**
55 * if the resource was changed externally 55 * if the resource was changed externally
56 * You should use the signal handling instead of polling possible changes ! 56 * You should use the signal handling instead of polling possible changes !
57 * zecke: Do you implement a signal for otodoaccess ? 57 * zecke: Do you implement a signal for otodoaccess ?
58 */ 58 */
59 bool wasChangedExternally()const; 59 bool wasChangedExternally()const;
60 60
61 /** 61 /**
62 * return a List of records 62 * return a List of records
63 * you can iterate over them 63 * you can iterate over them
64 */ 64 */
65 virtual List allRecords()const; 65 virtual List allRecords()const;
66 66
67 /** 67 /**
68 * queryByExample. 68 * queryByExample.
69 * @see otodoaccess, ocontactaccess 69 * @see otodoaccess, ocontactaccess
70 */ 70 */
71 virtual List queryByExample( const T& t, int querySettings ); 71 virtual List queryByExample( const T& t, int querySettings );
72 72
73 /** 73 /**
74 * find the OPimRecord uid 74 * find the OPimRecord uid
75 */ 75 */
76 virtual T find( int uid )const; 76 virtual T find( int uid )const;
77 77
78 /** 78 /**
79 * read ahead cache find method ;) 79 * read ahead cache find method ;)
80 */ 80 */
81 virtual T find( int uid, const QArray<int>&, 81 virtual T find( int uid, const QArray<int>&,
82 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; 82 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
83 83
84 /* invalidate cache here */ 84 /* invalidate cache here */
85 /** 85 /**
86 * clears the backend and invalidates the backend 86 * clears the backend and invalidates the backend
87 */ 87 */
88 virtual void clear() ; 88 virtual void clear() ;
89 89
90 /** 90 /**
91 * add T to the backend 91 * add T to the backend
92 * @param t The item to add. 92 * @param t The item to add.
93 * @return <i>true</i> if added successfully. 93 * @return <i>true</i> if added successfully.
94 */ 94 */
95 virtual bool add( const T& t ) ; 95 virtual bool add( const T& t ) ;
96 bool add( const OPimRecord& );
96 97
97 /* only the uid matters */ 98 /* only the uid matters */
98 /** 99 /**
99 * remove T from the backend 100 * remove T from the backend
100 * @param t The item to remove 101 * @param t The item to remove
101 * @return <i>true</i> if successful. 102 * @return <i>true</i> if successful.
102 */ 103 */
103 virtual bool remove( const T& t ); 104 virtual bool remove( const T& t );
104 105
105 /** 106 /**
106 * remove the OPimRecord with uid 107 * remove the OPimRecord with uid
107 * @param uid The ID of the item to remove 108 * @param uid The ID of the item to remove
108 * @return <i>true</i> if successful. 109 * @return <i>true</i> if successful.
109 */ 110 */
110 virtual bool remove( int uid ); 111 virtual bool remove( int uid );
111 112
112 /** 113 /**
113 * replace T from backend 114 * replace T from backend
114 * @param t The item to replace 115 * @param t The item to replace
115 * @return <i>true</i> if successful. 116 * @return <i>true</i> if successful.
116 */ 117 */
117 virtual bool replace( const T& t) ; 118 virtual bool replace( const T& t) ;
118 119
119 void setReadAhead( uint count ); 120 void setReadAhead( uint count );
120 /** 121 /**
121 * @internal 122 * @internal
122 */ 123 */
123 void cache( const T& )const; 124 void cache( const T& )const;
124 void setSaneCacheSize( int ); 125 void setSaneCacheSize( int );
125protected: 126protected:
126 /** 127 /**
127 * invalidate the cache 128 * invalidate the cache
128 */ 129 */
129 void invalidateCache(); 130 void invalidateCache();
130 131
131 void setBackEnd( BackEnd* end ); 132 void setBackEnd( BackEnd* end );
132 /** 133 /**
133 * returns the backend 134 * returns the backend
134 */ 135 */
135 BackEnd* backEnd(); 136 BackEnd* backEnd();
136 BackEnd* m_backEnd; 137 BackEnd* m_backEnd;
137 Cache m_cache; 138 Cache m_cache;
138 139
139}; 140};
140 141
141template <class T> 142template <class T>
142OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) 143OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
143 : OTemplateBase<T>(), m_backEnd( end ) 144 : OTemplateBase<T>(), m_backEnd( end )
144{ 145{
145 if (end ) 146 if (end )
146 end->setFrontend( this ); 147 end->setFrontend( this );
147} 148}
148template <class T> 149template <class T>
149OPimAccessTemplate<T>::~OPimAccessTemplate() { 150OPimAccessTemplate<T>::~OPimAccessTemplate() {
150 qWarning("~OPimAccessTemplate<T>"); 151 qWarning("~OPimAccessTemplate<T>");
151 delete m_backEnd; 152 delete m_backEnd;
152} 153}
153template <class T> 154template <class T>
154bool OPimAccessTemplate<T>::load() { 155bool OPimAccessTemplate<T>::load() {
155 invalidateCache(); 156 invalidateCache();
156 return m_backEnd->load(); 157 return m_backEnd->load();
157} 158}
158template <class T> 159template <class T>
159bool OPimAccessTemplate<T>::reload() { 160bool OPimAccessTemplate<T>::reload() {
160 invalidateCache(); // zecke: I think this should be added (se) 161 invalidateCache(); // zecke: I think this should be added (se)
161 return m_backEnd->reload(); 162 return m_backEnd->reload();
162} 163}
163template <class T> 164template <class T>
164bool OPimAccessTemplate<T>::save() { 165bool OPimAccessTemplate<T>::save() {
165 return m_backEnd->save(); 166 return m_backEnd->save();
166} 167}
167template <class T> 168template <class T>
168typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { 169typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
169 QArray<int> ints = m_backEnd->allRecords(); 170 QArray<int> ints = m_backEnd->allRecords();
170 List lis(ints, this ); 171 List lis(ints, this );
171 return lis; 172 return lis;
172} 173}
173template <class T> 174template <class T>
174typename OPimAccessTemplate<T>::List 175typename OPimAccessTemplate<T>::List
175OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { 176OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) {
176 QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); 177 QArray<int> ints = m_backEnd->queryByExample( t, sortOrder );
177 178
178 List lis(ints, this ); 179 List lis(ints, this );
179 return lis; 180 return lis;
180} 181}
181template <class T> 182template <class T>
182T OPimAccessTemplate<T>::find( int uid ) const{ 183T OPimAccessTemplate<T>::find( int uid ) const{
183 T t = m_backEnd->find( uid ); 184 T t = m_backEnd->find( uid );
184 cache( t ); 185 cache( t );
185 return t; 186 return t;
186} 187}
187template <class T> 188template <class T>
188T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, 189T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
189 uint current, typename OTemplateBase<T>::CacheDirection dir )const { 190 uint current, typename OTemplateBase<T>::CacheDirection dir )const {
190 /* 191 /*
191 * better do T.isEmpty() 192 * better do T.isEmpty()
192 * after a find this way we would 193 * after a find this way we would
193 * avoid two finds in QCache... 194 * avoid two finds in QCache...
194 */ 195 */
195 // qWarning("find it now %d", uid ); 196 // qWarning("find it now %d", uid );
196 if (m_cache.contains( uid ) ) { 197 if (m_cache.contains( uid ) ) {
197 return m_cache.find( uid ); 198 return m_cache.find( uid );
198 } 199 }
199 200
200 T t = m_backEnd->find( uid, ar, current, dir ); 201 T t = m_backEnd->find( uid, ar, current, dir );
201 cache( t ); 202 cache( t );
202 return t; 203 return t;
203} 204}
204template <class T> 205template <class T>
205void OPimAccessTemplate<T>::clear() { 206void OPimAccessTemplate<T>::clear() {
206 invalidateCache(); 207 invalidateCache();
207 m_backEnd->clear(); 208 m_backEnd->clear();
208} 209}
209template <class T> 210template <class T>
210bool OPimAccessTemplate<T>::add( const T& t ) { 211bool OPimAccessTemplate<T>::add( const T& t ) {
211 cache( t ); 212 cache( t );
212 return m_backEnd->add( t ); 213 return m_backEnd->add( t );
213} 214}
214template <class T> 215template <class T>
216bool OPimAccessTemplate<T>::add( const OPimRecord& rec) {
217 /* same type */
218 if ( rec.rtti() == T::rtti() ) {
219 const T &t = static_cast<const T&>(rec);
220 return add(t);
221 }
222 return false;
223}
224template <class T>
215bool OPimAccessTemplate<T>::remove( const T& t ) { 225bool OPimAccessTemplate<T>::remove( const T& t ) {
216 return remove( t.uid() ); 226 return remove( t.uid() );
217} 227}
218template <class T> 228template <class T>
219bool OPimAccessTemplate<T>::remove( int uid ) { 229bool OPimAccessTemplate<T>::remove( int uid ) {
220 m_cache.remove( uid ); 230 m_cache.remove( uid );
221 return m_backEnd->remove( uid ); 231 return m_backEnd->remove( uid );
222} 232}
223template <class T> 233template <class T>
224bool OPimAccessTemplate<T>::replace( const T& t ) { 234bool OPimAccessTemplate<T>::replace( const T& t ) {
225 m_cache.replace( t ); 235 m_cache.replace( t );
226 return m_backEnd->replace( t ); 236 return m_backEnd->replace( t );
227} 237}
228template <class T> 238template <class T>
229void OPimAccessTemplate<T>::invalidateCache() { 239void OPimAccessTemplate<T>::invalidateCache() {
230 m_cache.invalidate(); 240 m_cache.invalidate();
231} 241}
232template <class T> 242template <class T>
233typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 243typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
234 return m_backEnd; 244 return m_backEnd;
235} 245}
236template <class T> 246template <class T>
237bool OPimAccessTemplate<T>::wasChangedExternally()const { 247bool OPimAccessTemplate<T>::wasChangedExternally()const {
238 return false; 248 return false;
239} 249}
240template <class T> 250template <class T>
241void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { 251void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
242 m_backEnd = end; 252 m_backEnd = end;
243 if (m_backEnd ) 253 if (m_backEnd )
244 m_backEnd->setFrontend( this ); 254 m_backEnd->setFrontend( this );
245} 255}
246template <class T> 256template <class T>
247void OPimAccessTemplate<T>::cache( const T& t ) const{ 257void OPimAccessTemplate<T>::cache( const T& t ) const{
248 /* hacky we need to work around the const*/ 258 /* hacky we need to work around the const*/
249 ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); 259 ((OPimAccessTemplate<T>*)this)->m_cache.add( t );
250} 260}
251template <class T> 261template <class T>
252void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { 262void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
253 m_cache.setSize( size ); 263 m_cache.setSize( size );
254} 264}
255template <class T> 265template <class T>
256void OPimAccessTemplate<T>::setReadAhead( uint count ) { 266void OPimAccessTemplate<T>::setReadAhead( uint count ) {
257 m_backEnd->setReadAhead( count ); 267 m_backEnd->setReadAhead( count );
258} 268}
259#endif 269#endif
diff --git a/libopie/pim/opimmaintainer.cpp b/libopie/pim/opimmaintainer.cpp
index e34f035..92cb25a 100644
--- a/libopie/pim/opimmaintainer.cpp
+++ b/libopie/pim/opimmaintainer.cpp
@@ -1,37 +1,37 @@
1#include "opimmaintainer.h" 1#include "opimmaintainer.h"
2 2
3OPimMaintainer::OPimMaintainer( enum Mode mode, int uid ) 3OPimMaintainer::OPimMaintainer( int mode, int uid )
4 : m_mode(mode), m_uid(uid ) 4 : m_mode(mode), m_uid(uid )
5{} 5{}
6OPimMaintainer::~OPimMaintainer() { 6OPimMaintainer::~OPimMaintainer() {
7} 7}
8OPimMaintainer::OPimMaintainer( const OPimMaintainer& main ) { 8OPimMaintainer::OPimMaintainer( const OPimMaintainer& main ) {
9 *this = main; 9 *this = main;
10} 10}
11OPimMaintainer &OPimMaintainer::operator=( const OPimMaintainer& main ) { 11OPimMaintainer &OPimMaintainer::operator=( const OPimMaintainer& main ) {
12 m_mode = main.m_mode; 12 m_mode = main.m_mode;
13 m_uid = main.m_uid; 13 m_uid = main.m_uid;
14 14
15 return *this; 15 return *this;
16} 16}
17bool OPimMaintainer::operator==( const OPimMaintainer& main ) { 17bool OPimMaintainer::operator==( const OPimMaintainer& main ) {
18 if (m_mode != main.m_mode ) return false; 18 if (m_mode != main.m_mode ) return false;
19 if (m_uid != main.m_uid ) return false; 19 if (m_uid != main.m_uid ) return false;
20 20
21 return true; 21 return true;
22} 22}
23bool OPimMaintainer::operator!=( const OPimMaintainer& main ) { 23bool OPimMaintainer::operator!=( const OPimMaintainer& main ) {
24 return !(*this == main ); 24 return !(*this == main );
25} 25}
26OPimMaintainer::Mode OPimMaintainer::mode()const { 26int OPimMaintainer::mode()const {
27 return m_mode; 27 return m_mode;
28} 28}
29int OPimMaintainer::uid()const { 29int OPimMaintainer::uid()const {
30 return m_uid; 30 return m_uid;
31} 31}
32void OPimMaintainer::setMode( enum Mode mo) { 32void OPimMaintainer::setMode( int mo) {
33 m_mode = mo; 33 m_mode = mo;
34} 34}
35void OPimMaintainer::setUid( int uid ) { 35void OPimMaintainer::setUid( int uid ) {
36 m_uid = uid; 36 m_uid = uid;
37} 37}
diff --git a/libopie/pim/opimmaintainer.h b/libopie/pim/opimmaintainer.h
index 310e15a..793d066 100644
--- a/libopie/pim/opimmaintainer.h
+++ b/libopie/pim/opimmaintainer.h
@@ -1,36 +1,40 @@
1#ifndef OPIE_PIM_MAINTAINER_H 1#ifndef OPIE_PIM_MAINTAINER_H
2#define OPIE_PIM_MAINTAINER_H 2#define OPIE_PIM_MAINTAINER_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5 5
6/** 6/**
7 * Who maintains what? 7 * Who maintains what?
8 */ 8 */
9class OPimMaintainer { 9class OPimMaintainer {
10public: 10public:
11 enum Mode { Undefined = -1, 11 enum Mode { Undefined = -1,
12 Responsible = 0, 12 Nothing = 0,
13 Responsible,
13 DoneBy, 14 DoneBy,
14 Coordinating }; 15 Coordinating,
15 OPimMaintainer( enum Mode mode = Undefined, int uid = 0); 16 };
17 OPimMaintainer( int mode = Undefined, int uid = 0);
16 OPimMaintainer( const OPimMaintainer& ); 18 OPimMaintainer( const OPimMaintainer& );
17 ~OPimMaintainer(); 19 ~OPimMaintainer();
18 20
19 OPimMaintainer &operator=( const OPimMaintainer& ); 21 OPimMaintainer &operator=( const OPimMaintainer& );
20 bool operator==( const OPimMaintainer& ); 22 bool operator==( const OPimMaintainer& );
21 bool operator!=( const OPimMaintainer& ); 23 bool operator!=( const OPimMaintainer& );
22 24
23 25
24 Mode mode()const; 26 int mode()const;
25 int uid()const; 27 int uid()const;
26 28
27 void setMode( enum Mode ); 29 void setMode( int mode );
28 void setUid( int uid ); 30 void setUid( int uid );
29 31
30private: 32private:
31 Mode m_mode; 33 int m_mode;
32 int m_uid; 34 int m_uid;
35 class Private;
36 Private *d;
33 37
34}; 38};
35 39
36#endif 40#endif
diff --git a/libopie/pim/opimmainwindow.cpp b/libopie/pim/opimmainwindow.cpp
new file mode 100644
index 0000000..92be2fd
--- a/dev/null
+++ b/libopie/pim/opimmainwindow.cpp
@@ -0,0 +1,71 @@
1#include <qapplication.h>
2#include <qcopchannel_qws.h>
3
4#include <qpe/qcopenvelope_qws.h>
5
6#include "opimmainwindow.h"
7
8OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent,
9 const char* name, WFlags flag )
10 : QMainWindow( parent, name, flag ), m_service( service ), m_fallBack(0l) {
11
12 /*
13 * let's generate our QCopChannel
14 */
15 m_str = QString("QPE/"+m_service).local8Bit();
16 m_channel= new QCopChannel(m_str, this );
17 connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ),
18 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) );
19
20 /* connect flush and reload */
21 connect(qApp, SIGNAL(flush() ),
22 this, SLOT(flush() ) );
23 connect(qApp, SIGNAL(reload() ),
24 this, SLOT(reload() ) );
25}
26OPimMainWindow::~OPimMainWindow() {
27 delete m_channel;
28}
29QCopChannel* OPimMainWindow::channel() {
30 return m_channel;
31}
32void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) {
33 /*
34 * create demands to create
35 * a new record...
36 */
37 QDataStream stream(array, IO_ReadOnly);
38 if ( cmd == "create()" ) {
39 int uid = create();
40 QCopEnvelope e(m_str, "created(int)" );
41 e << uid;
42 }else if ( cmd == "remove(int)" ) {
43 int uid;
44 stream >> uid;
45 bool rem = remove( uid );
46 QCopEnvelope e(m_str, "removed(bool)" );
47 e << rem;
48 }else if ( cmd == "beam(int,int)" ) {
49 int uid, trans;
50 stream >> uid;
51 stream >> trans;
52 beam( uid, trans );
53 }else if ( cmd == "show(int)" ) {
54 int uid;
55 stream >> uid;
56 show( uid );
57 }else if ( cmd == "edit(int)" ) {
58 int uid;
59 stream >> uid;
60 edit( uid );
61 }else if ( cmd == "add(int,QByteArray)" ) {
62 int rtti;
63 QByteArray array;
64 stream >> rtti;
65 stream >> array;
66 m_fallBack = record(rtti, array );
67 if (!m_fallBack) return;
68 add( *m_fallBack );
69 delete m_fallBack;
70 }
71}
diff --git a/libopie/pim/opimmainwindow.h b/libopie/pim/opimmainwindow.h
new file mode 100644
index 0000000..94100bd
--- a/dev/null
+++ b/libopie/pim/opimmainwindow.h
@@ -0,0 +1,79 @@
1#ifndef OPIE_PIM_MAINWINDOW_H
2#define OPIE_PIM_MAINWINDOW_H
3
4#include <qmainwindow.h>
5
6#include <opie/opimrecord.h>
7
8/**
9 * This is a common Opie PIM MainWindow
10 * it takes care of the QCOP internals
11 * and implements some functions
12 * for the URL scripting schema
13 */
14/*
15 * due Qt and Templates with signal and slots
16 * do not work that good :(
17 * (Ok how to moc a template ;) )
18 * We will have the mainwindow which calls a struct which
19 * is normally reimplemented as a template ;)
20 */
21
22class QCopChannel;
23class OPimMainWindow : public QMainWindow {
24 Q_OBJECT
25public:
26 enum TransPort { BlueTooth=0,
27 IrDa };
28
29 OPimMainWindow( const QString& service, QWidget *parent = 0, const char* name = 0,
30 WFlags f = WType_TopLevel);
31 virtual ~OPimMainWindow();
32
33
34protected slots:
35 /* for syncing */
36 virtual void flush() = 0;
37 virtual void reload() = 0;
38
39 /** create a new Records and return the uid */
40 virtual int create() = 0;
41 /** remove a record with UID == uid */
42 virtual bool remove( int uid ) = 0;
43 /** beam the record with UID = uid */
44 virtual void beam( int uid , int transport = IrDa) = 0;
45
46 /** show the record with UID == uid */
47 virtual void show( int uid ) = 0;
48 /** edit the record */
49 virtual void edit( int uid ) = 0;
50
51 /** make a copy of it! */
52 virtual void add( const OPimRecord& ) = 0;
53
54 /* I would love to do this as a template
55 * but can't think of a right way
56 * because I need signal and slots -zecke
57 */
58 /*
59 * the only pointer in the whole PIM API :(
60 */
61 virtual OPimRecord* record( int rtti, const QByteArray& ) = 0;
62 QCopChannel* channel();
63
64private slots:
65 void appMessage( const QCString&, const QByteArray& );
66
67
68private:
69 class Private;
70 Private* d;
71
72 QCopChannel* m_channel;
73 QString m_service;
74 QCString m_str;
75 OPimRecord* m_fallBack;
76};
77
78
79#endif
diff --git a/libopie/pim/opimnotify.cpp b/libopie/pim/opimnotify.cpp
new file mode 100644
index 0000000..af5514b
--- a/dev/null
+++ b/libopie/pim/opimnotify.cpp
@@ -0,0 +1,227 @@
1#include <qshared.h>
2
3#include "opimnotify.h"
4
5struct OPimNotify::Data : public QShared {
6 Data() : QShared(),dur(-1),parent(0) {
7
8 }
9 QDateTime start;
10 int dur;
11 QString application;
12 int parent;
13};
14
15OPimNotify::OPimNotify( const QDateTime& start, int duration, int parent ) {
16 data = new Data;
17 data->start = start;
18 data->dur = duration;
19 data->parent = parent;
20}
21OPimNotify::OPimNotify( const OPimNotify& noti)
22 : data( noti.data )
23{
24 data->ref();
25}
26OPimNotify::~OPimNotify() {
27 if ( data->deref() ) {
28 delete data;
29 data = 0l;
30 }
31}
32
33OPimNotify &OPimNotify::operator=( const OPimNotify& noti) {
34 noti.data->ref();
35 deref();
36 data = noti.data;
37
38 return *this;
39}
40bool OPimNotify::operator==( const OPimNotify& noti ) {
41 if ( data == noti.data ) return true;
42 if ( data->dur != noti.data->dur ) return false;
43 if ( data->parent != noti.data->parent ) return false;
44 if ( data->application != noti.data->application ) return false;
45 if ( data->start != noti.data->start ) return false;
46
47 return true;
48}
49QDateTime OPimNotify::dateTime()const {
50 return data->start;
51}
52QString OPimNotify::service()const {
53 return data->application;
54}
55int OPimNotify::parent()const {
56 return data->parent;
57}
58int OPimNotify::duration()const {
59 return data->dur;
60}
61QDateTime OPimNotify::endTime()const {
62 return QDateTime( data->start.date(), data->start.time().addSecs( data->dur) );
63}
64void OPimNotify::setDateTime( const QDateTime& time ) {
65 copyIntern();
66 data->start = time;
67}
68void OPimNotify::setDuration( int dur ) {
69 copyIntern();
70 data->dur = dur;
71}
72void OPimNotify::setParent( int uid ) {
73 copyIntern();
74 data->parent = uid;
75}
76void OPimNotify::setService( const QString& str ) {
77 copyIntern();
78 data->application = str;
79}
80void OPimNotify::copyIntern() {
81 if ( data->count != 1 ) {
82 data->deref();
83 Data* dat = new Data;
84 dat->start = data->start;
85 dat->dur = data->dur;
86 dat->application = data->application;
87 dat->parent = data->parent;
88 data = dat;
89 }
90}
91void OPimNotify::deref() {
92 if ( data->deref() ) {
93 delete data;
94 data = 0;
95 }
96}
97
98/***********************************************************/
99struct OPimAlarm::Data : public QShared {
100 Data() : QShared() {
101 sound = 1;
102 }
103 int sound;
104 QString file;
105};
106OPimAlarm::OPimAlarm( int sound, const QDateTime& start, int duration, int parent )
107 : OPimNotify( start, duration, parent )
108{
109 data = new Data;
110 data->sound = sound;
111}
112OPimAlarm::OPimAlarm( const OPimAlarm& al)
113 : OPimNotify(al), data( al.data )
114{
115 data->ref();
116}
117OPimAlarm::~OPimAlarm() {
118 if ( data->deref() ) {
119 delete data;
120 data = 0l;
121 }
122}
123OPimAlarm &OPimAlarm::operator=( const OPimAlarm& al)
124{
125 OPimNotify::operator=( al );
126 deref();
127 al.data->ref();
128
129 data = al.data;
130
131
132 return *this;
133}
134bool OPimAlarm::operator==( const OPimAlarm& al) {
135 if ( data->sound != al.data->sound ) return false;
136 else if ( data->sound == Custom && data->file != al.data->file )
137 return false;
138
139 return OPimNotify::operator==( al );
140}
141QString OPimAlarm::type()const {
142 return QString::fromLatin1("OPimAlarm");
143}
144int OPimAlarm::sound()const {
145 return data->sound;
146}
147QString OPimAlarm::file()const {
148 return data->file;
149}
150void OPimAlarm::setSound( int snd) {
151 copyIntern();
152 data->sound = snd;
153}
154void OPimAlarm::setFile( const QString& sound ) {
155 copyIntern();
156 data->file = sound;
157}
158void OPimAlarm::deref() {
159 if ( data->deref() ) {
160 delete data;
161 data = 0l;
162 }
163}
164void OPimAlarm::copyIntern() {
165 if ( data->count != 1 ) {
166 data->deref();
167 Data *newDat = new Data;
168 newDat->sound = data->sound;
169 newDat->file = data->file;
170 data = newDat;
171 }
172}
173/************************/
174struct OPimReminder::Data : public QShared {
175 Data() : QShared(), record( 0) {
176 }
177 int record;
178
179};
180OPimReminder::OPimReminder( int uid, const QDateTime& start, int dur, int parent )
181 : OPimNotify( start, dur, parent )
182{
183 data = new Data;
184 data->record = uid;
185}
186OPimReminder::OPimReminder( const OPimReminder& rem )
187 : OPimNotify( rem ), data( rem.data )
188{
189 data->ref();
190}
191OPimReminder& OPimReminder::operator=( const OPimReminder& rem) {
192 OPimNotify::operator=(rem );
193
194 deref();
195 rem.data->ref();
196 data = rem.data;
197
198 return *this;
199}
200bool OPimReminder::operator==( const OPimReminder& rem) {
201 if ( data->record != rem.data->record ) return false;
202
203 return OPimNotify::operator==( rem );
204}
205QString OPimReminder::type()const {
206 return QString::fromLatin1("OPimReminder");
207}
208int OPimReminder::recordUid()const {
209 return data->record;
210}
211void OPimReminder::setRecordUid( int uid ) {
212 copyIntern();
213 data->record = uid;
214}
215void OPimReminder::deref() {
216 if ( data->deref() ) {
217 delete data;
218 data = 0l;
219 }
220}
221void OPimReminder::copyIntern() {
222 if ( data->count != 1 ) {
223 Data* da = new Data;
224 da->record = data->record;
225 data = da;
226 }
227}
diff --git a/libopie/pim/opimnotify.h b/libopie/pim/opimnotify.h
new file mode 100644
index 0000000..3501948
--- a/dev/null
+++ b/libopie/pim/opimnotify.h
@@ -0,0 +1,142 @@
1#ifndef OPIE_PIM_NOTIFY_H
2#define OPIE_PIM_NOTIFY_H
3
4#include <qdatetime.h>
5#include <qvaluelist.h>
6
7/**
8 * This is the base class of Notifiers. Possible
9 * notifiers would be Alarms, Reminders
10 * What they share is that they have
11 * A DateTime, Type, Duration
12 * This is what this base class takes care of
13 * on top of that it's shared
14 */
15/*
16 * TALK to eilers: have a class OPimDuration which sets the Duration
17 * given on the Due/Start Date? -zecke
18 * discuss: do we need a uid for the notify? -zecke
19 */
20class OPimNotify {
21public:
22 typedef QValueList<OPimNotify> ValueList;
23 OPimNotify( const QDateTime& start = QDateTime(), int duration = 0, int parent = 0 );
24 OPimNotify( const OPimNotify& );
25 virtual ~OPimNotify();
26
27 OPimNotify &operator=(const OPimNotify& );
28 bool operator==( const OPimNotify& );
29
30 virtual QString type()const = 0;
31
32 /** start date */
33 QDateTime dateTime()const;
34 QString service()const;
35
36 /**
37 * RETURN the parent uid
38 */
39 int parent()const;
40
41 /**
42 * in Seconds
43 */
44 int duration()const;
45
46 /**
47 * Start Time + Duration
48 */
49 QDateTime endTime()const;
50
51 void setDateTime( const QDateTime& );
52 void setDuration( int dur );
53 void setParent(int uid );
54 void setService( const QString& );
55
56
57private:
58 inline void copyIntern();
59 void deref();
60 struct Data;
61 Data* data;
62
63 /* d-pointer */
64 class NotifyPrivate;
65 NotifyPrivate* d;
66
67};
68/**
69 * An alarm is a sound/mail/buzzer played/send
70 * at a given time to inform about
71 * an Event
72 */
73class OPimAlarm : public OPimNotify {
74public:
75 enum Sound{Loud=0, Silent, Custom };
76 OPimAlarm( int sound = Silent, const QDateTime& start = QDateTime(), int duration = 0, int parent = 0 );
77 OPimAlarm( const OPimAlarm& );
78 ~OPimAlarm();
79
80 OPimAlarm &operator=( const OPimAlarm& );
81 bool operator==( const OPimAlarm& );
82 QString type()const;
83
84 int sound()const;
85 QString file()const;
86
87 void setSound( int );
88 /* only when sound is custom... */
89 void setFile( const QString& sound );
90
91private:
92 void deref();
93 void copyIntern();
94 struct Data;
95 Data * data;
96
97 class Private;
98 Private* d;
99
100};
101
102/**
103 * A Reminder will be put into the
104 * datebook
105 */
106class OPimReminder : public OPimNotify {
107public:
108
109 /**
110 * c'tor of a reminder
111 * @param uid The uid of the Record inside the Datebook
112 * @param start the StartDate invalid for all day...
113 * @param duration The duration of the event ( -1 for all day )
114 * @param parent The 'parent' record of this reminder
115 */
116 OPimReminder( int uid = 0, const QDateTime& start = QDateTime(),
117 int duration = 0, int parent = 0 );
118 OPimReminder( const OPimReminder& );
119 OPimReminder &operator=(const OPimReminder& );
120
121 QString type()const;
122
123 bool operator==( const OPimReminder& );
124
125 /**
126 * the uid of the alarm
127 * inside the 'datebook' application
128 */
129 int recordUid()const;
130 void setRecordUid( int uid );
131
132private:
133 void deref();
134 void copyIntern();
135
136 struct Data;
137 Data* data;
138 class Private;
139 Private *d;
140};
141
142#endif
diff --git a/libopie/pim/opimnotifymanager.cpp b/libopie/pim/opimnotifymanager.cpp
new file mode 100644
index 0000000..be4a1c2
--- a/dev/null
+++ b/libopie/pim/opimnotifymanager.cpp
@@ -0,0 +1,69 @@
1#include "opimnotifymanager.h"
2
3OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al)
4 : m_rem( rem ), m_al( al )
5{}
6OPimNotifyManager::~OPimNotifyManager() {
7}
8/* use static_cast and type instead of dynamic... */
9void OPimNotifyManager::add( const OPimNotify& noti) {
10 if ( noti.type() == QString::fromLatin1("OPimReminder") ) {
11 const OPimReminder& rem = static_cast<const OPimReminder&>(noti);
12 m_rem.append( rem );
13 }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) {
14 const OPimAlarm& al = static_cast<const OPimAlarm&>(noti);
15 m_al.append( al );
16 }
17}
18void OPimNotifyManager::remove( const OPimNotify& noti) {
19 if ( noti.type() == QString::fromLatin1("OPimReminder") ) {
20 const OPimReminder& rem = static_cast<const OPimReminder&>(noti);
21 m_rem.remove( rem );
22 }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) {
23 const OPimAlarm& al = static_cast<const OPimAlarm&>(noti);
24 m_al.remove( al );
25 }
26}
27void OPimNotifyManager::replace( const OPimNotify& noti) {
28 if ( noti.type() == QString::fromLatin1("OPimReminder") ) {
29 const OPimReminder& rem = static_cast<const OPimReminder&>(noti);
30 m_rem.remove( rem );
31 m_rem.append( rem );
32 }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) {
33 const OPimAlarm& al = static_cast<const OPimAlarm&>(noti);
34 m_al.remove( al );
35 m_al.append( al );
36 }
37}
38OPimNotifyManager::Reminders OPimNotifyManager::reminders()const {
39 return m_rem;
40}
41OPimNotifyManager::Alarms OPimNotifyManager::alarms()const {
42 return m_al;
43}
44void OPimNotifyManager::setAlarms( const Alarms& al) {
45 m_al = al;
46}
47void OPimNotifyManager::setReminders( const Reminders& rem) {
48 m_rem = rem;
49}
50/* FIXME!!! */
51/**
52 * The idea is to check if the provider for our service
53 * is online
54 * if it is we will use QCOP
55 * if not the Factory to get the backend...
56 * Qtopia1.6 services would be kewl to have here....
57 */
58void OPimNotifyManager::registerNotify( const OPimNotify& ) {
59
60}
61/* FIXME!!! */
62/**
63 * same as above...
64 * Also implement Url model
65 * have a MainWindow....
66 */
67void OPimNotifyManager::deregister( const OPimNotify& ) {
68
69}
diff --git a/libopie/pim/opimnotifymanager.h b/libopie/pim/opimnotifymanager.h
new file mode 100644
index 0000000..0eebc9b
--- a/dev/null
+++ b/libopie/pim/opimnotifymanager.h
@@ -0,0 +1,51 @@
1#ifndef OPIE_PIM_NOTIFY_MANAGER_H
2#define OPIE_PIM_NOTIFY_MANAGER_H
3
4#include <qvaluelist.h>
5
6#include <opie/opimnotify.h>
7
8/**
9 * The notify manager keeps track of the Notifiers....
10 */
11class OPimNotifyManager {
12public:
13 typedef QValueList<OPimReminder> Reminders;
14 typedef QValueList<OPimAlarm> Alarms;
15 OPimNotifyManager( const Reminders& rems = Reminders(), const Alarms& alarms = Alarms() );
16 ~OPimNotifyManager();
17
18 /* we will cast it for you ;) */
19 void add( const OPimNotify& );
20 void remove( const OPimNotify& );
21 /* replaces all with this one! */
22 void replace( const OPimNotify& );
23
24 Reminders reminders()const;
25 Alarms alarms()const;
26
27 void setAlarms( const Alarms& );
28 void setReminders( const Reminders& );
29
30 /* register is a Ansi C keyword... */
31 /**
32 * This function will register the Notify to the Alarm Server
33 * or datebook depending on the type of the notify
34 */
35 void registerNotify( const OPimNotify& );
36
37 /**
38 * this will do the opposite..
39 */
40 void deregister( const OPimNotify& );
41
42private:
43 Reminders m_rem;
44 Alarms m_al;
45
46 class Private;
47 Private *d;
48
49};
50
51#endif
diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp
index 0e3be9d..49b5bf9 100644
--- a/libopie/pim/opimrecord.cpp
+++ b/libopie/pim/opimrecord.cpp
@@ -1,81 +1,84 @@
1#include <qpe/categories.h> 1#include <qpe/categories.h>
2#include <qpe/categoryselect.h> 2#include <qpe/categoryselect.h>
3 3
4#include "opimrecord.h" 4#include "opimrecord.h"
5 5
6Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); 6Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
7 7
8 8
9OPimRecord::OPimRecord( int uid ) 9OPimRecord::OPimRecord( int uid )
10 : Qtopia::Record() { 10 : Qtopia::Record() {
11 11
12 setUid( uid ); 12 setUid( uid );
13} 13}
14OPimRecord::~OPimRecord() { 14OPimRecord::~OPimRecord() {
15} 15}
16OPimRecord::OPimRecord( const OPimRecord& rec ) 16OPimRecord::OPimRecord( const OPimRecord& rec )
17 : Qtopia::Record( rec ) 17 : Qtopia::Record( rec )
18{ 18{
19 (*this) = rec; 19 (*this) = rec;
20} 20}
21 21
22OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { 22OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
23 Qtopia::Record::operator=( rec ); 23 Qtopia::Record::operator=( rec );
24 m_xrefman = rec.m_xrefman; 24 m_xrefman = rec.m_xrefman;
25 25
26 return *this; 26 return *this;
27} 27}
28/* 28/*
29 * category names 29 * category names
30 */ 30 */
31QStringList OPimRecord::categoryNames()const { 31QStringList OPimRecord::categoryNames()const {
32 QStringList list; 32 QStringList list;
33 QArray<int> cats = categories(); 33 QArray<int> cats = categories();
34 Categories catDB; 34 Categories catDB;
35 catDB.load( categoryFileName() ); 35 catDB.load( categoryFileName() );
36 36
37 for (uint i = 0; i < cats.count(); i++ ) { 37 for (uint i = 0; i < cats.count(); i++ ) {
38 list << catDB.label("Todo List", cats[i] ); 38 list << catDB.label("Todo List", cats[i] );
39 } 39 }
40 40
41 return list; 41 return list;
42} 42}
43void OPimRecord::setCategoryNames( const QStringList& ) { 43void OPimRecord::setCategoryNames( const QStringList& ) {
44 44
45} 45}
46void OPimRecord::addCategoryName( const QString& ) { 46void OPimRecord::addCategoryName( const QString& ) {
47 Categories catDB; 47 Categories catDB;
48 catDB.load( categoryFileName() ); 48 catDB.load( categoryFileName() );
49 49
50 50
51} 51}
52bool OPimRecord::isEmpty()const { 52bool OPimRecord::isEmpty()const {
53 return ( uid() == 0 ); 53 return ( uid() == 0 );
54} 54}
55/*QString OPimRecord::crossToString()const { 55/*QString OPimRecord::crossToString()const {
56 QString str; 56 QString str;
57 QMap<QString, QArray<int> >::ConstIterator it; 57 QMap<QString, QArray<int> >::ConstIterator it;
58 for (it = m_relations.begin(); it != m_relations.end(); ++it ) { 58 for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
59 QArray<int> id = it.data(); 59 QArray<int> id = it.data();
60 for ( uint i = 0; i < id.size(); ++i ) { 60 for ( uint i = 0; i < id.size(); ++i ) {
61 str += it.key() + "," + QString::number( i ) + ";"; 61 str += it.key() + "," + QString::number( i ) + ";";
62 } 62 }
63 } 63 }
64 str = str.remove( str.length()-1, 1); // strip the ; 64 str = str.remove( str.length()-1, 1); // strip the ;
65 //qWarning("IDS " + str ); 65 //qWarning("IDS " + str );
66 66
67 return str; 67 return str;
68 }*/ 68 }*/
69/* if uid = 1 assign a new one */ 69/* if uid = 1 assign a new one */
70void OPimRecord::setUid( int uid ) { 70void OPimRecord::setUid( int uid ) {
71 if ( uid == 1) 71 if ( uid == 1)
72 uid = uidGen().generate(); 72 uid = uidGen().generate();
73 73
74 Qtopia::Record::setUid( uid ); 74 Qtopia::Record::setUid( uid );
75}; 75};
76Qtopia::UidGen &OPimRecord::uidGen() { 76Qtopia::UidGen &OPimRecord::uidGen() {
77 return m_uidGen; 77 return m_uidGen;
78} 78}
79OPimXRefManager &OPimRecord::xrefmanager() { 79OPimXRefManager &OPimRecord::xrefmanager() {
80 return m_xrefman; 80 return m_xrefman;
81} 81}
82int OPimRecord::rtti(){
83 return 0;
84}
diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h
index 1642a5e..ec99a13 100644
--- a/libopie/pim/opimrecord.h
+++ b/libopie/pim/opimrecord.h
@@ -1,116 +1,122 @@
1#ifndef OPIE_PIM_RECORD_H 1#ifndef OPIE_PIM_RECORD_H
2#define OPIE_PIM_RECORD_H 2#define OPIE_PIM_RECORD_H
3 3
4#include <qmap.h> 4#include <qmap.h>
5#include <qstring.h> 5#include <qstring.h>
6#include <qstringlist.h> 6#include <qstringlist.h>
7 7
8#include <qpe/palmtoprecord.h> 8#include <qpe/palmtoprecord.h>
9 9
10#include <opie/opimxrefmanager.h> 10#include <opie/opimxrefmanager.h>
11 11
12/** 12/**
13 * This is the base class for 13 * This is the base class for
14 * all PIM Records 14 * all PIM Records
15 * 15 *
16 */ 16 */
17class OPimRecord : public Qtopia::Record { 17class OPimRecord : public Qtopia::Record {
18public: 18public:
19 /** 19 /**
20 * c'tor 20 * c'tor
21 * uid of 0 isEmpty 21 * uid of 0 isEmpty
22 * uid of 1 will be assigned a new one 22 * uid of 1 will be assigned a new one
23 */ 23 */
24 OPimRecord(int uid = 0); 24 OPimRecord(int uid = 0);
25 ~OPimRecord(); 25 ~OPimRecord();
26 26
27 /** 27 /**
28 * copy c'tor 28 * copy c'tor
29 */ 29 */
30 OPimRecord( const OPimRecord& rec ); 30 OPimRecord( const OPimRecord& rec );
31 31
32 /** 32 /**
33 * copy operator 33 * copy operator
34 */ 34 */
35 OPimRecord &operator=( const OPimRecord& ); 35 OPimRecord &operator=( const OPimRecord& );
36 36
37 /** 37 /**
38 * category names resolved 38 * category names resolved
39 */ 39 */
40 QStringList categoryNames()const; 40 QStringList categoryNames()const;
41 41
42 /** 42 /**
43 * set category names they will be resolved 43 * set category names they will be resolved
44 */ 44 */
45 void setCategoryNames( const QStringList& ); 45 void setCategoryNames( const QStringList& );
46 46
47 /** 47 /**
48 * addCategoryName adds a name 48 * addCategoryName adds a name
49 * to the internal category list 49 * to the internal category list
50 */ 50 */
51 void addCategoryName( const QString& ); 51 void addCategoryName( const QString& );
52 52
53 /** 53 /**
54 * if a Record isEmpty 54 * if a Record isEmpty
55 * it's empty if it's 0 55 * it's empty if it's 0
56 */ 56 */
57 virtual bool isEmpty()const; 57 virtual bool isEmpty()const;
58 58
59 /** 59 /**
60 * toRichText summary 60 * toRichText summary
61 */ 61 */
62 virtual QString toRichText()const = 0; 62 virtual QString toRichText()const = 0;
63 63
64 /** 64 /**
65 * a small one line summary 65 * a small one line summary
66 */ 66 */
67 virtual QString toShortText()const = 0; 67 virtual QString toShortText()const = 0;
68 68
69 /** 69 /**
70 * the name of the Record 70 * the name of the Record
71 */ 71 */
72 virtual QString type()const = 0; 72 virtual QString type()const = 0;
73 73
74 /** 74 /**
75 * converts the internal structure to a map 75 * converts the internal structure to a map
76 */ 76 */
77 virtual QMap<int, QString> toMap()const = 0; 77 virtual QMap<int, QString> toMap()const = 0;
78 78
79 /** 79 /**
80 * key value representation of extra items 80 * key value representation of extra items
81 */ 81 */
82 virtual QMap<QString, QString> toExtraMap()const = 0; 82 virtual QMap<QString, QString> toExtraMap()const = 0;
83 83
84 /** 84 /**
85 * the name for a recordField 85 * the name for a recordField
86 */ 86 */
87 virtual QString recordField(int)const = 0; 87 virtual QString recordField(int)const = 0;
88 88
89 /** 89 /**
90 * returns a reference of the 90 * returns a reference of the
91 * Cross Reference Manager 91 * Cross Reference Manager
92 * Partner One is THIS PIM RECORD! 92 * Partner 'One' is THIS PIM RECORD!
93 * Two is the Partner where we link to 93 * 'Two' is the Partner where we link to
94 */ 94 */
95 OPimXRefManager& xrefmanager(); 95 OPimXRefManager& xrefmanager();
96 96
97 /** 97 /**
98 * set the uid 98 * set the uid
99 */ 99 */
100 virtual void setUid( int uid ); 100 virtual void setUid( int uid );
101 101
102 /*
103 * used inside the Templates for casting
104 * REIMPLEMENT in your ....
105 */
106 static int rtti();
107
102protected: 108protected:
103 Qtopia::UidGen &uidGen(); 109 Qtopia::UidGen &uidGen();
104// QString crossToString()const; 110// QString crossToString()const;
105 111
106private: 112private:
107 class OPimRecordPrivate; 113 class OPimRecordPrivate;
108 OPimRecordPrivate *d; 114 OPimRecordPrivate *d;
109 OPimXRefManager m_xrefman; 115 OPimXRefManager m_xrefman;
110 static Qtopia::UidGen m_uidGen; 116 static Qtopia::UidGen m_uidGen;
111 117
112}; 118};
113 119
114 120
115 121
116#endif 122#endif
diff --git a/libopie/pim/opimresolver.h b/libopie/pim/opimresolver.h
new file mode 100644
index 0000000..86ae3eb
--- a/dev/null
+++ b/libopie/pim/opimresolver.h
@@ -0,0 +1,56 @@
1#ifndef OPIE_PIM_RESOLVER
2#define OPIE_PIM_RESOLVER
3
4#include <qstring.h>
5#include <qvaluelist.h>
6
7/**
8 * OPimResolver is a MetaClass to access
9 * available backends read only.
10 * It will be used to resolve uids + app names
11 * to full informations
12 * to traverse through a list of alarms, reminders
13 * to get access to built in PIM functionality
14 * and to more stuff
15 * THE PERFORMANCE will depend on THE BACKEND
16 * USING XML is a waste of memory!!!!!
17 */
18class OPimResolver : public QObject {
19public:
20 enum BuiltIn { TodoList = 0,
21 DateBook,
22 AddressBook
23 };
24 static OPimResolver* self();
25
26
27 /*
28 * return a record for a uid
29 * and an app
30 */
31 OPimRecord &record( const QString& service, int uid );
32
33 /**
34 * return the QCopChannel for service
35 * When we will use Qtopia Services it will be used here
36 */
37 QString qcopChannel( enum BuiltIn& )const;
38 QString qcopChannel( const QString& service );
39
40 /**
41 * return a list of available services
42 */
43 QStringList services()const;
44
45 /**
46 * add a record to a service... ;)
47 */
48 bool add( const QString& service, const OPimRecord& );
49
50private:
51 OPimResolver();
52 OPimRecord *m_last;
53
54}:
55
56#endif
diff --git a/libopie/pim/opimxref.cpp b/libopie/pim/opimxref.cpp
index 5cae871..8eefbd8 100644
--- a/libopie/pim/opimxref.cpp
+++ b/libopie/pim/opimxref.cpp
@@ -1,47 +1,47 @@
1#include "opimxref.h" 1#include "opimxref.h"
2 2
3OPimXRef::OPimXRef( const OPimXRefPartner& one, const OPimXRefPartner& two ) 3OPimXRef::OPimXRef( const OPimXRefPartner& one, const OPimXRefPartner& two )
4 : m_partners(2) 4 : m_partners(2)
5{ 5{
6 m_partners[0] = one; 6 m_partners[0] = one;
7 m_partners[1] = two; 7 m_partners[1] = two;
8} 8}
9OPimXRef::OPimXRef() 9OPimXRef::OPimXRef()
10 : m_partners(2) 10 : m_partners(2)
11{ 11{
12 12
13} 13}
14OPimXRef::OPimXRef( const OPimXRef& ref) { 14OPimXRef::OPimXRef( const OPimXRef& ref) {
15 *this = ref; 15 *this = ref;
16} 16}
17OPimXRef::~OPimXRef() { 17OPimXRef::~OPimXRef() {
18} 18}
19OPimXRef &OPimXRef::operator=( const OPimXRef& ref) { 19OPimXRef &OPimXRef::operator=( const OPimXRef& ref) {
20 m_partners = ref.m_partners; 20 m_partners = ref.m_partners;
21 m_partners.detach(); 21 m_partners.detach();
22 22
23 return* this; 23 return* this;
24} 24}
25bool OPimXRef::operator==( const OPimXRef& oper ) { 25bool OPimXRef::operator==( const OPimXRef& oper ) {
26 if ( m_partners == oper.m_partners ) return true; 26 if ( m_partners == oper.m_partners ) return true;
27 27
28 return false; 28 return false;
29} 29}
30OPimXRefPartner OPimXRef::partner( enum Partners par) const{ 30OPimXRefPartner OPimXRef::partner( enum Partners par) const{
31 return m_partners[par]; 31 return m_partners[par];
32} 32}
33void OPimXRef::setPartner( enum Partners par, const OPimXRefPartner& part) { 33void OPimXRef::setPartner( enum Partners par, const OPimXRefPartner& part) {
34 m_partners[par] = part; 34 m_partners[par] = part;
35} 35}
36bool OPimXRef::containsString( const QString& string ) const{ 36bool OPimXRef::containsString( const QString& string ) const{
37 if ( m_partners[One].appName() == string || 37 if ( m_partners[One].service() == string ||
38 m_partners[Two].appName() == string ) return true; 38 m_partners[Two].service() == string ) return true;
39 39
40 return false; 40 return false;
41} 41}
42bool OPimXRef::containsUid( int uid ) const{ 42bool OPimXRef::containsUid( int uid ) const{
43 if ( m_partners[One].uid() == uid || 43 if ( m_partners[One].uid() == uid ||
44 m_partners[Two].uid() == uid ) return true; 44 m_partners[Two].uid() == uid ) return true;
45 45
46 return false; 46 return false;
47} 47}
diff --git a/libopie/pim/opimxref.h b/libopie/pim/opimxref.h
index 354739a..6852651 100644
--- a/libopie/pim/opimxref.h
+++ b/libopie/pim/opimxref.h
@@ -1,39 +1,39 @@
1#ifndef OPIM_XREF_H 1#ifndef OPIM_XREF_H
2#define OPIM_XREF_H 2#define OPIM_XREF_H
3 3
4#include <qarray.h> 4#include <qarray.h>
5#include <qvaluelist.h> 5#include <qvaluelist.h>
6 6
7#include <opie/opimxrefpartner.h> 7#include <opie/opimxrefpartner.h>
8 8
9/** 9/**
10 * this is a Cross Referecne between 10 * this is a Cross Referecne between
11 * two Cross Reference Partners 11 * two Cross Reference Partners
12 */ 12 */
13class OPimXRef { 13class OPimXRef {
14public: 14public:
15 typedef QValueList<OPimXRef> ValueList; 15 typedef QValueList<OPimXRef> ValueList;
16 enum Partners { One, Two }; 16 enum Partners { One, Two };
17 OPimXRef( const OPimXRefPartner& ONE, const OPimXRefPartner& ); 17 OPimXRef( const OPimXRefPartner& ONE, const OPimXRefPartner& );
18 OPimXRef(); 18 OPimXRef();
19 OPimXRef( const OPimXRef& ); 19 OPimXRef( const OPimXRef& );
20 ~OPimXRef(); 20 ~OPimXRef();
21 21
22 OPimXRef &operator=( const OPimXRef& ); 22 OPimXRef &operator=( const OPimXRef& );
23 bool operator==( const OPimXRef& ); 23 bool operator==( const OPimXRef& );
24 24
25 OPimXRefPartner partner( enum Partners )const; 25 OPimXRefPartner partner( enum Partners )const;
26 26
27 void setPartner( enum Partners, const OPimXRefPartner& ); 27 void setPartner( enum Partners, const OPimXRefPartner& );
28 28
29 bool containsString( const QString& appName)const; 29 bool containsString( const QString& service)const;
30 bool containsUid( int uid )const; 30 bool containsUid( int uid )const;
31 31
32private: 32private:
33 QArray<OPimXRefPartner> m_partners; 33 QArray<OPimXRefPartner> m_partners;
34 34
35 class Private; 35 class Private;
36 Private *d; 36 Private *d;
37}; 37};
38 38
39#endif 39#endif
diff --git a/libopie/pim/opimxrefmanager.cpp b/libopie/pim/opimxrefmanager.cpp
index 965f542..58bfd24 100644
--- a/libopie/pim/opimxrefmanager.cpp
+++ b/libopie/pim/opimxrefmanager.cpp
@@ -1,71 +1,71 @@
1#include "opimxrefmanager.h" 1#include "opimxrefmanager.h"
2 2
3 3
4OPimXRefManager::OPimXRefManager() { 4OPimXRefManager::OPimXRefManager() {
5} 5}
6OPimXRefManager::OPimXRefManager( const OPimXRefManager& ref) { 6OPimXRefManager::OPimXRefManager( const OPimXRefManager& ref) {
7 m_list = ref.m_list; 7 m_list = ref.m_list;
8} 8}
9OPimXRefManager::~OPimXRefManager() { 9OPimXRefManager::~OPimXRefManager() {
10} 10}
11OPimXRefManager &OPimXRefManager::operator=( const OPimXRefManager& ref) { 11OPimXRefManager &OPimXRefManager::operator=( const OPimXRefManager& ref) {
12 m_list = ref.m_list; 12 m_list = ref.m_list;
13 return *this; 13 return *this;
14} 14}
15bool OPimXRefManager::operator==( const OPimXRefManager& /*ref*/) { 15bool OPimXRefManager::operator==( const OPimXRefManager& /*ref*/) {
16 // if ( m_list == ref.m_list ) return true; 16 // if ( m_list == ref.m_list ) return true;
17 17
18 return false; 18 return false;
19} 19}
20void OPimXRefManager::add( const OPimXRef& ref) { 20void OPimXRefManager::add( const OPimXRef& ref) {
21 m_list.append( ref ); 21 m_list.append( ref );
22} 22}
23void OPimXRefManager::remove( const OPimXRef& ref) { 23void OPimXRefManager::remove( const OPimXRef& ref) {
24 m_list.remove( ref ); 24 m_list.remove( ref );
25} 25}
26void OPimXRefManager::replace( const OPimXRef& ref) { 26void OPimXRefManager::replace( const OPimXRef& ref) {
27 m_list.remove( ref ); 27 m_list.remove( ref );
28 m_list.append( ref ); 28 m_list.append( ref );
29} 29}
30void OPimXRefManager::clear() { 30void OPimXRefManager::clear() {
31 m_list.clear(); 31 m_list.clear();
32} 32}
33QStringList OPimXRefManager::apps()const { 33QStringList OPimXRefManager::apps()const {
34 OPimXRef::ValueList::ConstIterator it; 34 OPimXRef::ValueList::ConstIterator it;
35 QStringList list; 35 QStringList list;
36 36
37 QString str; 37 QString str;
38 for ( it = m_list.begin(); it != m_list.end(); ++it ) { 38 for ( it = m_list.begin(); it != m_list.end(); ++it ) {
39 str = (*it).partner( OPimXRef::One ).appName(); 39 str = (*it).partner( OPimXRef::One ).service();
40 if ( !list.contains( str ) ) list << str; 40 if ( !list.contains( str ) ) list << str;
41 41
42 str = (*it).partner( OPimXRef::Two ).appName(); 42 str = (*it).partner( OPimXRef::Two ).service();
43 if ( !list.contains( str ) ) list << str; 43 if ( !list.contains( str ) ) list << str;
44 } 44 }
45 return list; 45 return list;
46} 46}
47OPimXRef::ValueList OPimXRefManager::list()const { 47OPimXRef::ValueList OPimXRefManager::list()const {
48 return m_list; 48 return m_list;
49} 49}
50OPimXRef::ValueList OPimXRefManager::list( const QString& appName )const{ 50OPimXRef::ValueList OPimXRefManager::list( const QString& appName )const{
51 OPimXRef::ValueList list; 51 OPimXRef::ValueList list;
52 OPimXRef::ValueList::ConstIterator it; 52 OPimXRef::ValueList::ConstIterator it;
53 53
54 for ( it = m_list.begin(); it != m_list.end(); ++it ) { 54 for ( it = m_list.begin(); it != m_list.end(); ++it ) {
55 if ( (*it).containsString( appName ) ) 55 if ( (*it).containsString( appName ) )
56 list.append( (*it) ); 56 list.append( (*it) );
57 } 57 }
58 58
59 return list; 59 return list;
60} 60}
61OPimXRef::ValueList OPimXRefManager::list( int uid )const { 61OPimXRef::ValueList OPimXRefManager::list( int uid )const {
62 OPimXRef::ValueList list; 62 OPimXRef::ValueList list;
63 OPimXRef::ValueList::ConstIterator it; 63 OPimXRef::ValueList::ConstIterator it;
64 64
65 for ( it = m_list.begin(); it != m_list.end(); ++it ) { 65 for ( it = m_list.begin(); it != m_list.end(); ++it ) {
66 if ( (*it).containsUid( uid ) ) 66 if ( (*it).containsUid( uid ) )
67 list.append( (*it) ); 67 list.append( (*it) );
68 } 68 }
69 69
70 return list; 70 return list;
71} 71}
diff --git a/libopie/pim/opimxrefmanager.h b/libopie/pim/opimxrefmanager.h
index 9b003a3..39e5eef 100644
--- a/libopie/pim/opimxrefmanager.h
+++ b/libopie/pim/opimxrefmanager.h
@@ -1,41 +1,41 @@
1#ifndef OPIM_XREF_MANAGER_H 1#ifndef OPIM_XREF_MANAGER_H
2#define OPIM_XREF_MANAGER_H 2#define OPIM_XREF_MANAGER_H
3 3
4#include <qstringlist.h> 4#include <qstringlist.h>
5 5
6#include <opie/opimxref.h> 6#include <opie/opimxref.h>
7 7
8/** 8/**
9 * This is a simple manager for 9 * This is a simple manager for
10 * OPimXRefs. 10 * OPimXRefs.
11 * It allows addition, removing, replacing 11 * It allows addition, removing, replacing
12 * clearing and 'querying' the XRef... 12 * clearing and 'querying' the XRef...
13 */ 13 */
14class OPimXRefManager { 14class OPimXRefManager {
15public: 15public:
16 OPimXRefManager(); 16 OPimXRefManager();
17 OPimXRefManager( const OPimXRefManager& ); 17 OPimXRefManager( const OPimXRefManager& );
18 ~OPimXRefManager(); 18 ~OPimXRefManager();
19 19
20 OPimXRefManager& operator=( const OPimXRefManager& ); 20 OPimXRefManager& operator=( const OPimXRefManager& );
21 bool operator==( const OPimXRefManager& ); 21 bool operator==( const OPimXRefManager& );
22 22
23 void add( const OPimXRef& ); 23 void add( const OPimXRef& );
24 void remove( const OPimXRef& ); 24 void remove( const OPimXRef& );
25 void replace( const OPimXRef& ); 25 void replace( const OPimXRef& );
26 26
27 void clear(); 27 void clear();
28 28
29 /** 29 /**
30 * apps participating 30 * apps participating
31 */ 31 */
32 QStringList apps()const; 32 QStringList apps()const;
33 OPimXRef::ValueList list()const; 33 OPimXRef::ValueList list()const;
34 OPimXRef::ValueList list( const QString& appName )const; 34 OPimXRef::ValueList list( const QString& service )const;
35 OPimXRef::ValueList list( int uid )const; 35 OPimXRef::ValueList list( int uid )const;
36 36
37private: 37private:
38 OPimXRef::ValueList m_list; 38 OPimXRef::ValueList m_list;
39}; 39};
40 40
41#endif 41#endif
diff --git a/libopie/pim/opimxrefpartner.cpp b/libopie/pim/opimxrefpartner.cpp
index 028f4e6..6ef3efb 100644
--- a/libopie/pim/opimxrefpartner.cpp
+++ b/libopie/pim/opimxrefpartner.cpp
@@ -1,43 +1,43 @@
1#include "opimxrefpartner.h" 1#include "opimxrefpartner.h"
2 2
3OPimXRefPartner::OPimXRefPartner( const QString& appName, 3OPimXRefPartner::OPimXRefPartner( const QString& appName,
4 int uid, int field ) 4 int uid, int field )
5 : m_app(appName), m_uid(uid), m_field( field ) { 5 : m_app(appName), m_uid(uid), m_field( field ) {
6} 6}
7OPimXRefPartner::OPimXRefPartner( const OPimXRefPartner& ref ) { 7OPimXRefPartner::OPimXRefPartner( const OPimXRefPartner& ref ) {
8 *this = ref; 8 *this = ref;
9} 9}
10OPimXRefPartner::~OPimXRefPartner() { 10OPimXRefPartner::~OPimXRefPartner() {
11} 11}
12OPimXRefPartner &OPimXRefPartner::operator=( const OPimXRefPartner& par ) { 12OPimXRefPartner &OPimXRefPartner::operator=( const OPimXRefPartner& par ) {
13 m_app = par.m_app; 13 m_app = par.m_app;
14 m_uid = par.m_uid; 14 m_uid = par.m_uid;
15 m_field = par.m_field; 15 m_field = par.m_field;
16 16
17 return *this; 17 return *this;
18} 18}
19bool OPimXRefPartner::operator==( const OPimXRefPartner& par ) { 19bool OPimXRefPartner::operator==( const OPimXRefPartner& par ) {
20 if ( m_app != par.m_app ) return false; 20 if ( m_app != par.m_app ) return false;
21 if ( m_uid != par.m_uid ) return false; 21 if ( m_uid != par.m_uid ) return false;
22 if ( m_field != par.m_field ) return false; 22 if ( m_field != par.m_field ) return false;
23 23
24 return true; 24 return true;
25} 25}
26QString OPimXRefPartner::appName()const { 26QString OPimXRefPartner::service()const {
27 return m_app; 27 return m_app;
28} 28}
29int OPimXRefPartner::uid()const { 29int OPimXRefPartner::uid()const {
30 return m_uid; 30 return m_uid;
31} 31}
32int OPimXRefPartner::field()const { 32int OPimXRefPartner::field()const {
33 return m_field; 33 return m_field;
34} 34}
35void OPimXRefPartner::setAppName( const QString& appName ) { 35void OPimXRefPartner::setService( const QString& appName ) {
36 m_app = appName; 36 m_app = appName;
37} 37}
38void OPimXRefPartner::setUid( int uid ) { 38void OPimXRefPartner::setUid( int uid ) {
39 m_uid = uid; 39 m_uid = uid;
40} 40}
41void OPimXRefPartner::setField( int field ) { 41void OPimXRefPartner::setField( int field ) {
42 m_field = field; 42 m_field = field;
43} 43}
diff --git a/libopie/pim/opimxrefpartner.h b/libopie/pim/opimxrefpartner.h
index 808b9ab..d76e384 100644
--- a/libopie/pim/opimxrefpartner.h
+++ b/libopie/pim/opimxrefpartner.h
@@ -1,40 +1,40 @@
1#ifndef OPIM_XREF_PARTNER_H 1#ifndef OPIM_XREF_PARTNER_H
2#define OPIM_XREF_PARTNER_H 2#define OPIM_XREF_PARTNER_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5 5
6/** 6/**
7 * This class represents one partner 7 * This class represents one partner
8 * of a Cross Reference. 8 * of a Cross Reference.
9 * In Opie one application 9 * In Opie one application
10 * can link one uid 10 * can link one uid
11 * with one tableId( fieldId ) to another. 11 * with one tableId( fieldId ) to another.
12 */ 12 */
13class OPimXRefPartner { 13class OPimXRefPartner {
14public: 14public:
15 OPimXRefPartner( const QString& appName = QString::null, 15 OPimXRefPartner( const QString& service = QString::null,
16 int uid = 0, int field = -1 ); 16 int uid = 0, int field = -1 );
17 OPimXRefPartner( const OPimXRefPartner& ); 17 OPimXRefPartner( const OPimXRefPartner& );
18 OPimXRefPartner& operator=( const OPimXRefPartner& ); 18 OPimXRefPartner& operator=( const OPimXRefPartner& );
19 ~OPimXRefPartner(); 19 ~OPimXRefPartner();
20 20
21 bool operator==(const OPimXRefPartner& ); 21 bool operator==(const OPimXRefPartner& );
22 22
23 QString appName()const; 23 QString service()const;
24 int uid()const; 24 int uid()const;
25 int field()const; 25 int field()const;
26 26
27 void setAppName( const QString& appName ); 27 void setService( const QString& service );
28 void setUid( int uid ); 28 void setUid( int uid );
29 void setField( int field ); 29 void setField( int field );
30private: 30private:
31 QString m_app; 31 QString m_app;
32 int m_uid; 32 int m_uid;
33 int m_field; 33 int m_field;
34 34
35 class Private; 35 class Private;
36 Private* d; 36 Private* d;
37}; 37};
38 38
39 39
40#endif 40#endif
diff --git a/libopie/pim/orecur.cpp b/libopie/pim/orecur.cpp
index 257d4fd..daf3506 100644
--- a/libopie/pim/orecur.cpp
+++ b/libopie/pim/orecur.cpp
@@ -1,136 +1,451 @@
1#include <qshared.h> 1#include <qshared.h>
2 2
3#include <qtopia/timeconversion.h> 3#include <qtopia/timeconversion.h>
4 4
5#include "orecur.h" 5#include "orecur.h"
6 6
7struct ORecur::Data : public QShared { 7struct ORecur::Data : public QShared {
8 Data() : QShared() { 8 Data() : QShared() {
9 type = ORecur::NoRepeat; 9 type = ORecur::NoRepeat;
10 freq = -1; 10 freq = -1;
11 days = 0; 11 days = 0;
12 pos = 0; 12 pos = 0;
13 create = -1; 13 create = -1;
14 hasEnd = FALSE; 14 hasEnd = FALSE;
15 end = 0; 15 end = 0;
16 } 16 }
17 char days; // Q_UINT8 for 8 seven days;) 17 char days; // Q_UINT8 for 8 seven days;)
18 ORecur::RepeatType type; 18 ORecur::RepeatType type;
19 int freq; 19 int freq;
20 int pos; 20 int pos;
21 bool hasEnd : 1; 21 bool hasEnd : 1;
22 time_t end; 22 time_t end;
23 time_t create; 23 time_t create;
24 int rep; 24 int rep;
25 QString app;
26 ExceptionList list;
27 QDate start;
25}; 28};
26 29
27 30
28ORecur::ORecur() { 31ORecur::ORecur() {
29 data = new Data; 32 data = new Data;
30} 33}
31ORecur::ORecur( const ORecur& rec) 34ORecur::ORecur( const ORecur& rec)
32 : data( rec.data ) 35 : data( rec.data )
33{ 36{
34 data->ref(); 37 data->ref();
35} 38}
36ORecur::~ORecur() { 39ORecur::~ORecur() {
37 if ( data->deref() ) { 40 if ( data->deref() ) {
38 delete data; 41 delete data;
39 data = 0l; 42 data = 0l;
40 } 43 }
41} 44}
42void ORecur::deref() { 45void ORecur::deref() {
43 if ( data->deref() ) { 46 if ( data->deref() ) {
44 delete data; 47 delete data;
45 data = 0l; 48 data = 0l;
46 } 49 }
47} 50}
48bool ORecur::operator==( const ORecur& )const { 51bool ORecur::operator==( const ORecur& )const {
49 return false; 52 return false;
50} 53}
51ORecur &ORecur::operator=( const ORecur& re) { 54ORecur &ORecur::operator=( const ORecur& re) {
52 re.data->ref(); 55 re.data->ref();
53 deref(); 56 deref();
54 data = re.data; 57 data = re.data;
55 58
56 return *this; 59 return *this;
57} 60}
61bool ORecur::doesRecur()const {
62 return !( type() == NoRepeat );
63}
64/*
65 * we try to be smart here
66 *
67 */
68bool ORecur::doesRecur( const QDate& date ) {
69 /* the day before the recurrance */
70 QDate da = date.addDays(-1);
71
72 QDate recur;
73 if (!nextOcurrence( da, recur ) )
74 return false;
75
76 return (recur == date);
77}
78// FIXME unuglify!
79// GPL from Datebookdb.cpp
80// FIXME exception list!
81bool ORecur::nextOcurrence( const QDate& from, QDate& next ) {
82
83 // easy checks, first are we too far in the future or too far in the past?
84 QDate tmpDate;
85 int freq = frequency();
86 int diff, diff2, a;
87 int iday, imonth, iyear;
88 int dayOfWeek = 0;
89 int firstOfWeek = 0;
90 int weekOfMonth;
91
92
93 if (hasEndDate() && endDate() < from)
94 return FALSE;
95
96 if (start() >= from) {
97 next = start();
98 return TRUE;
99 }
100
101 switch ( type() ) {
102 case Weekly:
103 /* weekly is just daily by 7 */
104 /* first convert the repeatPattern.Days() mask to the next
105 day of week valid after from */
106 dayOfWeek = from.dayOfWeek();
107 dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */
108
109 /* this is done in case freq > 1 and from in week not
110 for this round */
111 // firstOfWeek = 0; this is already done at decl.
112 while(!((1 << firstOfWeek) & days() ))
113 firstOfWeek++;
114
115 /* there is at least one 'day', or there would be no event */
116 while(!((1 << (dayOfWeek % 7)) & days() ))
117 dayOfWeek++;
118
119 dayOfWeek = dayOfWeek % 7; /* the actual day of week */
120 dayOfWeek -= start().dayOfWeek() -1;
121
122 firstOfWeek = firstOfWeek % 7; /* the actual first of week */
123 firstOfWeek -= start().dayOfWeek() -1;
124
125 // dayOfWeek may be negitive now
126 // day of week is number of days to add to start day
127
128 freq *= 7;
129 // FALL-THROUGH !!!!!
130 case Daily:
131 // the add is for the possible fall through from weekly */
132 if(start().addDays(dayOfWeek) > from) {
133 /* first week exception */
134 next = QDate(start().addDays(dayOfWeek) );
135 if ((next > endDate())
136 && hasEndDate() )
137 return FALSE;
138 return TRUE;
139 }
140 /* if from is middle of a non-week */
141
142 diff = start().addDays(dayOfWeek).daysTo(from) % freq;
143 diff2 = start().addDays(firstOfWeek).daysTo(from) % freq;
144
145 if(diff != 0)
146 diff = freq - diff;
147 if(diff2 != 0)
148 diff2 = freq - diff2;
149 diff = QMIN(diff, diff2);
150
151 next = QDate(from.addDays(diff));
152 if ( (next > endDate())
153 && hasEndDate() )
154 return FALSE;
155 return TRUE;
156 case MonthlyDay:
157 iday = from.day();
158 iyear = from.year();
159 imonth = from.month();
160 /* find equivelent day of month for this month */
161 dayOfWeek = start().dayOfWeek();
162 weekOfMonth = (start().day() - 1) / 7;
163
164 /* work out when the next valid month is */
165 a = from.year() - start().year();
166 a *= 12;
167 a = a + (imonth - start().month());
168 /* a is e.start()monthsFrom(from); */
169 if(a % freq) {
170 a = freq - (a % freq);
171 imonth = from.month() + a;
172 if (imonth > 12) {
173 imonth--;
174 iyear += imonth / 12;
175 imonth = imonth % 12;
176 imonth++;
177 }
178 }
179 /* imonth is now the first month after or on
180 from that matches the frequency given */
181
182 /* find for this month */
183 tmpDate = QDate( iyear, imonth, 1 );
184
185 iday = 1;
186 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
187 iday += 7 * weekOfMonth;
188 while (iday > tmpDate.daysInMonth()) {
189 imonth += freq;
190 if (imonth > 12) {
191 imonth--;
192 iyear += imonth / 12;
193 imonth = imonth % 12;
194 imonth++;
195 }
196 tmpDate = QDate( iyear, imonth, 1 );
197 /* these loops could go for a while, check end case now */
198 if ((tmpDate > endDate()) && hasEndDate() )
199 return FALSE;
200 iday = 1;
201 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
202 iday += 7 * weekOfMonth;
203 }
204 tmpDate = QDate(iyear, imonth, iday);
205
206 if (tmpDate >= from) {
207 next = tmpDate;
208 if ((next > endDate() ) && hasEndDate() )
209 return FALSE;
210 return TRUE;
211 }
212
213 /* need to find the next iteration */
214 do {
215 imonth += freq;
216 if (imonth > 12) {
217 imonth--;
218 iyear += imonth / 12;
219 imonth = imonth % 12;
220 imonth++;
221 }
222 tmpDate = QDate( iyear, imonth, 1 );
223 /* these loops could go for a while, check end case now */
224 if ((tmpDate > endDate()) && hasEndDate() )
225 return FALSE;
226 iday = 1;
227 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
228 iday += 7 * weekOfMonth;
229 } while (iday > tmpDate.daysInMonth());
230 tmpDate = QDate(iyear, imonth, iday);
231
232 next = tmpDate;
233 if ((next > endDate()) && hasEndDate() )
234 return FALSE;
235 return TRUE;
236 case MonthlyDate:
237 iday = start().day();
238 iyear = from.year();
239 imonth = from.month();
240
241 a = from.year() - start().year();
242 a *= 12;
243 a = a + (imonth - start().month());
244 /* a is e.start()monthsFrom(from); */
245 if(a % freq) {
246 a = freq - (a % freq);
247 imonth = from.month() + a;
248 if (imonth > 12) {
249 imonth--;
250 iyear += imonth / 12;
251 imonth = imonth % 12;
252 imonth++;
253 }
254 }
255 /* imonth is now the first month after or on
256 from that matches the frequencey given */
257
258 /* this could go for a while, worse case, 4*12 iterations, probably */
259 while(!QDate::isValid(iyear, imonth, iday) ) {
260 imonth += freq;
261 if (imonth > 12) {
262 imonth--;
263 iyear += imonth / 12;
264 imonth = imonth % 12;
265 imonth++;
266 }
267 /* these loops could go for a while, check end case now */
268 if ((QDate(iyear, imonth, 1) > endDate()) && hasEndDate() )
269 return FALSE;
270 }
271
272 if(QDate(iyear, imonth, iday) >= from) {
273 /* done */
274 next = QDate(iyear, imonth, iday);
275 if ((next > endDate()) && hasEndDate() )
276 return FALSE;
277 return TRUE;
278 }
279
280 /* ok, need to cycle */
281 imonth += freq;
282 imonth--;
283 iyear += imonth / 12;
284 imonth = imonth % 12;
285 imonth++;
286
287 while(!QDate::isValid(iyear, imonth, iday) ) {
288 imonth += freq;
289 imonth--;
290 iyear += imonth / 12;
291 imonth = imonth % 12;
292 imonth++;
293 if ((QDate(iyear, imonth, 1) > endDate()) && hasEndDate() )
294 return FALSE;
295 }
296
297 next = QDate(iyear, imonth, iday);
298 if ((next > endDate()) && hasEndDate() )
299 return FALSE;
300 return TRUE;
301 case Yearly:
302 iday = start().day();
303 imonth = start().month();
304 iyear = from.year(); // after all, we want to start in this year
305
306 diff = 1;
307 if(imonth == 2 && iday > 28) {
308 /* leap year, and it counts, calculate actual frequency */
309 if(freq % 4)
310 if (freq % 2)
311 freq = freq * 4;
312 else
313 freq = freq * 2;
314 /* else divides by 4 already, leave freq alone */
315 diff = 4;
316 }
317
318 a = from.year() - start().year();
319 if(a % freq) {
320 a = freq - (a % freq);
321 iyear = iyear + a;
322 }
323
324 /* under the assumption we won't hit one of the special not-leap years twice */
325 if(!QDate::isValid(iyear, imonth, iday)) {
326 /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */
327 iyear += freq;
328 }
329
330 if(QDate(iyear, imonth, iday) >= from) {
331 next = QDate(iyear, imonth, iday);
332
333 if ((next > endDate()) && hasEndDate() )
334 return FALSE;
335 return TRUE;
336 }
337 /* iyear == from.year(), need to advance again */
338 iyear += freq;
339 /* under the assumption we won't hit one of the special not-leap years twice */
340 if(!QDate::isValid(iyear, imonth, iday)) {
341 /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */
342 iyear += freq;
343 }
344
345 next = QDate(iyear, imonth, iday);
346 if ((next > endDate()) && hasEndDate() )
347 return FALSE;
348 return TRUE;
349 default:
350 return FALSE;
351 }
352}
58ORecur::RepeatType ORecur::type()const{ 353ORecur::RepeatType ORecur::type()const{
59 return data->type; 354 return data->type;
60} 355}
61int ORecur::frequency()const { 356int ORecur::frequency()const {
62 return data->freq; 357 return data->freq;
63} 358}
64int ORecur::position()const { 359int ORecur::position()const {
65 return data->pos; 360 return data->pos;
66} 361}
67char ORecur::days() const{ 362char ORecur::days() const{
68 return data->days; 363 return data->days;
69} 364}
70bool ORecur::hasEndDate()const { 365bool ORecur::hasEndDate()const {
71 return data->hasEnd; 366 return data->hasEnd;
72} 367}
73QDate ORecur::endDate()const { 368QDate ORecur::endDate()const {
74 return TimeConversion::fromUTC( data->end ).date(); 369 return TimeConversion::fromUTC( data->end ).date();
75} 370}
371QDate ORecur::start()const{
372 return data->start;
373}
76time_t ORecur::endDateUTC()const { 374time_t ORecur::endDateUTC()const {
77 return data->end; 375 return data->end;
78} 376}
79time_t ORecur::createTime()const { 377time_t ORecur::createTime()const {
80 return data->create; 378 return data->create;
81} 379}
82int ORecur::repetition()const { 380int ORecur::repetition()const {
83 return data->rep; 381 return data->rep;
84} 382}
383QString ORecur::service()const {
384 return data->app;
385}
386ORecur::ExceptionList& ORecur::exceptions() {
387 return data->list;
388}
85void ORecur::setType( const RepeatType& z) { 389void ORecur::setType( const RepeatType& z) {
86 checkOrModify(); 390 checkOrModify();
87 data->type = z; 391 data->type = z;
88} 392}
89void ORecur::setFrequency( int freq ) { 393void ORecur::setFrequency( int freq ) {
90 checkOrModify(); 394 checkOrModify();
91 data->freq = freq; 395 data->freq = freq;
92} 396}
93void ORecur::setPosition( int pos ) { 397void ORecur::setPosition( int pos ) {
94 checkOrModify(); 398 checkOrModify();
95 data->pos = pos; 399 data->pos = pos;
96} 400}
97void ORecur::setDays( char c ) { 401void ORecur::setDays( char c ) {
98 checkOrModify(); 402 checkOrModify();
99 data->days = c; 403 data->days = c;
100} 404}
101void ORecur::setEndDate( const QDate& dt) { 405void ORecur::setEndDate( const QDate& dt) {
102 checkOrModify(); 406 checkOrModify();
103 data->end = TimeConversion::toUTC( dt ); 407 data->end = TimeConversion::toUTC( dt );
104} 408}
105void ORecur::setEndDateUTC( time_t t) { 409void ORecur::setEndDateUTC( time_t t) {
106 checkOrModify(); 410 checkOrModify();
107 data->end = t; 411 data->end = t;
108} 412}
109void ORecur::setCreateTime( time_t t) { 413void ORecur::setCreateTime( time_t t) {
110 checkOrModify(); 414 checkOrModify();
111 data->create = t; 415 data->create = t;
112} 416}
113void ORecur::setHasEndDate( bool b) { 417void ORecur::setHasEndDate( bool b) {
114 checkOrModify(); 418 checkOrModify();
115 data->hasEnd = b; 419 data->hasEnd = b;
116} 420}
117void ORecur::setRepitition( int rep ) { 421void ORecur::setRepitition( int rep ) {
118 checkOrModify(); 422 checkOrModify();
119 data->rep = rep; 423 data->rep = rep;
120} 424}
425void ORecur::setService( const QString& app ) {
426 checkOrModify();
427 data->app = app;
428}
429void ORecur::setStart( const QDate& dt ) {
430 checkOrModify();
431 data->start = dt;
432}
121void ORecur::checkOrModify() { 433void ORecur::checkOrModify() {
122 if ( data->count != 1 ) { 434 if ( data->count != 1 ) {
123 data->deref(); 435 data->deref();
124 Data* d2 = new Data; 436 Data* d2 = new Data;
125 d2->days = data->days; 437 d2->days = data->days;
126 d2->type = data->type; 438 d2->type = data->type;
127 d2->freq = data->freq; 439 d2->freq = data->freq;
128 d2->pos = data->pos; 440 d2->pos = data->pos;
129 d2->hasEnd = data->hasEnd; 441 d2->hasEnd = data->hasEnd;
130 d2->end = data->end; 442 d2->end = data->end;
131 d2->create = data->create; 443 d2->create = data->create;
132 d2->rep = data->rep; 444 d2->rep = data->rep;
445 d2->app = data->app;
446 d2->list = data->list;
447 d2->start = data->start;
133 data = d2; 448 data = d2;
134 } 449 }
135} 450}
136 451
diff --git a/libopie/pim/orecur.h b/libopie/pim/orecur.h
index d24d72d..8713d97 100644
--- a/libopie/pim/orecur.h
+++ b/libopie/pim/orecur.h
@@ -1,56 +1,83 @@
1/* 1/*
2 * GPL from TT 2 * GPL from TT
3 */ 3 */
4 4
5#ifndef OPIE_RECUR_H 5#ifndef OPIE_RECUR_H
6#define OPIE_RECUR_H 6#define OPIE_RECUR_H
7 7
8#include <sys/types.h> 8#include <sys/types.h>
9 9
10#include <qdatetime.h> 10#include <qdatetime.h>
11 11#include <qvaluelist.h>
12 12
13 13
14class ORecur { 14class ORecur {
15public: 15public:
16 typedef QValueList<QDate> ExceptionList;
16 enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay, 17 enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay,
17 MonthlyDate, Yearly }; 18 MonthlyDate, Yearly };
18 enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, 19 enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08,
19 FRI = 0x10, SAT = 0x20, SUN = 0x40 }; 20 FRI = 0x10, SAT = 0x20, SUN = 0x40 };
20 ORecur(); 21 ORecur();
21 ORecur( const ORecur& ); 22 ORecur( const ORecur& );
22 ~ORecur(); 23 ~ORecur();
23 24
24 ORecur &operator=( const ORecur& ); 25 ORecur &operator=( const ORecur& );
25 bool operator==(const ORecur& )const; 26 bool operator==(const ORecur& )const;
27
28 bool doesRecur()const;
29 /* if it recurrs on that day */
30 bool doesRecur( const QDate& );
26 RepeatType type()const; 31 RepeatType type()const;
27 int frequency()const; 32 int frequency()const;
28 int position()const; 33 int position()const;
29 char days()const; 34 char days()const;
30 bool hasEndDate()const; 35 bool hasEndDate()const;
36 QDate start()const;
31 QDate endDate()const; 37 QDate endDate()const;
32 time_t endDateUTC()const; 38 time_t endDateUTC()const;
33 time_t createTime()const; 39 time_t createTime()const;
40
41 /**
42 * FromWhereToStart is not included!!!
43 */
44 bool nextOcurrence( const QDate& FromWhereToStart, QDate &recurDate );
45 /**
46 * The module this ORecur belongs to
47 */
48 QString service()const;
49
50 /*
51 * reference to the exception list
52 */
53 ExceptionList &exceptions();
54
55 /**
56 * the current repetition
57 */
34 int repetition()const; 58 int repetition()const;
35 59
36 void setType( const RepeatType& ); 60 void setType( const RepeatType& );
37 void setFrequency( int freq ); 61 void setFrequency( int freq );
38 void setPosition( int pos ); 62 void setPosition( int pos );
39 void setDays( char c); 63 void setDays( char c);
40 void setEndDate( const QDate& dt ); 64 void setEndDate( const QDate& dt );
65 void setStart( const QDate& dt );
41 void setEndDateUTC( time_t ); 66 void setEndDateUTC( time_t );
42 void setCreateTime( time_t ); 67 void setCreateTime( time_t );
43 void setHasEndDate( bool b ); 68 void setHasEndDate( bool b );
44 void setRepitition(int ); 69 void setRepitition(int );
70
71 void setService( const QString& ser );
45private: 72private:
46 void deref(); 73 void deref();
47 inline void checkOrModify(); 74 inline void checkOrModify();
48 75
49 76
50 class Data; 77 class Data;
51 Data* data; 78 Data* data;
52 class ORecurPrivate; 79 class ORecurPrivate;
53 ORecurPrivate *d; 80 ORecurPrivate *d;
54}; 81};
55 82
56#endif 83#endif
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp
index 6fcf9f6..ece624a 100644
--- a/libopie/pim/otodo.cpp
+++ b/libopie/pim/otodo.cpp
@@ -1,423 +1,421 @@
1 1
2#include <qobject.h> 2#include <qobject.h>
3#include <qshared.h> 3#include <qshared.h>
4 4
5 5
6 6
7#include <qpe/palmtopuidgen.h> 7#include <qpe/palmtopuidgen.h>
8#include <qpe/stringutil.h> 8#include <qpe/stringutil.h>
9#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
10#include <qpe/stringutil.h> 10#include <qpe/stringutil.h>
11#include <qpe/categories.h> 11#include <qpe/categories.h>
12#include <qpe/categoryselect.h> 12#include <qpe/categoryselect.h>
13 13
14 14
15#include "opimstate.h" 15#include "opimstate.h"
16#include "orecur.h" 16#include "orecur.h"
17#include "opimmaintainer.h" 17#include "opimmaintainer.h"
18#include "opimnotifymanager.h"
18 19
19#include "otodo.h" 20#include "otodo.h"
20 21
21 22
22struct OTodo::OTodoData : public QShared { 23struct OTodo::OTodoData : public QShared {
23 OTodoData() : QShared() { 24 OTodoData() : QShared() {
24 }; 25 };
25 26
26 QDate date; 27 QDate date;
27 bool isCompleted:1; 28 bool isCompleted:1;
28 bool hasDate:1; 29 bool hasDate:1;
29 int priority; 30 int priority;
30 QString desc; 31 QString desc;
31 QString sum; 32 QString sum;
32 QMap<QString, QString> extra; 33 QMap<QString, QString> extra;
33 ushort prog; 34 ushort prog;
34 bool hasAlarmDateTime :1;
35 QDateTime alarmDateTime;
36 OPimState state; 35 OPimState state;
37 ORecur recur; 36 ORecur recur;
38 OPimMaintainer maintainer; 37 OPimMaintainer maintainer;
38 QDate start;
39 QDate completed;
40 OPimNotifyManager notifiers;
39}; 41};
40 42
41OTodo::OTodo(const OTodo &event ) 43OTodo::OTodo(const OTodo &event )
42 : OPimRecord( event ), data( event.data ) 44 : OPimRecord( event ), data( event.data )
43{ 45{
44 data->ref(); 46 data->ref();
45// qWarning("ref up"); 47// qWarning("ref up");
46} 48}
47OTodo::~OTodo() { 49OTodo::~OTodo() {
48 50
49// qWarning("~OTodo " ); 51// qWarning("~OTodo " );
50 if ( data->deref() ) { 52 if ( data->deref() ) {
51// qWarning("OTodo::dereffing"); 53// qWarning("OTodo::dereffing");
52 delete data; 54 delete data;
53 data = 0l; 55 data = 0l;
54 } 56 }
55} 57}
56OTodo::OTodo(bool completed, int priority, 58OTodo::OTodo(bool completed, int priority,
57 const QArray<int> &category, 59 const QArray<int> &category,
58 const QString& summary, 60 const QString& summary,
59 const QString &description, 61 const QString &description,
60 ushort progress, 62 ushort progress,
61 bool hasDate, QDate date, int uid ) 63 bool hasDate, QDate date, int uid )
62 : OPimRecord( uid ) 64 : OPimRecord( uid )
63{ 65{
64// qWarning("OTodoData " + summary); 66// qWarning("OTodoData " + summary);
65 setCategories( category ); 67 setCategories( category );
66 68
67 data = new OTodoData; 69 data = new OTodoData;
68 70
69 data->date = date; 71 data->date = date;
70 data->isCompleted = completed; 72 data->isCompleted = completed;
71 data->hasDate = hasDate; 73 data->hasDate = hasDate;
72 data->priority = priority; 74 data->priority = priority;
73 data->sum = summary; 75 data->sum = summary;
74 data->prog = progress; 76 data->prog = progress;
75 data->desc = Qtopia::simplifyMultiLineSpace(description ); 77 data->desc = Qtopia::simplifyMultiLineSpace(description );
76 data->hasAlarmDateTime = false;
77
78} 78}
79OTodo::OTodo(bool completed, int priority, 79OTodo::OTodo(bool completed, int priority,
80 const QStringList &category, 80 const QStringList &category,
81 const QString& summary, 81 const QString& summary,
82 const QString &description, 82 const QString &description,
83 ushort progress, 83 ushort progress,
84 bool hasDate, QDate date, int uid ) 84 bool hasDate, QDate date, int uid )
85 : OPimRecord( uid ) 85 : OPimRecord( uid )
86{ 86{
87// qWarning("OTodoData" + summary); 87// qWarning("OTodoData" + summary);
88 setCategories( idsFromString( category.join(";") ) ); 88 setCategories( idsFromString( category.join(";") ) );
89 89
90 data = new OTodoData; 90 data = new OTodoData;
91 91
92 data->date = date; 92 data->date = date;
93 data->isCompleted = completed; 93 data->isCompleted = completed;
94 data->hasDate = hasDate; 94 data->hasDate = hasDate;
95 data->priority = priority; 95 data->priority = priority;
96 data->sum = summary; 96 data->sum = summary;
97 data->prog = progress; 97 data->prog = progress;
98 data->desc = Qtopia::simplifyMultiLineSpace(description ); 98 data->desc = Qtopia::simplifyMultiLineSpace(description );
99 data->hasAlarmDateTime = false;
100
101} 99}
102bool OTodo::match( const QRegExp &regExp )const 100bool OTodo::match( const QRegExp &regExp )const
103{ 101{
104 if( QString::number( data->priority ).find( regExp ) != -1 ){ 102 if( QString::number( data->priority ).find( regExp ) != -1 ){
105 return true; 103 return true;
106 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ 104 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
107 return true; 105 return true;
108 }else if(data->desc.find( regExp ) != -1 ){ 106 }else if(data->desc.find( regExp ) != -1 ){
109 return true; 107 return true;
110 }else if(data->sum.find( regExp ) != -1 ) { 108 }else if(data->sum.find( regExp ) != -1 ) {
111 return true; 109 return true;
112 } 110 }
113 return false; 111 return false;
114} 112}
115bool OTodo::isCompleted() const 113bool OTodo::isCompleted() const
116{ 114{
117 return data->isCompleted; 115 return data->isCompleted;
118} 116}
119bool OTodo::hasDueDate() const 117bool OTodo::hasDueDate() const
120{ 118{
121 return data->hasDate; 119 return data->hasDate;
122} 120}
123bool OTodo::hasAlarmDateTime() const 121bool OTodo::hasStartDate()const {
124{ 122 return data->start.isValid();
125 return data->hasAlarmDateTime; 123}
124bool OTodo::hasCompletedDate()const {
125 return data->completed.isValid();
126} 126}
127int OTodo::priority()const 127int OTodo::priority()const
128{ 128{
129 return data->priority; 129 return data->priority;
130} 130}
131QString OTodo::summary() const 131QString OTodo::summary() const
132{ 132{
133 return data->sum; 133 return data->sum;
134} 134}
135ushort OTodo::progress() const 135ushort OTodo::progress() const
136{ 136{
137 return data->prog; 137 return data->prog;
138} 138}
139QDate OTodo::dueDate()const 139QDate OTodo::dueDate()const
140{ 140{
141 return data->date; 141 return data->date;
142} 142}
143 143QDate OTodo::startDate()const {
144QDateTime OTodo::alarmDateTime() const 144 return data->start;
145{ 145}
146 return data->alarmDateTime; 146QDate OTodo::completedDate()const {
147 return data->completed;
147} 148}
148
149QString OTodo::description()const 149QString OTodo::description()const
150{ 150{
151 return data->desc; 151 return data->desc;
152} 152}
153OPimState OTodo::state()const { 153OPimState OTodo::state()const {
154 return data->state; 154 return data->state;
155} 155}
156ORecur OTodo::recurrence()const { 156ORecur OTodo::recurrence()const {
157 return data->recur; 157 return data->recur;
158} 158}
159OPimMaintainer OTodo::maintainer()const { 159OPimMaintainer OTodo::maintainer()const {
160 return data->maintainer; 160 return data->maintainer;
161} 161}
162void OTodo::setCompleted( bool completed ) 162void OTodo::setCompleted( bool completed )
163{ 163{
164 changeOrModify(); 164 changeOrModify();
165 data->isCompleted = completed; 165 data->isCompleted = completed;
166} 166}
167void OTodo::setHasDueDate( bool hasDate ) 167void OTodo::setHasDueDate( bool hasDate )
168{ 168{
169 changeOrModify(); 169 changeOrModify();
170 data->hasDate = hasDate; 170 data->hasDate = hasDate;
171} 171}
172void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime )
173{
174 changeOrModify();
175 data->hasAlarmDateTime = hasAlarmDateTime;
176}
177void OTodo::setDescription(const QString &desc ) 172void OTodo::setDescription(const QString &desc )
178{ 173{
179// qWarning( "desc " + desc ); 174// qWarning( "desc " + desc );
180 changeOrModify(); 175 changeOrModify();
181 data->desc = Qtopia::simplifyMultiLineSpace(desc ); 176 data->desc = Qtopia::simplifyMultiLineSpace(desc );
182} 177}
183void OTodo::setSummary( const QString& sum ) 178void OTodo::setSummary( const QString& sum )
184{ 179{
185 changeOrModify(); 180 changeOrModify();
186 data->sum = sum; 181 data->sum = sum;
187} 182}
188void OTodo::setPriority(int prio ) 183void OTodo::setPriority(int prio )
189{ 184{
190 changeOrModify(); 185 changeOrModify();
191 data->priority = prio; 186 data->priority = prio;
192} 187}
193void OTodo::setDueDate( QDate date ) 188void OTodo::setDueDate( const QDate& date )
194{ 189{
195 changeOrModify(); 190 changeOrModify();
196 data->date = date; 191 data->date = date;
197} 192}
198void OTodo::setAlarmDateTime( const QDateTime& alarm ) 193void OTodo::setStartDate( const QDate& date ) {
199{
200 changeOrModify(); 194 changeOrModify();
201 data->alarmDateTime = alarm; 195 data->start = date;
196}
197void OTodo::setCompletedDate( const QDate& date ) {
198 changeOrModify();
199 data->completed = date;
202} 200}
203void OTodo::setState( const OPimState& state ) { 201void OTodo::setState( const OPimState& state ) {
204 changeOrModify(); 202 changeOrModify();
205 data->state = state; 203 data->state = state;
206} 204}
207void OTodo::setRecurrence( const ORecur& rec) { 205void OTodo::setRecurrence( const ORecur& rec) {
208 changeOrModify(); 206 changeOrModify();
209 data->recur = rec; 207 data->recur = rec;
210} 208}
211void OTodo::setMaintainer( const OPimMaintainer& pim ) { 209void OTodo::setMaintainer( const OPimMaintainer& pim ) {
212 changeOrModify(); 210 changeOrModify();
213 data->maintainer = pim; 211 data->maintainer = pim;
214} 212}
215bool OTodo::isOverdue( ) 213bool OTodo::isOverdue( )
216{ 214{
217 if( data->hasDate && !data->isCompleted) 215 if( data->hasDate && !data->isCompleted)
218 return QDate::currentDate() > data->date; 216 return QDate::currentDate() > data->date;
219 return false; 217 return false;
220} 218}
221void OTodo::setProgress(ushort progress ) 219void OTodo::setProgress(ushort progress )
222{ 220{
223 changeOrModify(); 221 changeOrModify();
224 data->prog = progress; 222 data->prog = progress;
225} 223}
226QString OTodo::toShortText() const { 224QString OTodo::toShortText() const {
227 return summary(); 225 return summary();
228} 226}
229/*! 227/*!
230 Returns a richt text string 228 Returns a richt text string
231*/ 229*/
232QString OTodo::toRichText() const 230QString OTodo::toRichText() const
233{ 231{
234 QString text; 232 QString text;
235 QStringList catlist; 233 QStringList catlist;
236 234
237 // Description of the todo 235 // Description of the todo
238 if ( !summary().isEmpty() ) { 236 if ( !summary().isEmpty() ) {
239 text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; 237 text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
240 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 238 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
241 } 239 }
242 if( !description().isEmpty() ){ 240 if( !description().isEmpty() ){
243 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 241 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
244 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; 242 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ;
245 } 243 }
246 text += "<br><br><br>"; 244 text += "<br><br><br>";
247 245
248 text += "<b>" + QObject::tr( "Priority:") +" </b>" 246 text += "<b>" + QObject::tr( "Priority:") +" </b>"
249 + QString::number( priority() ) + " <br>"; 247 + QString::number( priority() ) + " <br>";
250 text += "<b>" + QObject::tr( "Progress:") + " </b>" 248 text += "<b>" + QObject::tr( "Progress:") + " </b>"
251 + QString::number( progress() ) + " %<br>"; 249 + QString::number( progress() ) + " %<br>";
252 if (hasDueDate() ){ 250 if (hasDueDate() ){
253 text += "<b>" + QObject::tr( "Deadline:") + " </b>"; 251 text += "<b>" + QObject::tr( "Deadline:") + " </b>";
254 text += dueDate().toString(); 252 text += dueDate().toString();
255 text += "<br>"; 253 text += "<br>";
256 } 254 }
257 if (hasAlarmDateTime() ){
258 text += "<b>" + QObject::tr( "Alarmed Notification:") + " </b>";
259 text += alarmDateTime().toString();
260 text += "<br>";
261 }
262 255
263 text += "<b>" + QObject::tr( "Category:") + "</b> "; 256 text += "<b>" + QObject::tr( "Category:") + "</b> ";
264 text += categoryNames().join(", "); 257 text += categoryNames().join(", ");
265 text += "<br>"; 258 text += "<br>";
266 259
267 return text; 260 return text;
268} 261}
262OPimNotifyManager& OTodo::notifiers() {
263 return data->notifiers;
264}
269 265
270bool OTodo::operator<( const OTodo &toDoEvent )const{ 266bool OTodo::operator<( const OTodo &toDoEvent )const{
271 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 267 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
272 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 268 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
273 if( hasDueDate() && toDoEvent.hasDueDate() ){ 269 if( hasDueDate() && toDoEvent.hasDueDate() ){
274 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 270 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
275 return priority() < toDoEvent.priority(); 271 return priority() < toDoEvent.priority();
276 }else{ 272 }else{
277 return dueDate() < toDoEvent.dueDate(); 273 return dueDate() < toDoEvent.dueDate();
278 } 274 }
279 } 275 }
280 return false; 276 return false;
281} 277}
282bool OTodo::operator<=(const OTodo &toDoEvent )const 278bool OTodo::operator<=(const OTodo &toDoEvent )const
283{ 279{
284 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 280 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
285 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 281 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
286 if( hasDueDate() && toDoEvent.hasDueDate() ){ 282 if( hasDueDate() && toDoEvent.hasDueDate() ){
287 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 283 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
288 return priority() <= toDoEvent.priority(); 284 return priority() <= toDoEvent.priority();
289 }else{ 285 }else{
290 return dueDate() <= toDoEvent.dueDate(); 286 return dueDate() <= toDoEvent.dueDate();
291 } 287 }
292 } 288 }
293 return true; 289 return true;
294} 290}
295bool OTodo::operator>(const OTodo &toDoEvent )const 291bool OTodo::operator>(const OTodo &toDoEvent )const
296{ 292{
297 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 293 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
298 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 294 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
299 if( hasDueDate() && toDoEvent.hasDueDate() ){ 295 if( hasDueDate() && toDoEvent.hasDueDate() ){
300 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 296 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
301 return priority() > toDoEvent.priority(); 297 return priority() > toDoEvent.priority();
302 }else{ 298 }else{
303 return dueDate() > toDoEvent.dueDate(); 299 return dueDate() > toDoEvent.dueDate();
304 } 300 }
305 } 301 }
306 return false; 302 return false;
307} 303}
308bool OTodo::operator>=(const OTodo &toDoEvent )const 304bool OTodo::operator>=(const OTodo &toDoEvent )const
309{ 305{
310 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 306 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
311 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 307 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
312 if( hasDueDate() && toDoEvent.hasDueDate() ){ 308 if( hasDueDate() && toDoEvent.hasDueDate() ){
313 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 309 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
314 return priority() > toDoEvent.priority(); 310 return priority() > toDoEvent.priority();
315 }else{ 311 }else{
316 return dueDate() > toDoEvent.dueDate(); 312 return dueDate() > toDoEvent.dueDate();
317 } 313 }
318 } 314 }
319 return true; 315 return true;
320} 316}
321bool OTodo::operator==(const OTodo &toDoEvent )const 317bool OTodo::operator==(const OTodo &toDoEvent )const
322{ 318{
323 if ( data->priority != toDoEvent.data->priority ) return false; 319 if ( data->priority != toDoEvent.data->priority ) return false;
324 if ( data->priority != toDoEvent.data->prog ) return false; 320 if ( data->priority != toDoEvent.data->prog ) return false;
325 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 321 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
326 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 322 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
327 if ( data->date != toDoEvent.data->date ) return false; 323 if ( data->date != toDoEvent.data->date ) return false;
328 if ( data->sum != toDoEvent.data->sum ) return false; 324 if ( data->sum != toDoEvent.data->sum ) return false;
329 if ( data->desc != toDoEvent.data->desc ) return false; 325 if ( data->desc != toDoEvent.data->desc ) return false;
330 if ( data->hasAlarmDateTime != toDoEvent.data->hasAlarmDateTime )
331 return false;
332 if ( data->alarmDateTime != toDoEvent.data->alarmDateTime )
333 return false;
334 if ( data->maintainer != toDoEvent.data->maintainer ) 326 if ( data->maintainer != toDoEvent.data->maintainer )
335 return false; 327 return false;
336 328
337 return OPimRecord::operator==( toDoEvent ); 329 return OPimRecord::operator==( toDoEvent );
338} 330}
339void OTodo::deref() { 331void OTodo::deref() {
340 332
341// qWarning("deref in ToDoEvent"); 333// qWarning("deref in ToDoEvent");
342 if ( data->deref() ) { 334 if ( data->deref() ) {
343// qWarning("deleting"); 335// qWarning("deleting");
344 delete data; 336 delete data;
345 data= 0; 337 data= 0;
346 } 338 }
347} 339}
348OTodo &OTodo::operator=(const OTodo &item ) 340OTodo &OTodo::operator=(const OTodo &item )
349{ 341{
350 OPimRecord::operator=( item ); 342 OPimRecord::operator=( item );
351 //qWarning("operator= ref "); 343 //qWarning("operator= ref ");
352 item.data->ref(); 344 item.data->ref();
353 deref(); 345 deref();
354 data = item.data; 346 data = item.data;
355 347
356 return *this; 348 return *this;
357} 349}
358 350
359QMap<int, QString> OTodo::toMap() const { 351QMap<int, QString> OTodo::toMap() const {
360 QMap<int, QString> map; 352 QMap<int, QString> map;
361 353
362 map.insert( Uid, QString::number( uid() ) ); 354 map.insert( Uid, QString::number( uid() ) );
363 map.insert( Category, idsToString( categories() ) ); 355 map.insert( Category, idsToString( categories() ) );
364 map.insert( HasDate, QString::number( data->hasDate ) ); 356 map.insert( HasDate, QString::number( data->hasDate ) );
365 map.insert( Completed, QString::number( data->isCompleted ) ); 357 map.insert( Completed, QString::number( data->isCompleted ) );
366 map.insert( Description, data->desc ); 358 map.insert( Description, data->desc );
367 map.insert( Summary, data->sum ); 359 map.insert( Summary, data->sum );
368 map.insert( Priority, QString::number( data->priority ) ); 360 map.insert( Priority, QString::number( data->priority ) );
369 map.insert( DateDay, QString::number( data->date.day() ) ); 361 map.insert( DateDay, QString::number( data->date.day() ) );
370 map.insert( DateMonth, QString::number( data->date.month() ) ); 362 map.insert( DateMonth, QString::number( data->date.month() ) );
371 map.insert( DateYear, QString::number( data->date.year() ) ); 363 map.insert( DateYear, QString::number( data->date.year() ) );
372 map.insert( Progress, QString::number( data->prog ) ); 364 map.insert( Progress, QString::number( data->prog ) );
373// map.insert( CrossReference, crossToString() ); 365// map.insert( CrossReference, crossToString() );
374 map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) ); 366 /* FIXME!!! map.insert( State, );
375 map.insert( AlarmDateTime, data->alarmDateTime.toString() ); 367 map.insert( Recurrence, );
376 368 map.insert( Reminders, );
369 map.
370 */
377 return map; 371 return map;
378} 372}
379 373
380QMap<QString, QString> OTodo::toExtraMap()const { 374QMap<QString, QString> OTodo::toExtraMap()const {
381 return data->extra; 375 return data->extra;
382} 376}
383/** 377/**
384 * change or modify looks at the ref count and either 378 * change or modify looks at the ref count and either
385 * creates a new QShared Object or it can modify it 379 * creates a new QShared Object or it can modify it
386 * right in place 380 * right in place
387 */ 381 */
388void OTodo::changeOrModify() { 382void OTodo::changeOrModify() {
389 if ( data->count != 1 ) { 383 if ( data->count != 1 ) {
390 qWarning("changeOrModify"); 384 qWarning("changeOrModify");
391 data->deref(); 385 data->deref();
392 OTodoData* d2 = new OTodoData(); 386 OTodoData* d2 = new OTodoData();
393 copy(data, d2 ); 387 copy(data, d2 );
394 data = d2; 388 data = d2;
395 } 389 }
396} 390}
397// WATCHOUT 391// WATCHOUT
398/* 392/*
399 * if you add something to the Data struct 393 * if you add something to the Data struct
400 * be sure to copy it here 394 * be sure to copy it here
401 */ 395 */
402void OTodo::copy( OTodoData* src, OTodoData* dest ) { 396void OTodo::copy( OTodoData* src, OTodoData* dest ) {
403 dest->date = src->date; 397 dest->date = src->date;
404 dest->isCompleted = src->isCompleted; 398 dest->isCompleted = src->isCompleted;
405 dest->hasDate = src->hasDate; 399 dest->hasDate = src->hasDate;
406 dest->priority = src->priority; 400 dest->priority = src->priority;
407 dest->desc = src->desc; 401 dest->desc = src->desc;
408 dest->sum = src->sum; 402 dest->sum = src->sum;
409 dest->extra = src->extra; 403 dest->extra = src->extra;
410 dest->prog = src->prog; 404 dest->prog = src->prog;
411 dest->hasAlarmDateTime = src->hasAlarmDateTime;
412 dest->alarmDateTime = src->alarmDateTime;
413 dest->state = src->state; 405 dest->state = src->state;
414 dest->recur = src->recur; 406 dest->recur = src->recur;
415 dest->maintainer = src->maintainer; 407 dest->maintainer = src->maintainer;
408 dest->start = src->start;
409 dest->completed = src->completed;
410 dest->notifiers = src->notifiers;
416} 411}
417QString OTodo::type() const { 412QString OTodo::type() const {
418 return QString::fromLatin1("OTodo"); 413 return QString::fromLatin1("OTodo");
419} 414}
420QString OTodo::recordField(int /*id*/ )const { 415QString OTodo::recordField(int /*id*/ )const {
421 return QString::null; 416 return QString::null;
422} 417}
423 418
419int OTodo::rtti(){
420 return 1;
421}
diff --git a/libopie/pim/otodo.h b/libopie/pim/otodo.h
index 70b0253..2f66f55 100644
--- a/libopie/pim/otodo.h
+++ b/libopie/pim/otodo.h
@@ -1,246 +1,273 @@
1 1
2#ifndef OPIE_TODO_EVENT_H 2#ifndef OPIE_TODO_EVENT_H
3#define OPIE_TODO_EVENT_H 3#define OPIE_TODO_EVENT_H
4 4
5 5
6#include <qarray.h> 6#include <qarray.h>
7#include <qmap.h> 7#include <qmap.h>
8#include <qregexp.h> 8#include <qregexp.h>
9#include <qstringlist.h> 9#include <qstringlist.h>
10#include <qdatetime.h> 10#include <qdatetime.h>
11#include <qvaluelist.h> 11#include <qvaluelist.h>
12 12
13#include <qpe/recordfields.h> 13#include <qpe/recordfields.h>
14#include <qpe/palmtopuidgen.h> 14#include <qpe/palmtopuidgen.h>
15 15
16#include <opie/opimrecord.h> 16#include <opie/opimrecord.h>
17 17
18 18
19class OPimState; 19class OPimState;
20class ORecur; 20class ORecur;
21class OPimMaintainer; 21class OPimMaintainer;
22class OPimNotifyManager;
22class OTodo : public OPimRecord { 23class OTodo : public OPimRecord {
23public: 24public:
24 typedef QValueList<OTodo> ValueList; 25 typedef QValueList<OTodo> ValueList;
25 enum RecordFields { 26 enum RecordFields {
26 Uid = Qtopia::UID_ID, 27 Uid = Qtopia::UID_ID,
27 Category = Qtopia::CATEGORY_ID, 28 Category = Qtopia::CATEGORY_ID,
28 HasDate, 29 HasDate,
29 Completed, 30 Completed,
30 Description, 31 Description,
31 Summary, 32 Summary,
32 Priority, 33 Priority,
33 DateDay, 34 DateDay,
34 DateMonth, 35 DateMonth,
35 DateYear, 36 DateYear,
36 Progress, 37 Progress,
37 CrossReference, 38 CrossReference,
38 HasAlarmDateTime,
39 AlarmDateTime,
40 State, 39 State,
41 Recurrance, 40 Recurrence,
42 Alarms, 41 Alarms,
43 Reminders, 42 Reminders,
44 Notifiers 43 Notifiers,
44 Maintainer,
45 StartDate,
46 CompletedDate
45 }; 47 };
46 public: 48 public:
47 // priorities from Very low to very high 49 // priorities from Very low to very high
48 enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow }; 50 enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow };
49 51
50 /* Constructs a new ToDoEvent 52 /* Constructs a new ToDoEvent
51 @param completed Is the TodoEvent completed 53 @param completed Is the TodoEvent completed
52 @param priority What is the priority of this ToDoEvent 54 @param priority What is the priority of this ToDoEvent
53 @param category Which category does it belong( uid ) 55 @param category Which category does it belong( uid )
54 @param summary A small summary of the todo 56 @param summary A small summary of the todo
55 @param description What is this ToDoEvent about 57 @param description What is this ToDoEvent about
56 @param hasDate Does this Event got a deadline 58 @param hasDate Does this Event got a deadline
57 @param date what is the deadline? 59 @param date what is the deadline?
58 @param uid what is the UUID of this Event 60 @param uid what is the UUID of this Event
59 **/ 61 **/
60 OTodo( bool completed = false, int priority = Normal, 62 OTodo( bool completed = false, int priority = Normal,
61 const QStringList &category = QStringList(), 63 const QStringList &category = QStringList(),
62 const QString &summary = QString::null , 64 const QString &summary = QString::null ,
63 const QString &description = QString::null, 65 const QString &description = QString::null,
64 ushort progress = 0, 66 ushort progress = 0,
65 bool hasDate = false, QDate date = QDate::currentDate(), 67 bool hasDate = false, QDate date = QDate::currentDate(),
66 int uid = 0 /*empty*/ ); 68 int uid = 0 /*empty*/ );
67 69
68 OTodo( bool completed, int priority, 70 OTodo( bool completed, int priority,
69 const QArray<int>& category, 71 const QArray<int>& category,
70 const QString& summary = QString::null, 72 const QString& summary = QString::null,
71 const QString& description = QString::null, 73 const QString& description = QString::null,
72 ushort progress = 0, 74 ushort progress = 0,
73 bool hasDate = false, QDate date = QDate::currentDate(), 75 bool hasDate = false, QDate date = QDate::currentDate(),
74 int uid = 0 /* empty */ ); 76 int uid = 0 /* empty */ );
75 77
76 /* Copy c'tor 78 /** Copy c'tor
77 79 *
78 **/ 80 */
79 OTodo(const OTodo & ); 81 OTodo(const OTodo & );
80 82
81 /** 83 /**
82 *destructor 84 *destructor
83 */ 85 */
84 ~OTodo(); 86 ~OTodo();
85 87
86 /** 88 /**
87 * Is this event completed? 89 * Is this event completed?
88 */ 90 */
89 bool isCompleted() const; 91 bool isCompleted() const;
90 92
91 /** 93 /**
92 * Does this Event have a deadline 94 * Does this Event have a deadline
93 */ 95 */
94 bool hasDueDate() const; 96 bool hasDueDate() const;
97 bool hasStartDate()const;
98 bool hasCompletedDate()const;
95 99
96 /** 100 /**
97 * Does this Event has an alarm time ? 101 * Does this Event has an alarm time ?
98 */ 102 */
99 bool hasAlarmDateTime() const; 103 bool hasAlarmDateTime() const;
100 104
101 /** 105 /**
102 * What is the priority? 106 * What is the priority?
103 */ 107 */
104 int priority()const ; 108 int priority()const ;
105 109
106 /** 110 /**
107 * progress as ushort 0, 20, 40, 60, 80 or 100% 111 * progress as ushort 0, 20, 40, 60, 80 or 100%
108 */ 112 */
109 ushort progress() const; 113 ushort progress() const;
110 114
111 /** 115 /**
112 * The due Date 116 * The due Date
113 */ 117 */
114 QDate dueDate()const; 118 QDate dueDate()const;
115 119
116 /** 120 /**
117 * Alarm Date and Time 121 * When did it start?
122 */
123 QDate startDate()const;
124
125 /**
126 * When was it completed?
118 */ 127 */
119 QDateTime alarmDateTime()const; 128 QDate completedDate()const;
120 129
121 /** 130 /**
122 * What is the state of this OTodo? 131 * What is the state of this OTodo?
123 */ 132 */
124 OPimState state()const; 133 OPimState state()const;
125 134
126 /** 135 /**
127 * the recurrance of this 136 * the recurrance of this
128 */ 137 */
129 ORecur recurrence()const; 138 ORecur recurrence()const;
130 139
131 /** 140 /**
132 * the Maintainer of this OTodo 141 * the Maintainer of this OTodo
133 */ 142 */
134 OPimMaintainer maintainer()const; 143 OPimMaintainer maintainer()const;
135 144
136 /** 145 /**
137 * The description of the todo 146 * The description of the todo
138 */ 147 */
139 QString description()const; 148 QString description()const;
140 149
141 /** 150 /**
142 * A small summary of the todo 151 * A small summary of the todo
143 */ 152 */
144 QString summary() const; 153 QString summary() const;
145 154
146 /** 155 /**
147 * @reimplemented 156 * @reimplemented
148 * Return this todoevent in a RichText formatted QString 157 * Return this todoevent in a RichText formatted QString
149 */ 158 */
150 QString toRichText() const; 159 QString toRichText() const;
151 160
161 /*
162 * check if the sharing is still fine!! -zecke
163 */
164 /**
165 * return a reference to our notifiers...
166 */
167 OPimNotifyManager &notifiers();
168
152 /** 169 /**
153 * reimplementation 170 * reimplementations
154 */ 171 */
155 QString type()const; 172 QString type()const;
156 QString toShortText()const; 173 QString toShortText()const;
157 QMap<QString, QString> toExtraMap()const; 174 QMap<QString, QString> toExtraMap()const;
158 QString recordField(int id )const; 175 QString recordField(int id )const;
159 176
160 /** 177 /**
161 * toMap puts all data into the map. int relates 178 * toMap puts all data into the map. int relates
162 * to ToDoEvent RecordFields enum 179 * to ToDoEvent RecordFields enum
163 */ 180 */
164 QMap<int, QString> toMap()const; 181 QMap<int, QString> toMap()const;
165 182
166 /** 183 /**
167 * Set if this Todo is completed 184 * Set if this Todo is completed
168 */ 185 */
169 void setCompleted(bool completed ); 186 void setCompleted(bool completed );
170 187
171 /** 188 /**
172 * set if this todo got an end data 189 * set if this todo got an end data
173 */ 190 */
174 void setHasDueDate( bool hasDate ); 191 void setHasDueDate( bool hasDate );
175 192 // FIXME we do not have these for start, completed
176 /** 193 // cause we'll use the isNull() of QDate for figuring
177 * set if this todo has an alarm time and date 194 // out if it's has a date...
178 */ 195 // decide what to do here? -zecke
179 void setHasAlarmDateTime ( bool hasAlarm );
180 196
181 /** 197 /**
182 * Set the priority of the Todo 198 * Set the priority of the Todo
183 */ 199 */
184 void setPriority(int priority ); 200 void setPriority(int priority );
185 201
186 /** 202 /**
187 * Set the progress. 203 * Set the progress.
188 */ 204 */
189 void setProgress( ushort progress ); 205 void setProgress( ushort progress );
190 206
191 /** 207 /**
192 * set the end date 208 * set the end date
193 */ 209 */
194 void setDueDate( QDate date ); 210 void setDueDate( const QDate& date );
195 211
212 /**
213 * set the start date
214 */
215 void setStartDate( const QDate& date );
216
217 /**
218 * set the completed date
219 */
220 void setCompletedDate( const QDate& date );
196 221
197 void setRecurrence( const ORecur& ); 222 void setRecurrence( const ORecur& );
198 /** 223 /**
199 * set the alarm time 224 * set the alarm time
200 */ 225 */
201 void setAlarmDateTime ( const QDateTime& alarm ); 226 void setAlarmDateTime ( const QDateTime& alarm );
202 227
203 void setDescription(const QString& ); 228 void setDescription(const QString& );
204 void setSummary(const QString& ); 229 void setSummary(const QString& );
205 230
206 /** 231 /**
207 * set the state of a Todo 232 * set the state of a Todo
208 * @param state State what the todo should take 233 * @param state State what the todo should take
209 */ 234 */
210 void setState( const OPimState& state); 235 void setState( const OPimState& state);
211 236
212 /** 237 /**
213 * set the Maintainer Mode 238 * set the Maintainer Mode
214 */ 239 */
215 void setMaintainer( const OPimMaintainer& ); 240 void setMaintainer( const OPimMaintainer& );
216 241
217 bool isOverdue(); 242 bool isOverdue();
218 243
219 244
220 bool match( const QRegExp &r )const; 245 bool match( const QRegExp &r )const;
221 246
222 bool operator<(const OTodo &toDoEvent )const; 247 bool operator<(const OTodo &toDoEvent )const;
223 bool operator<=(const OTodo &toDoEvent )const; 248 bool operator<=(const OTodo &toDoEvent )const;
224 bool operator!=(const OTodo &toDoEvent )const; 249 bool operator!=(const OTodo &toDoEvent )const;
225 bool operator>(const OTodo &toDoEvent )const; 250 bool operator>(const OTodo &toDoEvent )const;
226 bool operator>=(const OTodo &toDoEvent)const; 251 bool operator>=(const OTodo &toDoEvent)const;
227 bool operator==(const OTodo &toDoEvent )const; 252 bool operator==(const OTodo &toDoEvent )const;
228 OTodo &operator=(const OTodo &toDoEvent ); 253 OTodo &operator=(const OTodo &toDoEvent );
229 254
255 static int rtti();
256
230 private: 257 private:
231 class OTodoPrivate; 258 class OTodoPrivate;
232 struct OTodoData; 259 struct OTodoData;
233 260
234 void deref(); 261 void deref();
235 inline void changeOrModify(); 262 inline void changeOrModify();
236 void copy( OTodoData* src, OTodoData* dest ); 263 void copy( OTodoData* src, OTodoData* dest );
237 OTodoPrivate *d; 264 OTodoPrivate *d;
238 OTodoData *data; 265 OTodoData *data;
239 266
240}; 267};
241inline bool OTodo::operator!=(const OTodo &toDoEvent )const { 268inline bool OTodo::operator!=(const OTodo &toDoEvent )const {
242 return !(*this == toDoEvent); 269 return !(*this == toDoEvent);
243} 270}
244 271
245 272
246#endif 273#endif
diff --git a/libopie/pim/otodoaccess.cpp b/libopie/pim/otodoaccess.cpp
index c258de6..d860411 100644
--- a/libopie/pim/otodoaccess.cpp
+++ b/libopie/pim/otodoaccess.cpp
@@ -1,81 +1,86 @@
1#include <qdatetime.h> 1#include <qdatetime.h>
2 2
3#include <qpe/alarmserver.h> 3#include <qpe/alarmserver.h>
4 4
5// #include "otodoaccesssql.h" 5// #include "otodoaccesssql.h"
6#include "otodoaccess.h" 6#include "otodoaccess.h"
7#include "obackendfactory.h" 7#include "obackendfactory.h"
8 8
9OTodoAccess::OTodoAccess( OTodoAccessBackend* end ) 9OTodoAccess::OTodoAccess( OTodoAccessBackend* end )
10 : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end ) 10 : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end )
11{ 11{
12// if (end == 0l ) 12// if (end == 0l )
13// m_todoBackEnd = new OTodoAccessBackendSQL( QString::null); 13// m_todoBackEnd = new OTodoAccessBackendSQL( QString::null);
14 14
15 // Zecke: Du musst hier noch für das XML-Backend einen Appnamen übergeben ! 15 // Zecke: Du musst hier noch für das XML-Backend einen Appnamen übergeben !
16 if (end == 0l ) 16 if (end == 0l )
17 m_todoBackEnd = OBackendFactory<OTodoAccessBackend>::Default ("todo", QString::null); 17 m_todoBackEnd = OBackendFactory<OTodoAccessBackend>::Default ("todo", QString::null);
18 18
19 setBackEnd( m_todoBackEnd ); 19 setBackEnd( m_todoBackEnd );
20} 20}
21OTodoAccess::~OTodoAccess() { 21OTodoAccess::~OTodoAccess() {
22// qWarning("~OTodoAccess"); 22// qWarning("~OTodoAccess");
23} 23}
24void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) { 24void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) {
25 QValueList<OTodo>::ConstIterator it; 25 QValueList<OTodo>::ConstIterator it;
26 for ( it = list.begin(); it != list.end(); ++it ) { 26 for ( it = list.begin(); it != list.end(); ++it ) {
27 replace( (*it) ); 27 replace( (*it) );
28 } 28 }
29} 29}
30OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, 30OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
31 const QDate& end, 31 const QDate& end,
32 bool includeNoDates ) { 32 bool includeNoDates ) {
33 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); 33 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates );
34 34
35 List lis( ints, this ); 35 List lis( ints, this );
36 return lis; 36 return lis;
37} 37}
38OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, 38OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
39 bool includeNoDates ) { 39 bool includeNoDates ) {
40 return effectiveToDos( start, QDate::currentDate(), 40 return effectiveToDos( start, QDate::currentDate(),
41 includeNoDates ); 41 includeNoDates );
42} 42}
43OTodoAccess::List OTodoAccess::overDue() { 43OTodoAccess::List OTodoAccess::overDue() {
44 List lis( m_todoBackEnd->overDue(), this ); 44 List lis( m_todoBackEnd->overDue(), this );
45 return lis; 45 return lis;
46} 46}
47void OTodoAccess::addAlarm( const OTodo& event) { 47void OTodoAccess::addAlarm( const OTodo& event) {
48 if (!event.hasAlarmDateTime() ) 48/* FIXME use the new notifier architecture
49 if (!event.hasAlarmDateTime() )
49 return; 50 return;
50 51
51 QDateTime now = QDateTime::currentDateTime(); 52 QDateTime now = QDateTime::currentDateTime();
52 QDateTime schedule = event.alarmDateTime(); 53 QDateTime schedule = event.alarmDateTime();
53 54
54 if ( schedule > now ){ 55 if ( schedule > now ){
55 AlarmServer::addAlarm( schedule, 56 AlarmServer::addAlarm( schedule,
56 "QPE/Application/todolist", 57 "QPE/Application/todolist",
57 "alarm(QDateTime,int)", event.uid() ); 58 "alarm(QDateTime,int)", event.uid() );
58 59
59 } 60 }
61*/
60} 62}
61void OTodoAccess::delAlarm( int uid) { 63void OTodoAccess::delAlarm( int uid) {
62 64
63 QDateTime schedule; // Create null DateTime 65 QDateTime schedule; // Create null DateTime
64 66
65 // I hope this will remove all scheduled alarms 67 // I hope this will remove all scheduled alarms
66 // with the given uid !? 68 // with the given uid !?
67 // If not: I have to rethink how to remove already 69 // If not: I have to rethink how to remove already
68 // scheduled events... (se) 70 // scheduled events... (se)
69 // it should be fine -zecke 71 // it should be fine -zecke
70// qWarning("Removing alarm for event with uid %d", uid ); 72// qWarning("Removing alarm for event with uid %d", uid );
71 AlarmServer::deleteAlarm( schedule , 73 AlarmServer::deleteAlarm( schedule ,
72 "QPE/Application/todolist", 74 "QPE/Application/todolist",
73 "alarm(QDateTime,int)", uid ); 75 "alarm(QDateTime,int)", uid );
74} 76}
75/* sort order */ 77/* sort order */
76OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { 78OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) {
77 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, 79 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort,
78 filter, cat ); 80 filter, cat );
79 OTodoAccess::List list( ints, this ); 81 OTodoAccess::List list( ints, this );
80 return list; 82 return list;
81} 83}
84void OTodoAccess::removeAllCompleted() {
85 m_todoBackEnd->removeAllCompleted();
86}
diff --git a/libopie/pim/otodoaccess.h b/libopie/pim/otodoaccess.h
index 390ab0e..c079155 100644
--- a/libopie/pim/otodoaccess.h
+++ b/libopie/pim/otodoaccess.h
@@ -1,93 +1,98 @@
1#ifndef OPIE_TODO_ACCESS_H 1#ifndef OPIE_TODO_ACCESS_H
2#define OPIE_TODO_ACCESS_H 2#define OPIE_TODO_ACCESS_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include <qvaluelist.h> 5#include <qvaluelist.h>
6 6
7#include "otodo.h" 7#include "otodo.h"
8#include "otodoaccessbackend.h" 8#include "otodoaccessbackend.h"
9#include "opimaccesstemplate.h" 9#include "opimaccesstemplate.h"
10 10
11 11
12/** 12/**
13 * OTodoAccess 13 * OTodoAccess
14 * the class to get access to 14 * the class to get access to
15 * the todolist 15 * the todolist
16 */ 16 */
17class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { 17class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> {
18 Q_OBJECT 18 Q_OBJECT
19public: 19public:
20 enum SortOrder { Completed = 0, 20 enum SortOrder { Completed = 0,
21 Priority, 21 Priority,
22 Description, 22 Description,
23 Deadline }; 23 Deadline };
24 enum SortFilter{ Category =1, 24 enum SortFilter{ Category =1,
25 OnlyOverDue= 2, 25 OnlyOverDue= 2,
26 DoNotShowCompleted =4 }; 26 DoNotShowCompleted =4 };
27 /** 27 /**
28 * if you use 0l 28 * if you use 0l
29 * the default resource will be 29 * the default resource will be
30 * picked up 30 * picked up
31 */ 31 */
32 OTodoAccess( OTodoAccessBackend* = 0l); 32 OTodoAccess( OTodoAccessBackend* = 0l);
33 ~OTodoAccess(); 33 ~OTodoAccess();
34 34
35 35
36 /* our functions here */ 36 /* our functions here */
37 /** 37 /**
38 * include todos from start to end 38 * include todos from start to end
39 * includeNoDates whether or not to include 39 * includeNoDates whether or not to include
40 * events with no dates 40 * events with no dates
41 */ 41 */
42 List effectiveToDos( const QDate& start, 42 List effectiveToDos( const QDate& start,
43 const QDate& end, 43 const QDate& end,
44 bool includeNoDates = true ); 44 bool includeNoDates = true );
45 45
46 /** 46 /**
47 * start 47 * start
48 * end date taken from the currentDate() 48 * end date taken from the currentDate()
49 */ 49 */
50 List effectiveToDos( const QDate& start, 50 List effectiveToDos( const QDate& start,
51 bool includeNoDates = true ); 51 bool includeNoDates = true );
52 52
53 53
54 /** 54 /**
55 * return overdue OTodos 55 * return overdue OTodos
56 */ 56 */
57 List overDue(); 57 List overDue();
58 58
59 /** 59 /**
60 * 60 *
61 */ 61 */
62 List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); 62 List sorted( bool ascending, int sortOrder, int sortFilter, int cat );
63 63
64 /** 64 /**
65 * merge a list of OTodos into 65 * merge a list of OTodos into
66 * the resource 66 * the resource
67 */ 67 */
68 void mergeWith( const QValueList<OTodo>& ); 68 void mergeWith( const QValueList<OTodo>& );
69 69
70 /** 70 /**
71 * delete all already completed items
72 */
73 void removeAllCompleted();
74
75signals:
76 /**
77 * if the OTodoAccess was changed
78 */
79 void signalChanged( const OTodoAccess* );
80private:
81 /**
71 * add an Alarm to the AlarmServer 82 * add an Alarm to the AlarmServer
72 */ 83 */
73 void addAlarm( const OTodo& ); 84 void addAlarm( const OTodo& );
74 85
75 /** 86 /**
76 * delete an alarm with the uid from 87 * delete an alarm with the uid from
77 * the alarm server 88 * the alarm server
78 */ 89 */
79 void delAlarm( int uid ); 90 void delAlarm( int uid );
80 91
81signals:
82 /**
83 * if the OTodoAccess was changed
84 */
85 void signalChanged( const OTodoAccess* );
86private:
87 int m_cat; 92 int m_cat;
88 OTodoAccessBackend* m_todoBackEnd; 93 OTodoAccessBackend* m_todoBackEnd;
89 class OTodoAccessPrivate; 94 class OTodoAccessPrivate;
90 OTodoAccessPrivate* d; 95 OTodoAccessPrivate* d;
91}; 96};
92 97
93#endif 98#endif
diff --git a/libopie/pim/otodoaccessbackend.h b/libopie/pim/otodoaccessbackend.h
index 3bad6b7..7944a2c 100644
--- a/libopie/pim/otodoaccessbackend.h
+++ b/libopie/pim/otodoaccessbackend.h
@@ -1,20 +1,21 @@
1#ifndef OPIE_TODO_ACCESS_BACKEND_H 1#ifndef OPIE_TODO_ACCESS_BACKEND_H
2#define OPIE_TODO_ACCESS_BACKEND_H 2#define OPIE_TODO_ACCESS_BACKEND_H
3 3
4#include "otodo.h" 4#include "otodo.h"
5#include "opimaccessbackend.h" 5#include "opimaccessbackend.h"
6 6
7class OTodoAccessBackend : public OPimAccessBackend<OTodo> { 7class OTodoAccessBackend : public OPimAccessBackend<OTodo> {
8public: 8public:
9 OTodoAccessBackend(); 9 OTodoAccessBackend();
10 ~OTodoAccessBackend(); 10 ~OTodoAccessBackend();
11 virtual QArray<int> effectiveToDos( const QDate& start, 11 virtual QArray<int> effectiveToDos( const QDate& start,
12 const QDate& end, 12 const QDate& end,
13 bool includeNoDates ) = 0; 13 bool includeNoDates ) = 0;
14 virtual QArray<int> overDue() = 0; 14 virtual QArray<int> overDue() = 0;
15 virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter, 15 virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter,
16 int cat ) = 0; 16 int cat ) = 0;
17 virtual void removeAllCompleted() = 0;
17 18
18}; 19};
19 20
20#endif 21#endif
diff --git a/libopie/pim/otodoaccessvcal.cpp b/libopie/pim/otodoaccessvcal.cpp
index ac70ea0..e96cc3c 100644
--- a/libopie/pim/otodoaccessvcal.cpp
+++ b/libopie/pim/otodoaccessvcal.cpp
@@ -1,192 +1,198 @@
1#include <qfile.h> 1#include <qfile.h>
2 2
3#include <qtopia/private/vobject_p.h> 3#include <qtopia/private/vobject_p.h>
4#include <qtopia/timeconversion.h> 4#include <qtopia/timeconversion.h>
5#include <qtopia/private/qfiledirect_p.h> 5#include <qtopia/private/qfiledirect_p.h>
6 6
7#include "otodoaccessvcal.h" 7#include "otodoaccessvcal.h"
8 8
9namespace { 9namespace {
10 static OTodo eventByVObj( VObject *obj ){ 10 static OTodo eventByVObj( VObject *obj ){
11 OTodo event; 11 OTodo event;
12 VObject *ob; 12 VObject *ob;
13 QCString name; 13 QCString name;
14 // no uid, attendees, ... and no fun 14 // no uid, attendees, ... and no fun
15 // description 15 // description
16 if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ 16 if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){
17 name = vObjectStringZValue( ob ); 17 name = vObjectStringZValue( ob );
18 event.setDescription( name ); 18 event.setDescription( name );
19 } 19 }
20 // summary 20 // summary
21 if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) { 21 if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) {
22 name = vObjectStringZValue( ob ); 22 name = vObjectStringZValue( ob );
23 event.setSummary( name ); 23 event.setSummary( name );
24 } 24 }
25 // completed 25 // completed
26 if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ 26 if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){
27 name = vObjectStringZValue( ob ); 27 name = vObjectStringZValue( ob );
28 if( name == "COMPLETED" ){ 28 if( name == "COMPLETED" ){
29 event.setCompleted( true ); 29 event.setCompleted( true );
30 }else{ 30 }else{
31 event.setCompleted( false ); 31 event.setCompleted( false );
32 } 32 }
33 }else 33 }else
34 event.setCompleted( false ); 34 event.setCompleted( false );
35 // priority 35 // priority
36 if ((ob = isAPropertyOf(obj, VCPriorityProp))) { 36 if ((ob = isAPropertyOf(obj, VCPriorityProp))) {
37 name = vObjectStringZValue( ob ); 37 name = vObjectStringZValue( ob );
38 bool ok; 38 bool ok;
39 event.setPriority(name.toInt(&ok) ); 39 event.setPriority(name.toInt(&ok) );
40 } 40 }
41 //due date 41 //due date
42 if((ob = isAPropertyOf(obj, VCDueProp)) ){ 42 if((ob = isAPropertyOf(obj, VCDueProp)) ){
43 event.setHasDueDate( true ); 43 event.setHasDueDate( true );
44 name = vObjectStringZValue( ob ); 44 name = vObjectStringZValue( ob );
45 event.setDueDate( TimeConversion::fromISO8601( name).date() ); 45 event.setDueDate( TimeConversion::fromISO8601( name).date() );
46 } 46 }
47 // categories 47 // categories
48 if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ 48 if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){
49 name = vObjectStringZValue( ob ); 49 name = vObjectStringZValue( ob );
50 qWarning("Categories:%s", name.data() ); 50 qWarning("Categories:%s", name.data() );
51 } 51 }
52 52
53 event.setUid( 1 ); 53 event.setUid( 1 );
54 return event; 54 return event;
55 }; 55 };
56 static VObject *vobjByEvent( const OTodo &event ) { 56 static VObject *vobjByEvent( const OTodo &event ) {
57 VObject *task = newVObject( VCTodoProp ); 57 VObject *task = newVObject( VCTodoProp );
58 if( task == 0 ) 58 if( task == 0 )
59 return 0l; 59 return 0l;
60 60
61 if( event.hasDueDate() ) 61 if( event.hasDueDate() )
62 addPropValue( task, VCDueProp, 62 addPropValue( task, VCDueProp,
63 TimeConversion::toISO8601( event.dueDate() ) ); 63 TimeConversion::toISO8601( event.dueDate() ) );
64 64
65 if( event.isCompleted() ) 65 if( event.isCompleted() )
66 addPropValue( task, VCStatusProp, "COMPLETED"); 66 addPropValue( task, VCStatusProp, "COMPLETED");
67 67
68 QString string = QString::number(event.priority() ); 68 QString string = QString::number(event.priority() );
69 addPropValue( task, VCPriorityProp, string.local8Bit() ); 69 addPropValue( task, VCPriorityProp, string.local8Bit() );
70 70
71 addPropValue( task, VCCategoriesProp, 71 addPropValue( task, VCCategoriesProp,
72 event.idsToString( event.categories() ).local8Bit() ); 72 event.idsToString( event.categories() ).local8Bit() );
73 73
74 addPropValue( task, VCDescriptionProp, 74 addPropValue( task, VCDescriptionProp,
75 event.description().local8Bit() ); 75 event.description().local8Bit() );
76 76
77 addPropValue( task, VCSummaryProp, 77 addPropValue( task, VCSummaryProp,
78 event.summary().local8Bit() ); 78 event.summary().local8Bit() );
79 return task; 79 return task;
80}; 80};
81} 81}
82 82
83OTodoAccessVCal::OTodoAccessVCal( const QString& path ) 83OTodoAccessVCal::OTodoAccessVCal( const QString& path )
84 : m_dirty(false), m_file( path ) 84 : m_dirty(false), m_file( path )
85{ 85{
86} 86}
87OTodoAccessVCal::~OTodoAccessVCal() { 87OTodoAccessVCal::~OTodoAccessVCal() {
88} 88}
89bool OTodoAccessVCal::load() { 89bool OTodoAccessVCal::load() {
90 m_map.clear(); 90 m_map.clear();
91 m_dirty = false; 91 m_dirty = false;
92 92
93 VObject* vcal = 0l; 93 VObject* vcal = 0l;
94 vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 94 vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
95 if (!vcal ) 95 if (!vcal )
96 return false; 96 return false;
97 97
98 // Iterate over the list 98 // Iterate over the list
99 VObjectIterator it; 99 VObjectIterator it;
100 VObject* vobj; 100 VObject* vobj;
101 101
102 initPropIterator(&it, vcal); 102 initPropIterator(&it, vcal);
103 103
104 while( moreIteration( &it ) ) { 104 while( moreIteration( &it ) ) {
105 vobj = ::nextVObject( &it ); 105 vobj = ::nextVObject( &it );
106 QCString name = ::vObjectName( vobj ); 106 QCString name = ::vObjectName( vobj );
107 if( name == VCTodoProp ){ 107 if( name == VCTodoProp ){
108 OTodo to = eventByVObj( vobj ); 108 OTodo to = eventByVObj( vobj );
109 m_map.insert( to.uid(), to ); 109 m_map.insert( to.uid(), to );
110 } 110 }
111 } 111 }
112 112
113 // Should I do a delete vcal? 113 // Should I do a delete vcal?
114 114
115 return true; 115 return true;
116} 116}
117bool OTodoAccessVCal::reload() { 117bool OTodoAccessVCal::reload() {
118 return load(); 118 return load();
119} 119}
120bool OTodoAccessVCal::save() { 120bool OTodoAccessVCal::save() {
121 if (!m_dirty ) 121 if (!m_dirty )
122 return true; 122 return true;
123 123
124 QFileDirect file( m_file ); 124 QFileDirect file( m_file );
125 if (!file.open(IO_WriteOnly ) ) 125 if (!file.open(IO_WriteOnly ) )
126 return false; 126 return false;
127 127
128 VObject *obj; 128 VObject *obj;
129 obj = newVObject( VCCalProp ); 129 obj = newVObject( VCCalProp );
130 addPropValue( obj, VCVersionProp, "1.0" ); 130 addPropValue( obj, VCVersionProp, "1.0" );
131 VObject *vo; 131 VObject *vo;
132 for(QMap<int, OTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ 132 for(QMap<int, OTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
133 vo = vobjByEvent( it.data() ); 133 vo = vobjByEvent( it.data() );
134 addVObjectProp(obj, vo ); 134 addVObjectProp(obj, vo );
135 } 135 }
136 writeVObject( file.directHandle(), obj ); 136 writeVObject( file.directHandle(), obj );
137 cleanVObject( obj ); 137 cleanVObject( obj );
138 cleanStrTbl(); 138 cleanStrTbl();
139 139
140 m_dirty = false; 140 m_dirty = false;
141 return true; 141 return true;
142} 142}
143void OTodoAccessVCal::clear() { 143void OTodoAccessVCal::clear() {
144 m_map.clear(); 144 m_map.clear();
145 m_dirty = true; 145 m_dirty = true;
146} 146}
147bool OTodoAccessVCal::add( const OTodo& to ) { 147bool OTodoAccessVCal::add( const OTodo& to ) {
148 m_map.insert( to.uid(), to ); 148 m_map.insert( to.uid(), to );
149 m_dirty = true; 149 m_dirty = true;
150 return true; 150 return true;
151} 151}
152bool OTodoAccessVCal::remove( int uid ) { 152bool OTodoAccessVCal::remove( int uid ) {
153 m_map.remove( uid ); 153 m_map.remove( uid );
154 m_dirty = true; 154 m_dirty = true;
155 return true; 155 return true;
156} 156}
157void OTodoAccessVCal::removeAllCompleted() {
158 for ( QMap<int, OTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) {
159 if ( (*it).isCompleted() )
160 m_map.remove( it );
161 }
162}
157bool OTodoAccessVCal::replace( const OTodo& to ) { 163bool OTodoAccessVCal::replace( const OTodo& to ) {
158 m_map.replace( to.uid(), to ); 164 m_map.replace( to.uid(), to );
159 m_dirty = true; 165 m_dirty = true;
160 return true; 166 return true;
161} 167}
162OTodo OTodoAccessVCal::find(int uid )const { 168OTodo OTodoAccessVCal::find(int uid )const {
163 return m_map[uid]; 169 return m_map[uid];
164} 170}
165QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) { 171QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) {
166 QArray<int> ar(0); 172 QArray<int> ar(0);
167 return ar; 173 return ar;
168} 174}
169QArray<int> OTodoAccessVCal::allRecords()const { 175QArray<int> OTodoAccessVCal::allRecords()const {
170 QArray<int> ar( m_map.count() ); 176 QArray<int> ar( m_map.count() );
171 QMap<int, OTodo>::ConstIterator it; 177 QMap<int, OTodo>::ConstIterator it;
172 int i = 0; 178 int i = 0;
173 for ( it = m_map.begin(); it != m_map.end(); ++it ) { 179 for ( it = m_map.begin(); it != m_map.end(); ++it ) {
174 ar[i] = it.key(); 180 ar[i] = it.key();
175 i++; 181 i++;
176 } 182 }
177 return ar; 183 return ar;
178} 184}
179QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int ) { 185QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int ) {
180 QArray<int> ar(0); 186 QArray<int> ar(0);
181 return ar; 187 return ar;
182} 188}
183QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& , 189QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& ,
184 const QDate& , 190 const QDate& ,
185 bool ) { 191 bool ) {
186 QArray<int> ar(0); 192 QArray<int> ar(0);
187 return ar; 193 return ar;
188} 194}
189QArray<int> OTodoAccessVCal::overDue() { 195QArray<int> OTodoAccessVCal::overDue() {
190 QArray<int> ar(0); 196 QArray<int> ar(0);
191 return ar; 197 return ar;
192} 198}
diff --git a/libopie/pim/otodoaccessvcal.h b/libopie/pim/otodoaccessvcal.h
index 4499a7e..452f602 100644
--- a/libopie/pim/otodoaccessvcal.h
+++ b/libopie/pim/otodoaccessvcal.h
@@ -1,35 +1,37 @@
1#ifndef OPIE_OTODO_ACCESS_VCAL_H 1#ifndef OPIE_OTODO_ACCESS_VCAL_H
2#define OPIE_OTODO_ACCESS_VCAL_H 2#define OPIE_OTODO_ACCESS_VCAL_H
3 3
4#include "otodoaccessbackend.h" 4#include "otodoaccessbackend.h"
5 5
6class OTodoAccessVCal : public OTodoAccessBackend { 6class OTodoAccessVCal : public OTodoAccessBackend {
7public: 7public:
8 OTodoAccessVCal(const QString& ); 8 OTodoAccessVCal(const QString& );
9 ~OTodoAccessVCal(); 9 ~OTodoAccessVCal();
10 10
11 bool load(); 11 bool load();
12 bool reload(); 12 bool reload();
13 bool save(); 13 bool save();
14 14
15 QArray<int> allRecords()const; 15 QArray<int> allRecords()const;
16 QArray<int> queryByExample( const OTodo& t, int sort ); 16 QArray<int> queryByExample( const OTodo& t, int sort );
17 QArray<int> effectiveToDos( const QDate& start, 17 QArray<int> effectiveToDos( const QDate& start,
18 const QDate& end, 18 const QDate& end,
19 bool includeNoDates ); 19 bool includeNoDates );
20 QArray<int> overDue(); 20 QArray<int> overDue();
21 QArray<int> sorted( bool asc, int sortOrder, int sortFilter, 21 QArray<int> sorted( bool asc, int sortOrder, int sortFilter,
22 int cat ); 22 int cat );
23 OTodo find(int uid)const; 23 OTodo find(int uid)const;
24 void clear(); 24 void clear();
25 bool add( const OTodo& ); 25 bool add( const OTodo& );
26 bool remove( int uid ); 26 bool remove( int uid );
27 bool replace( const OTodo& ); 27 bool replace( const OTodo& );
28 28
29 void removeAllCompleted();
30
29private: 31private:
30 bool m_dirty : 1; 32 bool m_dirty : 1;
31 QString m_file; 33 QString m_file;
32 QMap<int, OTodo> m_map; 34 QMap<int, OTodo> m_map;
33}; 35};
34 36
35#endif 37#endif
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp
index c1682c6..b2dfe80 100644
--- a/libopie/pim/otodoaccessxml.cpp
+++ b/libopie/pim/otodoaccessxml.cpp
@@ -1,618 +1,619 @@
1#include <qfile.h> 1#include <qfile.h>
2#include <qvector.h> 2#include <qvector.h>
3 3
4#include <qpe/global.h> 4#include <qpe/global.h>
5#include <qpe/stringutil.h> 5#include <qpe/stringutil.h>
6#include <qpe/timeconversion.h> 6#include <qpe/timeconversion.h>
7 7
8#include <opie/xmltree.h> 8#include <opie/xmltree.h>
9 9
10#include "otodoaccessxml.h" 10#include "otodoaccessxml.h"
11 11
12OTodoAccessXML::OTodoAccessXML( const QString& appName, 12OTodoAccessXML::OTodoAccessXML( const QString& appName,
13 const QString& fileName ) 13 const QString& fileName )
14 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) 14 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false )
15{ 15{
16 if (!fileName.isEmpty() ) 16 if (!fileName.isEmpty() )
17 m_file = fileName; 17 m_file = fileName;
18 else 18 else
19 m_file = Global::applicationFileName( "todolist", "todolist.xml" ); 19 m_file = Global::applicationFileName( "todolist", "todolist.xml" );
20} 20}
21OTodoAccessXML::~OTodoAccessXML() { 21OTodoAccessXML::~OTodoAccessXML() {
22 22
23} 23}
24bool OTodoAccessXML::load() { 24bool OTodoAccessXML::load() {
25 m_opened = true; 25 m_opened = true;
26 m_changed = false; 26 m_changed = false;
27 /* initialize dict */ 27 /* initialize dict */
28 /* 28 /*
29 * UPDATE dict if you change anything!!! 29 * UPDATE dict if you change anything!!!
30 */ 30 */
31 QAsciiDict<int> dict(15); 31 QAsciiDict<int> dict(21);
32 dict.setAutoDelete( TRUE ); 32 dict.setAutoDelete( TRUE );
33 dict.insert("Categories" , new int(OTodo::Category) ); 33 dict.insert("Categories" , new int(OTodo::Category) );
34 dict.insert("Uid" , new int(OTodo::Uid) ); 34 dict.insert("Uid" , new int(OTodo::Uid) );
35 dict.insert("HasDate" , new int(OTodo::HasDate) ); 35 dict.insert("HasDate" , new int(OTodo::HasDate) );
36 dict.insert("Completed" , new int(OTodo::Completed) ); 36 dict.insert("Completed" , new int(OTodo::Completed) );
37 dict.insert("Description" , new int(OTodo::Description) ); 37 dict.insert("Description" , new int(OTodo::Description) );
38 dict.insert("Summary" , new int(OTodo::Summary) ); 38 dict.insert("Summary" , new int(OTodo::Summary) );
39 dict.insert("Priority" , new int(OTodo::Priority) ); 39 dict.insert("Priority" , new int(OTodo::Priority) );
40 dict.insert("DateDay" , new int(OTodo::DateDay) ); 40 dict.insert("DateDay" , new int(OTodo::DateDay) );
41 dict.insert("DateMonth" , new int(OTodo::DateMonth) ); 41 dict.insert("DateMonth" , new int(OTodo::DateMonth) );
42 dict.insert("DateYear" , new int(OTodo::DateYear) ); 42 dict.insert("DateYear" , new int(OTodo::DateYear) );
43 dict.insert("Progress" , new int(OTodo::Progress) ); 43 dict.insert("Progress" , new int(OTodo::Progress) );
44 dict.insert("Completed", new int(OTodo::Completed) ); 44 dict.insert("Completed", new int(OTodo::Completed) );
45 dict.insert("CrossReference", new int(OTodo::CrossReference) ); 45 dict.insert("CrossReference", new int(OTodo::CrossReference) );
46 dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); 46 dict.insert("State", new int(OTodo::State) );
47 dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); 47 dict.insert("Recurrence", new int(OTodo::Recurrence) );
48 dict.insert("Alarms", new int(OTodo::Alarms) );
49 dict.insert("Reminders", new int(OTodo::Reminders) );
50 dict.insert("Notifiers", new int(OTodo::Notifiers) );
51 dict.insert("Maintainer", new int(OTodo::Maintainer) );
48 52
49 // here the custom XML parser from TT it's GPL 53 // here the custom XML parser from TT it's GPL
50 // but we want to push that to TT..... 54 // but we want to push OpiePIM... to TT.....
51 QFile f(m_file ); 55 QFile f(m_file );
52 if (!f.open(IO_ReadOnly) ) 56 if (!f.open(IO_ReadOnly) )
53 return false; 57 return false;
54 58
55 QByteArray ba = f.readAll(); 59 QByteArray ba = f.readAll();
56 f.close(); 60 f.close();
57 char* dt = ba.data(); 61 char* dt = ba.data();
58 int len = ba.size(); 62 int len = ba.size();
59 int i = 0; 63 int i = 0;
60 char *point; 64 char *point;
61 const char* collectionString = "<Task "; 65 const char* collectionString = "<Task ";
62 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) { 66 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) {
63 i = point -dt; 67 i = point -dt;
64 i+= strlen(collectionString); 68 i+= strlen(collectionString);
65 OTodo ev; 69 OTodo ev;
66 m_year = m_month = m_day = 0; 70 m_year = m_month = m_day = 0;
67 71
68 while ( TRUE ) { 72 while ( TRUE ) {
69 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 73 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
70 ++i; 74 ++i;
71 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 75 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
72 break; 76 break;
73 77
74 // we have another attribute, read it. 78 // we have another attribute, read it.
75 int j = i; 79 int j = i;
76 while ( j < len && dt[j] != '=' ) 80 while ( j < len && dt[j] != '=' )
77 ++j; 81 ++j;
78 QCString attr( dt+i, j-i+1); 82 QCString attr( dt+i, j-i+1);
79 83
80 i = ++j; // skip = 84 i = ++j; // skip =
81 85
82 // find the start of quotes 86 // find the start of quotes
83 while ( i < len && dt[i] != '"' ) 87 while ( i < len && dt[i] != '"' )
84 ++i; 88 ++i;
85 j = ++i; 89 j = ++i;
86 90
87 bool haveUtf = FALSE; 91 bool haveUtf = FALSE;
88 bool haveEnt = FALSE; 92 bool haveEnt = FALSE;
89 while ( j < len && dt[j] != '"' ) { 93 while ( j < len && dt[j] != '"' ) {
90 if ( ((unsigned char)dt[j]) > 0x7f ) 94 if ( ((unsigned char)dt[j]) > 0x7f )
91 haveUtf = TRUE; 95 haveUtf = TRUE;
92 if ( dt[j] == '&' ) 96 if ( dt[j] == '&' )
93 haveEnt = TRUE; 97 haveEnt = TRUE;
94 ++j; 98 ++j;
95 } 99 }
96 if ( i == j ) { 100 if ( i == j ) {
97 // empty value 101 // empty value
98 i = j + 1; 102 i = j + 1;
99 continue; 103 continue;
100 } 104 }
101 105
102 QCString value( dt+i, j-i+1 ); 106 QCString value( dt+i, j-i+1 );
103 i = j + 1; 107 i = j + 1;
104 108
105 QString str = (haveUtf ? QString::fromUtf8( value ) 109 QString str = (haveUtf ? QString::fromUtf8( value )
106 : QString::fromLatin1( value ) ); 110 : QString::fromLatin1( value ) );
107 if ( haveEnt ) 111 if ( haveEnt )
108 str = Qtopia::plainString( str ); 112 str = Qtopia::plainString( str );
109 113
110 /* 114 /*
111 * add key + value 115 * add key + value
112 */ 116 */
113 todo( &dict, ev, attr, str ); 117 todo( &dict, ev, attr, str );
114 118
115 } 119 }
116 /* 120 /*
117 * now add it 121 * now add it
118 */ 122 */
119 if (m_events.contains( ev.uid() ) || ev.uid() == 0) { 123 if (m_events.contains( ev.uid() ) || ev.uid() == 0) {
120 ev.setUid( 1 ); 124 ev.setUid( 1 );
121 m_changed = true; 125 m_changed = true;
122 } 126 }
123 if ( ev.hasDueDate() ) { 127 if ( ev.hasDueDate() ) {
124 ev.setDueDate( QDate(m_year, m_month, m_day) ); 128 ev.setDueDate( QDate(m_year, m_month, m_day) );
125 } 129 }
126 m_events.insert(ev.uid(), ev ); 130 m_events.insert(ev.uid(), ev );
127 m_year = m_month = m_day = -1; 131 m_year = m_month = m_day = -1;
128 } 132 }
129 133
130 qWarning("counts %d records loaded!", m_events.count() ); 134 qWarning("counts %d records loaded!", m_events.count() );
131 return true; 135 return true;
132} 136}
133bool OTodoAccessXML::reload() { 137bool OTodoAccessXML::reload() {
134 return load(); 138 return load();
135} 139}
136bool OTodoAccessXML::save() { 140bool OTodoAccessXML::save() {
137// qWarning("saving"); 141// qWarning("saving");
138 if (!m_opened || !m_changed ) { 142 if (!m_opened || !m_changed ) {
139// qWarning("not saving"); 143// qWarning("not saving");
140 return true; 144 return true;
141 } 145 }
142 QString strNewFile = m_file + ".new"; 146 QString strNewFile = m_file + ".new";
143 QFile f( strNewFile ); 147 QFile f( strNewFile );
144 if (!f.open( IO_WriteOnly|IO_Raw ) ) 148 if (!f.open( IO_WriteOnly|IO_Raw ) )
145 return false; 149 return false;
146 150
147 int written; 151 int written;
148 QString out; 152 QString out;
149 out = "<!DOCTYPE Tasks>\n<Tasks>\n"; 153 out = "<!DOCTYPE Tasks>\n<Tasks>\n";
150 154
151 // for all todos 155 // for all todos
152 QMap<int, OTodo>::Iterator it; 156 QMap<int, OTodo>::Iterator it;
153 for (it = m_events.begin(); it != m_events.end(); ++it ) { 157 for (it = m_events.begin(); it != m_events.end(); ++it ) {
154 out+= "<Task " + toString( (*it) ) + " />\n"; 158 out+= "<Task " + toString( (*it) ) + " />\n";
155 QCString cstr = out.utf8(); 159 QCString cstr = out.utf8();
156 written = f.writeBlock( cstr.data(), cstr.length() ); 160 written = f.writeBlock( cstr.data(), cstr.length() );
157 161
158 /* less written then we wanted */ 162 /* less written then we wanted */
159 if ( written != (int)cstr.length() ) { 163 if ( written != (int)cstr.length() ) {
160 f.close(); 164 f.close();
161 QFile::remove( strNewFile ); 165 QFile::remove( strNewFile );
162 return false; 166 return false;
163 } 167 }
164 out = QString::null; 168 out = QString::null;
165 } 169 }
166 170
167 out += "</Tasks>"; 171 out += "</Tasks>";
168 QCString cstr = out.utf8(); 172 QCString cstr = out.utf8();
169 written = f.writeBlock( cstr.data(), cstr.length() ); 173 written = f.writeBlock( cstr.data(), cstr.length() );
170 174
171 if ( written != (int)cstr.length() ) { 175 if ( written != (int)cstr.length() ) {
172 f.close(); 176 f.close();
173 QFile::remove( strNewFile ); 177 QFile::remove( strNewFile );
174 return false; 178 return false;
175 } 179 }
176 /* flush before renaming */ 180 /* flush before renaming */
177 f.close(); 181 f.close();
178 182
179 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { 183 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
180// qWarning("error renaming"); 184// qWarning("error renaming");
181 QFile::remove( strNewFile ); 185 QFile::remove( strNewFile );
182 } 186 }
183 187
184 m_changed = false; 188 m_changed = false;
185 return true; 189 return true;
186} 190}
187QArray<int> OTodoAccessXML::allRecords()const { 191QArray<int> OTodoAccessXML::allRecords()const {
188 QArray<int> ids( m_events.count() ); 192 QArray<int> ids( m_events.count() );
189 QMap<int, OTodo>::ConstIterator it; 193 QMap<int, OTodo>::ConstIterator it;
190 int i = 0; 194 int i = 0;
191 195
192 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 196 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
193 ids[i] = it.key(); 197 ids[i] = it.key();
194 i++; 198 i++;
195 } 199 }
196 return ids; 200 return ids;
197} 201}
198QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int ) { 202QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int ) {
199 QArray<int> ids(0); 203 QArray<int> ids(0);
200 return ids; 204 return ids;
201} 205}
202OTodo OTodoAccessXML::find( int uid )const { 206OTodo OTodoAccessXML::find( int uid )const {
203 OTodo todo; 207 OTodo todo;
204 todo.setUid( 0 ); // isEmpty() 208 todo.setUid( 0 ); // isEmpty()
205 QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); 209 QMap<int, OTodo>::ConstIterator it = m_events.find( uid );
206 if ( it != m_events.end() ) 210 if ( it != m_events.end() )
207 todo = it.data(); 211 todo = it.data();
208 212
209 return todo; 213 return todo;
210} 214}
211void OTodoAccessXML::clear() { 215void OTodoAccessXML::clear() {
212 if (m_opened ) 216 if (m_opened )
213 m_changed = true; 217 m_changed = true;
214 218
215 m_events.clear(); 219 m_events.clear();
216} 220}
217bool OTodoAccessXML::add( const OTodo& todo ) { 221bool OTodoAccessXML::add( const OTodo& todo ) {
218// qWarning("add"); 222// qWarning("add");
219 m_changed = true; 223 m_changed = true;
220 m_events.insert( todo.uid(), todo ); 224 m_events.insert( todo.uid(), todo );
221 225
222 return true; 226 return true;
223} 227}
224bool OTodoAccessXML::remove( int uid ) { 228bool OTodoAccessXML::remove( int uid ) {
225 m_changed = true; 229 m_changed = true;
226 m_events.remove( uid ); 230 m_events.remove( uid );
227 231
228 return true; 232 return true;
229} 233}
230bool OTodoAccessXML::replace( const OTodo& todo) { 234bool OTodoAccessXML::replace( const OTodo& todo) {
231 m_changed = true; 235 m_changed = true;
232 m_events.replace( todo.uid(), todo ); 236 m_events.replace( todo.uid(), todo );
233 237
234 return true; 238 return true;
235} 239}
236QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, 240QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start,
237 const QDate& end, 241 const QDate& end,
238 bool includeNoDates ) { 242 bool includeNoDates ) {
239 QArray<int> ids( m_events.count() ); 243 QArray<int> ids( m_events.count() );
240 QMap<int, OTodo>::Iterator it; 244 QMap<int, OTodo>::Iterator it;
241 245
242 int i = 0; 246 int i = 0;
243 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 247 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
244 if ( !it.data().hasDueDate() ) { 248 if ( !it.data().hasDueDate() ) {
245 if ( includeNoDates ) { 249 if ( includeNoDates ) {
246 ids[i] = it.key(); 250 ids[i] = it.key();
247 i++; 251 i++;
248 } 252 }
249 }else if ( it.data().dueDate() >= start && 253 }else if ( it.data().dueDate() >= start &&
250 it.data().dueDate() <= end ) { 254 it.data().dueDate() <= end ) {
251 ids[i] = it.key(); 255 ids[i] = it.key();
252 i++; 256 i++;
253 } 257 }
254 } 258 }
255 ids.resize( i ); 259 ids.resize( i );
256 return ids; 260 return ids;
257} 261}
258QArray<int> OTodoAccessXML::overDue() { 262QArray<int> OTodoAccessXML::overDue() {
259 QArray<int> ids( m_events.count() ); 263 QArray<int> ids( m_events.count() );
260 int i = 0; 264 int i = 0;
261 265
262 QMap<int, OTodo>::Iterator it; 266 QMap<int, OTodo>::Iterator it;
263 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 267 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
264 if ( it.data().isOverdue() ) { 268 if ( it.data().isOverdue() ) {
265 ids[i] = it.key(); 269 ids[i] = it.key();
266 i++; 270 i++;
267 } 271 }
268 } 272 }
269 ids.resize( i ); 273 ids.resize( i );
270 return ids; 274 return ids;
271} 275}
272 276
273 277
274/* private */ 278/* private */
275void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, 279void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev,
276 const QCString& attr, const QString& val) { 280 const QCString& attr, const QString& val) {
277// qWarning("parse to do from XMLElement" ); 281// qWarning("parse to do from XMLElement" );
278 282
279 int *find=0; 283 int *find=0;
280 284
281 find = (*dict)[ attr.data() ]; 285 find = (*dict)[ attr.data() ];
282 if (!find ) { 286 if (!find ) {
283// qWarning("Unknown option" + it.key() ); 287// qWarning("Unknown option" + it.key() );
284 ev.setCustomField( attr, val ); 288 ev.setCustomField( attr, val );
285 return; 289 return;
286 } 290 }
287 291
288 switch( *find ) { 292 switch( *find ) {
289 case OTodo::Uid: 293 case OTodo::Uid:
290 ev.setUid( val.toInt() ); 294 ev.setUid( val.toInt() );
291 break; 295 break;
292 case OTodo::Category: 296 case OTodo::Category:
293 ev.setCategories( ev.idsFromString( val ) ); 297 ev.setCategories( ev.idsFromString( val ) );
294 break; 298 break;
295 case OTodo::HasDate: 299 case OTodo::HasDate:
296 ev.setHasDueDate( val.toInt() ); 300 ev.setHasDueDate( val.toInt() );
297 break; 301 break;
298 case OTodo::Completed: 302 case OTodo::Completed:
299 ev.setCompleted( val.toInt() ); 303 ev.setCompleted( val.toInt() );
300 break; 304 break;
301 case OTodo::Description: 305 case OTodo::Description:
302 ev.setDescription( val ); 306 ev.setDescription( val );
303 break; 307 break;
304 case OTodo::Summary: 308 case OTodo::Summary:
305 ev.setSummary( val ); 309 ev.setSummary( val );
306 break; 310 break;
307 case OTodo::Priority: 311 case OTodo::Priority:
308 ev.setPriority( val.toInt() ); 312 ev.setPriority( val.toInt() );
309 break; 313 break;
310 case OTodo::DateDay: 314 case OTodo::DateDay:
311 m_day = val.toInt(); 315 m_day = val.toInt();
312 break; 316 break;
313 case OTodo::DateMonth: 317 case OTodo::DateMonth:
314 m_month = val.toInt(); 318 m_month = val.toInt();
315 break; 319 break;
316 case OTodo::DateYear: 320 case OTodo::DateYear:
317 m_year = val.toInt(); 321 m_year = val.toInt();
318 break; 322 break;
319 case OTodo::Progress: 323 case OTodo::Progress:
320 ev.setProgress( val.toInt() ); 324 ev.setProgress( val.toInt() );
321 break; 325 break;
322 case OTodo::CrossReference: 326 case OTodo::CrossReference:
323 { 327 {
324 /* 328 /*
325 * A cross refernce looks like 329 * A cross refernce looks like
326 * appname,id;appname,id 330 * appname,id;appname,id
327 * we need to split it up 331 * we need to split it up
328 */ 332 */
329 QStringList refs = QStringList::split(';', val ); 333 QStringList refs = QStringList::split(';', val );
330 QStringList::Iterator strIt; 334 QStringList::Iterator strIt;
331 for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { 335 for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) {
332 int pos = (*strIt).find(','); 336 int pos = (*strIt).find(',');
333 if ( pos > -1 ) 337 if ( pos > -1 )
334 ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); 338 ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() );
335 339
336 } 340 }
337 break; 341 break;
338 } 342 }
339 case OTodo::HasAlarmDateTime:
340 ev.setHasAlarmDateTime( val.toInt() );
341 break;
342 case OTodo::AlarmDateTime: {
343 /* this sounds better ;) zecke */
344 ev.setAlarmDateTime( TimeConversion::fromISO8601( val.local8Bit() ) );
345 break;
346 }
347 default: 343 default:
348 break; 344 break;
349 } 345 }
350} 346}
351QString OTodoAccessXML::toString( const OTodo& ev )const { 347QString OTodoAccessXML::toString( const OTodo& ev )const {
352 QString str; 348 QString str;
353 349
354 str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; 350 str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" ";
355 str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; 351 str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" ";
356 str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; 352 str += "Priority=\"" + QString::number( ev.priority() ) + "\" ";
357 str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; 353 str += "Progress=\"" + QString::number(ev.progress() ) + "\" ";
358 354
359 str += "Categories=\"" + toString( ev.categories() ) + "\" "; 355 str += "Categories=\"" + toString( ev.categories() ) + "\" ";
360 str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; 356 str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" ";
361 str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; 357 str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" ";
362 358
363 if ( ev.hasDueDate() ) { 359 if ( ev.hasDueDate() ) {
364 str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; 360 str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" ";
365 str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; 361 str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" ";
366 str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; 362 str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" ";
367 } 363 }
368// qWarning( "Uid %d", ev.uid() ); 364// qWarning( "Uid %d", ev.uid() );
369 str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; 365 str += "Uid=\"" + QString::number( ev.uid() ) + "\" ";
370 366
371// append the extra options 367// append the extra options
372 /* FIXME Qtopia::Record this is currently not 368 /* FIXME Qtopia::Record this is currently not
373 * possible you can set custom fields 369 * possible you can set custom fields
374 * but don' iterate over the list 370 * but don' iterate over the list
375 * I may do #define private protected 371 * I may do #define private protected
376 * for this case - cough --zecke 372 * for this case - cough --zecke
377 */ 373 */
378 /* 374 /*
379 QMap<QString, QString> extras = ev.extras(); 375 QMap<QString, QString> extras = ev.extras();
380 QMap<QString, QString>::Iterator extIt; 376 QMap<QString, QString>::Iterator extIt;
381 for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) 377 for (extIt = extras.begin(); extIt != extras.end(); ++extIt )
382 str += extIt.key() + "=\"" + extIt.data() + "\" "; 378 str += extIt.key() + "=\"" + extIt.data() + "\" ";
383 */ 379 */
384 // cross refernce 380 // cross refernce
385 381
386 str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" ";
387 382
388 return str; 383 return str;
389} 384}
390QString OTodoAccessXML::toString( const QArray<int>& ints ) const { 385QString OTodoAccessXML::toString( const QArray<int>& ints ) const {
391 return Qtopia::Record::idsToString( ints ); 386 return Qtopia::Record::idsToString( ints );
392} 387}
393 388
394/* internal class for sorting 389/* internal class for sorting
395 * 390 *
396 * Inspired by todoxmlio.cpp from TT 391 * Inspired by todoxmlio.cpp from TT
397 */ 392 */
398 393
399struct OTodoXMLContainer { 394struct OTodoXMLContainer {
400 OTodo todo; 395 OTodo todo;
401}; 396};
402 397
403namespace { 398namespace {
404 inline QString string( const OTodo& todo) { 399 inline QString string( const OTodo& todo) {
405 return todo.summary().isEmpty() ? 400 return todo.summary().isEmpty() ?
406 todo.description().left(20 ) : 401 todo.description().left(20 ) :
407 todo.summary(); 402 todo.summary();
408 } 403 }
409 inline int completed( const OTodo& todo1, const OTodo& todo2) { 404 inline int completed( const OTodo& todo1, const OTodo& todo2) {
410 int ret = 0; 405 int ret = 0;
411 if ( todo1.isCompleted() ) ret++; 406 if ( todo1.isCompleted() ) ret++;
412 if ( todo2.isCompleted() ) ret--; 407 if ( todo2.isCompleted() ) ret--;
413 return ret; 408 return ret;
414 } 409 }
415 inline int priority( const OTodo& t1, const OTodo& t2) { 410 inline int priority( const OTodo& t1, const OTodo& t2) {
416 return ( t1.priority() - t2.priority() ); 411 return ( t1.priority() - t2.priority() );
417 } 412 }
418 inline int description( const OTodo& t1, const OTodo& t2) { 413 inline int description( const OTodo& t1, const OTodo& t2) {
419 return QString::compare( string(t1), string(t2) ); 414 return QString::compare( string(t1), string(t2) );
420 } 415 }
421 inline int deadline( const OTodo& t1, const OTodo& t2) { 416 inline int deadline( const OTodo& t1, const OTodo& t2) {
422 int ret = 0; 417 int ret = 0;
423 if ( t1.hasDueDate() && 418 if ( t1.hasDueDate() &&
424 t2.hasDueDate() ) 419 t2.hasDueDate() )
425 ret = t2.dueDate().daysTo( t1.dueDate() ); 420 ret = t2.dueDate().daysTo( t1.dueDate() );
426 else if ( t1.hasDueDate() ) 421 else if ( t1.hasDueDate() )
427 ret = -1; 422 ret = -1;
428 else if ( t2.hasDueDate() ) 423 else if ( t2.hasDueDate() )
429 ret = 1; 424 ret = 1;
430 else 425 else
431 ret = 0; 426 ret = 0;
432 427
433 return ret; 428 return ret;
434 } 429 }
435 430
436}; 431};
437 432
438/* 433/*
439 * Returns: 434 * Returns:
440 * 0 if item1 == item2 435 * 0 if item1 == item2
441 * 436 *
442 * non-zero if item1 != item2 437 * non-zero if item1 != item2
443 * 438 *
444 * This function returns int rather than bool so that reimplementations 439 * This function returns int rather than bool so that reimplementations
445 * can return one of three values and use it to sort by: 440 * can return one of three values and use it to sort by:
446 * 441 *
447 * 0 if item1 == item2 442 * 0 if item1 == item2
448 * 443 *
449 * > 0 (positive integer) if item1 > item2 444 * > 0 (positive integer) if item1 > item2
450 * 445 *
451 * < 0 (negative integer) if item1 < item2 446 * < 0 (negative integer) if item1 < item2
452 * 447 *
453 */ 448 */
454class OTodoXMLVector : public QVector<OTodoXMLContainer> { 449class OTodoXMLVector : public QVector<OTodoXMLContainer> {
455public: 450public:
456 OTodoXMLVector(int size, bool asc, int sort) 451 OTodoXMLVector(int size, bool asc, int sort)
457 : QVector<OTodoXMLContainer>( size ) 452 : QVector<OTodoXMLContainer>( size )
458 { 453 {
459 setAutoDelete( true ); 454 setAutoDelete( true );
460 m_asc = asc; 455 m_asc = asc;
461 m_sort = sort; 456 m_sort = sort;
462 } 457 }
463 /* return the summary/description */ 458 /* return the summary/description */
464 QString string( const OTodo& todo) { 459 QString string( const OTodo& todo) {
465 return todo.summary().isEmpty() ? 460 return todo.summary().isEmpty() ?
466 todo.description().left(20 ) : 461 todo.description().left(20 ) :
467 todo.summary(); 462 todo.summary();
468 } 463 }
469 /** 464 /**
470 * we take the sortorder( switch on it ) 465 * we take the sortorder( switch on it )
471 * 466 *
472 */ 467 */
473 int compareItems( Item d1, Item d2 ) { 468 int compareItems( Item d1, Item d2 ) {
474 bool seComp, sePrio, seDesc, seDeadline; 469 bool seComp, sePrio, seDesc, seDeadline;
475 seComp = sePrio = seDeadline = seDesc = false; 470 seComp = sePrio = seDeadline = seDesc = false;
476 int ret =0; 471 int ret =0;
477 OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; 472 OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1;
478 OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; 473 OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2;
479 474
480 /* same item */ 475 /* same item */
481 if ( con1->todo.uid() == con2->todo.uid() ) 476 if ( con1->todo.uid() == con2->todo.uid() )
482 return 0; 477 return 0;
483 478
484 switch ( m_sort ) { 479 switch ( m_sort ) {
485 /* completed */ 480 /* completed */
486 case 0: { 481 case 0: {
487 ret = completed( con1->todo, con2->todo ); 482 ret = completed( con1->todo, con2->todo );
488 seComp = TRUE; 483 seComp = TRUE;
489 break; 484 break;
490 } 485 }
491 /* priority */ 486 /* priority */
492 case 1: { 487 case 1: {
493 ret = priority( con1->todo, con2->todo ); 488 ret = priority( con1->todo, con2->todo );
494 sePrio = TRUE; 489 sePrio = TRUE;
495 break; 490 break;
496 } 491 }
497 /* description */ 492 /* description */
498 case 2: { 493 case 2: {
499 ret = description( con1->todo, con2->todo ); 494 ret = description( con1->todo, con2->todo );
500 seDesc = TRUE; 495 seDesc = TRUE;
501 break; 496 break;
502 } 497 }
503 /* deadline */ 498 /* deadline */
504 case 3: { 499 case 3: {
505 ret = deadline( con1->todo, con2->todo ); 500 ret = deadline( con1->todo, con2->todo );
506 seDeadline = TRUE; 501 seDeadline = TRUE;
507 break; 502 break;
508 } 503 }
509 default: 504 default:
510 ret = 0; 505 ret = 0;
511 break; 506 break;
512 }; 507 };
513 /* 508 /*
514 * FIXME do better sorting if the first sort criteria 509 * FIXME do better sorting if the first sort criteria
515 * ret equals 0 start with complete and so on... 510 * ret equals 0 start with complete and so on...
516 */ 511 */
517 512
518 /* twist it we're not ascending*/ 513 /* twist it we're not ascending*/
519 if (!m_asc) 514 if (!m_asc)
520 ret = ret * -1; 515 ret = ret * -1;
521 516
522 if ( ret ) 517 if ( ret )
523 return ret; 518 return ret;
524 519
525 // default did not gave difference let's try it other way around 520 // default did not gave difference let's try it other way around
526 /* 521 /*
527 * General try if already checked if not test 522 * General try if already checked if not test
528 * and return 523 * and return
529 * 1.Completed 524 * 1.Completed
530 * 2.Priority 525 * 2.Priority
531 * 3.Description 526 * 3.Description
532 * 4.DueDate 527 * 4.DueDate
533 */ 528 */
534 if (!seComp ) { 529 if (!seComp ) {
535 if ( (ret = completed( con1->todo, con2->todo ) ) ) { 530 if ( (ret = completed( con1->todo, con2->todo ) ) ) {
536 if (!m_asc ) ret *= -1; 531 if (!m_asc ) ret *= -1;
537 return ret; 532 return ret;
538 } 533 }
539 } 534 }
540 if (!sePrio ) { 535 if (!sePrio ) {
541 if ( (ret = priority( con1->todo, con2->todo ) ) ) { 536 if ( (ret = priority( con1->todo, con2->todo ) ) ) {
542 if (!m_asc ) ret *= -1; 537 if (!m_asc ) ret *= -1;
543 return ret; 538 return ret;
544 } 539 }
545 } 540 }
546 if (!seDesc ) { 541 if (!seDesc ) {
547 if ( (ret = description(con1->todo, con2->todo ) ) ) { 542 if ( (ret = description(con1->todo, con2->todo ) ) ) {
548 if (!m_asc) ret *= -1; 543 if (!m_asc) ret *= -1;
549 return ret; 544 return ret;
550 } 545 }
551 } 546 }
552 if (!seDeadline) { 547 if (!seDeadline) {
553 if ( (ret = deadline( con1->todo, con2->todo ) ) ) { 548 if ( (ret = deadline( con1->todo, con2->todo ) ) ) {
554 if (!m_asc) ret *= -1; 549 if (!m_asc) ret *= -1;
555 return ret; 550 return ret;
556 } 551 }
557 } 552 }
558 553
559 return 0; 554 return 0;
560 } 555 }
561 private: 556 private:
562 bool m_asc; 557 bool m_asc;
563 int m_sort; 558 int m_sort;
564 559
565}; 560};
566 561
567QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, 562QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder,
568 int sortFilter, int cat ) { 563 int sortFilter, int cat ) {
569 qWarning("sorted! %d cat", cat); 564 qWarning("sorted! %d cat", cat);
570 OTodoXMLVector vector(m_events.count(), asc,sortOrder ); 565 OTodoXMLVector vector(m_events.count(), asc,sortOrder );
571 QMap<int, OTodo>::Iterator it; 566 QMap<int, OTodo>::Iterator it;
572 int item = 0; 567 int item = 0;
573 568
574 bool bCat = sortFilter & 1 ? true : false; 569 bool bCat = sortFilter & 1 ? true : false;
575 bool bOnly = sortFilter & 2 ? true : false; 570 bool bOnly = sortFilter & 2 ? true : false;
576 bool comp = sortFilter & 4 ? true : false; 571 bool comp = sortFilter & 4 ? true : false;
577 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 572 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
578 573
579 /* show category */ 574 /* show category */
580 if ( bCat && cat != 0) 575 if ( bCat && cat != 0)
581 if (!(*it).categories().contains( cat ) ) { 576 if (!(*it).categories().contains( cat ) ) {
582 qWarning("category mis match"); 577 qWarning("category mis match");
583 continue; 578 continue;
584 } 579 }
585 /* isOverdue but we should not show overdue - why?*/ 580 /* isOverdue but we should not show overdue - why?*/
586/* if ( (*it).isOverdue() && !bOnly ) { 581/* if ( (*it).isOverdue() && !bOnly ) {
587 qWarning("item is overdue but !bOnly"); 582 qWarning("item is overdue but !bOnly");
588 continue; 583 continue;
589 } 584 }
590*/ 585*/
591 if ( !(*it).isOverdue() && bOnly ) { 586 if ( !(*it).isOverdue() && bOnly ) {
592 qWarning("item is not overdue but bOnly checked"); 587 qWarning("item is not overdue but bOnly checked");
593 continue; 588 continue;
594 } 589 }
595 590
596 if ((*it).isCompleted() && comp ) { 591 if ((*it).isCompleted() && comp ) {
597 qWarning("completed continue!"); 592 qWarning("completed continue!");
598 continue; 593 continue;
599 } 594 }
600 595
601 596
602 OTodoXMLContainer* con = new OTodoXMLContainer(); 597 OTodoXMLContainer* con = new OTodoXMLContainer();
603 con->todo = (*it); 598 con->todo = (*it);
604 vector.insert(item, con ); 599 vector.insert(item, con );
605 item++; 600 item++;
606 } 601 }
607 qWarning("XXX %d Items added", item); 602 qWarning("XXX %d Items added", item);
608 vector.resize( item ); 603 vector.resize( item );
609 /* sort it now */ 604 /* sort it now */
610 vector.sort(); 605 vector.sort();
611 /* now get the uids */ 606 /* now get the uids */
612 QArray<int> array( vector.count() ); 607 QArray<int> array( vector.count() );
613 for (uint i= 0; i < vector.count(); i++ ) { 608 for (uint i= 0; i < vector.count(); i++ ) {
614 array[i] = ( vector.at(i) )->todo.uid(); 609 array[i] = ( vector.at(i) )->todo.uid();
615 } 610 }
616 qWarning("array count = %d %d", array.count(), vector.count() ); 611 qWarning("array count = %d %d", array.count(), vector.count() );
617 return array; 612 return array;
618}; 613};
614void OTodoAccessXML::removeAllCompleted() {
615 for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) {
616 if ( (*it).isCompleted() )
617 m_events.remove( it );
618 }
619}
diff --git a/libopie/pim/otodoaccessxml.h b/libopie/pim/otodoaccessxml.h
index dc41c32..93609fe 100644
--- a/libopie/pim/otodoaccessxml.h
+++ b/libopie/pim/otodoaccessxml.h
@@ -1,56 +1,57 @@
1#ifndef OPIE_TODO_ACCESS_XML_H 1#ifndef OPIE_TODO_ACCESS_XML_H
2#define OPIE_TODO_ACCESS_XML_H 2#define OPIE_TODO_ACCESS_XML_H
3 3
4#include <qasciidict.h> 4#include <qasciidict.h>
5#include <qmap.h> 5#include <qmap.h>
6 6
7#include "otodoaccessbackend.h" 7#include "otodoaccessbackend.h"
8 8
9namespace Opie { 9namespace Opie {
10 class XMLElement; 10 class XMLElement;
11}; 11};
12 12
13class OTodoAccessXML : public OTodoAccessBackend { 13class OTodoAccessXML : public OTodoAccessBackend {
14public: 14public:
15 /** 15 /**
16 * fileName if Empty we will use the default path 16 * fileName if Empty we will use the default path
17 */ 17 */
18 OTodoAccessXML( const QString& appName, 18 OTodoAccessXML( const QString& appName,
19 const QString& fileName = QString::null ); 19 const QString& fileName = QString::null );
20 ~OTodoAccessXML(); 20 ~OTodoAccessXML();
21 21
22 bool load(); 22 bool load();
23 bool reload(); 23 bool reload();
24 bool save(); 24 bool save();
25 25
26 QArray<int> allRecords()const; 26 QArray<int> allRecords()const;
27 QArray<int> queryByExample( const OTodo&, int querysettings ); 27 QArray<int> queryByExample( const OTodo&, int querysettings );
28 OTodo find( int uid )const; 28 OTodo find( int uid )const;
29 void clear(); 29 void clear();
30 bool add( const OTodo& ); 30 bool add( const OTodo& );
31 bool remove( int uid ); 31 bool remove( int uid );
32 void removeAllCompleted();
32 bool replace( const OTodo& ); 33 bool replace( const OTodo& );
33 34
34 /* our functions */ 35 /* our functions */
35 QArray<int> effectiveToDos( const QDate& start, 36 QArray<int> effectiveToDos( const QDate& start,
36 const QDate& end, 37 const QDate& end,
37 bool includeNoDates ); 38 bool includeNoDates );
38 QArray<int> overDue(); 39 QArray<int> overDue();
39 QArray<int> sorted( bool asc, int sortOrder, 40 QArray<int> sorted( bool asc, int sortOrder,
40 int sortFilter, int cat ); 41 int sortFilter, int cat );
41private: 42private:
42 void todo( QAsciiDict<int>*, OTodo&,const QCString&,const QString& ); 43 void todo( QAsciiDict<int>*, OTodo&,const QCString&,const QString& );
43 QString toString( const OTodo& )const; 44 QString toString( const OTodo& )const;
44 QString toString( const QArray<int>& ints ) const; 45 QString toString( const QArray<int>& ints ) const;
45 QMap<int, OTodo> m_events; 46 QMap<int, OTodo> m_events;
46 QString m_file; 47 QString m_file;
47 QString m_app; 48 QString m_app;
48 bool m_opened : 1; 49 bool m_opened : 1;
49 bool m_changed : 1; 50 bool m_changed : 1;
50 class OTodoAccessXMLPrivate; 51 class OTodoAccessXMLPrivate;
51 OTodoAccessXMLPrivate* d; 52 OTodoAccessXMLPrivate* d;
52 int m_year, m_month, m_day; 53 int m_year, m_month, m_day;
53 54
54}; 55};
55 56
56#endif 57#endif