summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp7
-rw-r--r--kaddressbook/kabcore.cpp23
-rw-r--r--kaddressbook/viewmanager.cpp5
-rw-r--r--kaddressbook/viewmanager.h1
-rw-r--r--korganizer/calendarview.cpp15
-rw-r--r--korganizer/calendarview.h1
-rw-r--r--libkdepim/ksyncmanager.cpp22
-rw-r--r--libkdepim/ksyncmanager.h2
8 files changed, 61 insertions, 15 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index d101589..9b196b5 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -481,760 +481,763 @@ int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool remo
481{ 481{
482 482
483 if ( removeOld ) 483 if ( removeOld )
484 setUntagged( true ); 484 setUntagged( true );
485 KABC::Addressee::List list; 485 KABC::Addressee::List list;
486 QFile file( fileName ); 486 QFile file( fileName );
487 file.open( IO_ReadOnly ); 487 file.open( IO_ReadOnly );
488 QByteArray rawData = file.readAll(); 488 QByteArray rawData = file.readAll();
489 file.close(); 489 file.close();
490 QString data; 490 QString data;
491 if ( replaceLabel ) { 491 if ( replaceLabel ) {
492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
493 data.replace ( QRegExp("LABEL") , "ADR" ); 493 data.replace ( QRegExp("LABEL") , "ADR" );
494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
495 } else 495 } else
496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
497 KABC::VCardTool tool; 497 KABC::VCardTool tool;
498 list = tool.parseVCards( data ); 498 list = tool.parseVCards( data );
499 KABC::Addressee::List::Iterator it; 499 KABC::Addressee::List::Iterator it;
500 for ( it = list.begin(); it != list.end(); ++it ) { 500 for ( it = list.begin(); it != list.end(); ++it ) {
501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
502 if ( !id.isEmpty() ) 502 if ( !id.isEmpty() )
503 (*it).setIDStr(id ); 503 (*it).setIDStr(id );
504 (*it).setResource( 0 ); 504 (*it).setResource( 0 );
505 if ( replaceLabel ) 505 if ( replaceLabel )
506 (*it).removeVoice(); 506 (*it).removeVoice();
507 if ( removeOld ) 507 if ( removeOld )
508 (*it).setTagged( true ); 508 (*it).setTagged( true );
509 insertAddressee( (*it), false, true ); 509 insertAddressee( (*it), false, true );
510 } 510 }
511 if ( removeOld ) 511 if ( removeOld )
512 removeUntagged(); 512 removeUntagged();
513 return list.count(); 513 return list.count();
514} 514}
515void AddressBook::setUntagged(bool setNonSyncTagged) // = false) 515void AddressBook::setUntagged(bool setNonSyncTagged) // = false)
516{ 516{
517 Iterator ait; 517 Iterator ait;
518 for ( ait = begin(); ait != end(); ++ait ) { 518 for ( ait = begin(); ait != end(); ++ait ) {
519 if ( setNonSyncTagged ) { 519 if ( setNonSyncTagged ) {
520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { 520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
521 (*ait).setTagged( true ); 521 (*ait).setTagged( true );
522 } else 522 } else
523 (*ait).setTagged( false ); 523 (*ait).setTagged( false );
524 } else 524 } else
525 (*ait).setTagged( false ); 525 (*ait).setTagged( false );
526 } 526 }
527} 527}
528void AddressBook::removeUntagged() 528void AddressBook::removeUntagged()
529{ 529{
530 Iterator ait; 530 Iterator ait;
531 bool todelete = false; 531 bool todelete = false;
532 Iterator todel; 532 Iterator todel;
533 for ( ait = begin(); ait != end(); ++ait ) { 533 for ( ait = begin(); ait != end(); ++ait ) {
534 if ( todelete ) 534 if ( todelete )
535 removeAddressee( todel ); 535 removeAddressee( todel );
536 if (!(*ait).tagged()) { 536 if (!(*ait).tagged()) {
537 todelete = true; 537 todelete = true;
538 todel = ait; 538 todel = ait;
539 } else 539 } else
540 todelete = false; 540 todelete = false;
541 } 541 }
542 if ( todelete ) 542 if ( todelete )
543 removeAddressee( todel ); 543 removeAddressee( todel );
544 deleteRemovedAddressees(); 544 deleteRemovedAddressees();
545} 545}
546void AddressBook::smplifyAddressees() 546void AddressBook::smplifyAddressees()
547{ 547{
548 Iterator ait; 548 Iterator ait;
549 for ( ait = begin(); ait != end(); ++ait ) { 549 for ( ait = begin(); ait != end(); ++ait ) {
550 (*ait).simplifyEmails(); 550 (*ait).simplifyEmails();
551 (*ait).simplifyPhoneNumbers(); 551 (*ait).simplifyPhoneNumbers();
552 (*ait).simplifyPhoneNumberTypes(); 552 (*ait).simplifyPhoneNumberTypes();
553 (*ait).simplifyAddresses(); 553 (*ait).simplifyAddresses();
554 } 554 }
555} 555}
556void AddressBook::removeSyncInfo( QString syncProfile) 556void AddressBook::removeSyncInfo( QString syncProfile)
557{ 557{
558 Iterator ait; 558 Iterator ait;
559 for ( ait = begin(); ait != end(); ++ait ) { 559 for ( ait = begin(); ait != end(); ++ait ) {
560 (*ait).removeID( syncProfile ); 560 (*ait).removeID( syncProfile );
561 } 561 }
562 if ( syncProfile.isEmpty() ) { 562 if ( syncProfile.isEmpty() ) {
563 Iterator it = begin(); 563 Iterator it = begin();
564 Iterator it2 ; 564 Iterator it2 ;
565 QDateTime dt ( QDate( 2004,1,1) ); 565 QDateTime dt ( QDate( 2004,1,1) );
566 while ( it != end() ) { 566 while ( it != end() ) {
567 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 567 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
568 it2 = it; 568 it2 = it;
569 //qDebug("removing %s ",(*it).uid().latin1() ); 569 //qDebug("removing %s ",(*it).uid().latin1() );
570 ++it; 570 ++it;
571 removeAddressee( it2 ); 571 removeAddressee( it2 );
572 } else { 572 } else {
573 //qDebug("skipping %s ",(*it).uid().latin1() ); 573 //qDebug("skipping %s ",(*it).uid().latin1() );
574 ++it; 574 ++it;
575 } 575 }
576 } 576 }
577 } else { 577 } else {
578 Addressee lse; 578 Addressee lse;
579 lse = findByUid( "last-syncAddressee-"+ syncProfile ); 579 lse = findByUid( "last-syncAddressee-"+ syncProfile );
580 if ( ! lse.isEmpty() ) 580 if ( ! lse.isEmpty() )
581 removeAddressee( lse ); 581 removeAddressee( lse );
582 } 582 }
583 583
584} 584}
585void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 585void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
586{ 586{
587 Iterator ait; 587 Iterator ait;
588 for ( ait = begin(); ait != end(); ++ait ) { 588 for ( ait = begin(); ait != end(); ++ait ) {
589 QString id = (*ait).IDStr(); 589 QString id = (*ait).IDStr();
590 (*ait).setIDStr( ":"); 590 (*ait).setIDStr( ":");
591 (*ait).setExternalUID( id ); 591 (*ait).setExternalUID( id );
592 (*ait).setOriginalExternalUID( id ); 592 (*ait).setOriginalExternalUID( id );
593 if ( isPreSync ) 593 if ( isPreSync )
594 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 594 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
595 else { 595 else {
596 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 596 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
597 (*ait).setID( currentSyncDevice,id ); 597 (*ait).setID( currentSyncDevice,id );
598 598
599 } 599 }
600 } 600 }
601} 601}
602void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 602void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
603{ 603{
604 604
605 setUntagged(); 605 setUntagged();
606 KABC::Addressee::List list; 606 KABC::Addressee::List list;
607 QFile file( fileName ); 607 QFile file( fileName );
608 file.open( IO_ReadOnly ); 608 file.open( IO_ReadOnly );
609 QByteArray rawData = file.readAll(); 609 QByteArray rawData = file.readAll();
610 file.close(); 610 file.close();
611 QString data; 611 QString data;
612 612
613 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 613 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
614 KABC::VCardTool tool; 614 KABC::VCardTool tool;
615 list = tool.parseVCards( data ); 615 list = tool.parseVCards( data );
616 KABC::Addressee::List::Iterator it; 616 KABC::Addressee::List::Iterator it;
617 for ( it = list.begin(); it != list.end(); ++it ) { 617 for ( it = list.begin(); it != list.end(); ++it ) {
618 Iterator ait; 618 Iterator ait;
619 for ( ait = begin(); ait != end(); ++ait ) { 619 for ( ait = begin(); ait != end(); ++ait ) {
620 if ( !(*ait).tagged() ) { 620 if ( !(*ait).tagged() ) {
621 if ( (*ait).containsAdr(*it)) { 621 if ( (*ait).containsAdr(*it)) {
622 (*ait).setTagged(true); 622 (*ait).setTagged(true);
623 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 623 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
624 (*it).setIDStr( ":"); 624 (*it).setIDStr( ":");
625 (*it).setID( currentSyncDevice,id ); 625 (*it).setID( currentSyncDevice,id );
626 (*it).setExternalUID( id ); 626 (*it).setExternalUID( id );
627 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 627 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
628 (*it).setUid( ( (*ait).uid() )); 628 (*it).setUid( ( (*ait).uid() ));
629 break; 629 break;
630 } 630 }
631 } 631 }
632 632
633 } 633 }
634 if ( ait == end() ) 634 if ( ait == end() )
635 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); 635 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
636 } 636 }
637 clear(); 637 clear();
638 for ( it = list.begin(); it != list.end(); ++it ) { 638 for ( it = list.begin(); it != list.end(); ++it ) {
639 insertAddressee( (*it) ); 639 insertAddressee( (*it) );
640 } 640 }
641} 641}
642 642
643bool AddressBook::saveABphone( QString fileName ) 643bool AddressBook::saveABphone( QString fileName )
644{ 644{
645 //smplifyAddressees(); 645 //smplifyAddressees();
646 qDebug("saveABphone:: saving AB... "); 646 qDebug("saveABphone:: saving AB... ");
647 if ( ! export2PhoneFormat( QStringList() ,fileName ) ) 647 if ( ! export2PhoneFormat( QStringList() ,fileName ) )
648 return false; 648 return false;
649 qDebug("saveABphone:: writing to phone... "); 649 qDebug("saveABphone:: writing to phone... ");
650 if ( !PhoneAccess::writeToPhone( fileName) ) { 650 if ( !PhoneAccess::writeToPhone( fileName) ) {
651 return false; 651 return false;
652 } 652 }
653 qDebug("saveABphone:: re-reading from phone... "); 653 qDebug("saveABphone:: re-reading from phone... ");
654 if ( !PhoneAccess::readFromPhone( fileName) ) { 654 if ( !PhoneAccess::readFromPhone( fileName) ) {
655 return false; 655 return false;
656 } 656 }
657 return true; 657 return true;
658} 658}
659bool AddressBook::saveAB() 659bool AddressBook::saveAB()
660{ 660{
661 bool ok = true; 661 bool ok = true;
662 662
663 deleteRemovedAddressees(); 663 deleteRemovedAddressees();
664 Iterator ait; 664 Iterator ait;
665 for ( ait = begin(); ait != end(); ++ait ) { 665 for ( ait = begin(); ait != end(); ++ait ) {
666 if ( !(*ait).IDStr().isEmpty() ) { 666 if ( !(*ait).IDStr().isEmpty() ) {
667 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 667 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
668 } 668 }
669 } 669 }
670 KRES::Manager<Resource>::ActiveIterator it; 670 KRES::Manager<Resource>::ActiveIterator it;
671 KRES::Manager<Resource> *manager = d->mManager; 671 KRES::Manager<Resource> *manager = d->mManager;
672 qDebug("SaveAB::saving..." ); 672 qDebug("SaveAB::saving..." );
673 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 673 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
674 qDebug("SaveAB::checking resource..." ); 674 qDebug("SaveAB::checking resource..." );
675 if ( (*it)->readOnly() ) 675 if ( (*it)->readOnly() )
676 qDebug("resource is readonly." ); 676 qDebug("resource is readonly." );
677 if ( (*it)->isOpen() ) 677 if ( (*it)->isOpen() )
678 qDebug("resource is open" ); 678 qDebug("resource is open" );
679 679
680 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 680 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
681 Ticket *ticket = requestSaveTicket( *it ); 681 Ticket *ticket = requestSaveTicket( *it );
682 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 682 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
683 if ( !ticket ) { 683 if ( !ticket ) {
684 qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) 684 qDebug( i18n( "Unable to save to resource '%1'. It is locked." )
685 .arg( (*it)->resourceName() ) ); 685 .arg( (*it)->resourceName() ) );
686 return false; 686 return false;
687 } 687 }
688 688
689 //if ( !save( ticket ) ) 689 //if ( !save( ticket ) )
690 if ( ticket->resource() ) { 690 if ( ticket->resource() ) {
691 QString name = ticket->resource()->resourceName(); 691 QString name = ticket->resource()->resourceName();
692 if ( ! ticket->resource()->save( ticket ) ) 692 if ( ! ticket->resource()->save( ticket ) )
693 ok = false; 693 ok = false;
694 else 694 else
695 qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); 695 qDebug("StdAddressBook::resource saved '%s'", name.latin1() );
696 696
697 } else 697 } else
698 ok = false; 698 ok = false;
699 699
700 } 700 }
701 } 701 }
702 return ok; 702 return ok;
703} 703}
704 704
705AddressBook::Iterator AddressBook::begin() 705AddressBook::Iterator AddressBook::begin()
706{ 706{
707 Iterator it = Iterator(); 707 Iterator it = Iterator();
708 it.d->mIt = d->mAddressees.begin(); 708 it.d->mIt = d->mAddressees.begin();
709 return it; 709 return it;
710} 710}
711 711
712AddressBook::ConstIterator AddressBook::begin() const 712AddressBook::ConstIterator AddressBook::begin() const
713{ 713{
714 ConstIterator it = ConstIterator(); 714 ConstIterator it = ConstIterator();
715 it.d->mIt = d->mAddressees.begin(); 715 it.d->mIt = d->mAddressees.begin();
716 return it; 716 return it;
717} 717}
718 718
719AddressBook::Iterator AddressBook::end() 719AddressBook::Iterator AddressBook::end()
720{ 720{
721 Iterator it = Iterator(); 721 Iterator it = Iterator();
722 it.d->mIt = d->mAddressees.end(); 722 it.d->mIt = d->mAddressees.end();
723 return it; 723 return it;
724} 724}
725 725
726AddressBook::ConstIterator AddressBook::end() const 726AddressBook::ConstIterator AddressBook::end() const
727{ 727{
728 ConstIterator it = ConstIterator(); 728 ConstIterator it = ConstIterator();
729 it.d->mIt = d->mAddressees.end(); 729 it.d->mIt = d->mAddressees.end();
730 return it; 730 return it;
731} 731}
732 732
733void AddressBook::clear() 733void AddressBook::clear()
734{ 734{
735 d->mAddressees.clear(); 735 d->mAddressees.clear();
736} 736}
737 737
738Ticket *AddressBook::requestSaveTicket( Resource *resource ) 738Ticket *AddressBook::requestSaveTicket( Resource *resource )
739{ 739{
740 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 740 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
741 741
742 if ( !resource ) 742 if ( !resource )
743 { 743 {
744 qDebug("AddressBook::requestSaveTicket no resource" ); 744 qDebug("AddressBook::requestSaveTicket no resource" );
745 resource = standardResource(); 745 resource = standardResource();
746 } 746 }
747 747
748 KRES::Manager<Resource>::ActiveIterator it; 748 KRES::Manager<Resource>::ActiveIterator it;
749 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 749 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
750 if ( (*it) == resource ) { 750 if ( (*it) == resource ) {
751 if ( (*it)->readOnly() || !(*it)->isOpen() ) 751 if ( (*it)->readOnly() || !(*it)->isOpen() )
752 return 0; 752 return 0;
753 else 753 else
754 return (*it)->requestSaveTicket(); 754 return (*it)->requestSaveTicket();
755 } 755 }
756 } 756 }
757 757
758 return 0; 758 return 0;
759} 759}
760//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 760//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
761void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 761void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
762{ 762{
763 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 763 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
764 //qDebug("block insert "); 764 //qDebug("block insert ");
765 return; 765 return;
766 } 766 }
767 //qDebug("inserting.... %s ",a.uid().latin1() ); 767 //qDebug("inserting.... %s ",a.uid().latin1() );
768 bool found = false; 768 bool found = false;
769 Addressee::List::Iterator it; 769 Addressee::List::Iterator it;
770 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 770 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
771 if ( a.uid() == (*it).uid() ) { 771 if ( a.uid() == (*it).uid() ) {
772 772
773 bool changed = false; 773 bool changed = false;
774 Addressee addr = a; 774 Addressee addr = a;
775 if ( addr != (*it) ) 775 if ( addr != (*it) )
776 changed = true; 776 changed = true;
777 777
778 if ( takeResource ) { 778 if ( takeResource ) {
779 Resource * res = (*it).resource(); 779 Resource * res = (*it).resource();
780 (*it) = a; 780 (*it) = a;
781 (*it).setResource( res ); 781 (*it).setResource( res );
782 } else { 782 } else {
783 (*it) = a; 783 (*it) = a;
784 if ( (*it).resource() == 0 ) 784 if ( (*it).resource() == 0 )
785 (*it).setResource( standardResource() ); 785 (*it).setResource( standardResource() );
786 } 786 }
787 if ( changed ) { 787 if ( changed ) {
788 if ( setRev ) { 788 if ( setRev ) {
789 789
790 // get rid of micro seconds 790 // get rid of micro seconds
791 QDateTime dt = QDateTime::currentDateTime(); 791 QDateTime dt = QDateTime::currentDateTime();
792 QTime t = dt.time(); 792 QTime t = dt.time();
793 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 793 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
794 (*it).setRevision( dt ); 794 (*it).setRevision( dt );
795 } 795 }
796 (*it).setChanged( true ); 796 (*it).setChanged( true );
797 } 797 }
798 798
799 found = true; 799 found = true;
800 } else { 800 } else {
801 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 801 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
802 QString name = (*it).uid().mid( 19 ); 802 QString name = (*it).uid().mid( 19 );
803 Addressee b = a; 803 Addressee b = a;
804 QString id = b.getID( name ); 804 QString id = b.getID( name );
805 if ( ! id.isEmpty() ) { 805 if ( ! id.isEmpty() ) {
806 QString des = (*it).note(); 806 QString des = (*it).note();
807 int startN; 807 int startN;
808 if( (startN = des.find( id ) ) >= 0 ) { 808 if( (startN = des.find( id ) ) >= 0 ) {
809 int endN = des.find( ",", startN+1 ); 809 int endN = des.find( ",", startN+1 );
810 des = des.left( startN ) + des.mid( endN+1 ); 810 des = des.left( startN ) + des.mid( endN+1 );
811 (*it).setNote( des ); 811 (*it).setNote( des );
812 } 812 }
813 } 813 }
814 } 814 }
815 } 815 }
816 } 816 }
817 if ( found ) 817 if ( found )
818 return; 818 return;
819 d->mAddressees.append( a ); 819 d->mAddressees.append( a );
820 Addressee& addr = d->mAddressees.last(); 820 Addressee& addr = d->mAddressees.last();
821 if ( addr.resource() == 0 ) 821 if ( addr.resource() == 0 )
822 addr.setResource( standardResource() ); 822 addr.setResource( standardResource() );
823 823
824 addr.setChanged( true ); 824 addr.setChanged( true );
825} 825}
826 826
827void AddressBook::removeAddressee( const Addressee &a ) 827void AddressBook::removeAddressee( const Addressee &a )
828{ 828{
829 Iterator it; 829 Iterator it;
830 Iterator it2; 830 Iterator it2;
831 bool found = false; 831 bool found = false;
832 for ( it = begin(); it != end(); ++it ) { 832 for ( it = begin(); it != end(); ++it ) {
833 if ( a.uid() == (*it).uid() ) { 833 if ( a.uid() == (*it).uid() ) {
834 found = true; 834 found = true;
835 it2 = it; 835 it2 = it;
836 } else { 836 } else {
837 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 837 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
838 QString name = (*it).uid().mid( 19 ); 838 QString name = (*it).uid().mid( 19 );
839 Addressee b = a; 839 Addressee b = a;
840 QString id = b.getID( name ); 840 QString id = b.getID( name );
841 if ( ! id.isEmpty() ) { 841 if ( ! id.isEmpty() ) {
842 QString des = (*it).note(); 842 QString des = (*it).note();
843 if( des.find( id ) < 0 ) { 843 if( des.find( id ) < 0 ) {
844 des += id + ","; 844 des += id + ",";
845 (*it).setNote( des ); 845 (*it).setNote( des );
846 } 846 }
847 } 847 }
848 } 848 }
849 849
850 } 850 }
851 } 851 }
852 852
853 if ( found ) 853 if ( found )
854 removeAddressee( it2 ); 854 removeAddressee( it2 );
855 855
856} 856}
857 857
858void AddressBook::removeSyncAddressees( bool removeDeleted ) 858void AddressBook::removeSyncAddressees( bool removeDeleted )
859{ 859{
860 Iterator it = begin(); 860 Iterator it = begin();
861 Iterator it2 ; 861 Iterator it2 ;
862 QDateTime dt ( QDate( 2004,1,1) ); 862 QDateTime dt ( QDate( 2004,1,1) );
863 while ( it != end() ) { 863 while ( it != end() ) {
864 (*it).setRevision( dt ); 864 (*it).setRevision( dt );
865 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 865 if (( *it).IDStr() != "changed" ) {
866 (*it).setIDStr(""); 866 // "changed" is used for tagging changed addressees when syncing with KDE or OL
867 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
868 (*it).setIDStr("");
869 }
867 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 870 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
868 it2 = it; 871 it2 = it;
869 //qDebug("removing %s ",(*it).uid().latin1() ); 872 //qDebug("removing %s ",(*it).uid().latin1() );
870 ++it; 873 ++it;
871 removeAddressee( it2 ); 874 removeAddressee( it2 );
872 } else { 875 } else {
873 //qDebug("skipping %s ",(*it).uid().latin1() ); 876 //qDebug("skipping %s ",(*it).uid().latin1() );
874 ++it; 877 ++it;
875 } 878 }
876 } 879 }
877 deleteRemovedAddressees(); 880 deleteRemovedAddressees();
878} 881}
879 882
880void AddressBook::removeAddressee( const Iterator &it ) 883void AddressBook::removeAddressee( const Iterator &it )
881{ 884{
882 d->mRemovedAddressees.append( (*it) ); 885 d->mRemovedAddressees.append( (*it) );
883 d->mAddressees.remove( it.d->mIt ); 886 d->mAddressees.remove( it.d->mIt );
884} 887}
885 888
886AddressBook::Iterator AddressBook::find( const Addressee &a ) 889AddressBook::Iterator AddressBook::find( const Addressee &a )
887{ 890{
888 Iterator it; 891 Iterator it;
889 for ( it = begin(); it != end(); ++it ) { 892 for ( it = begin(); it != end(); ++it ) {
890 if ( a.uid() == (*it).uid() ) { 893 if ( a.uid() == (*it).uid() ) {
891 return it; 894 return it;
892 } 895 }
893 } 896 }
894 return end(); 897 return end();
895} 898}
896 899
897Addressee AddressBook::findByUid( const QString &uid ) 900Addressee AddressBook::findByUid( const QString &uid )
898{ 901{
899 Iterator it; 902 Iterator it;
900 for ( it = begin(); it != end(); ++it ) { 903 for ( it = begin(); it != end(); ++it ) {
901 if ( uid == (*it).uid() ) { 904 if ( uid == (*it).uid() ) {
902 return *it; 905 return *it;
903 } 906 }
904 } 907 }
905 return Addressee(); 908 return Addressee();
906} 909}
907void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) 910void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset )
908{ 911{
909 //qDebug("AddressBook::preExternSync "); 912 //qDebug("AddressBook::preExternSync ");
910 AddressBook::Iterator it; 913 AddressBook::Iterator it;
911 for ( it = begin(); it != end(); ++it ) { 914 for ( it = begin(); it != end(); ++it ) {
912 (*it).setID( csd, (*it).externalUID() ); 915 (*it).setID( csd, (*it).externalUID() );
913 (*it).computeCsum( csd ); 916 (*it).computeCsum( csd );
914 } 917 }
915 mergeAB( aBook ,csd, isSubset ); 918 mergeAB( aBook ,csd, isSubset );
916} 919}
917void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 920void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
918{ 921{
919 //qDebug("AddressBook::postExternSync "); 922 //qDebug("AddressBook::postExternSync ");
920 AddressBook::Iterator it; 923 AddressBook::Iterator it;
921 for ( it = begin(); it != end(); ++it ) { 924 for ( it = begin(); it != end(); ++it ) {
922 // qDebug("check uid %s ", (*it).uid().latin1() ); 925 // qDebug("check uid %s ", (*it).uid().latin1() );
923 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 926 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
924 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 927 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
925 Addressee ad = aBook->findByUid( ( (*it).uid() )); 928 Addressee ad = aBook->findByUid( ( (*it).uid() ));
926 if ( ad.isEmpty() ) { 929 if ( ad.isEmpty() ) {
927 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); 930 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
928 } else { 931 } else {
929 (*it).computeCsum( csd ); 932 (*it).computeCsum( csd );
930 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 933 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
931 ad.setID( csd, (*it).externalUID() ); 934 ad.setID( csd, (*it).externalUID() );
932 ad.setCsum( csd, (*it).getCsum( csd ) ); 935 ad.setCsum( csd, (*it).getCsum( csd ) );
933 aBook->insertAddressee( ad ); 936 aBook->insertAddressee( ad );
934 } 937 }
935 } 938 }
936 } 939 }
937} 940}
938 941
939bool AddressBook::containsExternalUid( const QString& uid ) 942bool AddressBook::containsExternalUid( const QString& uid )
940{ 943{
941 Iterator it; 944 Iterator it;
942 for ( it = begin(); it != end(); ++it ) { 945 for ( it = begin(); it != end(); ++it ) {
943 if ( uid == (*it).externalUID( ) ) 946 if ( uid == (*it).externalUID( ) )
944 return true; 947 return true;
945 } 948 }
946 return false; 949 return false;
947} 950}
948Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 951Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
949{ 952{
950 Iterator it; 953 Iterator it;
951 for ( it = begin(); it != end(); ++it ) { 954 for ( it = begin(); it != end(); ++it ) {
952 if ( uid == (*it).getID( profile ) ) 955 if ( uid == (*it).getID( profile ) )
953 return (*it); 956 return (*it);
954 } 957 }
955 return Addressee(); 958 return Addressee();
956} 959}
957void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) 960void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset )
958{ 961{
959 Iterator it; 962 Iterator it;
960 Addressee ad; 963 Addressee ad;
961 for ( it = begin(); it != end(); ++it ) { 964 for ( it = begin(); it != end(); ++it ) {
962 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 965 ad = aBook->findByExternUid( (*it).externalUID(), profile );
963 if ( !ad.isEmpty() ) { 966 if ( !ad.isEmpty() ) {
964 (*it).mergeContact( ad ,isSubset); 967 (*it).mergeContact( ad ,isSubset);
965 } 968 }
966 } 969 }
967#if 0 970#if 0
968 // test only 971 // test only
969 for ( it = begin(); it != end(); ++it ) { 972 for ( it = begin(); it != end(); ++it ) {
970 973
971 qDebug("uid %s ", (*it).uid().latin1()); 974 qDebug("uid %s ", (*it).uid().latin1());
972 } 975 }
973#endif 976#endif
974} 977}
975 978
976#if 0 979#if 0
977Addressee::List AddressBook::getExternLastSyncAddressees() 980Addressee::List AddressBook::getExternLastSyncAddressees()
978{ 981{
979 Addressee::List results; 982 Addressee::List results;
980 983
981 Iterator it; 984 Iterator it;
982 for ( it = begin(); it != end(); ++it ) { 985 for ( it = begin(); it != end(); ++it ) {
983 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 986 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
984 if ( (*it).familyName().left(4) == "!E: " ) 987 if ( (*it).familyName().left(4) == "!E: " )
985 results.append( *it ); 988 results.append( *it );
986 } 989 }
987 } 990 }
988 991
989 return results; 992 return results;
990} 993}
991#endif 994#endif
992void AddressBook::resetTempSyncStat() 995void AddressBook::resetTempSyncStat()
993{ 996{
994 Iterator it; 997 Iterator it;
995 for ( it = begin(); it != end(); ++it ) { 998 for ( it = begin(); it != end(); ++it ) {
996 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 999 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
997 } 1000 }
998 1001
999} 1002}
1000 1003
1001QStringList AddressBook:: uidList() 1004QStringList AddressBook:: uidList()
1002{ 1005{
1003 QStringList results; 1006 QStringList results;
1004 Iterator it; 1007 Iterator it;
1005 for ( it = begin(); it != end(); ++it ) { 1008 for ( it = begin(); it != end(); ++it ) {
1006 results.append( (*it).uid() ); 1009 results.append( (*it).uid() );
1007 } 1010 }
1008 return results; 1011 return results;
1009} 1012}
1010 1013
1011 1014
1012Addressee::List AddressBook::allAddressees() 1015Addressee::List AddressBook::allAddressees()
1013{ 1016{
1014 return d->mAddressees; 1017 return d->mAddressees;
1015 1018
1016} 1019}
1017 1020
1018Addressee::List AddressBook::findByName( const QString &name ) 1021Addressee::List AddressBook::findByName( const QString &name )
1019{ 1022{
1020 Addressee::List results; 1023 Addressee::List results;
1021 1024
1022 Iterator it; 1025 Iterator it;
1023 for ( it = begin(); it != end(); ++it ) { 1026 for ( it = begin(); it != end(); ++it ) {
1024 if ( name == (*it).realName() ) { 1027 if ( name == (*it).realName() ) {
1025 results.append( *it ); 1028 results.append( *it );
1026 } 1029 }
1027 } 1030 }
1028 1031
1029 return results; 1032 return results;
1030} 1033}
1031 1034
1032Addressee::List AddressBook::findByEmail( const QString &email ) 1035Addressee::List AddressBook::findByEmail( const QString &email )
1033{ 1036{
1034 Addressee::List results; 1037 Addressee::List results;
1035 QStringList mailList; 1038 QStringList mailList;
1036 1039
1037 Iterator it; 1040 Iterator it;
1038 for ( it = begin(); it != end(); ++it ) { 1041 for ( it = begin(); it != end(); ++it ) {
1039 mailList = (*it).emails(); 1042 mailList = (*it).emails();
1040 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 1043 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
1041 if ( email == (*ite) ) { 1044 if ( email == (*ite) ) {
1042 results.append( *it ); 1045 results.append( *it );
1043 } 1046 }
1044 } 1047 }
1045 } 1048 }
1046 1049
1047 return results; 1050 return results;
1048} 1051}
1049 1052
1050Addressee::List AddressBook::findByCategory( const QString &category ) 1053Addressee::List AddressBook::findByCategory( const QString &category )
1051{ 1054{
1052 Addressee::List results; 1055 Addressee::List results;
1053 1056
1054 Iterator it; 1057 Iterator it;
1055 for ( it = begin(); it != end(); ++it ) { 1058 for ( it = begin(); it != end(); ++it ) {
1056 if ( (*it).hasCategory( category) ) { 1059 if ( (*it).hasCategory( category) ) {
1057 results.append( *it ); 1060 results.append( *it );
1058 } 1061 }
1059 } 1062 }
1060 1063
1061 return results; 1064 return results;
1062} 1065}
1063 1066
1064void AddressBook::dump() const 1067void AddressBook::dump() const
1065{ 1068{
1066 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 1069 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
1067 1070
1068 ConstIterator it; 1071 ConstIterator it;
1069 for( it = begin(); it != end(); ++it ) { 1072 for( it = begin(); it != end(); ++it ) {
1070 (*it).dump(); 1073 (*it).dump();
1071 } 1074 }
1072 1075
1073 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 1076 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
1074} 1077}
1075 1078
1076QString AddressBook::identifier() 1079QString AddressBook::identifier()
1077{ 1080{
1078 QStringList identifier; 1081 QStringList identifier;
1079 1082
1080 1083
1081 KRES::Manager<Resource>::ActiveIterator it; 1084 KRES::Manager<Resource>::ActiveIterator it;
1082 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1085 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1083 if ( !(*it)->identifier().isEmpty() ) 1086 if ( !(*it)->identifier().isEmpty() )
1084 identifier.append( (*it)->identifier() ); 1087 identifier.append( (*it)->identifier() );
1085 } 1088 }
1086 1089
1087 return identifier.join( ":" ); 1090 return identifier.join( ":" );
1088} 1091}
1089 1092
1090Field::List AddressBook::fields( int category ) 1093Field::List AddressBook::fields( int category )
1091{ 1094{
1092 if ( d->mAllFields.isEmpty() ) { 1095 if ( d->mAllFields.isEmpty() ) {
1093 d->mAllFields = Field::allFields(); 1096 d->mAllFields = Field::allFields();
1094 } 1097 }
1095 1098
1096 if ( category == Field::All ) return d->mAllFields; 1099 if ( category == Field::All ) return d->mAllFields;
1097 1100
1098 Field::List result; 1101 Field::List result;
1099 Field::List::ConstIterator it; 1102 Field::List::ConstIterator it;
1100 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 1103 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
1101 if ( (*it)->category() & category ) result.append( *it ); 1104 if ( (*it)->category() & category ) result.append( *it );
1102 } 1105 }
1103 1106
1104 return result; 1107 return result;
1105} 1108}
1106 1109
1107bool AddressBook::addCustomField( const QString &label, int category, 1110bool AddressBook::addCustomField( const QString &label, int category,
1108 const QString &key, const QString &app ) 1111 const QString &key, const QString &app )
1109{ 1112{
1110 if ( d->mAllFields.isEmpty() ) { 1113 if ( d->mAllFields.isEmpty() ) {
1111 d->mAllFields = Field::allFields(); 1114 d->mAllFields = Field::allFields();
1112 } 1115 }
1113//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 1116//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
1114 QString a = app.isNull() ? KGlobal::getAppName() : app; 1117 QString a = app.isNull() ? KGlobal::getAppName() : app;
1115 1118
1116 QString k = key.isNull() ? label : key; 1119 QString k = key.isNull() ? label : key;
1117 1120
1118 Field *field = Field::createCustomField( label, category, k, a ); 1121 Field *field = Field::createCustomField( label, category, k, a );
1119 1122
1120 if ( !field ) return false; 1123 if ( !field ) return false;
1121 1124
1122 d->mAllFields.append( field ); 1125 d->mAllFields.append( field );
1123 1126
1124 return true; 1127 return true;
1125} 1128}
1126 1129
1127QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 1130QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
1128{ 1131{
1129 if (!ab.d) return s; 1132 if (!ab.d) return s;
1130 1133
1131 return s << ab.d->mAddressees; 1134 return s << ab.d->mAddressees;
1132} 1135}
1133 1136
1134QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 1137QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
1135{ 1138{
1136 if (!ab.d) return s; 1139 if (!ab.d) return s;
1137 1140
1138 s >> ab.d->mAddressees; 1141 s >> ab.d->mAddressees;
1139 1142
1140 return s; 1143 return s;
1141} 1144}
1142 1145
1143bool AddressBook::addResource( Resource *resource ) 1146bool AddressBook::addResource( Resource *resource )
1144{ 1147{
1145 if ( !resource->open() ) { 1148 if ( !resource->open() ) {
1146 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 1149 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
1147 return false; 1150 return false;
1148 } 1151 }
1149 1152
1150 resource->setAddressBook( this ); 1153 resource->setAddressBook( this );
1151 1154
1152 d->mManager->add( resource ); 1155 d->mManager->add( resource );
1153 return true; 1156 return true;
1154} 1157}
1155 1158
1156bool AddressBook::removeResource( Resource *resource ) 1159bool AddressBook::removeResource( Resource *resource )
1157{ 1160{
1158 resource->close(); 1161 resource->close();
1159 1162
1160 if ( resource == standardResource() ) 1163 if ( resource == standardResource() )
1161 d->mManager->setStandardResource( 0 ); 1164 d->mManager->setStandardResource( 0 );
1162 1165
1163 resource->setAddressBook( 0 ); 1166 resource->setAddressBook( 0 );
1164 1167
1165 d->mManager->remove( resource ); 1168 d->mManager->remove( resource );
1166 return true; 1169 return true;
1167} 1170}
1168 1171
1169QPtrList<Resource> AddressBook::resources() 1172QPtrList<Resource> AddressBook::resources()
1170{ 1173{
1171 QPtrList<Resource> list; 1174 QPtrList<Resource> list;
1172 1175
1173// qDebug("AddressBook::resources() 1"); 1176// qDebug("AddressBook::resources() 1");
1174 1177
1175 KRES::Manager<Resource>::ActiveIterator it; 1178 KRES::Manager<Resource>::ActiveIterator it;
1176 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 1179 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
1177 list.append( *it ); 1180 list.append( *it );
1178 1181
1179 return list; 1182 return list;
1180} 1183}
1181 1184
1182/*US 1185/*US
1183void AddressBook::setErrorHandler( ErrorHandler *handler ) 1186void AddressBook::setErrorHandler( ErrorHandler *handler )
1184{ 1187{
1185 delete d->mErrorHandler; 1188 delete d->mErrorHandler;
1186 d->mErrorHandler = handler; 1189 d->mErrorHandler = handler;
1187} 1190}
1188*/ 1191*/
1189 1192
1190void AddressBook::error( const QString& msg ) 1193void AddressBook::error( const QString& msg )
1191{ 1194{
1192/*US 1195/*US
1193 if ( !d->mErrorHandler ) // create default error handler 1196 if ( !d->mErrorHandler ) // create default error handler
1194 d->mErrorHandler = new ConsoleErrorHandler; 1197 d->mErrorHandler = new ConsoleErrorHandler;
1195 1198
1196 if ( d->mErrorHandler ) 1199 if ( d->mErrorHandler )
1197 d->mErrorHandler->error( msg ); 1200 d->mErrorHandler->error( msg );
1198 else 1201 else
1199 kdError(5700) << "no error handler defined" << endl; 1202 kdError(5700) << "no error handler defined" << endl;
1200*/ 1203*/
1201 kdDebug(5700) << "msg" << endl; 1204 kdDebug(5700) << "msg" << endl;
1202 qDebug(msg); 1205 qDebug(msg);
1203} 1206}
1204 1207
1205void AddressBook::deleteRemovedAddressees() 1208void AddressBook::deleteRemovedAddressees()
1206{ 1209{
1207 Addressee::List::Iterator it; 1210 Addressee::List::Iterator it;
1208 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 1211 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
1209 Resource *resource = (*it).resource(); 1212 Resource *resource = (*it).resource();
1210 if ( resource && !resource->readOnly() && resource->isOpen() ) 1213 if ( resource && !resource->readOnly() && resource->isOpen() )
1211 resource->removeAddressee( *it ); 1214 resource->removeAddressee( *it );
1212 } 1215 }
1213 1216
1214 d->mRemovedAddressees.clear(); 1217 d->mRemovedAddressees.clear();
1215} 1218}
1216 1219
1217void AddressBook::setStandardResource( Resource *resource ) 1220void AddressBook::setStandardResource( Resource *resource )
1218{ 1221{
1219// qDebug("AddressBook::setStandardResource 1"); 1222// qDebug("AddressBook::setStandardResource 1");
1220 d->mManager->setStandardResource( resource ); 1223 d->mManager->setStandardResource( resource );
1221} 1224}
1222 1225
1223Resource *AddressBook::standardResource() 1226Resource *AddressBook::standardResource()
1224{ 1227{
1225 return d->mManager->standardResource(); 1228 return d->mManager->standardResource();
1226} 1229}
1227 1230
1228KRES::Manager<Resource> *AddressBook::resourceManager() 1231KRES::Manager<Resource> *AddressBook::resourceManager()
1229{ 1232{
1230 return d->mManager; 1233 return d->mManager;
1231} 1234}
1232 1235
1233void AddressBook::cleanUp() 1236void AddressBook::cleanUp()
1234{ 1237{
1235 KRES::Manager<Resource>::ActiveIterator it; 1238 KRES::Manager<Resource>::ActiveIterator it;
1236 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1239 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1237 if ( !(*it)->readOnly() && (*it)->isOpen() ) 1240 if ( !(*it)->readOnly() && (*it)->isOpen() )
1238 (*it)->cleanUp(); 1241 (*it)->cleanUp();
1239 } 1242 }
1240} 1243}
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 2f00a09..ea87929 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -931,1986 +931,2005 @@ void KABCore::pasteContacts()
931void KABCore::pasteContacts( KABC::Addressee::List &list ) 931void KABCore::pasteContacts( KABC::Addressee::List &list )
932{ 932{
933 KABC::Resource *resource = requestResource( this ); 933 KABC::Resource *resource = requestResource( this );
934 KABC::Addressee::List::Iterator it; 934 KABC::Addressee::List::Iterator it;
935 for ( it = list.begin(); it != list.end(); ++it ) 935 for ( it = list.begin(); it != list.end(); ++it )
936 (*it).setResource( resource ); 936 (*it).setResource( resource );
937 937
938 PwPasteCommand *command = new PwPasteCommand( this, list ); 938 PwPasteCommand *command = new PwPasteCommand( this, list );
939 UndoStack::instance()->push( command ); 939 UndoStack::instance()->push( command );
940 RedoStack::instance()->clear(); 940 RedoStack::instance()->clear();
941 941
942 setModified( true ); 942 setModified( true );
943} 943}
944 944
945void KABCore::setWhoAmI() 945void KABCore::setWhoAmI()
946{ 946{
947 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 947 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
948 948
949 if ( addrList.count() > 1 ) { 949 if ( addrList.count() > 1 ) {
950 KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); 950 KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
951 return; 951 return;
952 } 952 }
953 953
954 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); 954 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
955 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) 955 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
956 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); 956 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
957} 957}
958 958
959void KABCore::setCategories() 959void KABCore::setCategories()
960{ 960{
961 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); 961 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
962 if ( !dlg.exec() ) 962 if ( !dlg.exec() )
963 return; 963 return;
964 964
965 bool merge = false; 965 bool merge = false;
966 QString msg = i18n( "Merge with existing categories?" ); 966 QString msg = i18n( "Merge with existing categories?" );
967 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) 967 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
968 merge = true; 968 merge = true;
969 969
970 QStringList categories = dlg.selectedCategories(); 970 QStringList categories = dlg.selectedCategories();
971 971
972 QStringList uids = mViewManager->selectedUids(); 972 QStringList uids = mViewManager->selectedUids();
973 QStringList::Iterator it; 973 QStringList::Iterator it;
974 for ( it = uids.begin(); it != uids.end(); ++it ) { 974 for ( it = uids.begin(); it != uids.end(); ++it ) {
975 KABC::Addressee addr = mAddressBook->findByUid( *it ); 975 KABC::Addressee addr = mAddressBook->findByUid( *it );
976 if ( !addr.isEmpty() ) { 976 if ( !addr.isEmpty() ) {
977 if ( !merge ) 977 if ( !merge )
978 addr.setCategories( categories ); 978 addr.setCategories( categories );
979 else { 979 else {
980 QStringList addrCategories = addr.categories(); 980 QStringList addrCategories = addr.categories();
981 QStringList::Iterator catIt; 981 QStringList::Iterator catIt;
982 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { 982 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
983 if ( !addrCategories.contains( *catIt ) ) 983 if ( !addrCategories.contains( *catIt ) )
984 addrCategories.append( *catIt ); 984 addrCategories.append( *catIt );
985 } 985 }
986 addr.setCategories( addrCategories ); 986 addr.setCategories( addrCategories );
987 } 987 }
988 988
989 mAddressBook->insertAddressee( addr ); 989 mAddressBook->insertAddressee( addr );
990 } 990 }
991 } 991 }
992 992
993 if ( uids.count() > 0 ) 993 if ( uids.count() > 0 )
994 setModified( true ); 994 setModified( true );
995} 995}
996 996
997void KABCore::setSearchFields( const KABC::Field::List &fields ) 997void KABCore::setSearchFields( const KABC::Field::List &fields )
998{ 998{
999 mIncSearchWidget->setFields( fields ); 999 mIncSearchWidget->setFields( fields );
1000} 1000}
1001 1001
1002void KABCore::incrementalSearch( const QString& text ) 1002void KABCore::incrementalSearch( const QString& text )
1003{ 1003{
1004 mViewManager->doSearch( text, mIncSearchWidget->currentField() ); 1004 mViewManager->doSearch( text, mIncSearchWidget->currentField() );
1005} 1005}
1006 1006
1007void KABCore::setModified() 1007void KABCore::setModified()
1008{ 1008{
1009 setModified( true ); 1009 setModified( true );
1010} 1010}
1011 1011
1012void KABCore::setModifiedWOrefresh() 1012void KABCore::setModifiedWOrefresh()
1013{ 1013{
1014 // qDebug("KABCore::setModifiedWOrefresh() "); 1014 // qDebug("KABCore::setModifiedWOrefresh() ");
1015 mModified = true; 1015 mModified = true;
1016 mActionSave->setEnabled( mModified ); 1016 mActionSave->setEnabled( mModified );
1017#ifdef DESKTOP_VERSION 1017#ifdef DESKTOP_VERSION
1018 mDetails->refreshView(); 1018 mDetails->refreshView();
1019#endif 1019#endif
1020 1020
1021} 1021}
1022void KABCore::setModified( bool modified ) 1022void KABCore::setModified( bool modified )
1023{ 1023{
1024 mModified = modified; 1024 mModified = modified;
1025 mActionSave->setEnabled( mModified ); 1025 mActionSave->setEnabled( mModified );
1026 1026
1027 if ( modified ) 1027 if ( modified )
1028 mJumpButtonBar->recreateButtons(); 1028 mJumpButtonBar->recreateButtons();
1029 1029
1030 mViewManager->refreshView(); 1030 mViewManager->refreshView();
1031 mDetails->refreshView(); 1031 mDetails->refreshView();
1032 1032
1033} 1033}
1034 1034
1035bool KABCore::modified() const 1035bool KABCore::modified() const
1036{ 1036{
1037 return mModified; 1037 return mModified;
1038} 1038}
1039 1039
1040void KABCore::contactModified( const KABC::Addressee &addr ) 1040void KABCore::contactModified( const KABC::Addressee &addr )
1041{ 1041{
1042 1042
1043 Command *command = 0; 1043 Command *command = 0;
1044 QString uid; 1044 QString uid;
1045 1045
1046 // check if it exists already 1046 // check if it exists already
1047 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); 1047 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
1048 if ( origAddr.isEmpty() ) 1048 if ( origAddr.isEmpty() )
1049 command = new PwNewCommand( mAddressBook, addr ); 1049 command = new PwNewCommand( mAddressBook, addr );
1050 else { 1050 else {
1051 command = new PwEditCommand( mAddressBook, origAddr, addr ); 1051 command = new PwEditCommand( mAddressBook, origAddr, addr );
1052 uid = addr.uid(); 1052 uid = addr.uid();
1053 } 1053 }
1054 1054
1055 UndoStack::instance()->push( command ); 1055 UndoStack::instance()->push( command );
1056 RedoStack::instance()->clear(); 1056 RedoStack::instance()->clear();
1057 1057
1058 setModified( true ); 1058 setModified( true );
1059} 1059}
1060 1060
1061void KABCore::newContact() 1061void KABCore::newContact()
1062{ 1062{
1063 1063
1064 1064
1065 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); 1065 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
1066 1066
1067 QPtrList<KRES::Resource> kresResources; 1067 QPtrList<KRES::Resource> kresResources;
1068 QPtrListIterator<KABC::Resource> it( kabcResources ); 1068 QPtrListIterator<KABC::Resource> it( kabcResources );
1069 KABC::Resource *resource; 1069 KABC::Resource *resource;
1070 while ( ( resource = it.current() ) != 0 ) { 1070 while ( ( resource = it.current() ) != 0 ) {
1071 ++it; 1071 ++it;
1072 if ( !resource->readOnly() ) { 1072 if ( !resource->readOnly() ) {
1073 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 1073 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
1074 if ( res ) 1074 if ( res )
1075 kresResources.append( res ); 1075 kresResources.append( res );
1076 } 1076 }
1077 } 1077 }
1078 1078
1079 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); 1079 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
1080 resource = static_cast<KABC::Resource*>( res ); 1080 resource = static_cast<KABC::Resource*>( res );
1081 1081
1082 if ( resource ) { 1082 if ( resource ) {
1083 KABC::Addressee addr; 1083 KABC::Addressee addr;
1084 addr.setResource( resource ); 1084 addr.setResource( resource );
1085 mEditorDialog->setAddressee( addr ); 1085 mEditorDialog->setAddressee( addr );
1086 KApplication::execDialog ( mEditorDialog ); 1086 KApplication::execDialog ( mEditorDialog );
1087 1087
1088 } else 1088 } else
1089 return; 1089 return;
1090 1090
1091 // mEditorDict.insert( dialog->addressee().uid(), dialog ); 1091 // mEditorDict.insert( dialog->addressee().uid(), dialog );
1092 1092
1093 1093
1094} 1094}
1095 1095
1096void KABCore::addEmail( QString aStr ) 1096void KABCore::addEmail( QString aStr )
1097{ 1097{
1098#ifndef KAB_EMBEDDED 1098#ifndef KAB_EMBEDDED
1099 QString fullName, email; 1099 QString fullName, email;
1100 1100
1101 KABC::Addressee::parseEmailAddress( aStr, fullName, email ); 1101 KABC::Addressee::parseEmailAddress( aStr, fullName, email );
1102 1102
1103 // Try to lookup the addressee matching the email address 1103 // Try to lookup the addressee matching the email address
1104 bool found = false; 1104 bool found = false;
1105 QStringList emailList; 1105 QStringList emailList;
1106 KABC::AddressBook::Iterator it; 1106 KABC::AddressBook::Iterator it;
1107 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { 1107 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
1108 emailList = (*it).emails(); 1108 emailList = (*it).emails();
1109 if ( emailList.contains( email ) > 0 ) { 1109 if ( emailList.contains( email ) > 0 ) {
1110 found = true; 1110 found = true;
1111 (*it).setNameFromString( fullName ); 1111 (*it).setNameFromString( fullName );
1112 editContact( (*it).uid() ); 1112 editContact( (*it).uid() );
1113 } 1113 }
1114 } 1114 }
1115 1115
1116 if ( !found ) { 1116 if ( !found ) {
1117 KABC::Addressee addr; 1117 KABC::Addressee addr;
1118 addr.setNameFromString( fullName ); 1118 addr.setNameFromString( fullName );
1119 addr.insertEmail( email, true ); 1119 addr.insertEmail( email, true );
1120 1120
1121 mAddressBook->insertAddressee( addr ); 1121 mAddressBook->insertAddressee( addr );
1122 mViewManager->refreshView( addr.uid() ); 1122 mViewManager->refreshView( addr.uid() );
1123 editContact( addr.uid() ); 1123 editContact( addr.uid() );
1124 } 1124 }
1125#else //KAB_EMBEDDED 1125#else //KAB_EMBEDDED
1126 qDebug("KABCore::addEmail finsih method"); 1126 qDebug("KABCore::addEmail finsih method");
1127#endif //KAB_EMBEDDED 1127#endif //KAB_EMBEDDED
1128} 1128}
1129 1129
1130void KABCore::importVCard( const KURL &url, bool showPreview ) 1130void KABCore::importVCard( const KURL &url, bool showPreview )
1131{ 1131{
1132 mXXPortManager->importVCard( url, showPreview ); 1132 mXXPortManager->importVCard( url, showPreview );
1133} 1133}
1134void KABCore::importFromOL() 1134void KABCore::importFromOL()
1135{ 1135{
1136#ifdef _WIN32_ 1136#ifdef _WIN32_
1137 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); 1137 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this );
1138 idgl->exec(); 1138 idgl->exec();
1139 KABC::Addressee::List list = idgl->getAddressList(); 1139 KABC::Addressee::List list = idgl->getAddressList();
1140 if ( list.count() > 0 ) { 1140 if ( list.count() > 0 ) {
1141 KABC::Addressee::List listNew; 1141 KABC::Addressee::List listNew;
1142 KABC::Addressee::List listExisting; 1142 KABC::Addressee::List listExisting;
1143 KABC::Addressee::List::Iterator it; 1143 KABC::Addressee::List::Iterator it;
1144 KABC::AddressBook::Iterator iter; 1144 KABC::AddressBook::Iterator iter;
1145 for ( it = list.begin(); it != list.end(); ++it ) { 1145 for ( it = list.begin(); it != list.end(); ++it ) {
1146 if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) 1146 if ( mAddressBook->findByUid((*it).uid() ).isEmpty())
1147 listNew.append( (*it) ); 1147 listNew.append( (*it) );
1148 else 1148 else
1149 listExisting.append( (*it) ); 1149 listExisting.append( (*it) );
1150 } 1150 }
1151 if ( listExisting.count() > 0 ) 1151 if ( listExisting.count() > 0 )
1152 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); 1152 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() ));
1153 if ( listNew.count() > 0 ) { 1153 if ( listNew.count() > 0 ) {
1154 pasteWithNewUid = false; 1154 pasteWithNewUid = false;
1155 pasteContacts( listNew ); 1155 pasteContacts( listNew );
1156 pasteWithNewUid = true; 1156 pasteWithNewUid = true;
1157 } 1157 }
1158 } 1158 }
1159 delete idgl; 1159 delete idgl;
1160#endif 1160#endif
1161} 1161}
1162 1162
1163void KABCore::importVCard( const QString &vCard, bool showPreview ) 1163void KABCore::importVCard( const QString &vCard, bool showPreview )
1164{ 1164{
1165 mXXPortManager->importVCard( vCard, showPreview ); 1165 mXXPortManager->importVCard( vCard, showPreview );
1166} 1166}
1167 1167
1168//US added a second method without defaultparameter 1168//US added a second method without defaultparameter
1169void KABCore::editContact2() { 1169void KABCore::editContact2() {
1170 editContact( QString::null ); 1170 editContact( QString::null );
1171} 1171}
1172 1172
1173void KABCore::editContact( const QString &uid ) 1173void KABCore::editContact( const QString &uid )
1174{ 1174{
1175 1175
1176 if ( mExtensionManager->isQuickEditVisible() ) 1176 if ( mExtensionManager->isQuickEditVisible() )
1177 return; 1177 return;
1178 1178
1179 // First, locate the contact entry 1179 // First, locate the contact entry
1180 QString localUID = uid; 1180 QString localUID = uid;
1181 if ( localUID.isNull() ) { 1181 if ( localUID.isNull() ) {
1182 QStringList uidList = mViewManager->selectedUids(); 1182 QStringList uidList = mViewManager->selectedUids();
1183 if ( uidList.count() > 0 ) 1183 if ( uidList.count() > 0 )
1184 localUID = *( uidList.at( 0 ) ); 1184 localUID = *( uidList.at( 0 ) );
1185 } 1185 }
1186 1186
1187 KABC::Addressee addr = mAddressBook->findByUid( localUID ); 1187 KABC::Addressee addr = mAddressBook->findByUid( localUID );
1188 if ( !addr.isEmpty() ) { 1188 if ( !addr.isEmpty() ) {
1189 mEditorDialog->setAddressee( addr ); 1189 mEditorDialog->setAddressee( addr );
1190 KApplication::execDialog ( mEditorDialog ); 1190 KApplication::execDialog ( mEditorDialog );
1191 } 1191 }
1192} 1192}
1193 1193
1194/** 1194/**
1195 Shows or edits the detail view for the given uid. If the uid is QString::null, 1195 Shows or edits the detail view for the given uid. If the uid is QString::null,
1196 the method will try to find a selected addressee in the view. 1196 the method will try to find a selected addressee in the view.
1197 */ 1197 */
1198void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) 1198void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
1199{ 1199{
1200 if ( mMultipleViewsAtOnce ) 1200 if ( mMultipleViewsAtOnce )
1201 { 1201 {
1202 editContact( uid ); 1202 editContact( uid );
1203 } 1203 }
1204 else 1204 else
1205 { 1205 {
1206 setDetailsVisible( true ); 1206 setDetailsVisible( true );
1207 mActionDetails->setChecked(true); 1207 mActionDetails->setChecked(true);
1208 } 1208 }
1209 1209
1210} 1210}
1211 1211
1212void KABCore::save() 1212void KABCore::save()
1213{ 1213{
1214 if (syncManager->blockSave()) 1214 if (syncManager->blockSave())
1215 return; 1215 return;
1216 if ( !mModified ) 1216 if ( !mModified )
1217 return; 1217 return;
1218 1218
1219 syncManager->setBlockSave(true); 1219 syncManager->setBlockSave(true);
1220 QString text = i18n( "There was an error while attempting to save\n the " 1220 QString text = i18n( "There was an error while attempting to save\n the "
1221 "address book. Please check that some \nother application is " 1221 "address book. Please check that some \nother application is "
1222 "not using it. " ); 1222 "not using it. " );
1223 message(i18n("Saving addressbook ... ")); 1223 message(i18n("Saving addressbook ... "));
1224#ifndef KAB_EMBEDDED 1224#ifndef KAB_EMBEDDED
1225 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 1225 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
1226 if ( !b || !b->save() ) { 1226 if ( !b || !b->save() ) {
1227 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 1227 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
1228 } 1228 }
1229#else //KAB_EMBEDDED 1229#else //KAB_EMBEDDED
1230 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 1230 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
1231 if ( !b || !b->save() ) { 1231 if ( !b || !b->save() ) {
1232 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 1232 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
1233 } 1233 }
1234#endif //KAB_EMBEDDED 1234#endif //KAB_EMBEDDED
1235 1235
1236 message(i18n("Addressbook saved!")); 1236 message(i18n("Addressbook saved!"));
1237 setModified( false ); 1237 setModified( false );
1238 syncManager->setBlockSave(false); 1238 syncManager->setBlockSave(false);
1239} 1239}
1240 1240
1241 1241
1242void KABCore::undo() 1242void KABCore::undo()
1243{ 1243{
1244 UndoStack::instance()->undo(); 1244 UndoStack::instance()->undo();
1245 1245
1246 // Refresh the view 1246 // Refresh the view
1247 mViewManager->refreshView(); 1247 mViewManager->refreshView();
1248} 1248}
1249 1249
1250void KABCore::redo() 1250void KABCore::redo()
1251{ 1251{
1252 RedoStack::instance()->redo(); 1252 RedoStack::instance()->redo();
1253 1253
1254 // Refresh the view 1254 // Refresh the view
1255 mViewManager->refreshView(); 1255 mViewManager->refreshView();
1256} 1256}
1257 1257
1258void KABCore::setJumpButtonBarVisible( bool visible ) 1258void KABCore::setJumpButtonBarVisible( bool visible )
1259{ 1259{
1260 if (mMultipleViewsAtOnce) 1260 if (mMultipleViewsAtOnce)
1261 { 1261 {
1262 if ( visible ) 1262 if ( visible )
1263 mJumpButtonBar->show(); 1263 mJumpButtonBar->show();
1264 else 1264 else
1265 mJumpButtonBar->hide(); 1265 mJumpButtonBar->hide();
1266 } 1266 }
1267 else 1267 else
1268 { 1268 {
1269 // show the jumpbar only if "the details are hidden" == "viewmanager are shown" 1269 // show the jumpbar only if "the details are hidden" == "viewmanager are shown"
1270 if (mViewManager->isVisible()) 1270 if (mViewManager->isVisible())
1271 { 1271 {
1272 if ( visible ) 1272 if ( visible )
1273 mJumpButtonBar->show(); 1273 mJumpButtonBar->show();
1274 else 1274 else
1275 mJumpButtonBar->hide(); 1275 mJumpButtonBar->hide();
1276 } 1276 }
1277 else 1277 else
1278 { 1278 {
1279 mJumpButtonBar->hide(); 1279 mJumpButtonBar->hide();
1280 } 1280 }
1281 } 1281 }
1282} 1282}
1283 1283
1284 1284
1285void KABCore::setDetailsToState() 1285void KABCore::setDetailsToState()
1286{ 1286{
1287 setDetailsVisible( mActionDetails->isChecked() ); 1287 setDetailsVisible( mActionDetails->isChecked() );
1288} 1288}
1289 1289
1290 1290
1291 1291
1292void KABCore::setDetailsVisible( bool visible ) 1292void KABCore::setDetailsVisible( bool visible )
1293{ 1293{
1294 if (visible && mDetails->isHidden()) 1294 if (visible && mDetails->isHidden())
1295 { 1295 {
1296 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 1296 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
1297 if ( addrList.count() > 0 ) 1297 if ( addrList.count() > 0 )
1298 mDetails->setAddressee( addrList[ 0 ] ); 1298 mDetails->setAddressee( addrList[ 0 ] );
1299 } 1299 }
1300 1300
1301 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between 1301 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between
1302 // the listview and the detailview. We do that by changing the splitbar size. 1302 // the listview and the detailview. We do that by changing the splitbar size.
1303 if (mMultipleViewsAtOnce) 1303 if (mMultipleViewsAtOnce)
1304 { 1304 {
1305 if ( visible ) 1305 if ( visible )
1306 mDetails->show(); 1306 mDetails->show();
1307 else 1307 else
1308 mDetails->hide(); 1308 mDetails->hide();
1309 } 1309 }
1310 else 1310 else
1311 { 1311 {
1312 if ( visible ) { 1312 if ( visible ) {
1313 mViewManager->hide(); 1313 mViewManager->hide();
1314 mDetails->show(); 1314 mDetails->show();
1315 mIncSearchWidget->setFocus();
1315 } 1316 }
1316 else { 1317 else {
1317 mViewManager->show(); 1318 mViewManager->show();
1318 mDetails->hide(); 1319 mDetails->hide();
1320 mViewManager->setFocusAV();
1319 } 1321 }
1320 setJumpButtonBarVisible( !visible ); 1322 setJumpButtonBarVisible( !visible );
1321 } 1323 }
1322 1324
1323} 1325}
1324 1326
1325void KABCore::extensionChanged( int id ) 1327void KABCore::extensionChanged( int id )
1326{ 1328{
1327 //change the details view only for non desktop systems 1329 //change the details view only for non desktop systems
1328#ifndef DESKTOP_VERSION 1330#ifndef DESKTOP_VERSION
1329 1331
1330 if (id == 0) 1332 if (id == 0)
1331 { 1333 {
1332 //the user disabled the extension. 1334 //the user disabled the extension.
1333 1335
1334 if (mMultipleViewsAtOnce) 1336 if (mMultipleViewsAtOnce)
1335 { // enable detailsview again 1337 { // enable detailsview again
1336 setDetailsVisible( true ); 1338 setDetailsVisible( true );
1337 mActionDetails->setChecked( true ); 1339 mActionDetails->setChecked( true );
1338 } 1340 }
1339 else 1341 else
1340 { //go back to the listview 1342 { //go back to the listview
1341 setDetailsVisible( false ); 1343 setDetailsVisible( false );
1342 mActionDetails->setChecked( false ); 1344 mActionDetails->setChecked( false );
1343 mActionDetails->setEnabled(true); 1345 mActionDetails->setEnabled(true);
1344 } 1346 }
1345 1347
1346 } 1348 }
1347 else 1349 else
1348 { 1350 {
1349 //the user enabled the extension. 1351 //the user enabled the extension.
1350 setDetailsVisible( false ); 1352 setDetailsVisible( false );
1351 mActionDetails->setChecked( false ); 1353 mActionDetails->setChecked( false );
1352 1354
1353 if (!mMultipleViewsAtOnce) 1355 if (!mMultipleViewsAtOnce)
1354 { 1356 {
1355 mActionDetails->setEnabled(false); 1357 mActionDetails->setEnabled(false);
1356 } 1358 }
1357 1359
1358 mExtensionManager->setSelectionChanged(); 1360 mExtensionManager->setSelectionChanged();
1359 1361
1360 } 1362 }
1361 1363
1362#endif// DESKTOP_VERSION 1364#endif// DESKTOP_VERSION
1363 1365
1364} 1366}
1365 1367
1366 1368
1367void KABCore::extensionModified( const KABC::Addressee::List &list ) 1369void KABCore::extensionModified( const KABC::Addressee::List &list )
1368{ 1370{
1369 1371
1370 if ( list.count() != 0 ) { 1372 if ( list.count() != 0 ) {
1371 KABC::Addressee::List::ConstIterator it; 1373 KABC::Addressee::List::ConstIterator it;
1372 for ( it = list.begin(); it != list.end(); ++it ) 1374 for ( it = list.begin(); it != list.end(); ++it )
1373 mAddressBook->insertAddressee( *it ); 1375 mAddressBook->insertAddressee( *it );
1374 if ( list.count() > 1 ) 1376 if ( list.count() > 1 )
1375 setModified(); 1377 setModified();
1376 else 1378 else
1377 setModifiedWOrefresh(); 1379 setModifiedWOrefresh();
1378 } 1380 }
1379 if ( list.count() == 0 ) 1381 if ( list.count() == 0 )
1380 mViewManager->refreshView(); 1382 mViewManager->refreshView();
1381 else 1383 else
1382 mViewManager->refreshView( list[ 0 ].uid() ); 1384 mViewManager->refreshView( list[ 0 ].uid() );
1383 1385
1384 1386
1385 1387
1386} 1388}
1387 1389
1388QString KABCore::getNameByPhone( const QString &phone ) 1390QString KABCore::getNameByPhone( const QString &phone )
1389{ 1391{
1390#ifndef KAB_EMBEDDED 1392#ifndef KAB_EMBEDDED
1391 QRegExp r( "[/*/-/ ]" ); 1393 QRegExp r( "[/*/-/ ]" );
1392 QString localPhone( phone ); 1394 QString localPhone( phone );
1393 1395
1394 bool found = false; 1396 bool found = false;
1395 QString ownerName = ""; 1397 QString ownerName = "";
1396 KABC::AddressBook::Iterator iter; 1398 KABC::AddressBook::Iterator iter;
1397 KABC::PhoneNumber::List::Iterator phoneIter; 1399 KABC::PhoneNumber::List::Iterator phoneIter;
1398 KABC::PhoneNumber::List phoneList; 1400 KABC::PhoneNumber::List phoneList;
1399 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { 1401 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
1400 phoneList = (*iter).phoneNumbers(); 1402 phoneList = (*iter).phoneNumbers();
1401 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); 1403 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
1402 ++phoneIter) { 1404 ++phoneIter) {
1403 // Get rid of separator chars so just the numbers are compared. 1405 // Get rid of separator chars so just the numbers are compared.
1404 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { 1406 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
1405 ownerName = (*iter).formattedName(); 1407 ownerName = (*iter).formattedName();
1406 found = true; 1408 found = true;
1407 } 1409 }
1408 } 1410 }
1409 } 1411 }
1410 1412
1411 return ownerName; 1413 return ownerName;
1412#else //KAB_EMBEDDED 1414#else //KAB_EMBEDDED
1413 qDebug("KABCore::getNameByPhone finsih method"); 1415 qDebug("KABCore::getNameByPhone finsih method");
1414 return ""; 1416 return "";
1415#endif //KAB_EMBEDDED 1417#endif //KAB_EMBEDDED
1416 1418
1417} 1419}
1418 1420
1419void KABCore::openConfigDialog() 1421void KABCore::openConfigDialog()
1420{ 1422{
1421 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); 1423 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true );
1422 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); 1424 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" );
1423 ConfigureDialog->addModule(kabcfg ); 1425 ConfigureDialog->addModule(kabcfg );
1424 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); 1426 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
1425 ConfigureDialog->addModule(kdelibcfg ); 1427 ConfigureDialog->addModule(kdelibcfg );
1426 1428
1427 connect( ConfigureDialog, SIGNAL( applyClicked() ), 1429 connect( ConfigureDialog, SIGNAL( applyClicked() ),
1428 this, SLOT( configurationChanged() ) ); 1430 this, SLOT( configurationChanged() ) );
1429 connect( ConfigureDialog, SIGNAL( okClicked() ), 1431 connect( ConfigureDialog, SIGNAL( okClicked() ),
1430 this, SLOT( configurationChanged() ) ); 1432 this, SLOT( configurationChanged() ) );
1431 saveSettings(); 1433 saveSettings();
1432#ifndef DESKTOP_VERSION 1434#ifndef DESKTOP_VERSION
1433 ConfigureDialog->showMaximized(); 1435 ConfigureDialog->showMaximized();
1434#endif 1436#endif
1435 if ( ConfigureDialog->exec() ) 1437 if ( ConfigureDialog->exec() )
1436 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); 1438 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
1437 delete ConfigureDialog; 1439 delete ConfigureDialog;
1438} 1440}
1439 1441
1440void KABCore::openLDAPDialog() 1442void KABCore::openLDAPDialog()
1441{ 1443{
1442#ifndef KAB_EMBEDDED 1444#ifndef KAB_EMBEDDED
1443 if ( !mLdapSearchDialog ) { 1445 if ( !mLdapSearchDialog ) {
1444 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); 1446 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this );
1445 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, 1447 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager,
1446 SLOT( refreshView() ) ); 1448 SLOT( refreshView() ) );
1447 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, 1449 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
1448 SLOT( setModified() ) ); 1450 SLOT( setModified() ) );
1449 } else 1451 } else
1450 mLdapSearchDialog->restoreSettings(); 1452 mLdapSearchDialog->restoreSettings();
1451 1453
1452 if ( mLdapSearchDialog->isOK() ) 1454 if ( mLdapSearchDialog->isOK() )
1453 mLdapSearchDialog->exec(); 1455 mLdapSearchDialog->exec();
1454#else //KAB_EMBEDDED 1456#else //KAB_EMBEDDED
1455 qDebug("KABCore::openLDAPDialog() finsih method"); 1457 qDebug("KABCore::openLDAPDialog() finsih method");
1456#endif //KAB_EMBEDDED 1458#endif //KAB_EMBEDDED
1457} 1459}
1458 1460
1459void KABCore::print() 1461void KABCore::print()
1460{ 1462{
1461#ifndef KAB_EMBEDDED 1463#ifndef KAB_EMBEDDED
1462 KPrinter printer; 1464 KPrinter printer;
1463 if ( !printer.setup( this ) ) 1465 if ( !printer.setup( this ) )
1464 return; 1466 return;
1465 1467
1466 KABPrinting::PrintingWizard wizard( &printer, mAddressBook, 1468 KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
1467 mViewManager->selectedUids(), this ); 1469 mViewManager->selectedUids(), this );
1468 1470
1469 wizard.exec(); 1471 wizard.exec();
1470#else //KAB_EMBEDDED 1472#else //KAB_EMBEDDED
1471 qDebug("KABCore::print() finsih method"); 1473 qDebug("KABCore::print() finsih method");
1472#endif //KAB_EMBEDDED 1474#endif //KAB_EMBEDDED
1473 1475
1474} 1476}
1475 1477
1476 1478
1477void KABCore::addGUIClient( KXMLGUIClient *client ) 1479void KABCore::addGUIClient( KXMLGUIClient *client )
1478{ 1480{
1479 if ( mGUIClient ) 1481 if ( mGUIClient )
1480 mGUIClient->insertChildClient( client ); 1482 mGUIClient->insertChildClient( client );
1481 else 1483 else
1482 KMessageBox::error( this, "no KXMLGUICLient"); 1484 KMessageBox::error( this, "no KXMLGUICLient");
1483} 1485}
1484 1486
1485 1487
1486void KABCore::configurationChanged() 1488void KABCore::configurationChanged()
1487{ 1489{
1488 mExtensionManager->reconfigure(); 1490 mExtensionManager->reconfigure();
1489} 1491}
1490 1492
1491void KABCore::addressBookChanged() 1493void KABCore::addressBookChanged()
1492{ 1494{
1493/*US 1495/*US
1494 QDictIterator<AddresseeEditorDialog> it( mEditorDict ); 1496 QDictIterator<AddresseeEditorDialog> it( mEditorDict );
1495 while ( it.current() ) { 1497 while ( it.current() ) {
1496 if ( it.current()->dirty() ) { 1498 if ( it.current()->dirty() ) {
1497 QString text = i18n( "Data has been changed externally. Unsaved " 1499 QString text = i18n( "Data has been changed externally. Unsaved "
1498 "changes will be lost." ); 1500 "changes will be lost." );
1499 KMessageBox::information( this, text ); 1501 KMessageBox::information( this, text );
1500 } 1502 }
1501 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); 1503 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) );
1502 ++it; 1504 ++it;
1503 } 1505 }
1504*/ 1506*/
1505 if (mEditorDialog) 1507 if (mEditorDialog)
1506 { 1508 {
1507 if (mEditorDialog->dirty()) 1509 if (mEditorDialog->dirty())
1508 { 1510 {
1509 QString text = i18n( "Data has been changed externally. Unsaved " 1511 QString text = i18n( "Data has been changed externally. Unsaved "
1510 "changes will be lost." ); 1512 "changes will be lost." );
1511 KMessageBox::information( this, text ); 1513 KMessageBox::information( this, text );
1512 } 1514 }
1513 QString currentuid = mEditorDialog->addressee().uid(); 1515 QString currentuid = mEditorDialog->addressee().uid();
1514 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); 1516 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) );
1515 } 1517 }
1516 mViewManager->refreshView(); 1518 mViewManager->refreshView();
1517// mDetails->refreshView(); 1519// mDetails->refreshView();
1518 1520
1519 1521
1520} 1522}
1521 1523
1522AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, 1524AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
1523 const char *name ) 1525 const char *name )
1524{ 1526{
1525 1527
1526 if ( mEditorDialog == 0 ) { 1528 if ( mEditorDialog == 0 ) {
1527 mEditorDialog = new AddresseeEditorDialog( this, parent, 1529 mEditorDialog = new AddresseeEditorDialog( this, parent,
1528 name ? name : "editorDialog" ); 1530 name ? name : "editorDialog" );
1529 1531
1530 1532
1531 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), 1533 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
1532 SLOT( contactModified( const KABC::Addressee& ) ) ); 1534 SLOT( contactModified( const KABC::Addressee& ) ) );
1533 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), 1535 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ),
1534 // SLOT( slotEditorDestroyed( const QString& ) ) ; 1536 // SLOT( slotEditorDestroyed( const QString& ) ) ;
1535 } 1537 }
1536 1538
1537 return mEditorDialog; 1539 return mEditorDialog;
1538} 1540}
1539 1541
1540void KABCore::slotEditorDestroyed( const QString &uid ) 1542void KABCore::slotEditorDestroyed( const QString &uid )
1541{ 1543{
1542 //mEditorDict.remove( uid ); 1544 //mEditorDict.remove( uid );
1543} 1545}
1544 1546
1545void KABCore::initGUI() 1547void KABCore::initGUI()
1546{ 1548{
1547#ifndef KAB_EMBEDDED 1549#ifndef KAB_EMBEDDED
1548 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1550 QHBoxLayout *topLayout = new QHBoxLayout( this );
1549 topLayout->setSpacing( KDialogBase::spacingHint() ); 1551 topLayout->setSpacing( KDialogBase::spacingHint() );
1550 1552
1551 mExtensionBarSplitter = new QSplitter( this ); 1553 mExtensionBarSplitter = new QSplitter( this );
1552 mExtensionBarSplitter->setOrientation( Qt::Vertical ); 1554 mExtensionBarSplitter->setOrientation( Qt::Vertical );
1553 1555
1554 mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); 1556 mDetailsSplitter = new QSplitter( mExtensionBarSplitter );
1555 1557
1556 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1558 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1557 mIncSearchWidget = new IncSearchWidget( viewSpace ); 1559 mIncSearchWidget = new IncSearchWidget( viewSpace );
1558 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1560 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1559 SLOT( incrementalSearch( const QString& ) ) ); 1561 SLOT( incrementalSearch( const QString& ) ) );
1560 1562
1561 mViewManager = new ViewManager( this, viewSpace ); 1563 mViewManager = new ViewManager( this, viewSpace );
1562 viewSpace->setStretchFactor( mViewManager, 1 ); 1564 viewSpace->setStretchFactor( mViewManager, 1 );
1563 1565
1564 mDetails = new ViewContainer( mDetailsSplitter ); 1566 mDetails = new ViewContainer( mDetailsSplitter );
1565 1567
1566 mJumpButtonBar = new JumpButtonBar( this, this ); 1568 mJumpButtonBar = new JumpButtonBar( this, this );
1567 1569
1568 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1570 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1569 1571
1570 topLayout->addWidget( mExtensionBarSplitter ); 1572 topLayout->addWidget( mExtensionBarSplitter );
1571 topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); 1573 topLayout->setStretchFactor( mExtensionBarSplitter, 100 );
1572 topLayout->addWidget( mJumpButtonBar ); 1574 topLayout->addWidget( mJumpButtonBar );
1573 topLayout->setStretchFactor( mJumpButtonBar, 1 ); 1575 topLayout->setStretchFactor( mJumpButtonBar, 1 );
1574 1576
1575 mXXPortManager = new XXPortManager( this, this ); 1577 mXXPortManager = new XXPortManager( this, this );
1576 1578
1577#else //KAB_EMBEDDED 1579#else //KAB_EMBEDDED
1578 //US initialize viewMenu before settingup viewmanager. 1580 //US initialize viewMenu before settingup viewmanager.
1579 // Viewmanager needs this menu to plugin submenues. 1581 // Viewmanager needs this menu to plugin submenues.
1580 viewMenu = new QPopupMenu( this ); 1582 viewMenu = new QPopupMenu( this );
1581 settingsMenu = new QPopupMenu( this ); 1583 settingsMenu = new QPopupMenu( this );
1582 //filterMenu = new QPopupMenu( this ); 1584 //filterMenu = new QPopupMenu( this );
1583 ImportMenu = new QPopupMenu( this ); 1585 ImportMenu = new QPopupMenu( this );
1584 ExportMenu = new QPopupMenu( this ); 1586 ExportMenu = new QPopupMenu( this );
1585 syncMenu = new QPopupMenu( this ); 1587 syncMenu = new QPopupMenu( this );
1586 changeMenu= new QPopupMenu( this ); 1588 changeMenu= new QPopupMenu( this );
1587 1589
1588//US since we have no splitter for the embedded system, setup 1590//US since we have no splitter for the embedded system, setup
1589// a layout with two frames. One left and one right. 1591// a layout with two frames. One left and one right.
1590 1592
1591 QBoxLayout *topLayout; 1593 QBoxLayout *topLayout;
1592 1594
1593 // = new QHBoxLayout( this ); 1595 // = new QHBoxLayout( this );
1594// QBoxLayout *topLayout = (QBoxLayout*)layout(); 1596// QBoxLayout *topLayout = (QBoxLayout*)layout();
1595 1597
1596// QWidget *mainBox = new QWidget( this ); 1598// QWidget *mainBox = new QWidget( this );
1597// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); 1599// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
1598 1600
1599#ifdef DESKTOP_VERSION 1601#ifdef DESKTOP_VERSION
1600 topLayout = new QHBoxLayout( this ); 1602 topLayout = new QHBoxLayout( this );
1601 1603
1602 1604
1603 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1605 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1604 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1606 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1605 1607
1606 topLayout->addWidget(mMiniSplitter ); 1608 topLayout->addWidget(mMiniSplitter );
1607 1609
1608 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); 1610 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter );
1609 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1611 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1610 mViewManager = new ViewManager( this, mExtensionBarSplitter ); 1612 mViewManager = new ViewManager( this, mExtensionBarSplitter );
1611 mDetails = new ViewContainer( mMiniSplitter ); 1613 mDetails = new ViewContainer( mMiniSplitter );
1612 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1614 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1613#else 1615#else
1614 if ( QApplication::desktop()->width() > 480 ) { 1616 if ( QApplication::desktop()->width() > 480 ) {
1615 topLayout = new QHBoxLayout( this ); 1617 topLayout = new QHBoxLayout( this );
1616 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1618 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1617 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1619 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1618 } else { 1620 } else {
1619 1621
1620 topLayout = new QHBoxLayout( this ); 1622 topLayout = new QHBoxLayout( this );
1621 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); 1623 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this);
1622 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1624 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1623 } 1625 }
1624 1626
1625 topLayout->addWidget(mMiniSplitter ); 1627 topLayout->addWidget(mMiniSplitter );
1626 mViewManager = new ViewManager( this, mMiniSplitter ); 1628 mViewManager = new ViewManager( this, mMiniSplitter );
1627 mDetails = new ViewContainer( mMiniSplitter ); 1629 mDetails = new ViewContainer( mMiniSplitter );
1628 1630
1629 1631
1630 mExtensionManager = new ExtensionManager( this, mMiniSplitter ); 1632 mExtensionManager = new ExtensionManager( this, mMiniSplitter );
1631#endif 1633#endif
1632 //eh->hide(); 1634 //eh->hide();
1633 // topLayout->addWidget(mExtensionManager ); 1635 // topLayout->addWidget(mExtensionManager );
1634 1636
1635 1637
1636/*US 1638/*US
1637#ifndef KAB_NOSPLITTER 1639#ifndef KAB_NOSPLITTER
1638 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1640 QHBoxLayout *topLayout = new QHBoxLayout( this );
1639//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1641//US topLayout->setSpacing( KDialogBase::spacingHint() );
1640 topLayout->setSpacing( 10 ); 1642 topLayout->setSpacing( 10 );
1641 1643
1642 mDetailsSplitter = new QSplitter( this ); 1644 mDetailsSplitter = new QSplitter( this );
1643 1645
1644 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1646 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1645 1647
1646 mViewManager = new ViewManager( this, viewSpace ); 1648 mViewManager = new ViewManager( this, viewSpace );
1647 viewSpace->setStretchFactor( mViewManager, 1 ); 1649 viewSpace->setStretchFactor( mViewManager, 1 );
1648 1650
1649 mDetails = new ViewContainer( mDetailsSplitter ); 1651 mDetails = new ViewContainer( mDetailsSplitter );
1650 1652
1651 topLayout->addWidget( mDetailsSplitter ); 1653 topLayout->addWidget( mDetailsSplitter );
1652 topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1654 topLayout->setStretchFactor( mDetailsSplitter, 100 );
1653#else //KAB_NOSPLITTER 1655#else //KAB_NOSPLITTER
1654 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1656 QHBoxLayout *topLayout = new QHBoxLayout( this );
1655//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1657//US topLayout->setSpacing( KDialogBase::spacingHint() );
1656 topLayout->setSpacing( 10 ); 1658 topLayout->setSpacing( 10 );
1657 1659
1658// mDetailsSplitter = new QSplitter( this ); 1660// mDetailsSplitter = new QSplitter( this );
1659 1661
1660 QVBox *viewSpace = new QVBox( this ); 1662 QVBox *viewSpace = new QVBox( this );
1661 1663
1662 mViewManager = new ViewManager( this, viewSpace ); 1664 mViewManager = new ViewManager( this, viewSpace );
1663 viewSpace->setStretchFactor( mViewManager, 1 ); 1665 viewSpace->setStretchFactor( mViewManager, 1 );
1664 1666
1665 mDetails = new ViewContainer( this ); 1667 mDetails = new ViewContainer( this );
1666 1668
1667 topLayout->addWidget( viewSpace ); 1669 topLayout->addWidget( viewSpace );
1668// topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1670// topLayout->setStretchFactor( mDetailsSplitter, 100 );
1669 topLayout->addWidget( mDetails ); 1671 topLayout->addWidget( mDetails );
1670#endif //KAB_NOSPLITTER 1672#endif //KAB_NOSPLITTER
1671*/ 1673*/
1672 1674
1673 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); 1675 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
1674 syncManager->setBlockSave(false); 1676 syncManager->setBlockSave(false);
1675 1677
1676 connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); 1678 connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) );
1677 connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); 1679 connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) );
1678 syncManager->setDefaultFileName( sentSyncFile()); 1680 syncManager->setDefaultFileName( sentSyncFile());
1679 //connect(syncManager , SIGNAL( ), this, SLOT( ) ); 1681 //connect(syncManager , SIGNAL( ), this, SLOT( ) );
1680 1682
1681#endif //KAB_EMBEDDED 1683#endif //KAB_EMBEDDED
1682 initActions(); 1684 initActions();
1683 1685
1684#ifdef KAB_EMBEDDED 1686#ifdef KAB_EMBEDDED
1685 addActionsManually(); 1687 addActionsManually();
1686 //US make sure the export and import menues are initialized before creating the xxPortManager. 1688 //US make sure the export and import menues are initialized before creating the xxPortManager.
1687 mXXPortManager = new XXPortManager( this, this ); 1689 mXXPortManager = new XXPortManager( this, this );
1688 1690
1689 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); 1691 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() );
1690 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); 1692 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget);
1691 // mActionQuit->plug ( mMainWindow->toolBar()); 1693 // mActionQuit->plug ( mMainWindow->toolBar());
1692 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); 1694 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() );
1693 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); 1695 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget);
1694 // mIncSearchWidget->hide(); 1696 // mIncSearchWidget->hide();
1695 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1697 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1696 SLOT( incrementalSearch( const QString& ) ) ); 1698 SLOT( incrementalSearch( const QString& ) ) );
1697 connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) ); 1699 connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) );
1698 connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) ); 1700 connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) );
1699 1701
1700 mJumpButtonBar = new JumpButtonBar( this, this ); 1702 mJumpButtonBar = new JumpButtonBar( this, this );
1701 1703
1702 topLayout->addWidget( mJumpButtonBar ); 1704 topLayout->addWidget( mJumpButtonBar );
1703//US topLayout->setStretchFactor( mJumpButtonBar, 10 ); 1705//US topLayout->setStretchFactor( mJumpButtonBar, 10 );
1704 1706
1705// mMainWindow->getIconToolBar()->raise(); 1707// mMainWindow->getIconToolBar()->raise();
1706 1708
1707#endif //KAB_EMBEDDED 1709#endif //KAB_EMBEDDED
1708 1710
1709} 1711}
1710void KABCore::initActions() 1712void KABCore::initActions()
1711{ 1713{
1712//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1714//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1713 1715
1714#ifndef KAB_EMBEDDED 1716#ifndef KAB_EMBEDDED
1715 connect( QApplication::clipboard(), SIGNAL( dataChanged() ), 1717 connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
1716 SLOT( clipboardDataChanged() ) ); 1718 SLOT( clipboardDataChanged() ) );
1717#endif //KAB_EMBEDDED 1719#endif //KAB_EMBEDDED
1718 1720
1719 // file menu 1721 // file menu
1720 if ( mIsPart ) { 1722 if ( mIsPart ) {
1721 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, 1723 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this,
1722 SLOT( sendMail() ), actionCollection(), 1724 SLOT( sendMail() ), actionCollection(),
1723 "kaddressbook_mail" ); 1725 "kaddressbook_mail" );
1724 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, 1726 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this,
1725 SLOT( print() ), actionCollection(), "kaddressbook_print" ); 1727 SLOT( print() ), actionCollection(), "kaddressbook_print" );
1726 1728
1727 } else { 1729 } else {
1728 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); 1730 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() );
1729 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); 1731 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
1730 } 1732 }
1731 1733
1732 1734
1733 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, 1735 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
1734 SLOT( save() ), actionCollection(), "file_sync" ); 1736 SLOT( save() ), actionCollection(), "file_sync" );
1735 1737
1736 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, 1738 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this,
1737 SLOT( newContact() ), actionCollection(), "file_new_contact" ); 1739 SLOT( newContact() ), actionCollection(), "file_new_contact" );
1738 1740
1739 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, 1741 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0,
1740 this, SLOT( mailVCard() ), 1742 this, SLOT( mailVCard() ),
1741 actionCollection(), "file_mail_vcard"); 1743 actionCollection(), "file_mail_vcard");
1742 1744
1743 mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, 1745 mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this,
1744 SLOT( export2phone() ), actionCollection(), 1746 SLOT( export2phone() ), actionCollection(),
1745 "kaddressbook_ex2phone" ); 1747 "kaddressbook_ex2phone" );
1746 1748
1747 mActionBeamVCard = 0; 1749 mActionBeamVCard = 0;
1748 mActionBeam = 0; 1750 mActionBeam = 0;
1749 1751
1750#ifndef DESKTOP_VERSION 1752#ifndef DESKTOP_VERSION
1751 if ( Ir::supported() ) { 1753 if ( Ir::supported() ) {
1752 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, 1754 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this,
1753 SLOT( beamVCard() ), actionCollection(), 1755 SLOT( beamVCard() ), actionCollection(),
1754 "kaddressbook_beam_vcard" ); 1756 "kaddressbook_beam_vcard" );
1755 1757
1756 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, 1758 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this,
1757 SLOT( beamMySelf() ), actionCollection(), 1759 SLOT( beamMySelf() ), actionCollection(),
1758 "kaddressbook_beam_myself" ); 1760 "kaddressbook_beam_myself" );
1759 } 1761 }
1760#endif 1762#endif
1761 1763
1762 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, 1764 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
1763 this, SLOT( editContact2() ), 1765 this, SLOT( editContact2() ),
1764 actionCollection(), "file_properties" ); 1766 actionCollection(), "file_properties" );
1765 1767
1766#ifdef KAB_EMBEDDED 1768#ifdef KAB_EMBEDDED
1767 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); 1769 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() );
1768 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, 1770 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0,
1769 mMainWindow, SLOT( exit() ), 1771 mMainWindow, SLOT( exit() ),
1770 actionCollection(), "quit" ); 1772 actionCollection(), "quit" );
1771#endif //KAB_EMBEDDED 1773#endif //KAB_EMBEDDED
1772 1774
1773 // edit menu 1775 // edit menu
1774 if ( mIsPart ) { 1776 if ( mIsPart ) {
1775 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, 1777 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
1776 SLOT( copyContacts() ), actionCollection(), 1778 SLOT( copyContacts() ), actionCollection(),
1777 "kaddressbook_copy" ); 1779 "kaddressbook_copy" );
1778 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, 1780 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this,
1779 SLOT( cutContacts() ), actionCollection(), 1781 SLOT( cutContacts() ), actionCollection(),
1780 "kaddressbook_cut" ); 1782 "kaddressbook_cut" );
1781 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, 1783 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this,
1782 SLOT( pasteContacts() ), actionCollection(), 1784 SLOT( pasteContacts() ), actionCollection(),
1783 "kaddressbook_paste" ); 1785 "kaddressbook_paste" );
1784 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, 1786 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this,
1785 SLOT( selectAllContacts() ), actionCollection(), 1787 SLOT( selectAllContacts() ), actionCollection(),
1786 "kaddressbook_select_all" ); 1788 "kaddressbook_select_all" );
1787 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, 1789 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this,
1788 SLOT( undo() ), actionCollection(), 1790 SLOT( undo() ), actionCollection(),
1789 "kaddressbook_undo" ); 1791 "kaddressbook_undo" );
1790 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, 1792 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z,
1791 this, SLOT( redo() ), actionCollection(), 1793 this, SLOT( redo() ), actionCollection(),
1792 "kaddressbook_redo" ); 1794 "kaddressbook_redo" );
1793 } else { 1795 } else {
1794 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); 1796 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
1795 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); 1797 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
1796 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); 1798 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
1797 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); 1799 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
1798 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); 1800 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
1799 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); 1801 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
1800 } 1802 }
1801 1803
1802 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", 1804 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
1803 Key_Delete, this, SLOT( deleteContacts() ), 1805 Key_Delete, this, SLOT( deleteContacts() ),
1804 actionCollection(), "edit_delete" ); 1806 actionCollection(), "edit_delete" );
1805 1807
1806 mActionUndo->setEnabled( false ); 1808 mActionUndo->setEnabled( false );
1807 mActionRedo->setEnabled( false ); 1809 mActionRedo->setEnabled( false );
1808 1810
1809 // settings menu 1811 // settings menu
1810#ifdef KAB_EMBEDDED 1812#ifdef KAB_EMBEDDED
1811//US special menuentry to configure the addressbook resources. On KDE 1813//US special menuentry to configure the addressbook resources. On KDE
1812// you do that through the control center !!! 1814// you do that through the control center !!!
1813 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, 1815 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this,
1814 SLOT( configureResources() ), actionCollection(), 1816 SLOT( configureResources() ), actionCollection(),
1815 "kaddressbook_configure_resources" ); 1817 "kaddressbook_configure_resources" );
1816#endif //KAB_EMBEDDED 1818#endif //KAB_EMBEDDED
1817 1819
1818 if ( mIsPart ) { 1820 if ( mIsPart ) {
1819 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, 1821 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this,
1820 SLOT( openConfigDialog() ), actionCollection(), 1822 SLOT( openConfigDialog() ), actionCollection(),
1821 "kaddressbook_configure" ); 1823 "kaddressbook_configure" );
1822 1824
1823 //US not implemented yet 1825 //US not implemented yet
1824 //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, 1826 //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
1825 // this, SLOT( configureKeyBindings() ), actionCollection(), 1827 // this, SLOT( configureKeyBindings() ), actionCollection(),
1826 // "kaddressbook_configure_shortcuts" ); 1828 // "kaddressbook_configure_shortcuts" );
1827#ifdef KAB_EMBEDDED 1829#ifdef KAB_EMBEDDED
1828 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); 1830 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
1829 mActionConfigureToolbars->setEnabled( false ); 1831 mActionConfigureToolbars->setEnabled( false );
1830#endif //KAB_EMBEDDED 1832#endif //KAB_EMBEDDED
1831 1833
1832 } else { 1834 } else {
1833 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); 1835 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
1834 1836
1835 //US not implemented yet 1837 //US not implemented yet
1836 //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); 1838 //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
1837 } 1839 }
1838 1840
1839 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, 1841 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
1840 actionCollection(), "options_show_jump_bar" ); 1842 actionCollection(), "options_show_jump_bar" );
1841 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); 1843 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
1842 1844
1843 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, 1845 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0,
1844 actionCollection(), "options_show_details" ); 1846 actionCollection(), "options_show_details" );
1845 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); 1847 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
1846 1848
1847 1849
1848 mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this, 1850 mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this,
1849 SLOT( toggleBeamReceive() ), actionCollection(), 1851 SLOT( toggleBeamReceive() ), actionCollection(),
1850 "kaddressbook_beam_rec" ); 1852 "kaddressbook_beam_rec" );
1851 1853
1852 1854
1853 // misc 1855 // misc
1854 // only enable LDAP lookup if we can handle the protocol 1856 // only enable LDAP lookup if we can handle the protocol
1855#ifndef KAB_EMBEDDED 1857#ifndef KAB_EMBEDDED
1856 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { 1858 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
1857 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, 1859 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
1858 this, SLOT( openLDAPDialog() ), actionCollection(), 1860 this, SLOT( openLDAPDialog() ), actionCollection(),
1859 "ldap_lookup" ); 1861 "ldap_lookup" );
1860 } 1862 }
1861#else //KAB_EMBEDDED 1863#else //KAB_EMBEDDED
1862 //qDebug("KABCore::initActions() LDAP has to be implemented"); 1864 //qDebug("KABCore::initActions() LDAP has to be implemented");
1863#endif //KAB_EMBEDDED 1865#endif //KAB_EMBEDDED
1864 1866
1865 1867
1866 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, 1868 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
1867 SLOT( setWhoAmI() ), actionCollection(), 1869 SLOT( setWhoAmI() ), actionCollection(),
1868 "set_personal" ); 1870 "set_personal" );
1869 1871
1870 1872
1871 1873
1872 1874
1873 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, 1875 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
1874 SLOT( setCategories() ), actionCollection(), 1876 SLOT( setCategories() ), actionCollection(),
1875 "edit_set_categories" ); 1877 "edit_set_categories" );
1876 1878
1877 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, 1879 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this,
1878 SLOT( removeVoice() ), actionCollection(), 1880 SLOT( removeVoice() ), actionCollection(),
1879 "remove_voice" ); 1881 "remove_voice" );
1880 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, 1882 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this,
1881 SLOT( importFromOL() ), actionCollection(), 1883 SLOT( importFromOL() ), actionCollection(),
1882 "import_OL" ); 1884 "import_OL" );
1883#ifdef KAB_EMBEDDED 1885#ifdef KAB_EMBEDDED
1884 mActionLicence = new KAction( i18n( "Licence" ), 0, 1886 mActionLicence = new KAction( i18n( "Licence" ), 0,
1885 this, SLOT( showLicence() ), actionCollection(), 1887 this, SLOT( showLicence() ), actionCollection(),
1886 "licence_about_data" ); 1888 "licence_about_data" );
1887 mActionFaq = new KAction( i18n( "Faq" ), 0, 1889 mActionFaq = new KAction( i18n( "Faq" ), 0,
1888 this, SLOT( faq() ), actionCollection(), 1890 this, SLOT( faq() ), actionCollection(),
1889 "faq_about_data" ); 1891 "faq_about_data" );
1890 mActionWN = new KAction( i18n( "What's New?" ), 0, 1892 mActionWN = new KAction( i18n( "What's New?" ), 0,
1891 this, SLOT( whatsnew() ), actionCollection(), 1893 this, SLOT( whatsnew() ), actionCollection(),
1892 "wn" ); 1894 "wn" );
1893 mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0, 1895 mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0,
1894 this, SLOT( synchowto() ), actionCollection(), 1896 this, SLOT( synchowto() ), actionCollection(),
1895 "sync" ); 1897 "sync" );
1896 1898
1897 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, 1899 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0,
1898 this, SLOT( createAboutData() ), actionCollection(), 1900 this, SLOT( createAboutData() ), actionCollection(),
1899 "kaddressbook_about_data" ); 1901 "kaddressbook_about_data" );
1900#endif //KAB_EMBEDDED 1902#endif //KAB_EMBEDDED
1901 1903
1902 clipboardDataChanged(); 1904 clipboardDataChanged();
1903 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1905 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1904 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1906 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1905} 1907}
1906 1908
1907//US we need this function, to plug all actions into the correct menues. 1909//US we need this function, to plug all actions into the correct menues.
1908// KDE uses a XML format to plug the actions, but we work her without this overhead. 1910// KDE uses a XML format to plug the actions, but we work her without this overhead.
1909void KABCore::addActionsManually() 1911void KABCore::addActionsManually()
1910{ 1912{
1911//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1913//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1912 1914
1913#ifdef KAB_EMBEDDED 1915#ifdef KAB_EMBEDDED
1914 QPopupMenu *fileMenu = new QPopupMenu( this ); 1916 QPopupMenu *fileMenu = new QPopupMenu( this );
1915 QPopupMenu *editMenu = new QPopupMenu( this ); 1917 QPopupMenu *editMenu = new QPopupMenu( this );
1916 QPopupMenu *helpMenu = new QPopupMenu( this ); 1918 QPopupMenu *helpMenu = new QPopupMenu( this );
1917 1919
1918 KToolBar* tb = mMainWindow->toolBar(); 1920 KToolBar* tb = mMainWindow->toolBar();
1919 1921
1920#ifdef DESKTOP_VERSION 1922#ifdef DESKTOP_VERSION
1921 QMenuBar* mb = mMainWindow->menuBar(); 1923 QMenuBar* mb = mMainWindow->menuBar();
1922 1924
1923 //US setup menubar. 1925 //US setup menubar.
1924 //Disable the following block if you do not want to have a menubar. 1926 //Disable the following block if you do not want to have a menubar.
1925 mb->insertItem( "&File", fileMenu ); 1927 mb->insertItem( "&File", fileMenu );
1926 mb->insertItem( "&Edit", editMenu ); 1928 mb->insertItem( "&Edit", editMenu );
1927 mb->insertItem( "&View", viewMenu ); 1929 mb->insertItem( "&View", viewMenu );
1928 mb->insertItem( "&Settings", settingsMenu ); 1930 mb->insertItem( "&Settings", settingsMenu );
1929 mb->insertItem( i18n("Synchronize"), syncMenu ); 1931 mb->insertItem( i18n("Synchronize"), syncMenu );
1930 mb->insertItem( "&Change selected", changeMenu ); 1932 mb->insertItem( "&Change selected", changeMenu );
1931 mb->insertItem( "&Help", helpMenu ); 1933 mb->insertItem( "&Help", helpMenu );
1932 mIncSearchWidget = new IncSearchWidget( tb ); 1934 mIncSearchWidget = new IncSearchWidget( tb );
1933 // tb->insertWidget(-1, 0, mIncSearchWidget); 1935 // tb->insertWidget(-1, 0, mIncSearchWidget);
1934 1936
1935#else 1937#else
1936 //US setup toolbar 1938 //US setup toolbar
1937 QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); 1939 QPEMenuBar *menuBarTB = new QPEMenuBar( tb );
1938 QPopupMenu *popupBarTB = new QPopupMenu( this ); 1940 QPopupMenu *popupBarTB = new QPopupMenu( this );
1939 menuBarTB->insertItem( "ME", popupBarTB); 1941 menuBarTB->insertItem( "ME", popupBarTB);
1940 tb->insertWidget(-1, 0, menuBarTB); 1942 tb->insertWidget(-1, 0, menuBarTB);
1941 mIncSearchWidget = new IncSearchWidget( tb ); 1943 mIncSearchWidget = new IncSearchWidget( tb );
1942 1944
1943 tb->enableMoving(false); 1945 tb->enableMoving(false);
1944 popupBarTB->insertItem( "&File", fileMenu ); 1946 popupBarTB->insertItem( "&File", fileMenu );
1945 popupBarTB->insertItem( "&Edit", editMenu ); 1947 popupBarTB->insertItem( "&Edit", editMenu );
1946 popupBarTB->insertItem( "&View", viewMenu ); 1948 popupBarTB->insertItem( "&View", viewMenu );
1947 popupBarTB->insertItem( "&Settings", settingsMenu ); 1949 popupBarTB->insertItem( "&Settings", settingsMenu );
1948 popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); 1950 popupBarTB->insertItem( i18n("Synchronize"), syncMenu );
1949 mViewManager->getFilterAction()->plug ( popupBarTB); 1951 mViewManager->getFilterAction()->plug ( popupBarTB);
1950 popupBarTB->insertItem( "&Change selected", changeMenu ); 1952 popupBarTB->insertItem( "&Change selected", changeMenu );
1951 popupBarTB->insertItem( "&Help", helpMenu ); 1953 popupBarTB->insertItem( "&Help", helpMenu );
1952 if (QApplication::desktop()->width() > 320 ) { 1954 if (QApplication::desktop()->width() > 320 ) {
1953 // mViewManager->getFilterAction()->plug ( tb); 1955 // mViewManager->getFilterAction()->plug ( tb);
1954 } 1956 }
1955#endif 1957#endif
1956 // mActionQuit->plug ( mMainWindow->toolBar()); 1958 // mActionQuit->plug ( mMainWindow->toolBar());
1957 1959
1958 1960
1959 1961
1960 //US Now connect the actions with the menue entries. 1962 //US Now connect the actions with the menue entries.
1961 mActionPrint->plug( fileMenu ); 1963 mActionPrint->plug( fileMenu );
1962 mActionMail->plug( fileMenu ); 1964 mActionMail->plug( fileMenu );
1963 fileMenu->insertSeparator(); 1965 fileMenu->insertSeparator();
1964 1966
1965 mActionNewContact->plug( fileMenu ); 1967 mActionNewContact->plug( fileMenu );
1966 mActionNewContact->plug( tb ); 1968 mActionNewContact->plug( tb );
1967 1969
1968 mActionEditAddressee->plug( fileMenu ); 1970 mActionEditAddressee->plug( fileMenu );
1969 if ((KGlobal::getDesktopSize() > KGlobal::Small ) || 1971 if ((KGlobal::getDesktopSize() > KGlobal::Small ) ||
1970 (!KABPrefs::instance()->mMultipleViewsAtOnce )) 1972 (!KABPrefs::instance()->mMultipleViewsAtOnce ))
1971 mActionEditAddressee->plug( tb ); 1973 mActionEditAddressee->plug( tb );
1972 1974
1973 fileMenu->insertSeparator(); 1975 fileMenu->insertSeparator();
1974 mActionSave->plug( fileMenu ); 1976 mActionSave->plug( fileMenu );
1975 fileMenu->insertItem( "&Import", ImportMenu ); 1977 fileMenu->insertItem( "&Import", ImportMenu );
1976 fileMenu->insertItem( "&Export", ExportMenu ); 1978 fileMenu->insertItem( "&Export", ExportMenu );
1977 fileMenu->insertSeparator(); 1979 fileMenu->insertSeparator();
1978 mActionMailVCard->plug( fileMenu ); 1980 mActionMailVCard->plug( fileMenu );
1979#ifndef DESKTOP_VERSION 1981#ifndef DESKTOP_VERSION
1980 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); 1982 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu );
1981 if ( Ir::supported() ) mActionBeam->plug(fileMenu ); 1983 if ( Ir::supported() ) mActionBeam->plug(fileMenu );
1982#endif 1984#endif
1983 fileMenu->insertSeparator(); 1985 fileMenu->insertSeparator();
1984 mActionQuit->plug( fileMenu ); 1986 mActionQuit->plug( fileMenu );
1985#ifdef _WIN32_ 1987#ifdef _WIN32_
1986 mActionImportOL->plug( ImportMenu ); 1988 mActionImportOL->plug( ImportMenu );
1987#endif 1989#endif
1988 // edit menu 1990 // edit menu
1989 mActionUndo->plug( editMenu ); 1991 mActionUndo->plug( editMenu );
1990 mActionRedo->plug( editMenu ); 1992 mActionRedo->plug( editMenu );
1991 editMenu->insertSeparator(); 1993 editMenu->insertSeparator();
1992 mActionCut->plug( editMenu ); 1994 mActionCut->plug( editMenu );
1993 mActionCopy->plug( editMenu ); 1995 mActionCopy->plug( editMenu );
1994 mActionPaste->plug( editMenu ); 1996 mActionPaste->plug( editMenu );
1995 mActionDelete->plug( editMenu ); 1997 mActionDelete->plug( editMenu );
1996 editMenu->insertSeparator(); 1998 editMenu->insertSeparator();
1997 mActionSelectAll->plug( editMenu ); 1999 mActionSelectAll->plug( editMenu );
1998 2000
1999 mActionRemoveVoice->plug( changeMenu ); 2001 mActionRemoveVoice->plug( changeMenu );
2000 // settings menu 2002 // settings menu
2001//US special menuentry to configure the addressbook resources. On KDE 2003//US special menuentry to configure the addressbook resources. On KDE
2002// you do that through the control center !!! 2004// you do that through the control center !!!
2003 mActionConfigResources->plug( settingsMenu ); 2005 mActionConfigResources->plug( settingsMenu );
2004 settingsMenu->insertSeparator(); 2006 settingsMenu->insertSeparator();
2005 2007
2006 mActionConfigKAddressbook->plug( settingsMenu ); 2008 mActionConfigKAddressbook->plug( settingsMenu );
2007 2009
2008 if ( mIsPart ) { 2010 if ( mIsPart ) {
2009 //US not implemented yet 2011 //US not implemented yet
2010 //mActionConfigShortcuts->plug( settingsMenu ); 2012 //mActionConfigShortcuts->plug( settingsMenu );
2011 //mActionConfigureToolbars->plug( settingsMenu ); 2013 //mActionConfigureToolbars->plug( settingsMenu );
2012 2014
2013 } else { 2015 } else {
2014 //US not implemented yet 2016 //US not implemented yet
2015 //mActionKeyBindings->plug( settingsMenu ); 2017 //mActionKeyBindings->plug( settingsMenu );
2016 } 2018 }
2017 2019
2018 settingsMenu->insertSeparator(); 2020 settingsMenu->insertSeparator();
2019 2021
2020 mActionJumpBar->plug( settingsMenu ); 2022 mActionJumpBar->plug( settingsMenu );
2021 mActionDetails->plug( settingsMenu ); 2023 mActionDetails->plug( settingsMenu );
2022 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) 2024 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop )
2023 mActionDetails->plug( tb ); 2025 mActionDetails->plug( tb );
2024 settingsMenu->insertSeparator(); 2026 settingsMenu->insertSeparator();
2025 mActionBR->plug(settingsMenu ); 2027 mActionBR->plug(settingsMenu );
2026 settingsMenu->insertSeparator(); 2028 settingsMenu->insertSeparator();
2027 2029
2028 mActionWhoAmI->plug( settingsMenu ); 2030 mActionWhoAmI->plug( settingsMenu );
2029 mActionCategories->plug( settingsMenu ); 2031 mActionCategories->plug( settingsMenu );
2030 2032
2031 2033
2032 mActionWN->plug( helpMenu ); 2034 mActionWN->plug( helpMenu );
2033 mActionSyncHowto->plug( helpMenu ); 2035 mActionSyncHowto->plug( helpMenu );
2034 mActionLicence->plug( helpMenu ); 2036 mActionLicence->plug( helpMenu );
2035 mActionFaq->plug( helpMenu ); 2037 mActionFaq->plug( helpMenu );
2036 mActionAboutKAddressbook->plug( helpMenu ); 2038 mActionAboutKAddressbook->plug( helpMenu );
2037 2039
2038 if (KGlobal::getDesktopSize() > KGlobal::Small ) { 2040 if (KGlobal::getDesktopSize() > KGlobal::Small ) {
2039 2041
2040 mActionSave->plug( tb ); 2042 mActionSave->plug( tb );
2041 mViewManager->getFilterAction()->plug ( tb); 2043 mViewManager->getFilterAction()->plug ( tb);
2042 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { 2044 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) {
2043 mActionUndo->plug( tb ); 2045 mActionUndo->plug( tb );
2044 mActionDelete->plug( tb ); 2046 mActionDelete->plug( tb );
2045 mActionRedo->plug( tb ); 2047 mActionRedo->plug( tb );
2046 } 2048 }
2049 } else {
2050 if (KABPrefs::instance()->mMultipleViewsAtOnce )
2051 mActionSave->plug( tb );
2047 } 2052 }
2048 //mActionQuit->plug ( tb ); 2053 //mActionQuit->plug ( tb );
2049 // tb->insertWidget(-1, 0, mIncSearchWidget, 6); 2054 // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
2050 2055
2051 //US link the searchwidget first to this. 2056 //US link the searchwidget first to this.
2052 // The real linkage to the toolbar happens later. 2057 // The real linkage to the toolbar happens later.
2053//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); 2058//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
2054//US tb->insertItem( mIncSearchWidget ); 2059//US tb->insertItem( mIncSearchWidget );
2055/*US 2060/*US
2056 mIncSearchWidget = new IncSearchWidget( tb ); 2061 mIncSearchWidget = new IncSearchWidget( tb );
2057 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 2062 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
2058 SLOT( incrementalSearch( const QString& ) ) ); 2063 SLOT( incrementalSearch( const QString& ) ) );
2059 2064
2060 mJumpButtonBar = new JumpButtonBar( this, this ); 2065 mJumpButtonBar = new JumpButtonBar( this, this );
2061 2066
2062//US topLayout->addWidget( mJumpButtonBar ); 2067//US topLayout->addWidget( mJumpButtonBar );
2063 this->layout()->add( mJumpButtonBar ); 2068 this->layout()->add( mJumpButtonBar );
2064*/ 2069*/
2065 2070
2066#endif //KAB_EMBEDDED 2071#endif //KAB_EMBEDDED
2067 2072
2068 mActionExport2phone->plug( ExportMenu ); 2073 mActionExport2phone->plug( ExportMenu );
2069 connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); 2074 connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) );
2070 syncManager->fillSyncMenu(); 2075 syncManager->fillSyncMenu();
2071 2076
2072} 2077}
2073void KABCore::showLicence() 2078void KABCore::showLicence()
2074{ 2079{
2075 KApplication::showLicence(); 2080 KApplication::showLicence();
2076} 2081}
2077void KABCore::removeVoice() 2082void KABCore::removeVoice()
2078{ 2083{
2079 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) 2084 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No )
2080 return; 2085 return;
2081 KABC::Addressee::List list = mViewManager->selectedAddressees(); 2086 KABC::Addressee::List list = mViewManager->selectedAddressees();
2082 KABC::Addressee::List::Iterator it; 2087 KABC::Addressee::List::Iterator it;
2083 for ( it = list.begin(); it != list.end(); ++it ) { 2088 for ( it = list.begin(); it != list.end(); ++it ) {
2084 2089
2085 if ( (*it).removeVoice() ) 2090 if ( (*it).removeVoice() )
2086 contactModified((*it) ); 2091 contactModified((*it) );
2087 } 2092 }
2088} 2093}
2089 2094
2090 2095
2091 2096
2092void KABCore::clipboardDataChanged() 2097void KABCore::clipboardDataChanged()
2093{ 2098{
2094 2099
2095 if ( mReadWrite ) 2100 if ( mReadWrite )
2096 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); 2101 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
2097 2102
2098} 2103}
2099 2104
2100void KABCore::updateActionMenu() 2105void KABCore::updateActionMenu()
2101{ 2106{
2102 UndoStack *undo = UndoStack::instance(); 2107 UndoStack *undo = UndoStack::instance();
2103 RedoStack *redo = RedoStack::instance(); 2108 RedoStack *redo = RedoStack::instance();
2104 2109
2105 if ( undo->isEmpty() ) 2110 if ( undo->isEmpty() )
2106 mActionUndo->setText( i18n( "Undo" ) ); 2111 mActionUndo->setText( i18n( "Undo" ) );
2107 else 2112 else
2108 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); 2113 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
2109 2114
2110 mActionUndo->setEnabled( !undo->isEmpty() ); 2115 mActionUndo->setEnabled( !undo->isEmpty() );
2111 2116
2112 if ( !redo->top() ) 2117 if ( !redo->top() )
2113 mActionRedo->setText( i18n( "Redo" ) ); 2118 mActionRedo->setText( i18n( "Redo" ) );
2114 else 2119 else
2115 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); 2120 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
2116 2121
2117 mActionRedo->setEnabled( !redo->isEmpty() ); 2122 mActionRedo->setEnabled( !redo->isEmpty() );
2118} 2123}
2119 2124
2120void KABCore::configureKeyBindings() 2125void KABCore::configureKeyBindings()
2121{ 2126{
2122#ifndef KAB_EMBEDDED 2127#ifndef KAB_EMBEDDED
2123 KKeyDialog::configure( actionCollection(), true ); 2128 KKeyDialog::configure( actionCollection(), true );
2124#else //KAB_EMBEDDED 2129#else //KAB_EMBEDDED
2125 qDebug("KABCore::configureKeyBindings() not implemented"); 2130 qDebug("KABCore::configureKeyBindings() not implemented");
2126#endif //KAB_EMBEDDED 2131#endif //KAB_EMBEDDED
2127} 2132}
2128 2133
2129#ifdef KAB_EMBEDDED 2134#ifdef KAB_EMBEDDED
2130void KABCore::configureResources() 2135void KABCore::configureResources()
2131{ 2136{
2132 KRES::KCMKResources dlg( this, "" , 0 ); 2137 KRES::KCMKResources dlg( this, "" , 0 );
2133 2138
2134 if ( !dlg.exec() ) 2139 if ( !dlg.exec() )
2135 return; 2140 return;
2136 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); 2141 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") );
2137} 2142}
2138#endif //KAB_EMBEDDED 2143#endif //KAB_EMBEDDED
2139 2144
2140 2145
2141/* this method will be called through the QCop interface from Ko/Pi to select addresses 2146/* this method will be called through the QCop interface from Ko/Pi to select addresses
2142 * for the attendees list of an event. 2147 * for the attendees list of an event.
2143 */ 2148 */
2144void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) 2149void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid)
2145{ 2150{
2146 QStringList nameList; 2151 QStringList nameList;
2147 QStringList emailList; 2152 QStringList emailList;
2148 QStringList uidList; 2153 QStringList uidList;
2149 2154
2150 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); 2155 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this);
2151 uint i=0; 2156 uint i=0;
2152 for (i=0; i < list.count(); i++) 2157 for (i=0; i < list.count(); i++)
2153 { 2158 {
2154 nameList.append(list[i].realName()); 2159 nameList.append(list[i].realName());
2155 emailList.append(list[i].preferredEmail()); 2160 emailList.append(list[i].preferredEmail());
2156 uidList.append(list[i].uid()); 2161 uidList.append(list[i].uid());
2157 } 2162 }
2158 2163
2159 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); 2164 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList);
2160 2165
2161} 2166}
2162 2167
2163/* this method will be called through the QCop interface from Ko/Pi to select birthdays 2168/* this method will be called through the QCop interface from Ko/Pi to select birthdays
2164 * to put them into the calendar. 2169 * to put them into the calendar.
2165 */ 2170 */
2166void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) 2171void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid)
2167{ 2172{
2168 // qDebug("KABCore::requestForBirthdayList"); 2173 // qDebug("KABCore::requestForBirthdayList");
2169 QStringList birthdayList; 2174 QStringList birthdayList;
2170 QStringList anniversaryList; 2175 QStringList anniversaryList;
2171 QStringList realNameList; 2176 QStringList realNameList;
2172 QStringList preferredEmailList; 2177 QStringList preferredEmailList;
2173 QStringList assembledNameList; 2178 QStringList assembledNameList;
2174 QStringList uidList; 2179 QStringList uidList;
2175 2180
2176 KABC::AddressBook::Iterator it; 2181 KABC::AddressBook::Iterator it;
2177 2182
2178 int count = 0; 2183 int count = 0;
2179 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 2184 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
2180 ++count; 2185 ++count;
2181 } 2186 }
2182 QProgressBar bar(count,0 ); 2187 QProgressBar bar(count,0 );
2183 int w = 300; 2188 int w = 300;
2184 if ( QApplication::desktop()->width() < 320 ) 2189 if ( QApplication::desktop()->width() < 320 )
2185 w = 220; 2190 w = 220;
2186 int h = bar.sizeHint().height() ; 2191 int h = bar.sizeHint().height() ;
2187 int dw = QApplication::desktop()->width(); 2192 int dw = QApplication::desktop()->width();
2188 int dh = QApplication::desktop()->height(); 2193 int dh = QApplication::desktop()->height();
2189 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2194 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2190 bar.show(); 2195 bar.show();
2191 bar.setCaption (i18n("Collecting birthdays - close to abort!") ); 2196 bar.setCaption (i18n("Collecting birthdays - close to abort!") );
2192 qApp->processEvents(); 2197 qApp->processEvents();
2193 2198
2194 QDate bday; 2199 QDate bday;
2195 QString anni; 2200 QString anni;
2196 QString formattedbday; 2201 QString formattedbday;
2197 2202
2198 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) 2203 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it )
2199 { 2204 {
2200 if ( ! bar.isVisible() ) 2205 if ( ! bar.isVisible() )
2201 return; 2206 return;
2202 bar.setProgress( count++ ); 2207 bar.setProgress( count++ );
2203 qApp->processEvents(); 2208 qApp->processEvents();
2204 bday = (*it).birthday().date(); 2209 bday = (*it).birthday().date();
2205 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); 2210 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" );
2206 2211
2207 if ( bday.isValid() || !anni.isEmpty()) 2212 if ( bday.isValid() || !anni.isEmpty())
2208 { 2213 {
2209 if (bday.isValid()) 2214 if (bday.isValid())
2210 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); 2215 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate);
2211 else 2216 else
2212 formattedbday = "NOTVALID"; 2217 formattedbday = "NOTVALID";
2213 if (anni.isEmpty()) 2218 if (anni.isEmpty())
2214 anni = "INVALID"; 2219 anni = "INVALID";
2215 2220
2216 birthdayList.append(formattedbday); 2221 birthdayList.append(formattedbday);
2217 anniversaryList.append(anni); //should be ISODate 2222 anniversaryList.append(anni); //should be ISODate
2218 realNameList.append((*it).realName()); 2223 realNameList.append((*it).realName());
2219 preferredEmailList.append((*it).preferredEmail()); 2224 preferredEmailList.append((*it).preferredEmail());
2220 assembledNameList.append((*it).assembledName()); 2225 assembledNameList.append((*it).assembledName());
2221 uidList.append((*it).uid()); 2226 uidList.append((*it).uid());
2222 2227
2223 qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); 2228 qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() );
2224 } 2229 }
2225 } 2230 }
2226 2231
2227 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); 2232 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList);
2228 2233
2229} 2234}
2230 2235
2231/* this method will be called through the QCop interface from other apps to show details of a contact. 2236/* this method will be called through the QCop interface from other apps to show details of a contact.
2232 */ 2237 */
2233void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) 2238void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid)
2234{ 2239{
2235 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); 2240 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1());
2236 2241
2237 QString foundUid = QString::null; 2242 QString foundUid = QString::null;
2238 if ( ! uid.isEmpty() ) { 2243 if ( ! uid.isEmpty() ) {
2239 Addressee adrr = mAddressBook->findByUid( uid ); 2244 Addressee adrr = mAddressBook->findByUid( uid );
2240 if ( !adrr.isEmpty() ) { 2245 if ( !adrr.isEmpty() ) {
2241 foundUid = uid; 2246 foundUid = uid;
2242 } 2247 }
2243 if ( email == "sendbacklist" ) { 2248 if ( email == "sendbacklist" ) {
2244 //qDebug("ssssssssssssssssssssssend "); 2249 //qDebug("ssssssssssssssssssssssend ");
2245 QStringList nameList; 2250 QStringList nameList;
2246 QStringList emailList; 2251 QStringList emailList;
2247 QStringList uidList; 2252 QStringList uidList;
2248 nameList.append(adrr.realName()); 2253 nameList.append(adrr.realName());
2249 emailList = adrr.emails(); 2254 emailList = adrr.emails();
2250 uidList.append( adrr.preferredEmail()); 2255 uidList.append( adrr.preferredEmail());
2251 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); 2256 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
2252 return; 2257 return;
2253 } 2258 }
2254 2259
2255 } 2260 }
2256 2261
2257 if ( email == "sendbacklist" ) 2262 if ( email == "sendbacklist" )
2258 return; 2263 return;
2259 if (foundUid.isEmpty()) 2264 if (foundUid.isEmpty())
2260 { 2265 {
2261 //find the uid of the person first 2266 //find the uid of the person first
2262 Addressee::List namelist; 2267 Addressee::List namelist;
2263 Addressee::List emaillist; 2268 Addressee::List emaillist;
2264 2269
2265 if (!name.isEmpty()) 2270 if (!name.isEmpty())
2266 namelist = mAddressBook->findByName( name ); 2271 namelist = mAddressBook->findByName( name );
2267 2272
2268 if (!email.isEmpty()) 2273 if (!email.isEmpty())
2269 emaillist = mAddressBook->findByEmail( email ); 2274 emaillist = mAddressBook->findByEmail( email );
2270 qDebug("count %d %d ", namelist.count(),emaillist.count() ); 2275 qDebug("count %d %d ", namelist.count(),emaillist.count() );
2271 //check if we have a match in Namelist and Emaillist 2276 //check if we have a match in Namelist and Emaillist
2272 if ((namelist.count() == 0) && (emaillist.count() > 0)) { 2277 if ((namelist.count() == 0) && (emaillist.count() > 0)) {
2273 foundUid = emaillist[0].uid(); 2278 foundUid = emaillist[0].uid();
2274 } 2279 }
2275 else if ((namelist.count() > 0) && (emaillist.count() == 0)) 2280 else if ((namelist.count() > 0) && (emaillist.count() == 0))
2276 foundUid = namelist[0].uid(); 2281 foundUid = namelist[0].uid();
2277 else 2282 else
2278 { 2283 {
2279 for (int i = 0; i < namelist.count(); i++) 2284 for (int i = 0; i < namelist.count(); i++)
2280 { 2285 {
2281 for (int j = 0; j < emaillist.count(); j++) 2286 for (int j = 0; j < emaillist.count(); j++)
2282 { 2287 {
2283 if (namelist[i] == emaillist[j]) 2288 if (namelist[i] == emaillist[j])
2284 { 2289 {
2285 foundUid = namelist[i].uid(); 2290 foundUid = namelist[i].uid();
2286 } 2291 }
2287 } 2292 }
2288 } 2293 }
2289 } 2294 }
2290 } 2295 }
2291 else 2296 else
2292 { 2297 {
2293 foundUid = uid; 2298 foundUid = uid;
2294 } 2299 }
2295 2300
2296 if (!foundUid.isEmpty()) 2301 if (!foundUid.isEmpty())
2297 { 2302 {
2298 2303
2299 // raise Ka/Pi if it is in the background 2304 // raise Ka/Pi if it is in the background
2300#ifndef DESKTOP_VERSION 2305#ifndef DESKTOP_VERSION
2301#ifndef KORG_NODCOP 2306#ifndef KORG_NODCOP
2302 //QCopEnvelope e("QPE/Application/kapi", "raise()"); 2307 //QCopEnvelope e("QPE/Application/kapi", "raise()");
2303#endif 2308#endif
2304#endif 2309#endif
2305 2310
2306 mMainWindow->showMaximized(); 2311 mMainWindow->showMaximized();
2307 mMainWindow-> raise(); 2312 mMainWindow-> raise();
2308 2313
2309 mViewManager->setSelected( "", false); 2314 mViewManager->setSelected( "", false);
2310 mViewManager->refreshView( "" ); 2315 mViewManager->refreshView( "" );
2311 mViewManager->setSelected( foundUid, true ); 2316 mViewManager->setSelected( foundUid, true );
2312 mViewManager->refreshView( foundUid ); 2317 mViewManager->refreshView( foundUid );
2313 2318
2314 if ( !mMultipleViewsAtOnce ) 2319 if ( !mMultipleViewsAtOnce )
2315 { 2320 {
2316 setDetailsVisible( true ); 2321 setDetailsVisible( true );
2317 mActionDetails->setChecked(true); 2322 mActionDetails->setChecked(true);
2318 } 2323 }
2319 } 2324 }
2320} 2325}
2321 2326
2322void KABCore::whatsnew() 2327void KABCore::whatsnew()
2323{ 2328{
2324 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); 2329 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" );
2325} 2330}
2326void KABCore::synchowto() 2331void KABCore::synchowto()
2327{ 2332{
2328 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); 2333 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
2329} 2334}
2330 2335
2331void KABCore::faq() 2336void KABCore::faq()
2332{ 2337{
2333 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2338 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2334} 2339}
2335 2340
2336#include <libkcal/syncdefines.h> 2341#include <libkcal/syncdefines.h>
2337 2342
2338KABC::Addressee KABCore::getLastSyncAddressee() 2343KABC::Addressee KABCore::getLastSyncAddressee()
2339{ 2344{
2340 Addressee lse; 2345 Addressee lse;
2341 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2346 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2342 2347
2343 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2348 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2344 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2349 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2345 if (lse.isEmpty()) { 2350 if (lse.isEmpty()) {
2346 qDebug("Creating new last-syncAddressee "); 2351 qDebug("Creating new last-syncAddressee ");
2347 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2352 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2348 QString sum = ""; 2353 QString sum = "";
2349 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2354 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2350 sum = "E: "; 2355 sum = "E: ";
2351 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2356 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2352 lse.setRevision( mLastAddressbookSync ); 2357 lse.setRevision( mLastAddressbookSync );
2353 lse.setCategories( i18n("SyncEvent") ); 2358 lse.setCategories( i18n("SyncEvent") );
2354 mAddressBook->insertAddressee( lse ); 2359 mAddressBook->insertAddressee( lse );
2355 } 2360 }
2356 return lse; 2361 return lse;
2357} 2362}
2358int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2363int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2359{ 2364{
2360 2365
2361 //void setZaurusId(int id); 2366 //void setZaurusId(int id);
2362 // int zaurusId() const; 2367 // int zaurusId() const;
2363 // void setZaurusUid(int id); 2368 // void setZaurusUid(int id);
2364 // int zaurusUid() const; 2369 // int zaurusUid() const;
2365 // void setZaurusStat(int id); 2370 // void setZaurusStat(int id);
2366 // int zaurusStat() const; 2371 // int zaurusStat() const;
2367 // 0 equal 2372 // 0 equal
2368 // 1 take local 2373 // 1 take local
2369 // 2 take remote 2374 // 2 take remote
2370 // 3 cancel 2375 // 3 cancel
2371 QDateTime lastSync = mLastAddressbookSync; 2376 QDateTime lastSync = mLastAddressbookSync;
2372 QDateTime localMod = local->revision(); 2377 QDateTime localMod = local->revision();
2373 QDateTime remoteMod = remote->revision(); 2378 QDateTime remoteMod = remote->revision();
2374 2379
2375 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2380 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2376 2381
2377 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2382 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2378 bool remCh, locCh; 2383 bool remCh, locCh;
2379 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2384 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2380 2385
2381 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2386 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2382 locCh = ( localMod > mLastAddressbookSync ); 2387 locCh = ( localMod > mLastAddressbookSync );
2383 if ( !remCh && ! locCh ) { 2388 if ( !remCh && ! locCh ) {
2384 //qDebug("both not changed "); 2389 //qDebug("both not changed ");
2385 lastSync = localMod.addDays(1); 2390 lastSync = localMod.addDays(1);
2386 if ( mode <= SYNC_PREF_ASK ) 2391 if ( mode <= SYNC_PREF_ASK )
2387 return 0; 2392 return 0;
2388 } else { 2393 } else {
2389 if ( locCh ) { 2394 if ( locCh ) {
2390 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2395 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2391 lastSync = localMod.addDays( -1 ); 2396 lastSync = localMod.addDays( -1 );
2392 if ( !remCh ) 2397 if ( !remCh )
2393 remoteMod =( lastSync.addDays( -1 ) ); 2398 remoteMod =( lastSync.addDays( -1 ) );
2394 } else { 2399 } else {
2395 //qDebug(" not loc changed "); 2400 //qDebug(" not loc changed ");
2396 lastSync = localMod.addDays( 1 ); 2401 lastSync = localMod.addDays( 1 );
2397 if ( remCh ) 2402 if ( remCh )
2398 remoteMod =( lastSync.addDays( 1 ) ); 2403 remoteMod =( lastSync.addDays( 1 ) );
2399 2404
2400 } 2405 }
2401 } 2406 }
2402 full = true; 2407 full = true;
2403 if ( mode < SYNC_PREF_ASK ) 2408 if ( mode < SYNC_PREF_ASK )
2404 mode = SYNC_PREF_ASK; 2409 mode = SYNC_PREF_ASK;
2405 } else { 2410 } else {
2406 if ( localMod == remoteMod ) 2411 if ( localMod == remoteMod )
2407 return 0; 2412 return 0;
2408 2413
2409 } 2414 }
2410 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2415 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2411 2416
2412 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 2417 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
2413 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2418 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2414 //full = true; //debug only 2419 //full = true; //debug only
2415 if ( full ) { 2420 if ( full ) {
2416 bool equ = ( (*local) == (*remote) ); 2421 bool equ = ( (*local) == (*remote) );
2417 if ( equ ) { 2422 if ( equ ) {
2418 //qDebug("equal "); 2423 //qDebug("equal ");
2419 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2424 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2420 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2425 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2421 } 2426 }
2422 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2427 if ( mode < SYNC_PREF_FORCE_LOCAL )
2423 return 0; 2428 return 0;
2424 2429
2425 }//else //debug only 2430 }//else //debug only
2426 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2431 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2427 } 2432 }
2428 int result; 2433 int result;
2429 bool localIsNew; 2434 bool localIsNew;
2430 //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() ); 2435 //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() );
2431 2436
2432 if ( full && mode < SYNC_PREF_NEWEST ) 2437 if ( full && mode < SYNC_PREF_NEWEST )
2433 mode = SYNC_PREF_ASK; 2438 mode = SYNC_PREF_ASK;
2434 2439
2435 switch( mode ) { 2440 switch( mode ) {
2436 case SYNC_PREF_LOCAL: 2441 case SYNC_PREF_LOCAL:
2437 if ( lastSync > remoteMod ) 2442 if ( lastSync > remoteMod )
2438 return 1; 2443 return 1;
2439 if ( lastSync > localMod ) 2444 if ( lastSync > localMod )
2440 return 2; 2445 return 2;
2441 return 1; 2446 return 1;
2442 break; 2447 break;
2443 case SYNC_PREF_REMOTE: 2448 case SYNC_PREF_REMOTE:
2444 if ( lastSync > remoteMod ) 2449 if ( lastSync > remoteMod )
2445 return 1; 2450 return 1;
2446 if ( lastSync > localMod ) 2451 if ( lastSync > localMod )
2447 return 2; 2452 return 2;
2448 return 2; 2453 return 2;
2449 break; 2454 break;
2450 case SYNC_PREF_NEWEST: 2455 case SYNC_PREF_NEWEST:
2451 if ( localMod > remoteMod ) 2456 if ( localMod > remoteMod )
2452 return 1; 2457 return 1;
2453 else 2458 else
2454 return 2; 2459 return 2;
2455 break; 2460 break;
2456 case SYNC_PREF_ASK: 2461 case SYNC_PREF_ASK:
2457 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2462 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2458 if ( lastSync > remoteMod ) 2463 if ( lastSync > remoteMod )
2459 return 1; 2464 return 1;
2460 if ( lastSync > localMod ) 2465 if ( lastSync > localMod )
2461 return 2; 2466 return 2;
2462 localIsNew = localMod >= remoteMod; 2467 localIsNew = localMod >= remoteMod;
2463 //qDebug("conflict! ************************************** "); 2468 //qDebug("conflict! ************************************** ");
2464 { 2469 {
2465 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2470 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2466 result = acd.executeD(localIsNew); 2471 result = acd.executeD(localIsNew);
2467 return result; 2472 return result;
2468 } 2473 }
2469 break; 2474 break;
2470 case SYNC_PREF_FORCE_LOCAL: 2475 case SYNC_PREF_FORCE_LOCAL:
2471 return 1; 2476 return 1;
2472 break; 2477 break;
2473 case SYNC_PREF_FORCE_REMOTE: 2478 case SYNC_PREF_FORCE_REMOTE:
2474 return 2; 2479 return 2;
2475 break; 2480 break;
2476 2481
2477 default: 2482 default:
2478 // SYNC_PREF_TAKE_BOTH not implemented 2483 // SYNC_PREF_TAKE_BOTH not implemented
2479 break; 2484 break;
2480 } 2485 }
2481 return 0; 2486 return 0;
2482} 2487}
2483 2488
2484 2489
2485bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2490bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2486{ 2491{
2487 bool syncOK = true; 2492 bool syncOK = true;
2488 int addedAddressee = 0; 2493 int addedAddressee = 0;
2489 int addedAddresseeR = 0; 2494 int addedAddresseeR = 0;
2490 int deletedAddresseeR = 0; 2495 int deletedAddresseeR = 0;
2491 int deletedAddresseeL = 0; 2496 int deletedAddresseeL = 0;
2492 int changedLocal = 0; 2497 int changedLocal = 0;
2493 int changedRemote = 0; 2498 int changedRemote = 0;
2494 2499
2495 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2500 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2496 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2501 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2497 2502
2498 //QPtrList<Addressee> el = local->rawAddressees(); 2503 //QPtrList<Addressee> el = local->rawAddressees();
2499 Addressee addresseeR; 2504 Addressee addresseeR;
2500 QString uid; 2505 QString uid;
2501 int take; 2506 int take;
2502 Addressee addresseeL; 2507 Addressee addresseeL;
2503 Addressee addresseeRSync; 2508 Addressee addresseeRSync;
2504 Addressee addresseeLSync; 2509 Addressee addresseeLSync;
2505 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2510 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2506 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2511 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2507 bool fullDateRange = false; 2512 bool fullDateRange = false;
2508 local->resetTempSyncStat(); 2513 local->resetTempSyncStat();
2509 mLastAddressbookSync = QDateTime::currentDateTime(); 2514 mLastAddressbookSync = QDateTime::currentDateTime();
2510 QDateTime modifiedCalendar = mLastAddressbookSync;; 2515 if ( syncManager->syncWithDesktop() ) {
2516 remote->removeSyncInfo( QString());//remove all info
2517 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
2518 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent;
2519 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() );
2520 } else {
2521 qDebug("ERROR: KSyncManager::mRequestedSyncEvent has invalid datatime ");
2522 }
2523 }
2524 QDateTime modifiedCalendar = mLastAddressbookSync;
2511 addresseeLSync = getLastSyncAddressee(); 2525 addresseeLSync = getLastSyncAddressee();
2512 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2526 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2513 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2527 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2514 if ( !addresseeR.isEmpty() ) { 2528 if ( !addresseeR.isEmpty() ) {
2515 addresseeRSync = addresseeR; 2529 addresseeRSync = addresseeR;
2516 remote->removeAddressee(addresseeR ); 2530 remote->removeAddressee(addresseeR );
2517 2531
2518 } else { 2532 } else {
2519 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2533 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2520 addresseeRSync = addresseeLSync ; 2534 addresseeRSync = addresseeLSync ;
2521 } else { 2535 } else {
2522 qDebug("FULLDATE 1"); 2536 qDebug("FULLDATE 1");
2523 fullDateRange = true; 2537 fullDateRange = true;
2524 Addressee newAdd; 2538 Addressee newAdd;
2525 addresseeRSync = newAdd; 2539 addresseeRSync = newAdd;
2526 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2540 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2527 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2541 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2528 addresseeRSync.setRevision( mLastAddressbookSync ); 2542 addresseeRSync.setRevision( mLastAddressbookSync );
2529 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2543 addresseeRSync.setCategories( i18n("SyncAddressee") );
2530 } 2544 }
2531 } 2545 }
2532 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2546 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2533 qDebug("FULLDATE 2"); 2547 qDebug("FULLDATE 2");
2534 fullDateRange = true; 2548 fullDateRange = true;
2535 } 2549 }
2536 if ( ! fullDateRange ) { 2550 if ( ! fullDateRange ) {
2537 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2551 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2538 2552
2539 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2553 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2540 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2554 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2541 fullDateRange = true; 2555 fullDateRange = true;
2542 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2556 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2543 } 2557 }
2544 } 2558 }
2545 // fullDateRange = true; // debug only! 2559 // fullDateRange = true; // debug only!
2546 if ( fullDateRange ) 2560 if ( fullDateRange )
2547 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2561 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2548 else 2562 else
2549 mLastAddressbookSync = addresseeLSync.revision(); 2563 mLastAddressbookSync = addresseeLSync.revision();
2550 // for resyncing if own file has changed 2564 // for resyncing if own file has changed
2551 // PENDING fixme later when implemented 2565 // PENDING fixme later when implemented
2552#if 0 2566#if 0
2553 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2567 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2554 mLastAddressbookSync = loadedFileVersion; 2568 mLastAddressbookSync = loadedFileVersion;
2555 qDebug("setting mLastAddressbookSync "); 2569 qDebug("setting mLastAddressbookSync ");
2556 } 2570 }
2557#endif 2571#endif
2558 2572
2559 //qDebug("*************************** "); 2573 //qDebug("*************************** ");
2560 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2574 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2561 QStringList er = remote->uidList(); 2575 QStringList er = remote->uidList();
2562 Addressee inR ;//= er.first(); 2576 Addressee inR ;//= er.first();
2563 Addressee inL; 2577 Addressee inL;
2564 2578
2565 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2579 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2566 2580
2567 int modulo = (er.count()/10)+1; 2581 int modulo = (er.count()/10)+1;
2568 int incCounter = 0; 2582 int incCounter = 0;
2569 while ( incCounter < er.count()) { 2583 while ( incCounter < er.count()) {
2570 if (syncManager->isProgressBarCanceled()) 2584 if (syncManager->isProgressBarCanceled())
2571 return false; 2585 return false;
2572 if ( incCounter % modulo == 0 ) 2586 if ( incCounter % modulo == 0 )
2573 syncManager->showProgressBar(incCounter); 2587 syncManager->showProgressBar(incCounter);
2574 2588
2575 uid = er[ incCounter ]; 2589 uid = er[ incCounter ];
2576 bool skipIncidence = false; 2590 bool skipIncidence = false;
2577 if ( uid.left(19) == QString("last-syncAddressee-") ) 2591 if ( uid.left(19) == QString("last-syncAddressee-") )
2578 skipIncidence = true; 2592 skipIncidence = true;
2579 QString idS,OidS; 2593 QString idS,OidS;
2580 qApp->processEvents(); 2594 qApp->processEvents();
2581 if ( !skipIncidence ) { 2595 if ( !skipIncidence ) {
2582 inL = local->findByUid( uid ); 2596 inL = local->findByUid( uid );
2583 inR = remote->findByUid( uid ); 2597 inR = remote->findByUid( uid );
2584 //inL.setResource( 0 ); 2598 //inL.setResource( 0 );
2585 //inR.setResource( 0 ); 2599 //inR.setResource( 0 );
2586 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2600 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2587 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2601 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2588 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2602 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2589 //qDebug("take %d %s ", take, inL.summary().latin1()); 2603 //qDebug("take %d %s ", take, inL.summary().latin1());
2590 if ( take == 3 ) 2604 if ( take == 3 )
2591 return false; 2605 return false;
2592 if ( take == 1 ) {// take local 2606 if ( take == 1 ) {// take local
2593 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2607 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2594 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2608 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2595 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2609 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2596 local->insertAddressee( inL, false ); 2610 local->insertAddressee( inL, false );
2597 idS = inR.externalUID(); 2611 idS = inR.externalUID();
2598 OidS = inR.originalExternalUID(); 2612 OidS = inR.originalExternalUID();
2599 } 2613 }
2600 else 2614 else
2601 idS = inR.IDStr(); 2615 idS = inR.IDStr();
2602 remote->removeAddressee( inR ); 2616 remote->removeAddressee( inR );
2603 inR = inL; 2617 inR = inL;
2604 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2618 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2605 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2619 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2606 inR.setOriginalExternalUID( OidS ); 2620 inR.setOriginalExternalUID( OidS );
2607 inR.setExternalUID( idS ); 2621 inR.setExternalUID( idS );
2622 if ( syncManager->syncWithDesktop() )
2623 inR.setIDStr( "changed" );
2608 } else { 2624 } else {
2609 inR.setIDStr( idS ); 2625 inR.setIDStr( idS );
2610 } 2626 }
2611 inR.setResource( 0 ); 2627 inR.setResource( 0 );
2612 remote->insertAddressee( inR , false); 2628 remote->insertAddressee( inR , false);
2613 ++changedRemote; 2629 ++changedRemote;
2614 } else { // take == 2 take remote 2630 } else { // take == 2 take remote
2615 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2631 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2616 if ( inR.revision().date().year() < 2004 ) 2632 if ( inR.revision().date().year() < 2004 )
2617 inR.setRevision( modifiedCalendar ); 2633 inR.setRevision( modifiedCalendar );
2618 } 2634 }
2619 idS = inL.IDStr(); 2635 idS = inL.IDStr();
2620 local->removeAddressee( inL ); 2636 local->removeAddressee( inL );
2621 inL = inR; 2637 inL = inR;
2622 inL.setIDStr( idS ); 2638 inL.setIDStr( idS );
2623 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2639 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2624 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2640 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2625 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2641 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2626 } 2642 }
2627 inL.setResource( 0 ); 2643 inL.setResource( 0 );
2628 local->insertAddressee( inL , false ); 2644 local->insertAddressee( inL , false );
2629 ++changedLocal; 2645 ++changedLocal;
2630 } 2646 }
2631 } 2647 }
2632 } 2648 }
2633 } else { // no conflict 2649 } else { // no conflict
2634 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2650 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2635 QString des = addresseeLSync.note(); 2651 QString des = addresseeLSync.note();
2636 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2652 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2637 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2653 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2638 remote->insertAddressee( inR, false ); 2654 remote->insertAddressee( inR, false );
2639 ++deletedAddresseeR; 2655 ++deletedAddresseeR;
2640 } else { 2656 } else {
2641 inR.setRevision( modifiedCalendar ); 2657 inR.setRevision( modifiedCalendar );
2642 remote->insertAddressee( inR, false ); 2658 remote->insertAddressee( inR, false );
2643 inL = inR; 2659 inL = inR;
2644 inL.setResource( 0 ); 2660 inL.setResource( 0 );
2645 local->insertAddressee( inL , false); 2661 local->insertAddressee( inL , false);
2646 ++addedAddressee; 2662 ++addedAddressee;
2647 } 2663 }
2648 } else { 2664 } else {
2649 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2665 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2650 inR.setRevision( modifiedCalendar ); 2666 inR.setRevision( modifiedCalendar );
2651 remote->insertAddressee( inR, false ); 2667 remote->insertAddressee( inR, false );
2652 inR.setResource( 0 ); 2668 inR.setResource( 0 );
2653 local->insertAddressee( inR, false ); 2669 local->insertAddressee( inR, false );
2654 ++addedAddressee; 2670 ++addedAddressee;
2655 } else { 2671 } else {
2656 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2672 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2657 remote->removeAddressee( inR ); 2673 remote->removeAddressee( inR );
2658 ++deletedAddresseeR; 2674 ++deletedAddresseeR;
2659 } 2675 }
2660 } 2676 }
2661 } 2677 }
2662 } 2678 }
2663 ++incCounter; 2679 ++incCounter;
2664 } 2680 }
2665 er.clear(); 2681 er.clear();
2666 QStringList el = local->uidList(); 2682 QStringList el = local->uidList();
2667 modulo = (el.count()/10)+1; 2683 modulo = (el.count()/10)+1;
2668 2684
2669 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2685 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2670 incCounter = 0; 2686 incCounter = 0;
2671 while ( incCounter < el.count()) { 2687 while ( incCounter < el.count()) {
2672 qApp->processEvents(); 2688 qApp->processEvents();
2673 if (syncManager->isProgressBarCanceled()) 2689 if (syncManager->isProgressBarCanceled())
2674 return false; 2690 return false;
2675 if ( incCounter % modulo == 0 ) 2691 if ( incCounter % modulo == 0 )
2676 syncManager->showProgressBar(incCounter); 2692 syncManager->showProgressBar(incCounter);
2677 uid = el[ incCounter ]; 2693 uid = el[ incCounter ];
2678 bool skipIncidence = false; 2694 bool skipIncidence = false;
2679 if ( uid.left(19) == QString("last-syncAddressee-") ) 2695 if ( uid.left(19) == QString("last-syncAddressee-") )
2680 skipIncidence = true; 2696 skipIncidence = true;
2681 if ( !skipIncidence ) { 2697 if ( !skipIncidence ) {
2682 inL = local->findByUid( uid ); 2698 inL = local->findByUid( uid );
2683 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2699 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2684 inR = remote->findByUid( uid ); 2700 inR = remote->findByUid( uid );
2685 if ( inR.isEmpty() ) { 2701 if ( inR.isEmpty() ) {
2686 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2702 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2687 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2703 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2688 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2704 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2689 local->removeAddressee( inL ); 2705 local->removeAddressee( inL );
2690 ++deletedAddresseeL; 2706 ++deletedAddresseeL;
2691 } else { 2707 } else {
2692 if ( ! syncManager->mWriteBackExistingOnly ) { 2708 if ( ! syncManager->mWriteBackExistingOnly ) {
2693 inL.removeID(mCurrentSyncDevice ); 2709 inL.removeID(mCurrentSyncDevice );
2694 ++addedAddresseeR; 2710 ++addedAddresseeR;
2695 inL.setRevision( modifiedCalendar ); 2711 inL.setRevision( modifiedCalendar );
2696 local->insertAddressee( inL, false ); 2712 local->insertAddressee( inL, false );
2697 inR = inL; 2713 inR = inL;
2698 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2714 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2699 inR.setResource( 0 ); 2715 inR.setResource( 0 );
2700 remote->insertAddressee( inR, false ); 2716 remote->insertAddressee( inR, false );
2701 } 2717 }
2702 } 2718 }
2703 } else { 2719 } else {
2704 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2720 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2705 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2721 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2706 local->removeAddressee( inL ); 2722 local->removeAddressee( inL );
2707 ++deletedAddresseeL; 2723 ++deletedAddresseeL;
2708 } else { 2724 } else {
2709 if ( ! syncManager->mWriteBackExistingOnly ) { 2725 if ( ! syncManager->mWriteBackExistingOnly ) {
2710 ++addedAddresseeR; 2726 ++addedAddresseeR;
2711 inL.setRevision( modifiedCalendar ); 2727 inL.setRevision( modifiedCalendar );
2712 local->insertAddressee( inL, false ); 2728 local->insertAddressee( inL, false );
2713 inR = inL; 2729 inR = inL;
2714 inR.setResource( 0 ); 2730 inR.setResource( 0 );
2715 remote->insertAddressee( inR, false ); 2731 remote->insertAddressee( inR, false );
2716 } 2732 }
2717 } 2733 }
2718 } 2734 }
2719 } 2735 }
2720 } 2736 }
2721 } 2737 }
2722 ++incCounter; 2738 ++incCounter;
2723 } 2739 }
2724 el.clear(); 2740 el.clear();
2725 syncManager->hideProgressBar(); 2741 syncManager->hideProgressBar();
2726 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2742 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2727 // get rid of micro seconds 2743 // get rid of micro seconds
2728 QTime t = mLastAddressbookSync.time(); 2744 QTime t = mLastAddressbookSync.time();
2729 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2745 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2730 addresseeLSync.setRevision( mLastAddressbookSync ); 2746 addresseeLSync.setRevision( mLastAddressbookSync );
2731 addresseeRSync.setRevision( mLastAddressbookSync ); 2747 addresseeRSync.setRevision( mLastAddressbookSync );
2732 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2748 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2733 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2749 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2734 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2750 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2735 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2751 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2736 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2752 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2737 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2753 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2738 addresseeRSync.setNote( "" ) ; 2754 addresseeRSync.setNote( "" ) ;
2739 addresseeLSync.setNote( "" ); 2755 addresseeLSync.setNote( "" );
2740 2756
2741 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2757 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2742 remote->insertAddressee( addresseeRSync, false ); 2758 remote->insertAddressee( addresseeRSync, false );
2743 local->insertAddressee( addresseeLSync, false ); 2759 local->insertAddressee( addresseeLSync, false );
2744 QString mes; 2760 QString mes;
2745 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 ); 2761 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 );
2746 if ( syncManager->mShowSyncSummary ) { 2762 if ( syncManager->mShowSyncSummary ) {
2747 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2763 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2748 } 2764 }
2749 qDebug( mes ); 2765 qDebug( mes );
2750 return syncOK; 2766 return syncOK;
2751} 2767}
2752 2768
2753 2769
2754//this is a overwritten callbackmethods from the syncinterface 2770//this is a overwritten callbackmethods from the syncinterface
2755bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2771bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2756{ 2772{
2757 2773
2758 //pending prepare addresseeview for output 2774 //pending prepare addresseeview for output
2759 //pending detect, if remote file has REV field. if not switch to external sync 2775 //pending detect, if remote file has REV field. if not switch to external sync
2760 mGlobalSyncMode = SYNC_MODE_NORMAL; 2776 mGlobalSyncMode = SYNC_MODE_NORMAL;
2761 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2777 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2762 2778
2763 AddressBook abLocal(filename,"syncContact"); 2779 AddressBook abLocal(filename,"syncContact");
2764 bool syncOK = false; 2780 bool syncOK = false;
2765 if ( abLocal.load() ) { 2781 if ( abLocal.load() ) {
2766 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2782 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2767 bool external = false; 2783 bool external = false;
2768 bool isXML = false; 2784 bool isXML = false;
2769 if ( filename.right(4) == ".xml") { 2785 if ( filename.right(4) == ".xml") {
2770 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2786 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2771 isXML = true; 2787 isXML = true;
2772 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2788 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2773 } else { 2789 } else {
2774 external = !manager->mIsKapiFile; 2790 external = !manager->mIsKapiFile;
2775 if ( external ) { 2791 if ( external ) {
2776 qDebug("Setting vcf mode to external "); 2792 qDebug("Setting vcf mode to external ");
2777 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2793 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2778 AddressBook::Iterator it; 2794 AddressBook::Iterator it;
2779 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2795 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2780 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2796 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2781 (*it).computeCsum( mCurrentSyncDevice ); 2797 (*it).computeCsum( mCurrentSyncDevice );
2782 } 2798 }
2783 } 2799 }
2784 } 2800 }
2785 //AddressBook::Iterator it; 2801 //AddressBook::Iterator it;
2786 //QStringList vcards; 2802 //QStringList vcards;
2787 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2803 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2788 // qDebug("Name %s ", (*it).familyName().latin1()); 2804 // qDebug("Name %s ", (*it).familyName().latin1());
2789 //} 2805 //}
2790 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2806 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2791 if ( syncOK ) { 2807 if ( syncOK ) {
2792 if ( syncManager->mWriteBackFile ) 2808 if ( syncManager->mWriteBackFile )
2793 { 2809 {
2794 if ( external ) 2810 if ( external )
2795 abLocal.removeSyncAddressees( !isXML); 2811 abLocal.removeSyncAddressees( !isXML);
2796 qDebug("Saving remote AB "); 2812 qDebug("Saving remote AB ");
2797 if ( ! abLocal.saveAB()) 2813 if ( ! abLocal.saveAB())
2798 qDebug("Error writing back AB to file "); 2814 qDebug("Error writing back AB to file ");
2799 if ( isXML ) { 2815 if ( isXML ) {
2800 // afterwrite processing 2816 // afterwrite processing
2801 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2817 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2802 } 2818 }
2803 } 2819 }
2804 } 2820 }
2805 setModified(); 2821 setModified();
2806 2822
2807 } 2823 }
2808 if ( syncOK ) 2824 if ( syncOK )
2809 mViewManager->refreshView(); 2825 mViewManager->refreshView();
2810 return syncOK; 2826 return syncOK;
2811 2827
2812} 2828}
2813void KABCore::removeSyncInfo( QString syncProfile) 2829void KABCore::removeSyncInfo( QString syncProfile)
2814{ 2830{
2815 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); 2831 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1());
2816 mAddressBook->removeSyncInfo( syncProfile ); 2832 mAddressBook->removeSyncInfo( syncProfile );
2817} 2833}
2818 2834
2819 2835
2820//this is a overwritten callbackmethods from the syncinterface 2836//this is a overwritten callbackmethods from the syncinterface
2821bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2837bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2822{ 2838{
2823 if ( resource == "phone" ) 2839 if ( resource == "phone" )
2824 return syncPhone(); 2840 return syncPhone();
2825 disableBR( true ); 2841 disableBR( true );
2826 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2842 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2827 2843
2828 AddressBook abLocal( resource,"syncContact"); 2844 AddressBook abLocal( resource,"syncContact");
2829 bool syncOK = false; 2845 bool syncOK = false;
2830 if ( abLocal.load() ) { 2846 if ( abLocal.load() ) {
2831 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2847 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2832 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2848 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2833 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); 2849 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
2834 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2850 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2835 if ( syncOK ) { 2851 if ( syncOK ) {
2836 if ( syncManager->mWriteBackFile ) { 2852 if ( syncManager->mWriteBackFile ) {
2837 abLocal.removeSyncAddressees( false ); 2853 abLocal.removeSyncAddressees( false );
2838 abLocal.saveAB(); 2854 abLocal.saveAB();
2839 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2855 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2840 } 2856 }
2841 } 2857 }
2842 setModified(); 2858 setModified();
2843 } 2859 }
2844 if ( syncOK ) 2860 if ( syncOK )
2845 mViewManager->refreshView(); 2861 mViewManager->refreshView();
2846 disableBR( false ); 2862 disableBR( false );
2847 return syncOK; 2863 return syncOK;
2848 2864
2849} 2865}
2850void KABCore::message( QString m ) 2866void KABCore::message( QString m )
2851{ 2867{
2852 topLevelWidget()->setCaption( m ); 2868 topLevelWidget()->setCaption( m );
2853 mMessageTimer->start( 15000, true ); 2869 mMessageTimer->start( 15000, true );
2854} 2870}
2855bool KABCore::syncPhone() 2871bool KABCore::syncPhone()
2856{ 2872{
2857 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2873 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2858 QString fileName = getPhoneFile(); 2874 QString fileName = getPhoneFile();
2859 if ( !PhoneAccess::readFromPhone( fileName) ) { 2875 if ( !PhoneAccess::readFromPhone( fileName) ) {
2860 message(i18n("Phone access failed!")); 2876 message(i18n("Phone access failed!"));
2861 return false; 2877 return false;
2862 } 2878 }
2863 AddressBook abLocal( fileName,"syncContact"); 2879 AddressBook abLocal( fileName,"syncContact");
2864 bool syncOK = false; 2880 bool syncOK = false;
2865 { 2881 {
2866 abLocal.importFromFile( fileName ); 2882 abLocal.importFromFile( fileName );
2867 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2883 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2868 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2884 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2869 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2885 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2870 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2886 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2871 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2887 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2872 if ( syncOK ) { 2888 if ( syncOK ) {
2873 if ( syncManager->mWriteBackFile ) { 2889 if ( syncManager->mWriteBackFile ) {
2874 abLocal.removeSyncAddressees( true ); 2890 abLocal.removeSyncAddressees( true );
2875 abLocal.saveABphone( fileName ); 2891 abLocal.saveABphone( fileName );
2876 abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); 2892 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
2877 //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 2893 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2878 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2894 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2879 } 2895 }
2880 } 2896 }
2881 setModified(); 2897 setModified();
2882 } 2898 }
2883 if ( syncOK ) 2899 if ( syncOK )
2884 mViewManager->refreshView(); 2900 mViewManager->refreshView();
2885 return syncOK; 2901 return syncOK;
2886} 2902}
2887void KABCore::getFile( bool success ) 2903void KABCore::getFile( bool success )
2888{ 2904{
2889 if ( ! success ) { 2905 if ( ! success ) {
2890 message( i18n("Error receiving file. Nothing changed!") ); 2906 message( i18n("Error receiving file. Nothing changed!") );
2891 return; 2907 return;
2892 } 2908 }
2893 int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); 2909 int count = mAddressBook->importFromFile( sentSyncFile() , false, true );
2894 if ( count ) 2910 if ( count )
2895 setModified( true ); 2911 setModified( true );
2896 message( i18n("Pi-Sync successful!") ); 2912 message( i18n("Pi-Sync successful!") );
2897 mViewManager->refreshView(); 2913 mViewManager->refreshView();
2898} 2914}
2899void KABCore::syncFileRequest() 2915void KABCore::syncFileRequest()
2900{ 2916{
2917 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) {
2918 syncManager->slotSyncMenu( 999 );
2919 }
2901 mAddressBook->export2File( sentSyncFile() ); 2920 mAddressBook->export2File( sentSyncFile() );
2902} 2921}
2903QString KABCore::sentSyncFile() 2922QString KABCore::sentSyncFile()
2904{ 2923{
2905#ifdef DESKTOP_VERSION 2924#ifdef DESKTOP_VERSION
2906 return locateLocal( "tmp", "copysyncab.vcf" ); 2925 return locateLocal( "tmp", "copysyncab.vcf" );
2907#else 2926#else
2908 return QString( "/tmp/copysyncab.vcf" ); 2927 return QString( "/tmp/copysyncab.vcf" );
2909#endif 2928#endif
2910} 2929}
2911 2930
2912void KABCore::setCaptionBack() 2931void KABCore::setCaptionBack()
2913{ 2932{
2914 mMessageTimer->stop(); 2933 mMessageTimer->stop();
2915 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2934 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2916} 2935}
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index f4fb08b..81e0d99 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -1,686 +1,691 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31 31
32#ifndef KAB_EMBEDDED 32#ifndef KAB_EMBEDDED
33#include <libkdepim/kvcarddrag.h> 33#include <libkdepim/kvcarddrag.h>
34#include <kabc/vcardconverter.h> 34#include <kabc/vcardconverter.h>
35#include <kconfig.h> 35#include <kconfig.h>
36#include <kdeversion.h> 36#include <kdeversion.h>
37#include <kiconloader.h> 37#include <kiconloader.h>
38#include <klocale.h> 38#include <klocale.h>
39#include <kmessagebox.h> 39#include <kmessagebox.h>
40#include <kmultipledrag.h> 40#include <kmultipledrag.h>
41#include <ktrader.h> 41#include <ktrader.h>
42#include <kurldrag.h> 42#include <kurldrag.h>
43 43
44#include "addresseeutil.h" 44#include "addresseeutil.h"
45#else //KAB_EMBEDDED 45#else //KAB_EMBEDDED
46#include "views/kaddressbookiconview.h" 46#include "views/kaddressbookiconview.h"
47#include "views/kaddressbooktableview.h" 47#include "views/kaddressbooktableview.h"
48#include "views/kaddressbookcardview.h" 48#include "views/kaddressbookcardview.h"
49#include "kaddressbookview.h" 49#include "kaddressbookview.h"
50 50
51#include <qaction.h> 51#include <qaction.h>
52#include <qmessagebox.h> 52#include <qmessagebox.h>
53#include <qpopupmenu.h> 53#include <qpopupmenu.h>
54#include <kconfigbase.h> 54#include <kconfigbase.h>
55 55
56#endif //KAB_EMBEDDED 56#endif //KAB_EMBEDDED
57 57
58 58
59#include <kdebug.h> 59#include <kdebug.h>
60#include <kactionclasses.h> 60#include <kactionclasses.h>
61 61
62#include <qlayout.h> 62#include <qlayout.h>
63#include <qwidgetstack.h> 63#include <qwidgetstack.h>
64 64
65#include <kabc/addressbook.h> 65#include <kabc/addressbook.h>
66#include "filtereditdialog.h" 66#include "filtereditdialog.h"
67#include "addviewdialog.h" 67#include "addviewdialog.h"
68#include "kabcore.h" 68#include "kabcore.h"
69#include "kabprefs.h" 69#include "kabprefs.h"
70#include "viewmanager.h" 70#include "viewmanager.h"
71 71
72ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) 72ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name )
73 : QWidget( parent, name ), mCore( core ), mActiveView( 0 ) 73 : QWidget( parent, name ), mCore( core ), mActiveView( 0 )
74{ 74{
75 initGUI(); 75 initGUI();
76 initActions(); 76 initActions();
77 77
78 mViewDict.setAutoDelete( true ); 78 mViewDict.setAutoDelete( true );
79 79
80 createViewFactories(); 80 createViewFactories();
81} 81}
82 82
83ViewManager::~ViewManager() 83ViewManager::~ViewManager()
84{ 84{
85 unloadViews(); 85 unloadViews();
86 mViewFactoryDict.clear(); 86 mViewFactoryDict.clear();
87} 87}
88void ViewManager::scrollUP() 88void ViewManager::scrollUP()
89{ 89{
90 if ( mActiveView ) 90 if ( mActiveView )
91 mActiveView->scrollUP(); 91 mActiveView->scrollUP();
92} 92}
93void ViewManager::scrollDOWN() 93void ViewManager::scrollDOWN()
94{ 94{
95 if ( mActiveView ) 95 if ( mActiveView )
96 mActiveView->scrollDOWN(); 96 mActiveView->scrollDOWN();
97} 97}
98void ViewManager::restoreSettings() 98void ViewManager::restoreSettings()
99{ 99{
100 mViewNameList = KABPrefs::instance()->mViewNames; 100 mViewNameList = KABPrefs::instance()->mViewNames;
101 QString activeViewName = KABPrefs::instance()->mCurrentView; 101 QString activeViewName = KABPrefs::instance()->mCurrentView;
102 102
103 mActionSelectView->setItems( mViewNameList ); 103 mActionSelectView->setItems( mViewNameList );
104 104
105 // Filter 105 // Filter
106 mFilterList = Filter::restore( mCore->config(), "Filter" ); 106 mFilterList = Filter::restore( mCore->config(), "Filter" );
107 mActionSelectFilter->setItems( filterNames() ); 107 mActionSelectFilter->setItems( filterNames() );
108 mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); 108 mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter );
109 109
110 // Tell the views to reread their config, since they may have 110 // Tell the views to reread their config, since they may have
111 // been modified by global settings 111 // been modified by global settings
112 QString _oldgroup = mCore->config()->group(); 112 QString _oldgroup = mCore->config()->group();
113 113
114 QDictIterator<KAddressBookView> it( mViewDict ); 114 QDictIterator<KAddressBookView> it( mViewDict );
115 for ( it.toFirst(); it.current(); ++it ) { 115 for ( it.toFirst(); it.current(); ++it ) {
116 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 116 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
117 it.current()->readConfig( mCore->config() ); 117 it.current()->readConfig( mCore->config() );
118 } 118 }
119 setActiveView( activeViewName ); 119 setActiveView( activeViewName );
120 120
121 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 121 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
122} 122}
123 123
124void ViewManager::saveSettings() 124void ViewManager::saveSettings()
125{ 125{
126 QString _oldgroup = mCore->config()->group(); 126 QString _oldgroup = mCore->config()->group();
127 127
128 QDictIterator<KAddressBookView> it( mViewDict ); 128 QDictIterator<KAddressBookView> it( mViewDict );
129 for ( it.toFirst(); it.current(); ++it ) { 129 for ( it.toFirst(); it.current(); ++it ) {
130 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 130 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
131#ifdef DESKTOP_VERSION 131#ifdef DESKTOP_VERSION
132 (*it)->writeConfig( mCore->config() ); 132 (*it)->writeConfig( mCore->config() );
133#else 133#else
134 (*it).writeConfig( mCore->config() ); 134 (*it).writeConfig( mCore->config() );
135#endif 135#endif
136 } 136 }
137 137
138 Filter::save( mCore->config(), "Filter", mFilterList ); 138 Filter::save( mCore->config(), "Filter", mFilterList );
139 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); 139 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem();
140 140
141 // write the view name list 141 // write the view name list
142 KABPrefs::instance()->mViewNames = mViewNameList; 142 KABPrefs::instance()->mViewNames = mViewNameList;
143 KABPrefs::instance()->mCurrentView = mActiveView->caption(); 143 KABPrefs::instance()->mCurrentView = mActiveView->caption();
144 144
145} 145}
146 146
147QStringList ViewManager::selectedUids() const 147QStringList ViewManager::selectedUids() const
148{ 148{
149 if ( mActiveView ) 149 if ( mActiveView )
150 return mActiveView->selectedUids(); 150 return mActiveView->selectedUids();
151 else 151 else
152 return QStringList(); 152 return QStringList();
153} 153}
154 154
155QStringList ViewManager::selectedEmails() const 155QStringList ViewManager::selectedEmails() const
156{ 156{
157 if ( mActiveView ) 157 if ( mActiveView )
158 return mActiveView->selectedEmails(); 158 return mActiveView->selectedEmails();
159 else 159 else
160 return QStringList(); 160 return QStringList();
161} 161}
162 162
163KABC::Addressee::List ViewManager::selectedAddressees() const 163KABC::Addressee::List ViewManager::selectedAddressees() const
164{ 164{
165 KABC::Addressee::List list; 165 KABC::Addressee::List list;
166 if ( mActiveView ) { 166 if ( mActiveView ) {
167 QStringList uids = mActiveView->selectedUids(); 167 QStringList uids = mActiveView->selectedUids();
168 QStringList::Iterator it; 168 QStringList::Iterator it;
169 for ( it = uids.begin(); it != uids.end(); ++it ) { 169 for ( it = uids.begin(); it != uids.end(); ++it ) {
170 KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); 170 KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
171 if ( !addr.isEmpty() ) 171 if ( !addr.isEmpty() )
172 list.append( addr ); 172 list.append( addr );
173 } 173 }
174 } 174 }
175 175
176 return list; 176 return list;
177} 177}
178//US added another method with no parameter, since my moc compiler does not support default parameters. 178//US added another method with no parameter, since my moc compiler does not support default parameters.
179void ViewManager::setSelected() 179void ViewManager::setSelected()
180{ 180{
181 setSelected( QString::null, true ); 181 setSelected( QString::null, true );
182} 182}
183 183
184void ViewManager::setSelected( const QString &uid, bool selected ) 184void ViewManager::setSelected( const QString &uid, bool selected )
185{ 185{
186 if ( mActiveView ) 186 if ( mActiveView )
187 mActiveView->setSelected( uid, selected ); 187 mActiveView->setSelected( uid, selected );
188} 188}
189 189
190void ViewManager::setListSelected(QStringList list) 190void ViewManager::setListSelected(QStringList list)
191{ 191{
192 int i, count = list.count(); 192 int i, count = list.count();
193 for ( i = 0; i < count;++i ) 193 for ( i = 0; i < count;++i )
194 setSelected( list[i], true ); 194 setSelected( list[i], true );
195 195
196} 196}
197void ViewManager::unloadViews() 197void ViewManager::unloadViews()
198{ 198{
199 mViewDict.clear(); 199 mViewDict.clear();
200 mActiveView = 0; 200 mActiveView = 0;
201} 201}
202 202
203void ViewManager::setActiveView( const QString &name ) 203void ViewManager::setActiveView( const QString &name )
204{ 204{
205 KAddressBookView *view = 0; 205 KAddressBookView *view = 0;
206 206
207 // Check that this isn't the same as the current active view 207 // Check that this isn't the same as the current active view
208 if ( mActiveView && ( mActiveView->caption() == name ) ) 208 if ( mActiveView && ( mActiveView->caption() == name ) )
209 return; 209 return;
210 210
211 // At this point we know the view that should be active is not 211 // At this point we know the view that should be active is not
212 // currently active. We will try to find the new on in the list. If 212 // currently active. We will try to find the new on in the list. If
213 // we can't find it, it means it hasn't been instantiated, so we will 213 // we can't find it, it means it hasn't been instantiated, so we will
214 // create it on demand. 214 // create it on demand.
215 215
216 view = mViewDict.find( name ); 216 view = mViewDict.find( name );
217 217
218 // Check if we found the view. If we didn't, then we need to create it 218 // Check if we found the view. If we didn't, then we need to create it
219 if ( view == 0 ) { 219 if ( view == 0 ) {
220 KConfig *config = mCore->config(); 220 KConfig *config = mCore->config();
221 221
222 KConfigGroupSaver saver( config, name ); 222 KConfigGroupSaver saver( config, name );
223 223
224 QString type = config->readEntry( "Type", "Table" ); 224 QString type = config->readEntry( "Type", "Table" );
225 225
226 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; 226 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl;
227 227
228 ViewFactory *factory = mViewFactoryDict.find( type ); 228 ViewFactory *factory = mViewFactoryDict.find( type );
229 if ( factory ) 229 if ( factory )
230 view = factory->view( mCore->addressBook(), mViewWidgetStack ); 230 view = factory->view( mCore->addressBook(), mViewWidgetStack );
231 231
232 if ( view ) { 232 if ( view ) {
233 view->setCaption( name ); 233 view->setCaption( name );
234 mViewDict.insert( name, view ); 234 mViewDict.insert( name, view );
235//US my version needs an int as second parameter to addWidget 235//US my version needs an int as second parameter to addWidget
236 mViewWidgetStack->addWidget( view, -1 ); 236 mViewWidgetStack->addWidget( view, -1 );
237 view->readConfig( config ); 237 view->readConfig( config );
238 238
239 // The manager just relays the signals 239 // The manager just relays the signals
240 connect( view, SIGNAL( selected( const QString& ) ), 240 connect( view, SIGNAL( selected( const QString& ) ),
241 SIGNAL( selected( const QString & ) ) ); 241 SIGNAL( selected( const QString & ) ) );
242 connect( view, SIGNAL( executed( const QString& ) ), 242 connect( view, SIGNAL( executed( const QString& ) ),
243 SIGNAL( executed( const QString& ) ) ); 243 SIGNAL( executed( const QString& ) ) );
244 244
245 connect( view, SIGNAL( deleteRequest( ) ), 245 connect( view, SIGNAL( deleteRequest( ) ),
246 SIGNAL( deleteRequest( ) ) ); 246 SIGNAL( deleteRequest( ) ) );
247 247
248 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); 248 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) );
249 connect( view, SIGNAL( dropped( QDropEvent* ) ), 249 connect( view, SIGNAL( dropped( QDropEvent* ) ),
250 SLOT( dropped( QDropEvent* ) ) ); 250 SLOT( dropped( QDropEvent* ) ) );
251 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); 251 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) );
252 } 252 }
253 } 253 }
254 254
255 // If we found or created the view, raise it and refresh it 255 // If we found or created the view, raise it and refresh it
256 if ( view ) { 256 if ( view ) {
257 mActiveView = view; 257 mActiveView = view;
258 mViewWidgetStack->raiseWidget( view ); 258 mViewWidgetStack->raiseWidget( view );
259 // Set the proper filter in the view. By setting the combo 259 // Set the proper filter in the view. By setting the combo
260 // box, the activated slot will be called, which will push 260 // box, the activated slot will be called, which will push
261 // the filter to the view and refresh it. 261 // the filter to the view and refresh it.
262 262
263 if ( view->defaultFilterType() == KAddressBookView::None ) { 263 if ( view->defaultFilterType() == KAddressBookView::None ) {
264 264
265 mActionSelectFilter->setCurrentItem( 0 ); 265 mActionSelectFilter->setCurrentItem( 0 );
266 setActiveFilter( 0 ); 266 setActiveFilter( 0 );
267 } else if ( view->defaultFilterType() == KAddressBookView::Active ) { 267 } else if ( view->defaultFilterType() == KAddressBookView::Active ) {
268 setActiveFilter( mActionSelectFilter->currentItem() ); 268 setActiveFilter( mActionSelectFilter->currentItem() );
269 } else { 269 } else {
270 uint pos = filterPosition( view->defaultFilterName() ); 270 uint pos = filterPosition( view->defaultFilterName() );
271 mActionSelectFilter->setCurrentItem( pos ); 271 mActionSelectFilter->setCurrentItem( pos );
272 setActiveFilter( pos ); 272 setActiveFilter( pos );
273 } 273 }
274//US qDebug("ViewManager::setActiveView 6" ); 274//US qDebug("ViewManager::setActiveView 6" );
275 275
276 // Update the inc search widget to show the fields in the new active 276 // Update the inc search widget to show the fields in the new active
277 // view. 277 // view.
278 mCore->setSearchFields( mActiveView->fields() ); 278 mCore->setSearchFields( mActiveView->fields() );
279 279
280//US performance optimization. setActiveFilter calls also mActiveView->refresh() 280//US performance optimization. setActiveFilter calls also mActiveView->refresh()
281//US mActiveView->refresh(); 281//US mActiveView->refresh();
282 282
283 } 283 }
284 else 284 else
285 { 285 {
286 qDebug("ViewManager::setActiveView: unable to find view" ); 286 qDebug("ViewManager::setActiveView: unable to find view" );
287 kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; 287 kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n";
288 } 288 }
289} 289}
290 290
291//US added another method with no parameter, since my moc compiler does not support default parameters. 291//US added another method with no parameter, since my moc compiler does not support default parameters.
292void ViewManager::refreshView() 292void ViewManager::refreshView()
293{ 293{
294 refreshView( QString::null ); 294 refreshView( QString::null );
295} 295}
296 296
297void ViewManager::refreshView( const QString &uid ) 297void ViewManager::refreshView( const QString &uid )
298{ 298{
299 if ( mActiveView ) 299 if ( mActiveView )
300 mActiveView->refresh( uid ); 300 mActiveView->refresh( uid );
301} 301}
302 302
303void ViewManager::setFocusAV()
304{
305 if ( mActiveView )
306 mActiveView->setFocus();
307}
303void ViewManager::editView() 308void ViewManager::editView()
304{ 309{
305 if ( !mActiveView ) 310 if ( !mActiveView )
306 return; 311 return;
307 312
308 ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); 313 ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() );
309 ViewConfigureWidget *wdg = 0; 314 ViewConfigureWidget *wdg = 0;
310 ViewConfigureDialog* dlg = 0; 315 ViewConfigureDialog* dlg = 0;
311 if ( factory ) { 316 if ( factory ) {
312 // Save the filters so the dialog has the latest set 317 // Save the filters so the dialog has the latest set
313 Filter::save( mCore->config(), "Filter", mFilterList ); 318 Filter::save( mCore->config(), "Filter", mFilterList );
314 dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); 319 dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" );
315 wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); 320 wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" );
316 } else { 321 } else {
317 qDebug("ViewManager::editView()::cannot find viewfactory "); 322 qDebug("ViewManager::editView()::cannot find viewfactory ");
318 return; 323 return;
319 } 324 }
320 if ( wdg ) { 325 if ( wdg ) {
321 dlg->setWidget( wdg ); 326 dlg->setWidget( wdg );
322 327
323#ifndef DESKTOP_VERSION 328#ifndef DESKTOP_VERSION
324 //dlg.setMaximumSize( 640, 480 ); 329 //dlg.setMaximumSize( 640, 480 );
325 //dlg->setGeometry( 40,40, 400, 300); 330 //dlg->setGeometry( 40,40, 400, 300);
326 dlg->showMaximized(); 331 dlg->showMaximized();
327#endif 332#endif
328 333
329 KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); 334 KConfigGroupSaver saver( mCore->config(), mActiveView->caption() );
330 335
331 dlg->restoreSettings( mCore->config() ); 336 dlg->restoreSettings( mCore->config() );
332 337
333 if ( dlg->exec() ) { 338 if ( dlg->exec() ) {
334 dlg->saveSettings( mCore->config() ); 339 dlg->saveSettings( mCore->config() );
335 mActiveView->readConfig( mCore->config() ); 340 mActiveView->readConfig( mCore->config() );
336 341
337 // Set the proper filter in the view. By setting the combo 342 // Set the proper filter in the view. By setting the combo
338 // box, the activated slot will be called, which will push 343 // box, the activated slot will be called, which will push
339 // the filter to the view and refresh it. 344 // the filter to the view and refresh it.
340 if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { 345 if ( mActiveView->defaultFilterType() == KAddressBookView::None ) {
341 mActionSelectFilter->setCurrentItem( 0 ); 346 mActionSelectFilter->setCurrentItem( 0 );
342 setActiveFilter( 0 ); 347 setActiveFilter( 0 );
343 } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { 348 } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) {
344 setActiveFilter( mActionSelectFilter->currentItem() ); 349 setActiveFilter( mActionSelectFilter->currentItem() );
345 } else { 350 } else {
346 uint pos = filterPosition( mActiveView->defaultFilterName() ); 351 uint pos = filterPosition( mActiveView->defaultFilterName() );
347 mActionSelectFilter->setCurrentItem( pos ); 352 mActionSelectFilter->setCurrentItem( pos );
348 setActiveFilter( pos ); 353 setActiveFilter( pos );
349 } 354 }
350 mCore->setSearchFields( mActiveView->fields() ); 355 mCore->setSearchFields( mActiveView->fields() );
351//US performance optimization. setActiveFilter calls also mActiveView->refresh() 356//US performance optimization. setActiveFilter calls also mActiveView->refresh()
352//US mActiveView->refresh(); 357//US mActiveView->refresh();
353 358
354 359
355 //US this is a bugfix, that we get notified if we change a views configuration 360 //US this is a bugfix, that we get notified if we change a views configuration
356 emit modified(); 361 emit modified();
357 362
358 } 363 }
359 364
360 } 365 }
361 delete dlg; 366 delete dlg;
362} 367}
363 368
364void ViewManager::deleteView() 369void ViewManager::deleteView()
365{ 370{
366 QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) 371 QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" )
367 .arg( mActiveView->caption() ); 372 .arg( mActiveView->caption() );
368 QString caption = i18n( "Confirm Delete" ); 373 QString caption = i18n( "Confirm Delete" );
369 374
370 375
371 if (QMessageBox::information( this, caption, 376 if (QMessageBox::information( this, caption,
372 text, 377 text,
373 i18n("Yes!"), i18n("No"), 0, 0 ) == 0) 378 i18n("Yes!"), i18n("No"), 0, 0 ) == 0)
374 { 379 {
375 mViewNameList.remove( mActiveView->caption() ); 380 mViewNameList.remove( mActiveView->caption() );
376 381
377 // remove the view from the config file 382 // remove the view from the config file
378 KConfig *config = mCore->config(); 383 KConfig *config = mCore->config();
379 config->deleteGroup( mActiveView->caption() ); 384 config->deleteGroup( mActiveView->caption() );
380 385
381 mViewDict.remove( mActiveView->caption() ); 386 mViewDict.remove( mActiveView->caption() );
382 mActiveView = 0; 387 mActiveView = 0;
383 388
384 // we are in an invalid state now, but that should be fixed after 389 // we are in an invalid state now, but that should be fixed after
385 // we emit the signal 390 // we emit the signal
386 mActionSelectView->setItems( mViewNameList ); 391 mActionSelectView->setItems( mViewNameList );
387 if ( mViewNameList.count() > 0 ) { 392 if ( mViewNameList.count() > 0 ) {
388 mActionSelectView->setCurrentItem( 0 ); 393 mActionSelectView->setCurrentItem( 0 );
389 setActiveView( mViewNameList[ 0 ] ); 394 setActiveView( mViewNameList[ 0 ] );
390 } 395 }
391 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 396 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
392 } 397 }
393} 398}
394 399
395void ViewManager::addView() 400void ViewManager::addView()
396{ 401{
397 AddViewDialog dialog( &mViewFactoryDict, this ); 402 AddViewDialog dialog( &mViewFactoryDict, this );
398 403
399 if ( dialog.exec() ) { 404 if ( dialog.exec() ) {
400 QString newName = dialog.viewName(); 405 QString newName = dialog.viewName();
401 QString type = dialog.viewType(); 406 QString type = dialog.viewType();
402 407
403 // Check for name conflicts 408 // Check for name conflicts
404 bool firstConflict = true; 409 bool firstConflict = true;
405 int numTries = 1; 410 int numTries = 1;
406 while ( mViewNameList.contains( newName ) > 0 ) { 411 while ( mViewNameList.contains( newName ) > 0 ) {
407 if ( !firstConflict ) { 412 if ( !firstConflict ) {
408 newName = newName.left( newName.length() - 4 ); 413 newName = newName.left( newName.length() - 4 );
409 firstConflict = false; 414 firstConflict = false;
410 } 415 }
411 416
412 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); 417 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries );
413 numTries++; 418 numTries++;
414 } 419 }
415 420
416 // Add the new one to the list 421 // Add the new one to the list
417 mViewNameList.append( newName ); 422 mViewNameList.append( newName );
418 423
419 // write the view to the config file, 424 // write the view to the config file,
420 KConfig *config = mCore->config(); 425 KConfig *config = mCore->config();
421 426
422 config->deleteGroup( newName ); 427 config->deleteGroup( newName );
423 428
424 KConfigGroupSaver saver( config, newName ); 429 KConfigGroupSaver saver( config, newName );
425 430
426 config->writeEntry( "Type", type ); 431 config->writeEntry( "Type", type );
427 432
428 // try to set the active view 433 // try to set the active view
429 mActionSelectView->setItems( mViewNameList ); 434 mActionSelectView->setItems( mViewNameList );
430 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); 435 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) );
431 setActiveView( newName ); 436 setActiveView( newName );
432 437
433 editView(); 438 editView();
434 439
435 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 440 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
436 } 441 }
437} 442}
438 443
439void ViewManager::createViewFactories() 444void ViewManager::createViewFactories()
440{ 445{
441#ifndef KAB_EMBEDDED 446#ifndef KAB_EMBEDDED
442 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); 447 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" );
443 KTrader::OfferList::ConstIterator it; 448 KTrader::OfferList::ConstIterator it;
444 for ( it = plugins.begin(); it != plugins.end(); ++it ) { 449 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
445 if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) 450 if ( !(*it)->hasServiceType( "KAddressBook/View" ) )
446 continue; 451 continue;
447 452
448 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); 453 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
449 454
450 if ( !factory ) { 455 if ( !factory ) {
451 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; 456 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl;
452 continue; 457 continue;
453 } 458 }
454 459
455 ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); 460 ViewFactory *viewFactory = static_cast<ViewFactory*>( factory );
456 461
457 if ( !viewFactory ) { 462 if ( !viewFactory ) {
458 kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; 463 kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl;
459 continue; 464 continue;
460 } 465 }
461 466
462 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 467 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
463 } 468 }
464 469
465#else //KAB_EMBEDDED 470#else //KAB_EMBEDDED
466 ViewFactory* viewFactory = new IconViewFactory(); 471 ViewFactory* viewFactory = new IconViewFactory();
467 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 472 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
468// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 473// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
469 474
470 viewFactory = new TableViewFactory(); 475 viewFactory = new TableViewFactory();
471 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 476 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
472// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 477// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
473 478
474 viewFactory = new CardViewFactory(); 479 viewFactory = new CardViewFactory();
475 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 480 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
476// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 481// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
477 482
478#endif //KAB_EMBEDDED 483#endif //KAB_EMBEDDED
479 484
480} 485}
481 486
482void ViewManager::dropped( QDropEvent *e ) 487void ViewManager::dropped( QDropEvent *e )
483{ 488{
484 kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl; 489 kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl;
485 490
486#ifndef KAB_EMBEDDED 491#ifndef KAB_EMBEDDED
487 492
488 QString clipText, vcards; 493 QString clipText, vcards;
489 KURL::List urls; 494 KURL::List urls;
490 495
491 if ( KURLDrag::decode( e, urls) ) { 496 if ( KURLDrag::decode( e, urls) ) {
492 KURL::List::Iterator it = urls.begin(); 497 KURL::List::Iterator it = urls.begin();
493 int c = urls.count(); 498 int c = urls.count();
494 if ( c > 1 ) { 499 if ( c > 1 ) {
495 QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); 500 QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c );
496 if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { 501 if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) {
497 for ( ; it != urls.end(); ++it ) 502 for ( ; it != urls.end(); ++it )
498 emit urlDropped( *it ); 503 emit urlDropped( *it );
499 } 504 }
500 } else if ( c == 1 ) 505 } else if ( c == 1 )
501 emit urlDropped( *it ); 506 emit urlDropped( *it );
502 } else if ( KVCardDrag::decode( e, vcards ) ) { 507 } else if ( KVCardDrag::decode( e, vcards ) ) {
503 KABC::Addressee addr; 508 KABC::Addressee addr;
504 KABC::VCardConverter converter; 509 KABC::VCardConverter converter;
505 QStringList list = QStringList::split( "\r\n\r\n", vcards ); 510 QStringList list = QStringList::split( "\r\n\r\n", vcards );
506 QStringList::Iterator it; 511 QStringList::Iterator it;
507 for ( it = list.begin(); it != list.end(); ++it ) { 512 for ( it = list.begin(); it != list.end(); ++it ) {
508 if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { 513 if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) {
509 KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); 514 KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() );
510 if ( a.isEmpty() ) { 515 if ( a.isEmpty() ) {
511 mCore->addressBook()->insertAddressee( addr ); 516 mCore->addressBook()->insertAddressee( addr );
512 emit modified(); 517 emit modified();
513 } 518 }
514 } 519 }
515 } 520 }
516 521
517 mActiveView->refresh(); 522 mActiveView->refresh();
518 } 523 }
519#else //KAB_EMBEDDED 524#else //KAB_EMBEDDED
520qDebug("ViewManager::dropped() has to be changed!!" ); 525qDebug("ViewManager::dropped() has to be changed!!" );
521#endif //KAB_EMBEDDED 526#endif //KAB_EMBEDDED
522 527
523} 528}
524 529
525void ViewManager::startDrag() 530void ViewManager::startDrag()
526{ 531{
527 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; 532 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl;
528 533
529#ifndef KAB_EMBEDDED 534#ifndef KAB_EMBEDDED
530 535
531 // Get the list of all the selected addressees 536 // Get the list of all the selected addressees
532 KABC::Addressee::List addrList; 537 KABC::Addressee::List addrList;
533 QStringList uidList = selectedUids(); 538 QStringList uidList = selectedUids();
534 QStringList::Iterator iter; 539 QStringList::Iterator iter;
535 for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) 540 for ( iter = uidList.begin(); iter != uidList.end(); ++iter )
536 addrList.append( mCore->addressBook()->findByUid( *iter ) ); 541 addrList.append( mCore->addressBook()->findByUid( *iter ) );
537 542
538 KMultipleDrag *drag = new KMultipleDrag( this ); 543 KMultipleDrag *drag = new KMultipleDrag( this );
539 drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); 544 drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) );
540 KABC::Addressee::List::Iterator it; 545 KABC::Addressee::List::Iterator it;
541 QStringList vcards; 546 QStringList vcards;
542 for ( it = addrList.begin(); it != addrList.end(); ++it ) { 547 for ( it = addrList.begin(); it != addrList.end(); ++it ) {
543 QString vcard = QString::null; 548 QString vcard = QString::null;
544 KABC::VCardConverter converter; 549 KABC::VCardConverter converter;
545 if ( converter.addresseeToVCard( *it, vcard ) ) 550 if ( converter.addresseeToVCard( *it, vcard ) )
546 vcards.append( vcard ); 551 vcards.append( vcard );
547 } 552 }
548 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); 553 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) );
549 554
550 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); 555 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) );
551 drag->dragCopy(); 556 drag->dragCopy();
552 557
553#else //KAB_EMBEDDED 558#else //KAB_EMBEDDED
554qDebug("ViewManager::startDrag() has to be changed!!" ); 559qDebug("ViewManager::startDrag() has to be changed!!" );
555#endif //KAB_EMBEDDED 560#endif //KAB_EMBEDDED
556 561
557} 562}
558void ViewManager::doSearch( const QString& s,KABC::Field *field ) 563void ViewManager::doSearch( const QString& s,KABC::Field *field )
559{ 564{
560 if ( mActiveView ) 565 if ( mActiveView )
561 mActiveView->doSearch( s, field ); 566 mActiveView->doSearch( s, field );
562 567
563} 568}
564void ViewManager::setActiveFilter( int index ) 569void ViewManager::setActiveFilter( int index )
565{ 570{
566 Filter currentFilter; 571 Filter currentFilter;
567 572
568 if ( ( index - 1 ) < 0 ) 573 if ( ( index - 1 ) < 0 )
569 currentFilter = Filter(); 574 currentFilter = Filter();
570 else 575 else
571 currentFilter = mFilterList[ index - 1 ]; 576 currentFilter = mFilterList[ index - 1 ];
572 577
573 // Check if we have a view. Since the filter combo is created before 578 // Check if we have a view. Since the filter combo is created before
574 // the view, this slot could be called before there is a valid view. 579 // the view, this slot could be called before there is a valid view.
575 if ( mActiveView ) { 580 if ( mActiveView ) {
576 mActiveView->setFilter( currentFilter ); 581 mActiveView->setFilter( currentFilter );
577 mActiveView->refresh(); 582 mActiveView->refresh();
578 emit selected( QString::null ); 583 emit selected( QString::null );
579 } 584 }
580} 585}
581 586
582void ViewManager::configureFilters() 587void ViewManager::configureFilters()
583{ 588{
584 FilterDialog dlg( this ); 589 FilterDialog dlg( this );
585 590
586 dlg.setFilters( mFilterList ); 591 dlg.setFilters( mFilterList );
587 592
588 if ( dlg.exec() ) 593 if ( dlg.exec() )
589 mFilterList = dlg.filters(); 594 mFilterList = dlg.filters();
590 595
591 uint pos = mActionSelectFilter->currentItem(); 596 uint pos = mActionSelectFilter->currentItem();
592 mActionSelectFilter->setItems( filterNames() ); 597 mActionSelectFilter->setItems( filterNames() );
593 mActionSelectFilter->setCurrentItem( pos ); 598 mActionSelectFilter->setCurrentItem( pos );
594 setActiveFilter( pos ); 599 setActiveFilter( pos );
595} 600}
596 601
597QStringList ViewManager::filterNames() const 602QStringList ViewManager::filterNames() const
598{ 603{
599 QStringList names( i18n( "No Filter" ) ); 604 QStringList names( i18n( "No Filter" ) );
600 605
601 Filter::List::ConstIterator it; 606 Filter::List::ConstIterator it;
602 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) 607 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it )
603 names.append( (*it).name() ); 608 names.append( (*it).name() );
604 609
605 return names; 610 return names;
606} 611}
607 612
608int ViewManager::filterPosition( const QString &name ) const 613int ViewManager::filterPosition( const QString &name ) const
609{ 614{
610 int pos = 0; 615 int pos = 0;
611 616
612 Filter::List::ConstIterator it; 617 Filter::List::ConstIterator it;
613 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos ) 618 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos )
614 if ( name == (*it).name() ) 619 if ( name == (*it).name() )
615 return pos + 1; 620 return pos + 1;
616 621
617 return 0; 622 return 0;
618} 623}
619 624
620void ViewManager::initActions() 625void ViewManager::initActions()
621{ 626{
622//US <ActionList name="view_loadedviews"/> 627//US <ActionList name="view_loadedviews"/>
623//US <Separator/> 628//US <Separator/>
624 629
625#ifdef KAB_EMBEDDED 630#ifdef KAB_EMBEDDED
626 QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu(); 631 QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu();
627 QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu(); 632 QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu();
628 QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu(); 633 QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu();
629#endif //KAB_EMBEDDED 634#endif //KAB_EMBEDDED
630 635
631 mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" ); 636 mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" );
632#if KDE_VERSION >= 309 637#if KDE_VERSION >= 309
633 mActionSelectView->setMenuAccelsEnabled( false ); 638 mActionSelectView->setMenuAccelsEnabled( false );
634#endif 639#endif
635 connect( mActionSelectView, SIGNAL( activated( const QString& ) ), 640 connect( mActionSelectView, SIGNAL( activated( const QString& ) ),
636 SLOT( setActiveView( const QString& ) ) ); 641 SLOT( setActiveView( const QString& ) ) );
637 642
638 643
639#ifdef KAB_EMBEDDED 644#ifdef KAB_EMBEDDED
640 mActionSelectView->plug(viewmenu); 645 mActionSelectView->plug(viewmenu);
641 viewmenu->insertSeparator(); 646 viewmenu->insertSeparator();
642#endif //KAB_EMBEDDED 647#endif //KAB_EMBEDDED
643 648
644 KAction *action; 649 KAction *action;
645 650
646 action = new KAction( i18n( "Modify View..." ), "configure", 0, this, 651 action = new KAction( i18n( "Modify View..." ), "configure", 0, this,
647 SLOT( editView() ), mCore->actionCollection(), "view_modify" ); 652 SLOT( editView() ), mCore->actionCollection(), "view_modify" );
648#ifndef KAB_EMBEDDED 653#ifndef KAB_EMBEDDED
649 action->setWhatsThis( i18n( "By pressing this button a dialog opens that allows you to modify the view of the addressbook. There you can add or remove fields that you want to be shown or hidden in the addressbook like the name for example." ) ); 654 action->setWhatsThis( i18n( "By pressing this button a dialog opens that allows you to modify the view of the addressbook. There you can add or remove fields that you want to be shown or hidden in the addressbook like the name for example." ) );
650#else //KAB_EMBEDDED 655#else //KAB_EMBEDDED
651 action->plug(viewmenu); 656 action->plug(viewmenu);
652#endif //KAB_EMBEDDED 657#endif //KAB_EMBEDDED
653 658
654 action = new KAction( i18n( "Add View..." ), "window_new", 0, this, 659 action = new KAction( i18n( "Add View..." ), "window_new", 0, this,
655 SLOT( addView() ), mCore->actionCollection(), "view_add" ); 660 SLOT( addView() ), mCore->actionCollection(), "view_add" );
656#ifndef KAB_EMBEDDED 661#ifndef KAB_EMBEDDED
657 action->setWhatsThis( i18n( "You can add a new view by choosing one of the dialog that appears after pressing the button. You have to give the view a name, so that you can distinguish between the different views." ) ); 662 action->setWhatsThis( i18n( "You can add a new view by choosing one of the dialog that appears after pressing the button. You have to give the view a name, so that you can distinguish between the different views." ) );
658#else //KAB_EMBEDDED 663#else //KAB_EMBEDDED
659 action->plug(viewmenu); 664 action->plug(viewmenu);
660#endif //KAB_EMBEDDED 665#endif //KAB_EMBEDDED
661 666
662 mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0, 667 mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0,
663 this, SLOT( deleteView() ), 668 this, SLOT( deleteView() ),
664 mCore->actionCollection(), "view_delete" ); 669 mCore->actionCollection(), "view_delete" );
665#ifndef KAB_EMBEDDED 670#ifndef KAB_EMBEDDED
666 mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) ); 671 mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) );
667#else //KAB_EMBEDDED 672#else //KAB_EMBEDDED
668 mActionDeleteView->plug(viewmenu); 673 mActionDeleteView->plug(viewmenu);
669 viewmenu->insertSeparator(); 674 viewmenu->insertSeparator();
670#endif //KAB_EMBEDDED 675#endif //KAB_EMBEDDED
671 676
672#ifndef KAB_EMBEDDED 677#ifndef KAB_EMBEDDED
673 action = new KAction( i18n( "Refresh View" ), "reload", 0, this, 678 action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
674 SLOT( refreshView(const QString &) ), mCore->actionCollection(), 679 SLOT( refreshView(const QString &) ), mCore->actionCollection(),
675 "view_refresh" ); 680 "view_refresh" );
676 action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) ); 681 action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) );
677#else //KAB_EMBEDDED 682#else //KAB_EMBEDDED
678 action = new KAction( i18n( "Refresh View" ), "reload", 0, this, 683 action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
679 SLOT( refreshView()), mCore->actionCollection(), 684 SLOT( refreshView()), mCore->actionCollection(),
680 "view_refresh" ); 685 "view_refresh" );
681 action->plug(viewmenu); 686 action->plug(viewmenu);
682 viewmenu->insertSeparator(); 687 viewmenu->insertSeparator();
683#endif //KAB_EMBEDDED 688#endif //KAB_EMBEDDED
684 689
685 action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this, 690 action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this,
686 SLOT( configureFilters() ), mCore->actionCollection(), 691 SLOT( configureFilters() ), mCore->actionCollection(),
diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h
index 585f4e9..a03a83f 100644
--- a/kaddressbook/viewmanager.h
+++ b/kaddressbook/viewmanager.h
@@ -1,156 +1,157 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#ifndef VIEWMANAGER_H 24#ifndef VIEWMANAGER_H
25#define VIEWMANAGER_H 25#define VIEWMANAGER_H
26 26
27#include <qwidget.h> 27#include <qwidget.h>
28#include <qstringlist.h> 28#include <qstringlist.h>
29#include <kaddressbookview.h> 29#include <kaddressbookview.h>
30#include <qdict.h> 30#include <qdict.h>
31 31
32class KAction; 32class KAction;
33class KSelectAction; 33class KSelectAction;
34 34
35class KABCore; 35class KABCore;
36class QWidgetStack; 36class QWidgetStack;
37class QDropEvent; 37class QDropEvent;
38 38
39namespace KABC { class AddressBook; } 39namespace KABC { class AddressBook; }
40 40
41/** 41/**
42 The view manager manages the views and everything related to them. The 42 The view manager manages the views and everything related to them. The
43 manager will load the views at startup and display a view when told to 43 manager will load the views at startup and display a view when told to
44 make one active. 44 make one active.
45 45
46 The view manager will also create and manage all dialogs directly related to 46 The view manager will also create and manage all dialogs directly related to
47 views (ie: AddView, ConfigureView, DeleteView, etc). 47 views (ie: AddView, ConfigureView, DeleteView, etc).
48 */ 48 */
49class ViewManager : public QWidget 49class ViewManager : public QWidget
50{ 50{
51 Q_OBJECT 51 Q_OBJECT
52 public: 52 public:
53 ViewManager( KABCore *core, QWidget *parent, const char *name = 0 ); 53 ViewManager( KABCore *core, QWidget *parent, const char *name = 0 );
54 ~ViewManager(); 54 ~ViewManager();
55 55
56 void restoreSettings(); 56 void restoreSettings();
57 void saveSettings(); 57 void saveSettings();
58 void doSearch( const QString& s ,KABC::Field *field ); 58 void doSearch( const QString& s ,KABC::Field *field );
59 59
60 void unloadViews(); 60 void unloadViews();
61 KSelectAction * getFilterAction() { return mActionSelectFilter; } 61 KSelectAction * getFilterAction() { return mActionSelectFilter; }
62 62
63 QStringList selectedUids() const; 63 QStringList selectedUids() const;
64 QStringList selectedEmails() const; 64 QStringList selectedEmails() const;
65 KABC::Addressee::List selectedAddressees() const; 65 KABC::Addressee::List selectedAddressees() const;
66 void setListSelected(QStringList); 66 void setListSelected(QStringList);
67 void setFocusAV();
67 68
68 public slots: 69 public slots:
69 void scrollUP(); 70 void scrollUP();
70 void scrollDOWN(); 71 void scrollDOWN();
71 72
72//US void setSelected( const QString &uid = QString::null, bool selected = true ); 73//US void setSelected( const QString &uid = QString::null, bool selected = true );
73 void setSelected( const QString &uid, bool); 74 void setSelected( const QString &uid, bool);
74//US added another method with no parameter, since my moc compiler does not support default parameters. 75//US added another method with no parameter, since my moc compiler does not support default parameters.
75 void setSelected(); 76 void setSelected();
76 77
77 78
78 79
79//US added another method with no parameter, since my moc compiler does not support default parameters. 80//US added another method with no parameter, since my moc compiler does not support default parameters.
80 void refreshView(); 81 void refreshView();
81 void refreshView( const QString &uid); 82 void refreshView( const QString &uid);
82 83
83 void editView(); 84 void editView();
84 void deleteView(); 85 void deleteView();
85 void addView(); 86 void addView();
86 87
87 protected slots: 88 protected slots:
88 /** 89 /**
89 Called whenever the user drops something in the active view. 90 Called whenever the user drops something in the active view.
90 This method will try to decode what was dropped, and if it was 91 This method will try to decode what was dropped, and if it was
91 a valid addressee, add it to the addressbook. 92 a valid addressee, add it to the addressbook.
92 */ 93 */
93 void dropped( QDropEvent* ); 94 void dropped( QDropEvent* );
94 95
95 /** 96 /**
96 Called whenever the user attempts to start a drag in the view. 97 Called whenever the user attempts to start a drag in the view.
97 This method will convert all the selected addressees into text (vcard) 98 This method will convert all the selected addressees into text (vcard)
98 and create a drag object. 99 and create a drag object.
99 */ 100 */
100 void startDrag(); 101 void startDrag();
101 102
102 signals: 103 signals:
103 /** 104 /**
104 Emitted whenever the user selects an entry in the view. 105 Emitted whenever the user selects an entry in the view.
105 */ 106 */
106 void selected( const QString &uid ); 107 void selected( const QString &uid );
107 void deleteRequest( ); 108 void deleteRequest( );
108 109
109 /** 110 /**
110 Emitted whenever the user activates an entry in the view. 111 Emitted whenever the user activates an entry in the view.
111 */ 112 */
112 void executed( const QString &uid ); 113 void executed( const QString &uid );
113 114
114 /** 115 /**
115 Emitted whenever the address book is modified in some way. 116 Emitted whenever the address book is modified in some way.
116 */ 117 */
117 void modified(); 118 void modified();
118 119
119 /** 120 /**
120 Emitted whenever a url is dragged on a view. 121 Emitted whenever a url is dragged on a view.
121 */ 122 */
122 void urlDropped( const KURL& ); 123 void urlDropped( const KURL& );
123 124
124 private slots: 125 private slots:
125 void setActiveView( const QString &name ); 126 void setActiveView( const QString &name );
126 void setActiveFilter( int index ); 127 void setActiveFilter( int index );
127 void configureFilters(); 128 void configureFilters();
128 129
129 private: 130 private:
130 void createViewFactories(); 131 void createViewFactories();
131 QStringList filterNames() const; 132 QStringList filterNames() const;
132 int filterPosition( const QString &name ) const; 133 int filterPosition( const QString &name ) const;
133 QStringList viewNames() const; 134 QStringList viewNames() const;
134 int viewPosition( const QString &name ) const; 135 int viewPosition( const QString &name ) const;
135 void initActions(); 136 void initActions();
136 void initGUI(); 137 void initGUI();
137 138
138 KABCore *mCore; 139 KABCore *mCore;
139 140
140 Filter mCurrentFilter; 141 Filter mCurrentFilter;
141 Filter::List mFilterList; 142 Filter::List mFilterList;
142 143
143 QDict<KAddressBookView> mViewDict; 144 QDict<KAddressBookView> mViewDict;
144 QDict<ViewFactory> mViewFactoryDict; 145 QDict<ViewFactory> mViewFactoryDict;
145 QStringList mViewNameList; 146 QStringList mViewNameList;
146 147
147 QWidgetStack *mViewWidgetStack; 148 QWidgetStack *mViewWidgetStack;
148 KAddressBookView *mActiveView; 149 KAddressBookView *mActiveView;
149 150
150 KAction *mActionDeleteView; 151 KAction *mActionDeleteView;
151 KSelectAction *mActionSelectFilter; 152 KSelectAction *mActionSelectFilter;
152 KSelectAction *mActionSelectView; 153 KSelectAction *mActionSelectView;
153 154
154}; 155};
155 156
156#endif 157#endif
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 326db88..6e61351 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -546,1025 +546,1025 @@ void CalendarView::computeAlarm( QString msg )
546 //mTimerTime = 0; 546 //mTimerTime = 0;
547 startAlarm( mess.mid( 11 ), filename ); 547 startAlarm( mess.mid( 11 ), filename );
548 return; 548 return;
549 } 549 }
550 if ( mess.left( 10 ) == "proc_alarm") { 550 if ( mess.left( 10 ) == "proc_alarm") {
551 bool error = false; 551 bool error = false;
552 int len = mess.mid( 10 ).find("+++"); 552 int len = mess.mid( 10 ).find("+++");
553 if ( len < 2 ) 553 if ( len < 2 )
554 error = true; 554 error = true;
555 else { 555 else {
556 tempfilename = mess.mid( 10, len ); 556 tempfilename = mess.mid( 10, len );
557 if ( !QFile::exists( tempfilename ) ) 557 if ( !QFile::exists( tempfilename ) )
558 error = true; 558 error = true;
559 } 559 }
560 if ( error ) { 560 if ( error ) {
561 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 561 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
562 mAlarmMessage += mess.mid( 10+len+3+9 ); 562 mAlarmMessage += mess.mid( 10+len+3+9 );
563 } else { 563 } else {
564 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 564 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
565 //qDebug("-----system command %s ",tempfilename.latin1() ); 565 //qDebug("-----system command %s ",tempfilename.latin1() );
566#ifndef _WIN32_ 566#ifndef _WIN32_
567 if ( vfork () == 0 ) { 567 if ( vfork () == 0 ) {
568 execl ( tempfilename.latin1(), 0 ); 568 execl ( tempfilename.latin1(), 0 );
569 return; 569 return;
570 } 570 }
571#else 571#else
572 QProcess* p = new QProcess(); 572 QProcess* p = new QProcess();
573 p->addArgument( tempfilename.latin1() ); 573 p->addArgument( tempfilename.latin1() );
574 p->start(); 574 p->start();
575 return; 575 return;
576#endif 576#endif
577 577
578 return; 578 return;
579 } 579 }
580 580
581 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 581 //qDebug("+++++++system command %s ",tempfilename.latin1() );
582 } 582 }
583 if ( mess.left( 11 ) == "audio_alarm") { 583 if ( mess.left( 11 ) == "audio_alarm") {
584 bool error = false; 584 bool error = false;
585 int len = mess.mid( 11 ).find("+++"); 585 int len = mess.mid( 11 ).find("+++");
586 if ( len < 2 ) 586 if ( len < 2 )
587 error = true; 587 error = true;
588 else { 588 else {
589 tempfilename = mess.mid( 11, len ); 589 tempfilename = mess.mid( 11, len );
590 if ( !QFile::exists( tempfilename ) ) 590 if ( !QFile::exists( tempfilename ) )
591 error = true; 591 error = true;
592 } 592 }
593 if ( ! error ) { 593 if ( ! error ) {
594 filename = tempfilename; 594 filename = tempfilename;
595 } 595 }
596 mAlarmMessage = mess.mid( 11+len+3+9 ); 596 mAlarmMessage = mess.mid( 11+len+3+9 );
597 //qDebug("audio file command %s ",tempfilename.latin1() ); 597 //qDebug("audio file command %s ",tempfilename.latin1() );
598 } 598 }
599 if ( mess.left( 9 ) == "cal_alarm") { 599 if ( mess.left( 9 ) == "cal_alarm") {
600 mAlarmMessage = mess.mid( 9 ) ; 600 mAlarmMessage = mess.mid( 9 ) ;
601 } 601 }
602 602
603 startAlarm( mAlarmMessage, filename ); 603 startAlarm( mAlarmMessage, filename );
604 604
605 605
606} 606}
607 607
608void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 608void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
609{ 609{
610 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 610 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
611 611
612 mSuspendAlarmNotification = noti; 612 mSuspendAlarmNotification = noti;
613 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 613 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
614 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 614 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
615 mSuspendTimer->start( ms , true ); 615 mSuspendTimer->start( ms , true );
616 616
617} 617}
618 618
619void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 619void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
620{ 620{
621 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 621 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
622 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 622 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
623#ifndef DESKTOP_VERSION 623#ifndef DESKTOP_VERSION
624 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 624 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
625#endif 625#endif
626 return; 626 return;
627 } 627 }
628 int maxSec; 628 int maxSec;
629 //maxSec = 5; //testing only 629 //maxSec = 5; //testing only
630 maxSec = 86400+3600; // one day+1hour 630 maxSec = 86400+3600; // one day+1hour
631 mAlarmNotification = noti; 631 mAlarmNotification = noti;
632 int sec = QDateTime::currentDateTime().secsTo( qdt ); 632 int sec = QDateTime::currentDateTime().secsTo( qdt );
633 if ( sec > maxSec ) { 633 if ( sec > maxSec ) {
634 mRecheckAlarmTimer->start( maxSec * 1000 ); 634 mRecheckAlarmTimer->start( maxSec * 1000 );
635 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 635 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
636 return; 636 return;
637 } else { 637 } else {
638 mRecheckAlarmTimer->stop(); 638 mRecheckAlarmTimer->stop();
639 } 639 }
640 //qDebug("Alarm timer started with secs: %d ", sec); 640 //qDebug("Alarm timer started with secs: %d ", sec);
641 mAlarmTimer->start( sec *1000 , true ); 641 mAlarmTimer->start( sec *1000 , true );
642 642
643} 643}
644// called by mRecheckAlarmTimer to get next alarm 644// called by mRecheckAlarmTimer to get next alarm
645// we need this, because a QTimer has only a max range of 25 days 645// we need this, because a QTimer has only a max range of 25 days
646void CalendarView::recheckTimerAlarm() 646void CalendarView::recheckTimerAlarm()
647{ 647{
648 mAlarmTimer->stop(); 648 mAlarmTimer->stop();
649 mRecheckAlarmTimer->stop(); 649 mRecheckAlarmTimer->stop();
650 mCalendar->checkAlarmForIncidence( 0, true ); 650 mCalendar->checkAlarmForIncidence( 0, true );
651} 651}
652void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 652void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
653{ 653{
654 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 654 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
655 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 655 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
656#ifndef DESKTOP_VERSION 656#ifndef DESKTOP_VERSION
657 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 657 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
658#endif 658#endif
659 return; 659 return;
660 } 660 }
661 mAlarmTimer->stop(); 661 mAlarmTimer->stop();
662} 662}
663void CalendarView::selectWeekNum ( int num ) 663void CalendarView::selectWeekNum ( int num )
664{ 664{
665 dateNavigator()->selectWeek( num ); 665 dateNavigator()->selectWeek( num );
666 mViewManager->showWeekView(); 666 mViewManager->showWeekView();
667} 667}
668KOViewManager *CalendarView::viewManager() 668KOViewManager *CalendarView::viewManager()
669{ 669{
670 return mViewManager; 670 return mViewManager;
671} 671}
672 672
673KODialogManager *CalendarView::dialogManager() 673KODialogManager *CalendarView::dialogManager()
674{ 674{
675 return mDialogManager; 675 return mDialogManager;
676} 676}
677 677
678QDate CalendarView::startDate() 678QDate CalendarView::startDate()
679{ 679{
680 DateList dates = mNavigator->selectedDates(); 680 DateList dates = mNavigator->selectedDates();
681 681
682 return dates.first(); 682 return dates.first();
683} 683}
684 684
685QDate CalendarView::endDate() 685QDate CalendarView::endDate()
686{ 686{
687 DateList dates = mNavigator->selectedDates(); 687 DateList dates = mNavigator->selectedDates();
688 688
689 return dates.last(); 689 return dates.last();
690} 690}
691 691
692 692
693void CalendarView::createPrinter() 693void CalendarView::createPrinter()
694{ 694{
695#ifndef KORG_NOPRINTER 695#ifndef KORG_NOPRINTER
696 if (!mCalPrinter) { 696 if (!mCalPrinter) {
697 mCalPrinter = new CalPrinter(this, mCalendar); 697 mCalPrinter = new CalPrinter(this, mCalendar);
698 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 698 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
699 } 699 }
700#endif 700#endif
701} 701}
702 702
703 703
704//KOPrefs::instance()->mWriteBackFile 704//KOPrefs::instance()->mWriteBackFile
705//KOPrefs::instance()->mWriteBackExistingOnly 705//KOPrefs::instance()->mWriteBackExistingOnly
706 706
707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
713 713
714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
715{ 715{
716 716
717 // 0 equal 717 // 0 equal
718 // 1 take local 718 // 1 take local
719 // 2 take remote 719 // 2 take remote
720 // 3 cancel 720 // 3 cancel
721 QDateTime lastSync = mLastCalendarSync; 721 QDateTime lastSync = mLastCalendarSync;
722 QDateTime localMod = local->lastModified(); 722 QDateTime localMod = local->lastModified();
723 QDateTime remoteMod = remote->lastModified(); 723 QDateTime remoteMod = remote->lastModified();
724 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 724 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
725 bool remCh, locCh; 725 bool remCh, locCh;
726 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 726 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
727 //if ( remCh ) 727 //if ( remCh )
728 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 728 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
729 locCh = ( localMod > mLastCalendarSync ); 729 locCh = ( localMod > mLastCalendarSync );
730 if ( !remCh && ! locCh ) { 730 if ( !remCh && ! locCh ) {
731 //qDebug("both not changed "); 731 //qDebug("both not changed ");
732 lastSync = localMod.addDays(1); 732 lastSync = localMod.addDays(1);
733 if ( mode <= SYNC_PREF_ASK ) 733 if ( mode <= SYNC_PREF_ASK )
734 return 0; 734 return 0;
735 } else { 735 } else {
736 if ( locCh ) { 736 if ( locCh ) {
737 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 737 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
738 lastSync = localMod.addDays( -1 ); 738 lastSync = localMod.addDays( -1 );
739 if ( !remCh ) 739 if ( !remCh )
740 remoteMod = ( lastSync.addDays( -1 ) ); 740 remoteMod = ( lastSync.addDays( -1 ) );
741 } else { 741 } else {
742 //qDebug(" not loc changed "); 742 //qDebug(" not loc changed ");
743 lastSync = localMod.addDays( 1 ); 743 lastSync = localMod.addDays( 1 );
744 if ( remCh ) 744 if ( remCh )
745 remoteMod =( lastSync.addDays( 1 ) ); 745 remoteMod =( lastSync.addDays( 1 ) );
746 746
747 } 747 }
748 } 748 }
749 full = true; 749 full = true;
750 if ( mode < SYNC_PREF_ASK ) 750 if ( mode < SYNC_PREF_ASK )
751 mode = SYNC_PREF_ASK; 751 mode = SYNC_PREF_ASK;
752 } else { 752 } else {
753 if ( localMod == remoteMod ) 753 if ( localMod == remoteMod )
754 // if ( local->revision() == remote->revision() ) 754 // if ( local->revision() == remote->revision() )
755 return 0; 755 return 0;
756 756
757 } 757 }
758 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 758 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
759 759
760 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 760 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
761 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 761 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
762 //full = true; //debug only 762 //full = true; //debug only
763 if ( full ) { 763 if ( full ) {
764 bool equ = false; 764 bool equ = false;
765 if ( local->type() == "Event" ) { 765 if ( local->type() == "Event" ) {
766 equ = (*((Event*) local) == *((Event*) remote)); 766 equ = (*((Event*) local) == *((Event*) remote));
767 } 767 }
768 else if ( local->type() =="Todo" ) 768 else if ( local->type() =="Todo" )
769 equ = (*((Todo*) local) == (*(Todo*) remote)); 769 equ = (*((Todo*) local) == (*(Todo*) remote));
770 else if ( local->type() =="Journal" ) 770 else if ( local->type() =="Journal" )
771 equ = (*((Journal*) local) == *((Journal*) remote)); 771 equ = (*((Journal*) local) == *((Journal*) remote));
772 if ( equ ) { 772 if ( equ ) {
773 //qDebug("equal "); 773 //qDebug("equal ");
774 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 774 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
775 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 775 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
776 } 776 }
777 if ( mode < SYNC_PREF_FORCE_LOCAL ) 777 if ( mode < SYNC_PREF_FORCE_LOCAL )
778 return 0; 778 return 0;
779 779
780 }//else //debug only 780 }//else //debug only
781 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 781 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
782 } 782 }
783 int result; 783 int result;
784 bool localIsNew; 784 bool localIsNew;
785 //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() ); 785 //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() );
786 786
787 if ( full && mode < SYNC_PREF_NEWEST ) 787 if ( full && mode < SYNC_PREF_NEWEST )
788 mode = SYNC_PREF_ASK; 788 mode = SYNC_PREF_ASK;
789 789
790 switch( mode ) { 790 switch( mode ) {
791 case SYNC_PREF_LOCAL: 791 case SYNC_PREF_LOCAL:
792 if ( lastSync > remoteMod ) 792 if ( lastSync > remoteMod )
793 return 1; 793 return 1;
794 if ( lastSync > localMod ) 794 if ( lastSync > localMod )
795 return 2; 795 return 2;
796 return 1; 796 return 1;
797 break; 797 break;
798 case SYNC_PREF_REMOTE: 798 case SYNC_PREF_REMOTE:
799 if ( lastSync > remoteMod ) 799 if ( lastSync > remoteMod )
800 return 1; 800 return 1;
801 if ( lastSync > localMod ) 801 if ( lastSync > localMod )
802 return 2; 802 return 2;
803 return 2; 803 return 2;
804 break; 804 break;
805 case SYNC_PREF_NEWEST: 805 case SYNC_PREF_NEWEST:
806 if ( localMod > remoteMod ) 806 if ( localMod > remoteMod )
807 return 1; 807 return 1;
808 else 808 else
809 return 2; 809 return 2;
810 break; 810 break;
811 case SYNC_PREF_ASK: 811 case SYNC_PREF_ASK:
812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
813 if ( lastSync > remoteMod ) 813 if ( lastSync > remoteMod )
814 return 1; 814 return 1;
815 if ( lastSync > localMod ) 815 if ( lastSync > localMod )
816 return 2; 816 return 2;
817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
818 localIsNew = localMod >= remoteMod; 818 localIsNew = localMod >= remoteMod;
819 if ( localIsNew ) 819 if ( localIsNew )
820 getEventViewerDialog()->setColorMode( 1 ); 820 getEventViewerDialog()->setColorMode( 1 );
821 else 821 else
822 getEventViewerDialog()->setColorMode( 2 ); 822 getEventViewerDialog()->setColorMode( 2 );
823 getEventViewerDialog()->setIncidence(local); 823 getEventViewerDialog()->setIncidence(local);
824 if ( localIsNew ) 824 if ( localIsNew )
825 getEventViewerDialog()->setColorMode( 2 ); 825 getEventViewerDialog()->setColorMode( 2 );
826 else 826 else
827 getEventViewerDialog()->setColorMode( 1 ); 827 getEventViewerDialog()->setColorMode( 1 );
828 getEventViewerDialog()->addIncidence(remote); 828 getEventViewerDialog()->addIncidence(remote);
829 getEventViewerDialog()->setColorMode( 0 ); 829 getEventViewerDialog()->setColorMode( 0 );
830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
832 getEventViewerDialog()->showMe(); 832 getEventViewerDialog()->showMe();
833 result = getEventViewerDialog()->executeS( localIsNew ); 833 result = getEventViewerDialog()->executeS( localIsNew );
834 return result; 834 return result;
835 835
836 break; 836 break;
837 case SYNC_PREF_FORCE_LOCAL: 837 case SYNC_PREF_FORCE_LOCAL:
838 return 1; 838 return 1;
839 break; 839 break;
840 case SYNC_PREF_FORCE_REMOTE: 840 case SYNC_PREF_FORCE_REMOTE:
841 return 2; 841 return 2;
842 break; 842 break;
843 843
844 default: 844 default:
845 // SYNC_PREF_TAKE_BOTH not implemented 845 // SYNC_PREF_TAKE_BOTH not implemented
846 break; 846 break;
847 } 847 }
848 return 0; 848 return 0;
849} 849}
850Event* CalendarView::getLastSyncEvent() 850Event* CalendarView::getLastSyncEvent()
851{ 851{
852 Event* lse; 852 Event* lse;
853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
855 if (!lse) { 855 if (!lse) {
856 lse = new Event(); 856 lse = new Event();
857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
858 QString sum = ""; 858 QString sum = "";
859 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 859 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
860 sum = "E: "; 860 sum = "E: ";
861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
862 lse->setDtStart( mLastCalendarSync ); 862 lse->setDtStart( mLastCalendarSync );
863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
864 lse->setCategories( i18n("SyncEvent") ); 864 lse->setCategories( i18n("SyncEvent") );
865 lse->setReadOnly( true ); 865 lse->setReadOnly( true );
866 mCalendar->addEvent( lse ); 866 mCalendar->addEvent( lse );
867 } 867 }
868 868
869 return lse; 869 return lse;
870 870
871} 871}
872 872
873// we check, if the to delete event has a id for a profile 873// we check, if the to delete event has a id for a profile
874// if yes, we set this id in the profile to delete 874// if yes, we set this id in the profile to delete
875void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 875void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
876{ 876{
877 if ( lastSync.count() == 0 ) { 877 if ( lastSync.count() == 0 ) {
878 //qDebug(" lastSync.count() == 0"); 878 //qDebug(" lastSync.count() == 0");
879 return; 879 return;
880 } 880 }
881 if ( toDelete->type() == "Journal" ) 881 if ( toDelete->type() == "Journal" )
882 return; 882 return;
883 883
884 Event* eve = lastSync.first(); 884 Event* eve = lastSync.first();
885 885
886 while ( eve ) { 886 while ( eve ) {
887 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 887 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
888 if ( !id.isEmpty() ) { 888 if ( !id.isEmpty() ) {
889 QString des = eve->description(); 889 QString des = eve->description();
890 QString pref = "e"; 890 QString pref = "e";
891 if ( toDelete->type() == "Todo" ) 891 if ( toDelete->type() == "Todo" )
892 pref = "t"; 892 pref = "t";
893 des += pref+ id + ","; 893 des += pref+ id + ",";
894 eve->setReadOnly( false ); 894 eve->setReadOnly( false );
895 eve->setDescription( des ); 895 eve->setDescription( des );
896 //qDebug("setdes %s ", des.latin1()); 896 //qDebug("setdes %s ", des.latin1());
897 eve->setReadOnly( true ); 897 eve->setReadOnly( true );
898 } 898 }
899 eve = lastSync.next(); 899 eve = lastSync.next();
900 } 900 }
901 901
902} 902}
903void CalendarView::checkExternalId( Incidence * inc ) 903void CalendarView::checkExternalId( Incidence * inc )
904{ 904{
905 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 905 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
906 checkExternSyncEvent( lastSync, inc ); 906 checkExternSyncEvent( lastSync, inc );
907 907
908} 908}
909bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 909bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
910{ 910{
911 bool syncOK = true; 911 bool syncOK = true;
912 int addedEvent = 0; 912 int addedEvent = 0;
913 int addedEventR = 0; 913 int addedEventR = 0;
914 int deletedEventR = 0; 914 int deletedEventR = 0;
915 int deletedEventL = 0; 915 int deletedEventL = 0;
916 int changedLocal = 0; 916 int changedLocal = 0;
917 int changedRemote = 0; 917 int changedRemote = 0;
918 //QPtrList<Event> el = local->rawEvents(); 918 //QPtrList<Event> el = local->rawEvents();
919 Event* eventR; 919 Event* eventR;
920 QString uid; 920 QString uid;
921 int take; 921 int take;
922 Event* eventL; 922 Event* eventL;
923 Event* eventRSync; 923 Event* eventRSync;
924 Event* eventLSync; 924 Event* eventLSync;
925 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 925 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
926 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 926 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
927 bool fullDateRange = false; 927 bool fullDateRange = false;
928 local->resetTempSyncStat(); 928 local->resetTempSyncStat();
929 mLastCalendarSync = QDateTime::currentDateTime(); 929 mLastCalendarSync = QDateTime::currentDateTime();
930 if ( mSyncKDE ) { 930 if ( mSyncManager->syncWithDesktop() ) {
931 remote->resetPilotStat(1); 931 remote->resetPilotStat(1);
932 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 932 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
933 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 933 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
934 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 934 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
935 } else { 935 } else {
936 qDebug("ERROR: KSyncManager::mRequestedSyncEvent has invalid datatime "); 936 qDebug("ERROR: KSyncManager::mRequestedSyncEvent has invalid datatime ");
937 } 937 }
938 } 938 }
939 QDateTime modifiedCalendar = mLastCalendarSync;; 939 QDateTime modifiedCalendar = mLastCalendarSync;;
940 eventLSync = getLastSyncEvent(); 940 eventLSync = getLastSyncEvent();
941 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 941 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
942 if ( eventR ) { 942 if ( eventR ) {
943 eventRSync = (Event*) eventR->clone(); 943 eventRSync = (Event*) eventR->clone();
944 remote->deleteEvent(eventR ); 944 remote->deleteEvent(eventR );
945 945
946 } else { 946 } else {
947 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncKDE) { 947 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
948 eventRSync = (Event*)eventLSync->clone(); 948 eventRSync = (Event*)eventLSync->clone();
949 } else { 949 } else {
950 fullDateRange = true; 950 fullDateRange = true;
951 eventRSync = new Event(); 951 eventRSync = new Event();
952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
954 eventRSync->setDtStart( mLastCalendarSync ); 954 eventRSync->setDtStart( mLastCalendarSync );
955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
956 eventRSync->setCategories( i18n("SyncEvent") ); 956 eventRSync->setCategories( i18n("SyncEvent") );
957 } 957 }
958 } 958 }
959 if ( eventLSync->dtStart() == mLastCalendarSync ) 959 if ( eventLSync->dtStart() == mLastCalendarSync )
960 fullDateRange = true; 960 fullDateRange = true;
961 961
962 if ( ! fullDateRange ) { 962 if ( ! fullDateRange ) {
963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
964 964
965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
967 fullDateRange = true; 967 fullDateRange = true;
968 } 968 }
969 } 969 }
970 if ( mSyncKDE ) { 970 if ( mSyncManager->syncWithDesktop() ) {
971 fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync ); 971 fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync );
972 } 972 }
973 if ( fullDateRange ) 973 if ( fullDateRange )
974 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 974 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
975 else 975 else
976 mLastCalendarSync = eventLSync->dtStart(); 976 mLastCalendarSync = eventLSync->dtStart();
977 // for resyncing if own file has changed 977 // for resyncing if own file has changed
978 if ( mCurrentSyncDevice == "deleteaftersync" ) { 978 if ( mCurrentSyncDevice == "deleteaftersync" ) {
979 mLastCalendarSync = loadedFileVersion; 979 mLastCalendarSync = loadedFileVersion;
980 //qDebug("setting mLastCalendarSync "); 980 //qDebug("setting mLastCalendarSync ");
981 } 981 }
982 //qDebug("*************************** "); 982 //qDebug("*************************** ");
983 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 983 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
984 QPtrList<Incidence> er = remote->rawIncidences(); 984 QPtrList<Incidence> er = remote->rawIncidences();
985 Incidence* inR = er.first(); 985 Incidence* inR = er.first();
986 Incidence* inL; 986 Incidence* inL;
987 QProgressBar bar( er.count(),0 ); 987 QProgressBar bar( er.count(),0 );
988 bar.setCaption (i18n("Syncing - close to abort!") ); 988 bar.setCaption (i18n("Syncing - close to abort!") );
989 989
990 int w = 300; 990 int w = 300;
991 if ( QApplication::desktop()->width() < 320 ) 991 if ( QApplication::desktop()->width() < 320 )
992 w = 220; 992 w = 220;
993 int h = bar.sizeHint().height() ; 993 int h = bar.sizeHint().height() ;
994 int dw = QApplication::desktop()->width(); 994 int dw = QApplication::desktop()->width();
995 int dh = QApplication::desktop()->height(); 995 int dh = QApplication::desktop()->height();
996 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 996 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
997 bar.show(); 997 bar.show();
998 int modulo = (er.count()/10)+1; 998 int modulo = (er.count()/10)+1;
999 int incCounter = 0; 999 int incCounter = 0;
1000 while ( inR ) { 1000 while ( inR ) {
1001 if ( ! bar.isVisible() ) 1001 if ( ! bar.isVisible() )
1002 return false; 1002 return false;
1003 if ( incCounter % modulo == 0 ) 1003 if ( incCounter % modulo == 0 )
1004 bar.setProgress( incCounter ); 1004 bar.setProgress( incCounter );
1005 ++incCounter; 1005 ++incCounter;
1006 uid = inR->uid(); 1006 uid = inR->uid();
1007 bool skipIncidence = false; 1007 bool skipIncidence = false;
1008 if ( uid.left(15) == QString("last-syncEvent-") ) 1008 if ( uid.left(15) == QString("last-syncEvent-") )
1009 skipIncidence = true; 1009 skipIncidence = true;
1010 QString idS; 1010 QString idS;
1011 qApp->processEvents(); 1011 qApp->processEvents();
1012 if ( !skipIncidence ) { 1012 if ( !skipIncidence ) {
1013 inL = local->incidence( uid ); 1013 inL = local->incidence( uid );
1014 if ( inL ) { // maybe conflict - same uid in both calendars 1014 if ( inL ) { // maybe conflict - same uid in both calendars
1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1016 //qDebug("take %d %s ", take, inL->summary().latin1()); 1016 //qDebug("take %d %s ", take, inL->summary().latin1());
1017 if ( take == 3 ) 1017 if ( take == 3 )
1018 return false; 1018 return false;
1019 if ( take == 1 ) {// take local 1019 if ( take == 1 ) {// take local
1020 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1020 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1021 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1021 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1022 else 1022 else
1023 idS = inR->IDStr(); 1023 idS = inR->IDStr();
1024 remote->deleteIncidence( inR ); 1024 remote->deleteIncidence( inR );
1025 inR = inL->clone(); 1025 inR = inL->clone();
1026 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1026 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1027 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1027 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1028 inR->setIDStr( idS ); 1028 inR->setIDStr( idS );
1029 remote->addIncidence( inR ); 1029 remote->addIncidence( inR );
1030 if ( mSyncKDE ) 1030 if ( mSyncManager->syncWithDesktop() )
1031 inR->setPilotId( 2 ); 1031 inR->setPilotId( 2 );
1032 ++changedRemote; 1032 ++changedRemote;
1033 } else { 1033 } else {
1034 idS = inL->IDStr(); 1034 idS = inL->IDStr();
1035 int pid = inL->pilotId(); 1035 int pid = inL->pilotId();
1036 local->deleteIncidence( inL ); 1036 local->deleteIncidence( inL );
1037 inL = inR->clone(); 1037 inL = inR->clone();
1038 if ( mSyncKDE ) 1038 if ( mSyncManager->syncWithDesktop() )
1039 inL->setPilotId( pid ); 1039 inL->setPilotId( pid );
1040 inL->setIDStr( idS ); 1040 inL->setIDStr( idS );
1041 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1041 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1042 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1042 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1043 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1043 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1044 } 1044 }
1045 local->addIncidence( inL ); 1045 local->addIncidence( inL );
1046 ++changedLocal; 1046 ++changedLocal;
1047 } 1047 }
1048 } 1048 }
1049 } else { // no conflict 1049 } else { // no conflict
1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1051 QString des = eventLSync->description(); 1051 QString des = eventLSync->description();
1052 QString pref = "e"; 1052 QString pref = "e";
1053 if ( inR->type() == "Todo" ) 1053 if ( inR->type() == "Todo" )
1054 pref = "t"; 1054 pref = "t";
1055 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1055 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1056 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1056 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1057 //remote->deleteIncidence( inR ); 1057 //remote->deleteIncidence( inR );
1058 ++deletedEventR; 1058 ++deletedEventR;
1059 } else { 1059 } else {
1060 inR->setLastModified( modifiedCalendar ); 1060 inR->setLastModified( modifiedCalendar );
1061 inL = inR->clone(); 1061 inL = inR->clone();
1062 inL->setIDStr( ":" ); 1062 inL->setIDStr( ":" );
1063 local->addIncidence( inL ); 1063 local->addIncidence( inL );
1064 ++addedEvent; 1064 ++addedEvent;
1065 } 1065 }
1066 } else { 1066 } else {
1067 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1067 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1068 inR->setLastModified( modifiedCalendar ); 1068 inR->setLastModified( modifiedCalendar );
1069 inL = inR->clone(); 1069 inL = inR->clone();
1070 inL->setIDStr( ":" ); 1070 inL->setIDStr( ":" );
1071 local->addIncidence( inL ); 1071 local->addIncidence( inL );
1072 ++addedEvent; 1072 ++addedEvent;
1073 } else { 1073 } else {
1074 checkExternSyncEvent(eventRSyncSharp, inR); 1074 checkExternSyncEvent(eventRSyncSharp, inR);
1075 remote->deleteIncidence( inR ); 1075 remote->deleteIncidence( inR );
1076 ++deletedEventR; 1076 ++deletedEventR;
1077 } 1077 }
1078 } 1078 }
1079 } 1079 }
1080 } 1080 }
1081 inR = er.next(); 1081 inR = er.next();
1082 } 1082 }
1083 QPtrList<Incidence> el = local->rawIncidences(); 1083 QPtrList<Incidence> el = local->rawIncidences();
1084 inL = el.first(); 1084 inL = el.first();
1085 modulo = (el.count()/10)+1; 1085 modulo = (el.count()/10)+1;
1086 bar.setCaption (i18n("Add / remove events") ); 1086 bar.setCaption (i18n("Add / remove events") );
1087 bar.setTotalSteps ( el.count() ) ; 1087 bar.setTotalSteps ( el.count() ) ;
1088 bar.show(); 1088 bar.show();
1089 incCounter = 0; 1089 incCounter = 0;
1090 1090
1091 while ( inL ) { 1091 while ( inL ) {
1092 1092
1093 qApp->processEvents(); 1093 qApp->processEvents();
1094 if ( ! bar.isVisible() ) 1094 if ( ! bar.isVisible() )
1095 return false; 1095 return false;
1096 if ( incCounter % modulo == 0 ) 1096 if ( incCounter % modulo == 0 )
1097 bar.setProgress( incCounter ); 1097 bar.setProgress( incCounter );
1098 ++incCounter; 1098 ++incCounter;
1099 uid = inL->uid(); 1099 uid = inL->uid();
1100 bool skipIncidence = false; 1100 bool skipIncidence = false;
1101 if ( uid.left(15) == QString("last-syncEvent-") ) 1101 if ( uid.left(15) == QString("last-syncEvent-") )
1102 skipIncidence = true; 1102 skipIncidence = true;
1103 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1103 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1104 skipIncidence = true; 1104 skipIncidence = true;
1105 if ( !skipIncidence ) { 1105 if ( !skipIncidence ) {
1106 inR = remote->incidence( uid ); 1106 inR = remote->incidence( uid );
1107 if ( ! inR ) { 1107 if ( ! inR ) {
1108 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1108 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1109 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1109 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1110 checkExternSyncEvent(eventLSyncSharp, inL); 1110 checkExternSyncEvent(eventLSyncSharp, inL);
1111 local->deleteIncidence( inL ); 1111 local->deleteIncidence( inL );
1112 ++deletedEventL; 1112 ++deletedEventL;
1113 } else { 1113 } else {
1114 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1114 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1115 inL->removeID(mCurrentSyncDevice ); 1115 inL->removeID(mCurrentSyncDevice );
1116 ++addedEventR; 1116 ++addedEventR;
1117 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1117 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1118 inL->setLastModified( modifiedCalendar ); 1118 inL->setLastModified( modifiedCalendar );
1119 inR = inL->clone(); 1119 inR = inL->clone();
1120 inR->setIDStr( ":" ); 1120 inR->setIDStr( ":" );
1121 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1121 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1122 remote->addIncidence( inR ); 1122 remote->addIncidence( inR );
1123 } 1123 }
1124 } 1124 }
1125 } else { 1125 } else {
1126 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1126 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1127 checkExternSyncEvent(eventLSyncSharp, inL); 1127 checkExternSyncEvent(eventLSyncSharp, inL);
1128 local->deleteIncidence( inL ); 1128 local->deleteIncidence( inL );
1129 ++deletedEventL; 1129 ++deletedEventL;
1130 } else { 1130 } else {
1131 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1131 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1132 ++addedEventR; 1132 ++addedEventR;
1133 inL->setLastModified( modifiedCalendar ); 1133 inL->setLastModified( modifiedCalendar );
1134 inR = inL->clone(); 1134 inR = inL->clone();
1135 inR->setIDStr( ":" ); 1135 inR->setIDStr( ":" );
1136 remote->addIncidence( inR ); 1136 remote->addIncidence( inR );
1137 } 1137 }
1138 } 1138 }
1139 } 1139 }
1140 } 1140 }
1141 } 1141 }
1142 inL = el.next(); 1142 inL = el.next();
1143 } 1143 }
1144 int delFut = 0; 1144 int delFut = 0;
1145 int remRem = 0; 1145 int remRem = 0;
1146 if ( mSyncManager->mWriteBackInFuture ) { 1146 if ( mSyncManager->mWriteBackInFuture ) {
1147 er = remote->rawIncidences(); 1147 er = remote->rawIncidences();
1148 remRem = er.count(); 1148 remRem = er.count();
1149 inR = er.first(); 1149 inR = er.first();
1150 QDateTime dt; 1150 QDateTime dt;
1151 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1151 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1152 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); 1152 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 );
1153 while ( inR ) { 1153 while ( inR ) {
1154 if ( inR->type() == "Todo" ) { 1154 if ( inR->type() == "Todo" ) {
1155 Todo * t = (Todo*)inR; 1155 Todo * t = (Todo*)inR;
1156 if ( t->hasDueDate() ) 1156 if ( t->hasDueDate() )
1157 dt = t->dtDue(); 1157 dt = t->dtDue();
1158 else 1158 else
1159 dt = cur.addSecs( 62 ); 1159 dt = cur.addSecs( 62 );
1160 } 1160 }
1161 else if (inR->type() == "Event" ) { 1161 else if (inR->type() == "Event" ) {
1162 bool ok; 1162 bool ok;
1163 dt = inR->getNextOccurence( cur, &ok ); 1163 dt = inR->getNextOccurence( cur, &ok );
1164 if ( !ok ) 1164 if ( !ok )
1165 dt = cur.addSecs( -62 ); 1165 dt = cur.addSecs( -62 );
1166 } 1166 }
1167 else 1167 else
1168 dt = inR->dtStart(); 1168 dt = inR->dtStart();
1169 if ( dt < cur || dt > end ) { 1169 if ( dt < cur || dt > end ) {
1170 remote->deleteIncidence( inR ); 1170 remote->deleteIncidence( inR );
1171 ++delFut; 1171 ++delFut;
1172 } 1172 }
1173 inR = er.next(); 1173 inR = er.next();
1174 } 1174 }
1175 } 1175 }
1176 bar.hide(); 1176 bar.hide();
1177 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1177 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1178 eventLSync->setReadOnly( false ); 1178 eventLSync->setReadOnly( false );
1179 eventLSync->setDtStart( mLastCalendarSync ); 1179 eventLSync->setDtStart( mLastCalendarSync );
1180 eventRSync->setDtStart( mLastCalendarSync ); 1180 eventRSync->setDtStart( mLastCalendarSync );
1181 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1181 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1182 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1182 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1183 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1183 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1184 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1184 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1185 eventLSync->setReadOnly( true ); 1185 eventLSync->setReadOnly( true );
1186 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncKDE) // kde is abnormal... 1186 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1187 remote->addEvent( eventRSync ); 1187 remote->addEvent( eventRSync );
1188 else 1188 else
1189 delete eventRSync; 1189 delete eventRSync;
1190 QString mes; 1190 QString mes;
1191 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); 1191 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR );
1192 QString delmess; 1192 QString delmess;
1193 if ( delFut ) { 1193 if ( delFut ) {
1194 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut); 1194 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut);
1195 mes += delmess; 1195 mes += delmess;
1196 } 1196 }
1197 if ( mSyncManager->mShowSyncSummary ) { 1197 if ( mSyncManager->mShowSyncSummary ) {
1198 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1198 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1199 } 1199 }
1200 qDebug( mes ); 1200 qDebug( mes );
1201 mCalendar->checkAlarmForIncidence( 0, true ); 1201 mCalendar->checkAlarmForIncidence( 0, true );
1202 return syncOK; 1202 return syncOK;
1203} 1203}
1204 1204
1205void CalendarView::setSyncDevice( QString s ) 1205void CalendarView::setSyncDevice( QString s )
1206{ 1206{
1207 mCurrentSyncDevice= s; 1207 mCurrentSyncDevice= s;
1208} 1208}
1209void CalendarView::setSyncName( QString s ) 1209void CalendarView::setSyncName( QString s )
1210{ 1210{
1211 mCurrentSyncName= s; 1211 mCurrentSyncName= s;
1212} 1212}
1213bool CalendarView::syncCalendar(QString filename, int mode) 1213bool CalendarView::syncCalendar(QString filename, int mode)
1214{ 1214{
1215 //qDebug("syncCalendar %s ", filename.latin1()); 1215 //qDebug("syncCalendar %s ", filename.latin1());
1216 mGlobalSyncMode = SYNC_MODE_NORMAL; 1216 mGlobalSyncMode = SYNC_MODE_NORMAL;
1217 CalendarLocal* calendar = new CalendarLocal(); 1217 CalendarLocal* calendar = new CalendarLocal();
1218 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1218 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1219 FileStorage* storage = new FileStorage( calendar ); 1219 FileStorage* storage = new FileStorage( calendar );
1220 bool syncOK = false; 1220 bool syncOK = false;
1221 storage->setFileName( filename ); 1221 storage->setFileName( filename );
1222 // qDebug("loading ... "); 1222 // qDebug("loading ... ");
1223 if ( storage->load() ) { 1223 if ( storage->load() ) {
1224 getEventViewerDialog()->setSyncMode( true ); 1224 getEventViewerDialog()->setSyncMode( true );
1225 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1225 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1226 getEventViewerDialog()->setSyncMode( false ); 1226 getEventViewerDialog()->setSyncMode( false );
1227 if ( syncOK ) { 1227 if ( syncOK ) {
1228 if ( mSyncManager->mWriteBackFile ) 1228 if ( mSyncManager->mWriteBackFile )
1229 { 1229 {
1230 storage->setSaveFormat( new ICalFormat() ); 1230 storage->setSaveFormat( new ICalFormat() );
1231 storage->save(); 1231 storage->save();
1232 } 1232 }
1233 } 1233 }
1234 setModified( true ); 1234 setModified( true );
1235 } 1235 }
1236 delete storage; 1236 delete storage;
1237 delete calendar; 1237 delete calendar;
1238 if ( syncOK ) 1238 if ( syncOK )
1239 updateView(); 1239 updateView();
1240 return syncOK; 1240 return syncOK;
1241} 1241}
1242 1242
1243void CalendarView::syncExternal( int mode ) 1243void CalendarView::syncExternal( int mode )
1244{ 1244{
1245 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1245 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1246 1246
1247 qApp->processEvents(); 1247 qApp->processEvents();
1248 CalendarLocal* calendar = new CalendarLocal(); 1248 CalendarLocal* calendar = new CalendarLocal();
1249 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1249 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1250 bool syncOK = false; 1250 bool syncOK = false;
1251 bool loadSuccess = false; 1251 bool loadSuccess = false;
1252 PhoneFormat* phoneFormat = 0; 1252 PhoneFormat* phoneFormat = 0;
1253 emit tempDisableBR(true); 1253 emit tempDisableBR(true);
1254#ifndef DESKTOP_VERSION 1254#ifndef DESKTOP_VERSION
1255 SharpFormat* sharpFormat = 0; 1255 SharpFormat* sharpFormat = 0;
1256 if ( mode == 0 ) { // sharp 1256 if ( mode == 0 ) { // sharp
1257 sharpFormat = new SharpFormat () ; 1257 sharpFormat = new SharpFormat () ;
1258 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1258 loadSuccess = sharpFormat->load( calendar, mCalendar );
1259 1259
1260 } else 1260 } else
1261#endif 1261#endif
1262 if ( mode == 1 ) { // phone 1262 if ( mode == 1 ) { // phone
1263 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1263 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1264 mSyncManager->mPhoneDevice, 1264 mSyncManager->mPhoneDevice,
1265 mSyncManager->mPhoneConnection, 1265 mSyncManager->mPhoneConnection,
1266 mSyncManager->mPhoneModel); 1266 mSyncManager->mPhoneModel);
1267 loadSuccess = phoneFormat->load( calendar,mCalendar); 1267 loadSuccess = phoneFormat->load( calendar,mCalendar);
1268 1268
1269 } else { 1269 } else {
1270 emit tempDisableBR(false); 1270 emit tempDisableBR(false);
1271 return; 1271 return;
1272 } 1272 }
1273 if ( loadSuccess ) { 1273 if ( loadSuccess ) {
1274 getEventViewerDialog()->setSyncMode( true ); 1274 getEventViewerDialog()->setSyncMode( true );
1275 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1275 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1276 getEventViewerDialog()->setSyncMode( false ); 1276 getEventViewerDialog()->setSyncMode( false );
1277 qApp->processEvents(); 1277 qApp->processEvents();
1278 if ( syncOK ) { 1278 if ( syncOK ) {
1279 if ( mSyncManager->mWriteBackFile ) 1279 if ( mSyncManager->mWriteBackFile )
1280 { 1280 {
1281 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1281 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1282 Incidence* inc = iL.first(); 1282 Incidence* inc = iL.first();
1283 if ( phoneFormat ) { 1283 if ( phoneFormat ) {
1284 while ( inc ) { 1284 while ( inc ) {
1285 inc->removeID(mCurrentSyncDevice); 1285 inc->removeID(mCurrentSyncDevice);
1286 inc = iL.next(); 1286 inc = iL.next();
1287 } 1287 }
1288 } 1288 }
1289#ifndef DESKTOP_VERSION 1289#ifndef DESKTOP_VERSION
1290 if ( sharpFormat ) 1290 if ( sharpFormat )
1291 sharpFormat->save(calendar); 1291 sharpFormat->save(calendar);
1292#endif 1292#endif
1293 if ( phoneFormat ) 1293 if ( phoneFormat )
1294 phoneFormat->save(calendar); 1294 phoneFormat->save(calendar);
1295 iL = calendar->rawIncidences(); 1295 iL = calendar->rawIncidences();
1296 inc = iL.first(); 1296 inc = iL.first();
1297 Incidence* loc; 1297 Incidence* loc;
1298 while ( inc ) { 1298 while ( inc ) {
1299 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1299 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1300 loc = mCalendar->incidence(inc->uid() ); 1300 loc = mCalendar->incidence(inc->uid() );
1301 if ( loc ) { 1301 if ( loc ) {
1302 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1302 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1303 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1303 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1304 } 1304 }
1305 } 1305 }
1306 inc = iL.next(); 1306 inc = iL.next();
1307 } 1307 }
1308 Incidence* lse = getLastSyncEvent(); 1308 Incidence* lse = getLastSyncEvent();
1309 if ( lse ) { 1309 if ( lse ) {
1310 lse->setReadOnly( false ); 1310 lse->setReadOnly( false );
1311 lse->setDescription( "" ); 1311 lse->setDescription( "" );
1312 lse->setReadOnly( true ); 1312 lse->setReadOnly( true );
1313 } 1313 }
1314 } 1314 }
1315 } 1315 }
1316 setModified( true ); 1316 setModified( true );
1317 } else { 1317 } else {
1318 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1318 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1319 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1319 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1320 question, i18n("Ok")) ; 1320 question, i18n("Ok")) ;
1321 1321
1322 } 1322 }
1323 delete calendar; 1323 delete calendar;
1324 updateView(); 1324 updateView();
1325 emit tempDisableBR(false); 1325 emit tempDisableBR(false);
1326 return ;//syncOK; 1326 return ;//syncOK;
1327 1327
1328} 1328}
1329 1329
1330bool CalendarView::importBday() 1330bool CalendarView::importBday()
1331{ 1331{
1332#ifndef KORG_NOKABC 1332#ifndef KORG_NOKABC
1333 1333
1334#ifdef DESKTOP_VERSION 1334#ifdef DESKTOP_VERSION
1335 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1335 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1336 KABC::AddressBook::Iterator it; 1336 KABC::AddressBook::Iterator it;
1337 int count = 0; 1337 int count = 0;
1338 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1338 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1339 ++count; 1339 ++count;
1340 } 1340 }
1341 QProgressBar bar(count,0 ); 1341 QProgressBar bar(count,0 );
1342 int w = 300; 1342 int w = 300;
1343 if ( QApplication::desktop()->width() < 320 ) 1343 if ( QApplication::desktop()->width() < 320 )
1344 w = 220; 1344 w = 220;
1345 int h = bar.sizeHint().height() ; 1345 int h = bar.sizeHint().height() ;
1346 int dw = QApplication::desktop()->width(); 1346 int dw = QApplication::desktop()->width();
1347 int dh = QApplication::desktop()->height(); 1347 int dh = QApplication::desktop()->height();
1348 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1348 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1349 bar.show(); 1349 bar.show();
1350 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1350 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1351 qApp->processEvents(); 1351 qApp->processEvents();
1352 count = 0; 1352 count = 0;
1353 int addCount = 0; 1353 int addCount = 0;
1354 KCal::Attendee* a = 0; 1354 KCal::Attendee* a = 0;
1355 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1355 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1356 if ( ! bar.isVisible() ) 1356 if ( ! bar.isVisible() )
1357 return false; 1357 return false;
1358 bar.setProgress( count++ ); 1358 bar.setProgress( count++ );
1359 qApp->processEvents(); 1359 qApp->processEvents();
1360 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1360 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1361 if ( (*it).birthday().date().isValid() ){ 1361 if ( (*it).birthday().date().isValid() ){
1362 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1362 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1363 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1363 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1364 ++addCount; 1364 ++addCount;
1365 } 1365 }
1366 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1366 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1367 if ( anni.isValid() ){ 1367 if ( anni.isValid() ){
1368 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1368 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1369 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1369 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1370 ++addCount; 1370 ++addCount;
1371 } 1371 }
1372 } 1372 }
1373 updateView(); 1373 updateView();
1374 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1374 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1375#else //DESKTOP_VERSION 1375#else //DESKTOP_VERSION
1376 1376
1377 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1377 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1378 // the result should now arrive through method insertBirthdays 1378 // the result should now arrive through method insertBirthdays
1379 1379
1380#endif //DESKTOP_VERSION 1380#endif //DESKTOP_VERSION
1381 1381
1382#endif //KORG_NOKABC 1382#endif //KORG_NOKABC
1383 1383
1384 1384
1385 return true; 1385 return true;
1386} 1386}
1387 1387
1388// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1388// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1389void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1389void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1390 const QStringList& anniversaryList, const QStringList& realNameList, 1390 const QStringList& anniversaryList, const QStringList& realNameList,
1391 const QStringList& emailList, const QStringList& assembledNameList, 1391 const QStringList& emailList, const QStringList& assembledNameList,
1392 const QStringList& uidList) 1392 const QStringList& uidList)
1393{ 1393{
1394 qDebug("CalendarView::insertBirthdays"); 1394 qDebug("CalendarView::insertBirthdays");
1395 if (uid == this->name()) 1395 if (uid == this->name())
1396 { 1396 {
1397 int count = birthdayList.count(); 1397 int count = birthdayList.count();
1398 int addCount = 0; 1398 int addCount = 0;
1399 KCal::Attendee* a = 0; 1399 KCal::Attendee* a = 0;
1400 1400
1401 qDebug("CalView 1 %i", count); 1401 qDebug("CalView 1 %i", count);
1402 1402
1403 QProgressBar bar(count,0 ); 1403 QProgressBar bar(count,0 );
1404 int w = 300; 1404 int w = 300;
1405 if ( QApplication::desktop()->width() < 320 ) 1405 if ( QApplication::desktop()->width() < 320 )
1406 w = 220; 1406 w = 220;
1407 int h = bar.sizeHint().height() ; 1407 int h = bar.sizeHint().height() ;
1408 int dw = QApplication::desktop()->width(); 1408 int dw = QApplication::desktop()->width();
1409 int dh = QApplication::desktop()->height(); 1409 int dh = QApplication::desktop()->height();
1410 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1410 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1411 bar.show(); 1411 bar.show();
1412 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1412 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1413 qApp->processEvents(); 1413 qApp->processEvents();
1414 1414
1415 QDate birthday; 1415 QDate birthday;
1416 QDate anniversary; 1416 QDate anniversary;
1417 QString realName; 1417 QString realName;
1418 QString email; 1418 QString email;
1419 QString assembledName; 1419 QString assembledName;
1420 QString uid; 1420 QString uid;
1421 bool ok = true; 1421 bool ok = true;
1422 for ( int i = 0; i < count; i++) 1422 for ( int i = 0; i < count; i++)
1423 { 1423 {
1424 if ( ! bar.isVisible() ) 1424 if ( ! bar.isVisible() )
1425 return; 1425 return;
1426 bar.setProgress( i ); 1426 bar.setProgress( i );
1427 qApp->processEvents(); 1427 qApp->processEvents();
1428 1428
1429 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1429 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1430 if (!ok) { 1430 if (!ok) {
1431 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1431 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1432 } 1432 }
1433 1433
1434 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1434 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1435 if (!ok) { 1435 if (!ok) {
1436 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1436 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1437 } 1437 }
1438 realName = realNameList[i]; 1438 realName = realNameList[i];
1439 email = emailList[i]; 1439 email = emailList[i];
1440 assembledName = assembledNameList[i]; 1440 assembledName = assembledNameList[i];
1441 uid = uidList[i]; 1441 uid = uidList[i];
1442 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1442 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1443 1443
1444 if ( birthday.isValid() ){ 1444 if ( birthday.isValid() ){
1445 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1445 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1446 KCal::Attendee::ReqParticipant,uid) ; 1446 KCal::Attendee::ReqParticipant,uid) ;
1447 if ( addAnniversary( birthday, assembledName, a, true ) ) 1447 if ( addAnniversary( birthday, assembledName, a, true ) )
1448 ++addCount; 1448 ++addCount;
1449 } 1449 }
1450 1450
1451 if ( anniversary.isValid() ){ 1451 if ( anniversary.isValid() ){
1452 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1452 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1453 KCal::Attendee::ReqParticipant,uid) ; 1453 KCal::Attendee::ReqParticipant,uid) ;
1454 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1454 if ( addAnniversary( anniversary, assembledName, a, false ) )
1455 ++addCount; 1455 ++addCount;
1456 } 1456 }
1457 } 1457 }
1458 1458
1459 updateView(); 1459 updateView();
1460 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1460 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1461 1461
1462 } 1462 }
1463 1463
1464} 1464}
1465 1465
1466 1466
1467 1467
1468bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1468bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1469{ 1469{
1470 //qDebug("addAnni "); 1470 //qDebug("addAnni ");
1471 Event * ev = new Event(); 1471 Event * ev = new Event();
1472 if ( a ) { 1472 if ( a ) {
1473 ev->addAttendee( a ); 1473 ev->addAttendee( a );
1474 } 1474 }
1475 QString kind; 1475 QString kind;
1476 if ( birthday ) 1476 if ( birthday )
1477 kind = i18n( "Birthday" ); 1477 kind = i18n( "Birthday" );
1478 else 1478 else
1479 kind = i18n( "Anniversary" ); 1479 kind = i18n( "Anniversary" );
1480 ev->setSummary( name + " - " + kind ); 1480 ev->setSummary( name + " - " + kind );
1481 ev->setOrganizer(a->email()); 1481 ev->setOrganizer(a->email());
1482 ev->setCategories( kind ); 1482 ev->setCategories( kind );
1483 ev->setDtStart( QDateTime(date) ); 1483 ev->setDtStart( QDateTime(date) );
1484 ev->setDtEnd( QDateTime(date) ); 1484 ev->setDtEnd( QDateTime(date) );
1485 ev->setFloats( true ); 1485 ev->setFloats( true );
1486 Recurrence * rec = ev->recurrence(); 1486 Recurrence * rec = ev->recurrence();
1487 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1487 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1488 rec->addYearlyNum( date.month() ); 1488 rec->addYearlyNum( date.month() );
1489 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1489 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1490 delete ev; 1490 delete ev;
1491 return false; 1491 return false;
1492 } 1492 }
1493 return true; 1493 return true;
1494 1494
1495} 1495}
1496bool CalendarView::importQtopia( const QString &categories, 1496bool CalendarView::importQtopia( const QString &categories,
1497 const QString &datebook, 1497 const QString &datebook,
1498 const QString &todolist ) 1498 const QString &todolist )
1499{ 1499{
1500 1500
1501 QtopiaFormat qtopiaFormat; 1501 QtopiaFormat qtopiaFormat;
1502 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1502 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1503 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1503 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1504 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1504 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1505 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1505 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1506 1506
1507 updateView(); 1507 updateView();
1508 return true; 1508 return true;
1509 1509
1510#if 0 1510#if 0
1511 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1511 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1512 mCurrentSyncDevice = "qtopia-XML"; 1512 mCurrentSyncDevice = "qtopia-XML";
1513 if ( mSyncManager->mAskForPreferences ) 1513 if ( mSyncManager->mAskForPreferences )
1514 edit_sync_options(); 1514 edit_sync_options();
1515 qApp->processEvents(); 1515 qApp->processEvents();
1516 CalendarLocal* calendar = new CalendarLocal(); 1516 CalendarLocal* calendar = new CalendarLocal();
1517 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1517 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1518 bool syncOK = false; 1518 bool syncOK = false;
1519 QtopiaFormat qtopiaFormat; 1519 QtopiaFormat qtopiaFormat;
1520 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1520 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1521 bool loadOk = true; 1521 bool loadOk = true;
1522 if ( !categories.isEmpty() ) 1522 if ( !categories.isEmpty() )
1523 loadOk = qtopiaFormat.load( calendar, categories ); 1523 loadOk = qtopiaFormat.load( calendar, categories );
1524 if ( loadOk && !datebook.isEmpty() ) 1524 if ( loadOk && !datebook.isEmpty() )
1525 loadOk = qtopiaFormat.load( calendar, datebook ); 1525 loadOk = qtopiaFormat.load( calendar, datebook );
1526 if ( loadOk && !todolist.isEmpty() ) 1526 if ( loadOk && !todolist.isEmpty() )
1527 loadOk = qtopiaFormat.load( calendar, todolist ); 1527 loadOk = qtopiaFormat.load( calendar, todolist );
1528 1528
1529 if ( loadOk ) { 1529 if ( loadOk ) {
1530 getEventViewerDialog()->setSyncMode( true ); 1530 getEventViewerDialog()->setSyncMode( true );
1531 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1531 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1532 getEventViewerDialog()->setSyncMode( false ); 1532 getEventViewerDialog()->setSyncMode( false );
1533 qApp->processEvents(); 1533 qApp->processEvents();
1534 if ( syncOK ) { 1534 if ( syncOK ) {
1535 if ( mSyncManager->mWriteBackFile ) 1535 if ( mSyncManager->mWriteBackFile )
1536 { 1536 {
1537 // write back XML file 1537 // write back XML file
1538 1538
1539 } 1539 }
1540 setModified( true ); 1540 setModified( true );
1541 } 1541 }
1542 } else { 1542 } else {
1543 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1543 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1544 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1544 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1545 question, i18n("Ok")) ; 1545 question, i18n("Ok")) ;
1546 } 1546 }
1547 delete calendar; 1547 delete calendar;
1548 updateView(); 1548 updateView();
1549 return syncOK; 1549 return syncOK;
1550 1550
1551 1551
1552#endif 1552#endif
1553 1553
1554} 1554}
1555 1555
1556void CalendarView::setSyncEventsReadOnly() 1556void CalendarView::setSyncEventsReadOnly()
1557{ 1557{
1558 Event * ev; 1558 Event * ev;
1559 QPtrList<Event> eL = mCalendar->rawEvents(); 1559 QPtrList<Event> eL = mCalendar->rawEvents();
1560 ev = eL.first(); 1560 ev = eL.first();
1561 while ( ev ) { 1561 while ( ev ) {
1562 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1562 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1563 ev->setReadOnly( true ); 1563 ev->setReadOnly( true );
1564 ev = eL.next(); 1564 ev = eL.next();
1565 } 1565 }
1566} 1566}
1567bool CalendarView::openCalendar(QString filename, bool merge) 1567bool CalendarView::openCalendar(QString filename, bool merge)
1568{ 1568{
1569 1569
1570 if (filename.isEmpty()) { 1570 if (filename.isEmpty()) {
@@ -3364,417 +3364,414 @@ void CalendarView::processIncidenceSelection( Incidence *incidence )
3364 emit todoSelected( true ); 3364 emit todoSelected( true );
3365 } else { 3365 } else {
3366 emit todoSelected( false ); 3366 emit todoSelected( false );
3367 }*/ 3367 }*/
3368} 3368}
3369 3369
3370 3370
3371void CalendarView::checkClipboard() 3371void CalendarView::checkClipboard()
3372{ 3372{
3373#ifndef KORG_NODND 3373#ifndef KORG_NODND
3374 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3374 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3375 emit pasteEnabled(true); 3375 emit pasteEnabled(true);
3376 } else { 3376 } else {
3377 emit pasteEnabled(false); 3377 emit pasteEnabled(false);
3378 } 3378 }
3379#endif 3379#endif
3380} 3380}
3381 3381
3382void CalendarView::showDates(const DateList &selectedDates) 3382void CalendarView::showDates(const DateList &selectedDates)
3383{ 3383{
3384 // kdDebug() << "CalendarView::selectDates()" << endl; 3384 // kdDebug() << "CalendarView::selectDates()" << endl;
3385 3385
3386 if ( mViewManager->currentView() ) { 3386 if ( mViewManager->currentView() ) {
3387 updateView( selectedDates.first(), selectedDates.last() ); 3387 updateView( selectedDates.first(), selectedDates.last() );
3388 } else { 3388 } else {
3389 mViewManager->showAgendaView(); 3389 mViewManager->showAgendaView();
3390 } 3390 }
3391 3391
3392 QString selDates; 3392 QString selDates;
3393 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true); 3393 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true);
3394 if (selectedDates.first() < selectedDates.last() ) 3394 if (selectedDates.first() < selectedDates.last() )
3395 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3395 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3396 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3396 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3397 3397
3398} 3398}
3399 3399
3400QPtrList<CalFilter> CalendarView::filters() 3400QPtrList<CalFilter> CalendarView::filters()
3401{ 3401{
3402 return mFilters; 3402 return mFilters;
3403 3403
3404} 3404}
3405void CalendarView::editFilters() 3405void CalendarView::editFilters()
3406{ 3406{
3407 // kdDebug() << "CalendarView::editFilters()" << endl; 3407 // kdDebug() << "CalendarView::editFilters()" << endl;
3408 3408
3409 CalFilter *filter = mFilters.first(); 3409 CalFilter *filter = mFilters.first();
3410 while(filter) { 3410 while(filter) {
3411 kdDebug() << " Filter: " << filter->name() << endl; 3411 kdDebug() << " Filter: " << filter->name() << endl;
3412 filter = mFilters.next(); 3412 filter = mFilters.next();
3413 } 3413 }
3414 3414
3415 mDialogManager->showFilterEditDialog(&mFilters); 3415 mDialogManager->showFilterEditDialog(&mFilters);
3416} 3416}
3417void CalendarView::toggleFilter() 3417void CalendarView::toggleFilter()
3418{ 3418{
3419 showFilter(! mFilterView->isVisible()); 3419 showFilter(! mFilterView->isVisible());
3420} 3420}
3421 3421
3422KOFilterView *CalendarView::filterView() 3422KOFilterView *CalendarView::filterView()
3423{ 3423{
3424 return mFilterView; 3424 return mFilterView;
3425} 3425}
3426void CalendarView::selectFilter( int fil ) 3426void CalendarView::selectFilter( int fil )
3427{ 3427{
3428 mFilterView->setSelectedFilter( fil ); 3428 mFilterView->setSelectedFilter( fil );
3429} 3429}
3430void CalendarView::showFilter(bool visible) 3430void CalendarView::showFilter(bool visible)
3431{ 3431{
3432 if (visible) mFilterView->show(); 3432 if (visible) mFilterView->show();
3433 else mFilterView->hide(); 3433 else mFilterView->hide();
3434} 3434}
3435void CalendarView::toggleFilerEnabled( ) 3435void CalendarView::toggleFilerEnabled( )
3436{ 3436{
3437 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3437 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3438 if ( !mFilterView->filtersEnabled() ) 3438 if ( !mFilterView->filtersEnabled() )
3439 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3439 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3440 3440
3441} 3441}
3442void CalendarView::updateFilter() 3442void CalendarView::updateFilter()
3443{ 3443{
3444 CalFilter *filter = mFilterView->selectedFilter(); 3444 CalFilter *filter = mFilterView->selectedFilter();
3445 if (filter) { 3445 if (filter) {
3446 if (mFilterView->filtersEnabled()) { 3446 if (mFilterView->filtersEnabled()) {
3447 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() ); 3447 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() );
3448 filter->setEnabled(true); 3448 filter->setEnabled(true);
3449 } 3449 }
3450 else filter->setEnabled(false); 3450 else filter->setEnabled(false);
3451 mCalendar->setFilter(filter); 3451 mCalendar->setFilter(filter);
3452 updateView(); 3452 updateView();
3453 } 3453 }
3454} 3454}
3455 3455
3456void CalendarView::filterEdited() 3456void CalendarView::filterEdited()
3457{ 3457{
3458 mFilterView->updateFilters(); 3458 mFilterView->updateFilters();
3459 updateFilter(); 3459 updateFilter();
3460 writeSettings(); 3460 writeSettings();
3461} 3461}
3462 3462
3463 3463
3464void CalendarView::takeOverEvent() 3464void CalendarView::takeOverEvent()
3465{ 3465{
3466 Incidence *incidence = currentSelection(); 3466 Incidence *incidence = currentSelection();
3467 3467
3468 if (!incidence) return; 3468 if (!incidence) return;
3469 3469
3470 incidence->setOrganizer(KOPrefs::instance()->email()); 3470 incidence->setOrganizer(KOPrefs::instance()->email());
3471 incidence->recreate(); 3471 incidence->recreate();
3472 incidence->setReadOnly(false); 3472 incidence->setReadOnly(false);
3473 3473
3474 updateView(); 3474 updateView();
3475} 3475}
3476 3476
3477void CalendarView::takeOverCalendar() 3477void CalendarView::takeOverCalendar()
3478{ 3478{
3479 // TODO: Create Calendar::allIncidences() function and use it here 3479 // TODO: Create Calendar::allIncidences() function and use it here
3480 3480
3481 QPtrList<Event> events = mCalendar->events(); 3481 QPtrList<Event> events = mCalendar->events();
3482 for(uint i=0; i<events.count(); ++i) { 3482 for(uint i=0; i<events.count(); ++i) {
3483 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3483 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3484 events.at(i)->recreate(); 3484 events.at(i)->recreate();
3485 events.at(i)->setReadOnly(false); 3485 events.at(i)->setReadOnly(false);
3486 } 3486 }
3487 3487
3488 QPtrList<Todo> todos = mCalendar->todos(); 3488 QPtrList<Todo> todos = mCalendar->todos();
3489 for(uint i=0; i<todos.count(); ++i) { 3489 for(uint i=0; i<todos.count(); ++i) {
3490 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3490 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3491 todos.at(i)->recreate(); 3491 todos.at(i)->recreate();
3492 todos.at(i)->setReadOnly(false); 3492 todos.at(i)->setReadOnly(false);
3493 } 3493 }
3494 3494
3495 QPtrList<Journal> journals = mCalendar->journals(); 3495 QPtrList<Journal> journals = mCalendar->journals();
3496 for(uint i=0; i<journals.count(); ++i) { 3496 for(uint i=0; i<journals.count(); ++i) {
3497 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3497 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3498 journals.at(i)->recreate(); 3498 journals.at(i)->recreate();
3499 journals.at(i)->setReadOnly(false); 3499 journals.at(i)->setReadOnly(false);
3500 } 3500 }
3501 3501
3502 updateView(); 3502 updateView();
3503} 3503}
3504 3504
3505void CalendarView::showIntro() 3505void CalendarView::showIntro()
3506{ 3506{
3507 kdDebug() << "To be implemented." << endl; 3507 kdDebug() << "To be implemented." << endl;
3508} 3508}
3509 3509
3510QWidgetStack *CalendarView::viewStack() 3510QWidgetStack *CalendarView::viewStack()
3511{ 3511{
3512 return mRightFrame; 3512 return mRightFrame;
3513} 3513}
3514 3514
3515QWidget *CalendarView::leftFrame() 3515QWidget *CalendarView::leftFrame()
3516{ 3516{
3517 return mLeftFrame; 3517 return mLeftFrame;
3518} 3518}
3519 3519
3520DateNavigator *CalendarView::dateNavigator() 3520DateNavigator *CalendarView::dateNavigator()
3521{ 3521{
3522 return mNavigator; 3522 return mNavigator;
3523} 3523}
3524 3524
3525KDateNavigator* CalendarView::dateNavigatorWidget() 3525KDateNavigator* CalendarView::dateNavigatorWidget()
3526{ 3526{
3527 return mDateNavigator; 3527 return mDateNavigator;
3528} 3528}
3529void CalendarView::toggleDateNavigatorWidget() 3529void CalendarView::toggleDateNavigatorWidget()
3530{ 3530{
3531 if (mDateNavigator->isVisible()) 3531 if (mDateNavigator->isVisible())
3532 mDateNavigator->hide(); 3532 mDateNavigator->hide();
3533 else 3533 else
3534 mDateNavigator->show(); 3534 mDateNavigator->show();
3535} 3535}
3536void CalendarView::addView(KOrg::BaseView *view) 3536void CalendarView::addView(KOrg::BaseView *view)
3537{ 3537{
3538 mViewManager->addView(view); 3538 mViewManager->addView(view);
3539} 3539}
3540 3540
3541void CalendarView::showView(KOrg::BaseView *view) 3541void CalendarView::showView(KOrg::BaseView *view)
3542{ 3542{
3543 mViewManager->showView(view, mLeftFrame->isVisible()); 3543 mViewManager->showView(view, mLeftFrame->isVisible());
3544} 3544}
3545 3545
3546Incidence *CalendarView::currentSelection() 3546Incidence *CalendarView::currentSelection()
3547{ 3547{
3548 return mViewManager->currentSelection(); 3548 return mViewManager->currentSelection();
3549} 3549}
3550void CalendarView::toggleAllDaySize() 3550void CalendarView::toggleAllDaySize()
3551{ 3551{
3552 /* 3552 /*
3553 if ( KOPrefs::instance()->mAllDaySize > 47 ) 3553 if ( KOPrefs::instance()->mAllDaySize > 47 )
3554 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 3554 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
3555 else 3555 else
3556 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 3556 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
3557 */ 3557 */
3558 viewManager()->agendaView()->toggleAllDay(); 3558 viewManager()->agendaView()->toggleAllDay();
3559} 3559}
3560void CalendarView::toggleExpand() 3560void CalendarView::toggleExpand()
3561{ 3561{
3562 // if ( mLeftFrame->isHidden() ) { 3562 // if ( mLeftFrame->isHidden() ) {
3563 // mLeftFrame->show(); 3563 // mLeftFrame->show();
3564 // emit calendarViewExpanded( false ); 3564 // emit calendarViewExpanded( false );
3565 // } else { 3565 // } else {
3566 // mLeftFrame->hide(); 3566 // mLeftFrame->hide();
3567 // emit calendarViewExpanded( true ); 3567 // emit calendarViewExpanded( true );
3568 // } 3568 // }
3569 3569
3570 globalFlagBlockAgenda = 1; 3570 globalFlagBlockAgenda = 1;
3571 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 3571 emit calendarViewExpanded( !mLeftFrame->isHidden() );
3572 globalFlagBlockAgenda = 5; 3572 globalFlagBlockAgenda = 5;
3573 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 3573 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
3574 //mViewManager->showView( 0, true ); 3574 //mViewManager->showView( 0, true );
3575} 3575}
3576 3576
3577void CalendarView::calendarModified( bool modified, Calendar * ) 3577void CalendarView::calendarModified( bool modified, Calendar * )
3578{ 3578{
3579 setModified( modified ); 3579 setModified( modified );
3580} 3580}
3581 3581
3582Todo *CalendarView::selectedTodo() 3582Todo *CalendarView::selectedTodo()
3583{ 3583{
3584 Incidence *incidence = currentSelection(); 3584 Incidence *incidence = currentSelection();
3585 if ( incidence && incidence->type() == "Todo" ) { 3585 if ( incidence && incidence->type() == "Todo" ) {
3586 return static_cast<Todo *>( incidence ); 3586 return static_cast<Todo *>( incidence );
3587 } 3587 }
3588 3588
3589 incidence = mTodoList->selectedIncidences().first(); 3589 incidence = mTodoList->selectedIncidences().first();
3590 if ( incidence && incidence->type() == "Todo" ) { 3590 if ( incidence && incidence->type() == "Todo" ) {
3591 return static_cast<Todo *>( incidence ); 3591 return static_cast<Todo *>( incidence );
3592 } 3592 }
3593 3593
3594 return 0; 3594 return 0;
3595} 3595}
3596 3596
3597void CalendarView::dialogClosing(Incidence *in) 3597void CalendarView::dialogClosing(Incidence *in)
3598{ 3598{
3599 // mDialogList.remove(in); 3599 // mDialogList.remove(in);
3600} 3600}
3601 3601
3602void CalendarView::showIncidence() 3602void CalendarView::showIncidence()
3603{ 3603{
3604 Incidence *incidence = currentSelection(); 3604 Incidence *incidence = currentSelection();
3605 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3605 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3606 if ( incidence ) { 3606 if ( incidence ) {
3607 ShowIncidenceVisitor v; 3607 ShowIncidenceVisitor v;
3608 v.act( incidence, this ); 3608 v.act( incidence, this );
3609 } 3609 }
3610} 3610}
3611void CalendarView::editIncidenceDescription() 3611void CalendarView::editIncidenceDescription()
3612{ 3612{
3613 mFlagEditDescription = true; 3613 mFlagEditDescription = true;
3614 editIncidence(); 3614 editIncidence();
3615 mFlagEditDescription = false; 3615 mFlagEditDescription = false;
3616} 3616}
3617void CalendarView::editIncidence() 3617void CalendarView::editIncidence()
3618{ 3618{
3619 // qDebug("editIncidence() "); 3619 // qDebug("editIncidence() ");
3620 Incidence *incidence = currentSelection(); 3620 Incidence *incidence = currentSelection();
3621 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3621 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3622 if ( incidence ) { 3622 if ( incidence ) {
3623 EditIncidenceVisitor v; 3623 EditIncidenceVisitor v;
3624 v.act( incidence, this ); 3624 v.act( incidence, this );
3625 } 3625 }
3626} 3626}
3627 3627
3628void CalendarView::deleteIncidence() 3628void CalendarView::deleteIncidence()
3629{ 3629{
3630 Incidence *incidence = currentSelection(); 3630 Incidence *incidence = currentSelection();
3631 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3631 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3632 if ( incidence ) { 3632 if ( incidence ) {
3633 deleteIncidence(incidence); 3633 deleteIncidence(incidence);
3634 } 3634 }
3635} 3635}
3636 3636
3637void CalendarView::showIncidence(Incidence *incidence) 3637void CalendarView::showIncidence(Incidence *incidence)
3638{ 3638{
3639 if ( incidence ) { 3639 if ( incidence ) {
3640 ShowIncidenceVisitor v; 3640 ShowIncidenceVisitor v;
3641 v.act( incidence, this ); 3641 v.act( incidence, this );
3642 } 3642 }
3643} 3643}
3644 3644
3645void CalendarView::editIncidence(Incidence *incidence) 3645void CalendarView::editIncidence(Incidence *incidence)
3646{ 3646{
3647 if ( incidence ) { 3647 if ( incidence ) {
3648 3648
3649 EditIncidenceVisitor v; 3649 EditIncidenceVisitor v;
3650 v.act( incidence, this ); 3650 v.act( incidence, this );
3651 3651
3652 } 3652 }
3653} 3653}
3654 3654
3655void CalendarView::deleteIncidence(Incidence *incidence) 3655void CalendarView::deleteIncidence(Incidence *incidence)
3656{ 3656{
3657 //qDebug(" CalendarView::deleteIncidence "); 3657 //qDebug(" CalendarView::deleteIncidence ");
3658 if ( incidence ) { 3658 if ( incidence ) {
3659 DeleteIncidenceVisitor v; 3659 DeleteIncidenceVisitor v;
3660 v.act( incidence, this ); 3660 v.act( incidence, this );
3661 } 3661 }
3662} 3662}
3663 3663
3664 3664
3665void CalendarView::lookForOutgoingMessages() 3665void CalendarView::lookForOutgoingMessages()
3666{ 3666{
3667 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 3667 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
3668 ogd->loadMessages(); 3668 ogd->loadMessages();
3669} 3669}
3670 3670
3671void CalendarView::lookForIncomingMessages() 3671void CalendarView::lookForIncomingMessages()
3672{ 3672{
3673 IncomingDialog *icd = mDialogManager->incomingDialog(); 3673 IncomingDialog *icd = mDialogManager->incomingDialog();
3674 icd->retrieve(); 3674 icd->retrieve();
3675} 3675}
3676 3676
3677bool CalendarView::removeCompletedSubTodos( Todo* t ) 3677bool CalendarView::removeCompletedSubTodos( Todo* t )
3678{ 3678{
3679 bool deleteTodo = true; 3679 bool deleteTodo = true;
3680 QPtrList<Incidence> subTodos; 3680 QPtrList<Incidence> subTodos;
3681 Incidence *aTodo; 3681 Incidence *aTodo;
3682 subTodos = t->relations(); 3682 subTodos = t->relations();
3683 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 3683 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
3684 if (! removeCompletedSubTodos( (Todo*) aTodo )) 3684 if (! removeCompletedSubTodos( (Todo*) aTodo ))
3685 deleteTodo = false; 3685 deleteTodo = false;
3686 } 3686 }
3687 if ( deleteTodo ) { 3687 if ( deleteTodo ) {
3688 if ( t->isCompleted() ) { 3688 if ( t->isCompleted() ) {
3689 checkExternalId( t ); 3689 checkExternalId( t );
3690 mCalendar->deleteTodo( t ); 3690 mCalendar->deleteTodo( t );
3691 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 3691 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
3692 } 3692 }
3693 else 3693 else
3694 deleteTodo = false; 3694 deleteTodo = false;
3695 } 3695 }
3696 return deleteTodo; 3696 return deleteTodo;
3697 3697
3698} 3698}
3699void CalendarView::purgeCompleted() 3699void CalendarView::purgeCompleted()
3700{ 3700{
3701 int result = KMessageBox::warningContinueCancel(this, 3701 int result = KMessageBox::warningContinueCancel(this,
3702 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); 3702 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
3703 3703
3704 if (result == KMessageBox::Continue) { 3704 if (result == KMessageBox::Continue) {
3705 3705
3706 QPtrList<Todo> todoCal; 3706 QPtrList<Todo> todoCal;
3707 QPtrList<Todo> rootTodos; 3707 QPtrList<Todo> rootTodos;
3708 //QPtrList<Incidence> rel; 3708 //QPtrList<Incidence> rel;
3709 Todo *aTodo;//, *rTodo; 3709 Todo *aTodo;//, *rTodo;
3710 Incidence *rIncidence; 3710 Incidence *rIncidence;
3711 bool childDelete = false; 3711 bool childDelete = false;
3712 bool deletedOne = true; 3712 bool deletedOne = true;
3713 todoCal = calendar()->todos(); 3713 todoCal = calendar()->todos();
3714 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 3714 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
3715 if ( !aTodo->relatedTo() ) 3715 if ( !aTodo->relatedTo() )
3716 rootTodos.append( aTodo ); 3716 rootTodos.append( aTodo );
3717 } 3717 }
3718 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 3718 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
3719 removeCompletedSubTodos( aTodo ); 3719 removeCompletedSubTodos( aTodo );
3720 } 3720 }
3721 3721
3722 updateView(); 3722 updateView();
3723 } 3723 }
3724} 3724}
3725 3725
3726void CalendarView::slotCalendarChanged() 3726void CalendarView::slotCalendarChanged()
3727{ 3727{
3728 ; 3728 ;
3729} 3729}
3730 3730
3731NavigatorBar *CalendarView::navigatorBar() 3731NavigatorBar *CalendarView::navigatorBar()
3732{ 3732{
3733 return mNavigatorBar; 3733 return mNavigatorBar;
3734} 3734}
3735 3735
3736 3736
3737 3737
3738void CalendarView::keyPressEvent ( QKeyEvent *e) 3738void CalendarView::keyPressEvent ( QKeyEvent *e)
3739{ 3739{
3740 //qDebug(" alendarView::keyPressEvent "); 3740 //qDebug(" alendarView::keyPressEvent ");
3741 e->ignore(); 3741 e->ignore();
3742} 3742}
3743 3743
3744 3744
3745bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 3745bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
3746{ 3746{
3747 // mSyncManager = manager; 3747 // mSyncManager = manager;
3748 mSyncKDE = false;
3749 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 3748 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
3750 qDebug("SyncKDE request detected!"); 3749 qDebug("SyncKDE request detected!");
3751 mSyncKDE = true;
3752 } 3750 }
3753 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3751 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3754 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3752 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3755 return syncCalendar( filename, mode ); 3753 return syncCalendar( filename, mode );
3756} 3754}
3757bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 3755bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
3758{ 3756{
3759 mSyncKDE = false;
3760 //mSyncManager = manager; 3757 //mSyncManager = manager;
3761 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3758 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3762 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3759 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3763 if ( resource == "sharp" ) 3760 if ( resource == "sharp" )
3764 syncExternal( 0 ); 3761 syncExternal( 0 );
3765 if ( resource == "phone" ) 3762 if ( resource == "phone" )
3766 syncExternal( 1 ); 3763 syncExternal( 1 );
3767 // pending setmodified 3764 // pending setmodified
3768 return true; 3765 return true;
3769} 3766}
3770void CalendarView::setSyncManager(KSyncManager* manager) 3767void CalendarView::setSyncManager(KSyncManager* manager)
3771{ 3768{
3772 mSyncManager = manager; 3769 mSyncManager = manager;
3773} 3770}
3774 3771
3775void CalendarView::removeSyncInfo( QString syncProfile) 3772void CalendarView::removeSyncInfo( QString syncProfile)
3776{ 3773{
3777 qDebug("removeSyncInfo for profile %s ", syncProfile.latin1()); 3774 qDebug("removeSyncInfo for profile %s ", syncProfile.latin1());
3778 mCalendar->removeSyncInfo( syncProfile ); 3775 mCalendar->removeSyncInfo( syncProfile );
3779 3776
3780} 3777}
diff --git a/korganizer/calendarview.h b/korganizer/calendarview.h
index acc20d6..437a51c 100644
--- a/korganizer/calendarview.h
+++ b/korganizer/calendarview.h
@@ -108,499 +108,498 @@ class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Obser
108 QWidget *leftFrame(); 108 QWidget *leftFrame();
109 NavigatorBar *navigatorBar(); 109 NavigatorBar *navigatorBar();
110 110
111 DateNavigator *dateNavigator(); 111 DateNavigator *dateNavigator();
112 KDateNavigator *dateNavigatorWidget(); 112 KDateNavigator *dateNavigatorWidget();
113 113
114 void addView(KOrg::BaseView *); 114 void addView(KOrg::BaseView *);
115 void showView(KOrg::BaseView *); 115 void showView(KOrg::BaseView *);
116 KOEventViewerDialog* getEventViewerDialog(); 116 KOEventViewerDialog* getEventViewerDialog();
117 Incidence *currentSelection(); 117 Incidence *currentSelection();
118 118
119 signals: 119 signals:
120 void tempDisableBR(bool); 120 void tempDisableBR(bool);
121 /** This todo has been modified */ 121 /** This todo has been modified */
122 void todoModified(Todo *, int); 122 void todoModified(Todo *, int);
123 123
124 /** when change is made to options dialog, the topwidget will catch this 124 /** when change is made to options dialog, the topwidget will catch this
125 * and emit this signal which notifies all widgets which have registered 125 * and emit this signal which notifies all widgets which have registered
126 * for notification to update their settings. */ 126 * for notification to update their settings. */
127 void configChanged(); 127 void configChanged();
128 /** emitted when the topwidget is closing down, so that any attached 128 /** emitted when the topwidget is closing down, so that any attached
129 child windows can also close. */ 129 child windows can also close. */
130 void closingDown(); 130 void closingDown();
131 /** emitted right before we die */ 131 /** emitted right before we die */
132 void closed(QWidget *); 132 void closed(QWidget *);
133 133
134 /** Emitted when state of modified flag changes */ 134 /** Emitted when state of modified flag changes */
135 void modifiedChanged(bool); 135 void modifiedChanged(bool);
136 void signalmodified(); 136 void signalmodified();
137 137
138 /** Emitted when state of read-only flag changes */ 138 /** Emitted when state of read-only flag changes */
139 void readOnlyChanged(bool); 139 void readOnlyChanged(bool);
140 140
141 /** Emitted when the unit of navigation changes */ 141 /** Emitted when the unit of navigation changes */
142 void changeNavStringPrev(const QString &); 142 void changeNavStringPrev(const QString &);
143 void changeNavStringNext(const QString &); 143 void changeNavStringNext(const QString &);
144 144
145 /** Emitted when state of events selection has changed and user is organizer*/ 145 /** Emitted when state of events selection has changed and user is organizer*/
146 void organizerEventsSelected(bool); 146 void organizerEventsSelected(bool);
147 /** Emitted when state of events selection has changed and user is attendee*/ 147 /** Emitted when state of events selection has changed and user is attendee*/
148 void groupEventsSelected(bool); 148 void groupEventsSelected(bool);
149 /** 149 /**
150 Emitted when an incidence gets selected. If the selection is cleared the 150 Emitted when an incidence gets selected. If the selection is cleared the
151 signal is emitted with 0 as argument. 151 signal is emitted with 0 as argument.
152 */ 152 */
153 void incidenceSelected( Incidence * ); 153 void incidenceSelected( Incidence * );
154 /** Emitted, when a todoitem is selected or deselected. */ 154 /** Emitted, when a todoitem is selected or deselected. */
155 void todoSelected( bool ); 155 void todoSelected( bool );
156 156
157 /** 157 /**
158 Emitted, when clipboard content changes. Parameter indicates if paste 158 Emitted, when clipboard content changes. Parameter indicates if paste
159 is possible or not. 159 is possible or not.
160 */ 160 */
161 void pasteEnabled(bool); 161 void pasteEnabled(bool);
162 162
163 /** Emitted, when the number of incoming messages has changed. */ 163 /** Emitted, when the number of incoming messages has changed. */
164 void numIncomingChanged(int); 164 void numIncomingChanged(int);
165 165
166 /** Emitted, when the number of outgoing messages has changed. */ 166 /** Emitted, when the number of outgoing messages has changed. */
167 void numOutgoingChanged(int); 167 void numOutgoingChanged(int);
168 168
169 /** Send status message, which can e.g. be displayed in the status bar. */ 169 /** Send status message, which can e.g. be displayed in the status bar. */
170 void statusMessage(const QString &); 170 void statusMessage(const QString &);
171 171
172 void calendarViewExpanded( bool ); 172 void calendarViewExpanded( bool );
173 void updateSearchDialog(); 173 void updateSearchDialog();
174 174
175 175
176 public slots: 176 public slots:
177 void showOpenError(); 177 void showOpenError();
178 void watchSavedFile(); 178 void watchSavedFile();
179 void recheckTimerAlarm(); 179 void recheckTimerAlarm();
180 void checkNextTimerAlarm(); 180 void checkNextTimerAlarm();
181 void addAlarm(const QDateTime &qdt, const QString &noti ); 181 void addAlarm(const QDateTime &qdt, const QString &noti );
182 void addSuspendAlarm(const QDateTime &qdt, const QString &noti ); 182 void addSuspendAlarm(const QDateTime &qdt, const QString &noti );
183 void removeAlarm(const QDateTime &qdt, const QString &noti ); 183 void removeAlarm(const QDateTime &qdt, const QString &noti );
184 184
185 /** options dialog made a changed to the configuration. we catch this 185 /** options dialog made a changed to the configuration. we catch this
186 * and notify all widgets which need to update their configuration. */ 186 * and notify all widgets which need to update their configuration. */
187 void updateConfig(); 187 void updateConfig();
188 188
189 void insertBirthdays(const QString& uid, const QStringList& birthdayList, 189 void insertBirthdays(const QString& uid, const QStringList& birthdayList,
190 const QStringList& anniversaryList, const QStringList& realNameList, 190 const QStringList& anniversaryList, const QStringList& realNameList,
191 const QStringList& emailList, const QStringList& assembledNameList, 191 const QStringList& emailList, const QStringList& assembledNameList,
192 const QStringList& uidList); 192 const QStringList& uidList);
193 193
194 /** 194 /**
195 Load calendar from file \a filename. If \a merge is true, load 195 Load calendar from file \a filename. If \a merge is true, load
196 calendar into existing one, if it is false, clear calendar, before 196 calendar into existing one, if it is false, clear calendar, before
197 loading. Return true, if calendar could be successfully loaded. 197 loading. Return true, if calendar could be successfully loaded.
198 */ 198 */
199 bool openCalendar(QString filename, bool merge=false); 199 bool openCalendar(QString filename, bool merge=false);
200 bool syncCalendar(QString filename,int mode = 0 ); 200 bool syncCalendar(QString filename,int mode = 0 );
201 201
202 /** 202 /**
203 Save calendar data to file. Return true if calendar could be 203 Save calendar data to file. Return true if calendar could be
204 successfully saved. 204 successfully saved.
205 */ 205 */
206 bool saveCalendar(QString filename); 206 bool saveCalendar(QString filename);
207 207
208 /** 208 /**
209 Close calendar. Clear calendar data and reset views to display an empty 209 Close calendar. Clear calendar data and reset views to display an empty
210 calendar. 210 calendar.
211 */ 211 */
212 void closeCalendar(); 212 void closeCalendar();
213 213
214 /** Archive old events of calendar */ 214 /** Archive old events of calendar */
215 void archiveCalendar(); 215 void archiveCalendar();
216 216
217 void showIncidence(); 217 void showIncidence();
218 void editIncidence(); 218 void editIncidence();
219 void editIncidenceDescription(); 219 void editIncidenceDescription();
220 void deleteIncidence(); 220 void deleteIncidence();
221 void cloneIncidence(); 221 void cloneIncidence();
222 void moveIncidence(); 222 void moveIncidence();
223 void beamIncidence(); 223 void beamIncidence();
224 void toggleCancelIncidence(); 224 void toggleCancelIncidence();
225 225
226 /** create an editeventwin with supplied date/time, and if bool is true, 226 /** create an editeventwin with supplied date/time, and if bool is true,
227 * make the event take all day. */ 227 * make the event take all day. */
228 void newEvent(QDateTime, QDateTime, bool allDay = false); 228 void newEvent(QDateTime, QDateTime, bool allDay = false);
229 void newEvent(QDateTime fh); 229 void newEvent(QDateTime fh);
230 void newEvent(QDate dt); 230 void newEvent(QDate dt);
231 /** create new event without having a date hint. Takes current date as 231 /** create new event without having a date hint. Takes current date as
232 default hint. */ 232 default hint. */
233 void newEvent(); 233 void newEvent();
234 void newFloatingEvent(); 234 void newFloatingEvent();
235 235
236 /** Create a read-only viewer dialog for the supplied incidence. It calls the correct showXXX method*/ 236 /** Create a read-only viewer dialog for the supplied incidence. It calls the correct showXXX method*/
237 void showIncidence(Incidence *); 237 void showIncidence(Incidence *);
238 /** Create an editor for the supplied incidence. It calls the correct editXXX method*/ 238 /** Create an editor for the supplied incidence. It calls the correct editXXX method*/
239 void editIncidence(Incidence *); 239 void editIncidence(Incidence *);
240 /** Delete the supplied incidence. It calls the correct deleteXXX method*/ 240 /** Delete the supplied incidence. It calls the correct deleteXXX method*/
241 void deleteIncidence(Incidence *); 241 void deleteIncidence(Incidence *);
242 void cloneIncidence(Incidence *); 242 void cloneIncidence(Incidence *);
243 void cancelIncidence(Incidence *); 243 void cancelIncidence(Incidence *);
244 /** Create an editor for the supplied event. */ 244 /** Create an editor for the supplied event. */
245 void editEvent(Event *); 245 void editEvent(Event *);
246 /** Delete the supplied event. */ 246 /** Delete the supplied event. */
247 void deleteEvent(Event *); 247 void deleteEvent(Event *);
248 /** Delete the event with the given unique ID. Returns false, if event wasn't 248 /** Delete the event with the given unique ID. Returns false, if event wasn't
249 found. */ 249 found. */
250 bool deleteEvent(const QString &uid); 250 bool deleteEvent(const QString &uid);
251 /** Create a read-only viewer dialog for the supplied event. */ 251 /** Create a read-only viewer dialog for the supplied event. */
252 void showEvent(Event *); 252 void showEvent(Event *);
253 253
254 void editJournal(Journal *); 254 void editJournal(Journal *);
255 void showJournal(Journal *); 255 void showJournal(Journal *);
256 void deleteJournal(Journal *); 256 void deleteJournal(Journal *);
257 /** Create an editor dialog for a todo */ 257 /** Create an editor dialog for a todo */
258 void editTodo(Todo *); 258 void editTodo(Todo *);
259 /** Create a read-only viewer dialog for the supplied todo */ 259 /** Create a read-only viewer dialog for the supplied todo */
260 void showTodo(Todo *); 260 void showTodo(Todo *);
261 /** create new todo */ 261 /** create new todo */
262 void newTodo(); 262 void newTodo();
263 /** create new todo with a parent todo */ 263 /** create new todo with a parent todo */
264 void newSubTodo(); 264 void newSubTodo();
265 /** create new todo with a parent todo */ 265 /** create new todo with a parent todo */
266 void newSubTodo(Todo *); 266 void newSubTodo(Todo *);
267 /** Delete todo */ 267 /** Delete todo */
268 void deleteTodo(Todo *); 268 void deleteTodo(Todo *);
269 269
270 270
271 /** Check if clipboard contains vCalendar event. The signal pasteEnabled() is 271 /** Check if clipboard contains vCalendar event. The signal pasteEnabled() is
272 * emitted as result. */ 272 * emitted as result. */
273 void checkClipboard(); 273 void checkClipboard();
274 274
275 /** using the KConfig associated with the kapp variable, read in the 275 /** using the KConfig associated with the kapp variable, read in the
276 * settings from the config file. 276 * settings from the config file.
277 */ 277 */
278 void readSettings(); 278 void readSettings();
279 279
280 /** write current state to config file. */ 280 /** write current state to config file. */
281 void writeSettings(); 281 void writeSettings();
282 282
283 /** read settings for calendar filters */ 283 /** read settings for calendar filters */
284 void readFilterSettings(KConfig *config); 284 void readFilterSettings(KConfig *config);
285 285
286 /** write settings for calendar filters */ 286 /** write settings for calendar filters */
287 void writeFilterSettings(KConfig *config); 287 void writeFilterSettings(KConfig *config);
288 288
289 /** passes on the message that an event has changed to the currently 289 /** passes on the message that an event has changed to the currently
290 * activated view so that it can make appropriate display changes. */ 290 * activated view so that it can make appropriate display changes. */
291 void changeEventDisplay(Event *, int); 291 void changeEventDisplay(Event *, int);
292 void changeIncidenceDisplay(Incidence *, int); 292 void changeIncidenceDisplay(Incidence *, int);
293 void changeTodoDisplay(Todo *, int); 293 void changeTodoDisplay(Todo *, int);
294 294
295 void eventAdded(Event *); 295 void eventAdded(Event *);
296 void eventChanged(Event *); 296 void eventChanged(Event *);
297 void eventToBeDeleted(Event *); 297 void eventToBeDeleted(Event *);
298 void eventDeleted(); 298 void eventDeleted();
299 299
300 void todoAdded(Todo *); 300 void todoAdded(Todo *);
301 void todoChanged(Todo *); 301 void todoChanged(Todo *);
302 void todoToBeDeleted(Todo *); 302 void todoToBeDeleted(Todo *);
303 void todoDeleted(); 303 void todoDeleted();
304 304
305 void updateView(const QDate &start, const QDate &end); 305 void updateView(const QDate &start, const QDate &end);
306 void updateView(); 306 void updateView();
307 307
308 /** Full update of visible todo views */ 308 /** Full update of visible todo views */
309 void updateTodoViews(); 309 void updateTodoViews();
310 310
311 void updateUnmanagedViews(); 311 void updateUnmanagedViews();
312 312
313 /** cut the current appointment to the clipboard */ 313 /** cut the current appointment to the clipboard */
314 void edit_cut(); 314 void edit_cut();
315 315
316 /** copy the current appointment(s) to the clipboard */ 316 /** copy the current appointment(s) to the clipboard */
317 void edit_copy(); 317 void edit_copy();
318 318
319 /** paste the current vobject(s) in the clipboard buffer into calendar */ 319 /** paste the current vobject(s) in the clipboard buffer into calendar */
320 void edit_paste(); 320 void edit_paste();
321 321
322 /** edit viewing and configuration options. */ 322 /** edit viewing and configuration options. */
323 void edit_options(); 323 void edit_options();
324 /** 324 /**
325 Functions for printing, previewing a print, and setting up printing 325 Functions for printing, previewing a print, and setting up printing
326 parameters. 326 parameters.
327 */ 327 */
328 void print(); 328 void print();
329 void printSetup(); 329 void printSetup();
330 void printPreview(); 330 void printPreview();
331 331
332 /** Export as iCalendar file */ 332 /** Export as iCalendar file */
333 void exportICalendar(); 333 void exportICalendar();
334 334
335 /** Export as vCalendar file */ 335 /** Export as vCalendar file */
336 bool exportVCalendar( QString fn); 336 bool exportVCalendar( QString fn);
337 337
338 /** pop up a dialog to show an existing appointment. */ 338 /** pop up a dialog to show an existing appointment. */
339 void appointment_show(); 339 void appointment_show();
340 /** 340 /**
341 * pop up an Appointment Dialog to edit an existing appointment.Get 341 * pop up an Appointment Dialog to edit an existing appointment.Get
342 * information on the appointment from the list of unique IDs that is 342 * information on the appointment from the list of unique IDs that is
343 * currently in the View, called currIds. 343 * currently in the View, called currIds.
344 */ 344 */
345 void appointment_edit(); 345 void appointment_edit();
346 /** 346 /**
347 * pop up dialog confirming deletion of currently selected event in the 347 * pop up dialog confirming deletion of currently selected event in the
348 * View. 348 * View.
349 */ 349 */
350 void appointment_delete(); 350 void appointment_delete();
351 351
352 /** mails the currently selected event to a particular user as a vCalendar 352 /** mails the currently selected event to a particular user as a vCalendar
353 attachment. */ 353 attachment. */
354 void action_mail(); 354 void action_mail();
355 355
356 /* frees a subtodo from it's relation */ 356 /* frees a subtodo from it's relation */
357 void todo_unsub( Todo * ); 357 void todo_unsub( Todo * );
358 void todo_resub( Todo * parent, Todo * sub ); 358 void todo_resub( Todo * parent, Todo * sub );
359 359
360 /** Take ownership of selected event. */ 360 /** Take ownership of selected event. */
361 void takeOverEvent(); 361 void takeOverEvent();
362 362
363 /** Take ownership of all events in calendar. */ 363 /** Take ownership of all events in calendar. */
364 void takeOverCalendar(); 364 void takeOverCalendar();
365 365
366 /** query whether or not the calendar is "dirty". */ 366 /** query whether or not the calendar is "dirty". */
367 bool isModified(); 367 bool isModified();
368 /** set the state of calendar. Modified means "dirty", i.e. needing a save. */ 368 /** set the state of calendar. Modified means "dirty", i.e. needing a save. */
369 void setModified(bool modified=true); 369 void setModified(bool modified=true);
370 370
371 /** query if the calendar is read-only. */ 371 /** query if the calendar is read-only. */
372 bool isReadOnly(); 372 bool isReadOnly();
373 /** set state of calendar to read-only */ 373 /** set state of calendar to read-only */
374 void setReadOnly(bool readOnly=true); 374 void setReadOnly(bool readOnly=true);
375 375
376 void eventUpdated(Incidence *); 376 void eventUpdated(Incidence *);
377 377
378 /* iTIP scheduling actions */ 378 /* iTIP scheduling actions */
379 void schedule_publish(Incidence *incidence = 0); 379 void schedule_publish(Incidence *incidence = 0);
380 void schedule_request(Incidence *incidence = 0); 380 void schedule_request(Incidence *incidence = 0);
381 void schedule_refresh(Incidence *incidence = 0); 381 void schedule_refresh(Incidence *incidence = 0);
382 void schedule_cancel(Incidence *incidence = 0); 382 void schedule_cancel(Incidence *incidence = 0);
383 void schedule_add(Incidence *incidence = 0); 383 void schedule_add(Incidence *incidence = 0);
384 void schedule_reply(Incidence *incidence = 0); 384 void schedule_reply(Incidence *incidence = 0);
385 void schedule_counter(Incidence *incidence = 0); 385 void schedule_counter(Incidence *incidence = 0);
386 void schedule_declinecounter(Incidence *incidence = 0); 386 void schedule_declinecounter(Incidence *incidence = 0);
387 void schedule_publish_freebusy(int daysToPublish = 30); 387 void schedule_publish_freebusy(int daysToPublish = 30);
388 388
389 void openAddressbook(); 389 void openAddressbook();
390 390
391 void editFilters(); 391 void editFilters();
392 void toggleFilerEnabled(); 392 void toggleFilerEnabled();
393 QPtrList<CalFilter> filters(); 393 QPtrList<CalFilter> filters();
394 void toggleFilter(); 394 void toggleFilter();
395 void showFilter(bool visible); 395 void showFilter(bool visible);
396 void updateFilter(); 396 void updateFilter();
397 void filterEdited(); 397 void filterEdited();
398 void selectFilter( int ); 398 void selectFilter( int );
399 KOFilterView *filterView(); 399 KOFilterView *filterView();
400 400
401 void showIntro(); 401 void showIntro();
402 402
403 /** Move the curdatepient view date to today */ 403 /** Move the curdatepient view date to today */
404 void goToday(); 404 void goToday();
405 405
406 /** Move to the next date(s) in the current view */ 406 /** Move to the next date(s) in the current view */
407 void goNext(); 407 void goNext();
408 408
409 /** Move to the previous date(s) in the current view */ 409 /** Move to the previous date(s) in the current view */
410 void goPrevious(); 410 void goPrevious();
411 /** Move to the next date(s) in the current view */ 411 /** Move to the next date(s) in the current view */
412 void goNextMonth(); 412 void goNextMonth();
413 413
414 /** Move to the previous date(s) in the current view */ 414 /** Move to the previous date(s) in the current view */
415 void goPreviousMonth(); 415 void goPreviousMonth();
416 416
417 void toggleExpand(); 417 void toggleExpand();
418 void toggleDateNavigatorWidget(); 418 void toggleDateNavigatorWidget();
419 void toggleAllDaySize(); 419 void toggleAllDaySize();
420 void dialogClosing(Incidence *); 420 void dialogClosing(Incidence *);
421 421
422 /** Look for new messages in the inbox */ 422 /** Look for new messages in the inbox */
423 void lookForIncomingMessages(); 423 void lookForIncomingMessages();
424 /** Look for new messages in the outbox */ 424 /** Look for new messages in the outbox */
425 void lookForOutgoingMessages(); 425 void lookForOutgoingMessages();
426 426
427 void processMainViewSelection( Incidence * ); 427 void processMainViewSelection( Incidence * );
428 void processTodoListSelection( Incidence * ); 428 void processTodoListSelection( Incidence * );
429 429
430 void processIncidenceSelection( Incidence * ); 430 void processIncidenceSelection( Incidence * );
431 431
432 void purgeCompleted(); 432 void purgeCompleted();
433 bool removeCompletedSubTodos( Todo* ); 433 bool removeCompletedSubTodos( Todo* );
434 void slotCalendarChanged(); 434 void slotCalendarChanged();
435 bool importBday(); 435 bool importBday();
436 bool addAnniversary( QDate data, QString name, KCal::Attendee* a , bool birthday ); 436 bool addAnniversary( QDate data, QString name, KCal::Attendee* a , bool birthday );
437 bool importQtopia( const QString &categoriesFile, 437 bool importQtopia( const QString &categoriesFile,
438 const QString &datebookFile, 438 const QString &datebookFile,
439 const QString &tasklistFile ); 439 const QString &tasklistFile );
440 void syncExternal( int mode ); 440 void syncExternal( int mode );
441 void slotSelectPickerDate( QDate ) ; 441 void slotSelectPickerDate( QDate ) ;
442 void showDatePicker( ) ; 442 void showDatePicker( ) ;
443 void moveIncidence(Incidence *) ; 443 void moveIncidence(Incidence *) ;
444 void beamIncidence(Incidence *) ; 444 void beamIncidence(Incidence *) ;
445 void beamCalendar() ; 445 void beamCalendar() ;
446 void beamFilteredCalendar() ; 446 void beamFilteredCalendar() ;
447 void beamIncidenceList(QPtrList<Incidence>) ; 447 void beamIncidenceList(QPtrList<Incidence>) ;
448 void manageCategories(); 448 void manageCategories();
449 int addCategories(); 449 int addCategories();
450 void removeCategories(); 450 void removeCategories();
451 void setSyncDevice( QString ); 451 void setSyncDevice( QString );
452 void setSyncName( QString ); 452 void setSyncName( QString );
453 protected slots: 453 protected slots:
454 void timerAlarm(); 454 void timerAlarm();
455 void suspendAlarm(); 455 void suspendAlarm();
456 void beamDone( Ir *ir ); 456 void beamDone( Ir *ir );
457 /** Select a view or adapt the current view to display the specified dates. */ 457 /** Select a view or adapt the current view to display the specified dates. */
458 void showDates( const KCal::DateList & ); 458 void showDates( const KCal::DateList & );
459 void selectWeekNum ( int ); 459 void selectWeekNum ( int );
460 460
461 public: 461 public:
462 // show a standard warning 462 // show a standard warning
463 // returns KMsgBox::yesNoCancel() 463 // returns KMsgBox::yesNoCancel()
464 int msgCalModified(); 464 int msgCalModified();
465 virtual bool sync(KSyncManager* manager, QString filename, int mode); 465 virtual bool sync(KSyncManager* manager, QString filename, int mode);
466 466
467 virtual bool syncExternal(KSyncManager* manager, QString resource); 467 virtual bool syncExternal(KSyncManager* manager, QString resource);
468 virtual void removeSyncInfo( QString syncProfile); 468 virtual void removeSyncInfo( QString syncProfile);
469 void setSyncManager(KSyncManager* manager); 469 void setSyncManager(KSyncManager* manager);
470 void setLoadedFileVersion(QDateTime); 470 void setLoadedFileVersion(QDateTime);
471 bool checkFileVersion(QString fn); 471 bool checkFileVersion(QString fn);
472 bool checkFileChanged(QString fn); 472 bool checkFileChanged(QString fn);
473 Event* getLastSyncEvent(); 473 Event* getLastSyncEvent();
474 /** Adapt navigation units correpsonding to step size of navigation of the 474 /** Adapt navigation units correpsonding to step size of navigation of the
475 * current view. 475 * current view.
476 */ 476 */
477 void adaptNavigationUnits(); 477 void adaptNavigationUnits();
478 bool synchronizeCalendar( Calendar* local, Calendar* remote, int mode ); 478 bool synchronizeCalendar( Calendar* local, Calendar* remote, int mode );
479 int takeEvent( Incidence* local, Incidence* remote, int mode, bool full = false ); 479 int takeEvent( Incidence* local, Incidence* remote, int mode, bool full = false );
480 //Attendee* getYourAttendee(Event *event); 480 //Attendee* getYourAttendee(Event *event);
481 protected: 481 protected:
482 void schedule(Scheduler::Method, Incidence *incidence = 0); 482 void schedule(Scheduler::Method, Incidence *incidence = 0);
483 483
484 // returns KMsgBox::OKCandel() 484 // returns KMsgBox::OKCandel()
485 int msgItemDelete(); 485 int msgItemDelete();
486 void showEventEditor(); 486 void showEventEditor();
487 void showTodoEditor(); 487 void showTodoEditor();
488 void writeLocale(); 488 void writeLocale();
489 Todo *selectedTodo(); 489 Todo *selectedTodo();
490 490
491 private: 491 private:
492 bool mSyncKDE;
493 KSyncManager* mSyncManager; 492 KSyncManager* mSyncManager;
494 AlarmDialog * mAlarmDialog; 493 AlarmDialog * mAlarmDialog;
495 QString mAlarmNotification; 494 QString mAlarmNotification;
496 QString mSuspendAlarmNotification; 495 QString mSuspendAlarmNotification;
497 QTimer* mSuspendTimer; 496 QTimer* mSuspendTimer;
498 QTimer* mAlarmTimer; 497 QTimer* mAlarmTimer;
499 QTimer* mRecheckAlarmTimer; 498 QTimer* mRecheckAlarmTimer;
500 void computeAlarm( QString ); 499 void computeAlarm( QString );
501 void startAlarm( QString, QString ); 500 void startAlarm( QString, QString );
502 void setSyncEventsReadOnly(); 501 void setSyncEventsReadOnly();
503 502
504 QDateTime loadedFileVersion; 503 QDateTime loadedFileVersion;
505 void checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ); 504 void checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete );
506 void checkExternalId( Incidence * inc ); 505 void checkExternalId( Incidence * inc );
507 int mGlobalSyncMode; 506 int mGlobalSyncMode;
508 QString mCurrentSyncDevice; 507 QString mCurrentSyncDevice;
509 QString mCurrentSyncName; 508 QString mCurrentSyncName;
510 KOBeamPrefs* beamDialog; 509 KOBeamPrefs* beamDialog;
511 void init(); 510 void init();
512 int mDatePickerMode; 511 int mDatePickerMode;
513 bool mFlagEditDescription; 512 bool mFlagEditDescription;
514 QDateTime mLastCalendarSync; 513 QDateTime mLastCalendarSync;
515 void createPrinter(); 514 void createPrinter();
516 515
517 void calendarModified( bool, Calendar * ); 516 void calendarModified( bool, Calendar * );
518 517
519 CalPrinter *mCalPrinter; 518 CalPrinter *mCalPrinter;
520 519
521 QSplitter *mPanner; 520 QSplitter *mPanner;
522 QSplitter *mLeftSplitter; 521 QSplitter *mLeftSplitter;
523 QWidget *mLeftFrame; 522 QWidget *mLeftFrame;
524 QWidgetStack *mRightFrame; 523 QWidgetStack *mRightFrame;
525 524
526 KDatePicker* mDatePicker; 525 KDatePicker* mDatePicker;
527 QVBox* mDateFrame; 526 QVBox* mDateFrame;
528 NavigatorBar *mNavigatorBar; 527 NavigatorBar *mNavigatorBar;
529 528
530 KDateNavigator *mDateNavigator; // widget showing small month view. 529 KDateNavigator *mDateNavigator; // widget showing small month view.
531 530
532 KOFilterView *mFilterView; 531 KOFilterView *mFilterView;
533 532
534 ResourceView *mResourceView; 533 ResourceView *mResourceView;
535 534
536 // calendar object for this viewing instance 535 // calendar object for this viewing instance
537 Calendar *mCalendar; 536 Calendar *mCalendar;
538 537
539 CalendarResourceManager *mResourceManager; 538 CalendarResourceManager *mResourceManager;
540 539
541 FileStorage *mStorage; 540 FileStorage *mStorage;
542 541
543 DateNavigator *mNavigator; 542 DateNavigator *mNavigator;
544 543
545 KOViewManager *mViewManager; 544 KOViewManager *mViewManager;
546 KODialogManager *mDialogManager; 545 KODialogManager *mDialogManager;
547 546
548 // Calendar filters 547 // Calendar filters
549 QPtrList<CalFilter> mFilters; 548 QPtrList<CalFilter> mFilters;
550 549
551 // various housekeeping variables. 550 // various housekeeping variables.
552 bool mModified; // flag indicating if calendar is modified 551 bool mModified; // flag indicating if calendar is modified
553 bool mReadOnly; // flag indicating if calendar is read-only 552 bool mReadOnly; // flag indicating if calendar is read-only
554 QDate mSaveSingleDate; 553 QDate mSaveSingleDate;
555 554
556 Incidence *mSelectedIncidence; 555 Incidence *mSelectedIncidence;
557 Incidence *mMoveIncidence; 556 Incidence *mMoveIncidence;
558 KOTodoView *mTodoList; 557 KOTodoView *mTodoList;
559 KOEventEditor * mEventEditor; 558 KOEventEditor * mEventEditor;
560 KOTodoEditor * mTodoEditor; 559 KOTodoEditor * mTodoEditor;
561 KOEventViewerDialog * mEventViewerDialog; 560 KOEventViewerDialog * mEventViewerDialog;
562 void keyPressEvent ( QKeyEvent *e) ; 561 void keyPressEvent ( QKeyEvent *e) ;
563 //QMap<Incidence*,KOIncidenceEditor*> mDialogList; 562 //QMap<Incidence*,KOIncidenceEditor*> mDialogList;
564}; 563};
565 564
566 565
567class CalendarViewVisitor : public Incidence::Visitor 566class CalendarViewVisitor : public Incidence::Visitor
568{ 567{
569 public: 568 public:
570 CalendarViewVisitor() : mView( 0 ) {} 569 CalendarViewVisitor() : mView( 0 ) {}
571 570
572 bool act( Incidence *incidence, CalendarView *view ) 571 bool act( Incidence *incidence, CalendarView *view )
573 { 572 {
574 mView = view; 573 mView = view;
575 return incidence->accept( *this ); 574 return incidence->accept( *this );
576 } 575 }
577 576
578 protected: 577 protected:
579 CalendarView *mView; 578 CalendarView *mView;
580}; 579};
581 580
582class ShowIncidenceVisitor : public CalendarViewVisitor 581class ShowIncidenceVisitor : public CalendarViewVisitor
583{ 582{
584 protected: 583 protected:
585 bool visit( Event *event ) { mView->showEvent( event ); return true; } 584 bool visit( Event *event ) { mView->showEvent( event ); return true; }
586 bool visit( Todo *todo ) { mView->showTodo( todo ); return true; } 585 bool visit( Todo *todo ) { mView->showTodo( todo ); return true; }
587 bool visit( Journal * j ) { mView->showJournal( j );return true; } 586 bool visit( Journal * j ) { mView->showJournal( j );return true; }
588}; 587};
589 588
590class EditIncidenceVisitor : public CalendarViewVisitor 589class EditIncidenceVisitor : public CalendarViewVisitor
591{ 590{
592 protected: 591 protected:
593 bool visit( Event *event ) { mView->editEvent( event ); return true; } 592 bool visit( Event *event ) { mView->editEvent( event ); return true; }
594 bool visit( Todo *todo ) { mView->editTodo( todo ); return true; } 593 bool visit( Todo *todo ) { mView->editTodo( todo ); return true; }
595 bool visit( Journal *j ) { mView->editJournal( j); return true; } 594 bool visit( Journal *j ) { mView->editJournal( j); return true; }
596}; 595};
597 596
598class DeleteIncidenceVisitor : public CalendarViewVisitor 597class DeleteIncidenceVisitor : public CalendarViewVisitor
599{ 598{
600 protected: 599 protected:
601 bool visit( Event *event ) { mView->deleteEvent( event ); return true; } 600 bool visit( Event *event ) { mView->deleteEvent( event ); return true; }
602 bool visit( Todo *todo ) { mView->deleteTodo( todo ); return true; } 601 bool visit( Todo *todo ) { mView->deleteTodo( todo ); return true; }
603 bool visit( Journal * j) {mView->deleteJournal( j ); return true; } 602 bool visit( Journal * j) {mView->deleteJournal( j ); return true; }
604}; 603};
605 604
606#endif 605#endif
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index e09050e..17e6c75 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,1273 +1,1293 @@
1/* 1/*
2 This file is part of KDE-Pim/Pi. 2 This file is part of KDE-Pim/Pi.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
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// $Id$ 21// $Id$
22 22
23#include "ksyncmanager.h" 23#include "ksyncmanager.h"
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#include <unistd.h> 28#include <unistd.h>
29#endif 29#endif
30 30
31 31
32#include "ksyncprofile.h" 32#include "ksyncprofile.h"
33#include "ksyncprefsdialog.h" 33#include "ksyncprefsdialog.h"
34#include "kpimprefs.h" 34#include "kpimprefs.h"
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <qdir.h> 37#include <qdir.h>
38#include <qprogressbar.h> 38#include <qprogressbar.h>
39#include <qpopupmenu.h> 39#include <qpopupmenu.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qradiobutton.h> 41#include <qradiobutton.h>
42#include <qbuttongroup.h> 42#include <qbuttongroup.h>
43#include <qtimer.h> 43#include <qtimer.h>
44#include <qmessagebox.h> 44#include <qmessagebox.h>
45#include <qapplication.h> 45#include <qapplication.h>
46#include <qlineedit.h> 46#include <qlineedit.h>
47#include <qdialog.h> 47#include <qdialog.h>
48#include <qlayout.h> 48#include <qlayout.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#include <qlabel.h> 50#include <qlabel.h>
51#include <qcheckbox.h> 51#include <qcheckbox.h>
52 52
53#include <klocale.h> 53#include <klocale.h>
54#include <kglobal.h> 54#include <kglobal.h>
55#include <kconfig.h> 55#include <kconfig.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57 57
58QDateTime KSyncManager::mRequestedSyncEvent; 58QDateTime KSyncManager::mRequestedSyncEvent;
59 59
60 60
61KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 61KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
62 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) 62 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu)
63{ 63{
64 mServerSocket = 0; 64 mServerSocket = 0;
65 bar = new QProgressBar ( 1, 0 ); 65 bar = new QProgressBar ( 1, 0 );
66 bar->setCaption (""); 66 bar->setCaption ("");
67 67
68 int w = 300; 68 int w = 300;
69 if ( QApplication::desktop()->width() < 320 ) 69 if ( QApplication::desktop()->width() < 320 )
70 w = 220; 70 w = 220;
71 int h = bar->sizeHint().height() ; 71 int h = bar->sizeHint().height() ;
72 int dw = QApplication::desktop()->width(); 72 int dw = QApplication::desktop()->width();
73 int dh = QApplication::desktop()->height(); 73 int dh = QApplication::desktop()->height();
74 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 74 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
75 if ( mPrefs->mPassiveSyncAutoStart ) 75 if ( mPrefs->mPassiveSyncAutoStart )
76 enableQuick( false ); 76 enableQuick( false );
77 77
78} 78}
79 79
80KSyncManager::~KSyncManager() 80KSyncManager::~KSyncManager()
81{ 81{
82 delete bar; 82 delete bar;
83} 83}
84 84
85 85
86void KSyncManager::fillSyncMenu() 86void KSyncManager::fillSyncMenu()
87{ 87{
88 if ( mSyncMenu->count() ) 88 if ( mSyncMenu->count() )
89 mSyncMenu->clear(); 89 mSyncMenu->clear();
90 90
91 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 91 mSyncMenu->insertItem( i18n("Configure..."), 0 );
92 mSyncMenu->insertSeparator(); 92 mSyncMenu->insertSeparator();
93 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); 93 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu );
94 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); 94 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 );
95 clearMenu->insertItem( i18n("For all profiles"), 1 ); 95 clearMenu->insertItem( i18n("For all profiles"), 1 );
96 clearMenu->insertSeparator(); 96 clearMenu->insertSeparator();
97 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); 97 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) );
98 mSyncMenu->insertSeparator(); 98 mSyncMenu->insertSeparator();
99 if ( mServerSocket == 0 ) { 99 if ( mServerSocket == 0 ) {
100 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 100 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
101 } else { 101 } else {
102 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 102 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
103 } 103 }
104 mSyncMenu->insertSeparator(); 104 mSyncMenu->insertSeparator();
105 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 105 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
106 mSyncMenu->insertSeparator(); 106 mSyncMenu->insertSeparator();
107 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 107 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
108 config.setGroup("General"); 108 config.setGroup("General");
109 QStringList prof = config.readListEntry("SyncProfileNames"); 109 QStringList prof = config.readListEntry("SyncProfileNames");
110 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 110 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
111 if ( prof.count() < 2 ) { 111 if ( prof.count() < 2 ) {
112 prof.clear(); 112 prof.clear();
113 QString externalName; 113 QString externalName;
114#ifdef DESKTOP_VERSION 114#ifdef DESKTOP_VERSION
115#ifdef _WIN32_ 115#ifdef _WIN32_
116 externalName = "OutLook(not_implemented)"; 116 externalName = "OutLook(not_implemented)";
117#else 117#else
118 externalName = "KDE_Desktop"; 118 externalName = "KDE_Desktop";
119#endif 119#endif
120#else 120#else
121 externalName = "Sharp_DTM"; 121 externalName = "Sharp_DTM";
122#endif 122#endif
123 prof << externalName; 123 prof << externalName;
124 prof << i18n("Local_file"); 124 prof << i18n("Local_file");
125 prof << i18n("Last_file"); 125 prof << i18n("Last_file");
126 KSyncProfile* temp = new KSyncProfile (); 126 KSyncProfile* temp = new KSyncProfile ();
127 temp->setName( prof[0] ); 127 temp->setName( prof[0] );
128 temp->writeConfig(&config); 128 temp->writeConfig(&config);
129 temp->setName( prof[1] ); 129 temp->setName( prof[1] );
130 temp->writeConfig(&config); 130 temp->writeConfig(&config);
131 temp->setName( prof[2] ); 131 temp->setName( prof[2] );
132 temp->writeConfig(&config); 132 temp->writeConfig(&config);
133 config.setGroup("General"); 133 config.setGroup("General");
134 config.writeEntry("SyncProfileNames",prof); 134 config.writeEntry("SyncProfileNames",prof);
135 config.writeEntry("ExternSyncProfiles",externalName); 135 config.writeEntry("ExternSyncProfiles",externalName);
136 config.sync(); 136 config.sync();
137 delete temp; 137 delete temp;
138 } 138 }
139 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 139 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
140 mSyncProfileNames = prof; 140 mSyncProfileNames = prof;
141 unsigned int i; 141 unsigned int i;
142 for ( i = 0; i < prof.count(); ++i ) { 142 for ( i = 0; i < prof.count(); ++i ) {
143 mSyncMenu->insertItem( prof[i], 1000+i ); 143 mSyncMenu->insertItem( prof[i], 1000+i );
144 clearMenu->insertItem( prof[i], 1000+i ); 144 clearMenu->insertItem( prof[i], 1000+i );
145 if ( i == 2 ) 145 if ( i == 2 )
146 mSyncMenu->insertSeparator(); 146 mSyncMenu->insertSeparator();
147 } 147 }
148 QDir app_dir; 148 QDir app_dir;
149 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 149 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
150 if ( mTargetApp == PWMPI) { 150 if ( mTargetApp == PWMPI) {
151 mSyncMenu->removeItem( 1000 ); 151 mSyncMenu->removeItem( 1000 );
152 clearMenu->removeItem( 1000 ); 152 clearMenu->removeItem( 1000 );
153 } 153 }
154#ifndef DESKTOP_VERSION 154#ifndef DESKTOP_VERSION
155 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 155 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
156 mSyncMenu->removeItem( 1000 ); 156 mSyncMenu->removeItem( 1000 );
157 clearMenu->removeItem( 1000 ); 157 clearMenu->removeItem( 1000 );
158 } 158 }
159#endif 159#endif
160 mSyncMenu->removeItem( 1002 ); 160 mSyncMenu->removeItem( 1002 );
161 clearMenu->removeItem( 1002 ); 161 clearMenu->removeItem( 1002 );
162} 162}
163void KSyncManager::slotClearMenu( int action ) 163void KSyncManager::slotClearMenu( int action )
164{ 164{
165 QString syncDevice; 165 QString syncDevice;
166 if ( action > 999 ) { 166 if ( action > 999 ) {
167 syncDevice = mSyncProfileNames[action - 1000] ; 167 syncDevice = mSyncProfileNames[action - 1000] ;
168 } 168 }
169 169
170 170
171 171
172 int result = 0; 172 int result = 0;
173 QString sd; 173 QString sd;
174 if ( syncDevice.isEmpty() ) 174 if ( syncDevice.isEmpty() )
175 sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); 175 sd = i18n("Do you want to\nclear all sync info\nof all profiles?");
176 else 176 else
177 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); 177 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice );
178 178
179 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, 179 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0,
180 0, 1 ); 180 0, 1 );
181 if ( result ) 181 if ( result )
182 return; 182 return;
183 mImplementation->removeSyncInfo( syncDevice ); 183 mImplementation->removeSyncInfo( syncDevice );
184} 184}
185void KSyncManager::slotSyncMenu( int action ) 185void KSyncManager::slotSyncMenu( int action )
186{ 186{
187 qDebug("syncaction %d ", action); 187 qDebug("syncaction %d ", action);
188 if ( action == 5000 ) 188 if ( action == 5000 )
189 return; 189 return;
190 mSyncWithDesktop = false;
190 if ( action == 0 ) { 191 if ( action == 0 ) {
191 192
192 // seems to be a Qt2 event handling bug 193 // seems to be a Qt2 event handling bug
193 // syncmenu.clear causes a segfault at first time 194 // syncmenu.clear causes a segfault at first time
194 // when we call it after the main event loop, it is ok 195 // when we call it after the main event loop, it is ok
195 // same behaviour when calling OM/Pi via QCOP for the first time 196 // same behaviour when calling OM/Pi via QCOP for the first time
196 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 197 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
197 //confSync(); 198 //confSync();
198 199
199 return; 200 return;
200 } 201 }
201 if ( action == 1 ) { 202 if ( action == 1 ) {
202 multiSync( true ); 203 multiSync( true );
203 return; 204 return;
204 } 205 }
205 if ( action == 2 ) { 206 if ( action == 2 ) {
206 enableQuick(); 207 enableQuick();
207 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 208 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
208 return; 209 return;
209 } 210 }
210 if ( action == 3 ) { 211 if ( action == 3 ) {
211 delete mServerSocket; 212 delete mServerSocket;
212 mServerSocket = 0; 213 mServerSocket = 0;
213 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 214 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
214 return; 215 return;
215 } 216 }
216 217
217 if (blockSave()) 218 if (blockSave())
218 return; 219 return;
219 220
220 setBlockSave(true); 221 setBlockSave(true);
221 bool silent = false; 222 bool silent = false;
222 if ( action == 999 ) { 223 if ( action == 999 ) {
223 //special mode for silent syncing 224 //special mode for silent syncing
224 action = 1000; 225 action = 1000;
225 silent = true; 226 silent = true;
226 } 227 }
227 228
228 mCurrentSyncProfile = action - 1000 ; 229 mCurrentSyncProfile = action - 1000 ;
229 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 230 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
230 mCurrentSyncName = mLocalMachineName ; 231 mCurrentSyncName = mLocalMachineName ;
231 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 232 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
232 KSyncProfile* temp = new KSyncProfile (); 233 KSyncProfile* temp = new KSyncProfile ();
233 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 234 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
234 temp->readConfig(&config); 235 temp->readConfig(&config);
235 if (silent) { 236 if (silent) {
236 mAskForPreferences = false; 237 mAskForPreferences = false;
237 mShowSyncSummary = false; 238 mShowSyncSummary = false;
238 mWriteBackFile = true; 239 mWriteBackFile = true;
239 mSyncAlgoPrefs = 2;// take newest 240 mSyncAlgoPrefs = 2;// take newest
240 } 241 }
241 else { 242 else {
242 mAskForPreferences = temp->getAskForPreferences(); 243 mAskForPreferences = temp->getAskForPreferences();
243 mShowSyncSummary = temp->getShowSummaryAfterSync(); 244 mShowSyncSummary = temp->getShowSummaryAfterSync();
244 mWriteBackFile = temp->getWriteBackFile(); 245 mWriteBackFile = temp->getWriteBackFile();
245 mSyncAlgoPrefs = temp->getSyncPrefs(); 246 mSyncAlgoPrefs = temp->getSyncPrefs();
246 } 247 }
247 mWriteBackExistingOnly = temp->getWriteBackExisting(); 248 mWriteBackExistingOnly = temp->getWriteBackExisting();
248 mIsKapiFile = temp->getIsKapiFile(); 249 mIsKapiFile = temp->getIsKapiFile();
249 mWriteBackInFuture = 0; 250 mWriteBackInFuture = 0;
250 if ( temp->getWriteBackFuture() ) 251 if ( temp->getWriteBackFuture() )
251 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 252 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
252 253
253 if ( action == 1000 ) { 254 if ( action == 1000 ) {
255 mIsKapiFile = false;
254#ifdef DESKTOP_VERSION 256#ifdef DESKTOP_VERSION
255 syncKDE(); 257 syncKDE();
256#else 258#else
257 syncSharp(); 259 syncSharp();
258#endif 260#endif
259 261
260 } else if ( action == 1001 ) { 262 } else if ( action == 1001 ) {
261 syncLocalFile(); 263 syncLocalFile();
262 264
263 } else if ( action == 1002 ) { 265 } else if ( action == 1002 ) {
264 mWriteBackFile = false; 266 mWriteBackFile = false;
265 mAskForPreferences = false; 267 mAskForPreferences = false;
266 mShowSyncSummary = false; 268 mShowSyncSummary = false;
267 mSyncAlgoPrefs = 3; 269 mSyncAlgoPrefs = 3;
268 quickSyncLocalFile(); 270 quickSyncLocalFile();
269 271
270 } else if ( action >= 1003 ) { 272 } else if ( action >= 1003 ) {
271 if ( temp->getIsLocalFileSync() ) { 273 if ( temp->getIsLocalFileSync() ) {
272 switch(mTargetApp) 274 switch(mTargetApp)
273 { 275 {
274 case (KAPI): 276 case (KAPI):
275 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 277 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
276 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 278 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
277 break; 279 break;
278 case (KOPI): 280 case (KOPI):
279 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 281 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
280 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 282 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
281 break; 283 break;
282 case (PWMPI): 284 case (PWMPI):
283 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 285 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
284 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 286 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
285 break; 287 break;
286 default: 288 default:
287 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 289 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
288 break; 290 break;
289 291
290 } 292 }
291 } else { 293 } else {
292 if ( temp->getIsPhoneSync() ) { 294 if ( temp->getIsPhoneSync() ) {
293 mPhoneDevice = temp->getPhoneDevice( ) ; 295 mPhoneDevice = temp->getPhoneDevice( ) ;
294 mPhoneConnection = temp->getPhoneConnection( ); 296 mPhoneConnection = temp->getPhoneConnection( );
295 mPhoneModel = temp->getPhoneModel( ); 297 mPhoneModel = temp->getPhoneModel( );
296 syncPhone(); 298 syncPhone();
297 } else if ( temp->getIsPiSync() ) { 299 } else if ( temp->getIsPiSync() ) {
298 if ( mTargetApp == KAPI ) { 300 if ( mTargetApp == KAPI ) {
299 mPassWordPiSync = temp->getRemotePwAB(); 301 mPassWordPiSync = temp->getRemotePwAB();
300 mActiveSyncPort = temp->getRemotePortAB(); 302 mActiveSyncPort = temp->getRemotePortAB();
301 mActiveSyncIP = temp->getRemoteIPAB(); 303 mActiveSyncIP = temp->getRemoteIPAB();
302 } else if ( mTargetApp == KOPI ) { 304 } else if ( mTargetApp == KOPI ) {
303 mPassWordPiSync = temp->getRemotePw(); 305 mPassWordPiSync = temp->getRemotePw();
304 mActiveSyncPort = temp->getRemotePort(); 306 mActiveSyncPort = temp->getRemotePort();
305 mActiveSyncIP = temp->getRemoteIP(); 307 mActiveSyncIP = temp->getRemoteIP();
306 } else { 308 } else {
307 mPassWordPiSync = temp->getRemotePwPWM(); 309 mPassWordPiSync = temp->getRemotePwPWM();
308 mActiveSyncPort = temp->getRemotePortPWM(); 310 mActiveSyncPort = temp->getRemotePortPWM();
309 mActiveSyncIP = temp->getRemoteIPPWM(); 311 mActiveSyncIP = temp->getRemoteIPPWM();
310 } 312 }
311 syncPi(); 313 syncPi();
312 while ( !mPisyncFinished ) { 314 while ( !mPisyncFinished ) {
313 //qDebug("waiting "); 315 //qDebug("waiting ");
314 qApp->processEvents(); 316 qApp->processEvents();
315 } 317 }
316 } else 318 } else
317 syncRemote( temp ); 319 syncRemote( temp );
318 320
319 } 321 }
320 } 322 }
321 delete temp; 323 delete temp;
322 setBlockSave(false); 324 setBlockSave(false);
323} 325}
324 326
325void KSyncManager::enableQuick( bool ask ) 327void KSyncManager::enableQuick( bool ask )
326{ 328{
327 bool autoStart; 329 bool autoStart;
328 bool changed = false; 330 bool changed = false;
329 if ( ask ) { 331 if ( ask ) {
330 QDialog dia ( 0, "input-dialog", true ); 332 QDialog dia ( 0, "input-dialog", true );
331 QLineEdit lab ( &dia ); 333 QLineEdit lab ( &dia );
332 QVBoxLayout lay( &dia ); 334 QVBoxLayout lay( &dia );
333 lab.setText( mPrefs->mPassiveSyncPort ); 335 lab.setText( mPrefs->mPassiveSyncPort );
334 lay.setMargin(7); 336 lay.setMargin(7);
335 lay.setSpacing(7); 337 lay.setSpacing(7);
336 int po = 9197+mTargetApp; 338 int po = 9197+mTargetApp;
337 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 339 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
338 lay.addWidget( &label); 340 lay.addWidget( &label);
339 lay.addWidget( &lab); 341 lay.addWidget( &lab);
340 342
341 QLineEdit lepw ( &dia ); 343 QLineEdit lepw ( &dia );
342 lepw.setText( mPrefs->mPassiveSyncPw ); 344 lepw.setText( mPrefs->mPassiveSyncPw );
343 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 345 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
344 lay.addWidget( &label2); 346 lay.addWidget( &label2);
345 lay.addWidget( &lepw); 347 lay.addWidget( &lepw);
346 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); 348 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
347 lay.addWidget( &autostart); 349 lay.addWidget( &autostart);
348 autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); 350 autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
349#ifdef DESKTOP_VERSION 351#ifdef DESKTOP_VERSION
350#ifdef _WIN32_ 352#ifdef _WIN32_
351 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); 353 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia );
352#else 354#else
353 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); 355 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia );
354#endif 356#endif
355 lay.addWidget( &syncdesktop); 357 lay.addWidget( &syncdesktop);
356#else 358#else
357 mPrefs->mPassiveSyncWithDesktop = false; 359 mPrefs->mPassiveSyncWithDesktop = false;
358 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); 360 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia );
359 syncdesktop.hide(); 361 syncdesktop.hide();
360#endif 362#endif
361 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); 363 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop );
362 364
363 dia.setFixedSize( 230,120 ); 365 dia.setFixedSize( 230,120 );
364 dia.setCaption( i18n("Enter port for Pi-Sync") ); 366 dia.setCaption( i18n("Enter port for Pi-Sync") );
365 QPushButton pb ( "OK", &dia); 367 QPushButton pb ( "OK", &dia);
366 lay.addWidget( &pb ); 368 lay.addWidget( &pb );
367 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 369 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
368 dia.show(); 370 dia.show();
369 if ( ! dia.exec() ) 371 if ( ! dia.exec() )
370 return; 372 return;
371 dia.hide(); 373 dia.hide();
372 qApp->processEvents(); 374 qApp->processEvents();
373 if ( mPrefs->mPassiveSyncPw != lepw.text() ) { 375 if ( mPrefs->mPassiveSyncPw != lepw.text() ) {
374 changed = true; 376 changed = true;
375 mPrefs->mPassiveSyncPw = lepw.text(); 377 mPrefs->mPassiveSyncPw = lepw.text();
376 } 378 }
377 if ( mPrefs->mPassiveSyncPort != lab.text() ) { 379 if ( mPrefs->mPassiveSyncPort != lab.text() ) {
378 mPrefs->mPassiveSyncPort = lab.text(); 380 mPrefs->mPassiveSyncPort = lab.text();
379 changed = true; 381 changed = true;
380 } 382 }
381 autoStart = autostart.isChecked(); 383 autoStart = autostart.isChecked();
382 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { 384 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) {
383 changed = true; 385 changed = true;
384 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); 386 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked();
385 } 387 }
386 } 388 }
387 else 389 else
388 autoStart = mPrefs->mPassiveSyncAutoStart; 390 autoStart = mPrefs->mPassiveSyncAutoStart;
389 if ( autoStart != mPrefs->mPassiveSyncAutoStart ) 391 if ( autoStart != mPrefs->mPassiveSyncAutoStart )
390 changed = true; 392 changed = true;
391 bool ok; 393 bool ok;
392 mPrefs->mPassiveSyncAutoStart = false; 394 mPrefs->mPassiveSyncAutoStart = false;
393 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 395 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
394 if ( ! ok ) { 396 if ( ! ok ) {
395 KMessageBox::information( 0, i18n("No valid port")); 397 KMessageBox::information( 0, i18n("No valid port"));
396 return; 398 return;
397 } 399 }
398 //qDebug("port %d ", port); 400 //qDebug("port %d ", port);
399 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 401 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
400 mServerSocket->setFileName( defaultFileName() ); 402 mServerSocket->setFileName( defaultFileName() );
401 //qDebug("connected "); 403 //qDebug("connected ");
402 if ( !mServerSocket->ok() ) { 404 if ( !mServerSocket->ok() ) {
403 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 405 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
404 delete mServerSocket; 406 delete mServerSocket;
405 mServerSocket = 0; 407 mServerSocket = 0;
406 return; 408 return;
407 } 409 }
408 mPrefs->mPassiveSyncAutoStart = autoStart; 410 mPrefs->mPassiveSyncAutoStart = autoStart;
409 if ( changed ) { 411 if ( changed ) {
410 mPrefs->writeConfig(); 412 mPrefs->writeConfig();
411 } 413 }
412 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 414 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
413 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 415 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
414} 416}
415 417
416void KSyncManager::syncLocalFile() 418void KSyncManager::syncLocalFile()
417{ 419{
418 420
419 QString fn =mPrefs->mLastSyncedLocalFile; 421 QString fn =mPrefs->mLastSyncedLocalFile;
420 QString ext; 422 QString ext;
421 423
422 switch(mTargetApp) 424 switch(mTargetApp)
423 { 425 {
424 case (KAPI): 426 case (KAPI):
425 ext = "(*.vcf)"; 427 ext = "(*.vcf)";
426 break; 428 break;
427 case (KOPI): 429 case (KOPI):
428 ext = "(*.ics/*.vcs)"; 430 ext = "(*.ics/*.vcs)";
429 break; 431 break;
430 case (PWMPI): 432 case (PWMPI):
431 ext = "(*.pwm)"; 433 ext = "(*.pwm)";
432 break; 434 break;
433 default: 435 default:
434 qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); 436 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
435 break; 437 break;
436 438
437 } 439 }
438 440
439 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 441 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
440 if ( fn == "" ) 442 if ( fn == "" )
441 return; 443 return;
442 if ( syncWithFile( fn, false ) ) { 444 if ( syncWithFile( fn, false ) ) {
443 qDebug("syncLocalFile() successful "); 445 qDebug("syncLocalFile() successful ");
444 } 446 }
445 447
446} 448}
447 449
448bool KSyncManager::syncWithFile( QString fn , bool quick ) 450bool KSyncManager::syncWithFile( QString fn , bool quick )
449{ 451{
450 bool ret = false; 452 bool ret = false;
451 QFileInfo info; 453 QFileInfo info;
452 info.setFile( fn ); 454 info.setFile( fn );
453 QString mess; 455 QString mess;
454 bool loadbup = true; 456 bool loadbup = true;
455 if ( !info. exists() ) { 457 if ( !info. exists() ) {
456 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 458 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
457 int result = QMessageBox::warning( mParent, i18n("Warning!"), 459 int result = QMessageBox::warning( mParent, i18n("Warning!"),
458 mess ); 460 mess );
459 return ret; 461 return ret;
460 } 462 }
461 int result = 0; 463 int result = 0;
462 if ( !quick ) { 464 if ( !quick ) {
463 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 465 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
464 result = QMessageBox::warning( mParent, i18n("Warning!"), 466 result = QMessageBox::warning( mParent, i18n("Warning!"),
465 mess, 467 mess,
466 i18n("Sync"), i18n("Cancel"), 0, 468 i18n("Sync"), i18n("Cancel"), 0,
467 0, 1 ); 469 0, 1 );
468 if ( result ) 470 if ( result )
469 return false; 471 return false;
470 } 472 }
471 if ( mAskForPreferences ) 473 if ( mAskForPreferences )
472 if ( !edit_sync_options()) { 474 if ( !edit_sync_options()) {
473 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 475 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
474 return false; 476 return false;
475 } 477 }
476 if ( result == 0 ) { 478 if ( result == 0 ) {
477 //qDebug("Now sycing ... "); 479 //qDebug("Now sycing ... ");
478 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 480 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
479 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 481 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
480 else 482 else
481 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 483 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
482 if ( ! quick ) 484 if ( ! quick )
483 mPrefs->mLastSyncedLocalFile = fn; 485 mPrefs->mLastSyncedLocalFile = fn;
484 } 486 }
485 return ret; 487 return ret;
486} 488}
487 489
488void KSyncManager::quickSyncLocalFile() 490void KSyncManager::quickSyncLocalFile()
489{ 491{
490 492
491 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { 493 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) {
492 qDebug("quick syncLocalFile() successful "); 494 qDebug("quick syncLocalFile() successful ");
493 495
494 } 496 }
495} 497}
496 498
497void KSyncManager::multiSync( bool askforPrefs ) 499void KSyncManager::multiSync( bool askforPrefs )
498{ 500{
499 if (blockSave()) 501 if (blockSave())
500 return; 502 return;
501 setBlockSave(true); 503 setBlockSave(true);
502 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 504 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
503 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), 505 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
504 question, 506 question,
505 i18n("Yes"), i18n("No"), 507 i18n("Yes"), i18n("No"),
506 0, 0 ) != 0 ) { 508 0, 0 ) != 0 ) {
507 setBlockSave(false); 509 setBlockSave(false);
508 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 510 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
509 return; 511 return;
510 } 512 }
511 mCurrentSyncDevice = i18n("Multiple profiles") ; 513 mCurrentSyncDevice = i18n("Multiple profiles") ;
512 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; 514 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
513 if ( askforPrefs ) { 515 if ( askforPrefs ) {
514 if ( !edit_sync_options()) { 516 if ( !edit_sync_options()) {
515 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 517 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
516 return; 518 return;
517 } 519 }
518 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 520 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
519 } 521 }
520 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 522 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
521 qApp->processEvents(); 523 qApp->processEvents();
522 int num = ringSync() ; 524 int num = ringSync() ;
523 if ( num > 1 ) 525 if ( num > 1 )
524 ringSync(); 526 ringSync();
525 setBlockSave(false); 527 setBlockSave(false);
526 if ( num ) 528 if ( num )
527 emit save(); 529 emit save();
528 if ( num ) 530 if ( num )
529 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 531 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
530 else 532 else
531 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 533 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
532 return; 534 return;
533} 535}
534 536
535int KSyncManager::ringSync() 537int KSyncManager::ringSync()
536{ 538{
537 int syncedProfiles = 0; 539 int syncedProfiles = 0;
538 unsigned int i; 540 unsigned int i;
539 QTime timer; 541 QTime timer;
540 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 542 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
541 QStringList syncProfileNames = mSyncProfileNames; 543 QStringList syncProfileNames = mSyncProfileNames;
542 KSyncProfile* temp = new KSyncProfile (); 544 KSyncProfile* temp = new KSyncProfile ();
543 mAskForPreferences = false; 545 mAskForPreferences = false;
544 for ( i = 0; i < syncProfileNames.count(); ++i ) { 546 for ( i = 0; i < syncProfileNames.count(); ++i ) {
545 mCurrentSyncProfile = i; 547 mCurrentSyncProfile = i;
546 temp->setName(syncProfileNames[mCurrentSyncProfile]); 548 temp->setName(syncProfileNames[mCurrentSyncProfile]);
547 temp->readConfig(&config); 549 temp->readConfig(&config);
548 550
549 bool includeInRingSync; 551 bool includeInRingSync;
550 switch(mTargetApp) 552 switch(mTargetApp)
551 { 553 {
552 case (KAPI): 554 case (KAPI):
553 includeInRingSync = temp->getIncludeInRingSyncAB(); 555 includeInRingSync = temp->getIncludeInRingSyncAB();
554 break; 556 break;
555 case (KOPI): 557 case (KOPI):
556 includeInRingSync = temp->getIncludeInRingSync(); 558 includeInRingSync = temp->getIncludeInRingSync();
557 break; 559 break;
558 case (PWMPI): 560 case (PWMPI):
559 includeInRingSync = temp->getIncludeInRingSyncPWM(); 561 includeInRingSync = temp->getIncludeInRingSyncPWM();
560 break; 562 break;
561 default: 563 default:
562 qDebug("KSyncManager::ringSync: invalid apptype selected"); 564 qDebug("KSyncManager::ringSync: invalid apptype selected");
563 break; 565 break;
564 566
565 } 567 }
566 568
567 569
568 if ( includeInRingSync && ( i < 1 || i > 2 )) { 570 if ( includeInRingSync && ( i < 1 || i > 2 )) {
569 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 571 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
570 ++syncedProfiles; 572 ++syncedProfiles;
571 // mAskForPreferences = temp->getAskForPreferences(); 573 // mAskForPreferences = temp->getAskForPreferences();
572 mWriteBackFile = temp->getWriteBackFile(); 574 mWriteBackFile = temp->getWriteBackFile();
573 mWriteBackExistingOnly = temp->getWriteBackExisting(); 575 mWriteBackExistingOnly = temp->getWriteBackExisting();
574 mWriteBackInFuture = 0; 576 mWriteBackInFuture = 0;
575 if ( temp->getWriteBackFuture() ) 577 if ( temp->getWriteBackFuture() )
576 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 578 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
577 mShowSyncSummary = false; 579 mShowSyncSummary = false;
578 mCurrentSyncDevice = syncProfileNames[i] ; 580 mCurrentSyncDevice = syncProfileNames[i] ;
579 mCurrentSyncName = mLocalMachineName; 581 mCurrentSyncName = mLocalMachineName;
580 if ( i == 0 ) { 582 if ( i == 0 ) {
581#ifdef DESKTOP_VERSION 583#ifdef DESKTOP_VERSION
582 syncKDE(); 584 syncKDE();
583#else 585#else
584 syncSharp(); 586 syncSharp();
585#endif 587#endif
586 } else { 588 } else {
587 if ( temp->getIsLocalFileSync() ) { 589 if ( temp->getIsLocalFileSync() ) {
588 switch(mTargetApp) 590 switch(mTargetApp)
589 { 591 {
590 case (KAPI): 592 case (KAPI):
591 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 593 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
592 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 594 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
593 break; 595 break;
594 case (KOPI): 596 case (KOPI):
595 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 597 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
596 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 598 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
597 break; 599 break;
598 case (PWMPI): 600 case (PWMPI):
599 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 601 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
600 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 602 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
601 break; 603 break;
602 default: 604 default:
603 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 605 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
604 break; 606 break;
605 } 607 }
606 } else { 608 } else {
607 if ( temp->getIsPhoneSync() ) { 609 if ( temp->getIsPhoneSync() ) {
608 mPhoneDevice = temp->getPhoneDevice( ) ; 610 mPhoneDevice = temp->getPhoneDevice( ) ;
609 mPhoneConnection = temp->getPhoneConnection( ); 611 mPhoneConnection = temp->getPhoneConnection( );
610 mPhoneModel = temp->getPhoneModel( ); 612 mPhoneModel = temp->getPhoneModel( );
611 syncPhone(); 613 syncPhone();
612 } else if ( temp->getIsPiSync() ) { 614 } else if ( temp->getIsPiSync() ) {
613 if ( mTargetApp == KAPI ) { 615 if ( mTargetApp == KAPI ) {
614 mPassWordPiSync = temp->getRemotePwAB(); 616 mPassWordPiSync = temp->getRemotePwAB();
615 mActiveSyncPort = temp->getRemotePortAB(); 617 mActiveSyncPort = temp->getRemotePortAB();
616 mActiveSyncIP = temp->getRemoteIPAB(); 618 mActiveSyncIP = temp->getRemoteIPAB();
617 } else if ( mTargetApp == KOPI ) { 619 } else if ( mTargetApp == KOPI ) {
618 mPassWordPiSync = temp->getRemotePw(); 620 mPassWordPiSync = temp->getRemotePw();
619 mActiveSyncPort = temp->getRemotePort(); 621 mActiveSyncPort = temp->getRemotePort();
620 mActiveSyncIP = temp->getRemoteIP(); 622 mActiveSyncIP = temp->getRemoteIP();
621 } else { 623 } else {
622 mPassWordPiSync = temp->getRemotePwPWM(); 624 mPassWordPiSync = temp->getRemotePwPWM();
623 mActiveSyncPort = temp->getRemotePortPWM(); 625 mActiveSyncPort = temp->getRemotePortPWM();
624 mActiveSyncIP = temp->getRemoteIPPWM(); 626 mActiveSyncIP = temp->getRemoteIPPWM();
625 } 627 }
626 syncPi(); 628 syncPi();
627 while ( !mPisyncFinished ) { 629 while ( !mPisyncFinished ) {
628 //qDebug("waiting "); 630 //qDebug("waiting ");
629 qApp->processEvents(); 631 qApp->processEvents();
630 } 632 }
631 timer.start(); 633 timer.start();
632 while ( timer.elapsed () < 2000 ) { 634 while ( timer.elapsed () < 2000 ) {
633 qApp->processEvents(); 635 qApp->processEvents();
634 } 636 }
635 } else 637 } else
636 syncRemote( temp, false ); 638 syncRemote( temp, false );
637 639
638 } 640 }
639 } 641 }
640 timer.start(); 642 timer.start();
641 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); 643 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") );
642 while ( timer.elapsed () < 2000 ) { 644 while ( timer.elapsed () < 2000 ) {
643 qApp->processEvents(); 645 qApp->processEvents();
644#ifndef _WIN32_ 646#ifndef _WIN32_
645 sleep (1); 647 sleep (1);
646#endif 648#endif
647 } 649 }
648 650
649 } 651 }
650 652
651 } 653 }
652 delete temp; 654 delete temp;
653 return syncedProfiles; 655 return syncedProfiles;
654} 656}
655 657
656void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 658void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
657{ 659{
658 QString question; 660 QString question;
659 if ( ask ) { 661 if ( ask ) {
660 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 662 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
661 if ( QMessageBox::information( mParent, i18n("Sync"), 663 if ( QMessageBox::information( mParent, i18n("Sync"),
662 question, 664 question,
663 i18n("Yes"), i18n("No"), 665 i18n("Yes"), i18n("No"),
664 0, 0 ) != 0 ) 666 0, 0 ) != 0 )
665 return; 667 return;
666 } 668 }
667 669
668 QString preCommand; 670 QString preCommand;
669 QString localTempFile; 671 QString localTempFile;
670 QString postCommand; 672 QString postCommand;
671 673
672 switch(mTargetApp) 674 switch(mTargetApp)
673 { 675 {
674 case (KAPI): 676 case (KAPI):
675 preCommand = prof->getPreSyncCommandAB(); 677 preCommand = prof->getPreSyncCommandAB();
676 postCommand = prof->getPostSyncCommandAB(); 678 postCommand = prof->getPostSyncCommandAB();
677 localTempFile = prof->getLocalTempFileAB(); 679 localTempFile = prof->getLocalTempFileAB();
678 break; 680 break;
679 case (KOPI): 681 case (KOPI):
680 preCommand = prof->getPreSyncCommand(); 682 preCommand = prof->getPreSyncCommand();
681 postCommand = prof->getPostSyncCommand(); 683 postCommand = prof->getPostSyncCommand();
682 localTempFile = prof->getLocalTempFile(); 684 localTempFile = prof->getLocalTempFile();
683 break; 685 break;
684 case (PWMPI): 686 case (PWMPI):
685 preCommand = prof->getPreSyncCommandPWM(); 687 preCommand = prof->getPreSyncCommandPWM();
686 postCommand = prof->getPostSyncCommandPWM(); 688 postCommand = prof->getPostSyncCommandPWM();
687 localTempFile = prof->getLocalTempFilePWM(); 689 localTempFile = prof->getLocalTempFilePWM();
688 break; 690 break;
689 default: 691 default:
690 qDebug("KSyncManager::syncRemote: invalid apptype selected"); 692 qDebug("KSyncManager::syncRemote: invalid apptype selected");
691 break; 693 break;
692 } 694 }
693 695
694 696
695 int fi; 697 int fi;
696 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 698 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
697 QString pwd = getPassword(); 699 QString pwd = getPassword();
698 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 700 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
699 701
700 } 702 }
701 int maxlen = 30; 703 int maxlen = 30;
702 if ( QApplication::desktop()->width() > 320 ) 704 if ( QApplication::desktop()->width() > 320 )
703 maxlen += 25; 705 maxlen += 25;
704 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); 706 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) );
705 int fileSize = 0; 707 int fileSize = 0;
706 int result = system ( preCommand ); 708 int result = system ( preCommand );
707 // 0 : okay 709 // 0 : okay
708 // 256: no such file or dir 710 // 256: no such file or dir
709 // 711 //
710 qDebug("Sync: Remote copy result(0 = okay): %d ",result ); 712 qDebug("Sync: Remote copy result(0 = okay): %d ",result );
711 if ( result != 0 ) { 713 if ( result != 0 ) {
712 unsigned int len = maxlen; 714 unsigned int len = maxlen;
713 while ( len < preCommand.length() ) { 715 while ( len < preCommand.length() ) {
714 preCommand.insert( len , "\n" ); 716 preCommand.insert( len , "\n" );
715 len += maxlen +2; 717 len += maxlen +2;
716 } 718 }
717 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 (preCommand) ; 719 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 (preCommand) ;
718 QMessageBox::information( mParent, i18n("Sync - ERROR"), 720 QMessageBox::information( mParent, i18n("Sync - ERROR"),
719 question, 721 question,
720 i18n("Okay!")) ; 722 i18n("Okay!")) ;
721 mParent->topLevelWidget()->setCaption ("KDE-Pim"); 723 mParent->topLevelWidget()->setCaption ("KDE-Pim");
722 return; 724 return;
723 } 725 }
724 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 726 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
725 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 727 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
726 728
727 if ( syncWithFile( localTempFile, true ) ) { 729 if ( syncWithFile( localTempFile, true ) ) {
728 730
729 if ( mWriteBackFile ) { 731 if ( mWriteBackFile ) {
730 int fi; 732 int fi;
731 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 733 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
732 QString pwd = getPassword(); 734 QString pwd = getPassword();
733 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 735 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
734 736
735 } 737 }
736 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 738 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
737 result = system ( postCommand ); 739 result = system ( postCommand );
738 qDebug("Sync:Writing back file result: %d ", result); 740 qDebug("Sync:Writing back file result: %d ", result);
739 if ( result != 0 ) { 741 if ( result != 0 ) {
740 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 742 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
741 return; 743 return;
742 } else { 744 } else {
743 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 745 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
744 } 746 }
745 } 747 }
746 } 748 }
747 return; 749 return;
748} 750}
749bool KSyncManager::edit_pisync_options() 751bool KSyncManager::edit_pisync_options()
750{ 752{
751 QDialog dia( mParent, "dia", true ); 753 QDialog dia( mParent, "dia", true );
752 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); 754 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
753 QVBoxLayout lay ( &dia ); 755 QVBoxLayout lay ( &dia );
754 lay.setSpacing( 5 ); 756 lay.setSpacing( 5 );
755 lay.setMargin( 3 ); 757 lay.setMargin( 3 );
756 QLabel lab1 ( i18n("Password for remote access:"), &dia); 758 QLabel lab1 ( i18n("Password for remote access:"), &dia);
757 lay.addWidget( &lab1 ); 759 lay.addWidget( &lab1 );
758 QLineEdit le1 (&dia ); 760 QLineEdit le1 (&dia );
759 lay.addWidget( &le1 ); 761 lay.addWidget( &le1 );
760 QLabel lab2 ( i18n("Remote IP address:"), &dia); 762 QLabel lab2 ( i18n("Remote IP address:"), &dia);
761 lay.addWidget( &lab2 ); 763 lay.addWidget( &lab2 );
762 QLineEdit le2 (&dia ); 764 QLineEdit le2 (&dia );
763 lay.addWidget( &le2 ); 765 lay.addWidget( &le2 );
764 QLabel lab3 ( i18n("Remote port number:"), &dia); 766 QLabel lab3 ( i18n("Remote port number:"), &dia);
765 lay.addWidget( &lab3 ); 767 lay.addWidget( &lab3 );
766 QLineEdit le3 (&dia ); 768 QLineEdit le3 (&dia );
767 lay.addWidget( &le3 ); 769 lay.addWidget( &le3 );
768 QPushButton pb ( "OK", &dia); 770 QPushButton pb ( "OK", &dia);
769 lay.addWidget( &pb ); 771 lay.addWidget( &pb );
770 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 772 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
771 le1.setText( mPassWordPiSync ); 773 le1.setText( mPassWordPiSync );
772 le2.setText( mActiveSyncIP ); 774 le2.setText( mActiveSyncIP );
773 le3.setText( mActiveSyncPort ); 775 le3.setText( mActiveSyncPort );
774 if ( dia.exec() ) { 776 if ( dia.exec() ) {
775 mPassWordPiSync = le1.text(); 777 mPassWordPiSync = le1.text();
776 mActiveSyncPort = le3.text(); 778 mActiveSyncPort = le3.text();
777 mActiveSyncIP = le2.text(); 779 mActiveSyncIP = le2.text();
778 return true; 780 return true;
779 } 781 }
780 return false; 782 return false;
781} 783}
782bool KSyncManager::edit_sync_options() 784bool KSyncManager::edit_sync_options()
783{ 785{
784 786
785 QDialog dia( mParent, "dia", true ); 787 QDialog dia( mParent, "dia", true );
786 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 788 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
787 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 789 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
788 QVBoxLayout lay ( &dia ); 790 QVBoxLayout lay ( &dia );
789 lay.setSpacing( 2 ); 791 lay.setSpacing( 2 );
790 lay.setMargin( 3 ); 792 lay.setMargin( 3 );
791 lay.addWidget(&gr); 793 lay.addWidget(&gr);
792 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 794 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
793 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 795 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
794 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 796 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
795 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 797 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
796 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 798 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
797 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 799 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
798 //QRadioButton both( i18n("Take both on conflict"), &gr ); 800 //QRadioButton both( i18n("Take both on conflict"), &gr );
799 QPushButton pb ( "OK", &dia); 801 QPushButton pb ( "OK", &dia);
800 lay.addWidget( &pb ); 802 lay.addWidget( &pb );
801 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 803 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
802 switch ( mSyncAlgoPrefs ) { 804 switch ( mSyncAlgoPrefs ) {
803 case 0: 805 case 0:
804 loc.setChecked( true); 806 loc.setChecked( true);
805 break; 807 break;
806 case 1: 808 case 1:
807 rem.setChecked( true ); 809 rem.setChecked( true );
808 break; 810 break;
809 case 2: 811 case 2:
810 newest.setChecked( true); 812 newest.setChecked( true);
811 break; 813 break;
812 case 3: 814 case 3:
813 ask.setChecked( true); 815 ask.setChecked( true);
814 break; 816 break;
815 case 4: 817 case 4:
816 f_loc.setChecked( true); 818 f_loc.setChecked( true);
817 break; 819 break;
818 case 5: 820 case 5:
819 f_rem.setChecked( true); 821 f_rem.setChecked( true);
820 break; 822 break;
821 case 6: 823 case 6:
822 // both.setChecked( true); 824 // both.setChecked( true);
823 break; 825 break;
824 default: 826 default:
825 break; 827 break;
826 } 828 }
827 if ( dia.exec() ) { 829 if ( dia.exec() ) {
828 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 830 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
829 return true; 831 return true;
830 } 832 }
831 return false; 833 return false;
832} 834}
833 835
834QString KSyncManager::getPassword( ) 836QString KSyncManager::getPassword( )
835{ 837{
836 QString retfile = ""; 838 QString retfile = "";
837 QDialog dia ( mParent, "input-dialog", true ); 839 QDialog dia ( mParent, "input-dialog", true );
838 QLineEdit lab ( &dia ); 840 QLineEdit lab ( &dia );
839 lab.setEchoMode( QLineEdit::Password ); 841 lab.setEchoMode( QLineEdit::Password );
840 QVBoxLayout lay( &dia ); 842 QVBoxLayout lay( &dia );
841 lay.setMargin(7); 843 lay.setMargin(7);
842 lay.setSpacing(7); 844 lay.setSpacing(7);
843 lay.addWidget( &lab); 845 lay.addWidget( &lab);
844 dia.setFixedSize( 230,50 ); 846 dia.setFixedSize( 230,50 );
845 dia.setCaption( i18n("Enter password") ); 847 dia.setCaption( i18n("Enter password") );
846 QPushButton pb ( "OK", &dia); 848 QPushButton pb ( "OK", &dia);
847 lay.addWidget( &pb ); 849 lay.addWidget( &pb );
848 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 850 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
849 dia.show(); 851 dia.show();
850 int res = dia.exec(); 852 int res = dia.exec();
851 if ( res ) 853 if ( res )
852 retfile = lab.text(); 854 retfile = lab.text();
853 dia.hide(); 855 dia.hide();
854 qApp->processEvents(); 856 qApp->processEvents();
855 return retfile; 857 return retfile;
856 858
857} 859}
858 860
859 861
860void KSyncManager::confSync() 862void KSyncManager::confSync()
861{ 863{
862 static KSyncPrefsDialog* sp = 0; 864 static KSyncPrefsDialog* sp = 0;
863 if ( ! sp ) { 865 if ( ! sp ) {
864 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 866 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
865 } 867 }
866 sp->usrReadConfig(); 868 sp->usrReadConfig();
867#ifndef DESKTOP_VERSION 869#ifndef DESKTOP_VERSION
868 sp->showMaximized(); 870 sp->showMaximized();
869#else 871#else
870 sp->show(); 872 sp->show();
871#endif 873#endif
872 sp->exec(); 874 sp->exec();
873 QStringList oldSyncProfileNames = mSyncProfileNames; 875 QStringList oldSyncProfileNames = mSyncProfileNames;
874 mSyncProfileNames = sp->getSyncProfileNames(); 876 mSyncProfileNames = sp->getSyncProfileNames();
875 mLocalMachineName = sp->getLocalMachineName (); 877 mLocalMachineName = sp->getLocalMachineName ();
876 int ii; 878 int ii;
877 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { 879 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) {
878 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) 880 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) )
879 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); 881 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] );
880 } 882 }
881 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 883 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
882} 884}
883void KSyncManager::syncKDE() 885void KSyncManager::syncKDE()
884{ 886{
887 mSyncWithDesktop = true;
885 emit save(); 888 emit save();
886 switch(mTargetApp) 889 switch(mTargetApp)
887 { 890 {
888 case (KAPI): 891 case (KAPI):
889 892 {
893#ifdef DESKTOP_VERSION
894 QString command = qApp->applicationDirPath () + "/kdeabdump";
895#else
896 QString command = "kdeabdump";
897#endif
898 if ( ! QFile::exists ( command ) )
899 command = "kdeabdump";
900 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf";
901 system ( command.latin1());
902 if ( syncWithFile( fileName,true ) ) {
903 if ( mWriteBackFile ) {
904 command += " --read";
905 system ( command.latin1());
906 }
907 }
908
909 }
890 break; 910 break;
891 case (KOPI): 911 case (KOPI):
892 { 912 {
893#ifdef DESKTOP_VERSION 913#ifdef DESKTOP_VERSION
894 QString command = qApp->applicationDirPath () + "/kdecaldump"; 914 QString command = qApp->applicationDirPath () + "/kdecaldump";
895#else 915#else
896 QString command = "kdecaldump"; 916 QString command = "kdecaldump";
897#endif 917#endif
898 if ( ! QFile::exists ( command ) ) 918 if ( ! QFile::exists ( command ) )
899 command = "kdecaldump"; 919 command = "kdecaldump";
900 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 920 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
901 system ( command.latin1()); 921 system ( command.latin1());
902 if ( syncWithFile( fileName,true ) ) { 922 if ( syncWithFile( fileName,true ) ) {
903 if ( mWriteBackFile ) { 923 if ( mWriteBackFile ) {
904 command += " --read"; 924 command += " --read";
905 system ( command.latin1()); 925 system ( command.latin1());
906 } 926 }
907 } 927 }
908 928
909 } 929 }
910 break; 930 break;
911 case (PWMPI): 931 case (PWMPI):
912 932
913 break; 933 break;
914 default: 934 default:
915 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 935 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
916 break; 936 break;
917 937
918 } 938 }
919} 939}
920 940
921void KSyncManager::syncSharp() 941void KSyncManager::syncSharp()
922{ 942{
923 943
924 if ( ! syncExternalApplication("sharp") ) 944 if ( ! syncExternalApplication("sharp") )
925 qDebug("ERROR sync sharp "); 945 qDebug("ERROR sync sharp ");
926} 946}
927 947
928bool KSyncManager::syncExternalApplication(QString resource) 948bool KSyncManager::syncExternalApplication(QString resource)
929{ 949{
930 950
931 emit save(); 951 emit save();
932 952
933 if ( mAskForPreferences ) 953 if ( mAskForPreferences )
934 if ( !edit_sync_options()) { 954 if ( !edit_sync_options()) {
935 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 955 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
936 return false; 956 return false;
937 } 957 }
938 958
939 qDebug("Sync extern %s", resource.latin1()); 959 qDebug("Sync extern %s", resource.latin1());
940 960
941 bool syncOK = mImplementation->syncExternal(this, resource); 961 bool syncOK = mImplementation->syncExternal(this, resource);
942 962
943 return syncOK; 963 return syncOK;
944 964
945} 965}
946 966
947void KSyncManager::syncPhone() 967void KSyncManager::syncPhone()
948{ 968{
949 969
950 syncExternalApplication("phone"); 970 syncExternalApplication("phone");
951 971
952} 972}
953 973
954void KSyncManager::showProgressBar(int percentage, QString caption, int total) 974void KSyncManager::showProgressBar(int percentage, QString caption, int total)
955{ 975{
956 if (!bar->isVisible()) 976 if (!bar->isVisible())
957 { 977 {
958 bar->setCaption (caption); 978 bar->setCaption (caption);
959 bar->setTotalSteps ( total ) ; 979 bar->setTotalSteps ( total ) ;
960 980
961 bar->show(); 981 bar->show();
962 } 982 }
963 983
964 bar->setProgress( percentage ); 984 bar->setProgress( percentage );
965} 985}
966 986
967void KSyncManager::hideProgressBar() 987void KSyncManager::hideProgressBar()
968{ 988{
969 bar->hide(); 989 bar->hide();
970} 990}
971 991
972bool KSyncManager::isProgressBarCanceled() 992bool KSyncManager::isProgressBarCanceled()
973{ 993{
974 return !bar->isVisible(); 994 return !bar->isVisible();
975} 995}
976 996
977QString KSyncManager::syncFileName() 997QString KSyncManager::syncFileName()
978{ 998{
979 999
980 QString fn = "tempfile"; 1000 QString fn = "tempfile";
981 switch(mTargetApp) 1001 switch(mTargetApp)
982 { 1002 {
983 case (KAPI): 1003 case (KAPI):
984 fn = "tempsyncab.vcf"; 1004 fn = "tempsyncab.vcf";
985 break; 1005 break;
986 case (KOPI): 1006 case (KOPI):
987 fn = "tempsynccal.ics"; 1007 fn = "tempsynccal.ics";
988 break; 1008 break;
989 case (PWMPI): 1009 case (PWMPI):
990 fn = "tempsyncpw.pwm"; 1010 fn = "tempsyncpw.pwm";
991 break; 1011 break;
992 default: 1012 default:
993 break; 1013 break;
994 } 1014 }
995#ifdef _WIN32_ 1015#ifdef _WIN32_
996 return locateLocal( "tmp", fn ); 1016 return locateLocal( "tmp", fn );
997#else 1017#else
998 return (QString( "/tmp/" )+ fn ); 1018 return (QString( "/tmp/" )+ fn );
999#endif 1019#endif
1000} 1020}
1001 1021
1002void KSyncManager::syncPi() 1022void KSyncManager::syncPi()
1003{ 1023{
1004 mPisyncFinished = false; 1024 mPisyncFinished = false;
1005 qApp->processEvents(); 1025 qApp->processEvents();
1006 if ( mAskForPreferences ) 1026 if ( mAskForPreferences )
1007 if ( !edit_pisync_options()) { 1027 if ( !edit_pisync_options()) {
1008 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1028 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1009 return; 1029 return;
1010 } 1030 }
1011 bool ok; 1031 bool ok;
1012 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1032 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1013 if ( ! ok ) { 1033 if ( ! ok ) {
1014 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1034 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1015 return; 1035 return;
1016 } 1036 }
1017 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 1037 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
1018 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1038 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1019 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 1039 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
1020 commandSocket->readFile( syncFileName() ); 1040 commandSocket->readFile( syncFileName() );
1021} 1041}
1022 1042
1023void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1043void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1024{ 1044{
1025 //enum { success, errorW, errorR, quiet }; 1045 //enum { success, errorW, errorR, quiet };
1026 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 1046 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
1027 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1047 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1028 delete s; 1048 delete s;
1029 if ( state == KCommandSocket::errorR ) { 1049 if ( state == KCommandSocket::errorR ) {
1030 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1050 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1031 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1051 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1032 commandSocket->sendStop(); 1052 commandSocket->sendStop();
1033 } 1053 }
1034 mPisyncFinished = true; 1054 mPisyncFinished = true;
1035 return; 1055 return;
1036 1056
1037 } else if ( state == KCommandSocket::errorW ) { 1057 } else if ( state == KCommandSocket::errorW ) {
1038 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1058 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1039 mPisyncFinished = true; 1059 mPisyncFinished = true;
1040 1060
1041 } else if ( state == KCommandSocket::successR ) { 1061 } else if ( state == KCommandSocket::successR ) {
1042 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1062 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1043 1063
1044 } else if ( state == KCommandSocket::successW ) { 1064 } else if ( state == KCommandSocket::successW ) {
1045 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1065 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1046 mPisyncFinished = true; 1066 mPisyncFinished = true;
1047 } 1067 }
1048 1068
1049 delete s; 1069 delete s;
1050} 1070}
1051 1071
1052void KSyncManager::readFileFromSocket() 1072void KSyncManager::readFileFromSocket()
1053{ 1073{
1054 QString fileName = syncFileName(); 1074 QString fileName = syncFileName();
1055 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1075 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1056 if ( ! syncWithFile( fileName , true ) ) { 1076 if ( ! syncWithFile( fileName , true ) ) {
1057 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1077 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1058 mPisyncFinished = true; 1078 mPisyncFinished = true;
1059 return; 1079 return;
1060 } 1080 }
1061 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1081 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1062 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1082 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1063 if ( mWriteBackFile ) 1083 if ( mWriteBackFile )
1064 commandSocket->writeFile( fileName ); 1084 commandSocket->writeFile( fileName );
1065 else { 1085 else {
1066 commandSocket->sendStop(); 1086 commandSocket->sendStop();
1067 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1087 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1068 mPisyncFinished = true; 1088 mPisyncFinished = true;
1069 } 1089 }
1070} 1090}
1071 1091
1072KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1092KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1073{ 1093{
1074 mPassWord = pw; 1094 mPassWord = pw;
1075 mSocket = 0; 1095 mSocket = 0;
1076 mSyncActionDialog = 0; 1096 mSyncActionDialog = 0;
1077 blockRC = false; 1097 blockRC = false;
1078}; 1098};
1079 1099
1080void KServerSocket::newConnection ( int socket ) 1100void KServerSocket::newConnection ( int socket )
1081{ 1101{
1082 // qDebug("KServerSocket:New connection %d ", socket); 1102 // qDebug("KServerSocket:New connection %d ", socket);
1083 if ( mSocket ) { 1103 if ( mSocket ) {
1084 qDebug("KServerSocket::newConnection Socket deleted! "); 1104 qDebug("KServerSocket::newConnection Socket deleted! ");
1085 delete mSocket; 1105 delete mSocket;
1086 mSocket = 0; 1106 mSocket = 0;
1087 } 1107 }
1088 mSocket = new QSocket( this ); 1108 mSocket = new QSocket( this );
1089 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1109 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1090 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1110 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1091 mSocket->setSocket( socket ); 1111 mSocket->setSocket( socket );
1092} 1112}
1093 1113
1094void KServerSocket::discardClient() 1114void KServerSocket::discardClient()
1095{ 1115{
1096 //qDebug(" KServerSocket::discardClient()"); 1116 //qDebug(" KServerSocket::discardClient()");
1097 if ( mSocket ) { 1117 if ( mSocket ) {
1098 delete mSocket; 1118 delete mSocket;
1099 mSocket = 0; 1119 mSocket = 0;
1100 } 1120 }
1101 //emit endConnect(); 1121 //emit endConnect();
1102} 1122}
1103void KServerSocket::readClient() 1123void KServerSocket::readClient()
1104{ 1124{
1105 if ( blockRC ) 1125 if ( blockRC )
1106 return; 1126 return;
1107 if ( mSocket == 0 ) { 1127 if ( mSocket == 0 ) {
1108 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 1128 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
1109 return; 1129 return;
1110 } 1130 }
1111 //qDebug("KServerSocket::readClient()"); 1131 //qDebug("KServerSocket::readClient()");
1112 if ( mSocket->canReadLine() ) { 1132 if ( mSocket->canReadLine() ) {
1113 QString line = mSocket->readLine(); 1133 QString line = mSocket->readLine();
1114 //qDebug("KServerSocket readline: %s ", line.latin1()); 1134 //qDebug("KServerSocket readline: %s ", line.latin1());
1115 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1135 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1116 if ( tokens[0] == "GET" ) { 1136 if ( tokens[0] == "GET" ) {
1117 if ( tokens[1] == mPassWord ) { 1137 if ( tokens[1] == mPassWord ) {
1118 //emit sendFile( mSocket ); 1138 //emit sendFile( mSocket );
1119 bool ok = false; 1139 bool ok = false;
1120 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); 1140 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1121 if ( ok ) 1141 if ( ok )
1122 KSyncManager::mRequestedSyncEvent = dt; 1142 KSyncManager::mRequestedSyncEvent = dt;
1123 else 1143 else
1124 KSyncManager::mRequestedSyncEvent = QDateTime(); 1144 KSyncManager::mRequestedSyncEvent = QDateTime();
1125 send_file(); 1145 send_file();
1126 } 1146 }
1127 else { 1147 else {
1128 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); 1148 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"));
1129 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1149 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1130 } 1150 }
1131 } 1151 }
1132 if ( tokens[0] == "PUT" ) { 1152 if ( tokens[0] == "PUT" ) {
1133 if ( tokens[1] == mPassWord ) { 1153 if ( tokens[1] == mPassWord ) {
1134 //emit getFile( mSocket ); 1154 //emit getFile( mSocket );
1135 blockRC = true; 1155 blockRC = true;
1136 get_file(); 1156 get_file();
1137 } 1157 }
1138 else { 1158 else {
1139 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); 1159 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"));
1140 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1160 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1141 } 1161 }
1142 } 1162 }
1143 if ( tokens[0] == "STOP" ) { 1163 if ( tokens[0] == "STOP" ) {
1144 //emit endConnect(); 1164 //emit endConnect();
1145 end_connect(); 1165 end_connect();
1146 } 1166 }
1147 } 1167 }
1148} 1168}
1149void KServerSocket::end_connect() 1169void KServerSocket::end_connect()
1150{ 1170{
1151 delete mSyncActionDialog; 1171 delete mSyncActionDialog;
1152 mSyncActionDialog = 0; 1172 mSyncActionDialog = 0;
1153} 1173}
1154void KServerSocket::send_file() 1174void KServerSocket::send_file()
1155{ 1175{
1156 //qDebug("MainWindow::sendFile(QSocket* s) "); 1176 //qDebug("MainWindow::sendFile(QSocket* s) ");
1157 if ( mSyncActionDialog ) 1177 if ( mSyncActionDialog )
1158 delete mSyncActionDialog; 1178 delete mSyncActionDialog;
1159 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1179 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1160 mSyncActionDialog->setCaption(i18n("Received sync request")); 1180 mSyncActionDialog->setCaption(i18n("Received sync request"));
1161 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1181 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1162 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1182 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1163 lay->addWidget( label); 1183 lay->addWidget( label);
1164 lay->setMargin(7); 1184 lay->setMargin(7);
1165 lay->setSpacing(7); 1185 lay->setSpacing(7);
1166 mSyncActionDialog->setFixedSize( 230, 120); 1186 mSyncActionDialog->setFixedSize( 230, 120);
1167 mSyncActionDialog->show(); 1187 mSyncActionDialog->show();
1168 mSyncActionDialog->raise(); 1188 mSyncActionDialog->raise();
1169 emit request_file(); 1189 emit request_file();
1170 qApp->processEvents(); 1190 qApp->processEvents();
1171 QString fileName = mFileName; 1191 QString fileName = mFileName;
1172 QFile file( fileName ); 1192 QFile file( fileName );
1173 if (!file.open( IO_ReadOnly ) ) { 1193 if (!file.open( IO_ReadOnly ) ) {
1174 delete mSyncActionDialog; 1194 delete mSyncActionDialog;
1175 mSyncActionDialog = 0; 1195 mSyncActionDialog = 0;
1176 qDebug("KSS::error open file "); 1196 qDebug("KSS::error open file ");
1177 mSocket->close(); 1197 mSocket->close();
1178 if ( mSocket->state() == QSocket::Idle ) 1198 if ( mSocket->state() == QSocket::Idle )
1179 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1199 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1180 return ; 1200 return ;
1181 1201
1182 } 1202 }
1183 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1203 mSyncActionDialog->setCaption( i18n("Sending file...") );
1184 QTextStream ts( &file ); 1204 QTextStream ts( &file );
1185 ts.setEncoding( QTextStream::Latin1 ); 1205 ts.setEncoding( QTextStream::Latin1 );
1186 1206
1187 QTextStream os( mSocket ); 1207 QTextStream os( mSocket );
1188 os.setEncoding( QTextStream::Latin1 ); 1208 os.setEncoding( QTextStream::Latin1 );
1189 while ( ! ts.atEnd() ) { 1209 while ( ! ts.atEnd() ) {
1190 os << ts.readLine() << "\r\n"; 1210 os << ts.readLine() << "\r\n";
1191 } 1211 }
1192 //os << ts.read(); 1212 //os << ts.read();
1193 file.close(); 1213 file.close();
1194 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1214 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1195 mSocket->close(); 1215 mSocket->close();
1196 if ( mSocket->state() == QSocket::Idle ) 1216 if ( mSocket->state() == QSocket::Idle )
1197 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1217 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1198} 1218}
1199void KServerSocket::get_file() 1219void KServerSocket::get_file()
1200{ 1220{
1201 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1221 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1202 1222
1203 piTime.start(); 1223 piTime.start();
1204 piFileString = ""; 1224 piFileString = "";
1205 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1225 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1206} 1226}
1207 1227
1208 1228
1209void KServerSocket::readBackFileFromSocket() 1229void KServerSocket::readBackFileFromSocket()
1210{ 1230{
1211 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1231 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1212 while ( mSocket->canReadLine () ) { 1232 while ( mSocket->canReadLine () ) {
1213 piTime.restart(); 1233 piTime.restart();
1214 QString line = mSocket->readLine (); 1234 QString line = mSocket->readLine ();
1215 piFileString += line; 1235 piFileString += line;
1216 //qDebug("readline: %s ", line.latin1()); 1236 //qDebug("readline: %s ", line.latin1());
1217 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1237 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1218 1238
1219 } 1239 }
1220 if ( piTime.elapsed () < 3000 ) { 1240 if ( piTime.elapsed () < 3000 ) {
1221 // wait for more 1241 // wait for more
1222 //qDebug("waitformore "); 1242 //qDebug("waitformore ");
1223 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1243 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1224 return; 1244 return;
1225 } 1245 }
1226 QString fileName = mFileName; 1246 QString fileName = mFileName;
1227 QFile file ( fileName ); 1247 QFile file ( fileName );
1228 if (!file.open( IO_WriteOnly ) ) { 1248 if (!file.open( IO_WriteOnly ) ) {
1229 delete mSyncActionDialog; 1249 delete mSyncActionDialog;
1230 mSyncActionDialog = 0; 1250 mSyncActionDialog = 0;
1231 qDebug("KSS:Error open read back file "); 1251 qDebug("KSS:Error open read back file ");
1232 piFileString = ""; 1252 piFileString = "";
1233 emit file_received( false ); 1253 emit file_received( false );
1234 blockRC = false; 1254 blockRC = false;
1235 return ; 1255 return ;
1236 1256
1237 } 1257 }
1238 1258
1239 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1259 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1240 QTextStream ts ( &file ); 1260 QTextStream ts ( &file );
1241 ts.setEncoding( QTextStream::Latin1 ); 1261 ts.setEncoding( QTextStream::Latin1 );
1242 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1262 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1243 ts << piFileString; 1263 ts << piFileString;
1244 mSocket->close(); 1264 mSocket->close();
1245 if ( mSocket->state() == QSocket::Idle ) 1265 if ( mSocket->state() == QSocket::Idle )
1246 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1266 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1247 file.close(); 1267 file.close();
1248 piFileString = ""; 1268 piFileString = "";
1249 emit file_received( true ); 1269 emit file_received( true );
1250 delete mSyncActionDialog; 1270 delete mSyncActionDialog;
1251 mSyncActionDialog = 0; 1271 mSyncActionDialog = 0;
1252 blockRC = false; 1272 blockRC = false;
1253 1273
1254} 1274}
1255 1275
1256KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1276KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1257{ 1277{
1258 mPassWord = password; 1278 mPassWord = password;
1259 mSocket = 0; 1279 mSocket = 0;
1260 mPort = port; 1280 mPort = port;
1261 mHost = host; 1281 mHost = host;
1262 1282
1263 mRetVal = quiet; 1283 mRetVal = quiet;
1264 mTimerSocket = new QTimer ( this ); 1284 mTimerSocket = new QTimer ( this );
1265 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1285 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1266} 1286}
1267void KCommandSocket::readFile( QString fn ) 1287void KCommandSocket::readFile( QString fn )
1268{ 1288{
1269 if ( !mSocket ) { 1289 if ( !mSocket ) {
1270 mSocket = new QSocket( this ); 1290 mSocket = new QSocket( this );
1271 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1291 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1272 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1292 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1273 } 1293 }
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index 2af891b..6da0ee4 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -1,214 +1,216 @@
1/* 1/*
2 This file is part of KDE-Pim/Pi. 2 This file is part of KDE-Pim/Pi.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
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 $Id$ 20 $Id$
21*/ 21*/
22#ifndef _KSYNCMANAGER_H 22#ifndef _KSYNCMANAGER_H
23#define _KSYNCMANAGER_H 23#define _KSYNCMANAGER_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qsocket.h> 27#include <qsocket.h>
28#include <qdatetime.h> 28#include <qdatetime.h>
29#include <qserversocket.h> 29#include <qserversocket.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qregexp.h> 31#include <qregexp.h>
32 32
33class QPopupMenu; 33class QPopupMenu;
34class KSyncProfile; 34class KSyncProfile;
35class KPimPrefs; 35class KPimPrefs;
36class QWidget; 36class QWidget;
37class KSyncManager; 37class KSyncManager;
38class KSyncInterface; 38class KSyncInterface;
39class QProgressBar; 39class QProgressBar;
40 40
41 41
42class KServerSocket : public QServerSocket 42class KServerSocket : public QServerSocket
43{ 43{
44 Q_OBJECT 44 Q_OBJECT
45 45
46 public: 46 public:
47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); 47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
48 48
49 void newConnection ( int socket ) ; 49 void newConnection ( int socket ) ;
50 void setFileName( QString fn ) {mFileName = fn;}; 50 void setFileName( QString fn ) {mFileName = fn;};
51 signals: 51 signals:
52 void file_received( bool ); 52 void file_received( bool );
53 void request_file(); 53 void request_file();
54 void saveFile(); 54 void saveFile();
55 void endConnect(); 55 void endConnect();
56 private slots: 56 private slots:
57 void discardClient(); 57 void discardClient();
58 void readClient(); 58 void readClient();
59 void readBackFileFromSocket(); 59 void readBackFileFromSocket();
60 private : 60 private :
61 bool blockRC; 61 bool blockRC;
62 void send_file(); 62 void send_file();
63 void get_file(); 63 void get_file();
64 void end_connect(); 64 void end_connect();
65 QDialog* mSyncActionDialog; 65 QDialog* mSyncActionDialog;
66 QSocket* mSocket; 66 QSocket* mSocket;
67 QString mPassWord; 67 QString mPassWord;
68 QString mFileName; 68 QString mFileName;
69 QTime piTime; 69 QTime piTime;
70 QString piFileString; 70 QString piFileString;
71}; 71};
72 72
73class KCommandSocket : public QObject 73class KCommandSocket : public QObject
74{ 74{
75 Q_OBJECT 75 Q_OBJECT
76 public: 76 public:
77 enum state { successR, errorR, successW, errorW, errorTO, quiet }; 77 enum state { successR, errorR, successW, errorW, errorTO, quiet };
78 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); 78 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
79 void readFile( QString ); 79 void readFile( QString );
80 void writeFile( QString ); 80 void writeFile( QString );
81 void sendStop(); 81 void sendStop();
82 82
83 signals: 83 signals:
84 void commandFinished( KCommandSocket*, int ); 84 void commandFinished( KCommandSocket*, int );
85 private slots: 85 private slots:
86 void startReadFileFromSocket(); 86 void startReadFileFromSocket();
87 void readFileFromSocket(); 87 void readFileFromSocket();
88 void deleteSocket(); 88 void deleteSocket();
89 void writeFileToSocket(); 89 void writeFileToSocket();
90 private : 90 private :
91 QSocket* mSocket; 91 QSocket* mSocket;
92 QString mPassWord; 92 QString mPassWord;
93 Q_UINT16 mPort; 93 Q_UINT16 mPort;
94 QString mHost; 94 QString mHost;
95 QString mFileName; 95 QString mFileName;
96 QTimer* mTimerSocket; 96 QTimer* mTimerSocket;
97 int mRetVal; 97 int mRetVal;
98 QTime mTime; 98 QTime mTime;
99 QString mFileString; 99 QString mFileString;
100 bool mFirst; 100 bool mFirst;
101}; 101};
102 102
103 103
104class KSyncManager : public QObject 104class KSyncManager : public QObject
105{ 105{
106 Q_OBJECT 106 Q_OBJECT
107 107
108 public: 108 public:
109 enum TargetApp { 109 enum TargetApp {
110 KOPI = 0, 110 KOPI = 0,
111 KAPI = 1, 111 KAPI = 1,
112 PWMPI = 2 }; 112 PWMPI = 2 };
113 113
114 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); 114 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu);
115 ~KSyncManager() ; 115 ~KSyncManager() ;
116 116
117 void multiSync( bool askforPrefs ); 117 void multiSync( bool askforPrefs );
118 bool blockSave() { return mBlockSaveFlag; } 118 bool blockSave() { return mBlockSaveFlag; }
119 void setBlockSave(bool sa) { mBlockSaveFlag = sa; } 119 void setBlockSave(bool sa) { mBlockSaveFlag = sa; }
120 void setDefaultFileName( QString s) { mDefFileName = s ;} 120 void setDefaultFileName( QString s) { mDefFileName = s ;}
121 QString defaultFileName() { return mDefFileName ;} 121 QString defaultFileName() { return mDefFileName ;}
122 QString syncFileName(); 122 QString syncFileName();
123 void enableQuick( bool ask = true); 123 void enableQuick( bool ask = true);
124 124
125 bool syncWithDesktop () { return mSyncWithDesktop;}
125 QString getCurrentSyncDevice() { return mCurrentSyncDevice; } 126 QString getCurrentSyncDevice() { return mCurrentSyncDevice; }
126 QString getCurrentSyncName() { return mCurrentSyncName; } 127 QString getCurrentSyncName() { return mCurrentSyncName; }
127 128
128 void showProgressBar(int percentage, QString caption = QString::null, int total=100); 129 void showProgressBar(int percentage, QString caption = QString::null, int total=100);
129 void hideProgressBar(); 130 void hideProgressBar();
130 bool isProgressBarCanceled(); 131 bool isProgressBarCanceled();
131 132
132 // sync stuff 133 // sync stuff
133 QString mLocalMachineName; 134 QString mLocalMachineName;
134 QStringList mExternSyncProfiles; 135 QStringList mExternSyncProfiles;
135 QStringList mSyncProfileNames; 136 QStringList mSyncProfileNames;
136 bool mAskForPreferences; 137 bool mAskForPreferences;
137 bool mShowSyncSummary; 138 bool mShowSyncSummary;
138 bool mIsKapiFile; 139 bool mIsKapiFile;
139 bool mWriteBackExistingOnly; 140 bool mWriteBackExistingOnly;
140 int mSyncAlgoPrefs; 141 int mSyncAlgoPrefs;
141 bool mWriteBackFile; 142 bool mWriteBackFile;
142 int mWriteBackInFuture; 143 int mWriteBackInFuture;
143 QString mPhoneDevice; 144 QString mPhoneDevice;
144 QString mPhoneConnection; 145 QString mPhoneConnection;
145 QString mPhoneModel; 146 QString mPhoneModel;
146 QString mPassWordPiSync; 147 QString mPassWordPiSync;
147 QString mActiveSyncPort; 148 QString mActiveSyncPort;
148 QString mActiveSyncIP ; 149 QString mActiveSyncIP ;
149 static QDateTime mRequestedSyncEvent; 150 static QDateTime mRequestedSyncEvent;
150 151
151 signals: 152 signals:
152 void save(); 153 void save();
153 void request_file(); 154 void request_file();
154 void getFile( bool ); 155 void getFile( bool );
155 156
156 public slots: 157 public slots:
157 void slotSyncMenu( int ); 158 void slotSyncMenu( int );
158 void slotClearMenu( int action ); 159 void slotClearMenu( int action );
159 void deleteCommandSocket(KCommandSocket*s, int state); 160 void deleteCommandSocket(KCommandSocket*s, int state);
160 void readFileFromSocket(); 161 void readFileFromSocket();
161 void fillSyncMenu(); 162 void fillSyncMenu();
162 163
163 private: 164 private:
164 void syncPi(); 165 void syncPi();
165 KServerSocket * mServerSocket; 166 KServerSocket * mServerSocket;
166 KPimPrefs* mPrefs; 167 KPimPrefs* mPrefs;
167 QString mDefFileName; 168 QString mDefFileName;
168 QString mCurrentSyncDevice; 169 QString mCurrentSyncDevice;
169 QString mCurrentSyncName; 170 QString mCurrentSyncName;
170 void quickSyncLocalFile(); 171 void quickSyncLocalFile();
171 bool syncWithFile( QString fn , bool quick ); 172 bool syncWithFile( QString fn , bool quick );
172 void syncLocalFile(); 173 void syncLocalFile();
173 void syncPhone(); 174 void syncPhone();
174 void syncSharp(); 175 void syncSharp();
175 void syncKDE(); 176 void syncKDE();
176 bool syncExternalApplication(QString); 177 bool syncExternalApplication(QString);
177 int mCurrentSyncProfile ; 178 int mCurrentSyncProfile ;
178 void syncRemote( KSyncProfile* prof, bool ask = true); 179 void syncRemote( KSyncProfile* prof, bool ask = true);
179 bool edit_sync_options(); 180 bool edit_sync_options();
180 bool edit_pisync_options(); 181 bool edit_pisync_options();
181 int ringSync(); 182 int ringSync();
182 QString getPassword( ); 183 QString getPassword( );
183 bool mPisyncFinished; 184 bool mPisyncFinished;
184 bool mBlockSaveFlag; 185 bool mBlockSaveFlag;
185 QWidget* mParent; 186 QWidget* mParent;
186 KSyncInterface* mImplementation; 187 KSyncInterface* mImplementation;
187 TargetApp mTargetApp; 188 TargetApp mTargetApp;
188 QPopupMenu* mSyncMenu; 189 QPopupMenu* mSyncMenu;
189 QProgressBar* bar; 190 QProgressBar* bar;
191 bool mSyncWithDesktop;
190 192
191private slots: 193private slots:
192 void confSync(); 194 void confSync();
193 195
194 196
195}; 197};
196 198
197 199
198class KSyncInterface 200class KSyncInterface
199{ 201{
200 public : 202 public :
201 virtual void removeSyncInfo( QString syncProfile) = 0; 203 virtual void removeSyncInfo( QString syncProfile) = 0;
202 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; 204 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0;
203 virtual bool syncExternal(KSyncManager* manager, QString resource) 205 virtual bool syncExternal(KSyncManager* manager, QString resource)
204 { 206 {
205 // empty implementation, because some syncable applications do not 207 // empty implementation, because some syncable applications do not
206 // have an external(sharpdtm) syncmode, like pwmanager. 208 // have an external(sharpdtm) syncmode, like pwmanager.
207 return false; 209 return false;
208 } 210 }
209 211
210 212
211}; 213};
212 214
213 215
214#endif 216#endif