-rw-r--r-- | kabc/addressbook.cpp | 133 |
1 files changed, 97 insertions, 36 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 16e1653..ec9f893 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -213,48 +213,49 @@ bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | |||
213 | { | 213 | { |
214 | return ( d->mIt != it.d->mIt ); | 214 | return ( d->mIt != it.d->mIt ); |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | AddressBook::AddressBook() | 218 | AddressBook::AddressBook() |
219 | { | 219 | { |
220 | init(0, "contact"); | 220 | init(0, "contact"); |
221 | } | 221 | } |
222 | 222 | ||
223 | AddressBook::AddressBook( const QString &config ) | 223 | AddressBook::AddressBook( const QString &config ) |
224 | { | 224 | { |
225 | init(config, "contact"); | 225 | init(config, "contact"); |
226 | } | 226 | } |
227 | 227 | ||
228 | AddressBook::AddressBook( const QString &config, const QString &family ) | 228 | AddressBook::AddressBook( const QString &config, const QString &family ) |
229 | { | 229 | { |
230 | init(config, family); | 230 | init(config, family); |
231 | 231 | ||
232 | } | 232 | } |
233 | 233 | ||
234 | // the default family is "contact" | 234 | // the default family is "contact" |
235 | void AddressBook::init(const QString &config, const QString &family ) | 235 | void AddressBook::init(const QString &config, const QString &family ) |
236 | { | 236 | { |
237 | blockLSEchange = false; | ||
237 | d = new AddressBookData; | 238 | d = new AddressBookData; |
238 | QString fami = family; | 239 | QString fami = family; |
239 | qDebug("new ab "); | 240 | qDebug("new ab "); |
240 | if (config != 0) { | 241 | if (config != 0) { |
241 | qDebug("config != 0 "); | 242 | qDebug("config != 0 "); |
242 | if ( family == "syncContact" ) { | 243 | if ( family == "syncContact" ) { |
243 | qDebug("creating sync config "); | 244 | qDebug("creating sync config "); |
244 | fami = "contact"; | 245 | fami = "contact"; |
245 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 246 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
246 | con->setGroup( "General" ); | 247 | con->setGroup( "General" ); |
247 | con->writeEntry( "ResourceKeys", QString("sync") ); | 248 | con->writeEntry( "ResourceKeys", QString("sync") ); |
248 | con->writeEntry( "Standard", QString("sync") ); | 249 | con->writeEntry( "Standard", QString("sync") ); |
249 | con->setGroup( "Resource_sync" ); | 250 | con->setGroup( "Resource_sync" ); |
250 | con->writeEntry( "FileFormat", QString("vcard") ); | 251 | con->writeEntry( "FileFormat", QString("vcard") ); |
251 | con->writeEntry( "FileName", config ); | 252 | con->writeEntry( "FileName", config ); |
252 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 253 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
253 | con->writeEntry( "ResourceName", QString("sync_res") ); | 254 | con->writeEntry( "ResourceName", QString("sync_res") ); |
254 | con->writeEntry( "ResourceType", QString("file") ); | 255 | con->writeEntry( "ResourceType", QString("file") ); |
255 | //con->sync(); | 256 | //con->sync(); |
256 | d->mConfig = con; | 257 | d->mConfig = con; |
257 | } | 258 | } |
258 | else | 259 | else |
259 | d->mConfig = new KConfig( locateLocal("config", config) ); | 260 | d->mConfig = new KConfig( locateLocal("config", config) ); |
260 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 261 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
@@ -324,48 +325,49 @@ AddressBook::~AddressBook() | |||
324 | delete d->mManager; d->mManager = 0; | 325 | delete d->mManager; d->mManager = 0; |
325 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 326 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
326 | delete d; d = 0; | 327 | delete d; d = 0; |
327 | } | 328 | } |
328 | 329 | ||
329 | bool AddressBook::load() | 330 | bool AddressBook::load() |
330 | { | 331 | { |
331 | 332 | ||
332 | 333 | ||
333 | clear(); | 334 | clear(); |
334 | 335 | ||
335 | KRES::Manager<Resource>::ActiveIterator it; | 336 | KRES::Manager<Resource>::ActiveIterator it; |
336 | bool ok = true; | 337 | bool ok = true; |
337 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 338 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
338 | if ( !(*it)->load() ) { | 339 | if ( !(*it)->load() ) { |
339 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 340 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
340 | ok = false; | 341 | ok = false; |
341 | } | 342 | } |
342 | 343 | ||
343 | // mark all addressees as unchanged | 344 | // mark all addressees as unchanged |
344 | Addressee::List::Iterator addrIt; | 345 | Addressee::List::Iterator addrIt; |
345 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) | 346 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) |
346 | (*addrIt).setChanged( false ); | 347 | (*addrIt).setChanged( false ); |
347 | 348 | ||
349 | blockLSEchange = true; | ||
348 | return ok; | 350 | return ok; |
349 | } | 351 | } |
350 | 352 | ||
351 | bool AddressBook::save( Ticket *ticket ) | 353 | bool AddressBook::save( Ticket *ticket ) |
352 | { | 354 | { |
353 | kdDebug(5700) << "AddressBook::save()"<< endl; | 355 | kdDebug(5700) << "AddressBook::save()"<< endl; |
354 | 356 | ||
355 | if ( ticket->resource() ) { | 357 | if ( ticket->resource() ) { |
356 | deleteRemovedAddressees(); | 358 | deleteRemovedAddressees(); |
357 | return ticket->resource()->save( ticket ); | 359 | return ticket->resource()->save( ticket ); |
358 | } | 360 | } |
359 | 361 | ||
360 | return false; | 362 | return false; |
361 | } | 363 | } |
362 | bool AddressBook::saveAB() | 364 | bool AddressBook::saveAB() |
363 | { | 365 | { |
364 | bool ok = true; | 366 | bool ok = true; |
365 | 367 | ||
366 | deleteRemovedAddressees(); | 368 | deleteRemovedAddressees(); |
367 | 369 | ||
368 | KRES::Manager<Resource>::ActiveIterator it; | 370 | KRES::Manager<Resource>::ActiveIterator it; |
369 | KRES::Manager<Resource> *manager = d->mManager; | 371 | KRES::Manager<Resource> *manager = d->mManager; |
370 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 372 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
371 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 373 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
@@ -426,138 +428,197 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) | |||
426 | { | 428 | { |
427 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 429 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
428 | 430 | ||
429 | if ( !resource ) | 431 | if ( !resource ) |
430 | { | 432 | { |
431 | qDebug("AddressBook::requestSaveTicket no resource" ); | 433 | qDebug("AddressBook::requestSaveTicket no resource" ); |
432 | resource = standardResource(); | 434 | resource = standardResource(); |
433 | } | 435 | } |
434 | 436 | ||
435 | KRES::Manager<Resource>::ActiveIterator it; | 437 | KRES::Manager<Resource>::ActiveIterator it; |
436 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 438 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
437 | if ( (*it) == resource ) { | 439 | if ( (*it) == resource ) { |
438 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 440 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
439 | return 0; | 441 | return 0; |
440 | else | 442 | else |
441 | return (*it)->requestSaveTicket(); | 443 | return (*it)->requestSaveTicket(); |
442 | } | 444 | } |
443 | } | 445 | } |
444 | 446 | ||
445 | return 0; | 447 | return 0; |
446 | } | 448 | } |
447 | 449 | ||
448 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) | 450 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) |
449 | { | 451 | { |
450 | Addressee::List::Iterator it; | 452 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
451 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 453 | return; |
452 | if ( a.uid() == (*it).uid() ) { | 454 | } |
453 | if ( setRev && (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 455 | bool found = false; |
454 | return; | 456 | Addressee::List::Iterator it; |
455 | } | 457 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
456 | bool changed = false; | 458 | if ( a.uid() == (*it).uid() ) { |
457 | Addressee addr = a; | 459 | |
458 | if ( addr != (*it) ) | 460 | bool changed = false; |
459 | changed = true; | 461 | Addressee addr = a; |
460 | 462 | if ( addr != (*it) ) | |
461 | (*it) = a; | 463 | changed = true; |
462 | if ( (*it).resource() == 0 ) | 464 | |
463 | (*it).setResource( standardResource() ); | 465 | (*it) = a; |
464 | 466 | if ( (*it).resource() == 0 ) | |
465 | if ( changed ) { | 467 | (*it).setResource( standardResource() ); |
466 | if ( setRev ) { | 468 | |
469 | if ( changed ) { | ||
470 | if ( setRev ) { | ||
467 | 471 | ||
468 | // get rid of micro seconds | 472 | // get rid of micro seconds |
469 | QDateTime dt = QDateTime::currentDateTime(); | 473 | QDateTime dt = QDateTime::currentDateTime(); |
470 | QTime t = dt.time(); | 474 | QTime t = dt.time(); |
471 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 475 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
472 | (*it).setRevision( dt ); | 476 | (*it).setRevision( dt ); |
473 | } | 477 | } |
474 | (*it).setChanged( true ); | 478 | (*it).setChanged( true ); |
475 | } | 479 | } |
476 | 480 | ||
477 | return; | 481 | found = true; |
482 | } else { | ||
483 | if ( (*it).uid() == QString("last-syncAddressee-") ) { | ||
484 | QString name = (*it).uid().mid( 19 ); | ||
485 | Addressee b = a; | ||
486 | QString id = b.getID( name ); | ||
487 | if ( ! id.isEmpty() ) { | ||
488 | QString des = (*it).note(); | ||
489 | int startN; | ||
490 | if( (startN = des.find( id ) ) >= 0 ) { | ||
491 | int endN = des.find( ",", startN+1 ); | ||
492 | des = des.left( startN ) + des.mid( endN+1 ); | ||
493 | (*it).setNote( des ); | ||
494 | } | ||
495 | } | ||
496 | } | ||
497 | } | ||
478 | } | 498 | } |
479 | } | 499 | if ( found ) |
480 | d->mAddressees.append( a ); | 500 | return; |
481 | Addressee& addr = d->mAddressees.last(); | 501 | d->mAddressees.append( a ); |
482 | if ( addr.resource() == 0 ) | 502 | Addressee& addr = d->mAddressees.last(); |
483 | addr.setResource( standardResource() ); | 503 | if ( addr.resource() == 0 ) |
504 | addr.setResource( standardResource() ); | ||
484 | 505 | ||
485 | addr.setChanged( true ); | 506 | addr.setChanged( true ); |
486 | } | 507 | } |
487 | 508 | ||
488 | void AddressBook::removeAddressee( const Addressee &a ) | 509 | void AddressBook::removeAddressee( const Addressee &a ) |
489 | { | 510 | { |
490 | Iterator it; | 511 | Iterator it; |
512 | Iterator it2; | ||
513 | bool found = false; | ||
491 | for ( it = begin(); it != end(); ++it ) { | 514 | for ( it = begin(); it != end(); ++it ) { |
492 | if ( a.uid() == (*it).uid() ) { | 515 | if ( a.uid() == (*it).uid() ) { |
493 | removeAddressee( it ); | 516 | found = true; |
494 | return; | 517 | it2 = it; |
518 | } else { | ||
519 | if ( (*it).uid() == QString("last-syncAddressee-") ) { | ||
520 | QString name = (*it).uid().mid( 19 ); | ||
521 | Addressee b = a; | ||
522 | QString id = b.getID( name ); | ||
523 | if ( ! id.isEmpty() ) { | ||
524 | QString des = (*it).note(); | ||
525 | if( des.find( id ) < 0 ) { | ||
526 | des += id + ","; | ||
527 | (*it).setNote( des ); | ||
528 | } | ||
529 | } | ||
530 | } | ||
531 | |||
495 | } | 532 | } |
496 | } | 533 | } |
534 | |||
535 | if ( found ) | ||
536 | removeAddressee( it2 ); | ||
537 | |||
538 | } | ||
539 | |||
540 | void AddressBook::removeDeletedAddressees() | ||
541 | { | ||
542 | deleteRemovedAddressees(); | ||
543 | Iterator it = begin(); | ||
544 | Iterator it2 ; | ||
545 | QDateTime dt ( QDate( 2004,1,1) ); | ||
546 | while ( it != end() ) { | ||
547 | (*it).setRevision( dt ); | ||
548 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | ||
549 | it2 = it; | ||
550 | ++it; | ||
551 | removeAddressee( it2 ); | ||
552 | } else | ||
553 | ++it; | ||
554 | } | ||
555 | deleteRemovedAddressees(); | ||
497 | } | 556 | } |
498 | 557 | ||
499 | void AddressBook::removeAddressee( const Iterator &it ) | 558 | void AddressBook::removeAddressee( const Iterator &it ) |
500 | { | 559 | { |
501 | d->mRemovedAddressees.append( (*it) ); | 560 | d->mRemovedAddressees.append( (*it) ); |
502 | d->mAddressees.remove( it.d->mIt ); | 561 | d->mAddressees.remove( it.d->mIt ); |
503 | } | 562 | } |
504 | 563 | ||
505 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 564 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
506 | { | 565 | { |
507 | Iterator it; | 566 | Iterator it; |
508 | for ( it = begin(); it != end(); ++it ) { | 567 | for ( it = begin(); it != end(); ++it ) { |
509 | if ( a.uid() == (*it).uid() ) { | 568 | if ( a.uid() == (*it).uid() ) { |
510 | return it; | 569 | return it; |
511 | } | 570 | } |
512 | } | 571 | } |
513 | return end(); | 572 | return end(); |
514 | } | 573 | } |
515 | 574 | ||
516 | Addressee AddressBook::findByUid( const QString &uid ) | 575 | Addressee AddressBook::findByUid( const QString &uid ) |
517 | { | 576 | { |
518 | Iterator it; | 577 | Iterator it; |
519 | for ( it = begin(); it != end(); ++it ) { | 578 | for ( it = begin(); it != end(); ++it ) { |
520 | if ( uid == (*it).uid() ) { | 579 | if ( uid == (*it).uid() ) { |
521 | return *it; | 580 | return *it; |
522 | } | 581 | } |
523 | } | 582 | } |
524 | return Addressee(); | 583 | return Addressee(); |
525 | } | 584 | } |
585 | #if 0 | ||
526 | Addressee::List AddressBook::getExternLastSyncAddressees() | 586 | Addressee::List AddressBook::getExternLastSyncAddressees() |
527 | { | 587 | { |
528 | Addressee::List results; | 588 | Addressee::List results; |
529 | 589 | ||
530 | Iterator it; | 590 | Iterator it; |
531 | for ( it = begin(); it != end(); ++it ) { | 591 | for ( it = begin(); it != end(); ++it ) { |
532 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 592 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
533 | if ( (*it).familyName().left(3) == "E: " ) | 593 | if ( (*it).familyName().left(4) == "!E: " ) |
534 | results.append( *it ); | 594 | results.append( *it ); |
535 | } | 595 | } |
536 | } | 596 | } |
537 | 597 | ||
538 | return results; | 598 | return results; |
539 | } | 599 | } |
600 | #endif | ||
540 | void AddressBook::resetTempSyncStat() | 601 | void AddressBook::resetTempSyncStat() |
541 | { | 602 | { |
542 | Iterator it; | 603 | Iterator it; |
543 | for ( it = begin(); it != end(); ++it ) { | 604 | for ( it = begin(); it != end(); ++it ) { |
544 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 605 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
545 | } | 606 | } |
546 | 607 | ||
547 | } | 608 | } |
548 | 609 | ||
549 | QStringList AddressBook:: uidList() | 610 | QStringList AddressBook:: uidList() |
550 | { | 611 | { |
551 | QStringList results; | 612 | QStringList results; |
552 | Iterator it; | 613 | Iterator it; |
553 | for ( it = begin(); it != end(); ++it ) { | 614 | for ( it = begin(); it != end(); ++it ) { |
554 | results.append( (*it).uid() ); | 615 | results.append( (*it).uid() ); |
555 | } | 616 | } |
556 | return results; | 617 | return results; |
557 | } | 618 | } |
558 | 619 | ||
559 | 620 | ||
560 | Addressee::List AddressBook::allAddressees() | 621 | Addressee::List AddressBook::allAddressees() |
561 | { | 622 | { |
562 | return d->mAddressees; | 623 | return d->mAddressees; |
563 | 624 | ||