summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-26 00:26:43 (UTC)
committer zautrix <zautrix>2004-10-26 00:26:43 (UTC)
commitd9a3130b909cc32cfdee4cc6136105d9a488f357 (patch) (unidiff)
tree78e3cb0d8552f5a369f507b6b29eede81754db6b
parent283cdf0b976a66c8e29ac327385472844d92f581 (diff)
downloadkdepimpi-d9a3130b909cc32cfdee4cc6136105d9a488f357.zip
kdepimpi-d9a3130b909cc32cfdee4cc6136105d9a488f357.tar.gz
kdepimpi-d9a3130b909cc32cfdee4cc6136105d9a488f357.tar.bz2
set organizer when importing b days
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index e64d83a..284ddbf 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1081,769 +1081,769 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
1081 if ( ! bar.isVisible() ) 1081 if ( ! bar.isVisible() )
1082 return false; 1082 return false;
1083 if ( incCounter % modulo == 0 ) 1083 if ( incCounter % modulo == 0 )
1084 bar.setProgress( incCounter ); 1084 bar.setProgress( incCounter );
1085 ++incCounter; 1085 ++incCounter;
1086 uid = inL->uid(); 1086 uid = inL->uid();
1087 bool skipIncidence = false; 1087 bool skipIncidence = false;
1088 if ( uid.left(15) == QString("last-syncEvent-") ) 1088 if ( uid.left(15) == QString("last-syncEvent-") )
1089 skipIncidence = true; 1089 skipIncidence = true;
1090 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1090 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1091 skipIncidence = true; 1091 skipIncidence = true;
1092 if ( !skipIncidence ) { 1092 if ( !skipIncidence ) {
1093 inR = remote->incidence( uid ); 1093 inR = remote->incidence( uid );
1094 if ( ! inR ) { 1094 if ( ! inR ) {
1095 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1095 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1096 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1096 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1097 checkExternSyncEvent(eventLSyncSharp, inL); 1097 checkExternSyncEvent(eventLSyncSharp, inL);
1098 local->deleteIncidence( inL ); 1098 local->deleteIncidence( inL );
1099 ++deletedEventL; 1099 ++deletedEventL;
1100 } else { 1100 } else {
1101 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1101 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1102 inL->removeID(mCurrentSyncDevice ); 1102 inL->removeID(mCurrentSyncDevice );
1103 ++addedEventR; 1103 ++addedEventR;
1104 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1104 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1105 inL->setLastModified( modifiedCalendar ); 1105 inL->setLastModified( modifiedCalendar );
1106 inR = inL->clone(); 1106 inR = inL->clone();
1107 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1107 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1108 remote->addIncidence( inR ); 1108 remote->addIncidence( inR );
1109 } 1109 }
1110 } 1110 }
1111 } else { 1111 } else {
1112 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1112 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1113 checkExternSyncEvent(eventLSyncSharp, inL); 1113 checkExternSyncEvent(eventLSyncSharp, inL);
1114 local->deleteIncidence( inL ); 1114 local->deleteIncidence( inL );
1115 ++deletedEventL; 1115 ++deletedEventL;
1116 } else { 1116 } else {
1117 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1117 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1118 ++addedEventR; 1118 ++addedEventR;
1119 inL->setLastModified( modifiedCalendar ); 1119 inL->setLastModified( modifiedCalendar );
1120 remote->addIncidence( inL->clone() ); 1120 remote->addIncidence( inL->clone() );
1121 } 1121 }
1122 } 1122 }
1123 } 1123 }
1124 } 1124 }
1125 } 1125 }
1126 inL = el.next(); 1126 inL = el.next();
1127 } 1127 }
1128 int delFut = 0; 1128 int delFut = 0;
1129 int remRem = 0; 1129 int remRem = 0;
1130 if ( mSyncManager->mWriteBackInFuture ) { 1130 if ( mSyncManager->mWriteBackInFuture ) {
1131 er = remote->rawIncidences(); 1131 er = remote->rawIncidences();
1132 remRem = er.count(); 1132 remRem = er.count();
1133 inR = er.first(); 1133 inR = er.first();
1134 QDateTime dt; 1134 QDateTime dt;
1135 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1135 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1136 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); 1136 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 );
1137 while ( inR ) { 1137 while ( inR ) {
1138 if ( inR->type() == "Todo" ) { 1138 if ( inR->type() == "Todo" ) {
1139 Todo * t = (Todo*)inR; 1139 Todo * t = (Todo*)inR;
1140 if ( t->hasDueDate() ) 1140 if ( t->hasDueDate() )
1141 dt = t->dtDue(); 1141 dt = t->dtDue();
1142 else 1142 else
1143 dt = cur.addSecs( 62 ); 1143 dt = cur.addSecs( 62 );
1144 } 1144 }
1145 else if (inR->type() == "Event" ) { 1145 else if (inR->type() == "Event" ) {
1146 bool ok; 1146 bool ok;
1147 dt = inR->getNextOccurence( cur, &ok ); 1147 dt = inR->getNextOccurence( cur, &ok );
1148 if ( !ok ) 1148 if ( !ok )
1149 dt = cur.addSecs( -62 ); 1149 dt = cur.addSecs( -62 );
1150 } 1150 }
1151 else 1151 else
1152 dt = inR->dtStart(); 1152 dt = inR->dtStart();
1153 if ( dt < cur || dt > end ) { 1153 if ( dt < cur || dt > end ) {
1154 remote->deleteIncidence( inR ); 1154 remote->deleteIncidence( inR );
1155 ++delFut; 1155 ++delFut;
1156 } 1156 }
1157 inR = er.next(); 1157 inR = er.next();
1158 } 1158 }
1159 } 1159 }
1160 bar.hide(); 1160 bar.hide();
1161 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1161 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1162 eventLSync->setReadOnly( false ); 1162 eventLSync->setReadOnly( false );
1163 eventLSync->setDtStart( mLastCalendarSync ); 1163 eventLSync->setDtStart( mLastCalendarSync );
1164 eventRSync->setDtStart( mLastCalendarSync ); 1164 eventRSync->setDtStart( mLastCalendarSync );
1165 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1165 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1166 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1166 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1167 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1167 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1168 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1168 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1169 eventLSync->setReadOnly( true ); 1169 eventLSync->setReadOnly( true );
1170 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncKDE) // kde is abnormal... 1170 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncKDE) // kde is abnormal...
1171 remote->addEvent( eventRSync ); 1171 remote->addEvent( eventRSync );
1172 else 1172 else
1173 delete eventRSync; 1173 delete eventRSync;
1174 QString mes; 1174 QString mes;
1175 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 ); 1175 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 );
1176 QString delmess; 1176 QString delmess;
1177 if ( delFut ) { 1177 if ( delFut ) {
1178 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); 1178 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);
1179 mes += delmess; 1179 mes += delmess;
1180 } 1180 }
1181 if ( mSyncManager->mShowSyncSummary ) { 1181 if ( mSyncManager->mShowSyncSummary ) {
1182 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1182 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1183 } 1183 }
1184 qDebug( mes ); 1184 qDebug( mes );
1185 mCalendar->checkAlarmForIncidence( 0, true ); 1185 mCalendar->checkAlarmForIncidence( 0, true );
1186 return syncOK; 1186 return syncOK;
1187} 1187}
1188 1188
1189void CalendarView::setSyncDevice( QString s ) 1189void CalendarView::setSyncDevice( QString s )
1190{ 1190{
1191 mCurrentSyncDevice= s; 1191 mCurrentSyncDevice= s;
1192} 1192}
1193void CalendarView::setSyncName( QString s ) 1193void CalendarView::setSyncName( QString s )
1194{ 1194{
1195 mCurrentSyncName= s; 1195 mCurrentSyncName= s;
1196} 1196}
1197bool CalendarView::syncCalendar(QString filename, int mode) 1197bool CalendarView::syncCalendar(QString filename, int mode)
1198{ 1198{
1199 //qDebug("syncCalendar %s ", filename.latin1()); 1199 //qDebug("syncCalendar %s ", filename.latin1());
1200 mGlobalSyncMode = SYNC_MODE_NORMAL; 1200 mGlobalSyncMode = SYNC_MODE_NORMAL;
1201 CalendarLocal* calendar = new CalendarLocal(); 1201 CalendarLocal* calendar = new CalendarLocal();
1202 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1202 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1203 FileStorage* storage = new FileStorage( calendar ); 1203 FileStorage* storage = new FileStorage( calendar );
1204 bool syncOK = false; 1204 bool syncOK = false;
1205 storage->setFileName( filename ); 1205 storage->setFileName( filename );
1206 // qDebug("loading ... "); 1206 // qDebug("loading ... ");
1207 if ( storage->load() ) { 1207 if ( storage->load() ) {
1208 getEventViewerDialog()->setSyncMode( true ); 1208 getEventViewerDialog()->setSyncMode( true );
1209 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1209 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1210 getEventViewerDialog()->setSyncMode( false ); 1210 getEventViewerDialog()->setSyncMode( false );
1211 if ( syncOK ) { 1211 if ( syncOK ) {
1212 if ( mSyncManager->mWriteBackFile ) 1212 if ( mSyncManager->mWriteBackFile )
1213 { 1213 {
1214 storage->setSaveFormat( new ICalFormat() ); 1214 storage->setSaveFormat( new ICalFormat() );
1215 storage->save(); 1215 storage->save();
1216 } 1216 }
1217 } 1217 }
1218 setModified( true ); 1218 setModified( true );
1219 } 1219 }
1220 delete storage; 1220 delete storage;
1221 delete calendar; 1221 delete calendar;
1222 if ( syncOK ) 1222 if ( syncOK )
1223 updateView(); 1223 updateView();
1224 return syncOK; 1224 return syncOK;
1225} 1225}
1226 1226
1227void CalendarView::syncExternal( int mode ) 1227void CalendarView::syncExternal( int mode )
1228{ 1228{
1229 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1229 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1230 1230
1231 qApp->processEvents(); 1231 qApp->processEvents();
1232 CalendarLocal* calendar = new CalendarLocal(); 1232 CalendarLocal* calendar = new CalendarLocal();
1233 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1233 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1234 bool syncOK = false; 1234 bool syncOK = false;
1235 bool loadSuccess = false; 1235 bool loadSuccess = false;
1236 PhoneFormat* phoneFormat = 0; 1236 PhoneFormat* phoneFormat = 0;
1237 emit tempDisableBR(true); 1237 emit tempDisableBR(true);
1238#ifndef DESKTOP_VERSION 1238#ifndef DESKTOP_VERSION
1239 SharpFormat* sharpFormat = 0; 1239 SharpFormat* sharpFormat = 0;
1240 if ( mode == 0 ) { // sharp 1240 if ( mode == 0 ) { // sharp
1241 sharpFormat = new SharpFormat () ; 1241 sharpFormat = new SharpFormat () ;
1242 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1242 loadSuccess = sharpFormat->load( calendar, mCalendar );
1243 1243
1244 } else 1244 } else
1245#endif 1245#endif
1246 if ( mode == 1 ) { // phone 1246 if ( mode == 1 ) { // phone
1247 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1247 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1248 mSyncManager->mPhoneDevice, 1248 mSyncManager->mPhoneDevice,
1249 mSyncManager->mPhoneConnection, 1249 mSyncManager->mPhoneConnection,
1250 mSyncManager->mPhoneModel); 1250 mSyncManager->mPhoneModel);
1251 loadSuccess = phoneFormat->load( calendar,mCalendar); 1251 loadSuccess = phoneFormat->load( calendar,mCalendar);
1252 1252
1253 } else { 1253 } else {
1254 emit tempDisableBR(false); 1254 emit tempDisableBR(false);
1255 return; 1255 return;
1256 } 1256 }
1257 if ( loadSuccess ) { 1257 if ( loadSuccess ) {
1258 getEventViewerDialog()->setSyncMode( true ); 1258 getEventViewerDialog()->setSyncMode( true );
1259 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1259 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1260 getEventViewerDialog()->setSyncMode( false ); 1260 getEventViewerDialog()->setSyncMode( false );
1261 qApp->processEvents(); 1261 qApp->processEvents();
1262 if ( syncOK ) { 1262 if ( syncOK ) {
1263 if ( mSyncManager->mWriteBackFile ) 1263 if ( mSyncManager->mWriteBackFile )
1264 { 1264 {
1265 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1265 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1266 Incidence* inc = iL.first(); 1266 Incidence* inc = iL.first();
1267 if ( phoneFormat ) { 1267 if ( phoneFormat ) {
1268 while ( inc ) { 1268 while ( inc ) {
1269 inc->removeID(mCurrentSyncDevice); 1269 inc->removeID(mCurrentSyncDevice);
1270 inc = iL.next(); 1270 inc = iL.next();
1271 } 1271 }
1272 } 1272 }
1273#ifndef DESKTOP_VERSION 1273#ifndef DESKTOP_VERSION
1274 if ( sharpFormat ) 1274 if ( sharpFormat )
1275 sharpFormat->save(calendar); 1275 sharpFormat->save(calendar);
1276#endif 1276#endif
1277 if ( phoneFormat ) 1277 if ( phoneFormat )
1278 phoneFormat->save(calendar); 1278 phoneFormat->save(calendar);
1279 iL = calendar->rawIncidences(); 1279 iL = calendar->rawIncidences();
1280 inc = iL.first(); 1280 inc = iL.first();
1281 Incidence* loc; 1281 Incidence* loc;
1282 while ( inc ) { 1282 while ( inc ) {
1283 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1283 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1284 loc = mCalendar->incidence(inc->uid() ); 1284 loc = mCalendar->incidence(inc->uid() );
1285 if ( loc ) { 1285 if ( loc ) {
1286 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1286 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1287 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1287 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1288 } 1288 }
1289 } 1289 }
1290 inc = iL.next(); 1290 inc = iL.next();
1291 } 1291 }
1292 Incidence* lse = getLastSyncEvent(); 1292 Incidence* lse = getLastSyncEvent();
1293 if ( lse ) { 1293 if ( lse ) {
1294 lse->setReadOnly( false ); 1294 lse->setReadOnly( false );
1295 lse->setDescription( "" ); 1295 lse->setDescription( "" );
1296 lse->setReadOnly( true ); 1296 lse->setReadOnly( true );
1297 } 1297 }
1298 } 1298 }
1299 } 1299 }
1300 setModified( true ); 1300 setModified( true );
1301 } else { 1301 } else {
1302 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1302 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1303 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1303 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1304 question, i18n("Ok")) ; 1304 question, i18n("Ok")) ;
1305 1305
1306 } 1306 }
1307 delete calendar; 1307 delete calendar;
1308 updateView(); 1308 updateView();
1309 emit tempDisableBR(false); 1309 emit tempDisableBR(false);
1310 return ;//syncOK; 1310 return ;//syncOK;
1311 1311
1312} 1312}
1313 1313
1314bool CalendarView::importBday() 1314bool CalendarView::importBday()
1315{ 1315{
1316#ifndef KORG_NOKABC 1316#ifndef KORG_NOKABC
1317 1317
1318#ifdef DESKTOP_VERSION 1318#ifdef DESKTOP_VERSION
1319 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1319 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1320 KABC::AddressBook::Iterator it; 1320 KABC::AddressBook::Iterator it;
1321 int count = 0; 1321 int count = 0;
1322 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1322 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1323 ++count; 1323 ++count;
1324 } 1324 }
1325 QProgressBar bar(count,0 ); 1325 QProgressBar bar(count,0 );
1326 int w = 300; 1326 int w = 300;
1327 if ( QApplication::desktop()->width() < 320 ) 1327 if ( QApplication::desktop()->width() < 320 )
1328 w = 220; 1328 w = 220;
1329 int h = bar.sizeHint().height() ; 1329 int h = bar.sizeHint().height() ;
1330 int dw = QApplication::desktop()->width(); 1330 int dw = QApplication::desktop()->width();
1331 int dh = QApplication::desktop()->height(); 1331 int dh = QApplication::desktop()->height();
1332 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1332 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1333 bar.show(); 1333 bar.show();
1334 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1334 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1335 qApp->processEvents(); 1335 qApp->processEvents();
1336 count = 0; 1336 count = 0;
1337 int addCount = 0; 1337 int addCount = 0;
1338 KCal::Attendee* a = 0; 1338 KCal::Attendee* a = 0;
1339 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1339 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1340 if ( ! bar.isVisible() ) 1340 if ( ! bar.isVisible() )
1341 return false; 1341 return false;
1342 bar.setProgress( count++ ); 1342 bar.setProgress( count++ );
1343 qApp->processEvents(); 1343 qApp->processEvents();
1344 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1344 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1345 if ( (*it).birthday().date().isValid() ){ 1345 if ( (*it).birthday().date().isValid() ){
1346 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1346 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1347 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1347 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1348 ++addCount; 1348 ++addCount;
1349 } 1349 }
1350 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1350 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1351 if ( anni.isValid() ){ 1351 if ( anni.isValid() ){
1352 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1352 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1353 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1353 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1354 ++addCount; 1354 ++addCount;
1355 } 1355 }
1356 } 1356 }
1357 updateView(); 1357 updateView();
1358 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1358 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1359#else //DESKTOP_VERSION 1359#else //DESKTOP_VERSION
1360 1360
1361 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1361 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1362 // the result should now arrive through method insertBirthdays 1362 // the result should now arrive through method insertBirthdays
1363 1363
1364#endif //DESKTOP_VERSION 1364#endif //DESKTOP_VERSION
1365 1365
1366#endif //KORG_NOKABC 1366#endif //KORG_NOKABC
1367 1367
1368 1368
1369 return true; 1369 return true;
1370} 1370}
1371 1371
1372// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1372// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1373void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1373void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1374 const QStringList& anniversaryList, const QStringList& realNameList, 1374 const QStringList& anniversaryList, const QStringList& realNameList,
1375 const QStringList& emailList, const QStringList& assembledNameList, 1375 const QStringList& emailList, const QStringList& assembledNameList,
1376 const QStringList& uidList) 1376 const QStringList& uidList)
1377{ 1377{
1378 qDebug("CalendarView::insertBirthdays"); 1378 qDebug("CalendarView::insertBirthdays");
1379 if (uid == this->name()) 1379 if (uid == this->name())
1380 { 1380 {
1381 int count = birthdayList.count(); 1381 int count = birthdayList.count();
1382 int addCount = 0; 1382 int addCount = 0;
1383 KCal::Attendee* a = 0; 1383 KCal::Attendee* a = 0;
1384 1384
1385 qDebug("CalView 1 %i", count); 1385 qDebug("CalView 1 %i", count);
1386 1386
1387 QProgressBar bar(count,0 ); 1387 QProgressBar bar(count,0 );
1388 int w = 300; 1388 int w = 300;
1389 if ( QApplication::desktop()->width() < 320 ) 1389 if ( QApplication::desktop()->width() < 320 )
1390 w = 220; 1390 w = 220;
1391 int h = bar.sizeHint().height() ; 1391 int h = bar.sizeHint().height() ;
1392 int dw = QApplication::desktop()->width(); 1392 int dw = QApplication::desktop()->width();
1393 int dh = QApplication::desktop()->height(); 1393 int dh = QApplication::desktop()->height();
1394 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1394 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1395 bar.show(); 1395 bar.show();
1396 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1396 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1397 qApp->processEvents(); 1397 qApp->processEvents();
1398 1398
1399 QDate birthday; 1399 QDate birthday;
1400 QDate anniversary; 1400 QDate anniversary;
1401 QString realName; 1401 QString realName;
1402 QString email; 1402 QString email;
1403 QString assembledName; 1403 QString assembledName;
1404 QString uid; 1404 QString uid;
1405 bool ok = true; 1405 bool ok = true;
1406 for ( int i = 0; i < count; i++) 1406 for ( int i = 0; i < count; i++)
1407 { 1407 {
1408 if ( ! bar.isVisible() ) 1408 if ( ! bar.isVisible() )
1409 return; 1409 return;
1410 bar.setProgress( i ); 1410 bar.setProgress( i );
1411 qApp->processEvents(); 1411 qApp->processEvents();
1412 1412
1413 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1413 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1414 if (!ok) { 1414 if (!ok) {
1415 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1415 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1416 } 1416 }
1417 1417
1418 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1418 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1419 if (!ok) { 1419 if (!ok) {
1420 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1420 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1421 } 1421 }
1422 realName = realNameList[i]; 1422 realName = realNameList[i];
1423 email = emailList[i]; 1423 email = emailList[i];
1424 assembledName = assembledNameList[i]; 1424 assembledName = assembledNameList[i];
1425 uid = uidList[i]; 1425 uid = uidList[i];
1426 //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() ); 1426 //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() );
1427 1427
1428 if ( birthday.isValid() ){ 1428 if ( birthday.isValid() ){
1429 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1429 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1430 KCal::Attendee::ReqParticipant,uid) ; 1430 KCal::Attendee::ReqParticipant,uid) ;
1431 if ( addAnniversary( birthday, assembledName, a, true ) ) 1431 if ( addAnniversary( birthday, assembledName, a, true ) )
1432 ++addCount; 1432 ++addCount;
1433 } 1433 }
1434 1434
1435 if ( anniversary.isValid() ){ 1435 if ( anniversary.isValid() ){
1436 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1436 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1437 KCal::Attendee::ReqParticipant,uid) ; 1437 KCal::Attendee::ReqParticipant,uid) ;
1438 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1438 if ( addAnniversary( anniversary, assembledName, a, false ) )
1439 ++addCount; 1439 ++addCount;
1440 } 1440 }
1441 } 1441 }
1442 1442
1443 updateView(); 1443 updateView();
1444 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1444 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1445 1445
1446 } 1446 }
1447 1447
1448} 1448}
1449 1449
1450 1450
1451 1451
1452bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1452bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1453{ 1453{
1454 //qDebug("addAnni "); 1454 //qDebug("addAnni ");
1455 Event * ev = new Event(); 1455 Event * ev = new Event();
1456 if ( a ) { 1456 if ( a ) {
1457 ev->addAttendee( a ); 1457 ev->addAttendee( a );
1458 } 1458 }
1459 QString kind; 1459 QString kind;
1460 if ( birthday ) 1460 if ( birthday )
1461 kind = i18n( "Birthday" ); 1461 kind = i18n( "Birthday" );
1462 else 1462 else
1463 kind = i18n( "Anniversary" ); 1463 kind = i18n( "Anniversary" );
1464 ev->setSummary( name + " - " + kind ); 1464 ev->setSummary( name + " - " + kind );
1465 ev->setOrganizer( "nobody@nowhere" ); 1465 ev->setOrganizer(a->email());
1466 ev->setCategories( kind ); 1466 ev->setCategories( kind );
1467 ev->setDtStart( QDateTime(date) ); 1467 ev->setDtStart( QDateTime(date) );
1468 ev->setDtEnd( QDateTime(date) ); 1468 ev->setDtEnd( QDateTime(date) );
1469 ev->setFloats( true ); 1469 ev->setFloats( true );
1470 Recurrence * rec = ev->recurrence(); 1470 Recurrence * rec = ev->recurrence();
1471 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1471 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1472 rec->addYearlyNum( date.month() ); 1472 rec->addYearlyNum( date.month() );
1473 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1473 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1474 delete ev; 1474 delete ev;
1475 return false; 1475 return false;
1476 } 1476 }
1477 return true; 1477 return true;
1478 1478
1479} 1479}
1480bool CalendarView::importQtopia( const QString &categories, 1480bool CalendarView::importQtopia( const QString &categories,
1481 const QString &datebook, 1481 const QString &datebook,
1482 const QString &todolist ) 1482 const QString &todolist )
1483{ 1483{
1484 1484
1485 QtopiaFormat qtopiaFormat; 1485 QtopiaFormat qtopiaFormat;
1486 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1486 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1487 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1487 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1488 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1488 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1489 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1489 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1490 1490
1491 updateView(); 1491 updateView();
1492 return true; 1492 return true;
1493 1493
1494#if 0 1494#if 0
1495 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1495 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1496 mCurrentSyncDevice = "qtopia-XML"; 1496 mCurrentSyncDevice = "qtopia-XML";
1497 if ( mSyncManager->mAskForPreferences ) 1497 if ( mSyncManager->mAskForPreferences )
1498 edit_sync_options(); 1498 edit_sync_options();
1499 qApp->processEvents(); 1499 qApp->processEvents();
1500 CalendarLocal* calendar = new CalendarLocal(); 1500 CalendarLocal* calendar = new CalendarLocal();
1501 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1501 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1502 bool syncOK = false; 1502 bool syncOK = false;
1503 QtopiaFormat qtopiaFormat; 1503 QtopiaFormat qtopiaFormat;
1504 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1504 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1505 bool loadOk = true; 1505 bool loadOk = true;
1506 if ( !categories.isEmpty() ) 1506 if ( !categories.isEmpty() )
1507 loadOk = qtopiaFormat.load( calendar, categories ); 1507 loadOk = qtopiaFormat.load( calendar, categories );
1508 if ( loadOk && !datebook.isEmpty() ) 1508 if ( loadOk && !datebook.isEmpty() )
1509 loadOk = qtopiaFormat.load( calendar, datebook ); 1509 loadOk = qtopiaFormat.load( calendar, datebook );
1510 if ( loadOk && !todolist.isEmpty() ) 1510 if ( loadOk && !todolist.isEmpty() )
1511 loadOk = qtopiaFormat.load( calendar, todolist ); 1511 loadOk = qtopiaFormat.load( calendar, todolist );
1512 1512
1513 if ( loadOk ) { 1513 if ( loadOk ) {
1514 getEventViewerDialog()->setSyncMode( true ); 1514 getEventViewerDialog()->setSyncMode( true );
1515 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1515 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1516 getEventViewerDialog()->setSyncMode( false ); 1516 getEventViewerDialog()->setSyncMode( false );
1517 qApp->processEvents(); 1517 qApp->processEvents();
1518 if ( syncOK ) { 1518 if ( syncOK ) {
1519 if ( mSyncManager->mWriteBackFile ) 1519 if ( mSyncManager->mWriteBackFile )
1520 { 1520 {
1521 // write back XML file 1521 // write back XML file
1522 1522
1523 } 1523 }
1524 setModified( true ); 1524 setModified( true );
1525 } 1525 }
1526 } else { 1526 } else {
1527 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1527 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1528 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1528 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1529 question, i18n("Ok")) ; 1529 question, i18n("Ok")) ;
1530 } 1530 }
1531 delete calendar; 1531 delete calendar;
1532 updateView(); 1532 updateView();
1533 return syncOK; 1533 return syncOK;
1534 1534
1535 1535
1536#endif 1536#endif
1537 1537
1538} 1538}
1539 1539
1540void CalendarView::setSyncEventsReadOnly() 1540void CalendarView::setSyncEventsReadOnly()
1541{ 1541{
1542 Event * ev; 1542 Event * ev;
1543 QPtrList<Event> eL = mCalendar->rawEvents(); 1543 QPtrList<Event> eL = mCalendar->rawEvents();
1544 ev = eL.first(); 1544 ev = eL.first();
1545 while ( ev ) { 1545 while ( ev ) {
1546 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1546 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1547 ev->setReadOnly( true ); 1547 ev->setReadOnly( true );
1548 ev = eL.next(); 1548 ev = eL.next();
1549 } 1549 }
1550} 1550}
1551bool CalendarView::openCalendar(QString filename, bool merge) 1551bool CalendarView::openCalendar(QString filename, bool merge)
1552{ 1552{
1553 1553
1554 if (filename.isEmpty()) { 1554 if (filename.isEmpty()) {
1555 return false; 1555 return false;
1556 } 1556 }
1557 1557
1558 if (!QFile::exists(filename)) { 1558 if (!QFile::exists(filename)) {
1559 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1559 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1560 return false; 1560 return false;
1561 } 1561 }
1562 1562
1563 globalFlagBlockAgenda = 1; 1563 globalFlagBlockAgenda = 1;
1564 if (!merge) mCalendar->close(); 1564 if (!merge) mCalendar->close();
1565 1565
1566 mStorage->setFileName( filename ); 1566 mStorage->setFileName( filename );
1567 1567
1568 if ( mStorage->load() ) { 1568 if ( mStorage->load() ) {
1569 if ( merge ) ;//setModified( true ); 1569 if ( merge ) ;//setModified( true );
1570 else { 1570 else {
1571 //setModified( true ); 1571 //setModified( true );
1572 mViewManager->setDocumentId( filename ); 1572 mViewManager->setDocumentId( filename );
1573 mDialogManager->setDocumentId( filename ); 1573 mDialogManager->setDocumentId( filename );
1574 mTodoList->setDocumentId( filename ); 1574 mTodoList->setDocumentId( filename );
1575 } 1575 }
1576 globalFlagBlockAgenda = 2; 1576 globalFlagBlockAgenda = 2;
1577 // if ( getLastSyncEvent() ) 1577 // if ( getLastSyncEvent() )
1578 // getLastSyncEvent()->setReadOnly( true ); 1578 // getLastSyncEvent()->setReadOnly( true );
1579 mCalendar->reInitAlarmSettings(); 1579 mCalendar->reInitAlarmSettings();
1580 setSyncEventsReadOnly(); 1580 setSyncEventsReadOnly();
1581 updateUnmanagedViews(); 1581 updateUnmanagedViews();
1582 updateView(); 1582 updateView();
1583 if ( filename != MainWindow::defaultFileName() ) { 1583 if ( filename != MainWindow::defaultFileName() ) {
1584 saveCalendar( MainWindow::defaultFileName() ); 1584 saveCalendar( MainWindow::defaultFileName() );
1585 } else { 1585 } else {
1586 QFileInfo finf ( MainWindow::defaultFileName()); 1586 QFileInfo finf ( MainWindow::defaultFileName());
1587 if ( finf.exists() ) { 1587 if ( finf.exists() ) {
1588 setLoadedFileVersion( finf.lastModified () ); 1588 setLoadedFileVersion( finf.lastModified () );
1589 } 1589 }
1590 } 1590 }
1591 return true; 1591 return true;
1592 } else { 1592 } else {
1593 // while failing to load, the calendar object could 1593 // while failing to load, the calendar object could
1594 // have become partially populated. Clear it out. 1594 // have become partially populated. Clear it out.
1595 if ( !merge ) { 1595 if ( !merge ) {
1596 mCalendar->close(); 1596 mCalendar->close();
1597 mViewManager->setDocumentId( filename ); 1597 mViewManager->setDocumentId( filename );
1598 mDialogManager->setDocumentId( filename ); 1598 mDialogManager->setDocumentId( filename );
1599 mTodoList->setDocumentId( filename ); 1599 mTodoList->setDocumentId( filename );
1600 } 1600 }
1601 1601
1602 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1602 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1603 1603
1604 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1604 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1605 globalFlagBlockAgenda = 2; 1605 globalFlagBlockAgenda = 2;
1606 mCalendar->reInitAlarmSettings(); 1606 mCalendar->reInitAlarmSettings();
1607 setSyncEventsReadOnly(); 1607 setSyncEventsReadOnly();
1608 updateUnmanagedViews(); 1608 updateUnmanagedViews();
1609 updateView(); 1609 updateView();
1610 } 1610 }
1611 return false; 1611 return false;
1612} 1612}
1613void CalendarView::showOpenError() 1613void CalendarView::showOpenError()
1614{ 1614{
1615 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1615 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1616} 1616}
1617void CalendarView::setLoadedFileVersion(QDateTime dt) 1617void CalendarView::setLoadedFileVersion(QDateTime dt)
1618{ 1618{
1619 loadedFileVersion = dt; 1619 loadedFileVersion = dt;
1620} 1620}
1621bool CalendarView::checkFileChanged(QString fn) 1621bool CalendarView::checkFileChanged(QString fn)
1622{ 1622{
1623 QFileInfo finf ( fn ); 1623 QFileInfo finf ( fn );
1624 if ( !finf.exists() ) 1624 if ( !finf.exists() )
1625 return true; 1625 return true;
1626 QDateTime dt = finf.lastModified (); 1626 QDateTime dt = finf.lastModified ();
1627 if ( dt <= loadedFileVersion ) 1627 if ( dt <= loadedFileVersion )
1628 return false; 1628 return false;
1629 return true; 1629 return true;
1630 1630
1631} 1631}
1632void CalendarView::watchSavedFile() 1632void CalendarView::watchSavedFile()
1633{ 1633{
1634 QFileInfo finf ( MainWindow::defaultFileName()); 1634 QFileInfo finf ( MainWindow::defaultFileName());
1635 if ( !finf.exists() ) 1635 if ( !finf.exists() )
1636 return; 1636 return;
1637 QDateTime dt = finf.lastModified (); 1637 QDateTime dt = finf.lastModified ();
1638 if ( dt < loadedFileVersion ) { 1638 if ( dt < loadedFileVersion ) {
1639 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1639 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1640 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1640 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1641 return; 1641 return;
1642 } 1642 }
1643 loadedFileVersion = dt; 1643 loadedFileVersion = dt;
1644} 1644}
1645 1645
1646bool CalendarView::checkFileVersion(QString fn) 1646bool CalendarView::checkFileVersion(QString fn)
1647{ 1647{
1648 QFileInfo finf ( fn ); 1648 QFileInfo finf ( fn );
1649 if ( !finf.exists() ) 1649 if ( !finf.exists() )
1650 return true; 1650 return true;
1651 QDateTime dt = finf.lastModified (); 1651 QDateTime dt = finf.lastModified ();
1652 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1652 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1653 //qDebug("file on disk version %s",dt.toString().latin1()); 1653 //qDebug("file on disk version %s",dt.toString().latin1());
1654 if ( dt <= loadedFileVersion ) 1654 if ( dt <= loadedFileVersion )
1655 return true; 1655 return true;
1656 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 1656 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
1657 i18n("KO/Pi Warning"),i18n("Overwrite"), 1657 i18n("KO/Pi Warning"),i18n("Overwrite"),
1658 i18n("Sync+save")); 1658 i18n("Sync+save"));
1659 1659
1660 if ( km == KMessageBox::Cancel ) 1660 if ( km == KMessageBox::Cancel )
1661 return false; 1661 return false;
1662 if ( km == KMessageBox::Yes ) 1662 if ( km == KMessageBox::Yes )
1663 return true; 1663 return true;
1664 1664
1665 setSyncDevice("deleteaftersync" ); 1665 setSyncDevice("deleteaftersync" );
1666 mSyncManager->mAskForPreferences = true; 1666 mSyncManager->mAskForPreferences = true;
1667 mSyncManager->mSyncAlgoPrefs = 3; 1667 mSyncManager->mSyncAlgoPrefs = 3;
1668 mSyncManager->mWriteBackFile = false; 1668 mSyncManager->mWriteBackFile = false;
1669 mSyncManager->mWriteBackExistingOnly = false; 1669 mSyncManager->mWriteBackExistingOnly = false;
1670 mSyncManager->mShowSyncSummary = false; 1670 mSyncManager->mShowSyncSummary = false;
1671 syncCalendar( fn, 3 ); 1671 syncCalendar( fn, 3 );
1672 Event * e = getLastSyncEvent(); 1672 Event * e = getLastSyncEvent();
1673 mCalendar->deleteEvent ( e ); 1673 mCalendar->deleteEvent ( e );
1674 updateView(); 1674 updateView();
1675 return true; 1675 return true;
1676} 1676}
1677 1677
1678bool CalendarView::saveCalendar( QString filename ) 1678bool CalendarView::saveCalendar( QString filename )
1679{ 1679{
1680 1680
1681 // Store back all unsaved data into calendar object 1681 // Store back all unsaved data into calendar object
1682 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1682 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1683 if ( mViewManager->currentView() ) 1683 if ( mViewManager->currentView() )
1684 mViewManager->currentView()->flushView(); 1684 mViewManager->currentView()->flushView();
1685 1685
1686 1686
1687 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1687 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1688 mStorage->setSaveFormat( new ICalFormat() ); 1688 mStorage->setSaveFormat( new ICalFormat() );
1689 mStorage->setFileName( filename ); 1689 mStorage->setFileName( filename );
1690 bool success; 1690 bool success;
1691 success = mStorage->save(); 1691 success = mStorage->save();
1692 if ( !success ) { 1692 if ( !success ) {
1693 return false; 1693 return false;
1694 } 1694 }
1695 if ( filename == MainWindow::defaultFileName() ) { 1695 if ( filename == MainWindow::defaultFileName() ) {
1696 setLoadedFileVersion( lfv ); 1696 setLoadedFileVersion( lfv );
1697 watchSavedFile(); 1697 watchSavedFile();
1698 } 1698 }
1699 return true; 1699 return true;
1700} 1700}
1701 1701
1702void CalendarView::closeCalendar() 1702void CalendarView::closeCalendar()
1703{ 1703{
1704 1704
1705 // child windows no longer valid 1705 // child windows no longer valid
1706 emit closingDown(); 1706 emit closingDown();
1707 1707
1708 mCalendar->close(); 1708 mCalendar->close();
1709 setModified(false); 1709 setModified(false);
1710 updateView(); 1710 updateView();
1711} 1711}
1712 1712
1713void CalendarView::archiveCalendar() 1713void CalendarView::archiveCalendar()
1714{ 1714{
1715 mDialogManager->showArchiveDialog(); 1715 mDialogManager->showArchiveDialog();
1716} 1716}
1717 1717
1718 1718
1719void CalendarView::readSettings() 1719void CalendarView::readSettings()
1720{ 1720{
1721 1721
1722 1722
1723 // mViewManager->showAgendaView(); 1723 // mViewManager->showAgendaView();
1724 QString str; 1724 QString str;
1725 //qDebug("CalendarView::readSettings() "); 1725 //qDebug("CalendarView::readSettings() ");
1726 // read settings from the KConfig, supplying reasonable 1726 // read settings from the KConfig, supplying reasonable
1727 // defaults where none are to be found 1727 // defaults where none are to be found
1728 KConfig *config = KOGlobals::config(); 1728 KConfig *config = KOGlobals::config();
1729#ifndef KORG_NOSPLITTER 1729#ifndef KORG_NOSPLITTER
1730 config->setGroup("KOrganizer Geometry"); 1730 config->setGroup("KOrganizer Geometry");
1731 1731
1732 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1732 QValueList<int> sizes = config->readIntListEntry("Separator1");
1733 if (sizes.count() != 2) { 1733 if (sizes.count() != 2) {
1734 sizes << mDateNavigator->minimumSizeHint().width(); 1734 sizes << mDateNavigator->minimumSizeHint().width();
1735 sizes << 300; 1735 sizes << 300;
1736 } 1736 }
1737 mPanner->setSizes(sizes); 1737 mPanner->setSizes(sizes);
1738 1738
1739 sizes = config->readIntListEntry("Separator2"); 1739 sizes = config->readIntListEntry("Separator2");
1740 if ( ( mResourceView && sizes.count() == 4 ) || 1740 if ( ( mResourceView && sizes.count() == 4 ) ||
1741 ( !mResourceView && sizes.count() == 3 ) ) { 1741 ( !mResourceView && sizes.count() == 3 ) ) {
1742 mLeftSplitter->setSizes(sizes); 1742 mLeftSplitter->setSizes(sizes);
1743 } 1743 }
1744#endif 1744#endif
1745 globalFlagBlockAgenda = 1; 1745 globalFlagBlockAgenda = 1;
1746 mViewManager->showAgendaView(); 1746 mViewManager->showAgendaView();
1747 //mViewManager->readSettings( config ); 1747 //mViewManager->readSettings( config );
1748 mTodoList->restoreLayout(config,QString("Todo Layout")); 1748 mTodoList->restoreLayout(config,QString("Todo Layout"));
1749 readFilterSettings(config); 1749 readFilterSettings(config);
1750 config->setGroup( "Views" ); 1750 config->setGroup( "Views" );
1751 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1751 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1752 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1752 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1753 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1753 else if ( dateCount == 7 ) mNavigator->selectWeek();
1754 else mNavigator->selectDates( dateCount ); 1754 else mNavigator->selectDates( dateCount );
1755 // mViewManager->readSettings( config ); 1755 // mViewManager->readSettings( config );
1756 updateConfig(); 1756 updateConfig();
1757 globalFlagBlockAgenda = 2; 1757 globalFlagBlockAgenda = 2;
1758 mViewManager->readSettings( config ); 1758 mViewManager->readSettings( config );
1759#ifdef DESKTOP_VERSION 1759#ifdef DESKTOP_VERSION
1760 config->setGroup("WidgetLayout"); 1760 config->setGroup("WidgetLayout");
1761 QStringList list; 1761 QStringList list;
1762 list = config->readListEntry("MainLayout"); 1762 list = config->readListEntry("MainLayout");
1763 int x,y,w,h; 1763 int x,y,w,h;
1764 if ( ! list.isEmpty() ) { 1764 if ( ! list.isEmpty() ) {
1765 x = list[0].toInt(); 1765 x = list[0].toInt();
1766 y = list[1].toInt(); 1766 y = list[1].toInt();
1767 w = list[2].toInt(); 1767 w = list[2].toInt();
1768 h = list[3].toInt(); 1768 h = list[3].toInt();
1769 topLevelWidget()->setGeometry(x,y,w,h); 1769 topLevelWidget()->setGeometry(x,y,w,h);
1770 1770
1771 } else { 1771 } else {
1772 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1772 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1773 } 1773 }
1774 list = config->readListEntry("EditEventLayout"); 1774 list = config->readListEntry("EditEventLayout");
1775 if ( ! list.isEmpty() ) { 1775 if ( ! list.isEmpty() ) {
1776 x = list[0].toInt(); 1776 x = list[0].toInt();
1777 y = list[1].toInt(); 1777 y = list[1].toInt();
1778 w = list[2].toInt(); 1778 w = list[2].toInt();
1779 h = list[3].toInt(); 1779 h = list[3].toInt();
1780 mEventEditor->setGeometry(x,y,w,h); 1780 mEventEditor->setGeometry(x,y,w,h);
1781 1781
1782 } 1782 }
1783 list = config->readListEntry("EditTodoLayout"); 1783 list = config->readListEntry("EditTodoLayout");
1784 if ( ! list.isEmpty() ) { 1784 if ( ! list.isEmpty() ) {
1785 x = list[0].toInt(); 1785 x = list[0].toInt();
1786 y = list[1].toInt(); 1786 y = list[1].toInt();
1787 w = list[2].toInt(); 1787 w = list[2].toInt();
1788 h = list[3].toInt(); 1788 h = list[3].toInt();
1789 mTodoEditor->setGeometry(x,y,w,h); 1789 mTodoEditor->setGeometry(x,y,w,h);
1790 1790
1791 } 1791 }
1792 list = config->readListEntry("ViewerLayout"); 1792 list = config->readListEntry("ViewerLayout");
1793 if ( ! list.isEmpty() ) { 1793 if ( ! list.isEmpty() ) {
1794 x = list[0].toInt(); 1794 x = list[0].toInt();
1795 y = list[1].toInt(); 1795 y = list[1].toInt();
1796 w = list[2].toInt(); 1796 w = list[2].toInt();
1797 h = list[3].toInt(); 1797 h = list[3].toInt();
1798 getEventViewerDialog()->setGeometry(x,y,w,h); 1798 getEventViewerDialog()->setGeometry(x,y,w,h);
1799 } 1799 }
1800#endif 1800#endif
1801 1801
1802} 1802}
1803 1803
1804 1804
1805void CalendarView::writeSettings() 1805void CalendarView::writeSettings()
1806{ 1806{
1807 // kdDebug() << "CalendarView::writeSettings" << endl; 1807 // kdDebug() << "CalendarView::writeSettings" << endl;
1808 1808
1809 KConfig *config = KOGlobals::config(); 1809 KConfig *config = KOGlobals::config();
1810 1810
1811#ifndef KORG_NOSPLITTER 1811#ifndef KORG_NOSPLITTER
1812 config->setGroup("KOrganizer Geometry"); 1812 config->setGroup("KOrganizer Geometry");
1813 1813
1814 QValueList<int> list = mPanner->sizes(); 1814 QValueList<int> list = mPanner->sizes();
1815 config->writeEntry("Separator1",list); 1815 config->writeEntry("Separator1",list);
1816 1816
1817 list = mLeftSplitter->sizes(); 1817 list = mLeftSplitter->sizes();
1818 config->writeEntry("Separator2",list); 1818 config->writeEntry("Separator2",list);
1819#endif 1819#endif
1820 1820
1821 mViewManager->writeSettings( config ); 1821 mViewManager->writeSettings( config );
1822 mTodoList->saveLayout(config,QString("Todo Layout")); 1822 mTodoList->saveLayout(config,QString("Todo Layout"));
1823 mDialogManager->writeSettings( config ); 1823 mDialogManager->writeSettings( config );
1824 //KOPrefs::instance()->usrWriteConfig(); 1824 //KOPrefs::instance()->usrWriteConfig();
1825 KOPrefs::instance()->writeConfig(); 1825 KOPrefs::instance()->writeConfig();
1826 1826
1827 writeFilterSettings(config); 1827 writeFilterSettings(config);
1828 1828
1829 config->setGroup( "Views" ); 1829 config->setGroup( "Views" );
1830 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1830 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1831 1831
1832#ifdef DESKTOP_VERSION 1832#ifdef DESKTOP_VERSION
1833 config->setGroup("WidgetLayout"); 1833 config->setGroup("WidgetLayout");
1834 QStringList list ;//= config->readListEntry("MainLayout"); 1834 QStringList list ;//= config->readListEntry("MainLayout");
1835 int x,y,w,h; 1835 int x,y,w,h;
1836 QWidget* wid; 1836 QWidget* wid;
1837 wid = topLevelWidget(); 1837 wid = topLevelWidget();
1838 x = wid->geometry().x(); 1838 x = wid->geometry().x();
1839 y = wid->geometry().y(); 1839 y = wid->geometry().y();
1840 w = wid->width(); 1840 w = wid->width();
1841 h = wid->height(); 1841 h = wid->height();
1842 list.clear(); 1842 list.clear();
1843 list << QString::number( x ); 1843 list << QString::number( x );
1844 list << QString::number( y ); 1844 list << QString::number( y );
1845 list << QString::number( w ); 1845 list << QString::number( w );
1846 list << QString::number( h ); 1846 list << QString::number( h );
1847 config->writeEntry("MainLayout",list ); 1847 config->writeEntry("MainLayout",list );
1848 1848
1849 wid = mEventEditor; 1849 wid = mEventEditor;