summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp160
1 files changed, 99 insertions, 61 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
index 2df6757..4abf4d9 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
@@ -19,2 +19,16 @@
19 * $Log$ 19 * $Log$
20 * Revision 1.2 2003/03/21 10:33:09 eilers
21 * Merged speed optimized xml backend for contacts to main.
22 * Added QDateTime to querybyexample. For instance, it is now possible to get
23 * all Birthdays/Anniversaries between two dates. This should be used
24 * to show all birthdays in the datebook..
25 * This change is sourcecode backward compatible but you have to upgrade
26 * the binaries for today-addressbook.
27 *
28 * Revision 1.1.2.2 2003/02/11 12:17:28 eilers
29 * Speed optimization. Removed the sequential search loops.
30 *
31 * Revision 1.1.2.1 2003/02/10 15:31:38 eilers
32 * Writing offsets to debug output..
33 *
20 * Revision 1.1 2003/02/09 15:05:01 eilers 34 * Revision 1.1 2003/02/09 15:05:01 eilers
@@ -91,2 +105,7 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString
91{ 105{
106 // Just m_contactlist should call delete if an entry
107 // is removed.
108 m_contactList.setAutoDelete( true );
109 m_uidToContact.setAutoDelete( false );
110
92 m_appName = appname; 111 m_appName = appname;
@@ -119,3 +138,6 @@ bool OContactAccessBackend_XML::save()
119 int total_written; 138 int total_written;
139 int idx_offset = 0;
120 QString out; 140 QString out;
141
142 // Write Header
121 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" 143 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
@@ -124,10 +146,17 @@ bool OContactAccessBackend_XML::save()
124 " <Contacts>\n"; 146 " <Contacts>\n";
125 //QValueList<Contact>::iterator it; 147 QCString cstr = out.utf8();
126 QValueListConstIterator<OContact> it; 148 f.writeBlock( cstr.data(), cstr.length() );
127 for ( it = m_contactList.begin(); it != m_contactList.end(); ++it ) { 149 idx_offset += cstr.length();
150 out = "";
151
152 // Write all contacts
153 QListIterator<OContact> it( m_contactList );
154 for ( ; it.current(); ++it ) {
155 qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset );
128 out += "<Contact "; 156 out += "<Contact ";
129 (*it).save( out ); 157 (*it)->save( out );
130 out += "/>\n"; 158 out += "/>\n";
131 QCString cstr = out.utf8(); 159 cstr = out.utf8();
132 total_written = f.writeBlock( cstr.data(), cstr.length() ); 160 total_written = f.writeBlock( cstr.data(), cstr.length() );
161 idx_offset += cstr.length();
133 if ( total_written != int(cstr.length()) ) { 162 if ( total_written != int(cstr.length()) ) {
@@ -141,3 +170,4 @@ bool OContactAccessBackend_XML::save()
141 170
142 QCString cstr = out.utf8(); 171 // Write Footer
172 cstr = out.utf8();
143 total_written = f.writeBlock( cstr.data(), cstr.length() ); 173 total_written = f.writeBlock( cstr.data(), cstr.length() );
@@ -169,2 +199,3 @@ bool OContactAccessBackend_XML::load ()
169 m_contactList.clear(); 199 m_contactList.clear();
200 m_uidToContact.clear();
170 201
@@ -187,4 +218,5 @@ void OContactAccessBackend_XML::clear ()
187 m_contactList.clear(); 218 m_contactList.clear();
188 m_changed = false; 219 m_uidToContact.clear();
189 220
221 m_changed = false;
190} 222}
@@ -205,5 +237,5 @@ QArray<int> OContactAccessBackend_XML::allRecords() const
205 uint counter = 0; 237 uint counter = 0;
206 QValueListConstIterator<OContact> it; 238 QListIterator<OContact> it( m_contactList );
207 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ 239 for( ; it.current(); ++it ){
208 uid_list[counter++] = (*it).uid(); 240 uid_list[counter++] = (*it)->uid();
209 } 241 }
@@ -215,14 +247,8 @@ OContact OContactAccessBackend_XML::find ( int uid ) const
215{ 247{
216 bool found = false;
217 OContact foundContact; //Create empty contact 248 OContact foundContact; //Create empty contact
218 249
219 QValueListConstIterator<OContact> it; 250 OContact* found = m_uidToContact.find( QString().setNum( uid ) );
220 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ 251
221 if ((*it).uid() == uid){
222 found = true;
223 break;
224 }
225 }
226 if ( found ){ 252 if ( found ){
227 foundContact = *it; 253 foundContact = *found;
228 } 254 }
@@ -232,3 +258,4 @@ OContact OContactAccessBackend_XML::find ( int uid ) const
232 258
233QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings ) 259QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings,
260 const QDateTime& d )
234{ 261{
@@ -236,6 +263,6 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
236 QArray<int> m_currentQuery( m_contactList.count() ); 263 QArray<int> m_currentQuery( m_contactList.count() );
237 QValueListConstIterator<OContact> it; 264 QListIterator<OContact> it( m_contactList );
238 uint arraycounter = 0; 265 uint arraycounter = 0;
239 266
240 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ 267 for( ; it.current(); ++it ){
241 /* Search all fields and compare them with query object. Store them into list 268 /* Search all fields and compare them with query object. Store them into list
@@ -252,3 +279,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
252 queryDate = new QDate( query.birthday() ); 279 queryDate = new QDate( query.birthday() );
253 checkDate = new QDate( (*it).birthday() ); 280 checkDate = new QDate( (*it)->birthday() );
254 case Qtopia::Anniversary: 281 case Qtopia::Anniversary:
@@ -256,3 +283,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
256 queryDate = new QDate( query.anniversary() ); 283 queryDate = new QDate( query.anniversary() );
257 checkDate = new QDate( (*it).anniversary() ); 284 checkDate = new QDate( (*it)->anniversary() );
258 } 285 }
@@ -274,3 +301,11 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
274 if ( settings & OContactAccess::DateDiff ) { 301 if ( settings & OContactAccess::DateDiff ) {
275 QDate current = QDate::currentDate(); 302 QDate current;
303 // If we get an additional date, we
304 // will take this date instead of
305 // the current one..
306 if ( !d.date().isValid() )
307 current = QDate::currentDate();
308 else
309 current = d.date();
310
276 // We have to equalize the year, otherwise 311 // We have to equalize the year, otherwise
@@ -284,2 +319,6 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
284 checkDate->day() ); 319 checkDate->day() );
320
321 // Check whether the birthday/anniversary date is between
322 // the current/given date and the maximum date
323 // ( maximum time range ) !
285 qWarning("Checking if %s is between %s and %s ! ", 324 qWarning("Checking if %s is between %s and %s ! ",
@@ -297,3 +336,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
297 } else{ 336 } else{
298 // checkDate is invalid. Therfore this entry is always rejected 337 // checkDate is invalid. Therefore this entry is always rejected
299 allcorrect = false; 338 allcorrect = false;
@@ -322,3 +361,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
322 false ); 361 false );
323 if ( expr.find ( (*it).field(i), 0 ) == -1 ) 362 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
324 allcorrect = false; 363 allcorrect = false;
@@ -330,3 +369,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
330 true ); 369 true );
331 if ( expr.find ( (*it).field(i), 0 ) == -1 ) 370 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
332 allcorrect = false; 371 allcorrect = false;
@@ -337,6 +376,6 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
337 if ( query.field(i).upper() != 376 if ( query.field(i).upper() !=
338 (*it).field(i).upper() ) 377 (*it)->field(i).upper() )
339 allcorrect = false; 378 allcorrect = false;
340 }else{ 379 }else{
341 if ( query.field(i) != (*it).field(i) ) 380 if ( query.field(i) != (*it)->field(i) )
342 allcorrect = false; 381 allcorrect = false;
@@ -350,3 +389,3 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i
350 if ( allcorrect ){ 389 if ( allcorrect ){
351 m_currentQuery[arraycounter++] = (*it).uid(); 390 m_currentQuery[arraycounter++] = (*it)->uid();
352 } 391 }
@@ -363,8 +402,8 @@ QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
363 QArray<int> m_currentQuery( m_contactList.count() ); 402 QArray<int> m_currentQuery( m_contactList.count() );
364 QValueListConstIterator<OContact> it; 403 QListIterator<OContact> it( m_contactList );
365 uint arraycounter = 0; 404 uint arraycounter = 0;
366 405
367 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ 406 for( ; it.current(); ++it ){
368 if ( (*it).match( r ) ){ 407 if ( (*it)->match( r ) ){
369 m_currentQuery[arraycounter++] = (*it).uid(); 408 m_currentQuery[arraycounter++] = (*it)->uid();
370 } 409 }
@@ -428,6 +467,6 @@ QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int )
428 // Afterwards sort namelist and use map to fill array to return.. 467 // Afterwards sort namelist and use map to fill array to return..
429 QValueListConstIterator<OContact> it; 468 QListIterator<OContact> it( m_contactList );
430 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ 469 for( ; it.current(); ++it ){
431 names.append( (*it).fileAs() + QString::number( (*it).uid() ) ); 470 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) );
432 nameToUid.insert( (*it).fileAs() + QString::number( (*it).uid() ), (*it).uid() ); 471 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() );
433 } 472 }
@@ -463,15 +502,15 @@ bool OContactAccessBackend_XML::replace ( const OContact &contact )
463 502
464 bool found = false; 503 OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) );
465 504
466 QValueListIterator<OContact> it;
467 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
468 if ( (*it).uid() == contact.uid() ){
469 found = true;
470 break;
471 }
472 }
473 if (found) { 505 if (found) {
474 updateJournal (contact, ACTION_REPLACE); 506 OContact* newCont = new OContact( contact );
475 m_contactList.remove (it); 507
476 m_contactList.append (contact); 508 updateJournal ( *newCont, ACTION_REPLACE);
509 m_contactList.removeRef ( found );
510 m_contactList.append ( newCont );
511 m_uidToContact.remove( QString().setNum( contact.uid() ) );
512 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont );
513
514 qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid());
515
477 return true; 516 return true;
@@ -485,13 +524,9 @@ bool OContactAccessBackend_XML::remove ( int uid )
485 524
486 bool found = false; 525 OContact* found = m_uidToContact.find ( QString().setNum( uid ) );
487 QValueListIterator<OContact> it; 526
488 for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){
489 if ((*it).uid() == uid){
490 found = true;
491 break;
492 }
493 }
494 if (found) { 527 if (found) {
495 updateJournal ( *it, ACTION_REMOVE); 528 updateJournal ( *found, ACTION_REMOVE);
496 m_contactList.remove (it); 529 m_contactList.removeRef ( found );
530 m_uidToContact.remove( QString().setNum( uid ) );
531
497 return true; 532 return true;
@@ -508,3 +543,6 @@ void OContactAccessBackend_XML::addContact_p( const OContact &newcontact )
508{ 543{
509 m_contactList.append (newcontact); 544 OContact* contRef = new OContact( newcontact );
545
546 m_contactList.append ( contRef );
547 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef );
510} 548}