summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp71
1 files changed, 35 insertions, 36 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 02c5e45..685bb60 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -814,609 +814,608 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
814 case SYNC_PREF_NEWEST: 814 case SYNC_PREF_NEWEST:
815 if ( localMod > remoteMod ) 815 if ( localMod > remoteMod )
816 return 1; 816 return 1;
817 else 817 else
818 return 2; 818 return 2;
819 break; 819 break;
820 case SYNC_PREF_ASK: 820 case SYNC_PREF_ASK:
821 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 821 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
822 if ( lastSync > remoteMod ) 822 if ( lastSync > remoteMod )
823 return 1; 823 return 1;
824 if ( lastSync > localMod ) 824 if ( lastSync > localMod )
825 return 2; 825 return 2;
826 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 826 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
827 localIsNew = localMod >= remoteMod; 827 localIsNew = localMod >= remoteMod;
828 if ( localIsNew ) 828 if ( localIsNew )
829 getEventViewerDialog()->setColorMode( 1 ); 829 getEventViewerDialog()->setColorMode( 1 );
830 else 830 else
831 getEventViewerDialog()->setColorMode( 2 ); 831 getEventViewerDialog()->setColorMode( 2 );
832 getEventViewerDialog()->setIncidence(local); 832 getEventViewerDialog()->setIncidence(local);
833 if ( localIsNew ) 833 if ( localIsNew )
834 getEventViewerDialog()->setColorMode( 2 ); 834 getEventViewerDialog()->setColorMode( 2 );
835 else 835 else
836 getEventViewerDialog()->setColorMode( 1 ); 836 getEventViewerDialog()->setColorMode( 1 );
837 getEventViewerDialog()->addIncidence(remote); 837 getEventViewerDialog()->addIncidence(remote);
838 getEventViewerDialog()->setColorMode( 0 ); 838 getEventViewerDialog()->setColorMode( 0 );
839 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 839 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
840 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 840 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
841 getEventViewerDialog()->showMe(); 841 getEventViewerDialog()->showMe();
842 result = getEventViewerDialog()->executeS( localIsNew ); 842 result = getEventViewerDialog()->executeS( localIsNew );
843 return result; 843 return result;
844 844
845 break; 845 break;
846 case SYNC_PREF_FORCE_LOCAL: 846 case SYNC_PREF_FORCE_LOCAL:
847 return 1; 847 return 1;
848 break; 848 break;
849 case SYNC_PREF_FORCE_REMOTE: 849 case SYNC_PREF_FORCE_REMOTE:
850 return 2; 850 return 2;
851 break; 851 break;
852 852
853 default: 853 default:
854 // SYNC_PREF_TAKE_BOTH not implemented 854 // SYNC_PREF_TAKE_BOTH not implemented
855 break; 855 break;
856 } 856 }
857 return 0; 857 return 0;
858} 858}
859Event* CalendarView::getLastSyncEvent() 859Event* CalendarView::getLastSyncEvent()
860{ 860{
861 Event* lse; 861 Event* lse;
862 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 862 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
863 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 863 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
864 if (!lse) { 864 if (!lse) {
865 lse = new Event(); 865 lse = new Event();
866 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 866 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
867 QString sum = ""; 867 QString sum = "";
868 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 868 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
869 sum = "E: "; 869 sum = "E: ";
870 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 870 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
871 lse->setDtStart( mLastCalendarSync ); 871 lse->setDtStart( mLastCalendarSync );
872 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 872 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
873 lse->setCategories( i18n("SyncEvent") ); 873 lse->setCategories( i18n("SyncEvent") );
874 lse->setReadOnly( true ); 874 lse->setReadOnly( true );
875 mCalendar->addEvent( lse ); 875 mCalendar->addEvent( lse );
876 } 876 }
877 877
878 return lse; 878 return lse;
879 879
880} 880}
881 881
882// we check, if the to delete event has a id for a profile 882// we check, if the to delete event has a id for a profile
883// if yes, we set this id in the profile to delete 883// if yes, we set this id in the profile to delete
884void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 884void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
885{ 885{
886 if ( lastSync.count() == 0 ) { 886 if ( lastSync.count() == 0 ) {
887 //qDebug(" lastSync.count() == 0"); 887 //qDebug(" lastSync.count() == 0");
888 return; 888 return;
889 } 889 }
890 if ( toDelete->type() == "Journal" ) 890 if ( toDelete->type() == "Journal" )
891 return; 891 return;
892 892
893 Event* eve = lastSync.first(); 893 Event* eve = lastSync.first();
894 894
895 while ( eve ) { 895 while ( eve ) {
896 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 896 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
897 if ( !id.isEmpty() ) { 897 if ( !id.isEmpty() ) {
898 QString des = eve->description(); 898 QString des = eve->description();
899 QString pref = "e"; 899 QString pref = "e";
900 if ( toDelete->type() == "Todo" ) 900 if ( toDelete->type() == "Todo" )
901 pref = "t"; 901 pref = "t";
902 des += pref+ id + ","; 902 des += pref+ id + ",";
903 eve->setReadOnly( false ); 903 eve->setReadOnly( false );
904 eve->setDescription( des ); 904 eve->setDescription( des );
905 //qDebug("setdes %s ", des.latin1()); 905 //qDebug("setdes %s ", des.latin1());
906 eve->setReadOnly( true ); 906 eve->setReadOnly( true );
907 } 907 }
908 eve = lastSync.next(); 908 eve = lastSync.next();
909 } 909 }
910 910
911} 911}
912void CalendarView::checkExternalId( Incidence * inc ) 912void CalendarView::checkExternalId( Incidence * inc )
913{ 913{
914 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 914 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
915 checkExternSyncEvent( lastSync, inc ); 915 checkExternSyncEvent( lastSync, inc );
916 916
917} 917}
918bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 918bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
919{ 919{
920 bool syncOK = true; 920 bool syncOK = true;
921 int addedEvent = 0; 921 int addedEvent = 0;
922 int addedEventR = 0; 922 int addedEventR = 0;
923 int deletedEventR = 0; 923 int deletedEventR = 0;
924 int deletedEventL = 0; 924 int deletedEventL = 0;
925 int changedLocal = 0; 925 int changedLocal = 0;
926 int changedRemote = 0; 926 int changedRemote = 0;
927 //QPtrList<Event> el = local->rawEvents(); 927 //QPtrList<Event> el = local->rawEvents();
928 Event* eventR; 928 Event* eventR;
929 QString uid; 929 QString uid;
930 int take; 930 int take;
931 Event* eventL; 931 Event* eventL;
932 Event* eventRSync; 932 Event* eventRSync;
933 Event* eventLSync; 933 Event* eventLSync;
934 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 934 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
935 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 935 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
936 bool fullDateRange = false; 936 bool fullDateRange = false;
937 local->resetTempSyncStat(); 937 local->resetTempSyncStat();
938 mLastCalendarSync = QDateTime::currentDateTime(); 938 mLastCalendarSync = QDateTime::currentDateTime();
939 if ( mSyncManager->syncWithDesktop() ) { 939 if ( mSyncManager->syncWithDesktop() ) {
940 remote->resetPilotStat(1); 940 remote->resetPilotStat(1);
941 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 941 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
942 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 942 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
943 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 943 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
944 } else { 944 } else {
945 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 945 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
946 } 946 }
947 } 947 }
948 QDateTime modifiedCalendar = mLastCalendarSync; 948 QDateTime modifiedCalendar = mLastCalendarSync;
949 eventLSync = getLastSyncEvent(); 949 eventLSync = getLastSyncEvent();
950 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 950 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
951 if ( eventR ) { 951 if ( eventR ) {
952 eventRSync = (Event*) eventR->clone(); 952 eventRSync = (Event*) eventR->clone();
953 remote->deleteEvent(eventR ); 953 remote->deleteEvent(eventR );
954 954
955 } else { 955 } else {
956 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 956 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
957 eventRSync = (Event*)eventLSync->clone(); 957 eventRSync = (Event*)eventLSync->clone();
958 } else { 958 } else {
959 fullDateRange = true; 959 fullDateRange = true;
960 eventRSync = new Event(); 960 eventRSync = new Event();
961 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 961 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
962 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 962 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
963 eventRSync->setDtStart( mLastCalendarSync ); 963 eventRSync->setDtStart( mLastCalendarSync );
964 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 964 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
965 eventRSync->setCategories( i18n("SyncEvent") ); 965 eventRSync->setCategories( i18n("SyncEvent") );
966 } 966 }
967 } 967 }
968 if ( eventLSync->dtStart() == mLastCalendarSync ) 968 if ( eventLSync->dtStart() == mLastCalendarSync )
969 fullDateRange = true; 969 fullDateRange = true;
970 970
971 if ( ! fullDateRange ) { 971 if ( ! fullDateRange ) {
972 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 972 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
973 973
974 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 974 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
975 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 975 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
976 fullDateRange = true; 976 fullDateRange = true;
977 } 977 }
978 } 978 }
979 if ( mSyncManager->syncWithDesktop() ) { 979 if ( mSyncManager->syncWithDesktop() ) {
980 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 980 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
981 } 981 }
982 if ( fullDateRange ) 982 if ( fullDateRange )
983 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 983 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
984 else 984 else
985 mLastCalendarSync = eventLSync->dtStart(); 985 mLastCalendarSync = eventLSync->dtStart();
986 // for resyncing if own file has changed 986 // for resyncing if own file has changed
987 if ( mCurrentSyncDevice == "deleteaftersync" ) { 987 if ( mCurrentSyncDevice == "deleteaftersync" ) {
988 mLastCalendarSync = loadedFileVersion; 988 mLastCalendarSync = loadedFileVersion;
989 //qDebug("setting mLastCalendarSync "); 989 //qDebug("setting mLastCalendarSync ");
990 } 990 }
991 //qDebug("*************************** "); 991 //qDebug("*************************** ");
992 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 992 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
993 QPtrList<Incidence> er = remote->rawIncidences(); 993 QPtrList<Incidence> er = remote->rawIncidences();
994 Incidence* inR = er.first(); 994 Incidence* inR = er.first();
995 Incidence* inL; 995 Incidence* inL;
996 QProgressBar bar( er.count(),0 ); 996 QProgressBar bar( er.count(),0 );
997 bar.setCaption (i18n("Syncing - close to abort!") ); 997 bar.setCaption (i18n("Syncing - close to abort!") );
998 998
999 // ************** setting up filter ************* 999 // ************** setting up filter *************
1000 CalFilter *filterIN = 0; 1000 CalFilter *filterIN = 0;
1001 CalFilter *filterOUT = 0; 1001 CalFilter *filterOUT = 0;
1002 CalFilter *filter = mFilters.first(); 1002 CalFilter *filter = mFilters.first();
1003 while(filter) { 1003 while(filter) {
1004 if ( filter->name() == mSyncManager->mFilterInCal ) 1004 if ( filter->name() == mSyncManager->mFilterInCal )
1005 filterIN = filter; 1005 filterIN = filter;
1006 if ( filter->name() == mSyncManager->mFilterOutCal ) 1006 if ( filter->name() == mSyncManager->mFilterOutCal )
1007 filterOUT = filter; 1007 filterOUT = filter;
1008 filter = mFilters.next(); 1008 filter = mFilters.next();
1009 } 1009 }
1010 int w = 300; 1010 int w = 300;
1011 if ( QApplication::desktop()->width() < 320 ) 1011 if ( QApplication::desktop()->width() < 320 )
1012 w = 220; 1012 w = 220;
1013 int h = bar.sizeHint().height() ; 1013 int h = bar.sizeHint().height() ;
1014 int dw = QApplication::desktop()->width(); 1014 int dw = QApplication::desktop()->width();
1015 int dh = QApplication::desktop()->height(); 1015 int dh = QApplication::desktop()->height();
1016 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1016 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1017 bar.show(); 1017 bar.show();
1018 int modulo = (er.count()/10)+1; 1018 int modulo = (er.count()/10)+1;
1019 int incCounter = 0; 1019 int incCounter = 0;
1020 while ( inR ) { 1020 while ( inR ) {
1021 if ( ! bar.isVisible() ) 1021 if ( ! bar.isVisible() )
1022 return false; 1022 return false;
1023 if ( incCounter % modulo == 0 ) 1023 if ( incCounter % modulo == 0 )
1024 bar.setProgress( incCounter ); 1024 bar.setProgress( incCounter );
1025 ++incCounter; 1025 ++incCounter;
1026 uid = inR->uid(); 1026 uid = inR->uid();
1027 bool skipIncidence = false; 1027 bool skipIncidence = false;
1028 if ( uid.left(15) == QString("last-syncEvent-") ) 1028 if ( uid.left(15) == QString("last-syncEvent-") )
1029 skipIncidence = true; 1029 skipIncidence = true;
1030 QString idS; 1030 QString idS;
1031 qApp->processEvents(); 1031 qApp->processEvents();
1032 if ( !skipIncidence ) { 1032 if ( !skipIncidence ) {
1033 inL = local->incidence( uid ); 1033 inL = local->incidence( uid );
1034 if ( inL ) { // maybe conflict - same uid in both calendars 1034 if ( inL ) { // maybe conflict - same uid in both calendars
1035 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1035 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1036 //qDebug("take %d %s ", take, inL->summary().latin1()); 1036 //qDebug("take %d %s ", take, inL->summary().latin1());
1037 if ( take == 3 ) 1037 if ( take == 3 )
1038 return false; 1038 return false;
1039 if ( take == 1 ) {// take local ********************** 1039 if ( take == 1 ) {// take local **********************
1040 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1040 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1041 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1041 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1042 else 1042 else
1043 idS = inR->IDStr(); 1043 idS = inR->IDStr();
1044 remote->deleteIncidence( inR ); 1044 remote->deleteIncidence( inR );
1045 inR = inL->clone(); 1045 inR = inL->clone();
1046 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1046 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1047 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1047 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1048 inR->setIDStr( idS ); 1048 inR->setIDStr( idS );
1049 remote->addIncidence( inR ); 1049 remote->addIncidence( inR );
1050 if ( mSyncManager->syncWithDesktop() ) 1050 if ( mSyncManager->syncWithDesktop() )
1051 inR->setPilotId( 2 ); 1051 inR->setPilotId( 2 );
1052 ++changedRemote; 1052 ++changedRemote;
1053 } else {// take remote ********************** 1053 } else {// take remote **********************
1054 idS = inL->IDStr(); 1054 idS = inL->IDStr();
1055 int pid = inL->pilotId(); 1055 int pid = inL->pilotId();
1056 local->deleteIncidence( inL ); 1056 local->deleteIncidence( inL );
1057 inL = inR->clone(); 1057 inL = inR->clone();
1058 if ( mSyncManager->syncWithDesktop() ) 1058 if ( mSyncManager->syncWithDesktop() )
1059 inL->setPilotId( pid ); 1059 inL->setPilotId( pid );
1060 inL->setIDStr( idS ); 1060 inL->setIDStr( idS );
1061 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1061 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1062 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1062 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1063 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1063 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1064 } 1064 }
1065 local->addIncidence( inL ); 1065 local->addIncidence( inL );
1066 ++changedLocal; 1066 ++changedLocal;
1067 } 1067 }
1068 } 1068 }
1069 } else { // no conflict ********** add or delete remote 1069 } else { // no conflict ********** add or delete remote
1070 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1070 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1071 QString des = eventLSync->description(); 1071 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1072 QString pref = "e"; 1072 QString des = eventLSync->description();
1073 if ( inR->type() == "Todo" ) 1073 QString pref = "e";
1074 pref = "t"; 1074 if ( inR->type() == "Todo" )
1075 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1075 pref = "t";
1076 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1076 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1077 //remote->deleteIncidence( inR ); 1077 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1078 ++deletedEventR; 1078 //remote->deleteIncidence( inR );
1079 } else { 1079 ++deletedEventR;
1080 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1080 } else {
1081 inR->setLastModified( modifiedCalendar ); 1081 inR->setLastModified( modifiedCalendar );
1082 inL = inR->clone(); 1082 inL = inR->clone();
1083 inL->setIDStr( ":" ); 1083 inL->setIDStr( ":" );
1084 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1084 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1085 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1085 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1086 local->addIncidence( inL ); 1086 local->addIncidence( inL );
1087 ++addedEvent; 1087 ++addedEvent;
1088
1088 } 1089 }
1089 } 1090 } else {
1090 } else { 1091 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1091 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1092 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1093 inR->setLastModified( modifiedCalendar ); 1092 inR->setLastModified( modifiedCalendar );
1094 inL = inR->clone(); 1093 inL = inR->clone();
1095 inL->setIDStr( ":" ); 1094 inL->setIDStr( ":" );
1096 local->addIncidence( inL ); 1095 local->addIncidence( inL );
1097 ++addedEvent; 1096 ++addedEvent;
1097
1098 } else {
1099 checkExternSyncEvent(eventRSyncSharp, inR);
1100 remote->deleteIncidence( inR );
1101 ++deletedEventR;
1098 } 1102 }
1099 } else {
1100 checkExternSyncEvent(eventRSyncSharp, inR);
1101 remote->deleteIncidence( inR );
1102 ++deletedEventR;
1103 } 1103 }
1104 } 1104 }
1105 } 1105 }
1106 } 1106 }
1107 inR = er.next(); 1107 inR = er.next();
1108 } 1108 }
1109 QPtrList<Incidence> el = local->rawIncidences(); 1109 QPtrList<Incidence> el = local->rawIncidences();
1110 inL = el.first(); 1110 inL = el.first();
1111 modulo = (el.count()/10)+1; 1111 modulo = (el.count()/10)+1;
1112 bar.setCaption (i18n("Add / remove events") ); 1112 bar.setCaption (i18n("Add / remove events") );
1113 bar.setTotalSteps ( el.count() ) ; 1113 bar.setTotalSteps ( el.count() ) ;
1114 bar.show(); 1114 bar.show();
1115 incCounter = 0; 1115 incCounter = 0;
1116 1116
1117 while ( inL ) { 1117 while ( inL ) {
1118 1118
1119 qApp->processEvents(); 1119 qApp->processEvents();
1120 if ( ! bar.isVisible() ) 1120 if ( ! bar.isVisible() )
1121 return false; 1121 return false;
1122 if ( incCounter % modulo == 0 ) 1122 if ( incCounter % modulo == 0 )
1123 bar.setProgress( incCounter ); 1123 bar.setProgress( incCounter );
1124 ++incCounter; 1124 ++incCounter;
1125 uid = inL->uid(); 1125 uid = inL->uid();
1126 bool skipIncidence = false; 1126 bool skipIncidence = false;
1127 if ( uid.left(15) == QString("last-syncEvent-") ) 1127 if ( uid.left(15) == QString("last-syncEvent-") )
1128 skipIncidence = true; 1128 skipIncidence = true;
1129 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1129 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1130 skipIncidence = true; 1130 skipIncidence = true;
1131 if ( filterOUT && ! filterOUT->filterCalendarItem( inL ) ){
1132 skipIncidence = true;
1133 }
1131 if ( !skipIncidence ) { 1134 if ( !skipIncidence ) {
1132 inR = remote->incidence( uid ); 1135 inR = remote->incidence( uid );
1133 if ( ! inR ) { // no conflict ********** add or delete local 1136 if ( ! inR ) { // no conflict ********** add or delete local
1134 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1137 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1135 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1138 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1136 checkExternSyncEvent(eventLSyncSharp, inL); 1139 checkExternSyncEvent(eventLSyncSharp, inL);
1137 local->deleteIncidence( inL ); 1140 local->deleteIncidence( inL );
1138 ++deletedEventL; 1141 ++deletedEventL;
1139 } else { 1142 } else {
1140 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1143 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1141 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1144 inL->removeID(mCurrentSyncDevice );
1142 inL->removeID(mCurrentSyncDevice ); 1145 ++addedEventR;
1143 ++addedEventR; 1146 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1144 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1147 inL->setLastModified( modifiedCalendar );
1145 inL->setLastModified( modifiedCalendar ); 1148 inR = inL->clone();
1146 inR = inL->clone(); 1149 inR->setIDStr( ":" );
1147 inR->setIDStr( ":" ); 1150 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1148 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1151 remote->addIncidence( inR );
1149 remote->addIncidence( inR );
1150 }
1151 } 1152 }
1152 } 1153 }
1153 } else { 1154 } else {
1154 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1155 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1155 checkExternSyncEvent(eventLSyncSharp, inL); 1156 checkExternSyncEvent(eventLSyncSharp, inL);
1156 local->deleteIncidence( inL ); 1157 local->deleteIncidence( inL );
1157 ++deletedEventL; 1158 ++deletedEventL;
1158 } else { 1159 } else {
1159 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1160 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1160 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1161 ++addedEventR;
1161 ++addedEventR; 1162 inL->setLastModified( modifiedCalendar );
1162 inL->setLastModified( modifiedCalendar ); 1163 inR = inL->clone();
1163 inR = inL->clone(); 1164 inR->setIDStr( ":" );
1164 inR->setIDStr( ":" ); 1165 remote->addIncidence( inR );
1165 remote->addIncidence( inR );
1166 }
1167 } 1166 }
1168 } 1167 }
1169 } 1168 }
1170 } 1169 }
1171 } 1170 }
1172 inL = el.next(); 1171 inL = el.next();
1173 } 1172 }
1174 int delFut = 0; 1173 int delFut = 0;
1175 int remRem = 0; 1174 int remRem = 0;
1176 if ( mSyncManager->mWriteBackInFuture ) { 1175 if ( mSyncManager->mWriteBackInFuture ) {
1177 er = remote->rawIncidences(); 1176 er = remote->rawIncidences();
1178 remRem = er.count(); 1177 remRem = er.count();
1179 inR = er.first(); 1178 inR = er.first();
1180 QDateTime dt; 1179 QDateTime dt;
1181 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1180 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1182 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1181 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1183 while ( inR ) { 1182 while ( inR ) {
1184 if ( inR->type() == "Todo" ) { 1183 if ( inR->type() == "Todo" ) {
1185 Todo * t = (Todo*)inR; 1184 Todo * t = (Todo*)inR;
1186 if ( t->hasDueDate() ) 1185 if ( t->hasDueDate() )
1187 dt = t->dtDue(); 1186 dt = t->dtDue();
1188 else 1187 else
1189 dt = cur.addSecs( 62 ); 1188 dt = cur.addSecs( 62 );
1190 } 1189 }
1191 else if (inR->type() == "Event" ) { 1190 else if (inR->type() == "Event" ) {
1192 bool ok; 1191 bool ok;
1193 dt = inR->getNextOccurence( cur, &ok ); 1192 dt = inR->getNextOccurence( cur, &ok );
1194 if ( !ok ) 1193 if ( !ok )
1195 dt = cur.addSecs( -62 ); 1194 dt = cur.addSecs( -62 );
1196 } 1195 }
1197 else 1196 else
1198 dt = inR->dtStart(); 1197 dt = inR->dtStart();
1199 if ( dt < cur || dt > end ) { 1198 if ( dt < cur || dt > end ) {
1200 remote->deleteIncidence( inR ); 1199 remote->deleteIncidence( inR );
1201 ++delFut; 1200 ++delFut;
1202 } 1201 }
1203 inR = er.next(); 1202 inR = er.next();
1204 } 1203 }
1205 } 1204 }
1206 bar.hide(); 1205 bar.hide();
1207 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1206 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1208 eventLSync->setReadOnly( false ); 1207 eventLSync->setReadOnly( false );
1209 eventLSync->setDtStart( mLastCalendarSync ); 1208 eventLSync->setDtStart( mLastCalendarSync );
1210 eventRSync->setDtStart( mLastCalendarSync ); 1209 eventRSync->setDtStart( mLastCalendarSync );
1211 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1210 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1212 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1211 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1213 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1212 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1214 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1213 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1215 eventLSync->setReadOnly( true ); 1214 eventLSync->setReadOnly( true );
1216 qDebug("********** %d %d ", mGlobalSyncMode == SYNC_MODE_NORMAL, mSyncManager->syncWithDesktop() ); 1215 qDebug("********** %d %d ", mGlobalSyncMode == SYNC_MODE_NORMAL, mSyncManager->syncWithDesktop() );
1217 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1216 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1218 remote->addEvent( eventRSync ); 1217 remote->addEvent( eventRSync );
1219 else 1218 else
1220 delete eventRSync; 1219 delete eventRSync;
1221 QString mes; 1220 QString mes;
1222 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 ); 1221 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 );
1223 QString delmess; 1222 QString delmess;
1224 if ( delFut ) { 1223 if ( delFut ) {
1225 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); 1224 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut);
1226 mes += delmess; 1225 mes += delmess;
1227 } 1226 }
1228 mes = i18n("Local calendar changed!\n") +mes; 1227 mes = i18n("Local calendar changed!\n") +mes;
1229 mCalendar->checkAlarmForIncidence( 0, true ); 1228 mCalendar->checkAlarmForIncidence( 0, true );
1230 qDebug( mes ); 1229 qDebug( mes );
1231 if ( mSyncManager->mShowSyncSummary ) { 1230 if ( mSyncManager->mShowSyncSummary ) {
1232 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1231 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1233 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1232 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1234 qDebug("cancelled "); 1233 qDebug("cancelled ");
1235 return false; 1234 return false;
1236 } 1235 }
1237 } 1236 }
1238 return syncOK; 1237 return syncOK;
1239} 1238}
1240 1239
1241void CalendarView::setSyncDevice( QString s ) 1240void CalendarView::setSyncDevice( QString s )
1242{ 1241{
1243 mCurrentSyncDevice= s; 1242 mCurrentSyncDevice= s;
1244} 1243}
1245void CalendarView::setSyncName( QString s ) 1244void CalendarView::setSyncName( QString s )
1246{ 1245{
1247 mCurrentSyncName= s; 1246 mCurrentSyncName= s;
1248} 1247}
1249bool CalendarView::syncCalendar(QString filename, int mode) 1248bool CalendarView::syncCalendar(QString filename, int mode)
1250{ 1249{
1251 //qDebug("syncCalendar %s ", filename.latin1()); 1250 //qDebug("syncCalendar %s ", filename.latin1());
1252 mGlobalSyncMode = SYNC_MODE_NORMAL; 1251 mGlobalSyncMode = SYNC_MODE_NORMAL;
1253 CalendarLocal* calendar = new CalendarLocal(); 1252 CalendarLocal* calendar = new CalendarLocal();
1254 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1253 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1255 FileStorage* storage = new FileStorage( calendar ); 1254 FileStorage* storage = new FileStorage( calendar );
1256 bool syncOK = false; 1255 bool syncOK = false;
1257 storage->setFileName( filename ); 1256 storage->setFileName( filename );
1258 // qDebug("loading ... "); 1257 // qDebug("loading ... ");
1259 if ( storage->load() ) { 1258 if ( storage->load() ) {
1260 getEventViewerDialog()->setSyncMode( true ); 1259 getEventViewerDialog()->setSyncMode( true );
1261 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1260 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1262 getEventViewerDialog()->setSyncMode( false ); 1261 getEventViewerDialog()->setSyncMode( false );
1263 if ( syncOK ) { 1262 if ( syncOK ) {
1264 if ( mSyncManager->mWriteBackFile ) 1263 if ( mSyncManager->mWriteBackFile )
1265 { 1264 {
1266 storage->setSaveFormat( new ICalFormat() ); 1265 storage->setSaveFormat( new ICalFormat() );
1267 storage->save(); 1266 storage->save();
1268 } 1267 }
1269 } 1268 }
1270 setModified( true ); 1269 setModified( true );
1271 } 1270 }
1272 delete storage; 1271 delete storage;
1273 delete calendar; 1272 delete calendar;
1274 if ( syncOK ) 1273 if ( syncOK )
1275 updateView(); 1274 updateView();
1276 return syncOK; 1275 return syncOK;
1277} 1276}
1278 1277
1279void CalendarView::syncExternal( int mode ) 1278void CalendarView::syncExternal( int mode )
1280{ 1279{
1281 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1280 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1282 1281
1283 qApp->processEvents(); 1282 qApp->processEvents();
1284 CalendarLocal* calendar = new CalendarLocal(); 1283 CalendarLocal* calendar = new CalendarLocal();
1285 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1284 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1286 bool syncOK = false; 1285 bool syncOK = false;
1287 bool loadSuccess = false; 1286 bool loadSuccess = false;
1288 PhoneFormat* phoneFormat = 0; 1287 PhoneFormat* phoneFormat = 0;
1289 emit tempDisableBR(true); 1288 emit tempDisableBR(true);
1290#ifndef DESKTOP_VERSION 1289#ifndef DESKTOP_VERSION
1291 SharpFormat* sharpFormat = 0; 1290 SharpFormat* sharpFormat = 0;
1292 if ( mode == 0 ) { // sharp 1291 if ( mode == 0 ) { // sharp
1293 sharpFormat = new SharpFormat () ; 1292 sharpFormat = new SharpFormat () ;
1294 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1293 loadSuccess = sharpFormat->load( calendar, mCalendar );
1295 1294
1296 } else 1295 } else
1297#endif 1296#endif
1298 if ( mode == 1 ) { // phone 1297 if ( mode == 1 ) { // phone
1299 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1298 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1300 mSyncManager->mPhoneDevice, 1299 mSyncManager->mPhoneDevice,
1301 mSyncManager->mPhoneConnection, 1300 mSyncManager->mPhoneConnection,
1302 mSyncManager->mPhoneModel); 1301 mSyncManager->mPhoneModel);
1303 loadSuccess = phoneFormat->load( calendar,mCalendar); 1302 loadSuccess = phoneFormat->load( calendar,mCalendar);
1304 1303
1305 } else { 1304 } else {
1306 emit tempDisableBR(false); 1305 emit tempDisableBR(false);
1307 return; 1306 return;
1308 } 1307 }
1309 if ( loadSuccess ) { 1308 if ( loadSuccess ) {
1310 getEventViewerDialog()->setSyncMode( true ); 1309 getEventViewerDialog()->setSyncMode( true );
1311 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1310 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1312 getEventViewerDialog()->setSyncMode( false ); 1311 getEventViewerDialog()->setSyncMode( false );
1313 qApp->processEvents(); 1312 qApp->processEvents();
1314 if ( syncOK ) { 1313 if ( syncOK ) {
1315 if ( mSyncManager->mWriteBackFile ) 1314 if ( mSyncManager->mWriteBackFile )
1316 { 1315 {
1317 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1316 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1318 Incidence* inc = iL.first(); 1317 Incidence* inc = iL.first();
1319 if ( phoneFormat ) { 1318 if ( phoneFormat ) {
1320 while ( inc ) { 1319 while ( inc ) {
1321 inc->removeID(mCurrentSyncDevice); 1320 inc->removeID(mCurrentSyncDevice);
1322 inc = iL.next(); 1321 inc = iL.next();
1323 } 1322 }
1324 } 1323 }
1325#ifndef DESKTOP_VERSION 1324#ifndef DESKTOP_VERSION
1326 if ( sharpFormat ) 1325 if ( sharpFormat )
1327 sharpFormat->save(calendar); 1326 sharpFormat->save(calendar);
1328#endif 1327#endif
1329 if ( phoneFormat ) 1328 if ( phoneFormat )
1330 phoneFormat->save(calendar); 1329 phoneFormat->save(calendar);
1331 iL = calendar->rawIncidences(); 1330 iL = calendar->rawIncidences();
1332 inc = iL.first(); 1331 inc = iL.first();
1333 Incidence* loc; 1332 Incidence* loc;
1334 while ( inc ) { 1333 while ( inc ) {
1335 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1334 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1336 loc = mCalendar->incidence(inc->uid() ); 1335 loc = mCalendar->incidence(inc->uid() );
1337 if ( loc ) { 1336 if ( loc ) {
1338 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1337 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1339 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1338 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1340 } 1339 }
1341 } 1340 }
1342 inc = iL.next(); 1341 inc = iL.next();
1343 } 1342 }
1344 Incidence* lse = getLastSyncEvent(); 1343 Incidence* lse = getLastSyncEvent();
1345 if ( lse ) { 1344 if ( lse ) {
1346 lse->setReadOnly( false ); 1345 lse->setReadOnly( false );
1347 lse->setDescription( "" ); 1346 lse->setDescription( "" );
1348 lse->setReadOnly( true ); 1347 lse->setReadOnly( true );
1349 } 1348 }
1350 } 1349 }
1351 } else { 1350 } else {
1352 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1351 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1353 } 1352 }
1354 setModified( true ); 1353 setModified( true );
1355 } else { 1354 } else {
1356 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1355 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1357 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1356 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1358 question, i18n("Ok")) ; 1357 question, i18n("Ok")) ;
1359 1358
1360 } 1359 }
1361 delete calendar; 1360 delete calendar;
1362 updateView(); 1361 updateView();
1363 emit tempDisableBR(false); 1362 emit tempDisableBR(false);
1364 return ;//syncOK; 1363 return ;//syncOK;
1365 1364
1366} 1365}
1367 1366
1368bool CalendarView::importBday() 1367bool CalendarView::importBday()
1369{ 1368{
1370#ifndef KORG_NOKABC 1369#ifndef KORG_NOKABC
1371 1370
1372#ifdef DESKTOP_VERSION 1371#ifdef DESKTOP_VERSION
1373 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1372 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1374 KABC::AddressBook::Iterator it; 1373 KABC::AddressBook::Iterator it;
1375 int count = 0; 1374 int count = 0;
1376 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1375 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1377 ++count; 1376 ++count;
1378 } 1377 }
1379 QProgressBar bar(count,0 ); 1378 QProgressBar bar(count,0 );
1380 int w = 300; 1379 int w = 300;
1381 if ( QApplication::desktop()->width() < 320 ) 1380 if ( QApplication::desktop()->width() < 320 )
1382 w = 220; 1381 w = 220;
1383 int h = bar.sizeHint().height() ; 1382 int h = bar.sizeHint().height() ;
1384 int dw = QApplication::desktop()->width(); 1383 int dw = QApplication::desktop()->width();
1385 int dh = QApplication::desktop()->height(); 1384 int dh = QApplication::desktop()->height();
1386 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1385 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1387 bar.show(); 1386 bar.show();
1388 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1387 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1389 qApp->processEvents(); 1388 qApp->processEvents();
1390 count = 0; 1389 count = 0;
1391 int addCount = 0; 1390 int addCount = 0;
1392 KCal::Attendee* a = 0; 1391 KCal::Attendee* a = 0;
1393 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1392 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1394 if ( ! bar.isVisible() ) 1393 if ( ! bar.isVisible() )
1395 return false; 1394 return false;
1396 bar.setProgress( count++ ); 1395 bar.setProgress( count++ );
1397 qApp->processEvents(); 1396 qApp->processEvents();
1398 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1397 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1399 if ( (*it).birthday().date().isValid() ){ 1398 if ( (*it).birthday().date().isValid() ){
1400 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1399 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1401 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1400 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1402 ++addCount; 1401 ++addCount;
1403 } 1402 }
1404 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1403 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1405 if ( anni.isValid() ){ 1404 if ( anni.isValid() ){
1406 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1405 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1407 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1406 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1408 ++addCount; 1407 ++addCount;
1409 } 1408 }
1410 } 1409 }
1411 updateView(); 1410 updateView();
1412 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1411 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1413#else //DESKTOP_VERSION 1412#else //DESKTOP_VERSION
1414 1413
1415 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1414 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1416 // the result should now arrive through method insertBirthdays 1415 // the result should now arrive through method insertBirthdays
1417 1416
1418#endif //DESKTOP_VERSION 1417#endif //DESKTOP_VERSION
1419 1418
1420#endif //KORG_NOKABC 1419#endif //KORG_NOKABC
1421 1420
1422 1421