summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp27
-rw-r--r--kabc/addressbook.h3
-rw-r--r--kabc/addressee.cpp6
-rw-r--r--kabc/plugins/qtopia/qtopiaconverter.cpp2
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp79
-rw-r--r--kaddressbook/kabcore.cpp58
-rw-r--r--korganizer/calendarview.cpp44
7 files changed, 153 insertions, 66 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 86dc7c2..17b9ba2 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -363,485 +363,500 @@ bool AddressBook::save( Ticket *ticket )
363 kdDebug(5700) << "AddressBook::save()"<< endl; 363 kdDebug(5700) << "AddressBook::save()"<< endl;
364 364
365 if ( ticket->resource() ) { 365 if ( ticket->resource() ) {
366 deleteRemovedAddressees(); 366 deleteRemovedAddressees();
367 return ticket->resource()->save( ticket ); 367 return ticket->resource()->save( ticket );
368 } 368 }
369 369
370 return false; 370 return false;
371} 371}
372bool AddressBook::saveAB() 372bool AddressBook::saveAB()
373{ 373{
374 bool ok = true; 374 bool ok = true;
375 375
376 deleteRemovedAddressees(); 376 deleteRemovedAddressees();
377 Iterator ait; 377 Iterator ait;
378 for ( ait = begin(); ait != end(); ++ait ) { 378 for ( ait = begin(); ait != end(); ++ait ) {
379 if ( !(*ait).IDStr().isEmpty() ) { 379 if ( !(*ait).IDStr().isEmpty() ) {
380 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 380 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
381 } 381 }
382 } 382 }
383 KRES::Manager<Resource>::ActiveIterator it; 383 KRES::Manager<Resource>::ActiveIterator it;
384 KRES::Manager<Resource> *manager = d->mManager; 384 KRES::Manager<Resource> *manager = d->mManager;
385 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 385 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
386 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 386 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
387 Ticket *ticket = requestSaveTicket( *it ); 387 Ticket *ticket = requestSaveTicket( *it );
388// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 388// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
389 if ( !ticket ) { 389 if ( !ticket ) {
390 error( i18n( "Unable to save to resource '%1'. It is locked." ) 390 error( i18n( "Unable to save to resource '%1'. It is locked." )
391 .arg( (*it)->resourceName() ) ); 391 .arg( (*it)->resourceName() ) );
392 return false; 392 return false;
393 } 393 }
394 394
395 //if ( !save( ticket ) ) 395 //if ( !save( ticket ) )
396 if ( ticket->resource() ) { 396 if ( ticket->resource() ) {
397 if ( ! ticket->resource()->save( ticket ) ) 397 if ( ! ticket->resource()->save( ticket ) )
398 ok = false; 398 ok = false;
399 } else 399 } else
400 ok = false; 400 ok = false;
401 401
402 } 402 }
403 } 403 }
404 return ok; 404 return ok;
405} 405}
406 406
407AddressBook::Iterator AddressBook::begin() 407AddressBook::Iterator AddressBook::begin()
408{ 408{
409 Iterator it = Iterator(); 409 Iterator it = Iterator();
410 it.d->mIt = d->mAddressees.begin(); 410 it.d->mIt = d->mAddressees.begin();
411 return it; 411 return it;
412} 412}
413 413
414AddressBook::ConstIterator AddressBook::begin() const 414AddressBook::ConstIterator AddressBook::begin() const
415{ 415{
416 ConstIterator it = ConstIterator(); 416 ConstIterator it = ConstIterator();
417 it.d->mIt = d->mAddressees.begin(); 417 it.d->mIt = d->mAddressees.begin();
418 return it; 418 return it;
419} 419}
420 420
421AddressBook::Iterator AddressBook::end() 421AddressBook::Iterator AddressBook::end()
422{ 422{
423 Iterator it = Iterator(); 423 Iterator it = Iterator();
424 it.d->mIt = d->mAddressees.end(); 424 it.d->mIt = d->mAddressees.end();
425 return it; 425 return it;
426} 426}
427 427
428AddressBook::ConstIterator AddressBook::end() const 428AddressBook::ConstIterator AddressBook::end() const
429{ 429{
430 ConstIterator it = ConstIterator(); 430 ConstIterator it = ConstIterator();
431 it.d->mIt = d->mAddressees.end(); 431 it.d->mIt = d->mAddressees.end();
432 return it; 432 return it;
433} 433}
434 434
435void AddressBook::clear() 435void AddressBook::clear()
436{ 436{
437 d->mAddressees.clear(); 437 d->mAddressees.clear();
438} 438}
439 439
440Ticket *AddressBook::requestSaveTicket( Resource *resource ) 440Ticket *AddressBook::requestSaveTicket( Resource *resource )
441{ 441{
442 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 442 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
443 443
444 if ( !resource ) 444 if ( !resource )
445 { 445 {
446 qDebug("AddressBook::requestSaveTicket no resource" ); 446 qDebug("AddressBook::requestSaveTicket no resource" );
447 resource = standardResource(); 447 resource = standardResource();
448 } 448 }
449 449
450 KRES::Manager<Resource>::ActiveIterator it; 450 KRES::Manager<Resource>::ActiveIterator it;
451 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 451 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
452 if ( (*it) == resource ) { 452 if ( (*it) == resource ) {
453 if ( (*it)->readOnly() || !(*it)->isOpen() ) 453 if ( (*it)->readOnly() || !(*it)->isOpen() )
454 return 0; 454 return 0;
455 else 455 else
456 return (*it)->requestSaveTicket(); 456 return (*it)->requestSaveTicket();
457 } 457 }
458 } 458 }
459 459
460 return 0; 460 return 0;
461} 461}
462 462
463void AddressBook::insertAddressee( const Addressee &a, bool setRev ) 463void AddressBook::insertAddressee( const Addressee &a, bool setRev )
464{ 464{
465 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 465 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
466 //qDebug("block insert "); 466 //qDebug("block insert ");
467 return; 467 return;
468 } 468 }
469 //qDebug("inserting.... %s ",a.uid().latin1() ); 469 //qDebug("inserting.... %s ",a.uid().latin1() );
470 bool found = false; 470 bool found = false;
471 Addressee::List::Iterator it; 471 Addressee::List::Iterator it;
472 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 472 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
473 if ( a.uid() == (*it).uid() ) { 473 if ( a.uid() == (*it).uid() ) {
474 474
475 bool changed = false; 475 bool changed = false;
476 Addressee addr = a; 476 Addressee addr = a;
477 if ( addr != (*it) ) 477 if ( addr != (*it) )
478 changed = true; 478 changed = true;
479 479
480 (*it) = a; 480 (*it) = a;
481 if ( (*it).resource() == 0 ) 481 if ( (*it).resource() == 0 )
482 (*it).setResource( standardResource() ); 482 (*it).setResource( standardResource() );
483 483
484 if ( changed ) { 484 if ( changed ) {
485 if ( setRev ) { 485 if ( setRev ) {
486 486
487 // get rid of micro seconds 487 // get rid of micro seconds
488 QDateTime dt = QDateTime::currentDateTime(); 488 QDateTime dt = QDateTime::currentDateTime();
489 QTime t = dt.time(); 489 QTime t = dt.time();
490 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 490 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
491 (*it).setRevision( dt ); 491 (*it).setRevision( dt );
492 } 492 }
493 (*it).setChanged( true ); 493 (*it).setChanged( true );
494 } 494 }
495 495
496 found = true; 496 found = true;
497 } else { 497 } else {
498 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 498 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
499 QString name = (*it).uid().mid( 19 ); 499 QString name = (*it).uid().mid( 19 );
500 Addressee b = a; 500 Addressee b = a;
501 QString id = b.getID( name ); 501 QString id = b.getID( name );
502 if ( ! id.isEmpty() ) { 502 if ( ! id.isEmpty() ) {
503 QString des = (*it).note(); 503 QString des = (*it).note();
504 int startN; 504 int startN;
505 if( (startN = des.find( id ) ) >= 0 ) { 505 if( (startN = des.find( id ) ) >= 0 ) {
506 int endN = des.find( ",", startN+1 ); 506 int endN = des.find( ",", startN+1 );
507 des = des.left( startN ) + des.mid( endN+1 ); 507 des = des.left( startN ) + des.mid( endN+1 );
508 (*it).setNote( des ); 508 (*it).setNote( des );
509 } 509 }
510 } 510 }
511 } 511 }
512 } 512 }
513 } 513 }
514 if ( found ) 514 if ( found )
515 return; 515 return;
516 d->mAddressees.append( a ); 516 d->mAddressees.append( a );
517 Addressee& addr = d->mAddressees.last(); 517 Addressee& addr = d->mAddressees.last();
518 if ( addr.resource() == 0 ) 518 if ( addr.resource() == 0 )
519 addr.setResource( standardResource() ); 519 addr.setResource( standardResource() );
520 520
521 addr.setChanged( true ); 521 addr.setChanged( true );
522} 522}
523 523
524void AddressBook::removeAddressee( const Addressee &a ) 524void AddressBook::removeAddressee( const Addressee &a )
525{ 525{
526 Iterator it; 526 Iterator it;
527 Iterator it2; 527 Iterator it2;
528 bool found = false; 528 bool found = false;
529 for ( it = begin(); it != end(); ++it ) { 529 for ( it = begin(); it != end(); ++it ) {
530 if ( a.uid() == (*it).uid() ) { 530 if ( a.uid() == (*it).uid() ) {
531 found = true; 531 found = true;
532 it2 = it; 532 it2 = it;
533 } else { 533 } else {
534 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 534 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
535 QString name = (*it).uid().mid( 19 ); 535 QString name = (*it).uid().mid( 19 );
536 Addressee b = a; 536 Addressee b = a;
537 QString id = b.getID( name ); 537 QString id = b.getID( name );
538 if ( ! id.isEmpty() ) { 538 if ( ! id.isEmpty() ) {
539 QString des = (*it).note(); 539 QString des = (*it).note();
540 if( des.find( id ) < 0 ) { 540 if( des.find( id ) < 0 ) {
541 des += id + ","; 541 des += id + ",";
542 (*it).setNote( des ); 542 (*it).setNote( des );
543 } 543 }
544 } 544 }
545 } 545 }
546 546
547 } 547 }
548 } 548 }
549 549
550 if ( found ) 550 if ( found )
551 removeAddressee( it2 ); 551 removeAddressee( it2 );
552 552
553} 553}
554 554
555void AddressBook::removeDeletedAddressees() 555void AddressBook::removeSyncAddressees( bool removeDeleted )
556{ 556{
557 deleteRemovedAddressees();
558 Iterator it = begin(); 557 Iterator it = begin();
559 Iterator it2 ; 558 Iterator it2 ;
560 QDateTime dt ( QDate( 2004,1,1) ); 559 QDateTime dt ( QDate( 2004,1,1) );
561 while ( it != end() ) { 560 while ( it != end() ) {
562 (*it).setRevision( dt ); 561 (*it).setRevision( dt );
563 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 562 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
564 (*it).setIDStr(""); 563 (*it).setIDStr("");
565 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 564 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
566 it2 = it; 565 it2 = it;
567 //qDebug("removing %s ",(*it).uid().latin1() ); 566 //qDebug("removing %s ",(*it).uid().latin1() );
568 ++it; 567 ++it;
569 removeAddressee( it2 ); 568 removeAddressee( it2 );
570 } else { 569 } else {
571 //qDebug("skipping %s ",(*it).uid().latin1() ); 570 //qDebug("skipping %s ",(*it).uid().latin1() );
572 ++it; 571 ++it;
573 } 572 }
574 } 573 }
575 deleteRemovedAddressees(); 574 deleteRemovedAddressees();
576} 575}
577 576
578void AddressBook::removeAddressee( const Iterator &it ) 577void AddressBook::removeAddressee( const Iterator &it )
579{ 578{
580 d->mRemovedAddressees.append( (*it) ); 579 d->mRemovedAddressees.append( (*it) );
581 d->mAddressees.remove( it.d->mIt ); 580 d->mAddressees.remove( it.d->mIt );
582} 581}
583 582
584AddressBook::Iterator AddressBook::find( const Addressee &a ) 583AddressBook::Iterator AddressBook::find( const Addressee &a )
585{ 584{
586 Iterator it; 585 Iterator it;
587 for ( it = begin(); it != end(); ++it ) { 586 for ( it = begin(); it != end(); ++it ) {
588 if ( a.uid() == (*it).uid() ) { 587 if ( a.uid() == (*it).uid() ) {
589 return it; 588 return it;
590 } 589 }
591 } 590 }
592 return end(); 591 return end();
593} 592}
594 593
595Addressee AddressBook::findByUid( const QString &uid ) 594Addressee AddressBook::findByUid( const QString &uid )
596{ 595{
597 Iterator it; 596 Iterator it;
598 for ( it = begin(); it != end(); ++it ) { 597 for ( it = begin(); it != end(); ++it ) {
599 if ( uid == (*it).uid() ) { 598 if ( uid == (*it).uid() ) {
600 return *it; 599 return *it;
601 } 600 }
602 } 601 }
603 return Addressee(); 602 return Addressee();
604} 603}
605void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) 604void AddressBook::preExternSync( AddressBook* aBook, const QString& csd )
606{ 605{
607 qDebug("AddressBook::preExternSync "); 606 qDebug("AddressBook::preExternSync ");
608 AddressBook::Iterator it; 607 AddressBook::Iterator it;
609 for ( it = begin(); it != end(); ++it ) { 608 for ( it = begin(); it != end(); ++it ) {
610 (*it).setID( csd, (*it).externalUID() ); 609 (*it).setID( csd, (*it).externalUID() );
611 (*it).computeCsum( csd ); 610 (*it).computeCsum( csd );
612 } 611 }
613 mergeAB( aBook ,csd ); 612 mergeAB( aBook ,csd );
614} 613}
615void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 614void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
616{ 615{
617 qDebug("AddressBook::postExternSync "); 616 qDebug("AddressBook::postExternSync ");
618 AddressBook::Iterator it; 617 AddressBook::Iterator it;
619 for ( it = begin(); it != end(); ++it ) { 618 for ( it = begin(); it != end(); ++it ) {
619 qDebug("check uid %s ", (*it).uid().latin1() );
620 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 620 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
621 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 621 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
622 Addressee ad = aBook->findByUid( ( (*it).uid() )); 622 Addressee ad = aBook->findByUid( ( (*it).uid() ));
623 if ( ad.isEmpty() ) { 623 if ( ad.isEmpty() ) {
624 qDebug("ERROR ad empty "); 624 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
625 } else { 625 } else {
626 (*it).computeCsum( csd ); 626 (*it).computeCsum( csd );
627 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 627 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
628 ad.setID( csd, (*it).externalUID() ); 628 ad.setID( csd, (*it).externalUID() );
629 ad.setCsum( csd, (*it).getCsum( csd ) ); 629 ad.setCsum( csd, (*it).getCsum( csd ) );
630 aBook->insertAddressee( ad ); 630 aBook->insertAddressee( ad );
631 } 631 }
632 } 632 }
633 } 633 }
634} 634}
635 635
636 636bool AddressBook::containsExternalUid( const QString& uid )
637{
638 Iterator it;
639 for ( it = begin(); it != end(); ++it ) {
640 if ( uid == (*it).externalUID( ) )
641 return true;
642 }
643 return false;
644}
637Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 645Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
638{ 646{
639 Iterator it; 647 Iterator it;
640 for ( it = begin(); it != end(); ++it ) { 648 for ( it = begin(); it != end(); ++it ) {
641 if ( uid == (*it).getID( profile ) ) 649 if ( uid == (*it).getID( profile ) )
642 return (*it); 650 return (*it);
643 } 651 }
644 return Addressee(); 652 return Addressee();
645} 653}
646void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) 654void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
647{ 655{
648 Iterator it; 656 Iterator it;
649 Addressee ad; 657 Addressee ad;
650 for ( it = begin(); it != end(); ++it ) { 658 for ( it = begin(); it != end(); ++it ) {
651 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 659 ad = aBook->findByExternUid( (*it).externalUID(), profile );
652 if ( !ad.isEmpty() ) { 660 if ( !ad.isEmpty() ) {
653 (*it).mergeContact( ad ); 661 (*it).mergeContact( ad );
654 } 662 }
655 } 663 }
664#if 0
665 // test only
666 for ( it = begin(); it != end(); ++it ) {
667
668 qDebug("uid %s ", (*it).uid().latin1());
669 }
670#endif
656} 671}
657 672
658#if 0 673#if 0
659Addressee::List AddressBook::getExternLastSyncAddressees() 674Addressee::List AddressBook::getExternLastSyncAddressees()
660{ 675{
661 Addressee::List results; 676 Addressee::List results;
662 677
663 Iterator it; 678 Iterator it;
664 for ( it = begin(); it != end(); ++it ) { 679 for ( it = begin(); it != end(); ++it ) {
665 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 680 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
666 if ( (*it).familyName().left(4) == "!E: " ) 681 if ( (*it).familyName().left(4) == "!E: " )
667 results.append( *it ); 682 results.append( *it );
668 } 683 }
669 } 684 }
670 685
671 return results; 686 return results;
672} 687}
673#endif 688#endif
674void AddressBook::resetTempSyncStat() 689void AddressBook::resetTempSyncStat()
675{ 690{
676 Iterator it; 691 Iterator it;
677 for ( it = begin(); it != end(); ++it ) { 692 for ( it = begin(); it != end(); ++it ) {
678 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 693 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
679 } 694 }
680 695
681} 696}
682 697
683QStringList AddressBook:: uidList() 698QStringList AddressBook:: uidList()
684{ 699{
685 QStringList results; 700 QStringList results;
686 Iterator it; 701 Iterator it;
687 for ( it = begin(); it != end(); ++it ) { 702 for ( it = begin(); it != end(); ++it ) {
688 results.append( (*it).uid() ); 703 results.append( (*it).uid() );
689 } 704 }
690 return results; 705 return results;
691} 706}
692 707
693 708
694Addressee::List AddressBook::allAddressees() 709Addressee::List AddressBook::allAddressees()
695{ 710{
696 return d->mAddressees; 711 return d->mAddressees;
697 712
698} 713}
699 714
700Addressee::List AddressBook::findByName( const QString &name ) 715Addressee::List AddressBook::findByName( const QString &name )
701{ 716{
702 Addressee::List results; 717 Addressee::List results;
703 718
704 Iterator it; 719 Iterator it;
705 for ( it = begin(); it != end(); ++it ) { 720 for ( it = begin(); it != end(); ++it ) {
706 if ( name == (*it).realName() ) { 721 if ( name == (*it).realName() ) {
707 results.append( *it ); 722 results.append( *it );
708 } 723 }
709 } 724 }
710 725
711 return results; 726 return results;
712} 727}
713 728
714Addressee::List AddressBook::findByEmail( const QString &email ) 729Addressee::List AddressBook::findByEmail( const QString &email )
715{ 730{
716 Addressee::List results; 731 Addressee::List results;
717 QStringList mailList; 732 QStringList mailList;
718 733
719 Iterator it; 734 Iterator it;
720 for ( it = begin(); it != end(); ++it ) { 735 for ( it = begin(); it != end(); ++it ) {
721 mailList = (*it).emails(); 736 mailList = (*it).emails();
722 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 737 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
723 if ( email == (*ite) ) { 738 if ( email == (*ite) ) {
724 results.append( *it ); 739 results.append( *it );
725 } 740 }
726 } 741 }
727 } 742 }
728 743
729 return results; 744 return results;
730} 745}
731 746
732Addressee::List AddressBook::findByCategory( const QString &category ) 747Addressee::List AddressBook::findByCategory( const QString &category )
733{ 748{
734 Addressee::List results; 749 Addressee::List results;
735 750
736 Iterator it; 751 Iterator it;
737 for ( it = begin(); it != end(); ++it ) { 752 for ( it = begin(); it != end(); ++it ) {
738 if ( (*it).hasCategory( category) ) { 753 if ( (*it).hasCategory( category) ) {
739 results.append( *it ); 754 results.append( *it );
740 } 755 }
741 } 756 }
742 757
743 return results; 758 return results;
744} 759}
745 760
746void AddressBook::dump() const 761void AddressBook::dump() const
747{ 762{
748 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 763 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
749 764
750 ConstIterator it; 765 ConstIterator it;
751 for( it = begin(); it != end(); ++it ) { 766 for( it = begin(); it != end(); ++it ) {
752 (*it).dump(); 767 (*it).dump();
753 } 768 }
754 769
755 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 770 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
756} 771}
757 772
758QString AddressBook::identifier() 773QString AddressBook::identifier()
759{ 774{
760 QStringList identifier; 775 QStringList identifier;
761 776
762 777
763 KRES::Manager<Resource>::ActiveIterator it; 778 KRES::Manager<Resource>::ActiveIterator it;
764 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 779 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
765 if ( !(*it)->identifier().isEmpty() ) 780 if ( !(*it)->identifier().isEmpty() )
766 identifier.append( (*it)->identifier() ); 781 identifier.append( (*it)->identifier() );
767 } 782 }
768 783
769 return identifier.join( ":" ); 784 return identifier.join( ":" );
770} 785}
771 786
772Field::List AddressBook::fields( int category ) 787Field::List AddressBook::fields( int category )
773{ 788{
774 if ( d->mAllFields.isEmpty() ) { 789 if ( d->mAllFields.isEmpty() ) {
775 d->mAllFields = Field::allFields(); 790 d->mAllFields = Field::allFields();
776 } 791 }
777 792
778 if ( category == Field::All ) return d->mAllFields; 793 if ( category == Field::All ) return d->mAllFields;
779 794
780 Field::List result; 795 Field::List result;
781 Field::List::ConstIterator it; 796 Field::List::ConstIterator it;
782 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 797 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
783 if ( (*it)->category() & category ) result.append( *it ); 798 if ( (*it)->category() & category ) result.append( *it );
784 } 799 }
785 800
786 return result; 801 return result;
787} 802}
788 803
789bool AddressBook::addCustomField( const QString &label, int category, 804bool AddressBook::addCustomField( const QString &label, int category,
790 const QString &key, const QString &app ) 805 const QString &key, const QString &app )
791{ 806{
792 if ( d->mAllFields.isEmpty() ) { 807 if ( d->mAllFields.isEmpty() ) {
793 d->mAllFields = Field::allFields(); 808 d->mAllFields = Field::allFields();
794 } 809 }
795//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 810//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
796 QString a = app.isNull() ? KGlobal::getAppName() : app; 811 QString a = app.isNull() ? KGlobal::getAppName() : app;
797 812
798 QString k = key.isNull() ? label : key; 813 QString k = key.isNull() ? label : key;
799 814
800 Field *field = Field::createCustomField( label, category, k, a ); 815 Field *field = Field::createCustomField( label, category, k, a );
801 816
802 if ( !field ) return false; 817 if ( !field ) return false;
803 818
804 d->mAllFields.append( field ); 819 d->mAllFields.append( field );
805 820
806 return true; 821 return true;
807} 822}
808 823
809QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 824QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
810{ 825{
811 if (!ab.d) return s; 826 if (!ab.d) return s;
812 827
813 return s << ab.d->mAddressees; 828 return s << ab.d->mAddressees;
814} 829}
815 830
816QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 831QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
817{ 832{
818 if (!ab.d) return s; 833 if (!ab.d) return s;
819 834
820 s >> ab.d->mAddressees; 835 s >> ab.d->mAddressees;
821 836
822 return s; 837 return s;
823} 838}
824 839
825bool AddressBook::addResource( Resource *resource ) 840bool AddressBook::addResource( Resource *resource )
826{ 841{
827 if ( !resource->open() ) { 842 if ( !resource->open() ) {
828 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 843 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
829 return false; 844 return false;
830 } 845 }
831 846
832 resource->setAddressBook( this ); 847 resource->setAddressBook( this );
833 848
834 d->mManager->add( resource ); 849 d->mManager->add( resource );
835 return true; 850 return true;
836} 851}
837 852
838bool AddressBook::removeResource( Resource *resource ) 853bool AddressBook::removeResource( Resource *resource )
839{ 854{
840 resource->close(); 855 resource->close();
841 856
842 if ( resource == standardResource() ) 857 if ( resource == standardResource() )
843 d->mManager->setStandardResource( 0 ); 858 d->mManager->setStandardResource( 0 );
844 859
845 resource->setAddressBook( 0 ); 860 resource->setAddressBook( 0 );
846 861
847 d->mManager->remove( resource ); 862 d->mManager->remove( resource );
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 157dc56..8f62f0d 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -103,237 +103,238 @@ class AddressBook : public QObject
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 &, bool setRev = true ); 176 void insertAddressee( const Addressee &, bool setRev = true );
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 QStringList uidList();
295 void removeDeletedAddressees(); 295 void removeSyncAddressees( bool removeDeleted = false );
296 void mergeAB( AddressBook *aBook, const QString& profile ); 296 void mergeAB( AddressBook *aBook, const QString& profile );
297 Addressee findByExternUid( const QString& uid , const QString& profile ); 297 Addressee findByExternUid( const QString& uid , const QString& profile );
298 bool containsExternalUid( const QString& uid );
298 299
299 void preExternSync( AddressBook* aBook, const QString& csd ); 300 void preExternSync( AddressBook* aBook, const QString& csd );
300 void postExternSync( AddressBook* aBook, const QString& csd ); 301 void postExternSync( AddressBook* aBook, const QString& csd );
301 signals: 302 signals:
302 /** 303 /**
303 Emitted, when the address book has changed on disk. 304 Emitted, when the address book has changed on disk.
304 */ 305 */
305 void addressBookChanged( AddressBook * ); 306 void addressBookChanged( AddressBook * );
306 307
307 /** 308 /**
308 Emitted, when the address book has been locked for writing. 309 Emitted, when the address book has been locked for writing.
309 */ 310 */
310 void addressBookLocked( AddressBook * ); 311 void addressBookLocked( AddressBook * );
311 312
312 /** 313 /**
313 Emitted, when the address book has been unlocked. 314 Emitted, when the address book has been unlocked.
314 */ 315 */
315 void addressBookUnlocked( AddressBook * ); 316 void addressBookUnlocked( AddressBook * );
316 317
317 protected: 318 protected:
318 void deleteRemovedAddressees(); 319 void deleteRemovedAddressees();
319 void setStandardResource( Resource * ); 320 void setStandardResource( Resource * );
320 Resource *standardResource(); 321 Resource *standardResource();
321 KRES::Manager<Resource> *resourceManager(); 322 KRES::Manager<Resource> *resourceManager();
322 323
323 void init(const QString &config, const QString &family); 324 void init(const QString &config, const QString &family);
324 325
325 private: 326 private:
326//US QPtrList<Resource> mDummy; // Remove in KDE 4 327//US QPtrList<Resource> mDummy; // Remove in KDE 4
327 328
328 329
329 struct AddressBookData; 330 struct AddressBookData;
330 AddressBookData *d; 331 AddressBookData *d;
331 bool blockLSEchange; 332 bool blockLSEchange;
332}; 333};
333 334
334QDataStream &operator<<( QDataStream &, const AddressBook & ); 335QDataStream &operator<<( QDataStream &, const AddressBook & );
335QDataStream &operator>>( QDataStream &, AddressBook & ); 336QDataStream &operator>>( QDataStream &, AddressBook & );
336 337
337} 338}
338 339
339#endif 340#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index fda62f1..e241281 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,585 +1,589 @@
1/*** Warning! This file has been generated by the script makeaddressee ***/ 1/*** Warning! This file has been generated by the script makeaddressee ***/
2/* 2/*
3 This file is part of libkabc. 3 This file is part of libkabc.
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22/* 22/*
23Enhanced Version of the file for platform independent KDE tools. 23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk 24Copyright (c) 2004 Ulf Schenk
25 25
26$Id$ 26$Id$
27*/ 27*/
28 28
29#include <kconfig.h> 29#include <kconfig.h>
30 30
31#include <ksharedptr.h> 31#include <ksharedptr.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <kapplication.h> 33#include <kapplication.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kidmanager.h> 35#include <kidmanager.h>
36//US 36//US
37#include <kstandarddirs.h> 37#include <kstandarddirs.h>
38#include <libkcal/syncdefines.h> 38#include <libkcal/syncdefines.h>
39 39
40//US #include "resource.h" 40//US #include "resource.h"
41#include "addressee.h" 41#include "addressee.h"
42 42
43using namespace KABC; 43using namespace KABC;
44 44
45static bool matchBinaryPattern( int value, int pattern ); 45static bool matchBinaryPattern( int value, int pattern );
46 46
47struct Addressee::AddresseeData : public KShared 47struct Addressee::AddresseeData : public KShared
48{ 48{
49 QString uid; 49 QString uid;
50 QString name; 50 QString name;
51 QString formattedName; 51 QString formattedName;
52 QString familyName; 52 QString familyName;
53 QString givenName; 53 QString givenName;
54 QString additionalName; 54 QString additionalName;
55 QString prefix; 55 QString prefix;
56 QString suffix; 56 QString suffix;
57 QString nickName; 57 QString nickName;
58 QDateTime birthday; 58 QDateTime birthday;
59 QString mailer; 59 QString mailer;
60 TimeZone timeZone; 60 TimeZone timeZone;
61 Geo geo; 61 Geo geo;
62 QString title; 62 QString title;
63 QString role; 63 QString role;
64 QString organization; 64 QString organization;
65 QString note; 65 QString note;
66 QString productId; 66 QString productId;
67 QDateTime revision; 67 QDateTime revision;
68 QString sortString; 68 QString sortString;
69 QString externalUID; 69 QString externalUID;
70 QString originalExternalUID; 70 QString originalExternalUID;
71 KURL url; 71 KURL url;
72 Secrecy secrecy; 72 Secrecy secrecy;
73 Picture logo; 73 Picture logo;
74 Picture photo; 74 Picture photo;
75 Sound sound; 75 Sound sound;
76 Agent agent; 76 Agent agent;
77 QString mExternalId; 77 QString mExternalId;
78 PhoneNumber::List phoneNumbers; 78 PhoneNumber::List phoneNumbers;
79 Address::List addresses; 79 Address::List addresses;
80 Key::List keys; 80 Key::List keys;
81 QStringList emails; 81 QStringList emails;
82 QStringList categories; 82 QStringList categories;
83 QStringList custom; 83 QStringList custom;
84 int mTempSyncStat; 84 int mTempSyncStat;
85 Resource *resource; 85 Resource *resource;
86 86
87 bool empty :1; 87 bool empty :1;
88 bool changed :1; 88 bool changed :1;
89}; 89};
90 90
91Addressee::Addressee() 91Addressee::Addressee()
92{ 92{
93 mData = new AddresseeData; 93 mData = new AddresseeData;
94 mData->empty = true; 94 mData->empty = true;
95 mData->changed = false; 95 mData->changed = false;
96 mData->resource = 0; 96 mData->resource = 0;
97 mData->mExternalId = ":"; 97 mData->mExternalId = ":";
98 mData->revision = QDateTime ( QDate( 2004,1,1)); 98 mData->revision = QDateTime ( QDate( 2003,1,1));
99 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 99 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
100} 100}
101 101
102Addressee::~Addressee() 102Addressee::~Addressee()
103{ 103{
104} 104}
105 105
106Addressee::Addressee( const Addressee &a ) 106Addressee::Addressee( const Addressee &a )
107{ 107{
108 mData = a.mData; 108 mData = a.mData;
109} 109}
110 110
111Addressee &Addressee::operator=( const Addressee &a ) 111Addressee &Addressee::operator=( const Addressee &a )
112{ 112{
113 mData = a.mData; 113 mData = a.mData;
114 return (*this); 114 return (*this);
115} 115}
116 116
117Addressee Addressee::copy() 117Addressee Addressee::copy()
118{ 118{
119 Addressee a; 119 Addressee a;
120 *(a.mData) = *mData; 120 *(a.mData) = *mData;
121 return a; 121 return a;
122} 122}
123 123
124void Addressee::detach() 124void Addressee::detach()
125{ 125{
126 if ( mData.count() == 1 ) return; 126 if ( mData.count() == 1 ) return;
127 *this = copy(); 127 *this = copy();
128} 128}
129 129
130bool Addressee::operator==( const Addressee &a ) const 130bool Addressee::operator==( const Addressee &a ) const
131{ 131{
132 if ( uid() != a.uid() ) return false; 132 if ( uid() != a.uid() ) return false;
133 if ( mData->name != a.mData->name ) return false; 133 if ( mData->name != a.mData->name ) return false;
134 if ( mData->formattedName != a.mData->formattedName ) return false; 134 if ( mData->formattedName != a.mData->formattedName ) return false;
135 if ( mData->familyName != a.mData->familyName ) return false; 135 if ( mData->familyName != a.mData->familyName ) return false;
136 if ( mData->givenName != a.mData->givenName ) return false; 136 if ( mData->givenName != a.mData->givenName ) return false;
137 if ( mData->additionalName != a.mData->additionalName ) return false; 137 if ( mData->additionalName != a.mData->additionalName ) return false;
138 if ( mData->prefix != a.mData->prefix ) return false; 138 if ( mData->prefix != a.mData->prefix ) return false;
139 if ( mData->suffix != a.mData->suffix ) return false; 139 if ( mData->suffix != a.mData->suffix ) return false;
140 if ( mData->nickName != a.mData->nickName ) return false; 140 if ( mData->nickName != a.mData->nickName ) return false;
141 if ( mData->birthday != a.mData->birthday ) return false; 141 if ( mData->birthday != a.mData->birthday ) return false;
142 if ( mData->mailer != a.mData->mailer ) return false; 142 if ( mData->mailer != a.mData->mailer ) return false;
143 if ( mData->timeZone != a.mData->timeZone ) return false; 143 if ( mData->timeZone != a.mData->timeZone ) return false;
144 if ( mData->geo != a.mData->geo ) return false; 144 if ( mData->geo != a.mData->geo ) return false;
145 if ( mData->title != a.mData->title ) return false; 145 if ( mData->title != a.mData->title ) return false;
146 if ( mData->role != a.mData->role ) return false; 146 if ( mData->role != a.mData->role ) return false;
147 if ( mData->organization != a.mData->organization ) return false; 147 if ( mData->organization != a.mData->organization ) return false;
148 if ( mData->note != a.mData->note ) return false; 148 if ( mData->note != a.mData->note ) return false;
149 if ( mData->productId != a.mData->productId ) return false; 149 if ( mData->productId != a.mData->productId ) return false;
150 //if ( mData->revision != a.mData->revision ) return false; 150 //if ( mData->revision != a.mData->revision ) return false;
151 if ( mData->sortString != a.mData->sortString ) return false; 151 if ( mData->sortString != a.mData->sortString ) return false;
152 if ( mData->secrecy != a.mData->secrecy ) return false; 152 if ( mData->secrecy != a.mData->secrecy ) return false;
153 if ( mData->logo != a.mData->logo ) return false; 153 if ( mData->logo != a.mData->logo ) return false;
154 if ( mData->photo != a.mData->photo ) return false; 154 if ( mData->photo != a.mData->photo ) return false;
155 if ( mData->sound != a.mData->sound ) return false; 155 if ( mData->sound != a.mData->sound ) return false;
156 if ( mData->agent != a.mData->agent ) return false; 156 if ( mData->agent != a.mData->agent ) return false;
157 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 157 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
158 ( mData->url != a.mData->url ) ) return false; 158 ( mData->url != a.mData->url ) ) return false;
159 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 159 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
160 if ( mData->addresses != a.mData->addresses ) return false; 160 if ( mData->addresses != a.mData->addresses ) return false;
161 if ( mData->keys != a.mData->keys ) return false; 161 if ( mData->keys != a.mData->keys ) return false;
162 if ( mData->emails != a.mData->emails ) return false; 162 if ( mData->emails != a.mData->emails ) return false;
163 if ( mData->categories != a.mData->categories ) return false; 163 if ( mData->categories != a.mData->categories ) return false;
164 if ( mData->custom != a.mData->custom ) return false; 164 if ( mData->custom != a.mData->custom ) return false;
165 165
166 return true; 166 return true;
167} 167}
168 168
169bool Addressee::operator!=( const Addressee &a ) const 169bool Addressee::operator!=( const Addressee &a ) const
170{ 170{
171 return !( a == *this ); 171 return !( a == *this );
172} 172}
173 173
174bool Addressee::isEmpty() const 174bool Addressee::isEmpty() const
175{ 175{
176 return mData->empty; 176 return mData->empty;
177} 177}
178ulong Addressee::getCsum4List( const QStringList & attList) 178ulong Addressee::getCsum4List( const QStringList & attList)
179{ 179{
180 int max = attList.count(); 180 int max = attList.count();
181 ulong cSum = 0; 181 ulong cSum = 0;
182 int j,k,i; 182 int j,k,i;
183 int add; 183 int add;
184 for ( i = 0; i < max ; ++i ) { 184 for ( i = 0; i < max ; ++i ) {
185 QString s = attList[i]; 185 QString s = attList[i];
186 if ( ! s.isEmpty() ){ 186 if ( ! s.isEmpty() ){
187 j = s.length(); 187 j = s.length();
188 for ( k = 0; k < j; ++k ) { 188 for ( k = 0; k < j; ++k ) {
189 int mul = k +1; 189 int mul = k +1;
190 add = s[k].unicode (); 190 add = s[k].unicode ();
191 if ( k < 16 ) 191 if ( k < 16 )
192 mul = mul * mul; 192 mul = mul * mul;
193 int ii = i+1; 193 int ii = i+1;
194 add = add * mul *ii*ii*ii; 194 add = add * mul *ii*ii*ii;
195 cSum += add; 195 cSum += add;
196 } 196 }
197 } 197 }
198 198
199 } 199 }
200 //QString dump = attList.join(","); 200 //QString dump = attList.join(",");
201 //qDebug("csum: %d %s", cSum,dump.latin1()); 201 //qDebug("csum: %d %s", cSum,dump.latin1());
202 202
203 return cSum; 203 return cSum;
204 204
205} 205}
206void Addressee::computeCsum(const QString &dev) 206void Addressee::computeCsum(const QString &dev)
207{ 207{
208 QStringList l; 208 QStringList l;
209 if ( !mData->name.isEmpty() ) l.append(mData->name); 209 if ( !mData->name.isEmpty() ) l.append(mData->name);
210 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 210 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
211 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 211 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
212 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 212 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
213 if ( !mData->additionalName ) l.append( mData->additionalName ); 213 if ( !mData->additionalName ) l.append( mData->additionalName );
214 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 214 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
215 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 215 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
216 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 216 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
217 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 217 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
218 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 218 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
219 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 219 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
220 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 220 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
221 if ( !mData->title .isEmpty() ) l.append( mData->title ); 221 if ( !mData->title .isEmpty() ) l.append( mData->title );
222 if ( !mData->role.isEmpty() ) l.append( mData->role ); 222 if ( !mData->role.isEmpty() ) l.append( mData->role );
223 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 223 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
224 if ( !mData->note.isEmpty() ) l.append( mData->note ); 224 if ( !mData->note.isEmpty() ) l.append( mData->note );
225 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 225 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
226 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 226 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
227 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 227 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
228 // if ( !mData->logo.isEmpty() ) l.append( ); 228 // if ( !mData->logo.isEmpty() ) l.append( );
229 //if ( !mData->photo.isEmpty() ) l.append( ); 229 //if ( !mData->photo.isEmpty() ) l.append( );
230 //if ( !mData->sound.isEmpty() ) l.append( ); 230 //if ( !mData->sound.isEmpty() ) l.append( );
231 //if ( !mData->agent.isEmpty() ) l.append( ); 231 //if ( !mData->agent.isEmpty() ) l.append( );
232 //if ( mData->url.isValid() ) l.append( ); 232 //if ( mData->url.isValid() ) l.append( );
233#if 0 233#if 0
234 if ( !mData->phoneNumbers.isEmpty() ) l.append( ); 234 if ( !mData->phoneNumbers.isEmpty() ) l.append( );
235 if ( !mData->addresses.isEmpty() ) l.append( ); 235 if ( !mData->addresses.isEmpty() ) l.append( );
236 //if ( !mData->keys.isEmpty() ) l.append( ); 236 //if ( !mData->keys.isEmpty() ) l.append( );
237 if ( !mData->emails.isEmpty() ) l.append( ); 237 if ( !mData->emails.isEmpty() ) l.append( );
238 if ( !mData->categories .isEmpty() ) l.append( ); 238 if ( !mData->categories .isEmpty() ) l.append( );
239 if ( !mData->custom.isEmpty() ) l.append( ); 239 if ( !mData->custom.isEmpty() ) l.append( );
240#endif 240#endif
241 KABC::PhoneNumber::List phoneNumbers; 241 KABC::PhoneNumber::List phoneNumbers;
242 KABC::PhoneNumber::List::Iterator phoneIter; 242 KABC::PhoneNumber::List::Iterator phoneIter;
243 243
244 QStringList t; 244 QStringList t;
245 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 245 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
246 ++phoneIter ) 246 ++phoneIter )
247 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 247 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
248 t.sort(); 248 t.sort();
249 uint iii; 249 uint iii;
250 for ( iii = 0; iii < t.count(); ++iii) 250 for ( iii = 0; iii < t.count(); ++iii)
251 l.append( t[iii] ); 251 l.append( t[iii] );
252 t = mData->emails; 252 t = mData->emails;
253 t.sort(); 253 t.sort();
254 for ( iii = 0; iii < t.count(); ++iii) 254 for ( iii = 0; iii < t.count(); ++iii)
255 l.append( t[iii] ); 255 l.append( t[iii] );
256 t = mData->categories; 256 t = mData->categories;
257 t.sort(); 257 t.sort();
258 for ( iii = 0; iii < t.count(); ++iii) 258 for ( iii = 0; iii < t.count(); ++iii)
259 l.append( t[iii] ); 259 l.append( t[iii] );
260 t = mData->custom; 260 t = mData->custom;
261 t.sort(); 261 t.sort();
262 for ( iii = 0; iii < t.count(); ++iii) 262 for ( iii = 0; iii < t.count(); ++iii)
263 l.append( t[iii] ); 263 l.append( t[iii] );
264 KABC::Address::List::Iterator addressIter; 264 KABC::Address::List::Iterator addressIter;
265 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 265 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
266 ++addressIter ) { 266 ++addressIter ) {
267 t = (*addressIter).asList(); 267 t = (*addressIter).asList();
268 t.sort(); 268 t.sort();
269 for ( iii = 0; iii < t.count(); ++iii) 269 for ( iii = 0; iii < t.count(); ++iii)
270 l.append( t[iii] ); 270 l.append( t[iii] );
271 } 271 }
272 uint cs = getCsum4List(l); 272 uint cs = getCsum4List(l);
273 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 273 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
274 setCsum( dev, QString::number (cs )); 274 setCsum( dev, QString::number (cs ));
275} 275}
276 276
277void Addressee::mergeContact( const Addressee& ad ) 277void Addressee::mergeContact( const Addressee& ad )
278{ 278{
279 279
280 detach(); 280 detach();
281 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 281 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
282 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 282 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
283 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 283 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
284 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 284 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
285 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 285 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
286 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 286 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
287 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 287 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
288 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 288 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
289 if ( !mData->birthday.isValid() ) 289 if ( !mData->birthday.isValid() )
290 if ( ad.mData->birthday.isValid()) 290 if ( ad.mData->birthday.isValid())
291 mData->birthday = ad.mData->birthday; 291 mData->birthday = ad.mData->birthday;
292 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 292 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
293 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 293 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
294 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 294 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
295 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 295 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
296 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 296 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
297 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 297 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
298 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 298 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
299 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 299 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
300 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 300 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
301 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 301 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
302 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 302 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
303 303
304 // pending: 304 // pending:
305 // merging phonenumbers 305 // merging phonenumbers
306 // merging addresses 306 // merging addresses
307 // merging emails; 307 // merging emails;
308 // merging categories; 308 // merging categories;
309 // merging custom; 309 // merging custom;
310 // merging keys 310 // merging keys
311 qDebug("merge contact %s ", ad.uid().latin1());
312 setUid( ad.uid() );
311} 313}
312 314
313void Addressee::removeID(const QString &prof) 315void Addressee::removeID(const QString &prof)
314{ 316{
315 detach(); 317 detach();
316 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 318 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
317 319
318} 320}
319void Addressee::setID( const QString & prof , const QString & id ) 321void Addressee::setID( const QString & prof , const QString & id )
320{ 322{
321 detach(); 323 detach();
322 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 324 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
323 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 325 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
324} 326}
325void Addressee::setTempSyncStat( int id ) 327void Addressee::setTempSyncStat( int id )
326{ 328{
327 if ( mData->mTempSyncStat == id ) return; 329 if ( mData->mTempSyncStat == id ) return;
328 detach(); 330 detach();
329 mData->mTempSyncStat = id; 331 mData->mTempSyncStat = id;
330} 332}
331int Addressee::tempSyncStat() const 333int Addressee::tempSyncStat() const
332{ 334{
333 return mData->mTempSyncStat; 335 return mData->mTempSyncStat;
334} 336}
335 337
336QString Addressee::getID( const QString & prof) 338QString Addressee::getID( const QString & prof)
337{ 339{
338 return KIdManager::getId ( mData->mExternalId, prof ); 340 return KIdManager::getId ( mData->mExternalId, prof );
339} 341}
340 342
341void Addressee::setCsum( const QString & prof , const QString & id ) 343void Addressee::setCsum( const QString & prof , const QString & id )
342{ 344{
343 detach(); 345 detach();
344 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 346 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
345 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 347 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
346 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 348 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
347} 349}
348 350
349QString Addressee::getCsum( const QString & prof) 351QString Addressee::getCsum( const QString & prof)
350{ 352{
351 return KIdManager::getCsum ( mData->mExternalId, prof ); 353 return KIdManager::getCsum ( mData->mExternalId, prof );
352} 354}
353 355
354void Addressee::setIDStr( const QString & s ) 356void Addressee::setIDStr( const QString & s )
355{ 357{
356 detach(); 358 detach();
357 mData->mExternalId = s; 359 mData->mExternalId = s;
358} 360}
359 361
360QString Addressee::IDStr() const 362QString Addressee::IDStr() const
361{ 363{
362 return mData->mExternalId; 364 return mData->mExternalId;
363} 365}
364 366
365void Addressee::setExternalUID( const QString &id ) 367void Addressee::setExternalUID( const QString &id )
366{ 368{
367 if ( id == mData->externalUID ) return; 369 if ( id == mData->externalUID ) return;
368 detach(); 370 detach();
369 mData->empty = false; 371 mData->empty = false;
370 mData->externalUID = id; 372 mData->externalUID = id;
371} 373}
372 374
373QString Addressee::externalUID() const 375QString Addressee::externalUID() const
374{ 376{
375 return mData->externalUID; 377 return mData->externalUID;
376} 378}
377void Addressee::setOriginalExternalUID( const QString &id ) 379void Addressee::setOriginalExternalUID( const QString &id )
378{ 380{
379 if ( id == mData->originalExternalUID ) return; 381 if ( id == mData->originalExternalUID ) return;
380 detach(); 382 detach();
381 mData->empty = false; 383 mData->empty = false;
384 qDebug("*******Set orig uid %s ", id.latin1());
382 mData->originalExternalUID = id; 385 mData->originalExternalUID = id;
383} 386}
384 387
385QString Addressee::originalExternalUID() const 388QString Addressee::originalExternalUID() const
386{ 389{
387 return mData->originalExternalUID; 390 return mData->originalExternalUID;
388} 391}
389 392
390void Addressee::setUid( const QString &id ) 393void Addressee::setUid( const QString &id )
391{ 394{
392 if ( id == mData->uid ) return; 395 if ( id == mData->uid ) return;
393 detach(); 396 detach();
397 qDebug("****setuid %s ", id.latin1());
394 mData->empty = false; 398 mData->empty = false;
395 mData->uid = id; 399 mData->uid = id;
396} 400}
397 401
398QString Addressee::uid() const 402QString Addressee::uid() const
399{ 403{
400 if ( mData->uid.isEmpty() ) 404 if ( mData->uid.isEmpty() )
401 mData->uid = KApplication::randomString( 10 ); 405 mData->uid = KApplication::randomString( 10 );
402 406
403 return mData->uid; 407 return mData->uid;
404} 408}
405 409
406QString Addressee::uidLabel() 410QString Addressee::uidLabel()
407{ 411{
408 return i18n("Unique Identifier"); 412 return i18n("Unique Identifier");
409} 413}
410 414
411void Addressee::setName( const QString &name ) 415void Addressee::setName( const QString &name )
412{ 416{
413 if ( name == mData->name ) return; 417 if ( name == mData->name ) return;
414 detach(); 418 detach();
415 mData->empty = false; 419 mData->empty = false;
416 mData->name = name; 420 mData->name = name;
417} 421}
418 422
419QString Addressee::name() const 423QString Addressee::name() const
420{ 424{
421 return mData->name; 425 return mData->name;
422} 426}
423 427
424QString Addressee::nameLabel() 428QString Addressee::nameLabel()
425{ 429{
426 return i18n("Name"); 430 return i18n("Name");
427} 431}
428 432
429 433
430void Addressee::setFormattedName( const QString &formattedName ) 434void Addressee::setFormattedName( const QString &formattedName )
431{ 435{
432 if ( formattedName == mData->formattedName ) return; 436 if ( formattedName == mData->formattedName ) return;
433 detach(); 437 detach();
434 mData->empty = false; 438 mData->empty = false;
435 mData->formattedName = formattedName; 439 mData->formattedName = formattedName;
436} 440}
437 441
438QString Addressee::formattedName() const 442QString Addressee::formattedName() const
439{ 443{
440 return mData->formattedName; 444 return mData->formattedName;
441} 445}
442 446
443QString Addressee::formattedNameLabel() 447QString Addressee::formattedNameLabel()
444{ 448{
445 return i18n("Formatted Name"); 449 return i18n("Formatted Name");
446} 450}
447 451
448 452
449void Addressee::setFamilyName( const QString &familyName ) 453void Addressee::setFamilyName( const QString &familyName )
450{ 454{
451 if ( familyName == mData->familyName ) return; 455 if ( familyName == mData->familyName ) return;
452 detach(); 456 detach();
453 mData->empty = false; 457 mData->empty = false;
454 mData->familyName = familyName; 458 mData->familyName = familyName;
455} 459}
456 460
457QString Addressee::familyName() const 461QString Addressee::familyName() const
458{ 462{
459 return mData->familyName; 463 return mData->familyName;
460} 464}
461 465
462QString Addressee::familyNameLabel() 466QString Addressee::familyNameLabel()
463{ 467{
464 return i18n("Family Name"); 468 return i18n("Family Name");
465} 469}
466 470
467 471
468void Addressee::setGivenName( const QString &givenName ) 472void Addressee::setGivenName( const QString &givenName )
469{ 473{
470 if ( givenName == mData->givenName ) return; 474 if ( givenName == mData->givenName ) return;
471 detach(); 475 detach();
472 mData->empty = false; 476 mData->empty = false;
473 mData->givenName = givenName; 477 mData->givenName = givenName;
474} 478}
475 479
476QString Addressee::givenName() const 480QString Addressee::givenName() const
477{ 481{
478 return mData->givenName; 482 return mData->givenName;
479} 483}
480 484
481QString Addressee::givenNameLabel() 485QString Addressee::givenNameLabel()
482{ 486{
483 return i18n("Given Name"); 487 return i18n("Given Name");
484} 488}
485 489
486 490
487void Addressee::setAdditionalName( const QString &additionalName ) 491void Addressee::setAdditionalName( const QString &additionalName )
488{ 492{
489 if ( additionalName == mData->additionalName ) return; 493 if ( additionalName == mData->additionalName ) return;
490 detach(); 494 detach();
491 mData->empty = false; 495 mData->empty = false;
492 mData->additionalName = additionalName; 496 mData->additionalName = additionalName;
493} 497}
494 498
495QString Addressee::additionalName() const 499QString Addressee::additionalName() const
496{ 500{
497 return mData->additionalName; 501 return mData->additionalName;
498} 502}
499 503
500QString Addressee::additionalNameLabel() 504QString Addressee::additionalNameLabel()
501{ 505{
502 return i18n("Additional Names"); 506 return i18n("Additional Names");
503} 507}
504 508
505 509
506void Addressee::setPrefix( const QString &prefix ) 510void Addressee::setPrefix( const QString &prefix )
507{ 511{
508 if ( prefix == mData->prefix ) return; 512 if ( prefix == mData->prefix ) return;
509 detach(); 513 detach();
510 mData->empty = false; 514 mData->empty = false;
511 mData->prefix = prefix; 515 mData->prefix = prefix;
512} 516}
513 517
514QString Addressee::prefix() const 518QString Addressee::prefix() const
515{ 519{
516 return mData->prefix; 520 return mData->prefix;
517} 521}
518 522
519QString Addressee::prefixLabel() 523QString Addressee::prefixLabel()
520{ 524{
521 return i18n("Honorific Prefixes"); 525 return i18n("Honorific Prefixes");
522} 526}
523 527
524 528
525void Addressee::setSuffix( const QString &suffix ) 529void Addressee::setSuffix( const QString &suffix )
526{ 530{
527 if ( suffix == mData->suffix ) return; 531 if ( suffix == mData->suffix ) return;
528 detach(); 532 detach();
529 mData->empty = false; 533 mData->empty = false;
530 mData->suffix = suffix; 534 mData->suffix = suffix;
531} 535}
532 536
533QString Addressee::suffix() const 537QString Addressee::suffix() const
534{ 538{
535 return mData->suffix; 539 return mData->suffix;
536} 540}
537 541
538QString Addressee::suffixLabel() 542QString Addressee::suffixLabel()
539{ 543{
540 return i18n("Honorific Suffixes"); 544 return i18n("Honorific Suffixes");
541} 545}
542 546
543 547
544void Addressee::setNickName( const QString &nickName ) 548void Addressee::setNickName( const QString &nickName )
545{ 549{
546 if ( nickName == mData->nickName ) return; 550 if ( nickName == mData->nickName ) return;
547 detach(); 551 detach();
548 mData->empty = false; 552 mData->empty = false;
549 mData->nickName = nickName; 553 mData->nickName = nickName;
550} 554}
551 555
552QString Addressee::nickName() const 556QString Addressee::nickName() const
553{ 557{
554 return mData->nickName; 558 return mData->nickName;
555} 559}
556 560
557QString Addressee::nickNameLabel() 561QString Addressee::nickNameLabel()
558{ 562{
559 return i18n("Nick Name"); 563 return i18n("Nick Name");
560} 564}
561 565
562 566
563void Addressee::setBirthday( const QDateTime &birthday ) 567void Addressee::setBirthday( const QDateTime &birthday )
564{ 568{
565 if ( birthday == mData->birthday ) return; 569 if ( birthday == mData->birthday ) return;
566 detach(); 570 detach();
567 mData->empty = false; 571 mData->empty = false;
568 mData->birthday = birthday; 572 mData->birthday = birthday;
569} 573}
570 574
571QDateTime Addressee::birthday() const 575QDateTime Addressee::birthday() const
572{ 576{
573 return mData->birthday; 577 return mData->birthday;
574} 578}
575 579
576QString Addressee::birthdayLabel() 580QString Addressee::birthdayLabel()
577{ 581{
578 return i18n("Birthday"); 582 return i18n("Birthday");
579} 583}
580 584
581 585
582QString Addressee::homeAddressStreetLabel() 586QString Addressee::homeAddressStreetLabel()
583{ 587{
584 return i18n("Home Address Street"); 588 return i18n("Home Address Street");
585} 589}
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp
index de45e63..430c7b3 100644
--- a/kabc/plugins/qtopia/qtopiaconverter.cpp
+++ b/kabc/plugins/qtopia/qtopiaconverter.cpp
@@ -1,281 +1,281 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library 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 GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28//US 28//US
29#include "kglobal.h" 29#include "kglobal.h"
30 30
31 31
32#include "qtopiaconverter.h" 32#include "qtopiaconverter.h"
33 33
34#include <qpe/categories.h> 34#include <qpe/categories.h>
35#include <libkdepim/ksyncprofile.h> 35#include <libkdepim/ksyncprofile.h>
36//US #include <qpe/categoryselect.h> 36//US #include <qpe/categoryselect.h>
37 37
38 38
39using namespace KABC; 39using namespace KABC;
40 40
41QtopiaConverter::QtopiaConverter() : catDB(0) 41QtopiaConverter::QtopiaConverter() : catDB(0)
42{ 42{
43} 43}
44 44
45QtopiaConverter::~QtopiaConverter() 45QtopiaConverter::~QtopiaConverter()
46{ 46{
47 deinit(); 47 deinit();
48} 48}
49 49
50bool QtopiaConverter::init() 50bool QtopiaConverter::init()
51{ 51{
52 catDB = new Categories(); 52 catDB = new Categories();
53 53
54 if (!catDB) 54 if (!catDB)
55 return false; 55 return false;
56 56
57 catDB->load( categoryFileName() ); 57 catDB->load( categoryFileName() );
58 return true; 58 return true;
59} 59}
60 60
61void QtopiaConverter::deinit() 61void QtopiaConverter::deinit()
62{ 62{
63 if (catDB) 63 if (catDB)
64 { 64 {
65 delete catDB; 65 delete catDB;
66 catDB = 0; 66 catDB = 0;
67 } 67 }
68} 68}
69 69
70bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) 70bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr )
71{ 71{
72 // name 72 // name
73 addr.setFormattedName(contact.fileAs()); 73 addr.setFormattedName(contact.fileAs());
74 addr.setFamilyName( contact.lastName() ); 74 addr.setFamilyName( contact.lastName() );
75 addr.setGivenName( contact.firstName() ); 75 addr.setGivenName( contact.firstName() );
76 addr.setAdditionalName( contact.middleName() ); 76 addr.setAdditionalName( contact.middleName() );
77 addr.setPrefix( contact.nameTitle() ); 77 addr.setPrefix( contact.nameTitle() );
78 addr.setSuffix( contact.suffix() ); 78 addr.setSuffix( contact.suffix() );
79 79
80 addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 80 addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
81 QString exuid = contact.uid().toString(); 81 QString exuid = contact.uid().toString();
82 addr.setOriginalExternalUID( exuid ); 82 addr.setOriginalExternalUID( exuid );
83 int ente = exuid.find( "-0000"); 83 int ente = exuid.find( "-0000");
84 if ( exuid.left(1) == "{" ) 84 if ( exuid.left(1) == "{" )
85 exuid = exuid.mid(1); 85 exuid = exuid.mid(1);
86 if ( ente > -1 ) 86 if ( ente > -1 )
87 exuid = exuid.left( ente-1 ); 87 exuid = exuid.left( ente-1 );
88 addr.setExternalUID( exuid ); 88 addr.setExternalUID( exuid );
89 //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() ); 89 qDebug("QtopiaConverter:set %s uid %s ",addr.originalExternalUID().latin1(),addr.externalUID().latin1() );
90 90
91 // email 91 // email
92 QStringList emails = contact.emailList(); 92 QStringList emails = contact.emailList();
93 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 93 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
94 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); 94 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) );
95 } 95 }
96 96
97 if (!contact.defaultEmail().isEmpty()) 97 if (!contact.defaultEmail().isEmpty())
98 addr.insertEmail(contact.defaultEmail(), true); 98 addr.insertEmail(contact.defaultEmail(), true);
99 99
100 // home 100 // home
101 if ((!contact.homeStreet().isEmpty()) || 101 if ((!contact.homeStreet().isEmpty()) ||
102 (!contact.homeCity().isEmpty()) || 102 (!contact.homeCity().isEmpty()) ||
103 (!contact.homeState().isEmpty()) || 103 (!contact.homeState().isEmpty()) ||
104 (!contact.homeZip().isEmpty()) || 104 (!contact.homeZip().isEmpty()) ||
105 (!contact.homeCountry().isEmpty())) 105 (!contact.homeCountry().isEmpty()))
106 { 106 {
107 Address homeaddress; 107 Address homeaddress;
108 homeaddress.setType(Address::Home); 108 homeaddress.setType(Address::Home);
109//US homeaddress.setPostOfficeBox( "" ); 109//US homeaddress.setPostOfficeBox( "" );
110//US homeaddress.setExtended( "" ); 110//US homeaddress.setExtended( "" );
111 homeaddress.setStreet( contact.homeStreet() ); 111 homeaddress.setStreet( contact.homeStreet() );
112 homeaddress.setLocality( contact.homeCity() ); 112 homeaddress.setLocality( contact.homeCity() );
113 homeaddress.setRegion( contact.homeState() ); 113 homeaddress.setRegion( contact.homeState() );
114 homeaddress.setPostalCode( contact.homeZip() ); 114 homeaddress.setPostalCode( contact.homeZip() );
115 homeaddress.setCountry( contact.homeCountry() ); 115 homeaddress.setCountry( contact.homeCountry() );
116 116
117 addr.insertAddress( homeaddress ); 117 addr.insertAddress( homeaddress );
118 } 118 }
119 119
120 if (!contact.homePhone().isEmpty()) 120 if (!contact.homePhone().isEmpty())
121 { 121 {
122 PhoneNumber homephone; 122 PhoneNumber homephone;
123 homephone.setType( PhoneNumber::Home ); 123 homephone.setType( PhoneNumber::Home );
124 homephone.setNumber( contact.homePhone() ); 124 homephone.setNumber( contact.homePhone() );
125 addr.insertPhoneNumber( homephone ); 125 addr.insertPhoneNumber( homephone );
126 } 126 }
127 127
128 if (!contact.homeFax().isEmpty()) 128 if (!contact.homeFax().isEmpty())
129 { 129 {
130 PhoneNumber homefax; 130 PhoneNumber homefax;
131 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); 131 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax );
132 homefax.setNumber( contact.homeFax() ); 132 homefax.setNumber( contact.homeFax() );
133 addr.insertPhoneNumber( homefax ); 133 addr.insertPhoneNumber( homefax );
134 } 134 }
135 135
136 if (!contact.homeMobile().isEmpty()) 136 if (!contact.homeMobile().isEmpty())
137 { 137 {
138 PhoneNumber homemobile; 138 PhoneNumber homemobile;
139 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); 139 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell );
140 homemobile.setNumber( contact.homeMobile() ); 140 homemobile.setNumber( contact.homeMobile() );
141 addr.insertPhoneNumber( homemobile ); 141 addr.insertPhoneNumber( homemobile );
142 } 142 }
143 143
144 addr.setUrl( contact.homeWebpage() ); 144 addr.setUrl( contact.homeWebpage() );
145 145
146 146
147 // business 147 // business
148 if ((!contact.businessStreet().isEmpty()) || 148 if ((!contact.businessStreet().isEmpty()) ||
149 (!contact.businessCity().isEmpty()) || 149 (!contact.businessCity().isEmpty()) ||
150 (!contact.businessState().isEmpty()) || 150 (!contact.businessState().isEmpty()) ||
151 (!contact.businessZip().isEmpty()) || 151 (!contact.businessZip().isEmpty()) ||
152 (!contact.businessCountry().isEmpty())) 152 (!contact.businessCountry().isEmpty()))
153 { 153 {
154 Address businessaddress; 154 Address businessaddress;
155 businessaddress.setType(Address::Work); 155 businessaddress.setType(Address::Work);
156//US businessaddress.setPostOfficeBox( "" ); 156//US businessaddress.setPostOfficeBox( "" );
157//US businessaddress.setExtended( "" ); 157//US businessaddress.setExtended( "" );
158 businessaddress.setStreet( contact.businessStreet() ); 158 businessaddress.setStreet( contact.businessStreet() );
159 businessaddress.setLocality( contact.businessCity() ); 159 businessaddress.setLocality( contact.businessCity() );
160 businessaddress.setRegion( contact.businessState() ); 160 businessaddress.setRegion( contact.businessState() );
161 businessaddress.setPostalCode( contact.businessZip() ); 161 businessaddress.setPostalCode( contact.businessZip() );
162 businessaddress.setCountry( contact.businessCountry() ); 162 businessaddress.setCountry( contact.businessCountry() );
163 163
164 addr.insertAddress( businessaddress ); 164 addr.insertAddress( businessaddress );
165 } 165 }
166 166
167 167
168 if (!contact.businessPhone().isEmpty()) 168 if (!contact.businessPhone().isEmpty())
169 { 169 {
170 PhoneNumber businessphone; 170 PhoneNumber businessphone;
171 businessphone.setType( PhoneNumber::Work ); 171 businessphone.setType( PhoneNumber::Work );
172 businessphone.setNumber( contact.businessPhone() ); 172 businessphone.setNumber( contact.businessPhone() );
173 addr.insertPhoneNumber( businessphone ); 173 addr.insertPhoneNumber( businessphone );
174 } 174 }
175 175
176 if (!contact.businessFax().isEmpty()) 176 if (!contact.businessFax().isEmpty())
177 { 177 {
178 PhoneNumber businessfax; 178 PhoneNumber businessfax;
179 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); 179 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax );
180 businessfax.setNumber( contact.businessFax() ); 180 businessfax.setNumber( contact.businessFax() );
181 addr.insertPhoneNumber( businessfax ); 181 addr.insertPhoneNumber( businessfax );
182 } 182 }
183 183
184 if (!contact.businessMobile().isEmpty()) 184 if (!contact.businessMobile().isEmpty())
185 { 185 {
186 PhoneNumber businessmobile; 186 PhoneNumber businessmobile;
187 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); 187 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell );
188 businessmobile.setNumber( contact.businessMobile() ); 188 businessmobile.setNumber( contact.businessMobile() );
189 addr.insertPhoneNumber( businessmobile ); 189 addr.insertPhoneNumber( businessmobile );
190 } 190 }
191 191
192 if (!contact.businessPager().isEmpty()) 192 if (!contact.businessPager().isEmpty())
193 { 193 {
194 PhoneNumber businesspager; 194 PhoneNumber businesspager;
195 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); 195 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager );
196 businesspager.setNumber( contact.businessPager() ); 196 businesspager.setNumber( contact.businessPager() );
197 addr.insertPhoneNumber( businesspager ); 197 addr.insertPhoneNumber( businesspager );
198 } 198 }
199 199
200 addr.setRole( contact.jobTitle() ); //? 200 addr.setRole( contact.jobTitle() ); //?
201 addr.setOrganization( contact.company() ); 201 addr.setOrganization( contact.company() );
202 addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); 202 addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() );
203 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); 203 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() );
204 addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); 204 addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() );
205 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); 205 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() );
206 addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); 206 addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() );
207 207
208 //personal 208 //personal
209 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); 209 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() );
210 // qtopia uses this categorization: 210 // qtopia uses this categorization:
211 // enum GenderType { UnspecifiedGender=0, Male, Female }; 211 // enum GenderType { UnspecifiedGender=0, Male, Female };
212 if (contact.gender() == PimContact::Male) 212 if (contact.gender() == PimContact::Male)
213 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); 213 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male");
214 else if (contact.gender() == PimContact::Female) 214 else if (contact.gender() == PimContact::Female)
215 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); 215 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female");
216 216
217 if (contact.anniversary().isValid()) { 217 if (contact.anniversary().isValid()) {
218 QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); 218 QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate);
219//US 219//US
220// qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1()); 220// qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1());
221 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); 221 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
222 } 222 }
223 223
224 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); 224 addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() );
225 if (contact.birthday().isValid()) 225 if (contact.birthday().isValid())
226 addr.setBirthday( contact.birthday() ); 226 addr.setBirthday( contact.birthday() );
227 227
228 addr.setNickName( contact.nickname() ); 228 addr.setNickName( contact.nickname() );
229 229
230 // others 230 // others
231 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. 231 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available.
232 QString notes = contact.notes(); 232 QString notes = contact.notes();
233 notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; 233 notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n";
234 234
235 addr.setNote( contact.notes() ); 235 addr.setNote( contact.notes() );
236 236
237 237
238 238
239//US QString groups() const { return find( Qtopia::Groups ); } 239//US QString groups() const { return find( Qtopia::Groups ); }
240//US QStringList groupList() const; 240//US QStringList groupList() const;
241 241
242 QArray<int> catArray = contact.categories(); 242 QArray<int> catArray = contact.categories();
243 QString cat; 243 QString cat;
244 244
245 for ( unsigned int i=0; i < catArray.size(); i++ ) { 245 for ( unsigned int i=0; i < catArray.size(); i++ ) {
246 cat = catDB->label("contact", catArray[i]); 246 cat = catDB->label("contact", catArray[i]);
247 if ( cat.isEmpty() ) 247 if ( cat.isEmpty() )
248 addr.insertCategory(QString::number(catArray[i])); 248 addr.insertCategory(QString::number(catArray[i]));
249 else 249 else
250 addr.insertCategory( cat ); 250 addr.insertCategory( cat );
251 } 251 }
252 252
253 return true; 253 return true;
254} 254}
255 255
256bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) 256bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact )
257{ 257{
258 258
259 259
260 260
261 // name 261 // name
262 contact.setLastName(addr.familyName()); 262 contact.setLastName(addr.familyName());
263 contact.setFirstName(addr.givenName()); 263 contact.setFirstName(addr.givenName());
264 contact.setMiddleName(addr.additionalName()); 264 contact.setMiddleName(addr.additionalName());
265 contact.setNameTitle(addr.prefix()); 265 contact.setNameTitle(addr.prefix());
266 contact.setSuffix(addr.suffix()); 266 contact.setSuffix(addr.suffix());
267 contact.setFileAs(); 267 contact.setFileAs();
268 268
269 269
270 // email 270 // email
271 QStringList emails = addr.emails(); 271 QStringList emails = addr.emails();
272 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 272 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
273 contact.insertEmail(*it); 273 contact.insertEmail(*it);
274 } 274 }
275 contact.setDefaultEmail( addr.preferredEmail() ); 275 contact.setDefaultEmail( addr.preferredEmail() );
276 276
277 277
278 // home 278 // home
279 const Address homeaddress = addr.address(Address::Home); 279 const Address homeaddress = addr.address(Address::Home);
280 if (!homeaddress.isEmpty()) { 280 if (!homeaddress.isEmpty()) {
281 contact.setHomeStreet(homeaddress.street()); 281 contact.setHomeStreet(homeaddress.street());
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 935a1cf..1f90fcb 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -8,339 +8,398 @@
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library 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 GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/stat.h> 28#include <sys/stat.h>
29#include <unistd.h> 29#include <unistd.h>
30 30
31#include <qdir.h> 31#include <qdir.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34#include <qregexp.h> 34#include <qregexp.h>
35//US #include <qtimer.h> 35//US #include <qtimer.h>
36 36
37#include <kapplication.h> 37#include <kapplication.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41//US #include <ksavefile.h> 41//US #include <ksavefile.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44 44
45#include <qpe/pim/addressbookaccess.h> 45#include <qpe/pim/addressbookaccess.h>
46 46
47 47
48#include "resourceqtopiaconfig.h" 48#include "resourceqtopiaconfig.h"
49#include "stdaddressbook.h" 49#include "stdaddressbook.h"
50 50
51#include "qtopiaconverter.h" 51#include "qtopiaconverter.h"
52#include "syncprefwidget.h" 52#include "syncprefwidget.h"
53 53
54#include "resourceqtopia.h" 54#include "resourceqtopia.h"
55#include <libkdepim/ksyncprofile.h> 55#include <libkdepim/ksyncprofile.h>
56#include <qpe/quuid.h> 56#include <qpe/quuid.h>
57 57
58using namespace KABC; 58using namespace KABC;
59extern "C" 59extern "C"
60{ 60{
61 void *init_microkabc_qtopia() 61 void *init_microkabc_qtopia()
62 { 62 {
63 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); 63 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>();
64 } 64 }
65} 65}
66 66
67ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) 67ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable )
68 : Resource( config, syncable ), mConverter (0) 68 : Resource( config, syncable ), mConverter (0)
69{ 69{
70 // we can not choose the filename. Therefore use the default to display 70 // we can not choose the filename. Therefore use the default to display
71 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 71 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
72 init( fileName ); 72 init( fileName );
73} 73}
74 74
75ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) 75ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable )
76 : Resource( 0, syncable ) 76 : Resource( 0, syncable )
77{ 77{
78 init( fileName ); 78 init( fileName );
79} 79}
80 80
81void ResourceQtopia::init( const QString &fileName ) 81void ResourceQtopia::init( const QString &fileName )
82{ 82{
83 83
84 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 84 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
85 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 85 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
86 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 86 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
87 87
88 setFileName( fileName ); 88 setFileName( fileName );
89} 89}
90 90
91ResourceQtopia::~ResourceQtopia() 91ResourceQtopia::~ResourceQtopia()
92{ 92{
93 if (mConverter != 0) 93 if (mConverter != 0)
94 delete mConverter; 94 delete mConverter;
95 95
96 if(mAccess != 0) 96 if(mAccess != 0)
97 delete mAccess; 97 delete mAccess;
98} 98}
99 99
100void ResourceQtopia::writeConfig( KConfig *config ) 100void ResourceQtopia::writeConfig( KConfig *config )
101{ 101{
102 Resource::writeConfig( config ); 102 Resource::writeConfig( config );
103} 103}
104 104
105Ticket *ResourceQtopia::requestSaveTicket() 105Ticket *ResourceQtopia::requestSaveTicket()
106{ 106{
107 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; 107 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl;
108 108
109 qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); 109 qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1());
110 110
111 if ( !addressBook() ) return 0; 111 if ( !addressBook() ) return 0;
112 112
113 if ( !lock( fileName() ) ) { 113 if ( !lock( fileName() ) ) {
114 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" 114 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '"
115 << fileName() << "'" << endl; 115 << fileName() << "'" << endl;
116 return 0; 116 return 0;
117 } 117 }
118 return createTicket( this ); 118 return createTicket( this );
119} 119}
120 120
121 121
122bool ResourceQtopia::doOpen() 122bool ResourceQtopia::doOpen()
123{ 123{
124 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); 124 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1());
125 125
126 mAccess = new AddressBookAccess(); 126 mAccess = new AddressBookAccess();
127 127
128 if ( !mAccess ) { 128 if ( !mAccess ) {
129 qDebug("Unable to load file() %s", fileName().latin1()); 129 qDebug("Unable to load file() %s", fileName().latin1());
130 return false; 130 return false;
131 } 131 }
132 132
133 133
134 if (mConverter == 0) 134 if (mConverter == 0)
135 { 135 {
136 mConverter = new QtopiaConverter(); 136 mConverter = new QtopiaConverter();
137 bool res = mConverter->init(); 137 bool res = mConverter->init();
138 if ( !res ) 138 if ( !res )
139 { 139 {
140 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); 140 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file");
141 qDebug(msg); 141 qDebug(msg);
142 delete mAccess; 142 delete mAccess;
143 mAccess = 0; 143 mAccess = 0;
144 return false; 144 return false;
145 } 145 }
146 } 146 }
147 147
148 return true; 148 return true;
149} 149}
150 150
151void ResourceQtopia::doClose() 151void ResourceQtopia::doClose()
152{ 152{
153 qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); 153 qDebug("ResourceQtopia::doClose: %s", fileName().latin1());
154 154
155 if(mAccess) 155 if(mAccess)
156 { 156 {
157 delete mAccess; 157 delete mAccess;
158 mAccess = 0; 158 mAccess = 0;
159 } 159 }
160 // it seems so, that deletion of access deletes backend as well 160 // it seems so, that deletion of access deletes backend as well
161 //delete backend; 161 //delete backend;
162 162
163 return; 163 return;
164} 164}
165 165
166bool ResourceQtopia::load() 166bool ResourceQtopia::load()
167{ 167{
168 qDebug("ResourceQtopia::load: %s", fileName().latin1()); 168 qDebug("ResourceQtopia::load: %s", fileName().latin1());
169 169
170 AddressBookIterator it(*mAccess); 170 AddressBookIterator it(*mAccess);
171 const PimContact* contact; 171 const PimContact* contact;
172 bool res; 172 bool res;
173 173
174 for (contact=it.toFirst(); it.current(); ++it) 174 for (contact=it.toFirst(); it.current(); ++it)
175 { 175 {
176 contact = it.current(); 176 contact = it.current();
177 177
178 KABC::Addressee addressee; 178 KABC::Addressee addressee;
179 179
180 res = mConverter->qtopiaToAddressee( (*contact), addressee ); 180 res = mConverter->qtopiaToAddressee( (*contact), addressee );
181 181
182 if ( !addressee.isEmpty() && res ) 182 if ( !addressee.isEmpty() && res )
183 { 183 {
184 addressee.setResource( this ); 184 addressee.setResource( this );
185 addressBook()->insertAddressee( addressee ); 185 addressBook()->insertAddressee( addressee );
186 } 186 }
187 } 187 }
188 188
189 return true; 189 return true;
190} 190}
191 191
192bool ResourceQtopia::save( Ticket *ticket ) 192bool ResourceQtopia::save( Ticket *ticket )
193{ 193{
194 qDebug("ResourceQtopia::save: %s", fileName().latin1()); 194 qDebug("ResourceQtopia::save: %s", fileName().latin1());
195 195
196 mDirWatch.stopScan(); 196 mDirWatch.stopScan();
197 197
198 KABC::AddressBook::Iterator it; 198 KABC::AddressBook::Iterator it;
199 bool res; 199 bool res;
200 200 KABC::Addressee::List changedAddressees;
201 QStringList addedUID;
201 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 202 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
202 //KABC::Addressee addressee = (*it); 203 //KABC::Addressee addressee = (*it);
204 // qDebug("AAAfor uid %s ", (*it).originalExternalUID().latin1() );
203 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 205 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
204 QUuid uid( (*it).originalExternalUID() ); 206 QUuid uid( (*it).originalExternalUID() );
205 bool ok; 207 bool ok;
206 PimContact c = mAccess->contactForId( uid, &ok ); 208 PimContact c = mAccess->contactForId( uid, &ok );
209 qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() );
207 res = mConverter->addresseeToQtopia( *it, c ); 210 res = mConverter->addresseeToQtopia( *it, c );
208 if (res == true) { 211 if (res == true) {
209 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { 212 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
210 mAccess->addContact(c); 213 qDebug("skipping adding of contact ");
211 KABC::Addressee addressee; 214 continue;
212 mConverter->qtopiaToAddressee( c, addressee ); 215 PimContact e;
213 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 216 AddressBookAccess Access2;
214 addressBook()->insertAddressee( addressee ); 217 Access2.addContact(e);
218 const PimContact* contact;
219 bool res;
220 QString uid2, Ouid;
221 AddressBookIterator itt(Access2);
222 for (contact=itt.toFirst(); itt.current(); ++itt)
223 {
224 contact = itt.current();
225 QString exuid = contact->uid().toString();
226 Ouid =exuid;
227 int ente = exuid.find( "-0000");
228 if ( exuid.left(1) == "{" )
229 exuid = exuid.mid(1);
230 if ( ente > -1 )
231 exuid = exuid.left( ente-1 );
232 uid2 = exuid;
233 qDebug("trying find uid ");
234 if ( !addressBook()->containsExternalUid( uid2 ) ) {
235 qDebug("ab not contains ");
236 if ( !addedUID.contains( uid2 )) {
237 qDebug("list not contains ");
238 break;
239 }
240 }
241
242 }
243 if ( !itt.current()) {
244 qDebug("ERROR uid ");
245 continue;
246 }
247 else
248 qDebug("ADD uid detected ");
249
250
251 QUuid uid3( Ouid);
252 PimContact d = Access2.contactForId( uid3, &ok );
253 if ( ! ok ) {
254 qDebug("ADD: Error getting new uid ");
255 } else {
256 qDebug("NEW UID found ");
257 PimContact g = mAccess->contactForId( c.uid(), &ok );
258 KABC::Addressee addressee;
259 mConverter->qtopiaToAddressee( g, addressee );
260 addressee.setUid((*it).uid() );
261 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
262 changedAddressees.append( addressee );
263 addedUID.append( uid2 );
264 }
265
215 266
216 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 267 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
268 qDebug("Remove contact ");
217 if ( ok ) 269 if ( ok )
218 mAccess->removeContact(c); 270 mAccess->removeContact(c);
219 else 271 else
220 qDebug("Error revoe contact from qtopia "); 272 qDebug("Error remove contact from qtopia ");
221 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 273 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
222 if ( ok ) { 274 if ( ok ) {
275 qDebug("Update contact ");
223 mAccess->updateContact(c); 276 mAccess->updateContact(c);
277 PimContact g = mAccess->contactForId( c.uid(), &ok );
224 KABC::Addressee addressee; 278 KABC::Addressee addressee;
225 mConverter->qtopiaToAddressee( c, addressee ); 279 mConverter->qtopiaToAddressee( g, addressee );
280 addressee.setUid((*it).uid() );
226 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); 281 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
227 addressBook()->insertAddressee( addressee ); 282 changedAddressees.append( addressee );
228 } 283 }
229 else 284 else
230 qDebug("Error update contact from qtopia "); 285 qDebug("Error update contact from qtopia ");
231 286
232 } 287 }
233 288
234 } else { 289 } else {
235 qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1()); 290 qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1());
236 } 291 }
237 } 292 }
238 } 293 }
239 294
240 // mAccess->addressBookUpdated(); 295 KABC::Addressee::List::Iterator it2;
296 for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 )
297 addressBook()->insertAddressee((*it2));
298
299
241 300
242 mDirWatch.startScan(); 301 mDirWatch.startScan();
243 302
244 delete ticket; 303 delete ticket;
245 unlock( fileName() ); 304 unlock( fileName() );
246 305
247 return true; 306 return true;
248} 307}
249 308
250bool ResourceQtopia::lock( const QString &lockfileName ) 309bool ResourceQtopia::lock( const QString &lockfileName )
251{ 310{
252 qDebug("ResourceQtopia::lock: %s", fileName().latin1()); 311 qDebug("ResourceQtopia::lock: %s", fileName().latin1());
253 312
254 kdDebug(5700) << "ResourceQtopia::lock()" << endl; 313 kdDebug(5700) << "ResourceQtopia::lock()" << endl;
255 314
256 QString fn = lockfileName; 315 QString fn = lockfileName;
257 316
258 KURL url(fn); 317 KURL url(fn);
259 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 318 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
260 319
261 kdDebug(5700) << "-- lock name: " << lockName << endl; 320 kdDebug(5700) << "-- lock name: " << lockName << endl;
262 321
263 if (QFile::exists( lockName )) 322 if (QFile::exists( lockName ))
264 { 323 {
265 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); 324 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
266 return false; 325 return false;
267 } 326 }
268 327
269 QString lockUniqueName; 328 QString lockUniqueName;
270 lockUniqueName = fn + KApplication::randomString( 8 ); 329 lockUniqueName = fn + KApplication::randomString( 8 );
271 330
272 url = lockUniqueName; 331 url = lockUniqueName;
273//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 332//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
274 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 333 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
275 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 334 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
276 335
277 // Create unique file 336 // Create unique file
278 QFile file( mLockUniqueName ); 337 QFile file( mLockUniqueName );
279 file.open( IO_WriteOnly ); 338 file.open( IO_WriteOnly );
280 file.close(); 339 file.close();
281 340
282 // Create lock file 341 // Create lock file
283 int result = 0; 342 int result = 0;
284#ifndef _WIN32_ 343#ifndef _WIN32_
285 result = ::link( QFile::encodeName( mLockUniqueName ), 344 result = ::link( QFile::encodeName( mLockUniqueName ),
286 QFile::encodeName( lockName ) ); 345 QFile::encodeName( lockName ) );
287#endif 346#endif
288 if ( result == 0 ) { 347 if ( result == 0 ) {
289 addressBook()->emitAddressBookLocked(); 348 addressBook()->emitAddressBookLocked();
290 return true; 349 return true;
291 } 350 }
292 351
293 // TODO: check stat 352 // TODO: check stat
294 353
295 return false; 354 return false;
296} 355}
297 356
298void ResourceQtopia::unlock( const QString &fileName ) 357void ResourceQtopia::unlock( const QString &fileName )
299{ 358{
300 qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); 359 qDebug("ResourceQtopia::unlock() %s", fileName.latin1());
301 360
302 QString fn = fileName; 361 QString fn = fileName;
303 KURL url(fn); 362 KURL url(fn);
304 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 363 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
305 364
306 QFile::remove( lockName ); 365 QFile::remove( lockName );
307 QFile::remove( mLockUniqueName ); 366 QFile::remove( mLockUniqueName );
308 addressBook()->emitAddressBookUnlocked(); 367 addressBook()->emitAddressBookUnlocked();
309} 368}
310 369
311void ResourceQtopia::setFileName( const QString &newFileName ) 370void ResourceQtopia::setFileName( const QString &newFileName )
312{ 371{
313 mDirWatch.stopScan(); 372 mDirWatch.stopScan();
314 mDirWatch.removeFile( fileName() ); 373 mDirWatch.removeFile( fileName() );
315 374
316 Resource::setFileName( newFileName ); 375 Resource::setFileName( newFileName );
317 376
318 mDirWatch.addFile( fileName() ); 377 mDirWatch.addFile( fileName() );
319 mDirWatch.startScan(); 378 mDirWatch.startScan();
320} 379}
321 380
322 381
323void ResourceQtopia::fileChanged() 382void ResourceQtopia::fileChanged()
324{ 383{
325 // There is a small theoretical chance that KDirWatch calls us before 384 // There is a small theoretical chance that KDirWatch calls us before
326 // we are fully constructed 385 // we are fully constructed
327 if (!addressBook()) 386 if (!addressBook())
328 return; 387 return;
329 388
330 QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); 389 QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
331 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 390 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
332 load(); 391 load();
333 addressBook()->emitAddressBookChanged(); 392 addressBook()->emitAddressBookChanged();
334 } 393 }
335} 394}
336 395
337void ResourceQtopia::removeAddressee( const Addressee &addr ) 396void ResourceQtopia::removeAddressee( const Addressee &addr )
338{ 397{
339} 398}
340 399
341void ResourceQtopia::cleanUp() 400void ResourceQtopia::cleanUp()
342{ 401{
343 unlock( fileName() ); 402 unlock( fileName() );
344} 403}
345 404
346//US #include "resourceqtopia.moc" 405//US #include "resourceqtopia.moc"
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 8f3ca9b..f8683e7 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2360,679 +2360,685 @@ int KABCore::ringSync()
2360#endif 2360#endif
2361 } 2361 }
2362 2362
2363 } 2363 }
2364 2364
2365 } 2365 }
2366 delete temp; 2366 delete temp;
2367 return syncedProfiles; 2367 return syncedProfiles;
2368} 2368}
2369 2369
2370void KABCore::syncRemote( KSyncProfile* prof, bool ask) 2370void KABCore::syncRemote( KSyncProfile* prof, bool ask)
2371{ 2371{
2372 QString question; 2372 QString question;
2373 if ( ask ) { 2373 if ( ask ) {
2374 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 2374 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
2375 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2375 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2376 question, 2376 question,
2377 i18n("Yes"), i18n("No"), 2377 i18n("Yes"), i18n("No"),
2378 0, 0 ) != 0 ) 2378 0, 0 ) != 0 )
2379 return; 2379 return;
2380 } 2380 }
2381 QString command = prof->getPreSyncCommandAB(); 2381 QString command = prof->getPreSyncCommandAB();
2382 int fi; 2382 int fi;
2383 if ( (fi = command.find("$PWD$")) > 0 ) { 2383 if ( (fi = command.find("$PWD$")) > 0 ) {
2384 QString pwd = getPassword(); 2384 QString pwd = getPassword();
2385 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2385 command = command.left( fi )+ pwd + command.mid( fi+5 );
2386 2386
2387 } 2387 }
2388 int maxlen = 30; 2388 int maxlen = 30;
2389 if ( QApplication::desktop()->width() > 320 ) 2389 if ( QApplication::desktop()->width() > 320 )
2390 maxlen += 25; 2390 maxlen += 25;
2391 setCaption ( i18n( "Copy remote file to local machine..." ) ); 2391 setCaption ( i18n( "Copy remote file to local machine..." ) );
2392 int fileSize = 0; 2392 int fileSize = 0;
2393 int result = system ( command ); 2393 int result = system ( command );
2394 // 0 : okay 2394 // 0 : okay
2395 // 256: no such file or dir 2395 // 256: no such file or dir
2396 // 2396 //
2397 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 2397 qDebug("KO: Remote copy result(0 = okay): %d ",result );
2398 if ( result != 0 ) { 2398 if ( result != 0 ) {
2399 int len = maxlen; 2399 int len = maxlen;
2400 while ( len < command.length() ) { 2400 while ( len < command.length() ) {
2401 command.insert( len , "\n" ); 2401 command.insert( len , "\n" );
2402 len += maxlen +2; 2402 len += maxlen +2;
2403 } 2403 }
2404 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; 2404 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ;
2405 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 2405 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2406 question, 2406 question,
2407 i18n("Okay!")) ; 2407 i18n("Okay!")) ;
2408 setCaption ("KO/Pi"); 2408 setCaption ("KO/Pi");
2409 return; 2409 return;
2410 } 2410 }
2411 setCaption ( i18n( "Copying succeed." ) ); 2411 setCaption ( i18n( "Copying succeed." ) );
2412 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 2412 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
2413 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { 2413 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) {
2414// Event* e = mView->getLastSyncEvent(); 2414// Event* e = mView->getLastSyncEvent();
2415// e->setReadOnly( false ); 2415// e->setReadOnly( false );
2416// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2416// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2417// e->setReadOnly( true ); 2417// e->setReadOnly( true );
2418 if ( KABPrefs::instance()->mWriteBackFile ) { 2418 if ( KABPrefs::instance()->mWriteBackFile ) {
2419 command = prof->getPostSyncCommandAB(); 2419 command = prof->getPostSyncCommandAB();
2420 int fi; 2420 int fi;
2421 if ( (fi = command.find("$PWD$")) > 0 ) { 2421 if ( (fi = command.find("$PWD$")) > 0 ) {
2422 QString pwd = getPassword(); 2422 QString pwd = getPassword();
2423 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2423 command = command.left( fi )+ pwd + command.mid( fi+5 );
2424 2424
2425 } 2425 }
2426 setCaption ( i18n( "Writing back file ..." ) ); 2426 setCaption ( i18n( "Writing back file ..." ) );
2427 result = system ( command ); 2427 result = system ( command );
2428 qDebug("KO: Writing back file result: %d ", result); 2428 qDebug("KO: Writing back file result: %d ", result);
2429 if ( result != 0 ) { 2429 if ( result != 0 ) {
2430 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 2430 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
2431 return; 2431 return;
2432 } else { 2432 } else {
2433 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 2433 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2434 } 2434 }
2435 } 2435 }
2436 } 2436 }
2437 return; 2437 return;
2438} 2438}
2439#include <qpushbutton.h> 2439#include <qpushbutton.h>
2440#include <qradiobutton.h> 2440#include <qradiobutton.h>
2441#include <qbuttongroup.h> 2441#include <qbuttongroup.h>
2442void KABCore::edit_sync_options() 2442void KABCore::edit_sync_options()
2443{ 2443{
2444 //mDialogManager->showSyncOptions(); 2444 //mDialogManager->showSyncOptions();
2445 //KABPrefs::instance()->mSyncAlgoPrefs 2445 //KABPrefs::instance()->mSyncAlgoPrefs
2446 QDialog dia( this, "dia", true ); 2446 QDialog dia( this, "dia", true );
2447 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 2447 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2448 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 2448 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2449 QVBoxLayout lay ( &dia ); 2449 QVBoxLayout lay ( &dia );
2450 lay.setSpacing( 2 ); 2450 lay.setSpacing( 2 );
2451 lay.setMargin( 3 ); 2451 lay.setMargin( 3 );
2452 lay.addWidget(&gr); 2452 lay.addWidget(&gr);
2453 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 2453 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2454 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 2454 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2455 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 2455 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2456 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 2456 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2457 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 2457 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2458 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 2458 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2459 //QRadioButton both( i18n("Take both on conflict"), &gr ); 2459 //QRadioButton both( i18n("Take both on conflict"), &gr );
2460 QPushButton pb ( "OK", &dia); 2460 QPushButton pb ( "OK", &dia);
2461 lay.addWidget( &pb ); 2461 lay.addWidget( &pb );
2462 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2462 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2463 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { 2463 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) {
2464 case 0: 2464 case 0:
2465 loc.setChecked( true); 2465 loc.setChecked( true);
2466 break; 2466 break;
2467 case 1: 2467 case 1:
2468 rem.setChecked( true ); 2468 rem.setChecked( true );
2469 break; 2469 break;
2470 case 2: 2470 case 2:
2471 newest.setChecked( true); 2471 newest.setChecked( true);
2472 break; 2472 break;
2473 case 3: 2473 case 3:
2474 ask.setChecked( true); 2474 ask.setChecked( true);
2475 break; 2475 break;
2476 case 4: 2476 case 4:
2477 f_loc.setChecked( true); 2477 f_loc.setChecked( true);
2478 break; 2478 break;
2479 case 5: 2479 case 5:
2480 f_rem.setChecked( true); 2480 f_rem.setChecked( true);
2481 break; 2481 break;
2482 case 6: 2482 case 6:
2483 // both.setChecked( true); 2483 // both.setChecked( true);
2484 break; 2484 break;
2485 default: 2485 default:
2486 break; 2486 break;
2487 } 2487 }
2488 if ( dia.exec() ) { 2488 if ( dia.exec() ) {
2489 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 ;
2490 } 2490 }
2491 2491
2492 2492
2493} 2493}
2494QString KABCore::getPassword( ) 2494QString KABCore::getPassword( )
2495{ 2495{
2496 QString retfile = ""; 2496 QString retfile = "";
2497 QDialog dia ( this, "input-dialog", true ); 2497 QDialog dia ( this, "input-dialog", true );
2498 QLineEdit lab ( &dia ); 2498 QLineEdit lab ( &dia );
2499 lab.setEchoMode( QLineEdit::Password ); 2499 lab.setEchoMode( QLineEdit::Password );
2500 QVBoxLayout lay( &dia ); 2500 QVBoxLayout lay( &dia );
2501 lay.setMargin(7); 2501 lay.setMargin(7);
2502 lay.setSpacing(7); 2502 lay.setSpacing(7);
2503 lay.addWidget( &lab); 2503 lay.addWidget( &lab);
2504 dia.setFixedSize( 230,50 ); 2504 dia.setFixedSize( 230,50 );
2505 dia.setCaption( i18n("Enter password") ); 2505 dia.setCaption( i18n("Enter password") );
2506 QPushButton pb ( "OK", &dia); 2506 QPushButton pb ( "OK", &dia);
2507 lay.addWidget( &pb ); 2507 lay.addWidget( &pb );
2508 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2508 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2509 dia.show(); 2509 dia.show();
2510 int res = dia.exec(); 2510 int res = dia.exec();
2511 if ( res ) 2511 if ( res )
2512 retfile = lab.text(); 2512 retfile = lab.text();
2513 dia.hide(); 2513 dia.hide();
2514 qApp->processEvents(); 2514 qApp->processEvents();
2515 return retfile; 2515 return retfile;
2516 2516
2517} 2517}
2518#include <libkcal/syncdefines.h> 2518#include <libkcal/syncdefines.h>
2519 2519
2520KABC::Addressee KABCore::getLastSyncAddressee() 2520KABC::Addressee KABCore::getLastSyncAddressee()
2521{ 2521{
2522 Addressee lse; 2522 Addressee lse;
2523 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2523 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2524 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2524 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2525 if (lse.isEmpty()) { 2525 if (lse.isEmpty()) {
2526 qDebug("Creating new last-syncAddressee "); 2526 qDebug("Creating new last-syncAddressee ");
2527 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2527 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2528 QString sum = ""; 2528 QString sum = "";
2529 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2529 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2530 sum = "E: "; 2530 sum = "E: ";
2531 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2531 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2532 lse.setRevision( mLastAddressbookSync ); 2532 lse.setRevision( mLastAddressbookSync );
2533 lse.setCategories( i18n("SyncEvent") ); 2533 lse.setCategories( i18n("SyncEvent") );
2534 mAddressBook->insertAddressee( lse ); 2534 mAddressBook->insertAddressee( lse );
2535 } 2535 }
2536 return lse; 2536 return lse;
2537} 2537}
2538int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2538int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2539{ 2539{
2540 2540
2541 //void setZaurusId(int id); 2541 //void setZaurusId(int id);
2542 // int zaurusId() const; 2542 // int zaurusId() const;
2543 // void setZaurusUid(int id); 2543 // void setZaurusUid(int id);
2544 // int zaurusUid() const; 2544 // int zaurusUid() const;
2545 // void setZaurusStat(int id); 2545 // void setZaurusStat(int id);
2546 // int zaurusStat() const; 2546 // int zaurusStat() const;
2547 // 0 equal 2547 // 0 equal
2548 // 1 take local 2548 // 1 take local
2549 // 2 take remote 2549 // 2 take remote
2550 // 3 cancel 2550 // 3 cancel
2551 QDateTime lastSync = mLastAddressbookSync; 2551 QDateTime lastSync = mLastAddressbookSync;
2552 QDateTime localMod = local->revision();
2553 QDateTime remoteMod = remote->revision();
2552 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2554 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2553 bool remCh, locCh; 2555 bool remCh, locCh;
2554 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2556 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2555 2557
2556 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2558 qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2557 locCh = ( local->revision() > mLastAddressbookSync ); 2559 locCh = ( localMod > mLastAddressbookSync );
2558 if ( !remCh && ! locCh ) { 2560 if ( !remCh && ! locCh ) {
2559 //qDebug("both not changed "); 2561 qDebug("both not changed ");
2560 lastSync = local->revision().addDays(1); 2562 lastSync = localMod.addDays(1);
2561 if ( mode <= SYNC_PREF_ASK ) 2563 if ( mode <= SYNC_PREF_ASK )
2562 return 0; 2564 return 0;
2563 } else { 2565 } else {
2564 if ( locCh ) { 2566 if ( locCh ) {
2565 //qDebug("loc changed %s %s", local->revision().toString().latin1(), mLastAddressbookSync.toString().latin1()); 2567 qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2566 lastSync = local->revision().addDays( -1 ); 2568 lastSync = localMod.addDays( -1 );
2567 if ( !remCh ) 2569 if ( !remCh )
2568 remote->setRevision( lastSync.addDays( -1 ) ); 2570 remoteMod =( lastSync.addDays( -1 ) );
2569 } else { 2571 } else {
2570 //qDebug(" not loc changed "); 2572 //qDebug(" not loc changed ");
2571 lastSync = local->revision().addDays( 1 ); 2573 lastSync = localMod.addDays( 1 );
2572 if ( remCh ) 2574 if ( remCh )
2573 remote->setRevision( lastSync.addDays( 1 ) ); 2575 remoteMod =( lastSync.addDays( 1 ) );
2574 2576
2575 } 2577 }
2576 } 2578 }
2577 full = true; 2579 full = true;
2578 if ( mode < SYNC_PREF_ASK ) 2580 if ( mode < SYNC_PREF_ASK )
2579 mode = SYNC_PREF_ASK; 2581 mode = SYNC_PREF_ASK;
2580 } else { 2582 } else {
2581 if ( local->revision() == remote->revision() ) 2583 if ( localMod == remoteMod )
2582 return 0; 2584 return 0;
2583 2585
2584 } 2586 }
2585 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2587 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2586 2588
2587 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 2589 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
2588 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2590 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2589 //full = true; //debug only 2591 //full = true; //debug only
2590 if ( full ) { 2592 if ( full ) {
2591 bool equ = ( (*local) == (*remote) ); 2593 bool equ = ( (*local) == (*remote) );
2592 if ( equ ) { 2594 if ( equ ) {
2593 //qDebug("equal "); 2595 //qDebug("equal ");
2594 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2596 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2595 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2597 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2596 } 2598 }
2597 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2599 if ( mode < SYNC_PREF_FORCE_LOCAL )
2598 return 0; 2600 return 0;
2599 2601
2600 }//else //debug only 2602 }//else //debug only
2601 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2603 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2602 } 2604 }
2603 int result; 2605 int result;
2604 bool localIsNew; 2606 bool localIsNew;
2605 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 2607 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
2606 2608
2607 if ( full && mode < SYNC_PREF_NEWEST ) 2609 if ( full && mode < SYNC_PREF_NEWEST )
2608 mode = SYNC_PREF_ASK; 2610 mode = SYNC_PREF_ASK;
2609 2611
2610 switch( mode ) { 2612 switch( mode ) {
2611 case SYNC_PREF_LOCAL: 2613 case SYNC_PREF_LOCAL:
2612 if ( lastSync > remote->revision() ) 2614 if ( lastSync > remoteMod )
2613 return 1; 2615 return 1;
2614 if ( lastSync > local->revision() ) 2616 if ( lastSync > localMod )
2615 return 2; 2617 return 2;
2616 return 1; 2618 return 1;
2617 break; 2619 break;
2618 case SYNC_PREF_REMOTE: 2620 case SYNC_PREF_REMOTE:
2619 if ( lastSync > remote->revision() ) 2621 if ( lastSync > remoteMod )
2620 return 1; 2622 return 1;
2621 if ( lastSync > local->revision() ) 2623 if ( lastSync > localMod )
2622 return 2; 2624 return 2;
2623 return 2; 2625 return 2;
2624 break; 2626 break;
2625 case SYNC_PREF_NEWEST: 2627 case SYNC_PREF_NEWEST:
2626 if ( local->revision() > remote->revision() ) 2628 if ( localMod > remoteMod )
2627 return 1; 2629 return 1;
2628 else 2630 else
2629 return 2; 2631 return 2;
2630 break; 2632 break;
2631 case SYNC_PREF_ASK: 2633 case SYNC_PREF_ASK:
2632 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() ); 2634 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2633 if ( lastSync > remote->revision() ) 2635 if ( lastSync > remoteMod )
2634 return 1; 2636 return 1;
2635 if ( lastSync > local->revision() ) 2637 if ( lastSync > localMod )
2636 return 2; 2638 return 2;
2637 localIsNew = local->revision() >= remote->revision(); 2639 localIsNew = localMod >= remoteMod;
2638 //qDebug("conflict! ************************************** "); 2640 //qDebug("conflict! ************************************** ");
2639 { 2641 {
2640 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2642 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2641 result = acd.executeD(localIsNew); 2643 result = acd.executeD(localIsNew);
2642 return result; 2644 return result;
2643 } 2645 }
2644 break; 2646 break;
2645 case SYNC_PREF_FORCE_LOCAL: 2647 case SYNC_PREF_FORCE_LOCAL:
2646 return 1; 2648 return 1;
2647 break; 2649 break;
2648 case SYNC_PREF_FORCE_REMOTE: 2650 case SYNC_PREF_FORCE_REMOTE:
2649 return 2; 2651 return 2;
2650 break; 2652 break;
2651 2653
2652 default: 2654 default:
2653 // SYNC_PREF_TAKE_BOTH not implemented 2655 // SYNC_PREF_TAKE_BOTH not implemented
2654 break; 2656 break;
2655 } 2657 }
2656 return 0; 2658 return 0;
2657} 2659}
2658bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2660bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2659{ 2661{
2660 bool syncOK = true; 2662 bool syncOK = true;
2661 int addedAddressee = 0; 2663 int addedAddressee = 0;
2662 int addedAddresseeR = 0; 2664 int addedAddresseeR = 0;
2663 int deletedAddresseeR = 0; 2665 int deletedAddresseeR = 0;
2664 int deletedAddresseeL = 0; 2666 int deletedAddresseeL = 0;
2665 int changedLocal = 0; 2667 int changedLocal = 0;
2666 int changedRemote = 0; 2668 int changedRemote = 0;
2667 //QPtrList<Addressee> el = local->rawAddressees(); 2669 //QPtrList<Addressee> el = local->rawAddressees();
2668 Addressee addresseeR; 2670 Addressee addresseeR;
2669 QString uid; 2671 QString uid;
2670 int take; 2672 int take;
2671 Addressee addresseeL; 2673 Addressee addresseeL;
2672 Addressee addresseeRSync; 2674 Addressee addresseeRSync;
2673 Addressee addresseeLSync; 2675 Addressee addresseeLSync;
2674 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2676 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2675 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2677 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2676 bool fullDateRange = false; 2678 bool fullDateRange = false;
2677 local->resetTempSyncStat(); 2679 local->resetTempSyncStat();
2678 mLastAddressbookSync = QDateTime::currentDateTime(); 2680 mLastAddressbookSync = QDateTime::currentDateTime();
2679 QDateTime modifiedCalendar = mLastAddressbookSync;; 2681 QDateTime modifiedCalendar = mLastAddressbookSync;;
2680 addresseeLSync = getLastSyncAddressee(); 2682 addresseeLSync = getLastSyncAddressee();
2681 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2683 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2682 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2684 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2683 if ( !addresseeR.isEmpty() ) { 2685 if ( !addresseeR.isEmpty() ) {
2684 addresseeRSync = addresseeR; 2686 addresseeRSync = addresseeR;
2685 remote->removeAddressee(addresseeR ); 2687 remote->removeAddressee(addresseeR );
2686 2688
2687 } else { 2689 } else {
2688 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2690 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2689 addresseeRSync = addresseeLSync ; 2691 addresseeRSync = addresseeLSync ;
2690 } else { 2692 } else {
2691 qDebug("FULLDATE 1"); 2693 qDebug("FULLDATE 1");
2692 fullDateRange = true; 2694 fullDateRange = true;
2693 Addressee newAdd; 2695 Addressee newAdd;
2694 addresseeRSync = newAdd; 2696 addresseeRSync = newAdd;
2695 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2697 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2696 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2698 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2697 addresseeRSync.setRevision( mLastAddressbookSync ); 2699 addresseeRSync.setRevision( mLastAddressbookSync );
2698 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2700 addresseeRSync.setCategories( i18n("SyncAddressee") );
2699 } 2701 }
2700 } 2702 }
2701 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2703 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2702 qDebug("FULLDATE 2"); 2704 qDebug("FULLDATE 2");
2703 fullDateRange = true; 2705 fullDateRange = true;
2704 } 2706 }
2705 if ( ! fullDateRange ) { 2707 if ( ! fullDateRange ) {
2706 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2708 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2707 2709
2708 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2710 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2709 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2711 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2710 fullDateRange = true; 2712 fullDateRange = true;
2711 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2713 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2712 } 2714 }
2713 } 2715 }
2714 // fullDateRange = true; // debug only! 2716 // fullDateRange = true; // debug only!
2715 if ( fullDateRange ) 2717 if ( fullDateRange )
2716 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2718 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2717 else 2719 else
2718 mLastAddressbookSync = addresseeLSync.revision(); 2720 mLastAddressbookSync = addresseeLSync.revision();
2719 // for resyncing if own file has changed 2721 // for resyncing if own file has changed
2720 // PENDING fixme later when implemented 2722 // PENDING fixme later when implemented
2721#if 0 2723#if 0
2722 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2724 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2723 mLastAddressbookSync = loadedFileVersion; 2725 mLastAddressbookSync = loadedFileVersion;
2724 qDebug("setting mLastAddressbookSync "); 2726 qDebug("setting mLastAddressbookSync ");
2725 } 2727 }
2726#endif 2728#endif
2727 2729
2728 //qDebug("*************************** "); 2730 //qDebug("*************************** ");
2729 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2731 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2730 QStringList er = remote->uidList(); 2732 QStringList er = remote->uidList();
2731 Addressee inR ;//= er.first(); 2733 Addressee inR ;//= er.first();
2732 Addressee inL; 2734 Addressee inL;
2733 QProgressBar bar( er.count(),0 ); 2735 QProgressBar bar( er.count(),0 );
2734 bar.setCaption (i18n("Syncing - close to abort!") ); 2736 bar.setCaption (i18n("Syncing - close to abort!") );
2735 2737
2736 int w = 300; 2738 int w = 300;
2737 if ( QApplication::desktop()->width() < 320 ) 2739 if ( QApplication::desktop()->width() < 320 )
2738 w = 220; 2740 w = 220;
2739 int h = bar.sizeHint().height() ; 2741 int h = bar.sizeHint().height() ;
2740 int dw = QApplication::desktop()->width(); 2742 int dw = QApplication::desktop()->width();
2741 int dh = QApplication::desktop()->height(); 2743 int dh = QApplication::desktop()->height();
2742 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2744 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2743 bar.show(); 2745 bar.show();
2744 int modulo = (er.count()/10)+1; 2746 int modulo = (er.count()/10)+1;
2745 int incCounter = 0; 2747 int incCounter = 0;
2746 while ( incCounter < er.count()) { 2748 while ( incCounter < er.count()) {
2747 if ( ! bar.isVisible() ) 2749 if ( ! bar.isVisible() )
2748 return false; 2750 return false;
2749 if ( incCounter % modulo == 0 ) 2751 if ( incCounter % modulo == 0 )
2750 bar.setProgress( incCounter ); 2752 bar.setProgress( incCounter );
2751 uid = er[ incCounter ]; 2753 uid = er[ incCounter ];
2752 bool skipIncidence = false; 2754 bool skipIncidence = false;
2753 if ( uid.left(19) == QString("last-syncAddressee-") ) 2755 if ( uid.left(19) == QString("last-syncAddressee-") )
2754 skipIncidence = true; 2756 skipIncidence = true;
2755 QString idS,OidS; 2757 QString idS,OidS;
2756 qApp->processEvents(); 2758 qApp->processEvents();
2757 if ( !skipIncidence ) { 2759 if ( !skipIncidence ) {
2758 inL = local->findByUid( uid ); 2760 inL = local->findByUid( uid );
2759 inR = remote->findByUid( uid ); 2761 inR = remote->findByUid( uid );
2760 //inL.setResource( 0 ); 2762 //inL.setResource( 0 );
2761 //inR.setResource( 0 ); 2763 //inR.setResource( 0 );
2762 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2764 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2763 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2765 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2764 //qDebug("take %d %s ", take, inL.summary().latin1()); 2766 //qDebug("take %d %s ", take, inL.summary().latin1());
2765 if ( take == 3 ) 2767 if ( take == 3 )
2766 return false; 2768 return false;
2767 if ( take == 1 ) {// take local 2769 if ( take == 1 ) {// take local
2768 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2770 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2769 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2771 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2770 local->insertAddressee( inL, false ); 2772 local->insertAddressee( inL, false );
2771 idS = inR.externalUID(); 2773 idS = inR.externalUID();
2772 OidS = inR.originalExternalUID(); 2774 OidS = inR.originalExternalUID();
2773 } 2775 }
2774 else 2776 else
2775 idS = inR.IDStr(); 2777 idS = inR.IDStr();
2776 remote->removeAddressee( inR ); 2778 remote->removeAddressee( inR );
2777 inR = inL; 2779 inR = inL;
2778 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2780 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2779 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2781 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2780 inR.setOriginalExternalUID( OidS ); 2782 inR.setOriginalExternalUID( OidS );
2781 inR.setExternalUID( idS ); 2783 inR.setExternalUID( idS );
2782 } else { 2784 } else {
2783 inR.setIDStr( idS ); 2785 inR.setIDStr( idS );
2784 } 2786 }
2785 inR.setResource( 0 ); 2787 inR.setResource( 0 );
2786 remote->insertAddressee( inR , false); 2788 remote->insertAddressee( inR , false);
2787 ++changedRemote; 2789 ++changedRemote;
2788 } else { // take == 2 take remote 2790 } else { // take == 2 take remote
2791 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2792 if ( inR.revision().date().year() < 2004 )
2793 inR.setRevision( modifiedCalendar );
2794 }
2789 idS = inL.IDStr(); 2795 idS = inL.IDStr();
2790 local->removeAddressee( inL ); 2796 local->removeAddressee( inL );
2791 inL = inR; 2797 inL = inR;
2792 inL.setIDStr( idS ); 2798 inL.setIDStr( idS );
2793 inL.setResource( 0 ); 2799 inL.setResource( 0 );
2794 local->insertAddressee( inL , false ); 2800 local->insertAddressee( inL , false );
2795 ++changedLocal; 2801 ++changedLocal;
2796 } 2802 }
2797 } 2803 }
2798 } else { // no conflict 2804 } else { // no conflict
2799 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2805 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2800 QString des = addresseeLSync.note(); 2806 QString des = addresseeLSync.note();
2801 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2807 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2802 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2808 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2803 remote->insertAddressee( inR, false ); 2809 remote->insertAddressee( inR, false );
2804 ++deletedAddresseeR; 2810 ++deletedAddresseeR;
2805 } else { 2811 } else {
2806 inR.setRevision( modifiedCalendar ); 2812 inR.setRevision( modifiedCalendar );
2807 remote->insertAddressee( inR, false ); 2813 remote->insertAddressee( inR, false );
2808 inL = inR; 2814 inL = inR;
2809 inL.setResource( 0 ); 2815 inL.setResource( 0 );
2810 local->insertAddressee( inL , false); 2816 local->insertAddressee( inL , false);
2811 ++addedAddressee; 2817 ++addedAddressee;
2812 } 2818 }
2813 } else { 2819 } else {
2814 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2820 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2815 inR.setRevision( modifiedCalendar ); 2821 inR.setRevision( modifiedCalendar );
2816 remote->insertAddressee( inR, false ); 2822 remote->insertAddressee( inR, false );
2817 inR.setResource( 0 ); 2823 inR.setResource( 0 );
2818 local->insertAddressee( inR, false ); 2824 local->insertAddressee( inR, false );
2819 ++addedAddressee; 2825 ++addedAddressee;
2820 } else { 2826 } else {
2821 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2827 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2822 remote->removeAddressee( inR ); 2828 remote->removeAddressee( inR );
2823 ++deletedAddresseeR; 2829 ++deletedAddresseeR;
2824 } 2830 }
2825 } 2831 }
2826 } 2832 }
2827 } 2833 }
2828 ++incCounter; 2834 ++incCounter;
2829 } 2835 }
2830 er.clear(); 2836 er.clear();
2831 QStringList el = local->uidList(); 2837 QStringList el = local->uidList();
2832 modulo = (el.count()/10)+1; 2838 modulo = (el.count()/10)+1;
2833 bar.setCaption (i18n("Add / remove addressees") ); 2839 bar.setCaption (i18n("Add / remove addressees") );
2834 bar.setTotalSteps ( el.count() ) ; 2840 bar.setTotalSteps ( el.count() ) ;
2835 bar.show(); 2841 bar.show();
2836 incCounter = 0; 2842 incCounter = 0;
2837 while ( incCounter < el.count()) { 2843 while ( incCounter < el.count()) {
2838 qApp->processEvents(); 2844 qApp->processEvents();
2839 if ( ! bar.isVisible() ) 2845 if ( ! bar.isVisible() )
2840 return false; 2846 return false;
2841 if ( incCounter % modulo == 0 ) 2847 if ( incCounter % modulo == 0 )
2842 bar.setProgress( incCounter ); 2848 bar.setProgress( incCounter );
2843 uid = el[ incCounter ]; 2849 uid = el[ incCounter ];
2844 bool skipIncidence = false; 2850 bool skipIncidence = false;
2845 if ( uid.left(19) == QString("last-syncAddressee-") ) 2851 if ( uid.left(19) == QString("last-syncAddressee-") )
2846 skipIncidence = true; 2852 skipIncidence = true;
2847 if ( !skipIncidence ) { 2853 if ( !skipIncidence ) {
2848 inL = local->findByUid( uid ); 2854 inL = local->findByUid( uid );
2849 inR = remote->findByUid( uid ); 2855 inR = remote->findByUid( uid );
2850 if ( inR.isEmpty() ) { 2856 if ( inR.isEmpty() ) {
2851 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2857 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2852 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2858 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2853 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2859 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2854 local->removeAddressee( inL ); 2860 local->removeAddressee( inL );
2855 ++deletedAddresseeL; 2861 ++deletedAddresseeL;
2856 } else { 2862 } else {
2857 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2863 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2858 inL.removeID(mCurrentSyncDevice ); 2864 inL.removeID(mCurrentSyncDevice );
2859 ++addedAddresseeR; 2865 ++addedAddresseeR;
2860 inL.setRevision( modifiedCalendar ); 2866 inL.setRevision( modifiedCalendar );
2861 local->insertAddressee( inL, false ); 2867 local->insertAddressee( inL, false );
2862 inR = inL; 2868 inR = inL;
2863 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2869 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2864 inR.setResource( 0 ); 2870 inR.setResource( 0 );
2865 remote->insertAddressee( inR, false ); 2871 remote->insertAddressee( inR, false );
2866 } 2872 }
2867 } 2873 }
2868 } else { 2874 } else {
2869 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2875 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2870 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2876 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2871 local->removeAddressee( inL ); 2877 local->removeAddressee( inL );
2872 ++deletedAddresseeL; 2878 ++deletedAddresseeL;
2873 } else { 2879 } else {
2874 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2880 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2875 ++addedAddresseeR; 2881 ++addedAddresseeR;
2876 inL.setRevision( modifiedCalendar ); 2882 inL.setRevision( modifiedCalendar );
2877 local->insertAddressee( inL, false ); 2883 local->insertAddressee( inL, false );
2878 inR = inL; 2884 inR = inL;
2879 inR.setResource( 0 ); 2885 inR.setResource( 0 );
2880 remote->insertAddressee( inR, false ); 2886 remote->insertAddressee( inR, false );
2881 } 2887 }
2882 } 2888 }
2883 } 2889 }
2884 } 2890 }
2885 } 2891 }
2886 ++incCounter; 2892 ++incCounter;
2887 } 2893 }
2888 el.clear(); 2894 el.clear();
2889 bar.hide(); 2895 bar.hide();
2890 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2896 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2891 // get rid of micro seconds 2897 // get rid of micro seconds
2892 QTime t = mLastAddressbookSync.time(); 2898 QTime t = mLastAddressbookSync.time();
2893 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2899 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2894 addresseeLSync.setRevision( mLastAddressbookSync ); 2900 addresseeLSync.setRevision( mLastAddressbookSync );
2895 addresseeRSync.setRevision( mLastAddressbookSync ); 2901 addresseeRSync.setRevision( mLastAddressbookSync );
2896 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2902 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2897 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2903 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2898 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2904 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2899 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2905 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2900 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2906 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2901 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2907 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2902 addresseeRSync.setNote( "" ) ; 2908 addresseeRSync.setNote( "" ) ;
2903 addresseeLSync.setNote( "" ); 2909 addresseeLSync.setNote( "" );
2904 2910
2905 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2911 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2906 remote->insertAddressee( addresseeRSync, false ); 2912 remote->insertAddressee( addresseeRSync, false );
2907 local->insertAddressee( addresseeLSync, false ); 2913 local->insertAddressee( addresseeLSync, false );
2908 QString mes; 2914 QString mes;
2909 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 ); 2915 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 );
2910 if ( KABPrefs::instance()->mShowSyncSummary ) { 2916 if ( KABPrefs::instance()->mShowSyncSummary ) {
2911 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2917 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2912 } 2918 }
2913 qDebug( mes ); 2919 qDebug( mes );
2914 return syncOK; 2920 return syncOK;
2915} 2921}
2916 2922
2917bool KABCore::syncAB(QString filename, int mode) 2923bool KABCore::syncAB(QString filename, int mode)
2918{ 2924{
2919 2925
2920 //pending prepare addresseeview for output 2926 //pending prepare addresseeview for output
2921 //pending detect, if remote file has REV field. if not switch to external sync 2927 //pending detect, if remote file has REV field. if not switch to external sync
2922 mGlobalSyncMode = SYNC_MODE_NORMAL; 2928 mGlobalSyncMode = SYNC_MODE_NORMAL;
2923 AddressBook abLocal(filename,"syncContact"); 2929 AddressBook abLocal(filename,"syncContact");
2924 bool syncOK = false; 2930 bool syncOK = false;
2925 if ( abLocal.load() ) { 2931 if ( abLocal.load() ) {
2926 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2932 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2927 bool external = false; 2933 bool external = false;
2928 2934 bool isXML = false;
2929 if ( filename.right(4) == ".xml") { 2935 if ( filename.right(4) == ".xml") {
2930 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2936 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2937 isXML = true;
2931 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2938 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2932 } else { 2939 } else {
2933 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2940 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2934 if ( ! lse.isEmpty() ) { 2941 if ( ! lse.isEmpty() ) {
2935 if ( lse.familyName().left(4) == "!E: " ) 2942 if ( lse.familyName().left(4) == "!E: " )
2936 external = true; 2943 external = true;
2937 } else { 2944 } else {
2938 bool found = false; 2945 bool found = false;
2939 QDateTime dt( QDate( 2004,1,1));
2940 AddressBook::Iterator it; 2946 AddressBook::Iterator it;
2941 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2947 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2942 if ( (*it).revision() != dt ) { 2948 if ( (*it).revision().date().year() > 2003 ) {
2943 found = true; 2949 found = true;
2944 break; 2950 break;
2945 } 2951 }
2946 } 2952 }
2947 external = ! found; 2953 external = ! found;
2948 } 2954 }
2949 2955
2950 if ( external ) { 2956 if ( external ) {
2951 qDebug("Setting vcf mode to external "); 2957 qDebug("Setting vcf mode to external ");
2952 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2958 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2953 AddressBook::Iterator it; 2959 AddressBook::Iterator it;
2954 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2960 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2955 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2961 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2956 (*it).computeCsum( mCurrentSyncDevice ); 2962 (*it).computeCsum( mCurrentSyncDevice );
2957 } 2963 }
2958 } 2964 }
2959 } 2965 }
2960 //AddressBook::Iterator it; 2966 //AddressBook::Iterator it;
2961 //QStringList vcards; 2967 //QStringList vcards;
2962 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2968 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2963 // qDebug("Name %s ", (*it).familyName().latin1()); 2969 // qDebug("Name %s ", (*it).familyName().latin1());
2964 //} 2970 //}
2965 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2971 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2966 if ( syncOK ) { 2972 if ( syncOK ) {
2967 if ( KABPrefs::instance()->mWriteBackFile ) 2973 if ( KABPrefs::instance()->mWriteBackFile )
2968 { 2974 {
2969 if ( external && filename.right(4) != ".xml") 2975 if ( external )
2970 abLocal.removeDeletedAddressees(); 2976 abLocal.removeSyncAddressees( !isXML);
2971 qDebug("Saving remote AB "); 2977 qDebug("Saving remote AB ");
2972 abLocal.saveAB(); 2978 abLocal.saveAB();
2973 if ( external && filename.right(4) == ".xml") { 2979 if ( isXML ) {
2974 // afterwrite processing 2980 // afterwrite processing
2975 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2981 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2976 } 2982 }
2977 } 2983 }
2978 } 2984 }
2979 setModified(); 2985 setModified();
2980 2986
2981 } 2987 }
2982 if ( syncOK ) 2988 if ( syncOK )
2983 mViewManager->refreshView(); 2989 mViewManager->refreshView();
2984 return syncOK; 2990 return syncOK;
2985#if 0 2991#if 0
2986 2992
2987 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 2993 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2988 getEventViewerDialog()->setSyncMode( true ); 2994 getEventViewerDialog()->setSyncMode( true );
2989 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 2995 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
2990 getEventViewerDialog()->setSyncMode( false ); 2996 getEventViewerDialog()->setSyncMode( false );
2991 if ( syncOK ) { 2997 if ( syncOK ) {
2992 if ( KOPrefs::instance()->mWriteBackFile ) 2998 if ( KOPrefs::instance()->mWriteBackFile )
2993 { 2999 {
2994 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 3000 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2995 storage->save(); 3001 storage->save();
2996 } 3002 }
2997 } 3003 }
2998 setModified(); 3004 setModified();
2999 } 3005 }
3000 3006
3001#endif 3007#endif
3002} 3008}
3003 3009
3004void KABCore::confSync() 3010void KABCore::confSync()
3005{ 3011{
3006 static KSyncPrefsDialog* sp = 0; 3012 static KSyncPrefsDialog* sp = 0;
3007 if ( ! sp ) { 3013 if ( ! sp ) {
3008 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 3014 sp = new KSyncPrefsDialog( this, "syncprefs", true );
3009 } 3015 }
3010 sp->usrReadConfig(); 3016 sp->usrReadConfig();
3011#ifndef DESKTOP_VERSION 3017#ifndef DESKTOP_VERSION
3012 sp->showMaximized(); 3018 sp->showMaximized();
3013#else 3019#else
3014 sp->show(); 3020 sp->show();
3015#endif 3021#endif
3016 sp->exec(); 3022 sp->exec();
3017 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 3023 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
3018 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 3024 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
3019 fillSyncMenu(); 3025 fillSyncMenu();
3020} 3026}
3021void KABCore::syncSharp() 3027void KABCore::syncSharp()
3022{ 3028{
3023 if ( mModified ) 3029 if ( mModified )
3024 save(); 3030 save();
3025 qDebug("pending syncSharp() "); 3031 qDebug("pending syncSharp() ");
3026 //mView->syncSharp(); 3032 //mView->syncSharp();
3027 setModified(); 3033 setModified();
3028 3034
3029} 3035}
3030void KABCore::syncPhone() 3036void KABCore::syncPhone()
3031{ 3037{
3032 if ( mModified ) 3038 if ( mModified )
3033 save(); 3039 save();
3034 qDebug("pending syncPhone(); "); 3040 qDebug("pending syncPhone(); ");
3035 //mView->syncPhone(); 3041 //mView->syncPhone();
3036 setModified(); 3042 setModified();
3037 3043
3038} 3044}
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 0c75632..8e83723 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -537,479 +537,481 @@ void CalendarView::computeAlarm( QString msg )
537 if ( len < 2 ) 537 if ( len < 2 )
538 error = true; 538 error = true;
539 else { 539 else {
540 tempfilename = mess.mid( 10, len ); 540 tempfilename = mess.mid( 10, len );
541 if ( !QFile::exists( tempfilename ) ) 541 if ( !QFile::exists( tempfilename ) )
542 error = true; 542 error = true;
543 } 543 }
544 if ( error ) { 544 if ( error ) {
545 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 545 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
546 mAlarmMessage += mess.mid( 10+len+3+9 ); 546 mAlarmMessage += mess.mid( 10+len+3+9 );
547 } else { 547 } else {
548 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 548 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
549 //qDebug("-----system command %s ",tempfilename.latin1() ); 549 //qDebug("-----system command %s ",tempfilename.latin1() );
550#ifndef _WIN32_ 550#ifndef _WIN32_
551 if ( vfork () == 0 ) { 551 if ( vfork () == 0 ) {
552 execl ( tempfilename.latin1(), 0 ); 552 execl ( tempfilename.latin1(), 0 );
553 return; 553 return;
554 } 554 }
555#else 555#else
556 QProcess* p = new QProcess(); 556 QProcess* p = new QProcess();
557 p->addArgument( tempfilename.latin1() ); 557 p->addArgument( tempfilename.latin1() );
558 p->start(); 558 p->start();
559 return; 559 return;
560#endif 560#endif
561 561
562 return; 562 return;
563 } 563 }
564 564
565 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 565 //qDebug("+++++++system command %s ",tempfilename.latin1() );
566 } 566 }
567 if ( mess.left( 11 ) == "audio_alarm") { 567 if ( mess.left( 11 ) == "audio_alarm") {
568 bool error = false; 568 bool error = false;
569 int len = mess.mid( 11 ).find("+++"); 569 int len = mess.mid( 11 ).find("+++");
570 if ( len < 2 ) 570 if ( len < 2 )
571 error = true; 571 error = true;
572 else { 572 else {
573 tempfilename = mess.mid( 11, len ); 573 tempfilename = mess.mid( 11, len );
574 if ( !QFile::exists( tempfilename ) ) 574 if ( !QFile::exists( tempfilename ) )
575 error = true; 575 error = true;
576 } 576 }
577 if ( ! error ) { 577 if ( ! error ) {
578 filename = tempfilename; 578 filename = tempfilename;
579 } 579 }
580 mAlarmMessage = mess.mid( 11+len+3+9 ); 580 mAlarmMessage = mess.mid( 11+len+3+9 );
581 //qDebug("audio file command %s ",tempfilename.latin1() ); 581 //qDebug("audio file command %s ",tempfilename.latin1() );
582 } 582 }
583 if ( mess.left( 9 ) == "cal_alarm") { 583 if ( mess.left( 9 ) == "cal_alarm") {
584 mAlarmMessage = mess.mid( 9 ) ; 584 mAlarmMessage = mess.mid( 9 ) ;
585 } 585 }
586 586
587 startAlarm( mAlarmMessage, filename ); 587 startAlarm( mAlarmMessage, filename );
588 588
589 589
590} 590}
591 591
592void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 592void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
593{ 593{
594 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 594 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
595 595
596 mSuspendAlarmNotification = noti; 596 mSuspendAlarmNotification = noti;
597 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 597 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
598 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 598 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
599 mSuspendTimer->start( ms , true ); 599 mSuspendTimer->start( ms , true );
600 600
601} 601}
602 602
603void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 603void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
604{ 604{
605 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 605 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
606 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 606 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
607#ifndef DESKTOP_VERSION 607#ifndef DESKTOP_VERSION
608 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 608 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
609#endif 609#endif
610 return; 610 return;
611 } 611 }
612 int maxSec; 612 int maxSec;
613 //maxSec = 5; //testing only 613 //maxSec = 5; //testing only
614 maxSec = 86400+3600; // one day+1hour 614 maxSec = 86400+3600; // one day+1hour
615 mAlarmNotification = noti; 615 mAlarmNotification = noti;
616 int sec = QDateTime::currentDateTime().secsTo( qdt ); 616 int sec = QDateTime::currentDateTime().secsTo( qdt );
617 if ( sec > maxSec ) { 617 if ( sec > maxSec ) {
618 mRecheckAlarmTimer->start( maxSec * 1000 ); 618 mRecheckAlarmTimer->start( maxSec * 1000 );
619 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 619 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
620 return; 620 return;
621 } else { 621 } else {
622 mRecheckAlarmTimer->stop(); 622 mRecheckAlarmTimer->stop();
623 } 623 }
624 //qDebug("Alarm timer started with secs: %d ", sec); 624 //qDebug("Alarm timer started with secs: %d ", sec);
625 mAlarmTimer->start( sec *1000 , true ); 625 mAlarmTimer->start( sec *1000 , true );
626 626
627} 627}
628// called by mRecheckAlarmTimer to get next alarm 628// called by mRecheckAlarmTimer to get next alarm
629// we need this, because a QTimer has only a max range of 25 days 629// we need this, because a QTimer has only a max range of 25 days
630void CalendarView::recheckTimerAlarm() 630void CalendarView::recheckTimerAlarm()
631{ 631{
632 mAlarmTimer->stop(); 632 mAlarmTimer->stop();
633 mRecheckAlarmTimer->stop(); 633 mRecheckAlarmTimer->stop();
634 mCalendar->checkAlarmForIncidence( 0, true ); 634 mCalendar->checkAlarmForIncidence( 0, true );
635} 635}
636void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 636void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
637{ 637{
638 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 638 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
639 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 639 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
640#ifndef DESKTOP_VERSION 640#ifndef DESKTOP_VERSION
641 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 641 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
642#endif 642#endif
643 return; 643 return;
644 } 644 }
645 mAlarmTimer->stop(); 645 mAlarmTimer->stop();
646} 646}
647void CalendarView::selectWeekNum ( int num ) 647void CalendarView::selectWeekNum ( int num )
648{ 648{
649 dateNavigator()->selectWeek( num ); 649 dateNavigator()->selectWeek( num );
650 mViewManager->showWeekView(); 650 mViewManager->showWeekView();
651} 651}
652KOViewManager *CalendarView::viewManager() 652KOViewManager *CalendarView::viewManager()
653{ 653{
654 return mViewManager; 654 return mViewManager;
655} 655}
656 656
657KODialogManager *CalendarView::dialogManager() 657KODialogManager *CalendarView::dialogManager()
658{ 658{
659 return mDialogManager; 659 return mDialogManager;
660} 660}
661 661
662QDate CalendarView::startDate() 662QDate CalendarView::startDate()
663{ 663{
664 DateList dates = mNavigator->selectedDates(); 664 DateList dates = mNavigator->selectedDates();
665 665
666 return dates.first(); 666 return dates.first();
667} 667}
668 668
669QDate CalendarView::endDate() 669QDate CalendarView::endDate()
670{ 670{
671 DateList dates = mNavigator->selectedDates(); 671 DateList dates = mNavigator->selectedDates();
672 672
673 return dates.last(); 673 return dates.last();
674} 674}
675 675
676 676
677void CalendarView::createPrinter() 677void CalendarView::createPrinter()
678{ 678{
679#ifndef KORG_NOPRINTER 679#ifndef KORG_NOPRINTER
680 if (!mCalPrinter) { 680 if (!mCalPrinter) {
681 mCalPrinter = new CalPrinter(this, mCalendar); 681 mCalPrinter = new CalPrinter(this, mCalendar);
682 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 682 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
683 } 683 }
684#endif 684#endif
685} 685}
686 686
687void CalendarView::confSync() 687void CalendarView::confSync()
688{ 688{
689 static KSyncPrefsDialog* sp = 0; 689 static KSyncPrefsDialog* sp = 0;
690 if ( ! sp ) { 690 if ( ! sp ) {
691 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 691 sp = new KSyncPrefsDialog( this, "syncprefs", true );
692 } 692 }
693 sp->usrReadConfig(); 693 sp->usrReadConfig();
694#ifndef DESKTOP_VERSION 694#ifndef DESKTOP_VERSION
695 sp->showMaximized(); 695 sp->showMaximized();
696#else 696#else
697 sp->show(); 697 sp->show();
698#endif 698#endif
699 sp->exec(); 699 sp->exec();
700 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 700 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
701 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 701 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
702} 702}
703 703
704 704
705//KOPrefs::instance()->mWriteBackFile 705//KOPrefs::instance()->mWriteBackFile
706//KOPrefs::instance()->mWriteBackExistingOnly 706//KOPrefs::instance()->mWriteBackExistingOnly
707 707
708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
714 714
715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
716{ 716{
717 717
718 //void setZaurusId(int id); 718 //void setZaurusId(int id);
719 // int zaurusId() const; 719 // int zaurusId() const;
720 // void setZaurusUid(int id); 720 // void setZaurusUid(int id);
721 // int zaurusUid() const; 721 // int zaurusUid() const;
722 // void setZaurusStat(int id); 722 // void setZaurusStat(int id);
723 // int zaurusStat() const; 723 // int zaurusStat() const;
724 // 0 equal 724 // 0 equal
725 // 1 take local 725 // 1 take local
726 // 2 take remote 726 // 2 take remote
727 // 3 cancel 727 // 3 cancel
728 QDateTime lastSync = mLastCalendarSync; 728 QDateTime lastSync = mLastCalendarSync;
729 QDateTime localMod = local->lastModified();
730 QDateTime remoteMod = remote->lastModified();
729 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 731 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
730 bool remCh, locCh; 732 bool remCh, locCh;
731 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 733 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
732 //if ( remCh ) 734 //if ( remCh )
733 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 735 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
734 locCh = ( local->lastModified() > mLastCalendarSync ); 736 locCh = ( localMod > mLastCalendarSync );
735 if ( !remCh && ! locCh ) { 737 if ( !remCh && ! locCh ) {
736 //qDebug("both not changed "); 738 //qDebug("both not changed ");
737 lastSync = local->lastModified().addDays(1); 739 lastSync = localMod.addDays(1);
738 if ( mode <= SYNC_PREF_ASK ) 740 if ( mode <= SYNC_PREF_ASK )
739 return 0; 741 return 0;
740 } else { 742 } else {
741 if ( locCh ) { 743 if ( locCh ) {
742 //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1()); 744 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
743 lastSync = local->lastModified().addDays( -1 ); 745 lastSync = localMod.addDays( -1 );
744 if ( !remCh ) 746 if ( !remCh )
745 remote->setLastModified( lastSync.addDays( -1 ) ); 747 remoteMod = ( lastSync.addDays( -1 ) );
746 } else { 748 } else {
747 //qDebug(" not loc changed "); 749 //qDebug(" not loc changed ");
748 lastSync = local->lastModified().addDays( 1 ); 750 lastSync = localMod.addDays( 1 );
749 if ( remCh ) 751 if ( remCh )
750 remote->setLastModified( lastSync.addDays( 1 ) ); 752 remoteMod =( lastSync.addDays( 1 ) );
751 753
752 } 754 }
753 } 755 }
754 full = true; 756 full = true;
755 if ( mode < SYNC_PREF_ASK ) 757 if ( mode < SYNC_PREF_ASK )
756 mode = SYNC_PREF_ASK; 758 mode = SYNC_PREF_ASK;
757 } else { 759 } else {
758 if ( local->lastModified() == remote->lastModified() ) 760 if ( localMod == remoteMod )
759 if ( local->revision() == remote->revision() ) 761 if ( local->revision() == remote->revision() )
760 return 0; 762 return 0;
761 763
762 } 764 }
763 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 765 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
764 766
765 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 767 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
766 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 768 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
767 //full = true; //debug only 769 //full = true; //debug only
768 if ( full ) { 770 if ( full ) {
769 bool equ = false; 771 bool equ = false;
770 if ( local->type() == "Event" ) { 772 if ( local->type() == "Event" ) {
771 equ = (*((Event*) local) == *((Event*) remote)); 773 equ = (*((Event*) local) == *((Event*) remote));
772 } 774 }
773 else if ( local->type() =="Todo" ) 775 else if ( local->type() =="Todo" )
774 equ = (*((Todo*) local) == (*(Todo*) remote)); 776 equ = (*((Todo*) local) == (*(Todo*) remote));
775 else if ( local->type() =="Journal" ) 777 else if ( local->type() =="Journal" )
776 equ = (*((Journal*) local) == *((Journal*) remote)); 778 equ = (*((Journal*) local) == *((Journal*) remote));
777 if ( equ ) { 779 if ( equ ) {
778 //qDebug("equal "); 780 //qDebug("equal ");
779 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 781 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
780 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 782 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
781 } 783 }
782 if ( mode < SYNC_PREF_FORCE_LOCAL ) 784 if ( mode < SYNC_PREF_FORCE_LOCAL )
783 return 0; 785 return 0;
784 786
785 }//else //debug only 787 }//else //debug only
786 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 788 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
787 } 789 }
788 int result; 790 int result;
789 bool localIsNew; 791 bool localIsNew;
790 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 792 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
791 793
792 if ( full && mode < SYNC_PREF_NEWEST ) 794 if ( full && mode < SYNC_PREF_NEWEST )
793 mode = SYNC_PREF_ASK; 795 mode = SYNC_PREF_ASK;
794 796
795 switch( mode ) { 797 switch( mode ) {
796 case SYNC_PREF_LOCAL: 798 case SYNC_PREF_LOCAL:
797 if ( lastSync > remote->lastModified() ) 799 if ( lastSync > remoteMod )
798 return 1; 800 return 1;
799 if ( lastSync > local->lastModified() ) 801 if ( lastSync > localMod )
800 return 2; 802 return 2;
801 return 1; 803 return 1;
802 break; 804 break;
803 case SYNC_PREF_REMOTE: 805 case SYNC_PREF_REMOTE:
804 if ( lastSync > remote->lastModified() ) 806 if ( lastSync > remoteMod )
805 return 1; 807 return 1;
806 if ( lastSync > local->lastModified() ) 808 if ( lastSync > localMod )
807 return 2; 809 return 2;
808 return 2; 810 return 2;
809 break; 811 break;
810 case SYNC_PREF_NEWEST: 812 case SYNC_PREF_NEWEST:
811 if ( local->lastModified() > remote->lastModified() ) 813 if ( localMod > remoteMod )
812 return 1; 814 return 1;
813 else 815 else
814 return 2; 816 return 2;
815 break; 817 break;
816 case SYNC_PREF_ASK: 818 case SYNC_PREF_ASK:
817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 819 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
818 if ( lastSync > remote->lastModified() ) 820 if ( lastSync > remoteMod )
819 return 1; 821 return 1;
820 if ( lastSync > local->lastModified() ) 822 if ( lastSync > localMod )
821 return 2; 823 return 2;
822 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 824 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
823 localIsNew = local->lastModified() >= remote->lastModified(); 825 localIsNew = localMod >= remoteMod;
824 if ( localIsNew ) 826 if ( localIsNew )
825 getEventViewerDialog()->setColorMode( 1 ); 827 getEventViewerDialog()->setColorMode( 1 );
826 else 828 else
827 getEventViewerDialog()->setColorMode( 2 ); 829 getEventViewerDialog()->setColorMode( 2 );
828 getEventViewerDialog()->setIncidence(local); 830 getEventViewerDialog()->setIncidence(local);
829 if ( localIsNew ) 831 if ( localIsNew )
830 getEventViewerDialog()->setColorMode( 2 ); 832 getEventViewerDialog()->setColorMode( 2 );
831 else 833 else
832 getEventViewerDialog()->setColorMode( 1 ); 834 getEventViewerDialog()->setColorMode( 1 );
833 getEventViewerDialog()->addIncidence(remote); 835 getEventViewerDialog()->addIncidence(remote);
834 getEventViewerDialog()->setColorMode( 0 ); 836 getEventViewerDialog()->setColorMode( 0 );
835 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 837 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
836 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 838 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
837 getEventViewerDialog()->showMe(); 839 getEventViewerDialog()->showMe();
838 result = getEventViewerDialog()->executeS( localIsNew ); 840 result = getEventViewerDialog()->executeS( localIsNew );
839 return result; 841 return result;
840 842
841 break; 843 break;
842 case SYNC_PREF_FORCE_LOCAL: 844 case SYNC_PREF_FORCE_LOCAL:
843 return 1; 845 return 1;
844 break; 846 break;
845 case SYNC_PREF_FORCE_REMOTE: 847 case SYNC_PREF_FORCE_REMOTE:
846 return 2; 848 return 2;
847 break; 849 break;
848 850
849 default: 851 default:
850 // SYNC_PREF_TAKE_BOTH not implemented 852 // SYNC_PREF_TAKE_BOTH not implemented
851 break; 853 break;
852 } 854 }
853 return 0; 855 return 0;
854} 856}
855Event* CalendarView::getLastSyncEvent() 857Event* CalendarView::getLastSyncEvent()
856{ 858{
857 Event* lse; 859 Event* lse;
858 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 860 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
859 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 861 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
860 if (!lse) { 862 if (!lse) {
861 lse = new Event(); 863 lse = new Event();
862 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 864 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
863 QString sum = ""; 865 QString sum = "";
864 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 866 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
865 sum = "E: "; 867 sum = "E: ";
866 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 868 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
867 lse->setDtStart( mLastCalendarSync ); 869 lse->setDtStart( mLastCalendarSync );
868 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 870 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
869 lse->setCategories( i18n("SyncEvent") ); 871 lse->setCategories( i18n("SyncEvent") );
870 lse->setReadOnly( true ); 872 lse->setReadOnly( true );
871 mCalendar->addEvent( lse ); 873 mCalendar->addEvent( lse );
872 } 874 }
873 875
874 return lse; 876 return lse;
875 877
876} 878}
877// probaly useless 879// probaly useless
878void CalendarView::setupExternSyncProfiles() 880void CalendarView::setupExternSyncProfiles()
879{ 881{
880 Event* lse; 882 Event* lse;
881 mExternLastSyncEvent.clear(); 883 mExternLastSyncEvent.clear();
882 int i; 884 int i;
883 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { 885 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) {
884 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); 886 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] );
885 if ( lse ) 887 if ( lse )
886 mExternLastSyncEvent.append( lse ); 888 mExternLastSyncEvent.append( lse );
887 else 889 else
888 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); 890 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1());
889 } 891 }
890 892
891} 893}
892// we check, if the to delete event has a id for a profile 894// we check, if the to delete event has a id for a profile
893// if yes, we set this id in the profile to delete 895// if yes, we set this id in the profile to delete
894void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 896void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
895{ 897{
896 if ( lastSync.count() == 0 ) { 898 if ( lastSync.count() == 0 ) {
897 //qDebug(" lastSync.count() == 0"); 899 //qDebug(" lastSync.count() == 0");
898 return; 900 return;
899 } 901 }
900 if ( toDelete->type() == "Journal" ) 902 if ( toDelete->type() == "Journal" )
901 return; 903 return;
902 904
903 Event* eve = lastSync.first(); 905 Event* eve = lastSync.first();
904 906
905 while ( eve ) { 907 while ( eve ) {
906 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 908 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
907 if ( !id.isEmpty() ) { 909 if ( !id.isEmpty() ) {
908 QString des = eve->description(); 910 QString des = eve->description();
909 QString pref = "e"; 911 QString pref = "e";
910 if ( toDelete->type() == "Todo" ) 912 if ( toDelete->type() == "Todo" )
911 pref = "t"; 913 pref = "t";
912 des += pref+ id + ","; 914 des += pref+ id + ",";
913 eve->setReadOnly( false ); 915 eve->setReadOnly( false );
914 eve->setDescription( des ); 916 eve->setDescription( des );
915 //qDebug("setdes %s ", des.latin1()); 917 //qDebug("setdes %s ", des.latin1());
916 eve->setReadOnly( true ); 918 eve->setReadOnly( true );
917 } 919 }
918 eve = lastSync.next(); 920 eve = lastSync.next();
919 } 921 }
920 922
921} 923}
922void CalendarView::checkExternalId( Incidence * inc ) 924void CalendarView::checkExternalId( Incidence * inc )
923{ 925{
924 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 926 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
925 checkExternSyncEvent( lastSync, inc ); 927 checkExternSyncEvent( lastSync, inc );
926 928
927} 929}
928bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 930bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
929{ 931{
930 bool syncOK = true; 932 bool syncOK = true;
931 int addedEvent = 0; 933 int addedEvent = 0;
932 int addedEventR = 0; 934 int addedEventR = 0;
933 int deletedEventR = 0; 935 int deletedEventR = 0;
934 int deletedEventL = 0; 936 int deletedEventL = 0;
935 int changedLocal = 0; 937 int changedLocal = 0;
936 int changedRemote = 0; 938 int changedRemote = 0;
937 //QPtrList<Event> el = local->rawEvents(); 939 //QPtrList<Event> el = local->rawEvents();
938 Event* eventR; 940 Event* eventR;
939 QString uid; 941 QString uid;
940 int take; 942 int take;
941 Event* eventL; 943 Event* eventL;
942 Event* eventRSync; 944 Event* eventRSync;
943 Event* eventLSync; 945 Event* eventLSync;
944 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 946 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
945 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 947 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
946 bool fullDateRange = false; 948 bool fullDateRange = false;
947 local->resetTempSyncStat(); 949 local->resetTempSyncStat();
948 mLastCalendarSync = QDateTime::currentDateTime(); 950 mLastCalendarSync = QDateTime::currentDateTime();
949 QDateTime modifiedCalendar = mLastCalendarSync;; 951 QDateTime modifiedCalendar = mLastCalendarSync;;
950 eventLSync = getLastSyncEvent(); 952 eventLSync = getLastSyncEvent();
951 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 953 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
952 if ( eventR ) { 954 if ( eventR ) {
953 eventRSync = (Event*) eventR->clone(); 955 eventRSync = (Event*) eventR->clone();
954 remote->deleteEvent(eventR ); 956 remote->deleteEvent(eventR );
955 957
956 } else { 958 } else {
957 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 959 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
958 eventRSync = (Event*)eventLSync->clone(); 960 eventRSync = (Event*)eventLSync->clone();
959 } else { 961 } else {
960 fullDateRange = true; 962 fullDateRange = true;
961 eventRSync = new Event(); 963 eventRSync = new Event();
962 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 964 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
963 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 965 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
964 eventRSync->setDtStart( mLastCalendarSync ); 966 eventRSync->setDtStart( mLastCalendarSync );
965 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 967 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
966 eventRSync->setCategories( i18n("SyncEvent") ); 968 eventRSync->setCategories( i18n("SyncEvent") );
967 } 969 }
968 } 970 }
969 if ( eventLSync->dtStart() == mLastCalendarSync ) 971 if ( eventLSync->dtStart() == mLastCalendarSync )
970 fullDateRange = true; 972 fullDateRange = true;
971 973
972 if ( ! fullDateRange ) { 974 if ( ! fullDateRange ) {
973 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 975 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
974 976
975 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 977 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
976 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 978 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
977 fullDateRange = true; 979 fullDateRange = true;
978 } 980 }
979 } 981 }
980 if ( fullDateRange ) 982 if ( fullDateRange )
981 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 983 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
982 else 984 else
983 mLastCalendarSync = eventLSync->dtStart(); 985 mLastCalendarSync = eventLSync->dtStart();
984 // for resyncing if own file has changed 986 // for resyncing if own file has changed
985 if ( mCurrentSyncDevice == "deleteaftersync" ) { 987 if ( mCurrentSyncDevice == "deleteaftersync" ) {
986 mLastCalendarSync = loadedFileVersion; 988 mLastCalendarSync = loadedFileVersion;
987 qDebug("setting mLastCalendarSync "); 989 qDebug("setting mLastCalendarSync ");
988 } 990 }
989 //qDebug("*************************** "); 991 //qDebug("*************************** ");
990 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 992 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
991 QPtrList<Incidence> er = remote->rawIncidences(); 993 QPtrList<Incidence> er = remote->rawIncidences();
992 Incidence* inR = er.first(); 994 Incidence* inR = er.first();
993 Incidence* inL; 995 Incidence* inL;
994 QProgressBar bar( er.count(),0 ); 996 QProgressBar bar( er.count(),0 );
995 bar.setCaption (i18n("Syncing - close to abort!") ); 997 bar.setCaption (i18n("Syncing - close to abort!") );
996 998
997 int w = 300; 999 int w = 300;
998 if ( QApplication::desktop()->width() < 320 ) 1000 if ( QApplication::desktop()->width() < 320 )
999 w = 220; 1001 w = 220;
1000 int h = bar.sizeHint().height() ; 1002 int h = bar.sizeHint().height() ;
1001 int dw = QApplication::desktop()->width(); 1003 int dw = QApplication::desktop()->width();
1002 int dh = QApplication::desktop()->height(); 1004 int dh = QApplication::desktop()->height();
1003 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1005 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1004 bar.show(); 1006 bar.show();
1005 int modulo = (er.count()/10)+1; 1007 int modulo = (er.count()/10)+1;
1006 int incCounter = 0; 1008 int incCounter = 0;
1007 while ( inR ) { 1009 while ( inR ) {
1008 if ( ! bar.isVisible() ) 1010 if ( ! bar.isVisible() )
1009 return false; 1011 return false;
1010 if ( incCounter % modulo == 0 ) 1012 if ( incCounter % modulo == 0 )
1011 bar.setProgress( incCounter ); 1013 bar.setProgress( incCounter );
1012 ++incCounter; 1014 ++incCounter;
1013 uid = inR->uid(); 1015 uid = inR->uid();
1014 bool skipIncidence = false; 1016 bool skipIncidence = false;
1015 if ( uid.left(15) == QString("last-syncEvent-") ) 1017 if ( uid.left(15) == QString("last-syncEvent-") )