summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-27 12:27:39 (UTC)
committer zautrix <zautrix>2004-10-27 12:27:39 (UTC)
commit2f3396d84d2f3c92e1e0e420d677892c1f9c0778 (patch) (unidiff)
tree1ebab5dc6d00cb09720789897ce2c86df05cc9ab
parentf73d249579d52d7aeaacde2dcb23abeb42f9ee95 (diff)
downloadkdepimpi-2f3396d84d2f3c92e1e0e420d677892c1f9c0778.zip
kdepimpi-2f3396d84d2f3c92e1e0e420d677892c1f9c0778.tar.gz
kdepimpi-2f3396d84d2f3c92e1e0e420d677892c1f9c0778.tar.bz2
completed KDE AB sync. but will it work ...?
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
@@ -673,386 +673,389 @@ bool AddressBook::saveAB()
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 }
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 2f00a09..ea87929 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1123,388 +1123,390 @@ void KABCore::addEmail( QString aStr )
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." );
@@ -1855,384 +1857,387 @@ void KABCore::initActions()
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() ) {
@@ -2318,599 +2323,613 @@ void KABCore::requestForDetails(const QString& sourceChannel, const QString& ses
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
@@ -111,384 +111,389 @@ void ViewManager::restoreSettings()
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 ) {
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
@@ -738,641 +738,641 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
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
@@ -3556,225 +3556,222 @@ void CalendarView::toggleAllDaySize()
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
@@ -300,307 +300,306 @@ class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Obser
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,445 +1,447 @@
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
@@ -693,389 +695,407 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
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{
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