summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-18 14:22:10 (UTC)
committer zautrix <zautrix>2004-09-18 14:22:10 (UTC)
commitca8fcf3fd4dc068747d8f31e2189145b22853d55 (patch) (unidiff)
tree29417ffd55d1c4186922a64ed0cdf1c6a1cc69a3
parentbb16660f29fc709791aa0ee4cb63a40710a994a8 (diff)
downloadkdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.zip
kdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.tar.gz
kdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.tar.bz2
more AB sync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp15
-rw-r--r--kabc/addressbook.h3
-rw-r--r--kaddressbook/kabcore.cpp206
3 files changed, 105 insertions, 119 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);
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 05225f9..650a638 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -101,233 +101,234 @@ class AddressBook : public QObject
101 ConstIterator &operator++(); 101 ConstIterator &operator++();
102 ConstIterator &operator++(int); 102 ConstIterator &operator++(int);
103 ConstIterator &operator--(); 103 ConstIterator &operator--();
104 ConstIterator &operator--(int); 104 ConstIterator &operator--(int);
105 bool operator==( const ConstIterator &it ); 105 bool operator==( const ConstIterator &it );
106 bool operator!=( const ConstIterator &it ); 106 bool operator!=( const ConstIterator &it );
107 107
108 struct ConstIteratorData; 108 struct ConstIteratorData;
109 ConstIteratorData *d; 109 ConstIteratorData *d;
110 }; 110 };
111 111
112 /** 112 /**
113 Constructs a address book object. 113 Constructs a address book object.
114 114
115 @param format File format class. 115 @param format File format class.
116 */ 116 */
117 AddressBook(); 117 AddressBook();
118 AddressBook( const QString &config ); 118 AddressBook( const QString &config );
119 AddressBook( const QString &config, const QString &family ); 119 AddressBook( const QString &config, const QString &family );
120 virtual ~AddressBook(); 120 virtual ~AddressBook();
121 121
122 /** 122 /**
123 Requests a ticket for saving the addressbook. Calling this function locks 123 Requests a ticket for saving the addressbook. Calling this function locks
124 the addressbook for all other processes. If the address book is already 124 the addressbook for all other processes. If the address book is already
125 locked the function returns 0. You need the returned @ref Ticket object 125 locked the function returns 0. You need the returned @ref Ticket object
126 for calling the @ref save() function. 126 for calling the @ref save() function.
127 127
128 @see save() 128 @see save()
129 */ 129 */
130 Ticket *requestSaveTicket( Resource *resource=0 ); 130 Ticket *requestSaveTicket( Resource *resource=0 );
131 131
132 /** 132 /**
133 Load address book from file. 133 Load address book from file.
134 */ 134 */
135 bool load(); 135 bool load();
136 136
137 /** 137 /**
138 Save address book. The address book is saved to the file, the Ticket 138 Save address book. The address book is saved to the file, the Ticket
139 object has been requested for by @ref requestSaveTicket(). 139 object has been requested for by @ref requestSaveTicket().
140 140
141 @param ticket a ticket object returned by @ref requestSaveTicket() 141 @param ticket a ticket object returned by @ref requestSaveTicket()
142 */ 142 */
143 bool save( Ticket *ticket ); 143 bool save( Ticket *ticket );
144 bool saveAB( ); 144 bool saveAB( );
145 145
146 /** 146 /**
147 Returns a iterator for first entry of address book. 147 Returns a iterator for first entry of address book.
148 */ 148 */
149 Iterator begin(); 149 Iterator begin();
150 150
151 /** 151 /**
152 Returns a const iterator for first entry of address book. 152 Returns a const iterator for first entry of address book.
153 */ 153 */
154 ConstIterator begin() const; 154 ConstIterator begin() const;
155 155
156 /** 156 /**
157 Returns a iterator for first entry of address book. 157 Returns a iterator for first entry of address book.
158 */ 158 */
159 Iterator end(); 159 Iterator end();
160 160
161 /** 161 /**
162 Returns a const iterator for first entry of address book. 162 Returns a const iterator for first entry of address book.
163 */ 163 */
164 ConstIterator end() const; 164 ConstIterator end() const;
165 165
166 /** 166 /**
167 Removes all entries from address book. 167 Removes all entries from address book.
168 */ 168 */
169 void clear(); 169 void clear();
170 170
171 /** 171 /**
172 Insert an Addressee object into address book. If an object with the same 172 Insert an Addressee object into address book. If an object with the same
173 unique id already exists in the address book it it replaced by the new 173 unique id already exists in the address book it it replaced by the new
174 one. If not the new object is appended to the address book. 174 one. If not the new object is appended to the address book.
175 */ 175 */
176 void insertAddressee( const Addressee & ); 176 void insertAddressee( const Addressee & );
177 177
178 /** 178 /**
179 Removes entry from the address book. 179 Removes entry from the address book.
180 */ 180 */
181 void removeAddressee( const Addressee & ); 181 void removeAddressee( const Addressee & );
182 182
183 /** 183 /**
184 This is like @ref removeAddressee() just above, with the difference that 184 This is like @ref removeAddressee() just above, with the difference that
185 the first element is a iterator, returned by @ref begin(). 185 the first element is a iterator, returned by @ref begin().
186 */ 186 */
187 void removeAddressee( const Iterator & ); 187 void removeAddressee( const Iterator & );
188 188
189 /** 189 /**
190 Find the specified entry in address book. Returns end(), if the entry 190 Find the specified entry in address book. Returns end(), if the entry
191 couldn't be found. 191 couldn't be found.
192 */ 192 */
193 Iterator find( const Addressee & ); 193 Iterator find( const Addressee & );
194 194
195 /** 195 /**
196 Find the entry specified by an unique id. Returns an empty Addressee 196 Find the entry specified by an unique id. Returns an empty Addressee
197 object, if the address book does not contain an entry with this id. 197 object, if the address book does not contain an entry with this id.
198 */ 198 */
199 Addressee findByUid( const QString & ); 199 Addressee findByUid( const QString & );
200 200
201 201
202 /** 202 /**
203 Returns a list of all addressees in the address book. This list can 203 Returns a list of all addressees in the address book. This list can
204 be sorted with @ref KABC::AddresseeList for example. 204 be sorted with @ref KABC::AddresseeList for example.
205 */ 205 */
206 Addressee::List allAddressees(); 206 Addressee::List allAddressees();
207 207
208 /** 208 /**
209 Find all entries with the specified name in the address book. Returns 209 Find all entries with the specified name in the address book. Returns
210 an empty list, if no entries could be found. 210 an empty list, if no entries could be found.
211 */ 211 */
212 Addressee::List findByName( const QString & ); 212 Addressee::List findByName( const QString & );
213 213
214 /** 214 /**
215 Find all entries with the specified email address in the address book. 215 Find all entries with the specified email address in the address book.
216 Returns an empty list, if no entries could be found. 216 Returns an empty list, if no entries could be found.
217 */ 217 */
218 Addressee::List findByEmail( const QString & ); 218 Addressee::List findByEmail( const QString & );
219 219
220 /** 220 /**
221 Find all entries wich have the specified category in the address book. 221 Find all entries wich have the specified category in the address book.
222 Returns an empty list, if no entries could be found. 222 Returns an empty list, if no entries could be found.
223 */ 223 */
224 Addressee::List findByCategory( const QString & ); 224 Addressee::List findByCategory( const QString & );
225 225
226 /** 226 /**
227 Return a string identifying this addressbook. 227 Return a string identifying this addressbook.
228 */ 228 */
229 virtual QString identifier(); 229 virtual QString identifier();
230 230
231 /** 231 /**
232 Used for debug output. 232 Used for debug output.
233 */ 233 */
234 void dump() const; 234 void dump() const;
235 235
236 void emitAddressBookLocked() { emit addressBookLocked( this ); } 236 void emitAddressBookLocked() { emit addressBookLocked( this ); }
237 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 237 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
238 void emitAddressBookChanged() { emit addressBookChanged( this ); } 238 void emitAddressBookChanged() { emit addressBookChanged( this ); }
239 239
240 /** 240 /**
241 Return list of all Fields known to the address book which are associated 241 Return list of all Fields known to the address book which are associated
242 with the given field category. 242 with the given field category.
243 */ 243 */
244 Field::List fields( int category = Field::All ); 244 Field::List fields( int category = Field::All );
245 245
246 /** 246 /**
247 Add custom field to address book. 247 Add custom field to address book.
248 248
249 @param label User visible label of the field. 249 @param label User visible label of the field.
250 @param category Ored list of field categories. 250 @param category Ored list of field categories.
251 @param key Identifier used as key for reading and writing the field. 251 @param key Identifier used as key for reading and writing the field.
252 @param app String used as application key for reading and writing 252 @param app String used as application key for reading and writing
253 the field. 253 the field.
254 */ 254 */
255 bool addCustomField( const QString &label, int category = Field::All, 255 bool addCustomField( const QString &label, int category = Field::All,
256 const QString &key = QString::null, 256 const QString &key = QString::null,
257 const QString &app = QString::null ); 257 const QString &app = QString::null );
258 258
259 259
260 /** 260 /**
261 Add address book resource. 261 Add address book resource.
262 */ 262 */
263 bool addResource( Resource * ); 263 bool addResource( Resource * );
264 264
265 /** 265 /**
266 Remove address book resource. 266 Remove address book resource.
267 */ 267 */
268 bool removeResource( Resource * ); 268 bool removeResource( Resource * );
269 269
270 /** 270 /**
271 Return pointer list of all resources. 271 Return pointer list of all resources.
272 */ 272 */
273 QPtrList<Resource> resources(); 273 QPtrList<Resource> resources();
274 274
275 /** 275 /**
276 Set the @p ErrorHandler, that is used by @ref error() to 276 Set the @p ErrorHandler, that is used by @ref error() to
277 provide gui-independend error messages. 277 provide gui-independend error messages.
278 */ 278 */
279 void setErrorHandler( ErrorHandler * ); 279 void setErrorHandler( ErrorHandler * );
280 280
281 /** 281 /**
282 Shows gui independend error messages. 282 Shows gui independend error messages.
283 */ 283 */
284 void error( const QString& ); 284 void error( const QString& );
285 285
286 /** 286 /**
287 Query all resources to clean up their lock files 287 Query all resources to clean up their lock files
288 */ 288 */
289 void cleanUp(); 289 void cleanUp();
290 290
291 // sync stuff 291 // sync stuff
292 Addressee::List getExternLastSyncAddressees(); 292 Addressee::List getExternLastSyncAddressees();
293 void resetTempSyncStat(); 293 void resetTempSyncStat();
294 QStringList uidList();
294 295
295 296
296 signals: 297 signals:
297 /** 298 /**
298 Emitted, when the address book has changed on disk. 299 Emitted, when the address book has changed on disk.
299 */ 300 */
300 void addressBookChanged( AddressBook * ); 301 void addressBookChanged( AddressBook * );
301 302
302 /** 303 /**
303 Emitted, when the address book has been locked for writing. 304 Emitted, when the address book has been locked for writing.
304 */ 305 */
305 void addressBookLocked( AddressBook * ); 306 void addressBookLocked( AddressBook * );
306 307
307 /** 308 /**
308 Emitted, when the address book has been unlocked. 309 Emitted, when the address book has been unlocked.
309 */ 310 */
310 void addressBookUnlocked( AddressBook * ); 311 void addressBookUnlocked( AddressBook * );
311 312
312 protected: 313 protected:
313 void deleteRemovedAddressees(); 314 void deleteRemovedAddressees();
314 void setStandardResource( Resource * ); 315 void setStandardResource( Resource * );
315 Resource *standardResource(); 316 Resource *standardResource();
316 KRES::Manager<Resource> *resourceManager(); 317 KRES::Manager<Resource> *resourceManager();
317 318
318 void init(const QString &config, const QString &family); 319 void init(const QString &config, const QString &family);
319 320
320 private: 321 private:
321//US QPtrList<Resource> mDummy; // Remove in KDE 4 322//US QPtrList<Resource> mDummy; // Remove in KDE 4
322 323
323 324
324 struct AddressBookData; 325 struct AddressBookData;
325 AddressBookData *d; 326 AddressBookData *d;
326}; 327};
327 328
328QDataStream &operator<<( QDataStream &, const AddressBook & ); 329QDataStream &operator<<( QDataStream &, const AddressBook & );
329QDataStream &operator>>( QDataStream &, AddressBook & ); 330QDataStream &operator>>( QDataStream &, AddressBook & );
330 331
331} 332}
332 333
333#endif 334#endif
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 53c63ff..f497541 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1,233 +1,235 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include "kabcore.h" 31#include "kabcore.h"
32 32
33#include <stdaddressbook.h> 33#include <stdaddressbook.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kfiledialog.h> 35#include <kfiledialog.h>
36#include <qprogressbar.h>
36 37
37#ifndef KAB_EMBEDDED 38#ifndef KAB_EMBEDDED
38#include <qclipboard.h> 39#include <qclipboard.h>
39#include <qdir.h> 40#include <qdir.h>
40#include <qfile.h> 41#include <qfile.h>
41#include <qapplicaton.h> 42#include <qapplicaton.h>
43#include <qprogressbar.h>
42#include <qlayout.h> 44#include <qlayout.h>
43#include <qregexp.h> 45#include <qregexp.h>
44#include <qvbox.h> 46#include <qvbox.h>
45#include <kabc/addresseelist.h> 47#include <kabc/addresseelist.h>
46#include <kabc/errorhandler.h> 48#include <kabc/errorhandler.h>
47#include <kabc/resource.h> 49#include <kabc/resource.h>
48#include <kabc/vcardconverter.h> 50#include <kabc/vcardconverter.h>
49#include <kapplication.h> 51#include <kapplication.h>
50#include <kactionclasses.h> 52#include <kactionclasses.h>
51#include <kcmultidialog.h> 53#include <kcmultidialog.h>
52#include <kdebug.h> 54#include <kdebug.h>
53#include <kdeversion.h> 55#include <kdeversion.h>
54#include <kkeydialog.h> 56#include <kkeydialog.h>
55#include <kmessagebox.h> 57#include <kmessagebox.h>
56#include <kprinter.h> 58#include <kprinter.h>
57#include <kprotocolinfo.h> 59#include <kprotocolinfo.h>
58#include <kresources/selectdialog.h> 60#include <kresources/selectdialog.h>
59#include <kstandarddirs.h> 61#include <kstandarddirs.h>
60#include <ktempfile.h> 62#include <ktempfile.h>
61#include <kxmlguiclient.h> 63#include <kxmlguiclient.h>
62#include <kaboutdata.h> 64#include <kaboutdata.h>
63#include <libkdepim/categoryselectdialog.h> 65#include <libkdepim/categoryselectdialog.h>
64 66
65#include "addresseeutil.h" 67#include "addresseeutil.h"
66#include "addresseeeditordialog.h" 68#include "addresseeeditordialog.h"
67#include "extensionmanager.h" 69#include "extensionmanager.h"
68#include "kstdaction.h" 70#include "kstdaction.h"
69#include "kaddressbookservice.h" 71#include "kaddressbookservice.h"
70#include "ldapsearchdialog.h" 72#include "ldapsearchdialog.h"
71#include "printing/printingwizard.h" 73#include "printing/printingwizard.h"
72#else // KAB_EMBEDDED 74#else // KAB_EMBEDDED
73 75
74#include <kapplication.h> 76#include <kapplication.h>
75#include "KDGanttMinimizeSplitter.h" 77#include "KDGanttMinimizeSplitter.h"
76#include "kaddressbookmain.h" 78#include "kaddressbookmain.h"
77#include "kactioncollection.h" 79#include "kactioncollection.h"
78#include "addresseedialog.h" 80#include "addresseedialog.h"
79//US 81//US
80#include <addresseeview.h> 82#include <addresseeview.h>
81 83
82#include <qapp.h> 84#include <qapp.h>
83#include <qmenubar.h> 85#include <qmenubar.h>
84//#include <qtoolbar.h> 86//#include <qtoolbar.h>
85#include <qmessagebox.h> 87#include <qmessagebox.h>
86#include <kdebug.h> 88#include <kdebug.h>
87#include <kiconloader.h> // needed for SmallIcon 89#include <kiconloader.h> // needed for SmallIcon
88#include <kresources/kcmkresources.h> 90#include <kresources/kcmkresources.h>
89#include <ktoolbar.h> 91#include <ktoolbar.h>
90 92
91 93
92//#include <qlabel.h> 94//#include <qlabel.h>
93 95
94 96
95#ifndef DESKTOP_VERSION 97#ifndef DESKTOP_VERSION
96#include <qpe/ir.h> 98#include <qpe/ir.h>
97#include <qpe/qpemenubar.h> 99#include <qpe/qpemenubar.h>
98#include <qtopia/qcopenvelope_qws.h> 100#include <qtopia/qcopenvelope_qws.h>
99#else 101#else
100 102
101#include <qmenubar.h> 103#include <qmenubar.h>
102#endif 104#endif
103 105
104#endif // KAB_EMBEDDED 106#endif // KAB_EMBEDDED
105#include "kcmconfigs/kcmkabconfig.h" 107#include "kcmconfigs/kcmkabconfig.h"
106#include "kcmconfigs/kcmkdepimconfig.h" 108#include "kcmconfigs/kcmkdepimconfig.h"
107#include "kpimglobalprefs.h" 109#include "kpimglobalprefs.h"
108#include "externalapphandler.h" 110#include "externalapphandler.h"
109 111
110 112
111#include <kresources/selectdialog.h> 113#include <kresources/selectdialog.h>
112#include <kmessagebox.h> 114#include <kmessagebox.h>
113 115
114#include <picture.h> 116#include <picture.h>
115#include <resource.h> 117#include <resource.h>
116 118
117//US#include <qsplitter.h> 119//US#include <qsplitter.h>
118#include <qmap.h> 120#include <qmap.h>
119#include <qdir.h> 121#include <qdir.h>
120#include <qfile.h> 122#include <qfile.h>
121#include <qvbox.h> 123#include <qvbox.h>
122#include <qlayout.h> 124#include <qlayout.h>
123#include <qclipboard.h> 125#include <qclipboard.h>
124#include <qtextstream.h> 126#include <qtextstream.h>
125 127
126#include <libkdepim/categoryselectdialog.h> 128#include <libkdepim/categoryselectdialog.h>
127#include <kabc/vcardconverter.h> 129#include <kabc/vcardconverter.h>
128 130
129 131
130#include "addresseeutil.h" 132#include "addresseeutil.h"
131#include "undocmds.h" 133#include "undocmds.h"
132#include "addresseeeditordialog.h" 134#include "addresseeeditordialog.h"
133#include "viewmanager.h" 135#include "viewmanager.h"
134#include "details/detailsviewcontainer.h" 136#include "details/detailsviewcontainer.h"
135#include "kabprefs.h" 137#include "kabprefs.h"
136#include "xxportmanager.h" 138#include "xxportmanager.h"
137#include "incsearchwidget.h" 139#include "incsearchwidget.h"
138#include "jumpbuttonbar.h" 140#include "jumpbuttonbar.h"
139#include "extensionmanager.h" 141#include "extensionmanager.h"
140#include "addresseeconfig.h" 142#include "addresseeconfig.h"
141#include <kcmultidialog.h> 143#include <kcmultidialog.h>
142 144
143#ifdef _WIN32_ 145#ifdef _WIN32_
144 146
145#include "kaimportoldialog.h" 147#include "kaimportoldialog.h"
146#else 148#else
147#include <unistd.h> 149#include <unistd.h>
148#endif 150#endif
149// sync includes 151// sync includes
150#include <libkdepim/ksyncprofile.h> 152#include <libkdepim/ksyncprofile.h>
151#include <libkdepim/ksyncprefsdialog.h> 153#include <libkdepim/ksyncprefsdialog.h>
152 154
153 155
154bool pasteWithNewUid = true; 156bool pasteWithNewUid = true;
155 157
156#ifdef KAB_EMBEDDED 158#ifdef KAB_EMBEDDED
157KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) 159KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
158 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), 160 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
159 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ 161 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
160 mReadWrite( readWrite ), mModified( false ), mMainWindow(client) 162 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
161#else //KAB_EMBEDDED 163#else //KAB_EMBEDDED
162KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) 164KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
163 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), 165 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
164 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), 166 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
165 mReadWrite( readWrite ), mModified( false ) 167 mReadWrite( readWrite ), mModified( false )
166#endif //KAB_EMBEDDED 168#endif //KAB_EMBEDDED
167{ 169{
168 170
169 mBlockSaveFlag = false; 171 mBlockSaveFlag = false;
170 mExtensionBarSplitter = 0; 172 mExtensionBarSplitter = 0;
171 mIsPart = !parent->inherits( "KAddressBookMain" ); 173 mIsPart = !parent->inherits( "KAddressBookMain" );
172 174
173 mAddressBook = KABC::StdAddressBook::self(); 175 mAddressBook = KABC::StdAddressBook::self();
174 KABC::StdAddressBook::setAutomaticSave( false ); 176 KABC::StdAddressBook::setAutomaticSave( false );
175 177
176#ifndef KAB_EMBEDDED 178#ifndef KAB_EMBEDDED
177 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); 179 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
178#endif //KAB_EMBEDDED 180#endif //KAB_EMBEDDED
179 181
180 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), 182 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
181 SLOT( addressBookChanged() ) ); 183 SLOT( addressBookChanged() ) );
182 184
183#if 0 185#if 0
184 // LP moved to addressbook init method 186 // LP moved to addressbook init method
185 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, 187 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
186 "X-Department", "KADDRESSBOOK" ); 188 "X-Department", "KADDRESSBOOK" );
187 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, 189 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
188 "X-Profession", "KADDRESSBOOK" ); 190 "X-Profession", "KADDRESSBOOK" );
189 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 191 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
190 "X-AssistantsName", "KADDRESSBOOK" ); 192 "X-AssistantsName", "KADDRESSBOOK" );
191 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 193 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
192 "X-ManagersName", "KADDRESSBOOK" ); 194 "X-ManagersName", "KADDRESSBOOK" );
193 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 195 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
194 "X-SpousesName", "KADDRESSBOOK" ); 196 "X-SpousesName", "KADDRESSBOOK" );
195 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, 197 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal,
196 "X-Office", "KADDRESSBOOK" ); 198 "X-Office", "KADDRESSBOOK" );
197 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 199 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
198 "X-IMAddress", "KADDRESSBOOK" ); 200 "X-IMAddress", "KADDRESSBOOK" );
199 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 201 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
200 "X-Anniversary", "KADDRESSBOOK" ); 202 "X-Anniversary", "KADDRESSBOOK" );
201 203
202 //US added this field to become compatible with Opie/qtopia addressbook 204 //US added this field to become compatible with Opie/qtopia addressbook
203 // values can be "female" or "male" or "". An empty field represents undefined. 205 // values can be "female" or "male" or "". An empty field represents undefined.
204 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, 206 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal,
205 "X-Gender", "KADDRESSBOOK" ); 207 "X-Gender", "KADDRESSBOOK" );
206 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, 208 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal,
207 "X-Children", "KADDRESSBOOK" ); 209 "X-Children", "KADDRESSBOOK" );
208 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 210 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
209 "X-FreeBusyUrl", "KADDRESSBOOK" ); 211 "X-FreeBusyUrl", "KADDRESSBOOK" );
210#endif 212#endif
211 initGUI(); 213 initGUI();
212 214
213 mIncSearchWidget->setFocus(); 215 mIncSearchWidget->setFocus();
214 216
215 217
216 connect( mViewManager, SIGNAL( selected( const QString& ) ), 218 connect( mViewManager, SIGNAL( selected( const QString& ) ),
217 SLOT( setContactSelected( const QString& ) ) ); 219 SLOT( setContactSelected( const QString& ) ) );
218 connect( mViewManager, SIGNAL( executed( const QString& ) ), 220 connect( mViewManager, SIGNAL( executed( const QString& ) ),
219 SLOT( executeContact( const QString& ) ) ); 221 SLOT( executeContact( const QString& ) ) );
220 222
221 connect( mViewManager, SIGNAL( deleteRequest( ) ), 223 connect( mViewManager, SIGNAL( deleteRequest( ) ),
222 SLOT( deleteContacts( ) ) ); 224 SLOT( deleteContacts( ) ) );
223 connect( mViewManager, SIGNAL( modified() ), 225 connect( mViewManager, SIGNAL( modified() ),
224 SLOT( setModified() ) ); 226 SLOT( setModified() ) );
225 227
226 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); 228 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) );
227 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); 229 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) );
228 230
229 connect( mXXPortManager, SIGNAL( modified() ), 231 connect( mXXPortManager, SIGNAL( modified() ),
230 SLOT( setModified() ) ); 232 SLOT( setModified() ) );
231 233
232 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), 234 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ),
233 SLOT( incrementalSearch( const QString& ) ) ); 235 SLOT( incrementalSearch( const QString& ) ) );
@@ -2408,489 +2410,465 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask)
2408 } 2410 }
2409 setCaption ( i18n( "Copying succeed." ) ); 2411 setCaption ( i18n( "Copying succeed." ) );
2410 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 2412 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
2411 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { 2413 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) {
2412// Event* e = mView->getLastSyncEvent(); 2414// Event* e = mView->getLastSyncEvent();
2413// e->setReadOnly( false ); 2415// e->setReadOnly( false );
2414// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2416// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2415// e->setReadOnly( true ); 2417// e->setReadOnly( true );
2416 if ( KABPrefs::instance()->mWriteBackFile ) { 2418 if ( KABPrefs::instance()->mWriteBackFile ) {
2417 command = prof->getPostSyncCommandAB(); 2419 command = prof->getPostSyncCommandAB();
2418 int fi; 2420 int fi;
2419 if ( (fi = command.find("$PWD$")) > 0 ) { 2421 if ( (fi = command.find("$PWD$")) > 0 ) {
2420 QString pwd = getPassword(); 2422 QString pwd = getPassword();
2421 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2423 command = command.left( fi )+ pwd + command.mid( fi+5 );
2422 2424
2423 } 2425 }
2424 setCaption ( i18n( "Writing back file ..." ) ); 2426 setCaption ( i18n( "Writing back file ..." ) );
2425 result = system ( command ); 2427 result = system ( command );
2426 qDebug("KO: Writing back file result: %d ", result); 2428 qDebug("KO: Writing back file result: %d ", result);
2427 if ( result != 0 ) { 2429 if ( result != 0 ) {
2428 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 2430 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
2429 return; 2431 return;
2430 } else { 2432 } else {
2431 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 2433 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2432 } 2434 }
2433 } 2435 }
2434 } 2436 }
2435 return; 2437 return;
2436} 2438}
2437#include <qpushbutton.h> 2439#include <qpushbutton.h>
2438#include <qradiobutton.h> 2440#include <qradiobutton.h>
2439#include <qbuttongroup.h> 2441#include <qbuttongroup.h>
2440void KABCore::edit_sync_options() 2442void KABCore::edit_sync_options()
2441{ 2443{
2442 //mDialogManager->showSyncOptions(); 2444 //mDialogManager->showSyncOptions();
2443 //KABPrefs::instance()->mSyncAlgoPrefs 2445 //KABPrefs::instance()->mSyncAlgoPrefs
2444 QDialog dia( this, "dia", true ); 2446 QDialog dia( this, "dia", true );
2445 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 2447 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2446 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 2448 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2447 QVBoxLayout lay ( &dia ); 2449 QVBoxLayout lay ( &dia );
2448 lay.setSpacing( 2 ); 2450 lay.setSpacing( 2 );
2449 lay.setMargin( 3 ); 2451 lay.setMargin( 3 );
2450 lay.addWidget(&gr); 2452 lay.addWidget(&gr);
2451 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 2453 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2452 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 2454 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2453 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 2455 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2454 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 2456 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2455 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 2457 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2456 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 2458 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2457 //QRadioButton both( i18n("Take both on conflict"), &gr ); 2459 //QRadioButton both( i18n("Take both on conflict"), &gr );
2458 QPushButton pb ( "OK", &dia); 2460 QPushButton pb ( "OK", &dia);
2459 lay.addWidget( &pb ); 2461 lay.addWidget( &pb );
2460 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2462 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2461 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { 2463 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) {
2462 case 0: 2464 case 0:
2463 loc.setChecked( true); 2465 loc.setChecked( true);
2464 break; 2466 break;
2465 case 1: 2467 case 1:
2466 rem.setChecked( true ); 2468 rem.setChecked( true );
2467 break; 2469 break;
2468 case 2: 2470 case 2:
2469 newest.setChecked( true); 2471 newest.setChecked( true);
2470 break; 2472 break;
2471 case 3: 2473 case 3:
2472 ask.setChecked( true); 2474 ask.setChecked( true);
2473 break; 2475 break;
2474 case 4: 2476 case 4:
2475 f_loc.setChecked( true); 2477 f_loc.setChecked( true);
2476 break; 2478 break;
2477 case 5: 2479 case 5:
2478 f_rem.setChecked( true); 2480 f_rem.setChecked( true);
2479 break; 2481 break;
2480 case 6: 2482 case 6:
2481 // both.setChecked( true); 2483 // both.setChecked( true);
2482 break; 2484 break;
2483 default: 2485 default:
2484 break; 2486 break;
2485 } 2487 }
2486 if ( dia.exec() ) { 2488 if ( dia.exec() ) {
2487 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 2489 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2488 } 2490 }
2489 2491
2490 2492
2491} 2493}
2492QString KABCore::getPassword( ) 2494QString KABCore::getPassword( )
2493{ 2495{
2494 QString retfile = ""; 2496 QString retfile = "";
2495 QDialog dia ( this, "input-dialog", true ); 2497 QDialog dia ( this, "input-dialog", true );
2496 QLineEdit lab ( &dia ); 2498 QLineEdit lab ( &dia );
2497 lab.setEchoMode( QLineEdit::Password ); 2499 lab.setEchoMode( QLineEdit::Password );
2498 QVBoxLayout lay( &dia ); 2500 QVBoxLayout lay( &dia );
2499 lay.setMargin(7); 2501 lay.setMargin(7);
2500 lay.setSpacing(7); 2502 lay.setSpacing(7);
2501 lay.addWidget( &lab); 2503 lay.addWidget( &lab);
2502 dia.setFixedSize( 230,50 ); 2504 dia.setFixedSize( 230,50 );
2503 dia.setCaption( i18n("Enter password") ); 2505 dia.setCaption( i18n("Enter password") );
2504 QPushButton pb ( "OK", &dia); 2506 QPushButton pb ( "OK", &dia);
2505 lay.addWidget( &pb ); 2507 lay.addWidget( &pb );
2506 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2508 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2507 dia.show(); 2509 dia.show();
2508 int res = dia.exec(); 2510 int res = dia.exec();
2509 if ( res ) 2511 if ( res )
2510 retfile = lab.text(); 2512 retfile = lab.text();
2511 dia.hide(); 2513 dia.hide();
2512 qApp->processEvents(); 2514 qApp->processEvents();
2513 return retfile; 2515 return retfile;
2514 2516
2515} 2517}
2516#include <libkcal/syncdefines.h> 2518#include <libkcal/syncdefines.h>
2517 2519
2518KABC::Addressee KABCore::getLastSyncAddressee() 2520KABC::Addressee KABCore::getLastSyncAddressee()
2519{ 2521{
2520 Addressee lse; 2522 Addressee lse;
2521 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2523 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2522 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2524 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2523 if (lse.isEmpty()) { 2525 if (lse.isEmpty()) {
2524 lse.setUid( "last-syncEvent-"+mCurrentSyncDevice ); 2526 lse.setUid( "last-syncEvent-"+mCurrentSyncDevice );
2525 QString sum = ""; 2527 QString sum = "";
2526 if ( KABPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 2528 if ( KABPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
2527 sum = "E: "; 2529 sum = "E: ";
2528 lse.setFamilyName(sum+mCurrentSyncDevice + i18n(" - sync event")); 2530 lse.setFamilyName(sum+mCurrentSyncDevice + i18n(" - sync event"));
2529 lse.setRevision( mLastAddressbookSync ); 2531 lse.setRevision( mLastAddressbookSync );
2530 lse.setCategories( i18n("SyncEvent") ); 2532 lse.setCategories( i18n("SyncEvent") );
2531 mAddressBook->insertAddressee( lse ); 2533 mAddressBook->insertAddressee( lse );
2532 } 2534 }
2533 return lse; 2535 return lse;
2534} 2536}
2535 2537
2536bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2538bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2537{ 2539{
2538 bool syncOK = true; 2540 bool syncOK = true;
2539 int addedAddressee = 0; 2541 int addedAddressee = 0;
2540 int addedAddresseeR = 0; 2542 int addedAddresseeR = 0;
2541 int deletedAddresseeR = 0; 2543 int deletedAddresseeR = 0;
2542 int deletedAddresseeL = 0; 2544 int deletedAddresseeL = 0;
2543 int changedLocal = 0; 2545 int changedLocal = 0;
2544 int changedRemote = 0; 2546 int changedRemote = 0;
2545 //QPtrList<Addressee> el = local->rawAddressees(); 2547 //QPtrList<Addressee> el = local->rawAddressees();
2546 Addressee addresseeR; 2548 Addressee addresseeR;
2547 QString uid; 2549 QString uid;
2548 int take; 2550 int take;
2549 Addressee addresseeL; 2551 Addressee addresseeL;
2550 Addressee addresseeRSync; 2552 Addressee addresseeRSync;
2551 Addressee addresseeLSync; 2553 Addressee addresseeLSync;
2552 KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2554 KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2553 KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2555 KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2554 bool fullDateRange = false; 2556 bool fullDateRange = false;
2555 local->resetTempSyncStat(); 2557 local->resetTempSyncStat();
2556 mLastAddressbookSync = QDateTime::currentDateTime(); 2558 mLastAddressbookSync = QDateTime::currentDateTime();
2557 QDateTime modifiedCalendar = mLastAddressbookSync;; 2559 QDateTime modifiedCalendar = mLastAddressbookSync;;
2558 addresseeLSync = getLastSyncAddressee(); 2560 addresseeLSync = getLastSyncAddressee();
2559 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2561 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2560 if ( !addresseeR.isEmpty() ) { 2562 if ( !addresseeR.isEmpty() ) {
2561 addresseeRSync = addresseeR; 2563 addresseeRSync = addresseeR;
2562 remote->removeAddressee(addresseeR ); 2564 remote->removeAddressee(addresseeR );
2563 2565
2564 } else { 2566 } else {
2565 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2567 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2566 addresseeRSync = addresseeLSync ; 2568 addresseeRSync = addresseeLSync ;
2567 } else { 2569 } else {
2568 fullDateRange = true; 2570 fullDateRange = true;
2569 Addressee newAdd; 2571 Addressee newAdd;
2570 addresseeRSync = newAdd; 2572 addresseeRSync = newAdd;
2571 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2573 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2572 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2574 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2573 addresseeRSync.setRevision( mLastAddressbookSync ); 2575 addresseeRSync.setRevision( mLastAddressbookSync );
2574 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2576 addresseeRSync.setCategories( i18n("SyncAddressee") );
2575 } 2577 }
2576 } 2578 }
2577 if ( addresseeLSync.revision() == mLastAddressbookSync ) 2579 if ( addresseeLSync.revision() == mLastAddressbookSync )
2578 fullDateRange = true; 2580 fullDateRange = true;
2579 if ( ! fullDateRange ) { 2581 if ( ! fullDateRange ) {
2580 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2582 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2581 2583
2582 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2584 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2583 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2585 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2584 fullDateRange = true; 2586 fullDateRange = true;
2585 } 2587 }
2586 } 2588 }
2587 if ( fullDateRange ) 2589 if ( fullDateRange )
2588 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2590 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2589 else 2591 else
2590 mLastAddressbookSync = addresseeLSync.revision(); 2592 mLastAddressbookSync = addresseeLSync.revision();
2591 // for resyncing if own file has changed 2593 // for resyncing if own file has changed
2592 // PENDING fixme later when implemented 2594 // PENDING fixme later when implemented
2593#if 0 2595#if 0
2594 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2596 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2595 mLastAddressbookSync = loadedFileVersion; 2597 mLastAddressbookSync = loadedFileVersion;
2596 qDebug("setting mLastAddressbookSync "); 2598 qDebug("setting mLastAddressbookSync ");
2597 } 2599 }
2598#endif 2600#endif
2599 2601
2600 #if 0
2601 //qDebug("*************************** "); 2602 //qDebug("*************************** ");
2602 qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2603 qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2603 QPtrList<Incidence> er = remote->rawIncidences(); 2604 QStringList er = remote->uidList();
2604 Incidence* inR = er.first(); 2605 Addressee inR ;//= er.first();
2605 Incidence* inL; 2606 Addressee inL;
2606 QProgressBar bar( er.count(),0 ); 2607 QProgressBar bar( er.count(),0 );
2607 bar.setCaption (i18n("Syncing - close to abort!") ); 2608 bar.setCaption (i18n("Syncing - close to abort!") );
2608 2609
2609 int w = 300; 2610 int w = 300;
2610 if ( QApplication::desktop()->width() < 320 ) 2611 if ( QApplication::desktop()->width() < 320 )
2611 w = 220; 2612 w = 220;
2612 int h = bar.sizeHint().height() ; 2613 int h = bar.sizeHint().height() ;
2613 int dw = QApplication::desktop()->width(); 2614 int dw = QApplication::desktop()->width();
2614 int dh = QApplication::desktop()->height(); 2615 int dh = QApplication::desktop()->height();
2615 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2616 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2616 bar.show(); 2617 bar.show();
2617 int modulo = (er.count()/10)+1; 2618 int modulo = (er.count()/10)+1;
2618 int incCounter = 0; 2619 int incCounter = 0;
2619 while ( inR ) { 2620 while ( incCounter < er.count()) {
2620 if ( ! bar.isVisible() ) 2621 if ( ! bar.isVisible() )
2621 return false; 2622 return false;
2622 if ( incCounter % modulo == 0 ) 2623 if ( incCounter % modulo == 0 )
2623 bar.setProgress( incCounter ); 2624 bar.setProgress( incCounter );
2624 ++incCounter; 2625 uid = er[ incCounter ];
2625 uid = inR->uid();
2626 bool skipIncidence = false; 2626 bool skipIncidence = false;
2627 if ( uid.left(15) == QString("last-syncAddressee-") ) 2627 if ( uid.left(20) == QString("last-syncAddressee-") )
2628 skipIncidence = true; 2628 skipIncidence = true;
2629 QString idS; 2629 QString idS;
2630 qApp->processAddressees(); 2630 qApp->processEvents();
2631 if ( !skipIncidence ) { 2631 if ( !skipIncidence ) {
2632 inL = local->incidence( uid ); 2632 inL = local->findByUid( uid );
2633 if ( inL ) { // maybe conflict - same uid in both calendars 2633 inR = remote->findByUid( uid );
2634 int maxrev = inL->revision(); 2634 //inL.setResource( 0 );
2635 if ( maxrev < inR->revision() ) 2635 //inR.setResource( 0 );
2636 maxrev = inR->revision(); 2636 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2637 if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) { 2637 // pending if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) {
2638 //qDebug("take %d %s ", take, inL->summary().latin1()); 2638 if ( true ) {
2639 //qDebug("take %d %s ", take, inL.summary().latin1());
2639 if ( take == 3 ) 2640 if ( take == 3 )
2640 return false; 2641 return false;
2641 if ( take == 1 ) {// take local 2642 if ( take == 1 ) {// take local
2642 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2643 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2643 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 2644 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2645 local->insertAddressee( inL );
2646 }
2644 else 2647 else
2645 idS = inR->IDStr(); 2648 idS = inR.IDStr();
2646 remote->deleteIncidence( inR ); 2649 remote->removeAddressee( inR );
2647 if ( inL->revision() < maxrev ) 2650 inR = inL;
2648 inL->setRevision( maxrev ); 2651 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2649 inR = inL->clone();
2650 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2651 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 2652 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
2652 inR->setIDStr( idS ); 2653 inR.setIDStr( idS );
2653 remote->addIncidence( inR ); 2654 inR.setResource( 0 );
2655 remote->insertAddressee( inR );
2654 ++changedRemote; 2656 ++changedRemote;
2655 } else { 2657 } else {
2656 if ( inR->revision() < maxrev ) 2658 idS = inL.IDStr();
2657 inR->setRevision( maxrev ); 2659 local->removeAddressee( inL );
2658 idS = inL->IDStr(); 2660 inL = inR;
2659 local->deleteIncidence( inL ); 2661 inL.setIDStr( idS );
2660 inL = inR->clone(); 2662 inL.setResource( 0 );
2661 inL->setIDStr( idS ); 2663 local->insertAddressee( inL );
2662 local->addIncidence( inL );
2663 ++changedLocal; 2664 ++changedLocal;
2664 } 2665 }
2665 } 2666 }
2666 } else { // no conflict 2667 } else { // no conflict
2667 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2668 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2668 QString des = addresseeLSync->description(); 2669 QString des = addresseeLSync.note();
2669 QString pref = "e"; 2670 QString pref = "a";
2670 if ( inR->type() == "Todo" ) 2671 if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2671 pref = "t"; 2672 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2672 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2673 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2674 //remote->deleteIncidence( inR );
2675 ++deletedAddresseeR; 2673 ++deletedAddresseeR;
2676 } else { 2674 } else {
2677 inR->setLastModified( modifiedCalendar ); 2675 inR.setRevision( modifiedCalendar );
2678 inL = inR->clone(); 2676 remote->insertAddressee( inR );
2679 local->addIncidence( inL ); 2677 inL = inR;
2678 inL.setResource( 0 );
2679 local->insertAddressee( inL );
2680 ++addedAddressee; 2680 ++addedAddressee;
2681 } 2681 }
2682 } else { 2682 } else {
2683 if ( inR->lastModified() > mLastAddressbookSync || mode == 5 ) { 2683 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2684 inR->setLastModified( modifiedCalendar ); 2684 inR.setRevision( modifiedCalendar );
2685 local->addIncidence( inR->clone() ); 2685 remote->insertAddressee( inR );
2686 inR.setResource( 0 );
2687 local->insertAddressee( inR );
2686 ++addedAddressee; 2688 ++addedAddressee;
2687 } else { 2689 } else {
2688 checkExternSyncAddressee(addresseeRSyncSharp, inR); 2690 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2689 remote->deleteIncidence( inR ); 2691 remote->removeAddressee( inR );
2690 ++deletedAddresseeR; 2692 ++deletedAddresseeR;
2691 } 2693 }
2692 } 2694 }
2693 } 2695 }
2694 } 2696 }
2695 inR = er.next(); 2697 ++incCounter;
2696 } 2698 }
2697 QPtrList<Incidence> el = local->rawIncidences(); 2699 er.clear();
2698 inL = el.first(); 2700 QStringList el = remote->uidList();
2699 modulo = (el.count()/10)+1; 2701 modulo = (el.count()/10)+1;
2700 bar.setCaption (i18n("Add / remove addressees") ); 2702 bar.setCaption (i18n("Add / remove addressees") );
2701 bar.setTotalSteps ( el.count() ) ; 2703 bar.setTotalSteps ( el.count() ) ;
2702 bar.show(); 2704 bar.show();
2703 incCounter = 0; 2705 incCounter = 0;
2704 2706 while ( incCounter < el.count()) {
2705 while ( inL ) {
2706 2707
2707 qApp->processAddressees(); 2708 qApp->processEvents();
2708 if ( ! bar.isVisible() ) 2709 if ( ! bar.isVisible() )
2709 return false; 2710 return false;
2710 if ( incCounter % modulo == 0 ) 2711 if ( incCounter % modulo == 0 )
2711 bar.setProgress( incCounter ); 2712 bar.setProgress( incCounter );
2712 ++incCounter; 2713 uid = el[ incCounter ];
2713 uid = inL->uid();
2714 bool skipIncidence = false; 2714 bool skipIncidence = false;
2715 if ( uid.left(15) == QString("last-syncAddressee-") ) 2715 if ( uid.left(20) == QString("last-syncAddressee-") )
2716 skipIncidence = true; 2716 skipIncidence = true;
2717 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 2717 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2718 skipIncidence = true; 2718 skipIncidence = true;
2719 if ( !skipIncidence ) { 2719 if ( !skipIncidence ) {
2720 inR = remote->incidence( uid ); 2720 inL = local->findByUid( uid );
2721 if ( ! inR ) { 2721 inR = remote->findByUid( uid );
2722 if ( inR.isEmpty() ) {
2722 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2723 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2723 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2724 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2724 checkExternSyncAddressee(addresseeLSyncSharp, inL); 2725 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2725 local->deleteIncidence( inL ); 2726 local->removeAddressee( inL );
2726 ++deletedAddresseeL; 2727 ++deletedAddresseeL;
2727 } else { 2728 } else {
2728 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 2729 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2729 inL->removeID(mCurrentSyncDevice ); 2730 inL.removeID(mCurrentSyncDevice );
2730 ++addedAddresseeR; 2731 ++addedAddresseeR;
2731 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 2732 //qDebug("remote added Incidence %s ", inL.summary().latin1());
2732 inL->setLastModified( modifiedCalendar ); 2733 inL.setRevision( modifiedCalendar );
2733 inR = inL->clone(); 2734 local->insertAddressee( inL );
2734 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2735 inR = inL;
2735 remote->addIncidence( inR ); 2736 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2737 inR.setResource( 0 );
2738 remote->insertAddressee( inR );
2736 } 2739 }
2737 } 2740 }
2738 } else { 2741 } else {
2739 if ( inL->lastModified() < mLastAddressbookSync && mode != 4 ) { 2742 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2740 checkExternSyncAddressee(addresseeLSyncSharp, inL); 2743 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2741 local->deleteIncidence( inL ); 2744 local->removeAddressee( inL );
2742 ++deletedAddresseeL; 2745 ++deletedAddresseeL;
2743 } else { 2746 } else {
2744 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 2747 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2745 ++addedAddresseeR; 2748 ++addedAddresseeR;
2746 inL->setLastModified( modifiedCalendar ); 2749 inL.setRevision( modifiedCalendar );
2747 remote->addIncidence( inL->clone() ); 2750 local->insertAddressee( inL );
2751 inR = inL;
2752 inR.setResource( 0 );
2753 remote->insertAddressee( inR );
2748 } 2754 }
2749 } 2755 }
2750 } 2756 }
2751 } 2757 }
2752 } 2758 }
2753 inL = el.next(); 2759 ++incCounter;
2754 } 2760 }
2761 el.clear();
2755 int delFut = 0; 2762 int delFut = 0;
2756 if ( KOPrefs::instance()->mWriteBackInFuture ) { 2763
2757 er = remote->rawIncidences(); 2764 #if 0
2758 inR = er.first(); 2765
2759 QDateTime dt;
2760 QDateTime cur = QDateTime::currentDateTime();
2761 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 );
2762 while ( inR ) {
2763 if ( inR->type() == "Todo" ) {
2764 Todo * t = (Todo*)inR;
2765 if ( t->hasDueDate() )
2766 dt = t->dtDue();
2767 else
2768 dt = cur.addSecs( 62 );
2769 }
2770 else if (inR->type() == "Addressee" ) {
2771 bool ok;
2772 dt = inR->getNextOccurence( cur, &ok );
2773 if ( !ok )
2774 dt = cur.addSecs( -62 );
2775 }
2776 else
2777 dt = inR->dtStart();
2778 if ( dt < cur || dt > end ) {
2779 remote->deleteIncidence( inR );
2780 ++delFut;
2781 }
2782 inR = er.next();
2783 }
2784 }
2785 bar.hide(); 2766 bar.hide();
2786 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2767 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2787 addresseeLSync->setReadOnly( false ); 2768 addresseeLSync.setRevision( mLastAddressbookSync );
2788 addresseeLSync->setDtStart( mLastAddressbookSync ); 2769 addresseeRSync.setRevision( mLastAddressbookSync );
2789 addresseeRSync->setDtStart( mLastAddressbookSync ); 2770 addresseeRSync.setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
2790 addresseeLSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) ); 2771 addresseeLSync.setLocation(i18n("Local from: ") + mCurrentSyncName );
2791 addresseeRSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) ); 2772 addresseeLSync.setReadOnly( true );
2792 addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
2793 addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
2794 addresseeLSync->setReadOnly( true );
2795 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2773 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2796 remote->addAddressee( addresseeRSync ); 2774 remote->addAddressee( addresseeRSync );
2797 QString mes; 2775 QString mes;
2798 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2776 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2799 QString delmess; 2777 QString delmess;
2800 if ( delFut ) { 2778 if ( delFut ) {
2801 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); 2779 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture );
2802 mes += delmess; 2780 mes += delmess;
2803 } 2781 }
2804 if ( KOPrefs::instance()->mShowSyncSummary ) { 2782 if ( KOPrefs::instance()->mShowSyncSummary ) {
2805 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 2783 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
2806 } 2784 }
2807 qDebug( mes ); 2785 qDebug( mes );
2808 mCalendar->checkAlarmForIncidence( 0, true ); 2786 mCalendar->checkAlarmForIncidence( 0, true );
2809 return syncOK; 2787 return syncOK;
2810#endif 2788#endif
2811 return false; 2789 return false;
2812} 2790}
2813bool KABCore::syncAB(QString filename, int mode) 2791bool KABCore::syncAB(QString filename, int mode)
2814{ 2792{
2815 2793
2816 //pending prepare addresseeview for output 2794 //pending prepare addresseeview for output
2817 //pending detect, if remote file has REV field. if not switch to external sync 2795 //pending detect, if remote file has REV field. if not switch to external sync
2818 mGlobalSyncMode = SYNC_MODE_NORMAL; 2796 mGlobalSyncMode = SYNC_MODE_NORMAL;
2819 AddressBook abLocal(filename,"syncContact"); 2797 AddressBook abLocal(filename,"syncContact");
2820 bool syncOK = false; 2798 bool syncOK = false;
2821 if ( abLocal.load() ) { 2799 if ( abLocal.load() ) {
2822 qDebug("AB loaded %s mode %d",filename.latin1(), mode ); 2800 qDebug("AB loaded %s mode %d",filename.latin1(), mode );
2823 AddressBook::Iterator it; 2801 AddressBook::Iterator it;
2824 QStringList vcards; 2802 QStringList vcards;
2825 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2803 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2826 qDebug("Name %s ", (*it).familyName().latin1()); 2804 qDebug("Name %s ", (*it).familyName().latin1());
2827 } 2805 }
2828 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2806 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2829 if ( syncOK ) { 2807 if ( syncOK ) {
2830 if ( KABPrefs::instance()->mWriteBackFile ) 2808 if ( KABPrefs::instance()->mWriteBackFile )
2831 { 2809 {
2832 qDebug("saving remote AB "); 2810 qDebug("saving remote AB ");
2833 abLocal.saveAB(); 2811 abLocal.saveAB();
2834 } 2812 }
2835 } 2813 }
2836 setModified(); 2814 setModified();
2837 2815
2838 } 2816 }
2839 if ( syncOK ) 2817 if ( syncOK )
2840 mViewManager->refreshView(); 2818 mViewManager->refreshView();
2841 return syncOK; 2819 return syncOK;
2842#if 0 2820#if 0
2843 2821
2844 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 2822 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2845 getEventViewerDialog()->setSyncMode( true ); 2823 getEventViewerDialog()->setSyncMode( true );
2846 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 2824 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
2847 getEventViewerDialog()->setSyncMode( false ); 2825 getEventViewerDialog()->setSyncMode( false );
2848 if ( syncOK ) { 2826 if ( syncOK ) {
2849 if ( KOPrefs::instance()->mWriteBackFile ) 2827 if ( KOPrefs::instance()->mWriteBackFile )
2850 { 2828 {
2851 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 2829 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2852 storage->save(); 2830 storage->save();
2853 } 2831 }
2854 } 2832 }
2855 setModified(); 2833 setModified();
2856 } 2834 }
2857 2835
2858#endif 2836#endif
2859} 2837}
2860 2838
2861 2839
2862void KABCore::confSync() 2840void KABCore::confSync()
2863{ 2841{
2864 static KSyncPrefsDialog* sp = 0; 2842 static KSyncPrefsDialog* sp = 0;
2865 if ( ! sp ) { 2843 if ( ! sp ) {
2866 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 2844 sp = new KSyncPrefsDialog( this, "syncprefs", true );
2867 } 2845 }
2868 sp->usrReadConfig(); 2846 sp->usrReadConfig();
2869#ifndef DESKTOP_VERSION 2847#ifndef DESKTOP_VERSION
2870 sp->showMaximized(); 2848 sp->showMaximized();
2871#else 2849#else
2872 sp->show(); 2850 sp->show();
2873#endif 2851#endif
2874 sp->exec(); 2852 sp->exec();
2875 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 2853 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
2876 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 2854 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
2877 fillSyncMenu(); 2855 fillSyncMenu();
2878} 2856}
2879void KABCore::syncSharp() 2857void KABCore::syncSharp()
2880{ 2858{
2881 if ( mModified ) 2859 if ( mModified )
2882 save(); 2860 save();
2883 qDebug("pending syncSharp() "); 2861 qDebug("pending syncSharp() ");
2884 //mView->syncSharp(); 2862 //mView->syncSharp();
2885 setModified(); 2863 setModified();
2886 2864
2887} 2865}
2888void KABCore::syncPhone() 2866void KABCore::syncPhone()
2889{ 2867{
2890 if ( mModified ) 2868 if ( mModified )
2891 save(); 2869 save();
2892 qDebug("pending syncPhone(); "); 2870 qDebug("pending syncPhone(); ");
2893 //mView->syncPhone(); 2871 //mView->syncPhone();
2894 setModified(); 2872 setModified();
2895 2873
2896} 2874}