Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp index 18113c2..5df7253 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | |||
@@ -105,13 +105,12 @@ bool OPimContactAccessBackend_XML::save() | |||
105 | idx_offset += cstr.length(); | 105 | idx_offset += cstr.length(); |
106 | out = ""; | 106 | out = ""; |
107 | 107 | ||
108 | // Write all contacts | 108 | // Write all contacts |
109 | QListIterator<OPimContact> it( m_contactList ); | 109 | QListIterator<OPimContact> it( m_contactList ); |
110 | for ( ; it.current(); ++it ) { | 110 | for ( ; it.current(); ++it ) { |
111 | // owarn << " Uid " << (*it)->uid() << " at Offset: " << idx_offset << "" << oendl; | ||
112 | out += "<Contact "; | 111 | out += "<Contact "; |
113 | (*it)->save( out ); | 112 | (*it)->save( out ); |
114 | out += "/>\n"; | 113 | out += "/>\n"; |
115 | cstr = out.utf8(); | 114 | cstr = out.utf8(); |
116 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 115 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
117 | idx_offset += cstr.length(); | 116 | idx_offset += cstr.length(); |
@@ -134,14 +133,12 @@ bool OPimContactAccessBackend_XML::save() | |||
134 | } | 133 | } |
135 | f.close(); | 134 | f.close(); |
136 | 135 | ||
137 | // move the file over, I'm just going to use the system call | 136 | // move the file over, I'm just going to use the system call |
138 | // because, I don't feel like using QDir. | 137 | // because, I don't feel like using QDir. |
139 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { | 138 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { |
140 | owarn << "problem renaming file " << strNewFile << " to " << m_journalName | ||
141 | << ", errno: " << errno << oendl; | ||
142 | // remove the tmp file... | 139 | // remove the tmp file... |
143 | QFile::remove( strNewFile ); | 140 | QFile::remove( strNewFile ); |
144 | } | 141 | } |
145 | 142 | ||
146 | /* The journalfile should be removed now... */ | 143 | /* The journalfile should be removed now... */ |
147 | removeJournal(); | 144 | removeJournal(); |
@@ -210,15 +207,14 @@ OPimContact OPimContactAccessBackend_XML::find ( int uid ) const | |||
210 | } | 207 | } |
211 | 208 | ||
212 | return ( foundContact ); | 209 | return ( foundContact ); |
213 | } | 210 | } |
214 | 211 | ||
215 | QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings, | 212 | QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings, |
216 | const QDateTime& d ) | 213 | const QDateTime& d )const |
217 | { | 214 | { |
218 | |||
219 | QArray<int> m_currentQuery( m_contactList.count() ); | 215 | QArray<int> m_currentQuery( m_contactList.count() ); |
220 | QListIterator<OPimContact> it( m_contactList ); | 216 | QListIterator<OPimContact> it( m_contactList ); |
221 | uint arraycounter = 0; | 217 | uint arraycounter = 0; |
222 | 218 | ||
223 | for( ; it.current(); ++it ){ | 219 | for( ; it.current(); ++it ){ |
224 | /* Search all fields and compare them with query object. Store them into list | 220 | /* Search all fields and compare them with query object. Store them into list |
@@ -275,19 +271,16 @@ QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &qu | |||
275 | checkDate->month(), | 271 | checkDate->month(), |
276 | checkDate->day() ); | 272 | checkDate->day() ); |
277 | 273 | ||
278 | // Check whether the birthday/anniversary date is between | 274 | // Check whether the birthday/anniversary date is between |
279 | // the current/given date and the maximum date | 275 | // the current/given date and the maximum date |
280 | // ( maximum time range ) ! | 276 | // ( maximum time range ) ! |
281 | owarn << "Checking if " << checkDate->toString() << " is between " << current.toString() | ||
282 | << " and " << queryDate->toString() << " ! " << oendl; | ||
283 | if ( current.daysTo( *queryDate ) >= 0 ){ | 277 | if ( current.daysTo( *queryDate ) >= 0 ){ |
284 | if ( !( ( *checkDate >= current ) && | 278 | if ( !( ( *checkDate >= current ) && |
285 | ( *checkDate <= *queryDate ) ) ){ | 279 | ( *checkDate <= *queryDate ) ) ){ |
286 | allcorrect = false; | 280 | allcorrect = false; |
287 | owarn << " Nope!.." << oendl; | ||
288 | } | 281 | } |
289 | } | 282 | } |
290 | } | 283 | } |
291 | } else{ | 284 | } else{ |
292 | // checkDate is invalid. Therefore this entry is always rejected | 285 | // checkDate is invalid. Therefore this entry is always rejected |
293 | allcorrect = false; | 286 | allcorrect = false; |
@@ -427,12 +420,13 @@ bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | |||
427 | return ( true ); | 420 | return ( true ); |
428 | default: | 421 | default: |
429 | return ( false ); | 422 | return ( false ); |
430 | } | 423 | } |
431 | } | 424 | } |
432 | 425 | ||
426 | #if 0 | ||
433 | // Currently only asc implemented.. | 427 | // Currently only asc implemented.. |
434 | QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int ) | 428 | QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int ) |
435 | { | 429 | { |
436 | QMap<QString, int> nameToUid; | 430 | QMap<QString, int> nameToUid; |
437 | QStringList names; | 431 | QStringList names; |
438 | QArray<int> m_currentQuery( m_contactList.count() ); | 432 | QArray<int> m_currentQuery( m_contactList.count() ); |
@@ -455,16 +449,17 @@ QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int ) | |||
455 | m_currentQuery[i++] = nameToUid[ (*it) ]; | 449 | m_currentQuery[i++] = nameToUid[ (*it) ]; |
456 | } | 450 | } |
457 | 451 | ||
458 | return m_currentQuery; | 452 | return m_currentQuery; |
459 | 453 | ||
460 | } | 454 | } |
455 | #endif | ||
456 | |||
461 | 457 | ||
462 | bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact ) | 458 | bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact ) |
463 | { | 459 | { |
464 | //owarn << "odefaultbackend: ACTION::ADD" << oendl; | ||
465 | updateJournal (newcontact, ACTION_ADD); | 460 | updateJournal (newcontact, ACTION_ADD); |
466 | addContact_p( newcontact ); | 461 | addContact_p( newcontact ); |
467 | 462 | ||
468 | m_changed = true; | 463 | m_changed = true; |
469 | 464 | ||
470 | return true; | 465 | return true; |
@@ -482,14 +477,12 @@ bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact ) | |||
482 | updateJournal ( *newCont, ACTION_REPLACE); | 477 | updateJournal ( *newCont, ACTION_REPLACE); |
483 | m_contactList.removeRef ( found ); | 478 | m_contactList.removeRef ( found ); |
484 | m_contactList.append ( newCont ); | 479 | m_contactList.append ( newCont ); |
485 | m_uidToContact.remove( QString().setNum( contact.uid() ) ); | 480 | m_uidToContact.remove( QString().setNum( contact.uid() ) ); |
486 | m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); | 481 | m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); |
487 | 482 | ||
488 | owarn << "Nur zur Sicherheit: " << contact.uid() << " == " << newCont->uid() << " ?" << oendl; | ||
489 | |||
490 | return true; | 483 | return true; |
491 | } else | 484 | } else |
492 | return false; | 485 | return false; |
493 | } | 486 | } |
494 | 487 | ||
495 | bool OPimContactAccessBackend_XML::remove ( int uid ) | 488 | bool OPimContactAccessBackend_XML::remove ( int uid ) |
@@ -588,61 +581,49 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal | |||
588 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | 581 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); |
589 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | 582 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); |
590 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 583 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
591 | dict.insert( "action", new int(JOURNALACTION) ); | 584 | dict.insert( "action", new int(JOURNALACTION) ); |
592 | dict.insert( "actionrow", new int(JOURNALROW) ); | 585 | dict.insert( "actionrow", new int(JOURNALROW) ); |
593 | 586 | ||
594 | //owarn << "OPimContactDefaultBackEnd::loading " << filename << "" << oendl; | ||
595 | |||
596 | XMLElement *root = XMLElement::load( filename ); | 587 | XMLElement *root = XMLElement::load( filename ); |
597 | if(root != 0l ){ // start parsing | 588 | if(root != 0l ){ // start parsing |
598 | /* Parse all XML-Elements and put the data into the | 589 | /* Parse all XML-Elements and put the data into the |
599 | * Contact-Class | 590 | * Contact-Class |
600 | */ | 591 | */ |
601 | XMLElement *element = root->firstChild(); | 592 | XMLElement *element = root->firstChild(); |
602 | //owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl; | ||
603 | element = element ? element->firstChild() : 0; | 593 | element = element ? element->firstChild() : 0; |
604 | 594 | ||
605 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 595 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
606 | while( element && !isJournal ){ | 596 | while( element && !isJournal ){ |
607 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 597 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
608 | //owarn << "OPimContactDefBack::Searching for Tag \"Contacts\"! Found: " | ||
609 | // << element->tagName() << oendl; | ||
610 | element = element->nextChild(); | 598 | element = element->nextChild(); |
611 | } else { | 599 | } else { |
612 | element = element->firstChild(); | 600 | element = element->firstChild(); |
613 | break; | 601 | break; |
614 | } | 602 | } |
615 | } | 603 | } |
616 | /* Parse all Contacts and ignore unknown tags */ | 604 | /* Parse all Contacts and ignore unknown tags */ |
617 | while( element ){ | 605 | while( element ){ |
618 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 606 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
619 | //owarn << "OPimContactDefBack::Searching for Tag \"Contact\"! Found: " | ||
620 | // << element->tagName() << oendl; | ||
621 | element = element->nextChild(); | 607 | element = element->nextChild(); |
622 | continue; | 608 | continue; |
623 | } | 609 | } |
624 | /* Found alement with tagname "contact", now parse and store all | 610 | /* Found alement with tagname "contact", now parse and store all |
625 | * attributes contained | 611 | * attributes contained |
626 | */ | 612 | */ |
627 | //owarn << "OPimContactDefBack::load element tagName() : " | ||
628 | // << element->tagName() << oendl; | ||
629 | QString dummy; | 613 | QString dummy; |
630 | foundAction = false; | 614 | foundAction = false; |
631 | 615 | ||
632 | XMLElement::AttributeMap aMap = element->attributes(); | 616 | XMLElement::AttributeMap aMap = element->attributes(); |
633 | XMLElement::AttributeMap::Iterator it; | 617 | XMLElement::AttributeMap::Iterator it; |
634 | contactMap.clear(); | 618 | contactMap.clear(); |
635 | customMap.clear(); | 619 | customMap.clear(); |
636 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 620 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
637 | // owarn << "Read Attribute: " << it.key() << "=" << it.data() << oendl; | ||
638 | |||
639 | int *find = dict[ it.key() ]; | 621 | int *find = dict[ it.key() ]; |
640 | /* Unknown attributes will be stored as "Custom" elements */ | 622 | /* Unknown attributes will be stored as "Custom" elements */ |
641 | if ( !find ) { | 623 | if ( !find ) { |
642 | // owarn << "Attribute " << it.key() << " not known." << oendl; | ||
643 | //contact.setCustomField(it.key(), it.data()); | 624 | //contact.setCustomField(it.key(), it.data()); |
644 | customMap.insert( it.key(), it.data() ); | 625 | customMap.insert( it.key(), it.data() ); |
645 | continue; | 626 | continue; |
646 | } | 627 | } |
647 | 628 | ||
648 | /* Check if special conversion is needed and add attribute | 629 | /* Check if special conversion is needed and add attribute |
@@ -701,16 +682,14 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal | |||
701 | } | 682 | } |
702 | 683 | ||
703 | /* Move to next element */ | 684 | /* Move to next element */ |
704 | element = element->nextChild(); | 685 | element = element->nextChild(); |
705 | } | 686 | } |
706 | }else { | 687 | }else { |
707 | owarn << "ODefBack::could not load" << oendl; | ||
708 | } | 688 | } |
709 | delete root; | 689 | delete root; |
710 | owarn << "returning from loading" << oendl; | ||
711 | return true; | 690 | return true; |
712 | } | 691 | } |
713 | 692 | ||
714 | 693 | ||
715 | void OPimContactAccessBackend_XML::updateJournal( const OPimContact& cnt, | 694 | void OPimContactAccessBackend_XML::updateJournal( const OPimContact& cnt, |
716 | journal_action action ) | 695 | journal_action action ) |