-rw-r--r-- | kabc/addressbook.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 6e8d027..3ec0795 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -352,208 +352,209 @@ bool AddressBook::save( Ticket *ticket ) | |||
352 | { | 352 | { |
353 | kdDebug(5700) << "AddressBook::save()"<< endl; | 353 | kdDebug(5700) << "AddressBook::save()"<< endl; |
354 | 354 | ||
355 | if ( ticket->resource() ) { | 355 | if ( ticket->resource() ) { |
356 | deleteRemovedAddressees(); | 356 | deleteRemovedAddressees(); |
357 | return ticket->resource()->save( ticket ); | 357 | return ticket->resource()->save( ticket ); |
358 | } | 358 | } |
359 | 359 | ||
360 | return false; | 360 | return false; |
361 | } | 361 | } |
362 | bool AddressBook::saveAB() | 362 | bool AddressBook::saveAB() |
363 | { | 363 | { |
364 | bool ok = true; | 364 | bool ok = true; |
365 | 365 | ||
366 | deleteRemovedAddressees(); | 366 | deleteRemovedAddressees(); |
367 | 367 | ||
368 | KRES::Manager<Resource>::ActiveIterator it; | 368 | KRES::Manager<Resource>::ActiveIterator it; |
369 | KRES::Manager<Resource> *manager = d->mManager; | 369 | KRES::Manager<Resource> *manager = d->mManager; |
370 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 370 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
371 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 371 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
372 | Ticket *ticket = requestSaveTicket( *it ); | 372 | Ticket *ticket = requestSaveTicket( *it ); |
373 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 373 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
374 | if ( !ticket ) { | 374 | if ( !ticket ) { |
375 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 375 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
376 | .arg( (*it)->resourceName() ) ); | 376 | .arg( (*it)->resourceName() ) ); |
377 | return false; | 377 | return false; |
378 | } | 378 | } |
379 | 379 | ||
380 | //if ( !save( ticket ) ) | 380 | //if ( !save( ticket ) ) |
381 | if ( ticket->resource() ) { | 381 | if ( ticket->resource() ) { |
382 | if ( ! ticket->resource()->save( ticket ) ) | 382 | if ( ! ticket->resource()->save( ticket ) ) |
383 | ok = false; | 383 | ok = false; |
384 | } else | 384 | } else |
385 | ok = false; | 385 | ok = false; |
386 | 386 | ||
387 | } | 387 | } |
388 | } | 388 | } |
389 | return ok; | 389 | return ok; |
390 | } | 390 | } |
391 | 391 | ||
392 | AddressBook::Iterator AddressBook::begin() | 392 | AddressBook::Iterator AddressBook::begin() |
393 | { | 393 | { |
394 | Iterator it = Iterator(); | 394 | Iterator it = Iterator(); |
395 | it.d->mIt = d->mAddressees.begin(); | 395 | it.d->mIt = d->mAddressees.begin(); |
396 | return it; | 396 | return it; |
397 | } | 397 | } |
398 | 398 | ||
399 | AddressBook::ConstIterator AddressBook::begin() const | 399 | AddressBook::ConstIterator AddressBook::begin() const |
400 | { | 400 | { |
401 | ConstIterator it = ConstIterator(); | 401 | ConstIterator it = ConstIterator(); |
402 | it.d->mIt = d->mAddressees.begin(); | 402 | it.d->mIt = d->mAddressees.begin(); |
403 | return it; | 403 | return it; |
404 | } | 404 | } |
405 | 405 | ||
406 | AddressBook::Iterator AddressBook::end() | 406 | AddressBook::Iterator AddressBook::end() |
407 | { | 407 | { |
408 | Iterator it = Iterator(); | 408 | Iterator it = Iterator(); |
409 | it.d->mIt = d->mAddressees.end(); | 409 | it.d->mIt = d->mAddressees.end(); |
410 | return it; | 410 | return it; |
411 | } | 411 | } |
412 | 412 | ||
413 | AddressBook::ConstIterator AddressBook::end() const | 413 | AddressBook::ConstIterator AddressBook::end() const |
414 | { | 414 | { |
415 | ConstIterator it = ConstIterator(); | 415 | ConstIterator it = ConstIterator(); |
416 | it.d->mIt = d->mAddressees.end(); | 416 | it.d->mIt = d->mAddressees.end(); |
417 | return it; | 417 | return it; |
418 | } | 418 | } |
419 | 419 | ||
420 | void AddressBook::clear() | 420 | void AddressBook::clear() |
421 | { | 421 | { |
422 | d->mAddressees.clear(); | 422 | d->mAddressees.clear(); |
423 | } | 423 | } |
424 | 424 | ||
425 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 425 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
426 | { | 426 | { |
427 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 427 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
428 | 428 | ||
429 | if ( !resource ) | 429 | if ( !resource ) |
430 | { | 430 | { |
431 | qDebug("AddressBook::requestSaveTicket no resource" ); | 431 | qDebug("AddressBook::requestSaveTicket no resource" ); |
432 | resource = standardResource(); | 432 | resource = standardResource(); |
433 | } | 433 | } |
434 | 434 | ||
435 | KRES::Manager<Resource>::ActiveIterator it; | 435 | KRES::Manager<Resource>::ActiveIterator it; |
436 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 436 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
437 | if ( (*it) == resource ) { | 437 | if ( (*it) == resource ) { |
438 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 438 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
439 | return 0; | 439 | return 0; |
440 | else | 440 | else |
441 | return (*it)->requestSaveTicket(); | 441 | return (*it)->requestSaveTicket(); |
442 | } | 442 | } |
443 | } | 443 | } |
444 | 444 | ||
445 | return 0; | 445 | return 0; |
446 | } | 446 | } |
447 | 447 | ||
448 | void AddressBook::insertAddressee( const Addressee &a ) | 448 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) |
449 | { | 449 | { |
450 | Addressee::List::Iterator it; | 450 | Addressee::List::Iterator it; |
451 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 451 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
452 | if ( a.uid() == (*it).uid() ) { | 452 | if ( a.uid() == (*it).uid() ) { |
453 | bool changed = false; | 453 | bool changed = false; |
454 | Addressee addr = a; | 454 | Addressee addr = a; |
455 | if ( addr != (*it) ) | 455 | if ( addr != (*it) ) |
456 | changed = true; | 456 | changed = true; |
457 | 457 | ||
458 | (*it) = a; | 458 | (*it) = a; |
459 | if ( (*it).resource() == 0 ) | 459 | if ( (*it).resource() == 0 ) |
460 | (*it).setResource( standardResource() ); | 460 | (*it).setResource( standardResource() ); |
461 | 461 | ||
462 | if ( changed ) { | 462 | if ( changed ) { |
463 | (*it).setRevision( QDateTime::currentDateTime() ); | 463 | if ( setRev ) |
464 | (*it).setRevision( QDateTime::currentDateTime() ); | ||
464 | (*it).setChanged( true ); | 465 | (*it).setChanged( true ); |
465 | } | 466 | } |
466 | 467 | ||
467 | return; | 468 | return; |
468 | } | 469 | } |
469 | } | 470 | } |
470 | d->mAddressees.append( a ); | 471 | d->mAddressees.append( a ); |
471 | Addressee& addr = d->mAddressees.last(); | 472 | Addressee& addr = d->mAddressees.last(); |
472 | if ( addr.resource() == 0 ) | 473 | if ( addr.resource() == 0 ) |
473 | addr.setResource( standardResource() ); | 474 | addr.setResource( standardResource() ); |
474 | 475 | ||
475 | addr.setChanged( true ); | 476 | addr.setChanged( true ); |
476 | } | 477 | } |
477 | 478 | ||
478 | void AddressBook::removeAddressee( const Addressee &a ) | 479 | void AddressBook::removeAddressee( const Addressee &a ) |
479 | { | 480 | { |
480 | Iterator it; | 481 | Iterator it; |
481 | for ( it = begin(); it != end(); ++it ) { | 482 | for ( it = begin(); it != end(); ++it ) { |
482 | if ( a.uid() == (*it).uid() ) { | 483 | if ( a.uid() == (*it).uid() ) { |
483 | removeAddressee( it ); | 484 | removeAddressee( it ); |
484 | return; | 485 | return; |
485 | } | 486 | } |
486 | } | 487 | } |
487 | } | 488 | } |
488 | 489 | ||
489 | void AddressBook::removeAddressee( const Iterator &it ) | 490 | void AddressBook::removeAddressee( const Iterator &it ) |
490 | { | 491 | { |
491 | d->mRemovedAddressees.append( (*it) ); | 492 | d->mRemovedAddressees.append( (*it) ); |
492 | d->mAddressees.remove( it.d->mIt ); | 493 | d->mAddressees.remove( it.d->mIt ); |
493 | } | 494 | } |
494 | 495 | ||
495 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 496 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
496 | { | 497 | { |
497 | Iterator it; | 498 | Iterator it; |
498 | for ( it = begin(); it != end(); ++it ) { | 499 | for ( it = begin(); it != end(); ++it ) { |
499 | if ( a.uid() == (*it).uid() ) { | 500 | if ( a.uid() == (*it).uid() ) { |
500 | return it; | 501 | return it; |
501 | } | 502 | } |
502 | } | 503 | } |
503 | return end(); | 504 | return end(); |
504 | } | 505 | } |
505 | 506 | ||
506 | Addressee AddressBook::findByUid( const QString &uid ) | 507 | Addressee AddressBook::findByUid( const QString &uid ) |
507 | { | 508 | { |
508 | Iterator it; | 509 | Iterator it; |
509 | for ( it = begin(); it != end(); ++it ) { | 510 | for ( it = begin(); it != end(); ++it ) { |
510 | if ( uid == (*it).uid() ) { | 511 | if ( uid == (*it).uid() ) { |
511 | return *it; | 512 | return *it; |
512 | } | 513 | } |
513 | } | 514 | } |
514 | return Addressee(); | 515 | return Addressee(); |
515 | } | 516 | } |
516 | Addressee::List AddressBook::getExternLastSyncAddressees() | 517 | Addressee::List AddressBook::getExternLastSyncAddressees() |
517 | { | 518 | { |
518 | Addressee::List results; | 519 | Addressee::List results; |
519 | 520 | ||
520 | Iterator it; | 521 | Iterator it; |
521 | for ( it = begin(); it != end(); ++it ) { | 522 | for ( it = begin(); it != end(); ++it ) { |
522 | if ( (*it).uid().left( 20 ) == "last-syncAddressee-" ) { | 523 | if ( (*it).uid().left( 20 ) == "last-syncAddressee-" ) { |
523 | if ( (*it).familyName().left(3) == "E: " ) | 524 | if ( (*it).familyName().left(3) == "E: " ) |
524 | results.append( *it ); | 525 | results.append( *it ); |
525 | } | 526 | } |
526 | } | 527 | } |
527 | 528 | ||
528 | return results; | 529 | return results; |
529 | } | 530 | } |
530 | void AddressBook::resetTempSyncStat() | 531 | void AddressBook::resetTempSyncStat() |
531 | { | 532 | { |
532 | Iterator it; | 533 | Iterator it; |
533 | for ( it = begin(); it != end(); ++it ) { | 534 | for ( it = begin(); it != end(); ++it ) { |
534 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 535 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
535 | } | 536 | } |
536 | 537 | ||
537 | } | 538 | } |
538 | 539 | ||
539 | QStringList AddressBook:: uidList() | 540 | QStringList AddressBook:: uidList() |
540 | { | 541 | { |
541 | QStringList results; | 542 | QStringList results; |
542 | Iterator it; | 543 | Iterator it; |
543 | for ( it = begin(); it != end(); ++it ) { | 544 | for ( it = begin(); it != end(); ++it ) { |
544 | results.append( (*it).uid() ); | 545 | results.append( (*it).uid() ); |
545 | } | 546 | } |
546 | return results; | 547 | return results; |
547 | } | 548 | } |
548 | 549 | ||
549 | 550 | ||
550 | Addressee::List AddressBook::allAddressees() | 551 | Addressee::List AddressBook::allAddressees() |
551 | { | 552 | { |
552 | return d->mAddressees; | 553 | return d->mAddressees; |
553 | } | 554 | } |
554 | 555 | ||
555 | Addressee::List AddressBook::findByName( const QString &name ) | 556 | Addressee::List AddressBook::findByName( const QString &name ) |
556 | { | 557 | { |
557 | Addressee::List results; | 558 | Addressee::List results; |
558 | 559 | ||
559 | Iterator it; | 560 | Iterator it; |