summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 7ddbe23..363dc32 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -778,813 +778,813 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
778 equ = (*((Todo*) local) == (*(Todo*) remote)); 778 equ = (*((Todo*) local) == (*(Todo*) remote));
779 else if ( local->type() =="Journal" ) 779 else if ( local->type() =="Journal" )
780 equ = (*((Journal*) local) == *((Journal*) remote)); 780 equ = (*((Journal*) local) == *((Journal*) remote));
781 if ( equ ) { 781 if ( equ ) {
782 //qDebug("equal "); 782 //qDebug("equal ");
783 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 783 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
784 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 784 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
785 } 785 }
786 if ( mode < SYNC_PREF_FORCE_LOCAL ) 786 if ( mode < SYNC_PREF_FORCE_LOCAL )
787 return 0; 787 return 0;
788 788
789 }//else //debug only 789 }//else //debug only
790 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 790 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
791 } 791 }
792 int result; 792 int result;
793 bool localIsNew; 793 bool localIsNew;
794 //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() ); 794 //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() );
795 795
796 if ( full && mode < SYNC_PREF_NEWEST ) 796 if ( full && mode < SYNC_PREF_NEWEST )
797 mode = SYNC_PREF_ASK; 797 mode = SYNC_PREF_ASK;
798 798
799 switch( mode ) { 799 switch( mode ) {
800 case SYNC_PREF_LOCAL: 800 case SYNC_PREF_LOCAL:
801 if ( lastSync > remoteMod ) 801 if ( lastSync > remoteMod )
802 return 1; 802 return 1;
803 if ( lastSync > localMod ) 803 if ( lastSync > localMod )
804 return 2; 804 return 2;
805 return 1; 805 return 1;
806 break; 806 break;
807 case SYNC_PREF_REMOTE: 807 case SYNC_PREF_REMOTE:
808 if ( lastSync > remoteMod ) 808 if ( lastSync > remoteMod )
809 return 1; 809 return 1;
810 if ( lastSync > localMod ) 810 if ( lastSync > localMod )
811 return 2; 811 return 2;
812 return 2; 812 return 2;
813 break; 813 break;
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 int w = 300; 999 int w = 300;
1000 if ( QApplication::desktop()->width() < 320 ) 1000 if ( QApplication::desktop()->width() < 320 )
1001 w = 220; 1001 w = 220;
1002 int h = bar.sizeHint().height() ; 1002 int h = bar.sizeHint().height() ;
1003 int dw = QApplication::desktop()->width(); 1003 int dw = QApplication::desktop()->width();
1004 int dh = QApplication::desktop()->height(); 1004 int dh = QApplication::desktop()->height();
1005 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1005 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1006 bar.show(); 1006 bar.show();
1007 int modulo = (er.count()/10)+1; 1007 int modulo = (er.count()/10)+1;
1008 int incCounter = 0; 1008 int incCounter = 0;
1009 while ( inR ) { 1009 while ( inR ) {
1010 if ( ! bar.isVisible() ) 1010 if ( ! bar.isVisible() )
1011 return false; 1011 return false;
1012 if ( incCounter % modulo == 0 ) 1012 if ( incCounter % modulo == 0 )
1013 bar.setProgress( incCounter ); 1013 bar.setProgress( incCounter );
1014 ++incCounter; 1014 ++incCounter;
1015 uid = inR->uid(); 1015 uid = inR->uid();
1016 bool skipIncidence = false; 1016 bool skipIncidence = false;
1017 if ( uid.left(15) == QString("last-syncEvent-") ) 1017 if ( uid.left(15) == QString("last-syncEvent-") )
1018 skipIncidence = true; 1018 skipIncidence = true;
1019 QString idS; 1019 QString idS;
1020 qApp->processEvents(); 1020 qApp->processEvents();
1021 if ( !skipIncidence ) { 1021 if ( !skipIncidence ) {
1022 inL = local->incidence( uid ); 1022 inL = local->incidence( uid );
1023 if ( inL ) { // maybe conflict - same uid in both calendars 1023 if ( inL ) { // maybe conflict - same uid in both calendars
1024 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1024 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1025 //qDebug("take %d %s ", take, inL->summary().latin1()); 1025 //qDebug("take %d %s ", take, inL->summary().latin1());
1026 if ( take == 3 ) 1026 if ( take == 3 )
1027 return false; 1027 return false;
1028 if ( take == 1 ) {// take local ********************** 1028 if ( take == 1 ) {// take local **********************
1029 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1029 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1030 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1030 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1031 else 1031 else
1032 idS = inR->IDStr(); 1032 idS = inR->IDStr();
1033 remote->deleteIncidence( inR ); 1033 remote->deleteIncidence( inR );
1034 inR = inL->clone(); 1034 inR = inL->clone();
1035 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1035 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1036 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1036 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1037 inR->setIDStr( idS ); 1037 inR->setIDStr( idS );
1038 remote->addIncidence( inR ); 1038 remote->addIncidence( inR );
1039 if ( mSyncManager->syncWithDesktop() ) 1039 if ( mSyncManager->syncWithDesktop() )
1040 inR->setPilotId( 2 ); 1040 inR->setPilotId( 2 );
1041 ++changedRemote; 1041 ++changedRemote;
1042 } else {// take remote ********************** 1042 } else {// take remote **********************
1043 idS = inL->IDStr(); 1043 idS = inL->IDStr();
1044 int pid = inL->pilotId(); 1044 int pid = inL->pilotId();
1045 local->deleteIncidence( inL ); 1045 local->deleteIncidence( inL );
1046 inL = inR->clone(); 1046 inL = inR->clone();
1047 if ( mSyncManager->syncWithDesktop() ) 1047 if ( mSyncManager->syncWithDesktop() )
1048 inL->setPilotId( pid ); 1048 inL->setPilotId( pid );
1049 inL->setIDStr( idS ); 1049 inL->setIDStr( idS );
1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1051 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1051 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1052 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1052 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1053 } 1053 }
1054 local->addIncidence( inL ); 1054 local->addIncidence( inL );
1055 ++changedLocal; 1055 ++changedLocal;
1056 } 1056 }
1057 } 1057 }
1058 } else { // no conflict ********** add or delete remote 1058 } else { // no conflict ********** add or delete remote
1059 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1059 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1060 QString des = eventLSync->description(); 1060 QString des = eventLSync->description();
1061 QString pref = "e"; 1061 QString pref = "e";
1062 if ( inR->type() == "Todo" ) 1062 if ( inR->type() == "Todo" )
1063 pref = "t"; 1063 pref = "t";
1064 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1064 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1065 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1065 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1066 //remote->deleteIncidence( inR ); 1066 //remote->deleteIncidence( inR );
1067 ++deletedEventR; 1067 ++deletedEventR;
1068 } else { 1068 } else {
1069 inR->setLastModified( modifiedCalendar ); 1069 inR->setLastModified( modifiedCalendar );
1070 inL = inR->clone(); 1070 inL = inR->clone();
1071 inL->setIDStr( ":" ); 1071 inL->setIDStr( ":" );
1072 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1072 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1073 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1073 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1074 local->addIncidence( inL ); 1074 local->addIncidence( inL );
1075 ++addedEvent; 1075 ++addedEvent;
1076 } 1076 }
1077 } else { 1077 } else {
1078 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1078 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1079 inR->setLastModified( modifiedCalendar ); 1079 inR->setLastModified( modifiedCalendar );
1080 inL = inR->clone(); 1080 inL = inR->clone();
1081 inL->setIDStr( ":" ); 1081 inL->setIDStr( ":" );
1082 local->addIncidence( inL ); 1082 local->addIncidence( inL );
1083 ++addedEvent; 1083 ++addedEvent;
1084 } else { 1084 } else {
1085 checkExternSyncEvent(eventRSyncSharp, inR); 1085 checkExternSyncEvent(eventRSyncSharp, inR);
1086 remote->deleteIncidence( inR ); 1086 remote->deleteIncidence( inR );
1087 ++deletedEventR; 1087 ++deletedEventR;
1088 } 1088 }
1089 } 1089 }
1090 } 1090 }
1091 } 1091 }
1092 inR = er.next(); 1092 inR = er.next();
1093 } 1093 }
1094 QPtrList<Incidence> el = local->rawIncidences(); 1094 QPtrList<Incidence> el = local->rawIncidences();
1095 inL = el.first(); 1095 inL = el.first();
1096 modulo = (el.count()/10)+1; 1096 modulo = (el.count()/10)+1;
1097 bar.setCaption (i18n("Add / remove events") ); 1097 bar.setCaption (i18n("Add / remove events") );
1098 bar.setTotalSteps ( el.count() ) ; 1098 bar.setTotalSteps ( el.count() ) ;
1099 bar.show(); 1099 bar.show();
1100 incCounter = 0; 1100 incCounter = 0;
1101 1101
1102 while ( inL ) { 1102 while ( inL ) {
1103 1103
1104 qApp->processEvents(); 1104 qApp->processEvents();
1105 if ( ! bar.isVisible() ) 1105 if ( ! bar.isVisible() )
1106 return false; 1106 return false;
1107 if ( incCounter % modulo == 0 ) 1107 if ( incCounter % modulo == 0 )
1108 bar.setProgress( incCounter ); 1108 bar.setProgress( incCounter );
1109 ++incCounter; 1109 ++incCounter;
1110 uid = inL->uid(); 1110 uid = inL->uid();
1111 bool skipIncidence = false; 1111 bool skipIncidence = false;
1112 if ( uid.left(15) == QString("last-syncEvent-") ) 1112 if ( uid.left(15) == QString("last-syncEvent-") )
1113 skipIncidence = true; 1113 skipIncidence = true;
1114 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1114 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1115 skipIncidence = true; 1115 skipIncidence = true;
1116 if ( !skipIncidence ) { 1116 if ( !skipIncidence ) {
1117 inR = remote->incidence( uid ); 1117 inR = remote->incidence( uid );
1118 if ( ! inR ) { // no conflict ********** add or delete local 1118 if ( ! inR ) { // no conflict ********** add or delete local
1119 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1119 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1120 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1120 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1121 checkExternSyncEvent(eventLSyncSharp, inL); 1121 checkExternSyncEvent(eventLSyncSharp, inL);
1122 local->deleteIncidence( inL ); 1122 local->deleteIncidence( inL );
1123 ++deletedEventL; 1123 ++deletedEventL;
1124 } else { 1124 } else {
1125 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1125 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1126 inL->removeID(mCurrentSyncDevice ); 1126 inL->removeID(mCurrentSyncDevice );
1127 ++addedEventR; 1127 ++addedEventR;
1128 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1128 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1129 inL->setLastModified( modifiedCalendar ); 1129 inL->setLastModified( modifiedCalendar );
1130 inR = inL->clone(); 1130 inR = inL->clone();
1131 inR->setIDStr( ":" ); 1131 inR->setIDStr( ":" );
1132 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1132 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1133 remote->addIncidence( inR ); 1133 remote->addIncidence( inR );
1134 } 1134 }
1135 } 1135 }
1136 } else { 1136 } else {
1137 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1137 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1138 checkExternSyncEvent(eventLSyncSharp, inL); 1138 checkExternSyncEvent(eventLSyncSharp, inL);
1139 local->deleteIncidence( inL ); 1139 local->deleteIncidence( inL );
1140 ++deletedEventL; 1140 ++deletedEventL;
1141 } else { 1141 } else {
1142 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1142 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1143 ++addedEventR; 1143 ++addedEventR;
1144 inL->setLastModified( modifiedCalendar ); 1144 inL->setLastModified( modifiedCalendar );
1145 inR = inL->clone(); 1145 inR = inL->clone();
1146 inR->setIDStr( ":" ); 1146 inR->setIDStr( ":" );
1147 remote->addIncidence( inR ); 1147 remote->addIncidence( inR );
1148 } 1148 }
1149 } 1149 }
1150 } 1150 }
1151 } 1151 }
1152 } 1152 }
1153 inL = el.next(); 1153 inL = el.next();
1154 } 1154 }
1155 int delFut = 0; 1155 int delFut = 0;
1156 int remRem = 0; 1156 int remRem = 0;
1157 if ( mSyncManager->mWriteBackInFuture ) { 1157 if ( mSyncManager->mWriteBackInFuture ) {
1158 er = remote->rawIncidences(); 1158 er = remote->rawIncidences();
1159 remRem = er.count(); 1159 remRem = er.count();
1160 inR = er.first(); 1160 inR = er.first();
1161 QDateTime dt; 1161 QDateTime dt;
1162 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1162 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1163 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); 1163 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1164 while ( inR ) { 1164 while ( inR ) {
1165 if ( inR->type() == "Todo" ) { 1165 if ( inR->type() == "Todo" ) {
1166 Todo * t = (Todo*)inR; 1166 Todo * t = (Todo*)inR;
1167 if ( t->hasDueDate() ) 1167 if ( t->hasDueDate() )
1168 dt = t->dtDue(); 1168 dt = t->dtDue();
1169 else 1169 else
1170 dt = cur.addSecs( 62 ); 1170 dt = cur.addSecs( 62 );
1171 } 1171 }
1172 else if (inR->type() == "Event" ) { 1172 else if (inR->type() == "Event" ) {
1173 bool ok; 1173 bool ok;
1174 dt = inR->getNextOccurence( cur, &ok ); 1174 dt = inR->getNextOccurence( cur, &ok );
1175 if ( !ok ) 1175 if ( !ok )
1176 dt = cur.addSecs( -62 ); 1176 dt = cur.addSecs( -62 );
1177 } 1177 }
1178 else 1178 else
1179 dt = inR->dtStart(); 1179 dt = inR->dtStart();
1180 if ( dt < cur || dt > end ) { 1180 if ( dt < cur || dt > end ) {
1181 remote->deleteIncidence( inR ); 1181 remote->deleteIncidence( inR );
1182 ++delFut; 1182 ++delFut;
1183 } 1183 }
1184 inR = er.next(); 1184 inR = er.next();
1185 } 1185 }
1186 } 1186 }
1187 bar.hide(); 1187 bar.hide();
1188 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1188 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1189 eventLSync->setReadOnly( false ); 1189 eventLSync->setReadOnly( false );
1190 eventLSync->setDtStart( mLastCalendarSync ); 1190 eventLSync->setDtStart( mLastCalendarSync );
1191 eventRSync->setDtStart( mLastCalendarSync ); 1191 eventRSync->setDtStart( mLastCalendarSync );
1192 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1192 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1193 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1193 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1194 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1194 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1195 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1195 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1196 eventLSync->setReadOnly( true ); 1196 eventLSync->setReadOnly( true );
1197 qDebug("********** %d %d ", mGlobalSyncMode == SYNC_MODE_NORMAL, mSyncManager->syncWithDesktop() ); 1197 qDebug("********** %d %d ", mGlobalSyncMode == SYNC_MODE_NORMAL, mSyncManager->syncWithDesktop() );
1198 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1198 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1199 remote->addEvent( eventRSync ); 1199 remote->addEvent( eventRSync );
1200 else 1200 else
1201 delete eventRSync; 1201 delete eventRSync;
1202 QString mes; 1202 QString mes;
1203 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 ); 1203 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 );
1204 QString delmess; 1204 QString delmess;
1205 if ( delFut ) { 1205 if ( delFut ) {
1206 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); 1206 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);
1207 mes += delmess; 1207 mes += delmess;
1208 } 1208 }
1209 mes = i18n("Local calendar changed!\n") +mes; 1209 mes = i18n("Local calendar changed!\n") +mes;
1210 mCalendar->checkAlarmForIncidence( 0, true ); 1210 mCalendar->checkAlarmForIncidence( 0, true );
1211 qDebug( mes ); 1211 qDebug( mes );
1212 if ( mSyncManager->mShowSyncSummary ) { 1212 if ( mSyncManager->mShowSyncSummary ) {
1213 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1213 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1214 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1214 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1215 qDebug("cancelled "); 1215 qDebug("cancelled ");
1216 return false; 1216 return false;
1217 } 1217 }
1218 } 1218 }
1219 return syncOK; 1219 return syncOK;
1220} 1220}
1221 1221
1222void CalendarView::setSyncDevice( QString s ) 1222void CalendarView::setSyncDevice( QString s )
1223{ 1223{
1224 mCurrentSyncDevice= s; 1224 mCurrentSyncDevice= s;
1225} 1225}
1226void CalendarView::setSyncName( QString s ) 1226void CalendarView::setSyncName( QString s )
1227{ 1227{
1228 mCurrentSyncName= s; 1228 mCurrentSyncName= s;
1229} 1229}
1230bool CalendarView::syncCalendar(QString filename, int mode) 1230bool CalendarView::syncCalendar(QString filename, int mode)
1231{ 1231{
1232 //qDebug("syncCalendar %s ", filename.latin1()); 1232 //qDebug("syncCalendar %s ", filename.latin1());
1233 mGlobalSyncMode = SYNC_MODE_NORMAL; 1233 mGlobalSyncMode = SYNC_MODE_NORMAL;
1234 CalendarLocal* calendar = new CalendarLocal(); 1234 CalendarLocal* calendar = new CalendarLocal();
1235 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1235 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1236 FileStorage* storage = new FileStorage( calendar ); 1236 FileStorage* storage = new FileStorage( calendar );
1237 bool syncOK = false; 1237 bool syncOK = false;
1238 storage->setFileName( filename ); 1238 storage->setFileName( filename );
1239 // qDebug("loading ... "); 1239 // qDebug("loading ... ");
1240 if ( storage->load() ) { 1240 if ( storage->load() ) {
1241 getEventViewerDialog()->setSyncMode( true ); 1241 getEventViewerDialog()->setSyncMode( true );
1242 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1242 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1243 getEventViewerDialog()->setSyncMode( false ); 1243 getEventViewerDialog()->setSyncMode( false );
1244 if ( syncOK ) { 1244 if ( syncOK ) {
1245 if ( mSyncManager->mWriteBackFile ) 1245 if ( mSyncManager->mWriteBackFile )
1246 { 1246 {
1247 storage->setSaveFormat( new ICalFormat() ); 1247 storage->setSaveFormat( new ICalFormat() );
1248 storage->save(); 1248 storage->save();
1249 } 1249 }
1250 } 1250 }
1251 setModified( true ); 1251 setModified( true );
1252 } 1252 }
1253 delete storage; 1253 delete storage;
1254 delete calendar; 1254 delete calendar;
1255 if ( syncOK ) 1255 if ( syncOK )
1256 updateView(); 1256 updateView();
1257 return syncOK; 1257 return syncOK;
1258} 1258}
1259 1259
1260void CalendarView::syncExternal( int mode ) 1260void CalendarView::syncExternal( int mode )
1261{ 1261{
1262 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1262 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1263 1263
1264 qApp->processEvents(); 1264 qApp->processEvents();
1265 CalendarLocal* calendar = new CalendarLocal(); 1265 CalendarLocal* calendar = new CalendarLocal();
1266 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1266 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1267 bool syncOK = false; 1267 bool syncOK = false;
1268 bool loadSuccess = false; 1268 bool loadSuccess = false;
1269 PhoneFormat* phoneFormat = 0; 1269 PhoneFormat* phoneFormat = 0;
1270 emit tempDisableBR(true); 1270 emit tempDisableBR(true);
1271#ifndef DESKTOP_VERSION 1271#ifndef DESKTOP_VERSION
1272 SharpFormat* sharpFormat = 0; 1272 SharpFormat* sharpFormat = 0;
1273 if ( mode == 0 ) { // sharp 1273 if ( mode == 0 ) { // sharp
1274 sharpFormat = new SharpFormat () ; 1274 sharpFormat = new SharpFormat () ;
1275 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1275 loadSuccess = sharpFormat->load( calendar, mCalendar );
1276 1276
1277 } else 1277 } else
1278#endif 1278#endif
1279 if ( mode == 1 ) { // phone 1279 if ( mode == 1 ) { // phone
1280 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1280 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1281 mSyncManager->mPhoneDevice, 1281 mSyncManager->mPhoneDevice,
1282 mSyncManager->mPhoneConnection, 1282 mSyncManager->mPhoneConnection,
1283 mSyncManager->mPhoneModel); 1283 mSyncManager->mPhoneModel);
1284 loadSuccess = phoneFormat->load( calendar,mCalendar); 1284 loadSuccess = phoneFormat->load( calendar,mCalendar);
1285 1285
1286 } else { 1286 } else {
1287 emit tempDisableBR(false); 1287 emit tempDisableBR(false);
1288 return; 1288 return;
1289 } 1289 }
1290 if ( loadSuccess ) { 1290 if ( loadSuccess ) {
1291 getEventViewerDialog()->setSyncMode( true ); 1291 getEventViewerDialog()->setSyncMode( true );
1292 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1292 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1293 getEventViewerDialog()->setSyncMode( false ); 1293 getEventViewerDialog()->setSyncMode( false );
1294 qApp->processEvents(); 1294 qApp->processEvents();
1295 if ( syncOK ) { 1295 if ( syncOK ) {
1296 if ( mSyncManager->mWriteBackFile ) 1296 if ( mSyncManager->mWriteBackFile )
1297 { 1297 {
1298 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1298 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1299 Incidence* inc = iL.first(); 1299 Incidence* inc = iL.first();
1300 if ( phoneFormat ) { 1300 if ( phoneFormat ) {
1301 while ( inc ) { 1301 while ( inc ) {
1302 inc->removeID(mCurrentSyncDevice); 1302 inc->removeID(mCurrentSyncDevice);
1303 inc = iL.next(); 1303 inc = iL.next();
1304 } 1304 }
1305 } 1305 }
1306#ifndef DESKTOP_VERSION 1306#ifndef DESKTOP_VERSION
1307 if ( sharpFormat ) 1307 if ( sharpFormat )
1308 sharpFormat->save(calendar); 1308 sharpFormat->save(calendar);
1309#endif 1309#endif
1310 if ( phoneFormat ) 1310 if ( phoneFormat )
1311 phoneFormat->save(calendar); 1311 phoneFormat->save(calendar);
1312 iL = calendar->rawIncidences(); 1312 iL = calendar->rawIncidences();
1313 inc = iL.first(); 1313 inc = iL.first();
1314 Incidence* loc; 1314 Incidence* loc;
1315 while ( inc ) { 1315 while ( inc ) {
1316 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1316 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1317 loc = mCalendar->incidence(inc->uid() ); 1317 loc = mCalendar->incidence(inc->uid() );
1318 if ( loc ) { 1318 if ( loc ) {
1319 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1319 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1320 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1320 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1321 } 1321 }
1322 } 1322 }
1323 inc = iL.next(); 1323 inc = iL.next();
1324 } 1324 }
1325 Incidence* lse = getLastSyncEvent(); 1325 Incidence* lse = getLastSyncEvent();
1326 if ( lse ) { 1326 if ( lse ) {
1327 lse->setReadOnly( false ); 1327 lse->setReadOnly( false );
1328 lse->setDescription( "" ); 1328 lse->setDescription( "" );
1329 lse->setReadOnly( true ); 1329 lse->setReadOnly( true );
1330 } 1330 }
1331 } 1331 }
1332 } else { 1332 } else {
1333 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1333 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1334 } 1334 }
1335 setModified( true ); 1335 setModified( true );
1336 } else { 1336 } else {
1337 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1337 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1338 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1338 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1339 question, i18n("Ok")) ; 1339 question, i18n("Ok")) ;
1340 1340
1341 } 1341 }
1342 delete calendar; 1342 delete calendar;
1343 updateView(); 1343 updateView();
1344 emit tempDisableBR(false); 1344 emit tempDisableBR(false);
1345 return ;//syncOK; 1345 return ;//syncOK;
1346 1346
1347} 1347}
1348 1348
1349bool CalendarView::importBday() 1349bool CalendarView::importBday()
1350{ 1350{
1351#ifndef KORG_NOKABC 1351#ifndef KORG_NOKABC
1352 1352
1353#ifdef DESKTOP_VERSION 1353#ifdef DESKTOP_VERSION
1354 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1354 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1355 KABC::AddressBook::Iterator it; 1355 KABC::AddressBook::Iterator it;
1356 int count = 0; 1356 int count = 0;
1357 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1357 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1358 ++count; 1358 ++count;
1359 } 1359 }
1360 QProgressBar bar(count,0 ); 1360 QProgressBar bar(count,0 );
1361 int w = 300; 1361 int w = 300;
1362 if ( QApplication::desktop()->width() < 320 ) 1362 if ( QApplication::desktop()->width() < 320 )
1363 w = 220; 1363 w = 220;
1364 int h = bar.sizeHint().height() ; 1364 int h = bar.sizeHint().height() ;
1365 int dw = QApplication::desktop()->width(); 1365 int dw = QApplication::desktop()->width();
1366 int dh = QApplication::desktop()->height(); 1366 int dh = QApplication::desktop()->height();
1367 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1367 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1368 bar.show(); 1368 bar.show();
1369 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1369 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1370 qApp->processEvents(); 1370 qApp->processEvents();
1371 count = 0; 1371 count = 0;
1372 int addCount = 0; 1372 int addCount = 0;
1373 KCal::Attendee* a = 0; 1373 KCal::Attendee* a = 0;
1374 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1374 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1375 if ( ! bar.isVisible() ) 1375 if ( ! bar.isVisible() )
1376 return false; 1376 return false;
1377 bar.setProgress( count++ ); 1377 bar.setProgress( count++ );
1378 qApp->processEvents(); 1378 qApp->processEvents();
1379 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1379 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1380 if ( (*it).birthday().date().isValid() ){ 1380 if ( (*it).birthday().date().isValid() ){
1381 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1381 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1382 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1382 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1383 ++addCount; 1383 ++addCount;
1384 } 1384 }
1385 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1385 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1386 if ( anni.isValid() ){ 1386 if ( anni.isValid() ){
1387 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1387 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1388 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1388 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1389 ++addCount; 1389 ++addCount;
1390 } 1390 }
1391 } 1391 }
1392 updateView(); 1392 updateView();
1393 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1393 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1394#else //DESKTOP_VERSION 1394#else //DESKTOP_VERSION
1395 1395
1396 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1396 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1397 // the result should now arrive through method insertBirthdays 1397 // the result should now arrive through method insertBirthdays
1398 1398
1399#endif //DESKTOP_VERSION 1399#endif //DESKTOP_VERSION
1400 1400
1401#endif //KORG_NOKABC 1401#endif //KORG_NOKABC
1402 1402
1403 1403
1404 return true; 1404 return true;
1405} 1405}
1406 1406
1407// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1407// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1408void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1408void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1409 const QStringList& anniversaryList, const QStringList& realNameList, 1409 const QStringList& anniversaryList, const QStringList& realNameList,
1410 const QStringList& emailList, const QStringList& assembledNameList, 1410 const QStringList& emailList, const QStringList& assembledNameList,
1411 const QStringList& uidList) 1411 const QStringList& uidList)
1412{ 1412{
1413 qDebug("CalendarView::insertBirthdays"); 1413 qDebug("CalendarView::insertBirthdays");
1414 if (uid == this->name()) 1414 if (uid == this->name())
1415 { 1415 {
1416 int count = birthdayList.count(); 1416 int count = birthdayList.count();
1417 int addCount = 0; 1417 int addCount = 0;
1418 KCal::Attendee* a = 0; 1418 KCal::Attendee* a = 0;
1419 1419
1420 qDebug("CalView 1 %i", count); 1420 qDebug("CalView 1 %i", count);
1421 1421
1422 QProgressBar bar(count,0 ); 1422 QProgressBar bar(count,0 );
1423 int w = 300; 1423 int w = 300;
1424 if ( QApplication::desktop()->width() < 320 ) 1424 if ( QApplication::desktop()->width() < 320 )
1425 w = 220; 1425 w = 220;
1426 int h = bar.sizeHint().height() ; 1426 int h = bar.sizeHint().height() ;
1427 int dw = QApplication::desktop()->width(); 1427 int dw = QApplication::desktop()->width();
1428 int dh = QApplication::desktop()->height(); 1428 int dh = QApplication::desktop()->height();
1429 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1429 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1430 bar.show(); 1430 bar.show();
1431 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1431 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1432 qApp->processEvents(); 1432 qApp->processEvents();
1433 1433
1434 QDate birthday; 1434 QDate birthday;
1435 QDate anniversary; 1435 QDate anniversary;
1436 QString realName; 1436 QString realName;
1437 QString email; 1437 QString email;
1438 QString assembledName; 1438 QString assembledName;
1439 QString uid; 1439 QString uid;
1440 bool ok = true; 1440 bool ok = true;
1441 for ( int i = 0; i < count; i++) 1441 for ( int i = 0; i < count; i++)
1442 { 1442 {
1443 if ( ! bar.isVisible() ) 1443 if ( ! bar.isVisible() )
1444 return; 1444 return;
1445 bar.setProgress( i ); 1445 bar.setProgress( i );
1446 qApp->processEvents(); 1446 qApp->processEvents();
1447 1447
1448 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1448 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1449 if (!ok) { 1449 if (!ok) {
1450 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1450 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1451 } 1451 }
1452 1452
1453 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1453 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1454 if (!ok) { 1454 if (!ok) {
1455 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1455 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1456 } 1456 }
1457 realName = realNameList[i]; 1457 realName = realNameList[i];
1458 email = emailList[i]; 1458 email = emailList[i];
1459 assembledName = assembledNameList[i]; 1459 assembledName = assembledNameList[i];
1460 uid = uidList[i]; 1460 uid = uidList[i];
1461 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1461 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1462 1462
1463 if ( birthday.isValid() ){ 1463 if ( birthday.isValid() ){
1464 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1464 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1465 KCal::Attendee::ReqParticipant,uid) ; 1465 KCal::Attendee::ReqParticipant,uid) ;
1466 if ( addAnniversary( birthday, assembledName, a, true ) ) 1466 if ( addAnniversary( birthday, assembledName, a, true ) )
1467 ++addCount; 1467 ++addCount;
1468 } 1468 }
1469 1469
1470 if ( anniversary.isValid() ){ 1470 if ( anniversary.isValid() ){
1471 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1471 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1472 KCal::Attendee::ReqParticipant,uid) ; 1472 KCal::Attendee::ReqParticipant,uid) ;
1473 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1473 if ( addAnniversary( anniversary, assembledName, a, false ) )
1474 ++addCount; 1474 ++addCount;
1475 } 1475 }
1476 } 1476 }
1477 1477
1478 updateView(); 1478 updateView();
1479 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1479 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1480 1480
1481 } 1481 }
1482 1482
1483} 1483}
1484 1484
1485 1485
1486 1486
1487bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1487bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1488{ 1488{
1489 //qDebug("addAnni "); 1489 //qDebug("addAnni ");
1490 Event * ev = new Event(); 1490 Event * ev = new Event();
1491 if ( a ) { 1491 if ( a ) {
1492 ev->addAttendee( a ); 1492 ev->addAttendee( a );
1493 } 1493 }
1494 QString kind; 1494 QString kind;
1495 if ( birthday ) 1495 if ( birthday )
1496 kind = i18n( "Birthday" ); 1496 kind = i18n( "Birthday" );
1497 else 1497 else
1498 kind = i18n( "Anniversary" ); 1498 kind = i18n( "Anniversary" );
1499 ev->setSummary( name + " - " + kind ); 1499 ev->setSummary( name + " - " + kind );
1500 ev->setOrganizer(a->email()); 1500 ev->setOrganizer(a->email());
1501 ev->setCategories( kind ); 1501 ev->setCategories( kind );
1502 ev->setDtStart( QDateTime(date) ); 1502 ev->setDtStart( QDateTime(date) );
1503 ev->setDtEnd( QDateTime(date) ); 1503 ev->setDtEnd( QDateTime(date) );
1504 ev->setFloats( true ); 1504 ev->setFloats( true );
1505 Recurrence * rec = ev->recurrence(); 1505 Recurrence * rec = ev->recurrence();
1506 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1506 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1507 rec->addYearlyNum( date.month() ); 1507 rec->addYearlyNum( date.month() );
1508 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1508 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1509 delete ev; 1509 delete ev;
1510 return false; 1510 return false;
1511 } 1511 }
1512 return true; 1512 return true;
1513 1513
1514} 1514}
1515bool CalendarView::importQtopia( const QString &categories, 1515bool CalendarView::importQtopia( const QString &categories,
1516 const QString &datebook, 1516 const QString &datebook,
1517 const QString &todolist ) 1517 const QString &todolist )
1518{ 1518{
1519 1519
1520 QtopiaFormat qtopiaFormat; 1520 QtopiaFormat qtopiaFormat;
1521 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1521 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1522 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1522 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1523 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1523 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1524 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1524 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1525 1525
1526 updateView(); 1526 updateView();
1527 return true; 1527 return true;
1528 1528
1529#if 0 1529#if 0
1530 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1530 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1531 mCurrentSyncDevice = "qtopia-XML"; 1531 mCurrentSyncDevice = "qtopia-XML";
1532 if ( mSyncManager->mAskForPreferences ) 1532 if ( mSyncManager->mAskForPreferences )
1533 edit_sync_options(); 1533 edit_sync_options();
1534 qApp->processEvents(); 1534 qApp->processEvents();
1535 CalendarLocal* calendar = new CalendarLocal(); 1535 CalendarLocal* calendar = new CalendarLocal();
1536 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1536 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1537 bool syncOK = false; 1537 bool syncOK = false;
1538 QtopiaFormat qtopiaFormat; 1538 QtopiaFormat qtopiaFormat;
1539 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1539 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1540 bool loadOk = true; 1540 bool loadOk = true;
1541 if ( !categories.isEmpty() ) 1541 if ( !categories.isEmpty() )
1542 loadOk = qtopiaFormat.load( calendar, categories ); 1542 loadOk = qtopiaFormat.load( calendar, categories );
1543 if ( loadOk && !datebook.isEmpty() ) 1543 if ( loadOk && !datebook.isEmpty() )
1544 loadOk = qtopiaFormat.load( calendar, datebook ); 1544 loadOk = qtopiaFormat.load( calendar, datebook );
1545 if ( loadOk && !todolist.isEmpty() ) 1545 if ( loadOk && !todolist.isEmpty() )
1546 loadOk = qtopiaFormat.load( calendar, todolist ); 1546 loadOk = qtopiaFormat.load( calendar, todolist );
1547 1547
1548 if ( loadOk ) { 1548 if ( loadOk ) {
1549 getEventViewerDialog()->setSyncMode( true ); 1549 getEventViewerDialog()->setSyncMode( true );
1550 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1550 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1551 getEventViewerDialog()->setSyncMode( false ); 1551 getEventViewerDialog()->setSyncMode( false );
1552 qApp->processEvents(); 1552 qApp->processEvents();
1553 if ( syncOK ) { 1553 if ( syncOK ) {
1554 if ( mSyncManager->mWriteBackFile ) 1554 if ( mSyncManager->mWriteBackFile )
1555 { 1555 {
1556 // write back XML file 1556 // write back XML file
1557 1557
1558 } 1558 }
1559 setModified( true ); 1559 setModified( true );
1560 } 1560 }
1561 } else { 1561 } else {
1562 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1562 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1563 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1563 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1564 question, i18n("Ok")) ; 1564 question, i18n("Ok")) ;
1565 } 1565 }
1566 delete calendar; 1566 delete calendar;
1567 updateView(); 1567 updateView();
1568 return syncOK; 1568 return syncOK;
1569 1569
1570 1570
1571#endif 1571#endif
1572 1572
1573} 1573}
1574 1574
1575void CalendarView::setSyncEventsReadOnly() 1575void CalendarView::setSyncEventsReadOnly()
1576{ 1576{
1577 Event * ev; 1577 Event * ev;
1578 QPtrList<Event> eL = mCalendar->rawEvents(); 1578 QPtrList<Event> eL = mCalendar->rawEvents();
1579 ev = eL.first(); 1579 ev = eL.first();
1580 while ( ev ) { 1580 while ( ev ) {
1581 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1581 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1582 ev->setReadOnly( true ); 1582 ev->setReadOnly( true );
1583 ev = eL.next(); 1583 ev = eL.next();
1584 } 1584 }
1585} 1585}
1586bool CalendarView::openCalendar(QString filename, bool merge) 1586bool CalendarView::openCalendar(QString filename, bool merge)
1587{ 1587{
1588 1588
1589 if (filename.isEmpty()) { 1589 if (filename.isEmpty()) {
1590 return false; 1590 return false;