Diffstat (limited to 'libopie/pim/ocontactaccessbackend_xml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/ocontactaccessbackend_xml.cpp | 166 |
1 files changed, 102 insertions, 64 deletions
diff --git a/libopie/pim/ocontactaccessbackend_xml.cpp b/libopie/pim/ocontactaccessbackend_xml.cpp index 2df6757..4abf4d9 100644 --- a/libopie/pim/ocontactaccessbackend_xml.cpp +++ b/libopie/pim/ocontactaccessbackend_xml.cpp | |||
@@ -14,12 +14,26 @@ | |||
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
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 |
21 | * Nothing happened.. Just some cleanup before I will start.. | 35 | * Nothing happened.. Just some cleanup before I will start.. |
22 | * | 36 | * |
23 | * Revision 1.12 2003/01/03 16:58:03 eilers | 37 | * Revision 1.12 2003/01/03 16:58:03 eilers |
24 | * Reenable debug output | 38 | * Reenable debug output |
25 | * | 39 | * |
@@ -86,12 +100,17 @@ | |||
86 | using namespace Opie; | 100 | using namespace Opie; |
87 | 101 | ||
88 | 102 | ||
89 | OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString filename = 0l ): | 103 | OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString filename = 0l ): |
90 | m_changed( false ) | 104 | m_changed( false ) |
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; |
93 | 112 | ||
94 | /* Set journalfile name ... */ | 113 | /* Set journalfile name ... */ |
95 | m_journalName = getenv("HOME"); | 114 | m_journalName = getenv("HOME"); |
96 | m_journalName +="/.abjournal" + appname; | 115 | m_journalName +="/.abjournal" + appname; |
97 | 116 | ||
@@ -114,35 +133,46 @@ bool OContactAccessBackend_XML::save() | |||
114 | QString strNewFile = m_fileName + ".new"; | 133 | QString strNewFile = m_fileName + ".new"; |
115 | QFile f( strNewFile ); | 134 | QFile f( strNewFile ); |
116 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 135 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
117 | return false; | 136 | return false; |
118 | 137 | ||
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" |
122 | " <Groups>\n" | 144 | " <Groups>\n" |
123 | " </Groups>\n" | 145 | " </Groups>\n" |
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()) ) { |
134 | f.close(); | 163 | f.close(); |
135 | QFile::remove( strNewFile ); | 164 | QFile::remove( strNewFile ); |
136 | return false; | 165 | return false; |
137 | } | 166 | } |
138 | out = ""; | 167 | out = ""; |
139 | } | 168 | } |
140 | out += " </Contacts>\n</AddressBook>\n"; | 169 | out += " </Contacts>\n</AddressBook>\n"; |
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() ); |
144 | if ( total_written != int( cstr.length() ) ) { | 174 | if ( total_written != int( cstr.length() ) ) { |
145 | f.close(); | 175 | f.close(); |
146 | QFile::remove( strNewFile ); | 176 | QFile::remove( strNewFile ); |
147 | return false; | 177 | return false; |
148 | } | 178 | } |
@@ -164,12 +194,13 @@ bool OContactAccessBackend_XML::save() | |||
164 | return true; | 194 | return true; |
165 | } | 195 | } |
166 | 196 | ||
167 | bool OContactAccessBackend_XML::load () | 197 | bool OContactAccessBackend_XML::load () |
168 | { | 198 | { |
169 | m_contactList.clear(); | 199 | m_contactList.clear(); |
200 | m_uidToContact.clear(); | ||
170 | 201 | ||
171 | /* Load XML-File and journal if it exists */ | 202 | /* Load XML-File and journal if it exists */ |
172 | if ( !load ( m_fileName, false ) ) | 203 | if ( !load ( m_fileName, false ) ) |
173 | return false; | 204 | return false; |
174 | /* The returncode of the journalfile is ignored due to the | 205 | /* The returncode of the journalfile is ignored due to the |
175 | * fact that it does not exist when this class is instantiated ! | 206 | * fact that it does not exist when this class is instantiated ! |
@@ -182,14 +213,15 @@ bool OContactAccessBackend_XML::load () | |||
182 | return true; | 213 | return true; |
183 | } | 214 | } |
184 | 215 | ||
185 | void OContactAccessBackend_XML::clear () | 216 | void OContactAccessBackend_XML::clear () |
186 | { | 217 | { |
187 | m_contactList.clear(); | 218 | m_contactList.clear(); |
219 | m_uidToContact.clear(); | ||
220 | |||
188 | m_changed = false; | 221 | m_changed = false; |
189 | |||
190 | } | 222 | } |
191 | 223 | ||
192 | bool OContactAccessBackend_XML::wasChangedExternally() | 224 | bool OContactAccessBackend_XML::wasChangedExternally() |
193 | { | 225 | { |
194 | QFileInfo fi( m_fileName ); | 226 | QFileInfo fi( m_fileName ); |
195 | 227 | ||
@@ -200,64 +232,59 @@ bool OContactAccessBackend_XML::wasChangedExternally() | |||
200 | 232 | ||
201 | QArray<int> OContactAccessBackend_XML::allRecords() const | 233 | QArray<int> OContactAccessBackend_XML::allRecords() const |
202 | { | 234 | { |
203 | QArray<int> uid_list( m_contactList.count() ); | 235 | QArray<int> uid_list( m_contactList.count() ); |
204 | 236 | ||
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 | } |
210 | 242 | ||
211 | return ( uid_list ); | 243 | return ( uid_list ); |
212 | } | 244 | } |
213 | 245 | ||
214 | OContact OContactAccessBackend_XML::find ( int uid ) const | 246 | 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 | } |
229 | 255 | ||
230 | return ( foundContact ); | 256 | return ( foundContact ); |
231 | } | 257 | } |
232 | 258 | ||
233 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings ) | 259 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, |
260 | const QDateTime& d ) | ||
234 | { | 261 | { |
235 | 262 | ||
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 |
242 | * if all fields matches. | 269 | * if all fields matches. |
243 | */ | 270 | */ |
244 | QDate* queryDate = 0l; | 271 | QDate* queryDate = 0l; |
245 | QDate* checkDate = 0l; | 272 | QDate* checkDate = 0l; |
246 | bool allcorrect = true; | 273 | bool allcorrect = true; |
247 | for ( int i = 0; i < Qtopia::Groups; i++ ) { | 274 | for ( int i = 0; i < Qtopia::Groups; i++ ) { |
248 | // Birthday and anniversary are special nonstring fields and should | 275 | // Birthday and anniversary are special nonstring fields and should |
249 | // be handled specially | 276 | // be handled specially |
250 | switch ( i ){ | 277 | switch ( i ){ |
251 | case Qtopia::Birthday: | 278 | case Qtopia::Birthday: |
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: |
255 | if ( queryDate == 0l ){ | 282 | if ( queryDate == 0l ){ |
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 | } |
259 | 286 | ||
260 | if ( queryDate->isValid() ){ | 287 | if ( queryDate->isValid() ){ |
261 | if( checkDate->isValid() ){ | 288 | if( checkDate->isValid() ){ |
262 | if ( settings & OContactAccess::DateYear ){ | 289 | if ( settings & OContactAccess::DateYear ){ |
263 | if ( queryDate->year() != checkDate->year() ) | 290 | if ( queryDate->year() != checkDate->year() ) |
@@ -269,22 +296,34 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
269 | } | 296 | } |
270 | if ( settings & OContactAccess::DateDay ){ | 297 | if ( settings & OContactAccess::DateDay ){ |
271 | if ( queryDate->day() != checkDate->day() ) | 298 | if ( queryDate->day() != checkDate->day() ) |
272 | allcorrect = false; | 299 | allcorrect = false; |
273 | } | 300 | } |
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 |
277 | // the search will fail.. | 312 | // the search will fail.. |
278 | checkDate->setYMD( current.year(), | 313 | checkDate->setYMD( current.year(), |
279 | checkDate->month(), | 314 | checkDate->month(), |
280 | checkDate->day() ); | 315 | checkDate->day() ); |
281 | if ( *checkDate < current ) | 316 | if ( *checkDate < current ) |
282 | checkDate->setYMD( current.year()+1, | 317 | checkDate->setYMD( current.year()+1, |
283 | checkDate->month(), | 318 | checkDate->month(), |
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 ! ", |
286 | checkDate->toString().latin1(), | 325 | checkDate->toString().latin1(), |
287 | current.toString().latin1(), | 326 | current.toString().latin1(), |
288 | queryDate->toString().latin1() ); | 327 | queryDate->toString().latin1() ); |
289 | if ( current.daysTo( *queryDate ) > 0 ){ | 328 | if ( current.daysTo( *queryDate ) > 0 ){ |
290 | if ( !( ( *checkDate >= current ) && | 329 | if ( !( ( *checkDate >= current ) && |
@@ -292,13 +331,13 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
292 | allcorrect = false; | 331 | allcorrect = false; |
293 | qWarning (" Nope!.."); | 332 | qWarning (" Nope!.."); |
294 | } | 333 | } |
295 | } | 334 | } |
296 | } | 335 | } |
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; |
300 | } | 339 | } |
301 | } | 340 | } |
302 | 341 | ||
303 | delete queryDate; | 342 | delete queryDate; |
304 | queryDate = 0l; | 343 | queryDate = 0l; |
@@ -317,59 +356,59 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
317 | ) ){ | 356 | ) ){ |
318 | 357 | ||
319 | case OContactAccess::RegExp:{ | 358 | case OContactAccess::RegExp:{ |
320 | QRegExp expr ( query.field(i), | 359 | QRegExp expr ( query.field(i), |
321 | !(settings & OContactAccess::IgnoreCase), | 360 | !(settings & OContactAccess::IgnoreCase), |
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; |
325 | } | 364 | } |
326 | break; | 365 | break; |
327 | case OContactAccess::WildCards:{ | 366 | case OContactAccess::WildCards:{ |
328 | QRegExp expr ( query.field(i), | 367 | QRegExp expr ( query.field(i), |
329 | !(settings & OContactAccess::IgnoreCase), | 368 | !(settings & OContactAccess::IgnoreCase), |
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; |
333 | } | 372 | } |
334 | break; | 373 | break; |
335 | case OContactAccess::ExactMatch:{ | 374 | case OContactAccess::ExactMatch:{ |
336 | if (settings & OContactAccess::IgnoreCase){ | 375 | if (settings & OContactAccess::IgnoreCase){ |
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; |
343 | } | 382 | } |
344 | } | 383 | } |
345 | break; | 384 | break; |
346 | } | 385 | } |
347 | } | 386 | } |
348 | } | 387 | } |
349 | } | 388 | } |
350 | if ( allcorrect ){ | 389 | if ( allcorrect ){ |
351 | m_currentQuery[arraycounter++] = (*it).uid(); | 390 | m_currentQuery[arraycounter++] = (*it)->uid(); |
352 | } | 391 | } |
353 | } | 392 | } |
354 | 393 | ||
355 | // Shrink to fit.. | 394 | // Shrink to fit.. |
356 | m_currentQuery.resize(arraycounter); | 395 | m_currentQuery.resize(arraycounter); |
357 | 396 | ||
358 | return m_currentQuery; | 397 | return m_currentQuery; |
359 | } | 398 | } |
360 | 399 | ||
361 | QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const | 400 | QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const |
362 | { | 401 | { |
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 | } |
371 | 410 | ||
372 | } | 411 | } |
373 | // Shrink to fit.. | 412 | // Shrink to fit.. |
374 | m_currentQuery.resize(arraycounter); | 413 | m_currentQuery.resize(arraycounter); |
375 | 414 | ||
@@ -423,16 +462,16 @@ QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | |||
423 | QMap<QString, int> nameToUid; | 462 | QMap<QString, int> nameToUid; |
424 | QStringList names; | 463 | QStringList names; |
425 | QArray<int> m_currentQuery( m_contactList.count() ); | 464 | QArray<int> m_currentQuery( m_contactList.count() ); |
426 | 465 | ||
427 | // First fill map and StringList with all Names | 466 | // First fill map and StringList with all Names |
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 | } |
434 | names.sort(); | 473 | names.sort(); |
435 | 474 | ||
436 | int i = 0; | 475 | int i = 0; |
437 | if ( asc ){ | 476 | if ( asc ){ |
438 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) | 477 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) |
@@ -458,58 +497,57 @@ bool OContactAccessBackend_XML::add ( const OContact &newcontact ) | |||
458 | } | 497 | } |
459 | 498 | ||
460 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) | 499 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) |
461 | { | 500 | { |
462 | m_changed = true; | 501 | m_changed = true; |
463 | 502 | ||
464 | bool found = false; | 503 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); |
465 | 504 | ||
466 | QValueListIterator<OContact> it; | 505 | if ( found ) { |
467 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 506 | OContact* newCont = new OContact( contact ); |
468 | if ( (*it).uid() == contact.uid() ){ | 507 | |
469 | found = true; | 508 | updateJournal ( *newCont, ACTION_REPLACE); |
470 | break; | 509 | m_contactList.removeRef ( found ); |
471 | } | 510 | m_contactList.append ( newCont ); |
472 | } | 511 | m_uidToContact.remove( QString().setNum( contact.uid() ) ); |
473 | if (found) { | 512 | m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); |
474 | updateJournal (contact, ACTION_REPLACE); | 513 | |
475 | m_contactList.remove (it); | 514 | qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); |
476 | m_contactList.append (contact); | 515 | |
477 | return true; | 516 | return true; |
478 | } else | 517 | } else |
479 | return false; | 518 | return false; |
480 | } | 519 | } |
481 | 520 | ||
482 | bool OContactAccessBackend_XML::remove ( int uid ) | 521 | bool OContactAccessBackend_XML::remove ( int uid ) |
483 | { | 522 | { |
484 | m_changed = true; | 523 | m_changed = true; |
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 ){ | 527 | if ( found ) { |
489 | if ((*it).uid() == uid){ | 528 | updateJournal ( *found, ACTION_REMOVE); |
490 | found = true; | 529 | m_contactList.removeRef ( found ); |
491 | break; | 530 | m_uidToContact.remove( QString().setNum( uid ) ); |
492 | } | 531 | |
493 | } | ||
494 | if (found) { | ||
495 | updateJournal ( *it, ACTION_REMOVE); | ||
496 | m_contactList.remove (it); | ||
497 | return true; | 532 | return true; |
498 | } else | 533 | } else |
499 | return false; | 534 | return false; |
500 | } | 535 | } |
501 | 536 | ||
502 | bool OContactAccessBackend_XML::reload(){ | 537 | bool OContactAccessBackend_XML::reload(){ |
503 | /* Reload is the same as load in this implementation */ | 538 | /* Reload is the same as load in this implementation */ |
504 | return ( load() ); | 539 | return ( load() ); |
505 | } | 540 | } |
506 | 541 | ||
507 | void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) | 542 | 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 | } |
511 | 549 | ||
512 | /* This function loads the xml-database and the journalfile */ | 550 | /* This function loads the xml-database and the journalfile */ |
513 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | 551 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) |
514 | { | 552 | { |
515 | 553 | ||