summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index b307649..d6ead37 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -991,405 +991,410 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
991 int dw = QApplication::desktop()->width(); 991 int dw = QApplication::desktop()->width();
992 int dh = QApplication::desktop()->height(); 992 int dh = QApplication::desktop()->height();
993 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 993 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
994 bar.show(); 994 bar.show();
995 int modulo = (er.count()/10)+1; 995 int modulo = (er.count()/10)+1;
996 int incCounter = 0; 996 int incCounter = 0;
997 while ( inR ) { 997 while ( inR ) {
998 if ( ! bar.isVisible() ) 998 if ( ! bar.isVisible() )
999 return false; 999 return false;
1000 if ( incCounter % modulo == 0 ) 1000 if ( incCounter % modulo == 0 )
1001 bar.setProgress( incCounter ); 1001 bar.setProgress( incCounter );
1002 ++incCounter; 1002 ++incCounter;
1003 uid = inR->uid(); 1003 uid = inR->uid();
1004 bool skipIncidence = false; 1004 bool skipIncidence = false;
1005 if ( uid.left(15) == QString("last-syncEvent-") ) 1005 if ( uid.left(15) == QString("last-syncEvent-") )
1006 skipIncidence = true; 1006 skipIncidence = true;
1007 1007
1008 qApp->processEvents(); 1008 qApp->processEvents();
1009 if ( !skipIncidence ) { 1009 if ( !skipIncidence ) {
1010 inL = local->incidence( uid ); 1010 inL = local->incidence( uid );
1011 if ( inL ) { // maybe conflict - same uid in both calendars 1011 if ( inL ) { // maybe conflict - same uid in both calendars
1012 int maxrev = inL->revision(); 1012 int maxrev = inL->revision();
1013 if ( maxrev < inR->revision() ) 1013 if ( maxrev < inR->revision() )
1014 maxrev = inR->revision(); 1014 maxrev = inR->revision();
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 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1020 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1021 remote->deleteIncidence( inR ); 1021 remote->deleteIncidence( inR );
1022 if ( inL->revision() < maxrev ) 1022 if ( inL->revision() < maxrev )
1023 inL->setRevision( maxrev ); 1023 inL->setRevision( maxrev );
1024 remote->addIncidence( inL->clone() ); 1024 remote->addIncidence( inL->clone() );
1025 ++changedRemote; 1025 ++changedRemote;
1026 } else { 1026 } else {
1027 if ( inR->revision() < maxrev ) 1027 if ( inR->revision() < maxrev )
1028 inR->setRevision( maxrev ); 1028 inR->setRevision( maxrev );
1029 local->deleteIncidence( inL ); 1029 local->deleteIncidence( inL );
1030 local->addIncidence( inR->clone() ); 1030 local->addIncidence( inR->clone() );
1031 ++changedLocal; 1031 ++changedLocal;
1032 } 1032 }
1033 } 1033 }
1034 } else { // no conflict 1034 } else { // no conflict
1035 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1035 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1036 QString des = eventLSync->description(); 1036 QString des = eventLSync->description();
1037 QString pref = "e"; 1037 QString pref = "e";
1038 if ( inR->type() == "Todo" ) 1038 if ( inR->type() == "Todo" )
1039 pref = "t"; 1039 pref = "t";
1040 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1040 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1041 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1041 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1042 //remote->deleteIncidence( inR ); 1042 //remote->deleteIncidence( inR );
1043 ++deletedEventR; 1043 ++deletedEventR;
1044 } else { 1044 } else {
1045 inR->setLastModified( modifiedCalendar ); 1045 inR->setLastModified( modifiedCalendar );
1046 local->addIncidence( inR->clone() ); 1046 local->addIncidence( inR->clone() );
1047 ++addedEvent; 1047 ++addedEvent;
1048 } 1048 }
1049 } else { 1049 } else {
1050 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1050 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1051 inR->setLastModified( modifiedCalendar ); 1051 inR->setLastModified( modifiedCalendar );
1052 local->addIncidence( inR->clone() ); 1052 local->addIncidence( inR->clone() );
1053 ++addedEvent; 1053 ++addedEvent;
1054 } else { 1054 } else {
1055 checkExternSyncEvent(eventRSyncSharp, inR); 1055 checkExternSyncEvent(eventRSyncSharp, inR);
1056 remote->deleteIncidence( inR ); 1056 remote->deleteIncidence( inR );
1057 ++deletedEventR; 1057 ++deletedEventR;
1058 } 1058 }
1059 } 1059 }
1060 } 1060 }
1061 } 1061 }
1062 inR = er.next(); 1062 inR = er.next();
1063 } 1063 }
1064 QPtrList<Incidence> el = local->rawIncidences(); 1064 QPtrList<Incidence> el = local->rawIncidences();
1065 inL = el.first(); 1065 inL = el.first();
1066 modulo = (el.count()/10)+1; 1066 modulo = (el.count()/10)+1;
1067 bar.setCaption (i18n("Add / remove events") ); 1067 bar.setCaption (i18n("Add / remove events") );
1068 bar.setTotalSteps ( el.count() ) ; 1068 bar.setTotalSteps ( el.count() ) ;
1069 bar.show(); 1069 bar.show();
1070 incCounter = 0; 1070 incCounter = 0;
1071 1071
1072 while ( inL ) { 1072 while ( inL ) {
1073 1073
1074 qApp->processEvents(); 1074 qApp->processEvents();
1075 if ( ! bar.isVisible() ) 1075 if ( ! bar.isVisible() )
1076 return false; 1076 return false;
1077 if ( incCounter % modulo == 0 ) 1077 if ( incCounter % modulo == 0 )
1078 bar.setProgress( incCounter ); 1078 bar.setProgress( incCounter );
1079 ++incCounter; 1079 ++incCounter;
1080 uid = inL->uid(); 1080 uid = inL->uid();
1081 bool skipIncidence = false; 1081 bool skipIncidence = false;
1082 if ( uid.left(15) == QString("last-syncEvent-") ) 1082 if ( uid.left(15) == QString("last-syncEvent-") )
1083 skipIncidence = true; 1083 skipIncidence = true;
1084 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1084 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1085 skipIncidence = true; 1085 skipIncidence = true;
1086 if ( !skipIncidence ) { 1086 if ( !skipIncidence ) {
1087 inR = remote->incidence( uid ); 1087 inR = remote->incidence( uid );
1088 if ( ! inR ) { 1088 if ( ! inR ) {
1089 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1089 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1090 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1090 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1091 local->deleteIncidence( inL ); 1091 local->deleteIncidence( inL );
1092 ++deletedEventL; 1092 ++deletedEventL;
1093 } else { 1093 } else {
1094 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1094 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1095 inL->removeID(mCurrentSyncDevice ); 1095 inL->removeID(mCurrentSyncDevice );
1096 ++addedEventR; 1096 ++addedEventR;
1097 inL->setLastModified( modifiedCalendar ); 1097 inL->setLastModified( modifiedCalendar );
1098 remote->addIncidence( inL->clone() ); 1098 remote->addIncidence( inL->clone() );
1099 } 1099 }
1100 } 1100 }
1101 } else { 1101 } else {
1102 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1102 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1103 checkExternSyncEvent(eventLSyncSharp, inL); 1103 checkExternSyncEvent(eventLSyncSharp, inL);
1104 local->deleteIncidence( inL ); 1104 local->deleteIncidence( inL );
1105 ++deletedEventL; 1105 ++deletedEventL;
1106 } else { 1106 } else {
1107 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1107 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1108 ++addedEventR; 1108 ++addedEventR;
1109 inL->setLastModified( modifiedCalendar ); 1109 inL->setLastModified( modifiedCalendar );
1110 remote->addIncidence( inL->clone() ); 1110 remote->addIncidence( inL->clone() );
1111 } 1111 }
1112 } 1112 }
1113 } 1113 }
1114 } 1114 }
1115 } 1115 }
1116 inL = el.next(); 1116 inL = el.next();
1117 } 1117 }
1118 1118
1119 bar.hide(); 1119 bar.hide();
1120 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1120 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1121 eventLSync->setReadOnly( false ); 1121 eventLSync->setReadOnly( false );
1122 eventLSync->setDtStart( mLastCalendarSync ); 1122 eventLSync->setDtStart( mLastCalendarSync );
1123 eventRSync->setDtStart( mLastCalendarSync ); 1123 eventRSync->setDtStart( mLastCalendarSync );
1124 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1124 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1125 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1125 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1126 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1126 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1127 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1127 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1128 eventLSync->setReadOnly( true ); 1128 eventLSync->setReadOnly( true );
1129 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1129 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1130 remote->addEvent( eventRSync ); 1130 remote->addEvent( eventRSync );
1131 QString mes; 1131 QString mes;
1132 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 ); 1132 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 );
1133 if ( KOPrefs::instance()->mShowSyncSummary ) { 1133 if ( KOPrefs::instance()->mShowSyncSummary ) {
1134 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1134 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1135 } 1135 }
1136 qDebug( mes ); 1136 qDebug( mes );
1137 mCalendar->checkAlarmForIncidence( 0, true ); 1137 mCalendar->checkAlarmForIncidence( 0, true );
1138 return syncOK; 1138 return syncOK;
1139} 1139}
1140 1140
1141void CalendarView::setSyncDevice( QString s ) 1141void CalendarView::setSyncDevice( QString s )
1142{ 1142{
1143 mCurrentSyncDevice= s; 1143 mCurrentSyncDevice= s;
1144} 1144}
1145void CalendarView::setSyncName( QString s ) 1145void CalendarView::setSyncName( QString s )
1146{ 1146{
1147 mCurrentSyncName= s; 1147 mCurrentSyncName= s;
1148} 1148}
1149bool CalendarView::syncCalendar(QString filename, int mode) 1149bool CalendarView::syncCalendar(QString filename, int mode)
1150{ 1150{
1151 mGlobalSyncMode = SYNC_MODE_NORMAL; 1151 mGlobalSyncMode = SYNC_MODE_NORMAL;
1152 CalendarLocal* calendar = new CalendarLocal(); 1152 CalendarLocal* calendar = new CalendarLocal();
1153 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1153 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1154 FileStorage* storage = new FileStorage( calendar ); 1154 FileStorage* storage = new FileStorage( calendar );
1155 bool syncOK = false; 1155 bool syncOK = false;
1156 storage->setFileName( filename ); 1156 storage->setFileName( filename );
1157 // qDebug("loading ... "); 1157 // qDebug("loading ... ");
1158 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 1158 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
1159 getEventViewerDialog()->setSyncMode( true ); 1159 getEventViewerDialog()->setSyncMode( true );
1160 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1160 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1161 getEventViewerDialog()->setSyncMode( false ); 1161 getEventViewerDialog()->setSyncMode( false );
1162 if ( syncOK ) { 1162 if ( syncOK ) {
1163 if ( KOPrefs::instance()->mWriteBackFile ) 1163 if ( KOPrefs::instance()->mWriteBackFile )
1164 { 1164 {
1165 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1165 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1166 storage->save(); 1166 storage->save();
1167 } 1167 }
1168 } 1168 }
1169 setModified( true ); 1169 setModified( true );
1170 } 1170 }
1171 delete storage; 1171 delete storage;
1172 delete calendar; 1172 delete calendar;
1173 if ( syncOK ) 1173 if ( syncOK )
1174 updateView(); 1174 updateView();
1175 return syncOK; 1175 return syncOK;
1176} 1176}
1177void CalendarView::syncPhone() 1177void CalendarView::syncPhone()
1178{ 1178{
1179 syncExternal( 1 ); 1179 syncExternal( 1 );
1180} 1180}
1181void CalendarView::syncExternal( int mode ) 1181void CalendarView::syncExternal( int mode )
1182{ 1182{
1183 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1183 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1184 //mCurrentSyncDevice = "sharp-DTM"; 1184 //mCurrentSyncDevice = "sharp-DTM";
1185 if ( KOPrefs::instance()->mAskForPreferences ) 1185 if ( KOPrefs::instance()->mAskForPreferences )
1186 edit_sync_options(); 1186 edit_sync_options();
1187 qApp->processEvents(); 1187 qApp->processEvents();
1188 CalendarLocal* calendar = new CalendarLocal(); 1188 CalendarLocal* calendar = new CalendarLocal();
1189 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1189 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1190 bool syncOK = false; 1190 bool syncOK = false;
1191 bool loadSuccess = false; 1191 bool loadSuccess = false;
1192 PhoneFormat* phoneFormat = 0; 1192 PhoneFormat* phoneFormat = 0;
1193#ifndef DESKTOP_VERSION 1193#ifndef DESKTOP_VERSION
1194 SharpFormat* sharpFormat = 0; 1194 SharpFormat* sharpFormat = 0;
1195 if ( mode == 0 ) { // sharp 1195 if ( mode == 0 ) { // sharp
1196 sharpFormat = new SharpFormat () ; 1196 sharpFormat = new SharpFormat () ;
1197 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1197 loadSuccess = sharpFormat->load( calendar, mCalendar );
1198 1198
1199 } else 1199 } else
1200#endif 1200#endif
1201 if ( mode == 1 ) { // phone 1201 if ( mode == 1 ) { // phone
1202 phoneFormat = new PhoneFormat (); 1202 phoneFormat = new PhoneFormat ();
1203 loadSuccess = phoneFormat->load( calendar, mCalendar ); 1203 loadSuccess = phoneFormat->load( calendar,
1204 mCalendar,
1205 mCurrentSyncDevice,
1206 KOPrefs::instance()->mPhoneDevice,
1207 KOPrefs::instance()->mPhoneConnection,
1208 KOPrefs::instance()->mPhoneModel);
1204 1209
1205 } else 1210 } else
1206 return; 1211 return;
1207 if ( loadSuccess ) { 1212 if ( loadSuccess ) {
1208 getEventViewerDialog()->setSyncMode( true ); 1213 getEventViewerDialog()->setSyncMode( true );
1209 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1214 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1210 getEventViewerDialog()->setSyncMode( false ); 1215 getEventViewerDialog()->setSyncMode( false );
1211 qApp->processEvents(); 1216 qApp->processEvents();
1212 if ( syncOK ) { 1217 if ( syncOK ) {
1213 if ( KOPrefs::instance()->mWriteBackFile ) 1218 if ( KOPrefs::instance()->mWriteBackFile )
1214 { 1219 {
1215 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1220 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1216 Incidence* inc = iL.first(); 1221 Incidence* inc = iL.first();
1217 /* obsolete 1222 /* obsolete
1218 while ( inc ) { 1223 while ( inc ) {
1219 inc->setZaurusStat( inc->revision () ); 1224 inc->setZaurusStat( inc->revision () );
1220 inc = iL.next(); 1225 inc = iL.next();
1221 } 1226 }
1222 */ 1227 */
1223#ifndef DESKTOP_VERSION 1228#ifndef DESKTOP_VERSION
1224 if ( sharpFormat ) 1229 if ( sharpFormat )
1225 sharpFormat->save(calendar); 1230 sharpFormat->save(calendar);
1226#endif 1231#endif
1227 if ( phoneFormat ) 1232 if ( phoneFormat )
1228 phoneFormat->save(calendar); 1233 phoneFormat->save(calendar);
1229 iL = calendar->rawIncidences(); 1234 iL = calendar->rawIncidences();
1230 inc = iL.first(); 1235 inc = iL.first();
1231 Incidence* loc; 1236 Incidence* loc;
1232 while ( inc ) { 1237 while ( inc ) {
1233 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1238 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1234 loc = mCalendar->incidence(inc->uid() ); 1239 loc = mCalendar->incidence(inc->uid() );
1235 if ( loc ) { 1240 if ( loc ) {
1236 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1241 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1237 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1242 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1238 } 1243 }
1239 } 1244 }
1240 inc = iL.next(); 1245 inc = iL.next();
1241 } 1246 }
1242 Incidence* lse = getLastSyncEvent(); 1247 Incidence* lse = getLastSyncEvent();
1243 if ( lse ) { 1248 if ( lse ) {
1244 lse->setReadOnly( false ); 1249 lse->setReadOnly( false );
1245 lse->setDescription( "" ); 1250 lse->setDescription( "" );
1246 lse->setReadOnly( true ); 1251 lse->setReadOnly( true );
1247 } 1252 }
1248 } 1253 }
1249 } 1254 }
1250 setModified( true ); 1255 setModified( true );
1251 } else { 1256 } else {
1252 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1257 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1253 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1258 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1254 question, i18n("Ok")) ; 1259 question, i18n("Ok")) ;
1255 1260
1256 } 1261 }
1257 delete calendar; 1262 delete calendar;
1258 updateView(); 1263 updateView();
1259 return ;//syncOK; 1264 return ;//syncOK;
1260 1265
1261} 1266}
1262void CalendarView::syncSharp() 1267void CalendarView::syncSharp()
1263{ 1268{
1264 syncExternal( 0 ); 1269 syncExternal( 0 );
1265 1270
1266} 1271}
1267 1272
1268 1273
1269#include <kabc/stdaddressbook.h> 1274#include <kabc/stdaddressbook.h>
1270bool CalendarView::importBday() 1275bool CalendarView::importBday()
1271{ 1276{
1272 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1277 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1273 KABC::AddressBook::Iterator it; 1278 KABC::AddressBook::Iterator it;
1274 int count = 0; 1279 int count = 0;
1275 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1280 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1276 ++count; 1281 ++count;
1277 } 1282 }
1278 QProgressBar bar(count,0 ); 1283 QProgressBar bar(count,0 );
1279 int w = 300; 1284 int w = 300;
1280 if ( QApplication::desktop()->width() < 320 ) 1285 if ( QApplication::desktop()->width() < 320 )
1281 w = 220; 1286 w = 220;
1282 int h = bar.sizeHint().height() ; 1287 int h = bar.sizeHint().height() ;
1283 int dw = QApplication::desktop()->width(); 1288 int dw = QApplication::desktop()->width();
1284 int dh = QApplication::desktop()->height(); 1289 int dh = QApplication::desktop()->height();
1285 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1290 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1286 bar.show(); 1291 bar.show();
1287 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1292 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1288 qApp->processEvents(); 1293 qApp->processEvents();
1289 count = 0; 1294 count = 0;
1290 int addCount = 0; 1295 int addCount = 0;
1291 KCal::Attendee* a = 0; 1296 KCal::Attendee* a = 0;
1292 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1297 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1293 if ( ! bar.isVisible() ) 1298 if ( ! bar.isVisible() )
1294 return false; 1299 return false;
1295 bar.setProgress( count++ ); 1300 bar.setProgress( count++ );
1296 qApp->processEvents(); 1301 qApp->processEvents();
1297 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1302 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1298 if ( (*it).birthday().date().isValid() ){ 1303 if ( (*it).birthday().date().isValid() ){
1299 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1304 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1300 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1305 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1301 ++addCount; 1306 ++addCount;
1302 } 1307 }
1303 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1308 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1304 if ( anni.isValid() ){ 1309 if ( anni.isValid() ){
1305 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1310 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1306 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1311 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1307 ++addCount; 1312 ++addCount;
1308 } 1313 }
1309 } 1314 }
1310 updateView(); 1315 updateView();
1311 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1316 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1312 return true; 1317 return true;
1313} 1318}
1314 1319
1315bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1320bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1316{ 1321{
1317 //qDebug("addAnni "); 1322 //qDebug("addAnni ");
1318 Event * ev = new Event(); 1323 Event * ev = new Event();
1319 if ( a ) { 1324 if ( a ) {
1320 ev->addAttendee( a ); 1325 ev->addAttendee( a );
1321 } 1326 }
1322 QString kind; 1327 QString kind;
1323 if ( birthday ) 1328 if ( birthday )
1324 kind = i18n( "Birthday" ); 1329 kind = i18n( "Birthday" );
1325 else 1330 else
1326 kind = i18n( "Anniversary" ); 1331 kind = i18n( "Anniversary" );
1327 ev->setSummary( name + " - " + kind ); 1332 ev->setSummary( name + " - " + kind );
1328 ev->setOrganizer( "nobody@nowhere" ); 1333 ev->setOrganizer( "nobody@nowhere" );
1329 ev->setCategories( kind ); 1334 ev->setCategories( kind );
1330 ev->setDtStart( QDateTime(date) ); 1335 ev->setDtStart( QDateTime(date) );
1331 ev->setDtEnd( QDateTime(date) ); 1336 ev->setDtEnd( QDateTime(date) );
1332 ev->setFloats( true ); 1337 ev->setFloats( true );
1333 Recurrence * rec = ev->recurrence(); 1338 Recurrence * rec = ev->recurrence();
1334 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1339 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1335 rec->addYearlyNum( date.month() ); 1340 rec->addYearlyNum( date.month() );
1336 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1341 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1337 delete ev; 1342 delete ev;
1338 return false; 1343 return false;
1339 } 1344 }
1340 return true; 1345 return true;
1341 1346
1342} 1347}
1343bool CalendarView::importQtopia( const QString &categories, 1348bool CalendarView::importQtopia( const QString &categories,
1344 const QString &datebook, 1349 const QString &datebook,
1345 const QString &todolist ) 1350 const QString &todolist )
1346{ 1351{
1347 1352
1348 QtopiaFormat qtopiaFormat; 1353 QtopiaFormat qtopiaFormat;
1349 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1354 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1350 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1355 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1351 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1356 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1352 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1357 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1353 1358
1354 updateView(); 1359 updateView();
1355 return true; 1360 return true;
1356 1361
1357#if 0 1362#if 0
1358 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1363 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1359 mCurrentSyncDevice = "qtopia-XML"; 1364 mCurrentSyncDevice = "qtopia-XML";
1360 if ( KOPrefs::instance()->mAskForPreferences ) 1365 if ( KOPrefs::instance()->mAskForPreferences )
1361 edit_sync_options(); 1366 edit_sync_options();
1362 qApp->processEvents(); 1367 qApp->processEvents();
1363 CalendarLocal* calendar = new CalendarLocal(); 1368 CalendarLocal* calendar = new CalendarLocal();
1364 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1369 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1365 bool syncOK = false; 1370 bool syncOK = false;
1366 QtopiaFormat qtopiaFormat; 1371 QtopiaFormat qtopiaFormat;
1367 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1372 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1368 bool loadOk = true; 1373 bool loadOk = true;
1369 if ( !categories.isEmpty() ) 1374 if ( !categories.isEmpty() )
1370 loadOk = qtopiaFormat.load( calendar, categories ); 1375 loadOk = qtopiaFormat.load( calendar, categories );
1371 if ( loadOk && !datebook.isEmpty() ) 1376 if ( loadOk && !datebook.isEmpty() )
1372 loadOk = qtopiaFormat.load( calendar, datebook ); 1377 loadOk = qtopiaFormat.load( calendar, datebook );
1373 if ( loadOk && !todolist.isEmpty() ) 1378 if ( loadOk && !todolist.isEmpty() )
1374 loadOk = qtopiaFormat.load( calendar, todolist ); 1379 loadOk = qtopiaFormat.load( calendar, todolist );
1375 1380
1376 if ( loadOk ) { 1381 if ( loadOk ) {
1377 getEventViewerDialog()->setSyncMode( true ); 1382 getEventViewerDialog()->setSyncMode( true );
1378 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1383 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1379 getEventViewerDialog()->setSyncMode( false ); 1384 getEventViewerDialog()->setSyncMode( false );
1380 qApp->processEvents(); 1385 qApp->processEvents();
1381 if ( syncOK ) { 1386 if ( syncOK ) {
1382 if ( KOPrefs::instance()->mWriteBackFile ) 1387 if ( KOPrefs::instance()->mWriteBackFile )
1383 { 1388 {
1384 // write back XML file 1389 // write back XML file
1385 1390
1386 } 1391 }
1387 setModified( true ); 1392 setModified( true );
1388 } 1393 }
1389 } else { 1394 } else {
1390 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1395 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1391 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1396 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1392 question, i18n("Ok")) ; 1397 question, i18n("Ok")) ;
1393 } 1398 }
1394 delete calendar; 1399 delete calendar;
1395 updateView(); 1400 updateView();