summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
authorzautrix <zautrix>2004-09-18 14:22:10 (UTC)
committer zautrix <zautrix>2004-09-18 14:22:10 (UTC)
commitca8fcf3fd4dc068747d8f31e2189145b22853d55 (patch) (unidiff)
tree29417ffd55d1c4186922a64ed0cdf1c6a1cc69a3 /kabc/addressbook.cpp
parentbb16660f29fc709791aa0ee4cb63a40710a994a8 (diff)
downloadkdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.zip
kdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.tar.gz
kdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.tar.bz2
more AB sync
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 9332e21..6e8d027 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -340,393 +340,400 @@ bool AddressBook::load()
340 ok = false; 340 ok = false;
341 } 341 }
342 342
343 // mark all addressees as unchanged 343 // mark all addressees as unchanged
344 Addressee::List::Iterator addrIt; 344 Addressee::List::Iterator addrIt;
345 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) 345 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
346 (*addrIt).setChanged( false ); 346 (*addrIt).setChanged( false );
347 347
348 return ok; 348 return ok;
349} 349}
350 350
351bool AddressBook::save( Ticket *ticket ) 351bool 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}
362bool AddressBook::saveAB() 362bool 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
392AddressBook::Iterator AddressBook::begin() 392AddressBook::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
399AddressBook::ConstIterator AddressBook::begin() const 399AddressBook::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
406AddressBook::Iterator AddressBook::end() 406AddressBook::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
413AddressBook::ConstIterator AddressBook::end() const 413AddressBook::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
420void AddressBook::clear() 420void AddressBook::clear()
421{ 421{
422 d->mAddressees.clear(); 422 d->mAddressees.clear();
423} 423}
424 424
425Ticket *AddressBook::requestSaveTicket( Resource *resource ) 425Ticket *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
448void AddressBook::insertAddressee( const Addressee &a ) 448void AddressBook::insertAddressee( const Addressee &a )
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 (*it).setRevision( QDateTime::currentDateTime() );
464 (*it).setChanged( true ); 464 (*it).setChanged( true );
465 } 465 }
466 466
467 return; 467 return;
468 } 468 }
469 } 469 }
470 d->mAddressees.append( a ); 470 d->mAddressees.append( a );
471 Addressee& addr = d->mAddressees.last(); 471 Addressee& addr = d->mAddressees.last();
472 if ( addr.resource() == 0 ) 472 if ( addr.resource() == 0 )
473 addr.setResource( standardResource() ); 473 addr.setResource( standardResource() );
474 474
475 addr.setChanged( true ); 475 addr.setChanged( true );
476} 476}
477 477
478void AddressBook::removeAddressee( const Addressee &a ) 478void AddressBook::removeAddressee( const Addressee &a )
479{ 479{
480 Iterator it; 480 Iterator it;
481 for ( it = begin(); it != end(); ++it ) { 481 for ( it = begin(); it != end(); ++it ) {
482 if ( a.uid() == (*it).uid() ) { 482 if ( a.uid() == (*it).uid() ) {
483 removeAddressee( it ); 483 removeAddressee( it );
484 return; 484 return;
485 } 485 }
486 } 486 }
487} 487}
488 488
489void AddressBook::removeAddressee( const Iterator &it ) 489void AddressBook::removeAddressee( const Iterator &it )
490{ 490{
491 d->mRemovedAddressees.append( (*it) ); 491 d->mRemovedAddressees.append( (*it) );
492 d->mAddressees.remove( it.d->mIt ); 492 d->mAddressees.remove( it.d->mIt );
493} 493}
494 494
495AddressBook::Iterator AddressBook::find( const Addressee &a ) 495AddressBook::Iterator AddressBook::find( const Addressee &a )
496{ 496{
497 Iterator it; 497 Iterator it;
498 for ( it = begin(); it != end(); ++it ) { 498 for ( it = begin(); it != end(); ++it ) {
499 if ( a.uid() == (*it).uid() ) { 499 if ( a.uid() == (*it).uid() ) {
500 return it; 500 return it;
501 } 501 }
502 } 502 }
503 return end(); 503 return end();
504} 504}
505 505
506Addressee AddressBook::findByUid( const QString &uid ) 506Addressee AddressBook::findByUid( const QString &uid )
507{ 507{
508 Iterator it; 508 Iterator it;
509 for ( it = begin(); it != end(); ++it ) { 509 for ( it = begin(); it != end(); ++it ) {
510 if ( uid == (*it).uid() ) { 510 if ( uid == (*it).uid() ) {
511 return *it; 511 return *it;
512 } 512 }
513 } 513 }
514 return Addressee(); 514 return Addressee();
515} 515}
516Addressee::List AddressBook::getExternLastSyncAddressees() 516Addressee::List AddressBook::getExternLastSyncAddressees()
517{ 517{
518 Addressee::List results; 518 Addressee::List results;
519 519
520 Iterator it; 520 Iterator it;
521 for ( it = begin(); it != end(); ++it ) { 521 for ( it = begin(); it != end(); ++it ) {
522 if ( (*it).uid().left( 20 ) == "last-syncAddressee-" ) { 522 if ( (*it).uid().left( 20 ) == "last-syncAddressee-" ) {
523 if ( (*it).familyName().left(3) == "E: " ) 523 if ( (*it).familyName().left(3) == "E: " )
524 results.append( *it ); 524 results.append( *it );
525 } 525 }
526 } 526 }
527 527
528 return results; 528 return results;
529} 529}
530void AddressBook::resetTempSyncStat() 530void AddressBook::resetTempSyncStat()
531{ 531{
532 532 Iterator it;
533
534 Iterator it;
535 for ( it = begin(); it != end(); ++it ) { 533 for ( it = begin(); it != end(); ++it ) {
536 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 534 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
537 } 535 }
538 536
539} 537}
540 538
539QStringList AddressBook:: uidList()
540{
541 QStringList results;
542 Iterator it;
543 for ( it = begin(); it != end(); ++it ) {
544 results.append( (*it).uid() );
545 }
546 return results;
547}
541 548
542 549
543Addressee::List AddressBook::allAddressees() 550Addressee::List AddressBook::allAddressees()
544{ 551{
545 return d->mAddressees; 552 return d->mAddressees;
546} 553}
547 554
548Addressee::List AddressBook::findByName( const QString &name ) 555Addressee::List AddressBook::findByName( const QString &name )
549{ 556{
550 Addressee::List results; 557 Addressee::List results;
551 558
552 Iterator it; 559 Iterator it;
553 for ( it = begin(); it != end(); ++it ) { 560 for ( it = begin(); it != end(); ++it ) {
554 if ( name == (*it).realName() ) { 561 if ( name == (*it).realName() ) {
555 results.append( *it ); 562 results.append( *it );
556 } 563 }
557 } 564 }
558 565
559 return results; 566 return results;
560} 567}
561 568
562Addressee::List AddressBook::findByEmail( const QString &email ) 569Addressee::List AddressBook::findByEmail( const QString &email )
563{ 570{
564 Addressee::List results; 571 Addressee::List results;
565 QStringList mailList; 572 QStringList mailList;
566 573
567 Iterator it; 574 Iterator it;
568 for ( it = begin(); it != end(); ++it ) { 575 for ( it = begin(); it != end(); ++it ) {
569 mailList = (*it).emails(); 576 mailList = (*it).emails();
570 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 577 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
571 if ( email == (*ite) ) { 578 if ( email == (*ite) ) {
572 results.append( *it ); 579 results.append( *it );
573 } 580 }
574 } 581 }
575 } 582 }
576 583
577 return results; 584 return results;
578} 585}
579 586
580Addressee::List AddressBook::findByCategory( const QString &category ) 587Addressee::List AddressBook::findByCategory( const QString &category )
581{ 588{
582 Addressee::List results; 589 Addressee::List results;
583 590
584 Iterator it; 591 Iterator it;
585 for ( it = begin(); it != end(); ++it ) { 592 for ( it = begin(); it != end(); ++it ) {
586 if ( (*it).hasCategory( category) ) { 593 if ( (*it).hasCategory( category) ) {
587 results.append( *it ); 594 results.append( *it );
588 } 595 }
589 } 596 }
590 597
591 return results; 598 return results;
592} 599}
593 600
594void AddressBook::dump() const 601void AddressBook::dump() const
595{ 602{
596 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 603 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
597 604
598 ConstIterator it; 605 ConstIterator it;
599 for( it = begin(); it != end(); ++it ) { 606 for( it = begin(); it != end(); ++it ) {
600 (*it).dump(); 607 (*it).dump();
601 } 608 }
602 609
603 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 610 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
604} 611}
605 612
606QString AddressBook::identifier() 613QString AddressBook::identifier()
607{ 614{
608 QStringList identifier; 615 QStringList identifier;
609 616
610 617
611 KRES::Manager<Resource>::ActiveIterator it; 618 KRES::Manager<Resource>::ActiveIterator it;
612 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 619 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
613 if ( !(*it)->identifier().isEmpty() ) 620 if ( !(*it)->identifier().isEmpty() )
614 identifier.append( (*it)->identifier() ); 621 identifier.append( (*it)->identifier() );
615 } 622 }
616 623
617 return identifier.join( ":" ); 624 return identifier.join( ":" );
618} 625}
619 626
620Field::List AddressBook::fields( int category ) 627Field::List AddressBook::fields( int category )
621{ 628{
622 if ( d->mAllFields.isEmpty() ) { 629 if ( d->mAllFields.isEmpty() ) {
623 d->mAllFields = Field::allFields(); 630 d->mAllFields = Field::allFields();
624 } 631 }
625 632
626 if ( category == Field::All ) return d->mAllFields; 633 if ( category == Field::All ) return d->mAllFields;
627 634
628 Field::List result; 635 Field::List result;
629 Field::List::ConstIterator it; 636 Field::List::ConstIterator it;
630 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 637 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
631 if ( (*it)->category() & category ) result.append( *it ); 638 if ( (*it)->category() & category ) result.append( *it );
632 } 639 }
633 640
634 return result; 641 return result;
635} 642}
636 643
637bool AddressBook::addCustomField( const QString &label, int category, 644bool AddressBook::addCustomField( const QString &label, int category,
638 const QString &key, const QString &app ) 645 const QString &key, const QString &app )
639{ 646{
640 if ( d->mAllFields.isEmpty() ) { 647 if ( d->mAllFields.isEmpty() ) {
641 d->mAllFields = Field::allFields(); 648 d->mAllFields = Field::allFields();
642 } 649 }
643//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 650//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
644 QString a = app.isNull() ? KGlobal::getAppName() : app; 651 QString a = app.isNull() ? KGlobal::getAppName() : app;
645 652
646 QString k = key.isNull() ? label : key; 653 QString k = key.isNull() ? label : key;
647 654
648 Field *field = Field::createCustomField( label, category, k, a ); 655 Field *field = Field::createCustomField( label, category, k, a );
649 656
650 if ( !field ) return false; 657 if ( !field ) return false;
651 658
652 d->mAllFields.append( field ); 659 d->mAllFields.append( field );
653 660
654 return true; 661 return true;
655} 662}
656 663
657QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 664QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
658{ 665{
659 if (!ab.d) return s; 666 if (!ab.d) return s;
660 667
661 return s << ab.d->mAddressees; 668 return s << ab.d->mAddressees;
662} 669}
663 670
664QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 671QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
665{ 672{
666 if (!ab.d) return s; 673 if (!ab.d) return s;
667 674
668 s >> ab.d->mAddressees; 675 s >> ab.d->mAddressees;
669 676
670 return s; 677 return s;
671} 678}
672 679
673bool AddressBook::addResource( Resource *resource ) 680bool AddressBook::addResource( Resource *resource )
674{ 681{
675 if ( !resource->open() ) { 682 if ( !resource->open() ) {
676 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 683 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
677 return false; 684 return false;
678 } 685 }
679 686
680 resource->setAddressBook( this ); 687 resource->setAddressBook( this );
681 688
682 d->mManager->add( resource ); 689 d->mManager->add( resource );
683 return true; 690 return true;
684} 691}
685 692
686bool AddressBook::removeResource( Resource *resource ) 693bool AddressBook::removeResource( Resource *resource )
687{ 694{
688 resource->close(); 695 resource->close();
689 696
690 if ( resource == standardResource() ) 697 if ( resource == standardResource() )
691 d->mManager->setStandardResource( 0 ); 698 d->mManager->setStandardResource( 0 );
692 699
693 resource->setAddressBook( 0 ); 700 resource->setAddressBook( 0 );
694 701
695 d->mManager->remove( resource ); 702 d->mManager->remove( resource );
696 return true; 703 return true;
697} 704}
698 705
699QPtrList<Resource> AddressBook::resources() 706QPtrList<Resource> AddressBook::resources()
700{ 707{
701 QPtrList<Resource> list; 708 QPtrList<Resource> list;
702 709
703// qDebug("AddressBook::resources() 1"); 710// qDebug("AddressBook::resources() 1");
704 711
705 KRES::Manager<Resource>::ActiveIterator it; 712 KRES::Manager<Resource>::ActiveIterator it;
706 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 713 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
707 list.append( *it ); 714 list.append( *it );
708 715
709 return list; 716 return list;
710} 717}
711 718
712/*US 719/*US
713void AddressBook::setErrorHandler( ErrorHandler *handler ) 720void AddressBook::setErrorHandler( ErrorHandler *handler )
714{ 721{
715 delete d->mErrorHandler; 722 delete d->mErrorHandler;
716 d->mErrorHandler = handler; 723 d->mErrorHandler = handler;
717} 724}
718*/ 725*/
719 726
720void AddressBook::error( const QString& msg ) 727void AddressBook::error( const QString& msg )
721{ 728{
722/*US 729/*US
723 if ( !d->mErrorHandler ) // create default error handler 730 if ( !d->mErrorHandler ) // create default error handler
724 d->mErrorHandler = new ConsoleErrorHandler; 731 d->mErrorHandler = new ConsoleErrorHandler;
725 732
726 if ( d->mErrorHandler ) 733 if ( d->mErrorHandler )
727 d->mErrorHandler->error( msg ); 734 d->mErrorHandler->error( msg );
728 else 735 else
729 kdError(5700) << "no error handler defined" << endl; 736 kdError(5700) << "no error handler defined" << endl;
730*/ 737*/
731 kdDebug(5700) << "msg" << endl; 738 kdDebug(5700) << "msg" << endl;
732 qDebug(msg); 739 qDebug(msg);