Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp index 5ffcb11..00d62ee 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | |||
@@ -128,26 +128,26 @@ bool OPimContactAccessBackend_XML::save() | |||
128 | cstr = out.utf8(); | 128 | cstr = out.utf8(); |
129 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 129 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
130 | if ( total_written != int( cstr.length() ) ) { | 130 | if ( total_written != int( cstr.length() ) ) { |
131 | f.close(); | 131 | f.close(); |
132 | QFile::remove( strNewFile ); | 132 | QFile::remove( strNewFile ); |
133 | return false; | 133 | return false; |
134 | } | 134 | } |
135 | f.close(); | 135 | f.close(); |
136 | 136 | ||
137 | // move the file over, I'm just going to use the system call | 137 | // move the file over, I'm just going to use the system call |
138 | // because, I don't feel like using QDir. | 138 | // because, I don't feel like using QDir. |
139 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { | 139 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { |
140 | qWarning( "problem renaming file %s to %s, errno: %d", | 140 | owarn << "problem renaming file " << strNewFile << " to " << m_journalName |
141 | strNewFile.latin1(), m_journalName.latin1(), errno ); | 141 | << ", errno: " << errno << oendl; |
142 | // remove the tmp file... | 142 | // remove the tmp file... |
143 | QFile::remove( strNewFile ); | 143 | QFile::remove( strNewFile ); |
144 | } | 144 | } |
145 | 145 | ||
146 | /* The journalfile should be removed now... */ | 146 | /* The journalfile should be removed now... */ |
147 | removeJournal(); | 147 | removeJournal(); |
148 | 148 | ||
149 | m_changed = false; | 149 | m_changed = false; |
150 | return true; | 150 | return true; |
151 | } | 151 | } |
152 | 152 | ||
153 | bool OPimContactAccessBackend_XML::load () | 153 | bool OPimContactAccessBackend_XML::load () |
@@ -269,33 +269,31 @@ QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &qu | |||
269 | // the search will fail.. | 269 | // the search will fail.. |
270 | checkDate->setYMD( current.year(), | 270 | checkDate->setYMD( current.year(), |
271 | checkDate->month(), | 271 | checkDate->month(), |
272 | checkDate->day() ); | 272 | checkDate->day() ); |
273 | if ( *checkDate < current ) | 273 | if ( *checkDate < current ) |
274 | checkDate->setYMD( current.year()+1, | 274 | checkDate->setYMD( current.year()+1, |
275 | checkDate->month(), | 275 | checkDate->month(), |
276 | checkDate->day() ); | 276 | checkDate->day() ); |
277 | 277 | ||
278 | // Check whether the birthday/anniversary date is between | 278 | // Check whether the birthday/anniversary date is between |
279 | // the current/given date and the maximum date | 279 | // the current/given date and the maximum date |
280 | // ( maximum time range ) ! | 280 | // ( maximum time range ) ! |
281 | qWarning("Checking if %s is between %s and %s ! ", | 281 | owarn << "Checking if " << checkDate->toString() << " is between " << current.toString() |
282 | checkDate->toString().latin1(), | 282 | << " and " << queryDate->toString() << " ! " << oendl; |
283 | current.toString().latin1(), | ||
284 | queryDate->toString().latin1() ); | ||
285 | if ( current.daysTo( *queryDate ) >= 0 ){ | 283 | if ( current.daysTo( *queryDate ) >= 0 ){ |
286 | if ( !( ( *checkDate >= current ) && | 284 | if ( !( ( *checkDate >= current ) && |
287 | ( *checkDate <= *queryDate ) ) ){ | 285 | ( *checkDate <= *queryDate ) ) ){ |
288 | allcorrect = false; | 286 | allcorrect = false; |
289 | qWarning (" Nope!.."); | 287 | owarn << " Nope!.." << oendl; |
290 | } | 288 | } |
291 | } | 289 | } |
292 | } | 290 | } |
293 | } else{ | 291 | } else{ |
294 | // checkDate is invalid. Therefore this entry is always rejected | 292 | // checkDate is invalid. Therefore this entry is always rejected |
295 | allcorrect = false; | 293 | allcorrect = false; |
296 | } | 294 | } |
297 | } | 295 | } |
298 | 296 | ||
299 | delete queryDate; | 297 | delete queryDate; |
300 | queryDate = 0l; | 298 | queryDate = 0l; |
301 | delete checkDate; | 299 | delete checkDate; |
@@ -598,54 +596,54 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal | |||
598 | XMLElement *root = XMLElement::load( filename ); | 596 | XMLElement *root = XMLElement::load( filename ); |
599 | if(root != 0l ){ // start parsing | 597 | if(root != 0l ){ // start parsing |
600 | /* Parse all XML-Elements and put the data into the | 598 | /* Parse all XML-Elements and put the data into the |
601 | * Contact-Class | 599 | * Contact-Class |
602 | */ | 600 | */ |
603 | XMLElement *element = root->firstChild(); | 601 | XMLElement *element = root->firstChild(); |
604 | //owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl; | 602 | //owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl; |
605 | element = element->firstChild(); | 603 | element = element->firstChild(); |
606 | 604 | ||
607 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 605 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
608 | while( element && !isJournal ){ | 606 | while( element && !isJournal ){ |
609 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 607 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
610 | //qWarning ("OPimContactDefBack::Searching for Tag \"Contacts\"! Found: %s", | 608 | //owarn << "OPimContactDefBack::Searching for Tag \"Contacts\"! Found: " |
611 | // element->tagName().latin1()); | 609 | // << element->tagName() << oendl; |
612 | element = element->nextChild(); | 610 | element = element->nextChild(); |
613 | } else { | 611 | } else { |
614 | element = element->firstChild(); | 612 | element = element->firstChild(); |
615 | break; | 613 | break; |
616 | } | 614 | } |
617 | } | 615 | } |
618 | /* Parse all Contacts and ignore unknown tags */ | 616 | /* Parse all Contacts and ignore unknown tags */ |
619 | while( element ){ | 617 | while( element ){ |
620 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 618 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
621 | //qWarning ("OPimContactDefBack::Searching for Tag \"Contact\"! Found: %s", | 619 | //owarn << "OPimContactDefBack::Searching for Tag \"Contact\"! Found: " |
622 | // element->tagName().latin1()); | 620 | // << element->tagName() << oendl; |
623 | element = element->nextChild(); | 621 | element = element->nextChild(); |
624 | continue; | 622 | continue; |
625 | } | 623 | } |
626 | /* Found alement with tagname "contact", now parse and store all | 624 | /* Found alement with tagname "contact", now parse and store all |
627 | * attributes contained | 625 | * attributes contained |
628 | */ | 626 | */ |
629 | //qWarning("OPimContactDefBack::load element tagName() : %s", | 627 | //owarn << "OPimContactDefBack::load element tagName() : " |
630 | // element->tagName().latin1() ); | 628 | // << element->tagName() << oendl; |
631 | QString dummy; | 629 | QString dummy; |
632 | foundAction = false; | 630 | foundAction = false; |
633 | 631 | ||
634 | XMLElement::AttributeMap aMap = element->attributes(); | 632 | XMLElement::AttributeMap aMap = element->attributes(); |
635 | XMLElement::AttributeMap::Iterator it; | 633 | XMLElement::AttributeMap::Iterator it; |
636 | contactMap.clear(); | 634 | contactMap.clear(); |
637 | customMap.clear(); | 635 | customMap.clear(); |
638 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 636 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
639 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 637 | // owarn << "Read Attribute: " << it.key() << "=" << it.data() << oendl; |
640 | 638 | ||
641 | int *find = dict[ it.key() ]; | 639 | int *find = dict[ it.key() ]; |
642 | /* Unknown attributes will be stored as "Custom" elements */ | 640 | /* Unknown attributes will be stored as "Custom" elements */ |
643 | if ( !find ) { | 641 | if ( !find ) { |
644 | // owarn << "Attribute " << it.key() << " not known." << oendl; | 642 | // owarn << "Attribute " << it.key() << " not known." << oendl; |
645 | //contact.setCustomField(it.key(), it.data()); | 643 | //contact.setCustomField(it.key(), it.data()); |
646 | customMap.insert( it.key(), it.data() ); | 644 | customMap.insert( it.key(), it.data() ); |
647 | continue; | 645 | continue; |
648 | } | 646 | } |
649 | 647 | ||
650 | /* Check if special conversion is needed and add attribute | 648 | /* Check if special conversion is needed and add attribute |
651 | * into Contact class | 649 | * into Contact class |
@@ -653,59 +651,57 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal | |||
653 | switch( *find ) { | 651 | switch( *find ) { |
654 | /* | 652 | /* |
655 | case Qtopia::AddressUid: | 653 | case Qtopia::AddressUid: |
656 | contact.setUid( it.data().toInt() ); | 654 | contact.setUid( it.data().toInt() ); |
657 | break; | 655 | break; |
658 | case Qtopia::AddressCategory: | 656 | case Qtopia::AddressCategory: |
659 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); | 657 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); |
660 | break; | 658 | break; |
661 | */ | 659 | */ |
662 | case JOURNALACTION: | 660 | case JOURNALACTION: |
663 | action = journal_action(it.data().toInt()); | 661 | action = journal_action(it.data().toInt()); |
664 | foundAction = true; | 662 | foundAction = true; |
665 | qWarning ("ODefBack(journal)::ACTION found: %d", action); | 663 | owarn << "ODefBack(journal)::ACTION found: " << action << oendl; |
666 | break; | 664 | break; |
667 | case JOURNALROW: | 665 | case JOURNALROW: |
668 | journalKey = it.data().toInt(); | 666 | journalKey = it.data().toInt(); |
669 | break; | 667 | break; |
670 | default: // no conversion needed add them to the map | 668 | default: // no conversion needed add them to the map |
671 | contactMap.insert( *find, it.data() ); | 669 | contactMap.insert( *find, it.data() ); |
672 | break; | 670 | break; |
673 | } | 671 | } |
674 | } | 672 | } |
675 | /* now generate the Contact contact */ | 673 | /* now generate the Contact contact */ |
676 | OPimContact contact( contactMap ); | 674 | OPimContact contact( contactMap ); |
677 | 675 | ||
678 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 676 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
679 | contact.setCustomField( customIt.key(), customIt.data() ); | 677 | contact.setCustomField( customIt.key(), customIt.data() ); |
680 | } | 678 | } |
681 | 679 | ||
682 | if (foundAction){ | 680 | if (foundAction){ |
683 | foundAction = false; | 681 | foundAction = false; |
684 | switch ( action ) { | 682 | switch ( action ) { |
685 | case ACTION_ADD: | 683 | case ACTION_ADD: |
686 | addContact_p (contact); | 684 | addContact_p (contact); |
687 | break; | 685 | break; |
688 | case ACTION_REMOVE: | 686 | case ACTION_REMOVE: |
689 | if ( !remove (contact.uid()) ) | 687 | if ( !remove (contact.uid()) ) |
690 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", | 688 | owarn << "ODefBack(journal)::Unable to remove uid: " << contact.uid() << oendl; |
691 | contact.uid() ); | ||
692 | break; | 689 | break; |
693 | case ACTION_REPLACE: | 690 | case ACTION_REPLACE: |
694 | if ( !replace ( contact ) ) | 691 | if ( !replace ( contact ) ) |
695 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", | 692 | owarn << "ODefBack(journal)::Unable to replace uid: " << contact.uid() << oendl; |
696 | contact.uid() ); | ||
697 | break; | 693 | break; |
698 | default: | 694 | default: |
699 | qWarning ("Unknown action: ignored !"); | 695 | owarn << "Unknown action: ignored !" << oendl; |
700 | break; | 696 | break; |
701 | } | 697 | } |
702 | }else{ | 698 | }else{ |
703 | /* Add contact to list */ | 699 | /* Add contact to list */ |
704 | addContact_p (contact); | 700 | addContact_p (contact); |
705 | } | 701 | } |
706 | 702 | ||
707 | /* Move to next element */ | 703 | /* Move to next element */ |
708 | element = element->nextChild(); | 704 | element = element->nextChild(); |
709 | } | 705 | } |
710 | }else { | 706 | }else { |
711 | owarn << "ODefBack::could not load" << oendl; | 707 | owarn << "ODefBack::could not load" << oendl; |