-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp index 00d62ee..18113c2 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | |||
@@ -507,193 +507,193 @@ bool OPimContactAccessBackend_XML::remove ( int uid ) | |||
507 | } else | 507 | } else |
508 | return false; | 508 | return false; |
509 | } | 509 | } |
510 | 510 | ||
511 | bool OPimContactAccessBackend_XML::reload(){ | 511 | bool OPimContactAccessBackend_XML::reload(){ |
512 | /* Reload is the same as load in this implementation */ | 512 | /* Reload is the same as load in this implementation */ |
513 | return ( load() ); | 513 | return ( load() ); |
514 | } | 514 | } |
515 | 515 | ||
516 | void OPimContactAccessBackend_XML::addContact_p( const OPimContact &newcontact ) | 516 | void OPimContactAccessBackend_XML::addContact_p( const OPimContact &newcontact ) |
517 | { | 517 | { |
518 | OPimContact* contRef = new OPimContact( newcontact ); | 518 | OPimContact* contRef = new OPimContact( newcontact ); |
519 | 519 | ||
520 | m_contactList.append ( contRef ); | 520 | m_contactList.append ( contRef ); |
521 | m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); | 521 | m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); |
522 | } | 522 | } |
523 | 523 | ||
524 | /* This function loads the xml-database and the journalfile */ | 524 | /* This function loads the xml-database and the journalfile */ |
525 | bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal ) | 525 | bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal ) |
526 | { | 526 | { |
527 | 527 | ||
528 | /* We use the time of the last read to check if the file was | 528 | /* We use the time of the last read to check if the file was |
529 | * changed externally. | 529 | * changed externally. |
530 | */ | 530 | */ |
531 | if ( !isJournal ){ | 531 | if ( !isJournal ){ |
532 | QFileInfo fi( filename ); | 532 | QFileInfo fi( filename ); |
533 | m_readtime = fi.lastModified (); | 533 | m_readtime = fi.lastModified (); |
534 | } | 534 | } |
535 | 535 | ||
536 | const int JOURNALACTION = Qtopia::Notes + 1; | 536 | const int JOURNALACTION = Qtopia::Notes + 1; |
537 | const int JOURNALROW = JOURNALACTION + 1; | 537 | const int JOURNALROW = JOURNALACTION + 1; |
538 | 538 | ||
539 | bool foundAction = false; | 539 | bool foundAction = false; |
540 | journal_action action = ACTION_ADD; | 540 | journal_action action = ACTION_ADD; |
541 | int journalKey = 0; | 541 | int journalKey = 0; |
542 | QMap<int, QString> contactMap; | 542 | QMap<int, QString> contactMap; |
543 | QMap<QString, QString> customMap; | 543 | QMap<QString, QString> customMap; |
544 | QMap<QString, QString>::Iterator customIt; | 544 | QMap<QString, QString>::Iterator customIt; |
545 | QAsciiDict<int> dict( 47 ); | 545 | QAsciiDict<int> dict( 47 ); |
546 | 546 | ||
547 | dict.setAutoDelete( TRUE ); | 547 | dict.setAutoDelete( TRUE ); |
548 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); | 548 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); |
549 | dict.insert( "Title", new int(Qtopia::Title) ); | 549 | dict.insert( "Title", new int(Qtopia::Title) ); |
550 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); | 550 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); |
551 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); | 551 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); |
552 | dict.insert( "LastName", new int(Qtopia::LastName) ); | 552 | dict.insert( "LastName", new int(Qtopia::LastName) ); |
553 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); | 553 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); |
554 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); | 554 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); |
555 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); | 555 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); |
556 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); | 556 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); |
557 | dict.insert( "Emails", new int(Qtopia::Emails) ); | 557 | dict.insert( "Emails", new int(Qtopia::Emails) ); |
558 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); | 558 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); |
559 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); | 559 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); |
560 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); | 560 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); |
561 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); | 561 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); |
562 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); | 562 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); |
563 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); | 563 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); |
564 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); | 564 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); |
565 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); | 565 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); |
566 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); | 566 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); |
567 | dict.insert( "Company", new int(Qtopia::Company) ); | 567 | dict.insert( "Company", new int(Qtopia::Company) ); |
568 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); | 568 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); |
569 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); | 569 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); |
570 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); | 570 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); |
571 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); | 571 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); |
572 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); | 572 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); |
573 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); | 573 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); |
574 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); | 574 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); |
575 | dict.insert( "Department", new int(Qtopia::Department) ); | 575 | dict.insert( "Department", new int(Qtopia::Department) ); |
576 | dict.insert( "Office", new int(Qtopia::Office) ); | 576 | dict.insert( "Office", new int(Qtopia::Office) ); |
577 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); | 577 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); |
578 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); | 578 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); |
579 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); | 579 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); |
580 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); | 580 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); |
581 | dict.insert( "Profession", new int(Qtopia::Profession) ); | 581 | dict.insert( "Profession", new int(Qtopia::Profession) ); |
582 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); | 582 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); |
583 | dict.insert( "Manager", new int(Qtopia::Manager) ); | 583 | dict.insert( "Manager", new int(Qtopia::Manager) ); |
584 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); | 584 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); |
585 | dict.insert( "Children", new int(Qtopia::Children) ); | 585 | dict.insert( "Children", new int(Qtopia::Children) ); |
586 | dict.insert( "Gender", new int(Qtopia::Gender) ); | 586 | dict.insert( "Gender", new int(Qtopia::Gender) ); |
587 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); | 587 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); |
588 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | 588 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); |
589 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | 589 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); |
590 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 590 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
591 | dict.insert( "action", new int(JOURNALACTION) ); | 591 | dict.insert( "action", new int(JOURNALACTION) ); |
592 | dict.insert( "actionrow", new int(JOURNALROW) ); | 592 | dict.insert( "actionrow", new int(JOURNALROW) ); |
593 | 593 | ||
594 | //owarn << "OPimContactDefaultBackEnd::loading " << filename << "" << oendl; | 594 | //owarn << "OPimContactDefaultBackEnd::loading " << filename << "" << oendl; |
595 | 595 | ||
596 | XMLElement *root = XMLElement::load( filename ); | 596 | XMLElement *root = XMLElement::load( filename ); |
597 | if(root != 0l ){ // start parsing | 597 | if(root != 0l ){ // start parsing |
598 | /* Parse all XML-Elements and put the data into the | 598 | /* Parse all XML-Elements and put the data into the |
599 | * Contact-Class | 599 | * Contact-Class |
600 | */ | 600 | */ |
601 | XMLElement *element = root->firstChild(); | 601 | XMLElement *element = root->firstChild(); |
602 | //owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl; | 602 | //owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl; |
603 | element = element->firstChild(); | 603 | element = element ? element->firstChild() : 0; |
604 | 604 | ||
605 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 605 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
606 | while( element && !isJournal ){ | 606 | while( element && !isJournal ){ |
607 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 607 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
608 | //owarn << "OPimContactDefBack::Searching for Tag \"Contacts\"! Found: " | 608 | //owarn << "OPimContactDefBack::Searching for Tag \"Contacts\"! Found: " |
609 | // << element->tagName() << oendl; | 609 | // << element->tagName() << oendl; |
610 | element = element->nextChild(); | 610 | element = element->nextChild(); |
611 | } else { | 611 | } else { |
612 | element = element->firstChild(); | 612 | element = element->firstChild(); |
613 | break; | 613 | break; |
614 | } | 614 | } |
615 | } | 615 | } |
616 | /* Parse all Contacts and ignore unknown tags */ | 616 | /* Parse all Contacts and ignore unknown tags */ |
617 | while( element ){ | 617 | while( element ){ |
618 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 618 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
619 | //owarn << "OPimContactDefBack::Searching for Tag \"Contact\"! Found: " | 619 | //owarn << "OPimContactDefBack::Searching for Tag \"Contact\"! Found: " |
620 | // << element->tagName() << oendl; | 620 | // << element->tagName() << oendl; |
621 | element = element->nextChild(); | 621 | element = element->nextChild(); |
622 | continue; | 622 | continue; |
623 | } | 623 | } |
624 | /* Found alement with tagname "contact", now parse and store all | 624 | /* Found alement with tagname "contact", now parse and store all |
625 | * attributes contained | 625 | * attributes contained |
626 | */ | 626 | */ |
627 | //owarn << "OPimContactDefBack::load element tagName() : " | 627 | //owarn << "OPimContactDefBack::load element tagName() : " |
628 | // << element->tagName() << oendl; | 628 | // << element->tagName() << oendl; |
629 | QString dummy; | 629 | QString dummy; |
630 | foundAction = false; | 630 | foundAction = false; |
631 | 631 | ||
632 | XMLElement::AttributeMap aMap = element->attributes(); | 632 | XMLElement::AttributeMap aMap = element->attributes(); |
633 | XMLElement::AttributeMap::Iterator it; | 633 | XMLElement::AttributeMap::Iterator it; |
634 | contactMap.clear(); | 634 | contactMap.clear(); |
635 | customMap.clear(); | 635 | customMap.clear(); |
636 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 636 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
637 | // owarn << "Read Attribute: " << it.key() << "=" << it.data() << oendl; | 637 | // owarn << "Read Attribute: " << it.key() << "=" << it.data() << oendl; |
638 | 638 | ||
639 | int *find = dict[ it.key() ]; | 639 | int *find = dict[ it.key() ]; |
640 | /* Unknown attributes will be stored as "Custom" elements */ | 640 | /* Unknown attributes will be stored as "Custom" elements */ |
641 | if ( !find ) { | 641 | if ( !find ) { |
642 | // owarn << "Attribute " << it.key() << " not known." << oendl; | 642 | // owarn << "Attribute " << it.key() << " not known." << oendl; |
643 | //contact.setCustomField(it.key(), it.data()); | 643 | //contact.setCustomField(it.key(), it.data()); |
644 | customMap.insert( it.key(), it.data() ); | 644 | customMap.insert( it.key(), it.data() ); |
645 | continue; | 645 | continue; |
646 | } | 646 | } |
647 | 647 | ||
648 | /* Check if special conversion is needed and add attribute | 648 | /* Check if special conversion is needed and add attribute |
649 | * into Contact class | 649 | * into Contact class |
650 | */ | 650 | */ |
651 | switch( *find ) { | 651 | switch( *find ) { |
652 | /* | 652 | /* |
653 | case Qtopia::AddressUid: | 653 | case Qtopia::AddressUid: |
654 | contact.setUid( it.data().toInt() ); | 654 | contact.setUid( it.data().toInt() ); |
655 | break; | 655 | break; |
656 | case Qtopia::AddressCategory: | 656 | case Qtopia::AddressCategory: |
657 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); | 657 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); |
658 | break; | 658 | break; |
659 | */ | 659 | */ |
660 | case JOURNALACTION: | 660 | case JOURNALACTION: |
661 | action = journal_action(it.data().toInt()); | 661 | action = journal_action(it.data().toInt()); |
662 | foundAction = true; | 662 | foundAction = true; |
663 | owarn << "ODefBack(journal)::ACTION found: " << action << oendl; | 663 | owarn << "ODefBack(journal)::ACTION found: " << action << oendl; |
664 | break; | 664 | break; |
665 | case JOURNALROW: | 665 | case JOURNALROW: |
666 | journalKey = it.data().toInt(); | 666 | journalKey = it.data().toInt(); |
667 | break; | 667 | break; |
668 | default: // no conversion needed add them to the map | 668 | default: // no conversion needed add them to the map |
669 | contactMap.insert( *find, it.data() ); | 669 | contactMap.insert( *find, it.data() ); |
670 | break; | 670 | break; |
671 | } | 671 | } |
672 | } | 672 | } |
673 | /* now generate the Contact contact */ | 673 | /* now generate the Contact contact */ |
674 | OPimContact contact( contactMap ); | 674 | OPimContact contact( contactMap ); |
675 | 675 | ||
676 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 676 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
677 | contact.setCustomField( customIt.key(), customIt.data() ); | 677 | contact.setCustomField( customIt.key(), customIt.data() ); |
678 | } | 678 | } |
679 | 679 | ||
680 | if (foundAction){ | 680 | if (foundAction){ |
681 | foundAction = false; | 681 | foundAction = false; |
682 | switch ( action ) { | 682 | switch ( action ) { |
683 | case ACTION_ADD: | 683 | case ACTION_ADD: |
684 | addContact_p (contact); | 684 | addContact_p (contact); |
685 | break; | 685 | break; |
686 | case ACTION_REMOVE: | 686 | case ACTION_REMOVE: |
687 | if ( !remove (contact.uid()) ) | 687 | if ( !remove (contact.uid()) ) |
688 | owarn << "ODefBack(journal)::Unable to remove uid: " << contact.uid() << oendl; | 688 | owarn << "ODefBack(journal)::Unable to remove uid: " << contact.uid() << oendl; |
689 | break; | 689 | break; |
690 | case ACTION_REPLACE: | 690 | case ACTION_REPLACE: |
691 | if ( !replace ( contact ) ) | 691 | if ( !replace ( contact ) ) |
692 | owarn << "ODefBack(journal)::Unable to replace uid: " << contact.uid() << oendl; | 692 | owarn << "ODefBack(journal)::Unable to replace uid: " << contact.uid() << oendl; |
693 | break; | 693 | break; |
694 | default: | 694 | default: |
695 | owarn << "Unknown action: ignored !" << oendl; | 695 | owarn << "Unknown action: ignored !" << oendl; |
696 | break; | 696 | break; |
697 | } | 697 | } |
698 | }else{ | 698 | }else{ |
699 | /* Add contact to list */ | 699 | /* Add contact to list */ |