summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 4e29d6f..59bf615 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -943,512 +943,513 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
943 eventRSync = (Event*) eventR->clone(); 943 eventRSync = (Event*) eventR->clone();
944 remote->deleteEvent(eventR ); 944 remote->deleteEvent(eventR );
945 945
946 } else { 946 } else {
947 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 947 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
948 eventRSync = (Event*)eventLSync->clone(); 948 eventRSync = (Event*)eventLSync->clone();
949 } else { 949 } else {
950 fullDateRange = true; 950 fullDateRange = true;
951 eventRSync = new Event(); 951 eventRSync = new Event();
952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
954 eventRSync->setDtStart( mLastCalendarSync ); 954 eventRSync->setDtStart( mLastCalendarSync );
955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
956 eventRSync->setCategories( i18n("SyncEvent") ); 956 eventRSync->setCategories( i18n("SyncEvent") );
957 } 957 }
958 } 958 }
959 if ( eventLSync->dtStart() == mLastCalendarSync ) 959 if ( eventLSync->dtStart() == mLastCalendarSync )
960 fullDateRange = true; 960 fullDateRange = true;
961 961
962 if ( ! fullDateRange ) { 962 if ( ! fullDateRange ) {
963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
964 964
965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
967 fullDateRange = true; 967 fullDateRange = true;
968 } 968 }
969 } 969 }
970 if ( mSyncManager->syncWithDesktop() ) { 970 if ( mSyncManager->syncWithDesktop() ) {
971 fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync ); 971 fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync );
972 } 972 }
973 if ( fullDateRange ) 973 if ( fullDateRange )
974 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 974 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
975 else 975 else
976 mLastCalendarSync = eventLSync->dtStart(); 976 mLastCalendarSync = eventLSync->dtStart();
977 // for resyncing if own file has changed 977 // for resyncing if own file has changed
978 if ( mCurrentSyncDevice == "deleteaftersync" ) { 978 if ( mCurrentSyncDevice == "deleteaftersync" ) {
979 mLastCalendarSync = loadedFileVersion; 979 mLastCalendarSync = loadedFileVersion;
980 //qDebug("setting mLastCalendarSync "); 980 //qDebug("setting mLastCalendarSync ");
981 } 981 }
982 //qDebug("*************************** "); 982 //qDebug("*************************** ");
983 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 983 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
984 QPtrList<Incidence> er = remote->rawIncidences(); 984 QPtrList<Incidence> er = remote->rawIncidences();
985 Incidence* inR = er.first(); 985 Incidence* inR = er.first();
986 Incidence* inL; 986 Incidence* inL;
987 QProgressBar bar( er.count(),0 ); 987 QProgressBar bar( er.count(),0 );
988 bar.setCaption (i18n("Syncing - close to abort!") ); 988 bar.setCaption (i18n("Syncing - close to abort!") );
989 989
990 int w = 300; 990 int w = 300;
991 if ( QApplication::desktop()->width() < 320 ) 991 if ( QApplication::desktop()->width() < 320 )
992 w = 220; 992 w = 220;
993 int h = bar.sizeHint().height() ; 993 int h = bar.sizeHint().height() ;
994 int dw = QApplication::desktop()->width(); 994 int dw = QApplication::desktop()->width();
995 int dh = QApplication::desktop()->height(); 995 int dh = QApplication::desktop()->height();
996 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 996 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
997 bar.show(); 997 bar.show();
998 int modulo = (er.count()/10)+1; 998 int modulo = (er.count()/10)+1;
999 int incCounter = 0; 999 int incCounter = 0;
1000 while ( inR ) { 1000 while ( inR ) {
1001 if ( ! bar.isVisible() ) 1001 if ( ! bar.isVisible() )
1002 return false; 1002 return false;
1003 if ( incCounter % modulo == 0 ) 1003 if ( incCounter % modulo == 0 )
1004 bar.setProgress( incCounter ); 1004 bar.setProgress( incCounter );
1005 ++incCounter; 1005 ++incCounter;
1006 uid = inR->uid(); 1006 uid = inR->uid();
1007 bool skipIncidence = false; 1007 bool skipIncidence = false;
1008 if ( uid.left(15) == QString("last-syncEvent-") ) 1008 if ( uid.left(15) == QString("last-syncEvent-") )
1009 skipIncidence = true; 1009 skipIncidence = true;
1010 QString idS; 1010 QString idS;
1011 qApp->processEvents(); 1011 qApp->processEvents();
1012 if ( !skipIncidence ) { 1012 if ( !skipIncidence ) {
1013 inL = local->incidence( uid ); 1013 inL = local->incidence( uid );
1014 if ( inL ) { // maybe conflict - same uid in both calendars 1014 if ( inL ) { // maybe conflict - same uid in both calendars
1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1016 //qDebug("take %d %s ", take, inL->summary().latin1()); 1016 //qDebug("take %d %s ", take, inL->summary().latin1());
1017 if ( take == 3 ) 1017 if ( take == 3 )
1018 return false; 1018 return false;
1019 if ( take == 1 ) {// take local ********************** 1019 if ( take == 1 ) {// take local **********************
1020 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1020 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1021 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1021 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1022 else 1022 else
1023 idS = inR->IDStr(); 1023 idS = inR->IDStr();
1024 remote->deleteIncidence( inR ); 1024 remote->deleteIncidence( inR );
1025 inR = inL->clone(); 1025 inR = inL->clone();
1026 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1026 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1027 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1027 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1028 inR->setIDStr( idS ); 1028 inR->setIDStr( idS );
1029 remote->addIncidence( inR ); 1029 remote->addIncidence( inR );
1030 if ( mSyncManager->syncWithDesktop() ) 1030 if ( mSyncManager->syncWithDesktop() )
1031 inR->setPilotId( 2 ); 1031 inR->setPilotId( 2 );
1032 ++changedRemote; 1032 ++changedRemote;
1033 } else {// take remote ********************** 1033 } else {// take remote **********************
1034 idS = inL->IDStr(); 1034 idS = inL->IDStr();
1035 int pid = inL->pilotId(); 1035 int pid = inL->pilotId();
1036 local->deleteIncidence( inL ); 1036 local->deleteIncidence( inL );
1037 inL = inR->clone(); 1037 inL = inR->clone();
1038 if ( mSyncManager->syncWithDesktop() ) 1038 if ( mSyncManager->syncWithDesktop() )
1039 inL->setPilotId( pid ); 1039 inL->setPilotId( pid );
1040 inL->setIDStr( idS ); 1040 inL->setIDStr( idS );
1041 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1041 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1042 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1042 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1043 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1043 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1044 } 1044 }
1045 local->addIncidence( inL ); 1045 local->addIncidence( inL );
1046 ++changedLocal; 1046 ++changedLocal;
1047 } 1047 }
1048 } 1048 }
1049 } else { // no conflict ********** add or delete remote 1049 } else { // no conflict ********** add or delete remote
1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1051 QString des = eventLSync->description(); 1051 QString des = eventLSync->description();
1052 QString pref = "e"; 1052 QString pref = "e";
1053 if ( inR->type() == "Todo" ) 1053 if ( inR->type() == "Todo" )
1054 pref = "t"; 1054 pref = "t";
1055 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1055 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1056 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1056 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1057 //remote->deleteIncidence( inR ); 1057 //remote->deleteIncidence( inR );
1058 ++deletedEventR; 1058 ++deletedEventR;
1059 } else { 1059 } else {
1060 inR->setLastModified( modifiedCalendar ); 1060 inR->setLastModified( modifiedCalendar );
1061 inL = inR->clone(); 1061 inL = inR->clone();
1062 inL->setIDStr( ":" ); 1062 inL->setIDStr( ":" );
1063 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1063 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1064 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1064 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1065 local->addIncidence( inL ); 1065 local->addIncidence( inL );
1066 ++addedEvent; 1066 ++addedEvent;
1067 } 1067 }
1068 } else { 1068 } else {
1069 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1069 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1070 inR->setLastModified( modifiedCalendar ); 1070 inR->setLastModified( modifiedCalendar );
1071 inL = inR->clone(); 1071 inL = inR->clone();
1072 inL->setIDStr( ":" ); 1072 inL->setIDStr( ":" );
1073 local->addIncidence( inL ); 1073 local->addIncidence( inL );
1074 ++addedEvent; 1074 ++addedEvent;
1075 } else { 1075 } else {
1076 checkExternSyncEvent(eventRSyncSharp, inR); 1076 checkExternSyncEvent(eventRSyncSharp, inR);
1077 remote->deleteIncidence( inR ); 1077 remote->deleteIncidence( inR );
1078 ++deletedEventR; 1078 ++deletedEventR;
1079 } 1079 }
1080 } 1080 }
1081 } 1081 }
1082 } 1082 }
1083 inR = er.next(); 1083 inR = er.next();
1084 } 1084 }
1085 QPtrList<Incidence> el = local->rawIncidences(); 1085 QPtrList<Incidence> el = local->rawIncidences();
1086 inL = el.first(); 1086 inL = el.first();
1087 modulo = (el.count()/10)+1; 1087 modulo = (el.count()/10)+1;
1088 bar.setCaption (i18n("Add / remove events") ); 1088 bar.setCaption (i18n("Add / remove events") );
1089 bar.setTotalSteps ( el.count() ) ; 1089 bar.setTotalSteps ( el.count() ) ;
1090 bar.show(); 1090 bar.show();
1091 incCounter = 0; 1091 incCounter = 0;
1092 1092
1093 while ( inL ) { 1093 while ( inL ) {
1094 1094
1095 qApp->processEvents(); 1095 qApp->processEvents();
1096 if ( ! bar.isVisible() ) 1096 if ( ! bar.isVisible() )
1097 return false; 1097 return false;
1098 if ( incCounter % modulo == 0 ) 1098 if ( incCounter % modulo == 0 )
1099 bar.setProgress( incCounter ); 1099 bar.setProgress( incCounter );
1100 ++incCounter; 1100 ++incCounter;
1101 uid = inL->uid(); 1101 uid = inL->uid();
1102 bool skipIncidence = false; 1102 bool skipIncidence = false;
1103 if ( uid.left(15) == QString("last-syncEvent-") ) 1103 if ( uid.left(15) == QString("last-syncEvent-") )
1104 skipIncidence = true; 1104 skipIncidence = true;
1105 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1105 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1106 skipIncidence = true; 1106 skipIncidence = true;
1107 if ( !skipIncidence ) { 1107 if ( !skipIncidence ) {
1108 inR = remote->incidence( uid ); 1108 inR = remote->incidence( uid );
1109 if ( ! inR ) { // no conflict ********** add or delete local 1109 if ( ! inR ) { // no conflict ********** add or delete local
1110 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1110 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1111 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1111 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1112 checkExternSyncEvent(eventLSyncSharp, inL); 1112 checkExternSyncEvent(eventLSyncSharp, inL);
1113 local->deleteIncidence( inL ); 1113 local->deleteIncidence( inL );
1114 ++deletedEventL; 1114 ++deletedEventL;
1115 } else { 1115 } else {
1116 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1116 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1117 inL->removeID(mCurrentSyncDevice ); 1117 inL->removeID(mCurrentSyncDevice );
1118 ++addedEventR; 1118 ++addedEventR;
1119 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1119 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1120 inL->setLastModified( modifiedCalendar ); 1120 inL->setLastModified( modifiedCalendar );
1121 inR = inL->clone(); 1121 inR = inL->clone();
1122 inR->setIDStr( ":" ); 1122 inR->setIDStr( ":" );
1123 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1123 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1124 remote->addIncidence( inR ); 1124 remote->addIncidence( inR );
1125 } 1125 }
1126 } 1126 }
1127 } else { 1127 } else {
1128 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1128 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1129 checkExternSyncEvent(eventLSyncSharp, inL); 1129 checkExternSyncEvent(eventLSyncSharp, inL);
1130 local->deleteIncidence( inL ); 1130 local->deleteIncidence( inL );
1131 ++deletedEventL; 1131 ++deletedEventL;
1132 } else { 1132 } else {
1133 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1133 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1134 ++addedEventR; 1134 ++addedEventR;
1135 inL->setLastModified( modifiedCalendar ); 1135 inL->setLastModified( modifiedCalendar );
1136 inR = inL->clone(); 1136 inR = inL->clone();
1137 inR->setIDStr( ":" ); 1137 inR->setIDStr( ":" );
1138 remote->addIncidence( inR ); 1138 remote->addIncidence( inR );
1139 } 1139 }
1140 } 1140 }
1141 } 1141 }
1142 } 1142 }
1143 } 1143 }
1144 inL = el.next(); 1144 inL = el.next();
1145 } 1145 }
1146 int delFut = 0; 1146 int delFut = 0;
1147 int remRem = 0; 1147 int remRem = 0;
1148 if ( mSyncManager->mWriteBackInFuture ) { 1148 if ( mSyncManager->mWriteBackInFuture ) {
1149 er = remote->rawIncidences(); 1149 er = remote->rawIncidences();
1150 remRem = er.count(); 1150 remRem = er.count();
1151 inR = er.first(); 1151 inR = er.first();
1152 QDateTime dt; 1152 QDateTime dt;
1153 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1153 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1154 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); 1154 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 );
1155 while ( inR ) { 1155 while ( inR ) {
1156 if ( inR->type() == "Todo" ) { 1156 if ( inR->type() == "Todo" ) {
1157 Todo * t = (Todo*)inR; 1157 Todo * t = (Todo*)inR;
1158 if ( t->hasDueDate() ) 1158 if ( t->hasDueDate() )
1159 dt = t->dtDue(); 1159 dt = t->dtDue();
1160 else 1160 else
1161 dt = cur.addSecs( 62 ); 1161 dt = cur.addSecs( 62 );
1162 } 1162 }
1163 else if (inR->type() == "Event" ) { 1163 else if (inR->type() == "Event" ) {
1164 bool ok; 1164 bool ok;
1165 dt = inR->getNextOccurence( cur, &ok ); 1165 dt = inR->getNextOccurence( cur, &ok );
1166 if ( !ok ) 1166 if ( !ok )
1167 dt = cur.addSecs( -62 ); 1167 dt = cur.addSecs( -62 );
1168 } 1168 }
1169 else 1169 else
1170 dt = inR->dtStart(); 1170 dt = inR->dtStart();
1171 if ( dt < cur || dt > end ) { 1171 if ( dt < cur || dt > end ) {
1172 remote->deleteIncidence( inR ); 1172 remote->deleteIncidence( inR );
1173 ++delFut; 1173 ++delFut;
1174 } 1174 }
1175 inR = er.next(); 1175 inR = er.next();
1176 } 1176 }
1177 } 1177 }
1178 bar.hide(); 1178 bar.hide();
1179 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1179 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1180 eventLSync->setReadOnly( false ); 1180 eventLSync->setReadOnly( false );
1181 eventLSync->setDtStart( mLastCalendarSync ); 1181 eventLSync->setDtStart( mLastCalendarSync );
1182 eventRSync->setDtStart( mLastCalendarSync ); 1182 eventRSync->setDtStart( mLastCalendarSync );
1183 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1183 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1184 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1184 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1185 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1185 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1186 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1186 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1187 eventLSync->setReadOnly( true ); 1187 eventLSync->setReadOnly( true );
1188 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1188 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1189 remote->addEvent( eventRSync ); 1189 remote->addEvent( eventRSync );
1190 else 1190 else
1191 delete eventRSync; 1191 delete eventRSync;
1192 QString mes; 1192 QString mes;
1193 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 ); 1193 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 );
1194 QString delmess; 1194 QString delmess;
1195 if ( delFut ) { 1195 if ( delFut ) {
1196 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); 1196 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);
1197 mes += delmess; 1197 mes += delmess;
1198 } 1198 }
1199 mes = i18n("Local calendar changed!\n") +mes;
1199 mCalendar->checkAlarmForIncidence( 0, true ); 1200 mCalendar->checkAlarmForIncidence( 0, true );
1200 qDebug( mes ); 1201 qDebug( mes );
1201 if ( mSyncManager->mShowSyncSummary ) { 1202 if ( mSyncManager->mShowSyncSummary ) {
1202 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1203 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1203 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1204 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1204 qDebug("cancelled "); 1205 qDebug("cancelled ");
1205 return false; 1206 return false;
1206 } 1207 }
1207 } 1208 }
1208 return syncOK; 1209 return syncOK;
1209} 1210}
1210 1211
1211void CalendarView::setSyncDevice( QString s ) 1212void CalendarView::setSyncDevice( QString s )
1212{ 1213{
1213 mCurrentSyncDevice= s; 1214 mCurrentSyncDevice= s;
1214} 1215}
1215void CalendarView::setSyncName( QString s ) 1216void CalendarView::setSyncName( QString s )
1216{ 1217{
1217 mCurrentSyncName= s; 1218 mCurrentSyncName= s;
1218} 1219}
1219bool CalendarView::syncCalendar(QString filename, int mode) 1220bool CalendarView::syncCalendar(QString filename, int mode)
1220{ 1221{
1221 //qDebug("syncCalendar %s ", filename.latin1()); 1222 //qDebug("syncCalendar %s ", filename.latin1());
1222 mGlobalSyncMode = SYNC_MODE_NORMAL; 1223 mGlobalSyncMode = SYNC_MODE_NORMAL;
1223 CalendarLocal* calendar = new CalendarLocal(); 1224 CalendarLocal* calendar = new CalendarLocal();
1224 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1225 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1225 FileStorage* storage = new FileStorage( calendar ); 1226 FileStorage* storage = new FileStorage( calendar );
1226 bool syncOK = false; 1227 bool syncOK = false;
1227 storage->setFileName( filename ); 1228 storage->setFileName( filename );
1228 // qDebug("loading ... "); 1229 // qDebug("loading ... ");
1229 if ( storage->load() ) { 1230 if ( storage->load() ) {
1230 getEventViewerDialog()->setSyncMode( true ); 1231 getEventViewerDialog()->setSyncMode( true );
1231 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1232 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1232 getEventViewerDialog()->setSyncMode( false ); 1233 getEventViewerDialog()->setSyncMode( false );
1233 if ( syncOK ) { 1234 if ( syncOK ) {
1234 if ( mSyncManager->mWriteBackFile ) 1235 if ( mSyncManager->mWriteBackFile )
1235 { 1236 {
1236 storage->setSaveFormat( new ICalFormat() ); 1237 storage->setSaveFormat( new ICalFormat() );
1237 storage->save(); 1238 storage->save();
1238 } 1239 }
1239 } 1240 }
1240 setModified( true ); 1241 setModified( true );
1241 } 1242 }
1242 delete storage; 1243 delete storage;
1243 delete calendar; 1244 delete calendar;
1244 if ( syncOK ) 1245 if ( syncOK )
1245 updateView(); 1246 updateView();
1246 return syncOK; 1247 return syncOK;
1247} 1248}
1248 1249
1249void CalendarView::syncExternal( int mode ) 1250void CalendarView::syncExternal( int mode )
1250{ 1251{
1251 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1252 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1252 1253
1253 qApp->processEvents(); 1254 qApp->processEvents();
1254 CalendarLocal* calendar = new CalendarLocal(); 1255 CalendarLocal* calendar = new CalendarLocal();
1255 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1256 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1256 bool syncOK = false; 1257 bool syncOK = false;
1257 bool loadSuccess = false; 1258 bool loadSuccess = false;
1258 PhoneFormat* phoneFormat = 0; 1259 PhoneFormat* phoneFormat = 0;
1259 emit tempDisableBR(true); 1260 emit tempDisableBR(true);
1260#ifndef DESKTOP_VERSION 1261#ifndef DESKTOP_VERSION
1261 SharpFormat* sharpFormat = 0; 1262 SharpFormat* sharpFormat = 0;
1262 if ( mode == 0 ) { // sharp 1263 if ( mode == 0 ) { // sharp
1263 sharpFormat = new SharpFormat () ; 1264 sharpFormat = new SharpFormat () ;
1264 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1265 loadSuccess = sharpFormat->load( calendar, mCalendar );
1265 1266
1266 } else 1267 } else
1267#endif 1268#endif
1268 if ( mode == 1 ) { // phone 1269 if ( mode == 1 ) { // phone
1269 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1270 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1270 mSyncManager->mPhoneDevice, 1271 mSyncManager->mPhoneDevice,
1271 mSyncManager->mPhoneConnection, 1272 mSyncManager->mPhoneConnection,
1272 mSyncManager->mPhoneModel); 1273 mSyncManager->mPhoneModel);
1273 loadSuccess = phoneFormat->load( calendar,mCalendar); 1274 loadSuccess = phoneFormat->load( calendar,mCalendar);
1274 1275
1275 } else { 1276 } else {
1276 emit tempDisableBR(false); 1277 emit tempDisableBR(false);
1277 return; 1278 return;
1278 } 1279 }
1279 if ( loadSuccess ) { 1280 if ( loadSuccess ) {
1280 getEventViewerDialog()->setSyncMode( true ); 1281 getEventViewerDialog()->setSyncMode( true );
1281 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1282 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1282 getEventViewerDialog()->setSyncMode( false ); 1283 getEventViewerDialog()->setSyncMode( false );
1283 qApp->processEvents(); 1284 qApp->processEvents();
1284 if ( syncOK ) { 1285 if ( syncOK ) {
1285 if ( mSyncManager->mWriteBackFile ) 1286 if ( mSyncManager->mWriteBackFile )
1286 { 1287 {
1287 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1288 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1288 Incidence* inc = iL.first(); 1289 Incidence* inc = iL.first();
1289 if ( phoneFormat ) { 1290 if ( phoneFormat ) {
1290 while ( inc ) { 1291 while ( inc ) {
1291 inc->removeID(mCurrentSyncDevice); 1292 inc->removeID(mCurrentSyncDevice);
1292 inc = iL.next(); 1293 inc = iL.next();
1293 } 1294 }
1294 } 1295 }
1295#ifndef DESKTOP_VERSION 1296#ifndef DESKTOP_VERSION
1296 if ( sharpFormat ) 1297 if ( sharpFormat )
1297 sharpFormat->save(calendar); 1298 sharpFormat->save(calendar);
1298#endif 1299#endif
1299 if ( phoneFormat ) 1300 if ( phoneFormat )
1300 phoneFormat->save(calendar); 1301 phoneFormat->save(calendar);
1301 iL = calendar->rawIncidences(); 1302 iL = calendar->rawIncidences();
1302 inc = iL.first(); 1303 inc = iL.first();
1303 Incidence* loc; 1304 Incidence* loc;
1304 while ( inc ) { 1305 while ( inc ) {
1305 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1306 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1306 loc = mCalendar->incidence(inc->uid() ); 1307 loc = mCalendar->incidence(inc->uid() );
1307 if ( loc ) { 1308 if ( loc ) {
1308 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1309 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1309 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1310 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1310 } 1311 }
1311 } 1312 }
1312 inc = iL.next(); 1313 inc = iL.next();
1313 } 1314 }
1314 Incidence* lse = getLastSyncEvent(); 1315 Incidence* lse = getLastSyncEvent();
1315 if ( lse ) { 1316 if ( lse ) {
1316 lse->setReadOnly( false ); 1317 lse->setReadOnly( false );
1317 lse->setDescription( "" ); 1318 lse->setDescription( "" );
1318 lse->setReadOnly( true ); 1319 lse->setReadOnly( true );
1319 } 1320 }
1320 } 1321 }
1321 } else { 1322 } else {
1322 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1323 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1323 } 1324 }
1324 setModified( true ); 1325 setModified( true );
1325 } else { 1326 } else {
1326 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1327 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1327 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1328 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1328 question, i18n("Ok")) ; 1329 question, i18n("Ok")) ;
1329 1330
1330 } 1331 }
1331 delete calendar; 1332 delete calendar;
1332 updateView(); 1333 updateView();
1333 emit tempDisableBR(false); 1334 emit tempDisableBR(false);
1334 return ;//syncOK; 1335 return ;//syncOK;
1335 1336
1336} 1337}
1337 1338
1338bool CalendarView::importBday() 1339bool CalendarView::importBday()
1339{ 1340{
1340#ifndef KORG_NOKABC 1341#ifndef KORG_NOKABC
1341 1342
1342#ifdef DESKTOP_VERSION 1343#ifdef DESKTOP_VERSION
1343 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1344 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1344 KABC::AddressBook::Iterator it; 1345 KABC::AddressBook::Iterator it;
1345 int count = 0; 1346 int count = 0;
1346 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1347 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1347 ++count; 1348 ++count;
1348 } 1349 }
1349 QProgressBar bar(count,0 ); 1350 QProgressBar bar(count,0 );
1350 int w = 300; 1351 int w = 300;
1351 if ( QApplication::desktop()->width() < 320 ) 1352 if ( QApplication::desktop()->width() < 320 )
1352 w = 220; 1353 w = 220;
1353 int h = bar.sizeHint().height() ; 1354 int h = bar.sizeHint().height() ;
1354 int dw = QApplication::desktop()->width(); 1355 int dw = QApplication::desktop()->width();
1355 int dh = QApplication::desktop()->height(); 1356 int dh = QApplication::desktop()->height();
1356 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1357 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1357 bar.show(); 1358 bar.show();
1358 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1359 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1359 qApp->processEvents(); 1360 qApp->processEvents();
1360 count = 0; 1361 count = 0;
1361 int addCount = 0; 1362 int addCount = 0;
1362 KCal::Attendee* a = 0; 1363 KCal::Attendee* a = 0;
1363 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1364 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1364 if ( ! bar.isVisible() ) 1365 if ( ! bar.isVisible() )
1365 return false; 1366 return false;
1366 bar.setProgress( count++ ); 1367 bar.setProgress( count++ );
1367 qApp->processEvents(); 1368 qApp->processEvents();
1368 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1369 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1369 if ( (*it).birthday().date().isValid() ){ 1370 if ( (*it).birthday().date().isValid() ){
1370 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1371 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1371 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1372 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1372 ++addCount; 1373 ++addCount;
1373 } 1374 }
1374 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1375 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1375 if ( anni.isValid() ){ 1376 if ( anni.isValid() ){
1376 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1377 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1377 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1378 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1378 ++addCount; 1379 ++addCount;
1379 } 1380 }
1380 } 1381 }
1381 updateView(); 1382 updateView();
1382 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1383 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1383#else //DESKTOP_VERSION 1384#else //DESKTOP_VERSION
1384 1385
1385 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1386 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1386 // the result should now arrive through method insertBirthdays 1387 // the result should now arrive through method insertBirthdays
1387 1388
1388#endif //DESKTOP_VERSION 1389#endif //DESKTOP_VERSION
1389 1390
1390#endif //KORG_NOKABC 1391#endif //KORG_NOKABC
1391 1392
1392 1393
1393 return true; 1394 return true;
1394} 1395}
1395 1396
1396// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1397// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1397void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1398void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1398 const QStringList& anniversaryList, const QStringList& realNameList, 1399 const QStringList& anniversaryList, const QStringList& realNameList,
1399 const QStringList& emailList, const QStringList& assembledNameList, 1400 const QStringList& emailList, const QStringList& assembledNameList,
1400 const QStringList& uidList) 1401 const QStringList& uidList)
1401{ 1402{
1402 qDebug("CalendarView::insertBirthdays"); 1403 qDebug("CalendarView::insertBirthdays");
1403 if (uid == this->name()) 1404 if (uid == this->name())
1404 { 1405 {
1405 int count = birthdayList.count(); 1406 int count = birthdayList.count();
1406 int addCount = 0; 1407 int addCount = 0;
1407 KCal::Attendee* a = 0; 1408 KCal::Attendee* a = 0;
1408 1409
1409 qDebug("CalView 1 %i", count); 1410 qDebug("CalView 1 %i", count);
1410 1411
1411 QProgressBar bar(count,0 ); 1412 QProgressBar bar(count,0 );
1412 int w = 300; 1413 int w = 300;
1413 if ( QApplication::desktop()->width() < 320 ) 1414 if ( QApplication::desktop()->width() < 320 )
1414 w = 220; 1415 w = 220;
1415 int h = bar.sizeHint().height() ; 1416 int h = bar.sizeHint().height() ;
1416 int dw = QApplication::desktop()->width(); 1417 int dw = QApplication::desktop()->width();
1417 int dh = QApplication::desktop()->height(); 1418 int dh = QApplication::desktop()->height();
1418 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1419 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1419 bar.show(); 1420 bar.show();
1420 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1421 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1421 qApp->processEvents(); 1422 qApp->processEvents();
1422 1423
1423 QDate birthday; 1424 QDate birthday;
1424 QDate anniversary; 1425 QDate anniversary;
1425 QString realName; 1426 QString realName;
1426 QString email; 1427 QString email;
1427 QString assembledName; 1428 QString assembledName;
1428 QString uid; 1429 QString uid;
1429 bool ok = true; 1430 bool ok = true;
1430 for ( int i = 0; i < count; i++) 1431 for ( int i = 0; i < count; i++)
1431 { 1432 {
1432 if ( ! bar.isVisible() ) 1433 if ( ! bar.isVisible() )
1433 return; 1434 return;
1434 bar.setProgress( i ); 1435 bar.setProgress( i );
1435 qApp->processEvents(); 1436 qApp->processEvents();
1436 1437
1437 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1438 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1438 if (!ok) { 1439 if (!ok) {
1439 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1440 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1440 } 1441 }
1441 1442
1442 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1443 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1443 if (!ok) { 1444 if (!ok) {
1444 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1445 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1445 } 1446 }
1446 realName = realNameList[i]; 1447 realName = realNameList[i];
1447 email = emailList[i]; 1448 email = emailList[i];
1448 assembledName = assembledNameList[i]; 1449 assembledName = assembledNameList[i];
1449 uid = uidList[i]; 1450 uid = uidList[i];
1450 //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() ); 1451 //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() );
1451 1452
1452 if ( birthday.isValid() ){ 1453 if ( birthday.isValid() ){
1453 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1454 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1454 KCal::Attendee::ReqParticipant,uid) ; 1455 KCal::Attendee::ReqParticipant,uid) ;