summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp5
1 files changed, 2 insertions, 3 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 2582931..68d1bc6 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1214,3117 +1214,3116 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
1214 if ( lastSync > localMod ) 1214 if ( lastSync > localMod )
1215 return 2; 1215 return 2;
1216 if ( lastSync > remoteMod ) 1216 if ( lastSync > remoteMod )
1217 return 1; 1217 return 1;
1218 return 2; 1218 return 2;
1219 break; 1219 break;
1220 case SYNC_PREF_NEWEST: 1220 case SYNC_PREF_NEWEST:
1221 if ( localMod >= remoteMod ) 1221 if ( localMod >= remoteMod )
1222 return 1; 1222 return 1;
1223 else 1223 else
1224 return 2; 1224 return 2;
1225 break; 1225 break;
1226 case SYNC_PREF_ASK: 1226 case SYNC_PREF_ASK:
1227 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1227 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1228 if ( lastSync > remoteMod && lastSync > localMod) 1228 if ( lastSync > remoteMod && lastSync > localMod)
1229 return 0; 1229 return 0;
1230 if ( lastSync > remoteMod ) 1230 if ( lastSync > remoteMod )
1231 return 1; 1231 return 1;
1232 if ( lastSync > localMod ) 1232 if ( lastSync > localMod )
1233 return 2; 1233 return 2;
1234 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1234 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1235 localIsNew = localMod >= remoteMod; 1235 localIsNew = localMod >= remoteMod;
1236 if ( localIsNew ) 1236 if ( localIsNew )
1237 getEventViewerDialog()->setColorMode( 1 ); 1237 getEventViewerDialog()->setColorMode( 1 );
1238 else 1238 else
1239 getEventViewerDialog()->setColorMode( 2 ); 1239 getEventViewerDialog()->setColorMode( 2 );
1240 getEventViewerDialog()->setIncidence(local); 1240 getEventViewerDialog()->setIncidence(local);
1241 if ( localIsNew ) 1241 if ( localIsNew )
1242 getEventViewerDialog()->setColorMode( 2 ); 1242 getEventViewerDialog()->setColorMode( 2 );
1243 else 1243 else
1244 getEventViewerDialog()->setColorMode( 1 ); 1244 getEventViewerDialog()->setColorMode( 1 );
1245 getEventViewerDialog()->addIncidence(remote); 1245 getEventViewerDialog()->addIncidence(remote);
1246 getEventViewerDialog()->setColorMode( 0 ); 1246 getEventViewerDialog()->setColorMode( 0 );
1247 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1247 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1248 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1248 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1249 getEventViewerDialog()->showMe(); 1249 getEventViewerDialog()->showMe();
1250 result = getEventViewerDialog()->executeS( localIsNew ); 1250 result = getEventViewerDialog()->executeS( localIsNew );
1251 return result; 1251 return result;
1252 1252
1253 break; 1253 break;
1254 case SYNC_PREF_FORCE_LOCAL: 1254 case SYNC_PREF_FORCE_LOCAL:
1255 return 1; 1255 return 1;
1256 break; 1256 break;
1257 case SYNC_PREF_FORCE_REMOTE: 1257 case SYNC_PREF_FORCE_REMOTE:
1258 return 2; 1258 return 2;
1259 break; 1259 break;
1260 1260
1261 default: 1261 default:
1262 // SYNC_PREF_TAKE_BOTH not implemented 1262 // SYNC_PREF_TAKE_BOTH not implemented
1263 break; 1263 break;
1264 } 1264 }
1265 return 0; 1265 return 0;
1266} 1266}
1267Event* CalendarView::getLastSyncEvent() 1267Event* CalendarView::getLastSyncEvent()
1268{ 1268{
1269 Event* lse; 1269 Event* lse;
1270 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1270 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1271 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1271 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1272 if (!lse) { 1272 if (!lse) {
1273 lse = new Event(); 1273 lse = new Event();
1274 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1274 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1275 QString sum = ""; 1275 QString sum = "";
1276 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1276 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1277 sum = "E: "; 1277 sum = "E: ";
1278 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1278 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1279 lse->setDtStart( mLastCalendarSync ); 1279 lse->setDtStart( mLastCalendarSync );
1280 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1280 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1281 lse->setCategories( i18n("SyncEvent") ); 1281 lse->setCategories( i18n("SyncEvent") );
1282 lse->setReadOnly( true ); 1282 lse->setReadOnly( true );
1283 mCalendar->addEvent( lse ); 1283 mCalendar->addEvent( lse );
1284 } 1284 }
1285 1285
1286 return lse; 1286 return lse;
1287 1287
1288} 1288}
1289 1289
1290// we check, if the to delete event has a id for a profile 1290// we check, if the to delete event has a id for a profile
1291// if yes, we set this id in the profile to delete 1291// if yes, we set this id in the profile to delete
1292void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1292void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1293{ 1293{
1294 if ( lastSync.count() == 0 ) { 1294 if ( lastSync.count() == 0 ) {
1295 //qDebug(" lastSync.count() == 0"); 1295 //qDebug(" lastSync.count() == 0");
1296 return; 1296 return;
1297 } 1297 }
1298 if ( toDelete->typeID() == journalID ) 1298 if ( toDelete->typeID() == journalID )
1299 return; 1299 return;
1300 1300
1301 Event* eve = lastSync.first(); 1301 Event* eve = lastSync.first();
1302 1302
1303 while ( eve ) { 1303 while ( eve ) {
1304 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1304 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1305 if ( !id.isEmpty() ) { 1305 if ( !id.isEmpty() ) {
1306 QString des = eve->description(); 1306 QString des = eve->description();
1307 QString pref = "e"; 1307 QString pref = "e";
1308 if ( toDelete->typeID() == todoID ) 1308 if ( toDelete->typeID() == todoID )
1309 pref = "t"; 1309 pref = "t";
1310 des += pref+ id + ","; 1310 des += pref+ id + ",";
1311 eve->setReadOnly( false ); 1311 eve->setReadOnly( false );
1312 eve->setDescription( des ); 1312 eve->setDescription( des );
1313 //qDebug("setdes %s ", des.latin1()); 1313 //qDebug("setdes %s ", des.latin1());
1314 eve->setReadOnly( true ); 1314 eve->setReadOnly( true );
1315 } 1315 }
1316 eve = lastSync.next(); 1316 eve = lastSync.next();
1317 } 1317 }
1318 1318
1319} 1319}
1320void CalendarView::checkExternalId( Incidence * inc ) 1320void CalendarView::checkExternalId( Incidence * inc )
1321{ 1321{
1322 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1322 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1323 checkExternSyncEvent( lastSync, inc ); 1323 checkExternSyncEvent( lastSync, inc );
1324 1324
1325} 1325}
1326bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1326bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1327{ 1327{
1328 bool syncOK = true; 1328 bool syncOK = true;
1329 int addedEvent = 0; 1329 int addedEvent = 0;
1330 int addedEventR = 0; 1330 int addedEventR = 0;
1331 int deletedEventR = 0; 1331 int deletedEventR = 0;
1332 int deletedEventL = 0; 1332 int deletedEventL = 0;
1333 int changedLocal = 0; 1333 int changedLocal = 0;
1334 int changedRemote = 0; 1334 int changedRemote = 0;
1335 int filteredIN = 0; 1335 int filteredIN = 0;
1336 int filteredOUT = 0; 1336 int filteredOUT = 0;
1337 //QPtrList<Event> el = local->rawEvents(); 1337 //QPtrList<Event> el = local->rawEvents();
1338 Event* eventR; 1338 Event* eventR;
1339 QString uid; 1339 QString uid;
1340 int take; 1340 int take;
1341 Event* eventRSync; 1341 Event* eventRSync;
1342 Event* eventLSync; 1342 Event* eventLSync;
1343 clearAllViews(); 1343 clearAllViews();
1344 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1344 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1345 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1345 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1346 bool fullDateRange = false; 1346 bool fullDateRange = false;
1347 local->resetTempSyncStat(); 1347 local->resetTempSyncStat();
1348 mLastCalendarSync = QDateTime::currentDateTime(); 1348 mLastCalendarSync = QDateTime::currentDateTime();
1349 if ( mSyncManager->syncWithDesktop() ) { 1349 if ( mSyncManager->syncWithDesktop() ) {
1350 remote->resetPilotStat(1); 1350 remote->resetPilotStat(1);
1351 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1351 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1352 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1352 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1353 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1353 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1354 } else { 1354 } else {
1355 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1355 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1356 } 1356 }
1357 } 1357 }
1358 QDateTime modifiedCalendar = mLastCalendarSync; 1358 QDateTime modifiedCalendar = mLastCalendarSync;
1359 eventLSync = getLastSyncEvent(); 1359 eventLSync = getLastSyncEvent();
1360 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1360 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1361 if ( eventR ) { 1361 if ( eventR ) {
1362 eventRSync = (Event*) eventR->clone(); 1362 eventRSync = (Event*) eventR->clone();
1363 remote->deleteEvent(eventR ); 1363 remote->deleteEvent(eventR );
1364 1364
1365 } else { 1365 } else {
1366 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1366 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1367 eventRSync = (Event*)eventLSync->clone(); 1367 eventRSync = (Event*)eventLSync->clone();
1368 } else { 1368 } else {
1369 fullDateRange = true; 1369 fullDateRange = true;
1370 eventRSync = new Event(); 1370 eventRSync = new Event();
1371 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1371 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1372 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1372 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1373 eventRSync->setDtStart( mLastCalendarSync ); 1373 eventRSync->setDtStart( mLastCalendarSync );
1374 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1374 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1375 eventRSync->setCategories( i18n("SyncEvent") ); 1375 eventRSync->setCategories( i18n("SyncEvent") );
1376 } 1376 }
1377 } 1377 }
1378 if ( eventLSync->dtStart() == mLastCalendarSync ) 1378 if ( eventLSync->dtStart() == mLastCalendarSync )
1379 fullDateRange = true; 1379 fullDateRange = true;
1380 1380
1381 if ( ! fullDateRange ) { 1381 if ( ! fullDateRange ) {
1382 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1382 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1383 1383
1384 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1384 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1385 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1385 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1386 fullDateRange = true; 1386 fullDateRange = true;
1387 } 1387 }
1388 } 1388 }
1389 if ( mSyncManager->syncWithDesktop() ) { 1389 if ( mSyncManager->syncWithDesktop() ) {
1390 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1390 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1391 } 1391 }
1392 if ( fullDateRange ) 1392 if ( fullDateRange )
1393 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1393 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1394 else 1394 else
1395 mLastCalendarSync = eventLSync->dtStart(); 1395 mLastCalendarSync = eventLSync->dtStart();
1396 // for resyncing if own file has changed 1396 // for resyncing if own file has changed
1397 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1397 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1398 mLastCalendarSync = loadedFileVersion; 1398 mLastCalendarSync = loadedFileVersion;
1399 //qDebug("setting mLastCalendarSync "); 1399 //qDebug("setting mLastCalendarSync ");
1400 } 1400 }
1401 //qDebug("*************************** "); 1401 //qDebug("*************************** ");
1402 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1402 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1403 QPtrList<Incidence> er = remote->rawIncidences(); 1403 QPtrList<Incidence> er = remote->rawIncidences();
1404 Incidence* inR = er.first(); 1404 Incidence* inR = er.first();
1405 Incidence* inL; 1405 Incidence* inL;
1406 QProgressBar bar( er.count(),0 ); 1406 QProgressBar bar( er.count(),0 );
1407 bar.setCaption (i18n("Syncing - close to abort!") ); 1407 bar.setCaption (i18n("Syncing - close to abort!") );
1408 1408
1409 // ************** setting up filter ************* 1409 // ************** setting up filter *************
1410 CalFilter *filterIN = 0; 1410 CalFilter *filterIN = 0;
1411 CalFilter *filterOUT = 0; 1411 CalFilter *filterOUT = 0;
1412 CalFilter *filter = mFilters.first(); 1412 CalFilter *filter = mFilters.first();
1413 while(filter) { 1413 while(filter) {
1414 if ( filter->name() == mSyncManager->mFilterInCal ) 1414 if ( filter->name() == mSyncManager->mFilterInCal )
1415 filterIN = filter; 1415 filterIN = filter;
1416 if ( filter->name() == mSyncManager->mFilterOutCal ) 1416 if ( filter->name() == mSyncManager->mFilterOutCal )
1417 filterOUT = filter; 1417 filterOUT = filter;
1418 filter = mFilters.next(); 1418 filter = mFilters.next();
1419 } 1419 }
1420 int w = 300; 1420 int w = 300;
1421 if ( QApplication::desktop()->width() < 320 ) 1421 if ( QApplication::desktop()->width() < 320 )
1422 w = 220; 1422 w = 220;
1423 int h = bar.sizeHint().height() ; 1423 int h = bar.sizeHint().height() ;
1424 int dw = QApplication::desktop()->width(); 1424 int dw = QApplication::desktop()->width();
1425 int dh = QApplication::desktop()->height(); 1425 int dh = QApplication::desktop()->height();
1426 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1426 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1427 bar.show(); 1427 bar.show();
1428 int modulo = (er.count()/10)+1; 1428 int modulo = (er.count()/10)+1;
1429 int incCounter = 0; 1429 int incCounter = 0;
1430 while ( inR ) { 1430 while ( inR ) {
1431 if ( ! bar.isVisible() ) 1431 if ( ! bar.isVisible() )
1432 return false; 1432 return false;
1433 if ( incCounter % modulo == 0 ) 1433 if ( incCounter % modulo == 0 )
1434 bar.setProgress( incCounter ); 1434 bar.setProgress( incCounter );
1435 ++incCounter; 1435 ++incCounter;
1436 uid = inR->uid(); 1436 uid = inR->uid();
1437 bool skipIncidence = false; 1437 bool skipIncidence = false;
1438 if ( uid.left(15) == QString("last-syncEvent-") ) 1438 if ( uid.left(15) == QString("last-syncEvent-") )
1439 skipIncidence = true; 1439 skipIncidence = true;
1440 QString idS; 1440 QString idS;
1441 qApp->processEvents(); 1441 qApp->processEvents();
1442 if ( !skipIncidence ) { 1442 if ( !skipIncidence ) {
1443 inL = local->incidence( uid ); 1443 inL = local->incidence( uid );
1444 if ( inL ) { // maybe conflict - same uid in both calendars 1444 if ( inL ) { // maybe conflict - same uid in both calendars
1445 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1445 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1446 //qDebug("take %d %s ", take, inL->summary().latin1()); 1446 //qDebug("take %d %s ", take, inL->summary().latin1());
1447 if ( take == 3 ) 1447 if ( take == 3 )
1448 return false; 1448 return false;
1449 if ( take == 1 ) {// take local ********************** 1449 if ( take == 1 ) {// take local **********************
1450 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1450 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1451 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1451 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1452 else 1452 else
1453 idS = inR->IDStr(); 1453 idS = inR->IDStr();
1454 remote->deleteIncidence( inR ); 1454 remote->deleteIncidence( inR );
1455 inR = inL->clone(); 1455 inR = inL->clone();
1456 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1456 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1457 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1457 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1458 inR->setIDStr( idS ); 1458 inR->setIDStr( idS );
1459 remote->addIncidence( inR ); 1459 remote->addIncidence( inR );
1460 if ( mSyncManager->syncWithDesktop() ) 1460 if ( mSyncManager->syncWithDesktop() )
1461 inR->setPilotId( 2 ); 1461 inR->setPilotId( 2 );
1462 ++changedRemote; 1462 ++changedRemote;
1463 } else {// take remote ********************** 1463 } else {// take remote **********************
1464 idS = inL->IDStr(); 1464 idS = inL->IDStr();
1465 int pid = inL->pilotId(); 1465 int pid = inL->pilotId();
1466 local->deleteIncidence( inL ); 1466 local->deleteIncidence( inL );
1467 inL = inR->clone(); 1467 inL = inR->clone();
1468 if ( mSyncManager->syncWithDesktop() ) 1468 if ( mSyncManager->syncWithDesktop() )
1469 inL->setPilotId( pid ); 1469 inL->setPilotId( pid );
1470 inL->setIDStr( idS ); 1470 inL->setIDStr( idS );
1471 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1471 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1472 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1472 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1473 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1473 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1474 } 1474 }
1475 local->addIncidence( inL ); 1475 local->addIncidence( inL );
1476 ++changedLocal; 1476 ++changedLocal;
1477 } 1477 }
1478 } 1478 }
1479 } else { // no conflict ********** add or delete remote 1479 } else { // no conflict ********** add or delete remote
1480 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1480 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1481 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1481 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1482 QString des = eventLSync->description(); 1482 QString des = eventLSync->description();
1483 QString pref = "e"; 1483 QString pref = "e";
1484 if ( inR->typeID() == todoID ) 1484 if ( inR->typeID() == todoID )
1485 pref = "t"; 1485 pref = "t";
1486 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1486 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1487 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1487 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1488 //remote->deleteIncidence( inR ); 1488 //remote->deleteIncidence( inR );
1489 ++deletedEventR; 1489 ++deletedEventR;
1490 } else { 1490 } else {
1491 inR->setLastModified( modifiedCalendar ); 1491 inR->setLastModified( modifiedCalendar );
1492 inL = inR->clone(); 1492 inL = inR->clone();
1493 inL->setIDStr( ":" ); 1493 inL->setIDStr( ":" );
1494 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1494 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1495 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1495 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1496 local->addIncidence( inL ); 1496 local->addIncidence( inL );
1497 ++addedEvent; 1497 ++addedEvent;
1498 1498
1499 } 1499 }
1500 } else { 1500 } else {
1501 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1501 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1502 inR->setLastModified( modifiedCalendar ); 1502 inR->setLastModified( modifiedCalendar );
1503 inL = inR->clone(); 1503 inL = inR->clone();
1504 inL->setIDStr( ":" ); 1504 inL->setIDStr( ":" );
1505 local->addIncidence( inL ); 1505 local->addIncidence( inL );
1506 ++addedEvent; 1506 ++addedEvent;
1507 1507
1508 } else { 1508 } else {
1509 checkExternSyncEvent(eventRSyncSharp, inR); 1509 checkExternSyncEvent(eventRSyncSharp, inR);
1510 remote->deleteIncidence( inR ); 1510 remote->deleteIncidence( inR );
1511 ++deletedEventR; 1511 ++deletedEventR;
1512 } 1512 }
1513 } 1513 }
1514 } else { 1514 } else {
1515 ++filteredIN; 1515 ++filteredIN;
1516 } 1516 }
1517 } 1517 }
1518 } 1518 }
1519 inR = er.next(); 1519 inR = er.next();
1520 } 1520 }
1521 QPtrList<Incidence> el = local->rawIncidences(); 1521 QPtrList<Incidence> el = local->rawIncidences();
1522 inL = el.first(); 1522 inL = el.first();
1523 modulo = (el.count()/10)+1; 1523 modulo = (el.count()/10)+1;
1524 bar.setCaption (i18n("Add / remove events") ); 1524 bar.setCaption (i18n("Add / remove events") );
1525 bar.setTotalSteps ( el.count() ) ; 1525 bar.setTotalSteps ( el.count() ) ;
1526 bar.show(); 1526 bar.show();
1527 incCounter = 0; 1527 incCounter = 0;
1528 1528
1529 while ( inL ) { 1529 while ( inL ) {
1530 1530
1531 qApp->processEvents(); 1531 qApp->processEvents();
1532 if ( ! bar.isVisible() ) 1532 if ( ! bar.isVisible() )
1533 return false; 1533 return false;
1534 if ( incCounter % modulo == 0 ) 1534 if ( incCounter % modulo == 0 )
1535 bar.setProgress( incCounter ); 1535 bar.setProgress( incCounter );
1536 ++incCounter; 1536 ++incCounter;
1537 uid = inL->uid(); 1537 uid = inL->uid();
1538 bool skipIncidence = false; 1538 bool skipIncidence = false;
1539 if ( uid.left(15) == QString("last-syncEvent-") ) 1539 if ( uid.left(15) == QString("last-syncEvent-") )
1540 skipIncidence = true; 1540 skipIncidence = true;
1541 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1541 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1542 skipIncidence = true; 1542 skipIncidence = true;
1543 if ( !skipIncidence ) { 1543 if ( !skipIncidence ) {
1544 inR = remote->incidence( uid ); 1544 inR = remote->incidence( uid );
1545 if ( ! inR ) { 1545 if ( ! inR ) {
1546 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1546 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1547 // no conflict ********** add or delete local 1547 // no conflict ********** add or delete local
1548 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1548 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1549 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1549 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1550 checkExternSyncEvent(eventLSyncSharp, inL); 1550 checkExternSyncEvent(eventLSyncSharp, inL);
1551 local->deleteIncidence( inL ); 1551 local->deleteIncidence( inL );
1552 ++deletedEventL; 1552 ++deletedEventL;
1553 } else { 1553 } else {
1554 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1554 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1555 inL->removeID(mCurrentSyncDevice ); 1555 inL->removeID(mCurrentSyncDevice );
1556 ++addedEventR; 1556 ++addedEventR;
1557 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1557 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1558 inL->setLastModified( modifiedCalendar ); 1558 inL->setLastModified( modifiedCalendar );
1559 inR = inL->clone(); 1559 inR = inL->clone();
1560 inR->setIDStr( ":" ); 1560 inR->setIDStr( ":" );
1561 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1561 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1562 remote->addIncidence( inR ); 1562 remote->addIncidence( inR );
1563 } 1563 }
1564 } 1564 }
1565 } else { 1565 } else {
1566 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1566 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1567 checkExternSyncEvent(eventLSyncSharp, inL); 1567 checkExternSyncEvent(eventLSyncSharp, inL);
1568 local->deleteIncidence( inL ); 1568 local->deleteIncidence( inL );
1569 ++deletedEventL; 1569 ++deletedEventL;
1570 } else { 1570 } else {
1571 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1571 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1572 ++addedEventR; 1572 ++addedEventR;
1573 inL->setLastModified( modifiedCalendar ); 1573 inL->setLastModified( modifiedCalendar );
1574 inR = inL->clone(); 1574 inR = inL->clone();
1575 inR->setIDStr( ":" ); 1575 inR->setIDStr( ":" );
1576 remote->addIncidence( inR ); 1576 remote->addIncidence( inR );
1577 } 1577 }
1578 } 1578 }
1579 } 1579 }
1580 } else { 1580 } else {
1581 ++filteredOUT; 1581 ++filteredOUT;
1582 } 1582 }
1583 } 1583 }
1584 } 1584 }
1585 inL = el.next(); 1585 inL = el.next();
1586 } 1586 }
1587 int delFut = 0; 1587 int delFut = 0;
1588 int remRem = 0; 1588 int remRem = 0;
1589 if ( mSyncManager->mWriteBackInFuture ) { 1589 if ( mSyncManager->mWriteBackInFuture ) {
1590 er = remote->rawIncidences(); 1590 er = remote->rawIncidences();
1591 remRem = er.count(); 1591 remRem = er.count();
1592 inR = er.first(); 1592 inR = er.first();
1593 QDateTime dt; 1593 QDateTime dt;
1594 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1594 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1595 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1595 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1596 while ( inR ) { 1596 while ( inR ) {
1597 if ( inR->typeID() == todoID ) { 1597 if ( inR->typeID() == todoID ) {
1598 Todo * t = (Todo*)inR; 1598 Todo * t = (Todo*)inR;
1599 if ( t->hasDueDate() ) 1599 if ( t->hasDueDate() )
1600 dt = t->dtDue(); 1600 dt = t->dtDue();
1601 else 1601 else
1602 dt = cur.addSecs( 62 ); 1602 dt = cur.addSecs( 62 );
1603 } 1603 }
1604 else if (inR->typeID() == eventID ) { 1604 else if (inR->typeID() == eventID ) {
1605 bool ok; 1605 bool ok;
1606 dt = inR->getNextOccurence( cur, &ok ); 1606 dt = inR->getNextOccurence( cur, &ok );
1607 if ( !ok ) 1607 if ( !ok )
1608 dt = cur.addSecs( -62 ); 1608 dt = cur.addSecs( -62 );
1609 } 1609 }
1610 else 1610 else
1611 dt = inR->dtStart(); 1611 dt = inR->dtStart();
1612 if ( dt < cur || dt > end ) { 1612 if ( dt < cur || dt > end ) {
1613 remote->deleteIncidence( inR ); 1613 remote->deleteIncidence( inR );
1614 ++delFut; 1614 ++delFut;
1615 } 1615 }
1616 inR = er.next(); 1616 inR = er.next();
1617 } 1617 }
1618 } 1618 }
1619 bar.hide(); 1619 bar.hide();
1620 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1620 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1621 eventLSync->setReadOnly( false ); 1621 eventLSync->setReadOnly( false );
1622 eventLSync->setDtStart( mLastCalendarSync ); 1622 eventLSync->setDtStart( mLastCalendarSync );
1623 eventRSync->setDtStart( mLastCalendarSync ); 1623 eventRSync->setDtStart( mLastCalendarSync );
1624 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1624 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1625 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1625 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1626 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1626 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1627 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1627 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1628 eventLSync->setReadOnly( true ); 1628 eventLSync->setReadOnly( true );
1629 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1629 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1630 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1630 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1631 remote->addEvent( eventRSync ); 1631 remote->addEvent( eventRSync );
1632 else 1632 else
1633 delete eventRSync; 1633 delete eventRSync;
1634 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1634 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1635 QString mes; 1635 QString mes;
1636 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 %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); 1636 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 %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT );
1637 QString delmess; 1637 QString delmess;
1638 if ( delFut ) { 1638 if ( delFut ) {
1639 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); 1639 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut);
1640 mes += delmess; 1640 mes += delmess;
1641 } 1641 }
1642 mes = i18n("Local calendar changed!\n") +mes; 1642 mes = i18n("Local calendar changed!\n") +mes;
1643 mCalendar->checkAlarmForIncidence( 0, true ); 1643 mCalendar->checkAlarmForIncidence( 0, true );
1644 qDebug( mes ); 1644 qDebug( mes );
1645 if ( mSyncManager->mShowSyncSummary ) { 1645 if ( mSyncManager->mShowSyncSummary ) {
1646 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1646 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1647 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1647 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1648 qDebug("KO: WB cancelled "); 1648 qDebug("KO: WB cancelled ");
1649 mSyncManager->mWriteBackFile = false; 1649 mSyncManager->mWriteBackFile = false;
1650 return syncOK; 1650 return syncOK;
1651 } 1651 }
1652 } 1652 }
1653 return syncOK; 1653 return syncOK;
1654} 1654}
1655 1655
1656void CalendarView::setSyncDevice( QString s ) 1656void CalendarView::setSyncDevice( QString s )
1657{ 1657{
1658 mCurrentSyncDevice= s; 1658 mCurrentSyncDevice= s;
1659} 1659}
1660void CalendarView::setSyncName( QString s ) 1660void CalendarView::setSyncName( QString s )
1661{ 1661{
1662 mCurrentSyncName= s; 1662 mCurrentSyncName= s;
1663} 1663}
1664bool CalendarView::syncCalendar(QString filename, int mode) 1664bool CalendarView::syncCalendar(QString filename, int mode)
1665{ 1665{
1666 //qDebug("syncCalendar %s ", filename.latin1()); 1666 //qDebug("syncCalendar %s ", filename.latin1());
1667 mGlobalSyncMode = SYNC_MODE_NORMAL; 1667 mGlobalSyncMode = SYNC_MODE_NORMAL;
1668 CalendarLocal* calendar = new CalendarLocal(); 1668 CalendarLocal* calendar = new CalendarLocal();
1669 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1669 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1670 FileStorage* storage = new FileStorage( calendar ); 1670 FileStorage* storage = new FileStorage( calendar );
1671 bool syncOK = false; 1671 bool syncOK = false;
1672 storage->setFileName( filename ); 1672 storage->setFileName( filename );
1673 // qDebug("loading ... "); 1673 // qDebug("loading ... ");
1674 if ( storage->load() ) { 1674 if ( storage->load() ) {
1675 getEventViewerDialog()->setSyncMode( true ); 1675 getEventViewerDialog()->setSyncMode( true );
1676 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1676 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1677 getEventViewerDialog()->setSyncMode( false ); 1677 getEventViewerDialog()->setSyncMode( false );
1678 if ( syncOK ) { 1678 if ( syncOK ) {
1679 if ( mSyncManager->mWriteBackFile ) 1679 if ( mSyncManager->mWriteBackFile )
1680 { 1680 {
1681 storage->setSaveFormat( new ICalFormat() ); 1681 storage->setSaveFormat( new ICalFormat() );
1682 storage->save(); 1682 storage->save();
1683 } 1683 }
1684 } 1684 }
1685 setModified( true ); 1685 setModified( true );
1686 } 1686 }
1687 delete storage; 1687 delete storage;
1688 delete calendar; 1688 delete calendar;
1689 if ( syncOK ) 1689 if ( syncOK )
1690 updateView(); 1690 updateView();
1691 return syncOK; 1691 return syncOK;
1692} 1692}
1693 1693
1694void CalendarView::syncExternal( int mode ) 1694void CalendarView::syncExternal( int mode )
1695{ 1695{
1696 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1696 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1697 1697
1698 qApp->processEvents(); 1698 qApp->processEvents();
1699 CalendarLocal* calendar = new CalendarLocal(); 1699 CalendarLocal* calendar = new CalendarLocal();
1700 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1700 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1701 bool syncOK = false; 1701 bool syncOK = false;
1702 bool loadSuccess = false; 1702 bool loadSuccess = false;
1703 PhoneFormat* phoneFormat = 0; 1703 PhoneFormat* phoneFormat = 0;
1704 emit tempDisableBR(true); 1704 emit tempDisableBR(true);
1705#ifndef DESKTOP_VERSION 1705#ifndef DESKTOP_VERSION
1706 SharpFormat* sharpFormat = 0; 1706 SharpFormat* sharpFormat = 0;
1707 if ( mode == 0 ) { // sharp 1707 if ( mode == 0 ) { // sharp
1708 sharpFormat = new SharpFormat () ; 1708 sharpFormat = new SharpFormat () ;
1709 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1709 loadSuccess = sharpFormat->load( calendar, mCalendar );
1710 1710
1711 } else 1711 } else
1712#endif 1712#endif
1713 if ( mode == 1 ) { // phone 1713 if ( mode == 1 ) { // phone
1714 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1714 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1715 mSyncManager->mPhoneDevice, 1715 mSyncManager->mPhoneDevice,
1716 mSyncManager->mPhoneConnection, 1716 mSyncManager->mPhoneConnection,
1717 mSyncManager->mPhoneModel); 1717 mSyncManager->mPhoneModel);
1718 loadSuccess = phoneFormat->load( calendar,mCalendar); 1718 loadSuccess = phoneFormat->load( calendar,mCalendar);
1719 1719
1720 } else { 1720 } else {
1721 emit tempDisableBR(false); 1721 emit tempDisableBR(false);
1722 return; 1722 return;
1723 } 1723 }
1724 if ( loadSuccess ) { 1724 if ( loadSuccess ) {
1725 getEventViewerDialog()->setSyncMode( true ); 1725 getEventViewerDialog()->setSyncMode( true );
1726 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1726 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1727 getEventViewerDialog()->setSyncMode( false ); 1727 getEventViewerDialog()->setSyncMode( false );
1728 qApp->processEvents(); 1728 qApp->processEvents();
1729 if ( syncOK ) { 1729 if ( syncOK ) {
1730 if ( mSyncManager->mWriteBackFile ) 1730 if ( mSyncManager->mWriteBackFile )
1731 { 1731 {
1732 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1732 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1733 Incidence* inc = iL.first(); 1733 Incidence* inc = iL.first();
1734 if ( phoneFormat ) { 1734 if ( phoneFormat ) {
1735 while ( inc ) { 1735 while ( inc ) {
1736 inc->removeID(mCurrentSyncDevice); 1736 inc->removeID(mCurrentSyncDevice);
1737 inc = iL.next(); 1737 inc = iL.next();
1738 } 1738 }
1739 } 1739 }
1740#ifndef DESKTOP_VERSION 1740#ifndef DESKTOP_VERSION
1741 if ( sharpFormat ) 1741 if ( sharpFormat )
1742 sharpFormat->save(calendar); 1742 sharpFormat->save(calendar);
1743#endif 1743#endif
1744 if ( phoneFormat ) 1744 if ( phoneFormat )
1745 phoneFormat->save(calendar); 1745 phoneFormat->save(calendar);
1746 iL = calendar->rawIncidences(); 1746 iL = calendar->rawIncidences();
1747 inc = iL.first(); 1747 inc = iL.first();
1748 Incidence* loc; 1748 Incidence* loc;
1749 while ( inc ) { 1749 while ( inc ) {
1750 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1750 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1751 loc = mCalendar->incidence(inc->uid() ); 1751 loc = mCalendar->incidence(inc->uid() );
1752 if ( loc ) { 1752 if ( loc ) {
1753 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1753 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1754 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1754 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1755 } 1755 }
1756 } 1756 }
1757 inc = iL.next(); 1757 inc = iL.next();
1758 } 1758 }
1759 Incidence* lse = getLastSyncEvent(); 1759 Incidence* lse = getLastSyncEvent();
1760 if ( lse ) { 1760 if ( lse ) {
1761 lse->setReadOnly( false ); 1761 lse->setReadOnly( false );
1762 lse->setDescription( "" ); 1762 lse->setDescription( "" );
1763 lse->setReadOnly( true ); 1763 lse->setReadOnly( true );
1764 } 1764 }
1765 } 1765 }
1766 } else { 1766 } else {
1767 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1767 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1768 } 1768 }
1769 setModified( true ); 1769 setModified( true );
1770 } else { 1770 } else {
1771 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1771 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1772 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1772 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1773 question, i18n("Ok")) ; 1773 question, i18n("Ok")) ;
1774 1774
1775 } 1775 }
1776 delete calendar; 1776 delete calendar;
1777 updateView(); 1777 updateView();
1778 emit tempDisableBR(false); 1778 emit tempDisableBR(false);
1779 return ;//syncOK; 1779 return ;//syncOK;
1780 1780
1781} 1781}
1782 1782
1783bool CalendarView::importBday() 1783bool CalendarView::importBday()
1784{ 1784{
1785#ifndef KORG_NOKABC 1785#ifndef KORG_NOKABC
1786 1786
1787#ifdef DESKTOP_VERSION 1787#ifdef DESKTOP_VERSION
1788 int curCal = mCalendar->defaultCalendar(); 1788 int curCal = mCalendar->defaultCalendar();
1789 int bd = mCalEditView->getBirtdayID(); 1789 int bd = mCalEditView->getBirtdayID();
1790 if ( bd == 0 ) 1790 if ( bd == 0 )
1791 return false; 1791 return false;
1792 mCalendar->setDefaultCalendar( bd ); 1792 mCalendar->setDefaultCalendar( bd );
1793 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1793 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1794 KABC::AddressBook::Iterator it; 1794 KABC::AddressBook::Iterator it;
1795 int count = 0; 1795 int count = 0;
1796 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1796 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1797 ++count; 1797 ++count;
1798 } 1798 }
1799 QProgressBar bar(count,0 ); 1799 QProgressBar bar(count,0 );
1800 int w = 300; 1800 int w = 300;
1801 if ( QApplication::desktop()->width() < 320 ) 1801 if ( QApplication::desktop()->width() < 320 )
1802 w = 220; 1802 w = 220;
1803 int h = bar.sizeHint().height() ; 1803 int h = bar.sizeHint().height() ;
1804 int dw = QApplication::desktop()->width(); 1804 int dw = QApplication::desktop()->width();
1805 int dh = QApplication::desktop()->height(); 1805 int dh = QApplication::desktop()->height();
1806 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1806 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1807 bar.show(); 1807 bar.show();
1808 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1808 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1809 qApp->processEvents(); 1809 qApp->processEvents();
1810 count = 0; 1810 count = 0;
1811 int addCount = 0; 1811 int addCount = 0;
1812 KCal::Attendee* a = 0; 1812 KCal::Attendee* a = 0;
1813 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1813 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1814 if ( ! bar.isVisible() ) 1814 if ( ! bar.isVisible() )
1815 return false; 1815 return false;
1816 bar.setProgress( count++ ); 1816 bar.setProgress( count++ );
1817 qApp->processEvents(); 1817 qApp->processEvents();
1818 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1818 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1819 if ( (*it).birthday().date().isValid() ){ 1819 if ( (*it).birthday().date().isValid() ){
1820 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1820 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1821 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1821 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1822 ++addCount; 1822 ++addCount;
1823 } 1823 }
1824 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1824 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1825 if ( anni.isValid() ){ 1825 if ( anni.isValid() ){
1826 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1826 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1827 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1827 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1828 ++addCount; 1828 ++addCount;
1829 } 1829 }
1830 } 1830 }
1831 mCalendar->setDefaultCalendar( curCal ); 1831 mCalendar->setDefaultCalendar( curCal );
1832 updateView(); 1832 updateView();
1833 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1833 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1834#else //DESKTOP_VERSION 1834#else //DESKTOP_VERSION
1835 1835
1836 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1836 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1837 // the result should now arrive through method insertBirthdays 1837 // the result should now arrive through method insertBirthdays
1838 1838
1839#endif //DESKTOP_VERSION 1839#endif //DESKTOP_VERSION
1840 1840
1841#endif //KORG_NOKABC 1841#endif //KORG_NOKABC
1842 1842
1843 1843
1844 return true; 1844 return true;
1845} 1845}
1846 1846
1847// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1847// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1848void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1848void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1849 const QStringList& anniversaryList, const QStringList& realNameList, 1849 const QStringList& anniversaryList, const QStringList& realNameList,
1850 const QStringList& emailList, const QStringList& assembledNameList, 1850 const QStringList& emailList, const QStringList& assembledNameList,
1851 const QStringList& uidList) 1851 const QStringList& uidList)
1852{ 1852{
1853 1853
1854 //qDebug("KO::CalendarView::insertBirthdays"); 1854 //qDebug("KO::CalendarView::insertBirthdays");
1855 if (uid == this->name()) 1855 if (uid == this->name())
1856 { 1856 {
1857 int curCal = mCalendar->defaultCalendar(); 1857 int curCal = mCalendar->defaultCalendar();
1858 int bd = mCalEditView->getBirtdayID(); 1858 int bd = mCalEditView->getBirtdayID();
1859 if ( bd == 0 ) 1859 if ( bd == 0 )
1860 return; 1860 return;
1861 mCalendar->setDefaultCalendar( bd ); 1861 mCalendar->setDefaultCalendar( bd );
1862 1862
1863 1863
1864 int count = birthdayList.count(); 1864 int count = birthdayList.count();
1865 int addCount = 0; 1865 int addCount = 0;
1866 KCal::Attendee* a = 0; 1866 KCal::Attendee* a = 0;
1867 1867
1868 //qDebug("CalView 1 %i", count); 1868 //qDebug("CalView 1 %i", count);
1869 1869
1870 QProgressBar bar(count,0 ); 1870 QProgressBar bar(count,0 );
1871 int w = 300; 1871 int w = 300;
1872 if ( QApplication::desktop()->width() < 320 ) 1872 if ( QApplication::desktop()->width() < 320 )
1873 w = 220; 1873 w = 220;
1874 int h = bar.sizeHint().height() ; 1874 int h = bar.sizeHint().height() ;
1875 int dw = QApplication::desktop()->width(); 1875 int dw = QApplication::desktop()->width();
1876 int dh = QApplication::desktop()->height(); 1876 int dh = QApplication::desktop()->height();
1877 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1877 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1878 bar.show(); 1878 bar.show();
1879 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1879 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1880 qApp->processEvents(); 1880 qApp->processEvents();
1881 1881
1882 QDate birthday; 1882 QDate birthday;
1883 QDate anniversary; 1883 QDate anniversary;
1884 QString realName; 1884 QString realName;
1885 QString email; 1885 QString email;
1886 QString assembledName; 1886 QString assembledName;
1887 QString uid; 1887 QString uid;
1888 bool ok = true; 1888 bool ok = true;
1889 for ( int i = 0; i < count; i++) 1889 for ( int i = 0; i < count; i++)
1890 { 1890 {
1891 if ( ! bar.isVisible() ) 1891 if ( ! bar.isVisible() )
1892 return; 1892 return;
1893 bar.setProgress( i ); 1893 bar.setProgress( i );
1894 qApp->processEvents(); 1894 qApp->processEvents();
1895 1895
1896 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1896 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1897 if (!ok) { 1897 if (!ok) {
1898 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1898 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1899 } 1899 }
1900 1900
1901 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1901 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1902 if (!ok) { 1902 if (!ok) {
1903 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1903 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1904 } 1904 }
1905 realName = realNameList[i]; 1905 realName = realNameList[i];
1906 email = emailList[i]; 1906 email = emailList[i];
1907 assembledName = assembledNameList[i]; 1907 assembledName = assembledNameList[i];
1908 uid = uidList[i]; 1908 uid = uidList[i];
1909 //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() ); 1909 //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() );
1910 1910
1911 if ( birthday.isValid() ){ 1911 if ( birthday.isValid() ){
1912 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1912 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1913 KCal::Attendee::ReqParticipant,uid) ; 1913 KCal::Attendee::ReqParticipant,uid) ;
1914 if ( addAnniversary( birthday, assembledName, a, true ) ) 1914 if ( addAnniversary( birthday, assembledName, a, true ) )
1915 ++addCount; 1915 ++addCount;
1916 } 1916 }
1917 1917
1918 if ( anniversary.isValid() ){ 1918 if ( anniversary.isValid() ){
1919 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1919 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1920 KCal::Attendee::ReqParticipant,uid) ; 1920 KCal::Attendee::ReqParticipant,uid) ;
1921 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1921 if ( addAnniversary( anniversary, assembledName, a, false ) )
1922 ++addCount; 1922 ++addCount;
1923 } 1923 }
1924 } 1924 }
1925 1925
1926 mCalendar->setDefaultCalendar( curCal ); 1926 mCalendar->setDefaultCalendar( curCal );
1927 updateView(); 1927 updateView();
1928 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1928 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1929 1929
1930 } 1930 }
1931 1931
1932} 1932}
1933 1933
1934 1934
1935 1935
1936bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1936bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1937{ 1937{
1938 //qDebug("addAnni "); 1938 //qDebug("addAnni ");
1939 Event * ev = new Event(); 1939 Event * ev = new Event();
1940 ev->setOrganizer(KOPrefs::instance()->email()); 1940 ev->setOrganizer(KOPrefs::instance()->email());
1941 if ( a ) { 1941 if ( a ) {
1942 ev->addAttendee( a ); 1942 ev->addAttendee( a );
1943 } 1943 }
1944 QString kind; 1944 QString kind;
1945 if ( birthday ) { 1945 if ( birthday ) {
1946 kind = i18n( "Birthday" ); 1946 kind = i18n( "Birthday" );
1947 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1947 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1948 } 1948 }
1949 else { 1949 else {
1950 kind = i18n( "Anniversary" ); 1950 kind = i18n( "Anniversary" );
1951 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1951 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1952 } 1952 }
1953 ev->setCategories( kind ); 1953 ev->setCategories( kind );
1954 ev->setDtStart( QDateTime(date) ); 1954 ev->setDtStart( QDateTime(date) );
1955 ev->setDtEnd( QDateTime(date) ); 1955 ev->setDtEnd( QDateTime(date) );
1956 ev->setFloats( true ); 1956 ev->setFloats( true );
1957 Recurrence * rec = ev->recurrence(); 1957 Recurrence * rec = ev->recurrence();
1958 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1958 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1959 rec->addYearlyNum( date.month() ); 1959 rec->addYearlyNum( date.month() );
1960 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1960 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1961 delete ev; 1961 delete ev;
1962 return false; 1962 return false;
1963 } 1963 }
1964 return true; 1964 return true;
1965 1965
1966} 1966}
1967bool CalendarView::importQtopia( const QString &categories, 1967bool CalendarView::importQtopia( const QString &categories,
1968 const QString &datebook, 1968 const QString &datebook,
1969 const QString &todolist ) 1969 const QString &todolist )
1970{ 1970{
1971 1971
1972 QtopiaFormat qtopiaFormat; 1972 QtopiaFormat qtopiaFormat;
1973 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1973 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1974 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1974 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1975 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1975 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1976 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1976 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1977 1977
1978 updateView(); 1978 updateView();
1979 return true; 1979 return true;
1980 1980
1981#if 0 1981#if 0
1982 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1982 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1983 mCurrentSyncDevice = "qtopia-XML"; 1983 mCurrentSyncDevice = "qtopia-XML";
1984 if ( mSyncManager->mAskForPreferences ) 1984 if ( mSyncManager->mAskForPreferences )
1985 edit_sync_options(); 1985 edit_sync_options();
1986 qApp->processEvents(); 1986 qApp->processEvents();
1987 CalendarLocal* calendar = new CalendarLocal(); 1987 CalendarLocal* calendar = new CalendarLocal();
1988 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1988 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1989 bool syncOK = false; 1989 bool syncOK = false;
1990 QtopiaFormat qtopiaFormat; 1990 QtopiaFormat qtopiaFormat;
1991 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1991 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1992 bool loadOk = true; 1992 bool loadOk = true;
1993 if ( !categories.isEmpty() ) 1993 if ( !categories.isEmpty() )
1994 loadOk = qtopiaFormat.load( calendar, categories ); 1994 loadOk = qtopiaFormat.load( calendar, categories );
1995 if ( loadOk && !datebook.isEmpty() ) 1995 if ( loadOk && !datebook.isEmpty() )
1996 loadOk = qtopiaFormat.load( calendar, datebook ); 1996 loadOk = qtopiaFormat.load( calendar, datebook );
1997 if ( loadOk && !todolist.isEmpty() ) 1997 if ( loadOk && !todolist.isEmpty() )
1998 loadOk = qtopiaFormat.load( calendar, todolist ); 1998 loadOk = qtopiaFormat.load( calendar, todolist );
1999 1999
2000 if ( loadOk ) { 2000 if ( loadOk ) {
2001 getEventViewerDialog()->setSyncMode( true ); 2001 getEventViewerDialog()->setSyncMode( true );
2002 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2002 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2003 getEventViewerDialog()->setSyncMode( false ); 2003 getEventViewerDialog()->setSyncMode( false );
2004 qApp->processEvents(); 2004 qApp->processEvents();
2005 if ( syncOK ) { 2005 if ( syncOK ) {
2006 if ( mSyncManager->mWriteBackFile ) 2006 if ( mSyncManager->mWriteBackFile )
2007 { 2007 {
2008 // write back XML file 2008 // write back XML file
2009 2009
2010 } 2010 }
2011 setModified( true ); 2011 setModified( true );
2012 } 2012 }
2013 } else { 2013 } else {
2014 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 2014 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
2015 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 2015 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
2016 question, i18n("Ok")) ; 2016 question, i18n("Ok")) ;
2017 } 2017 }
2018 delete calendar; 2018 delete calendar;
2019 updateView(); 2019 updateView();
2020 return syncOK; 2020 return syncOK;
2021 2021
2022 2022
2023#endif 2023#endif
2024 2024
2025} 2025}
2026 2026
2027void CalendarView::setSyncEventsReadOnly() 2027void CalendarView::setSyncEventsReadOnly()
2028{ 2028{
2029 mCalendar->setSyncEventsReadOnly(); 2029 mCalendar->setSyncEventsReadOnly();
2030} 2030}
2031 2031
2032bool CalendarView::loadCalendars() 2032bool CalendarView::loadCalendars()
2033{ 2033{
2034 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2034 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2035 KopiCalendarFile * cal = calendars.first(); 2035 KopiCalendarFile * cal = calendars.first();
2036 mCalendar->setDefaultCalendar( 1 ); 2036 mCalendar->setDefaultCalendar( 1 );
2037 openCalendar( MainWindow::defaultFileName(), false ); 2037 openCalendar( MainWindow::defaultFileName(), false );
2038 cal = calendars.next(); 2038 cal = calendars.next();
2039 while ( cal ) { 2039 while ( cal ) {
2040 addCalendar( cal ); 2040 addCalendar( cal );
2041 cal = calendars.next(); 2041 cal = calendars.next();
2042 } 2042 }
2043 restoreCalendarSettings(); 2043 restoreCalendarSettings();
2044 return true; 2044 return true;
2045} 2045}
2046bool CalendarView::restoreCalendarSettings() 2046bool CalendarView::restoreCalendarSettings()
2047{ 2047{
2048 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2048 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2049 KopiCalendarFile * cal = calendars.first(); 2049 KopiCalendarFile * cal = calendars.first();
2050 while ( cal ) { 2050 while ( cal ) {
2051 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 2051 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
2052 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 2052 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
2053 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 2053 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
2054 if ( cal->isStandard ) 2054 if ( cal->isStandard )
2055 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2055 mCalendar->setDefaultCalendar( cal->mCalNumber );
2056 cal = calendars.next(); 2056 cal = calendars.next();
2057 } 2057 }
2058 setSyncEventsReadOnly(); 2058 setSyncEventsReadOnly();
2059 mCalendar->reInitAlarmSettings(); 2059 mCalendar->reInitAlarmSettings();
2060 updateUnmanagedViews(); 2060 updateUnmanagedViews();
2061 updateView(); 2061 updateView();
2062 return true; 2062 return true;
2063} 2063}
2064void CalendarView::addCalendarId( int id ) 2064void CalendarView::addCalendarId( int id )
2065{ 2065{
2066 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 2066 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
2067 if ( cal ) 2067 if ( cal )
2068 addCalendar( cal ); 2068 addCalendar( cal );
2069} 2069}
2070bool CalendarView::addCalendar( KopiCalendarFile * cal ) 2070bool CalendarView::addCalendar( KopiCalendarFile * cal )
2071{ 2071{
2072 cal->mErrorOnLoad = false; 2072 cal->mErrorOnLoad = false;
2073 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 2073 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
2074 cal->mLoadDt = QDateTime::currentDateTime(); 2074 cal->mLoadDt = QDateTime::currentDateTime();
2075 return true; 2075 return true;
2076 } 2076 }
2077 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); 2077 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() );
2078 cal->mErrorOnLoad = true; 2078 cal->mErrorOnLoad = true;
2079 return false; 2079 return false;
2080} 2080}
2081bool CalendarView::openCalendar(QString filename, bool merge) 2081bool CalendarView::openCalendar(QString filename, bool merge)
2082{ 2082{
2083 2083
2084 if (filename.isEmpty()) { 2084 if (filename.isEmpty()) {
2085 return false; 2085 return false;
2086 } 2086 }
2087 2087
2088 if (!QFile::exists(filename)) { 2088 if (!QFile::exists(filename)) {
2089 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 2089 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
2090 return false; 2090 return false;
2091 } 2091 }
2092 2092
2093 globalFlagBlockAgenda = 1; 2093 globalFlagBlockAgenda = 1;
2094 clearAllViews(); 2094 clearAllViews();
2095 if (!merge) { 2095 if (!merge) {
2096 mViewManager->setDocumentId( filename ); 2096 mViewManager->setDocumentId( filename );
2097 mCalendar->close(); 2097 mCalendar->close();
2098 } 2098 }
2099 mStorage->setFileName( filename ); 2099 mStorage->setFileName( filename );
2100 2100
2101 if ( mStorage->load() ) { 2101 if ( mStorage->load() ) {
2102 if ( merge ) ;//setModified( true ); 2102 if ( merge ) ;//setModified( true );
2103 else { 2103 else {
2104 //setModified( true ); 2104 //setModified( true );
2105 mViewManager->setDocumentId( filename ); 2105 mViewManager->setDocumentId( filename );
2106 mDialogManager->setDocumentId( filename ); 2106 mDialogManager->setDocumentId( filename );
2107 mTodoList->setDocumentId( filename ); 2107 mTodoList->setDocumentId( filename );
2108 } 2108 }
2109 globalFlagBlockAgenda = 2; 2109 globalFlagBlockAgenda = 2;
2110 // if ( getLastSyncEvent() ) 2110 // if ( getLastSyncEvent() )
2111 // getLastSyncEvent()->setReadOnly( true ); 2111 // getLastSyncEvent()->setReadOnly( true );
2112 mCalendar->reInitAlarmSettings(); 2112 mCalendar->reInitAlarmSettings();
2113 setSyncEventsReadOnly(); 2113 setSyncEventsReadOnly();
2114 updateUnmanagedViews(); 2114 updateUnmanagedViews();
2115 updateView(); 2115 updateView();
2116 if ( filename != MainWindow::defaultFileName() ) { 2116 if ( filename != MainWindow::defaultFileName() ) {
2117 saveCalendar( MainWindow::defaultFileName() ); 2117 saveCalendar( MainWindow::defaultFileName() );
2118 } else { 2118 } else {
2119 QFileInfo finf ( MainWindow::defaultFileName()); 2119 QFileInfo finf ( MainWindow::defaultFileName());
2120 if ( finf.exists() ) { 2120 if ( finf.exists() ) {
2121 setLoadedFileVersion( finf.lastModified () ); 2121 setLoadedFileVersion( finf.lastModified () );
2122 } 2122 }
2123 } 2123 }
2124 return true; 2124 return true;
2125 } else { 2125 } else {
2126 // while failing to load, the calendar object could 2126 // while failing to load, the calendar object could
2127 // have become partially populated. Clear it out. 2127 // have become partially populated. Clear it out.
2128 if ( !merge ) { 2128 if ( !merge ) {
2129 mCalendar->close(); 2129 mCalendar->close();
2130 mViewManager->setDocumentId( filename ); 2130 mViewManager->setDocumentId( filename );
2131 mDialogManager->setDocumentId( filename ); 2131 mDialogManager->setDocumentId( filename );
2132 mTodoList->setDocumentId( filename ); 2132 mTodoList->setDocumentId( filename );
2133 } 2133 }
2134 2134
2135 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 2135 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
2136 2136
2137 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 2137 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
2138 globalFlagBlockAgenda = 2; 2138 globalFlagBlockAgenda = 2;
2139 mCalendar->reInitAlarmSettings(); 2139 mCalendar->reInitAlarmSettings();
2140 setSyncEventsReadOnly(); 2140 setSyncEventsReadOnly();
2141 updateUnmanagedViews(); 2141 updateUnmanagedViews();
2142 updateView(); 2142 updateView();
2143 } 2143 }
2144 return false; 2144 return false;
2145} 2145}
2146void CalendarView::showOpenError() 2146void CalendarView::showOpenError()
2147{ 2147{
2148 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 2148 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
2149} 2149}
2150void CalendarView::setLoadedFileVersion(QDateTime dt) 2150void CalendarView::setLoadedFileVersion(QDateTime dt)
2151{ 2151{
2152 loadedFileVersion = dt; 2152 loadedFileVersion = dt;
2153} 2153}
2154bool CalendarView::checkFileChanged(QString fn) 2154bool CalendarView::checkFileChanged(QString fn)
2155{ 2155{
2156 QFileInfo finf ( fn ); 2156 QFileInfo finf ( fn );
2157 if ( !finf.exists() ) 2157 if ( !finf.exists() )
2158 return true; 2158 return true;
2159 QDateTime dt = finf.lastModified (); 2159 QDateTime dt = finf.lastModified ();
2160 if ( dt <= loadedFileVersion ) 2160 if ( dt <= loadedFileVersion )
2161 return false; 2161 return false;
2162 return true; 2162 return true;
2163 2163
2164} 2164}
2165void CalendarView::watchSavedFile() 2165void CalendarView::watchSavedFile()
2166{ 2166{
2167 QFileInfo finf ( MainWindow::defaultFileName()); 2167 QFileInfo finf ( MainWindow::defaultFileName());
2168 if ( !finf.exists() ) 2168 if ( !finf.exists() )
2169 return; 2169 return;
2170 QDateTime dt = finf.lastModified (); 2170 QDateTime dt = finf.lastModified ();
2171 if ( dt < loadedFileVersion ) { 2171 if ( dt < loadedFileVersion ) {
2172 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 2172 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
2173 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 2173 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
2174 return; 2174 return;
2175 } 2175 }
2176 loadedFileVersion = dt; 2176 loadedFileVersion = dt;
2177} 2177}
2178bool CalendarView::checkAllFileVersions() 2178bool CalendarView::checkAllFileVersions()
2179{ 2179{
2180 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2180 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2181 KopiCalendarFile * cal = calendars.first(); 2181 KopiCalendarFile * cal = calendars.first();
2182 mCalendar->setDefaultCalendar( 1 ); 2182 mCalendar->setDefaultCalendar( 1 );
2183 mCalendar->setDefaultCalendarEnabledOnly(); 2183 mCalendar->setDefaultCalendarEnabledOnly();
2184 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2184 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2185 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2185 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2186 restoreCalendarSettings(); 2186 restoreCalendarSettings();
2187 return false; 2187 return false;
2188 } 2188 }
2189 } 2189 }
2190 cal = calendars.next(); 2190 cal = calendars.next();
2191 QDateTime storeTemp = loadedFileVersion; 2191 QDateTime storeTemp = loadedFileVersion;
2192 while ( cal ) { 2192 while ( cal ) {
2193 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2193 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2194 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2194 mCalendar->setDefaultCalendar( cal->mCalNumber );
2195 mCalendar->setDefaultCalendarEnabledOnly(); 2195 mCalendar->setDefaultCalendarEnabledOnly();
2196 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2196 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2197 if ( !checkFileVersion(cal->mFileName )) { 2197 if ( !checkFileVersion(cal->mFileName )) {
2198 loadedFileVersion = storeTemp; 2198 loadedFileVersion = storeTemp;
2199 restoreCalendarSettings(); 2199 restoreCalendarSettings();
2200 return false; 2200 return false;
2201 } 2201 }
2202 } 2202 }
2203 cal = calendars.next(); 2203 cal = calendars.next();
2204 } 2204 }
2205 loadedFileVersion = storeTemp; 2205 loadedFileVersion = storeTemp;
2206 return true; 2206 return true;
2207} 2207}
2208bool CalendarView::checkFileVersion(QString fn) 2208bool CalendarView::checkFileVersion(QString fn)
2209{ 2209{
2210 QFileInfo finf ( fn ); 2210 QFileInfo finf ( fn );
2211 if ( !finf.exists() ) 2211 if ( !finf.exists() )
2212 return true; 2212 return true;
2213 QDateTime dt = finf.lastModified (); 2213 QDateTime dt = finf.lastModified ();
2214 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2214 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2215 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2215 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2216 if ( dt <= loadedFileVersion ) 2216 if ( dt <= loadedFileVersion )
2217 return true; 2217 return true;
2218 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 2218 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
2219 i18n("KO/Pi Warning"),i18n("Overwrite"), 2219 i18n("KO/Pi Warning"),i18n("Overwrite"),
2220 i18n("Sync+save")); 2220 i18n("Sync+save"));
2221 2221
2222 if ( km == KMessageBox::Cancel ) 2222 if ( km == KMessageBox::Cancel )
2223 return false; 2223 return false;
2224 if ( km == KMessageBox::Yes ) 2224 if ( km == KMessageBox::Yes )
2225 return true; 2225 return true;
2226 2226
2227 setSyncDevice("deleteaftersync" ); 2227 setSyncDevice("deleteaftersync" );
2228 mSyncManager->mAskForPreferences = true; 2228 mSyncManager->mAskForPreferences = true;
2229 mSyncManager->mSyncAlgoPrefs = 3; 2229 mSyncManager->mSyncAlgoPrefs = 3;
2230 mSyncManager->mWriteBackFile = false; 2230 mSyncManager->mWriteBackFile = false;
2231 mSyncManager->mWriteBackExistingOnly = false; 2231 mSyncManager->mWriteBackExistingOnly = false;
2232 mSyncManager->mShowSyncSummary = false; 2232 mSyncManager->mShowSyncSummary = false;
2233 syncCalendar( fn, 3 ); 2233 syncCalendar( fn, 3 );
2234 Event * e = getLastSyncEvent(); 2234 Event * e = getLastSyncEvent();
2235 if ( e ) 2235 if ( e )
2236 mCalendar->deleteEvent( e ); 2236 mCalendar->deleteEvent( e );
2237 return true; 2237 return true;
2238} 2238}
2239bool CalendarView::saveCalendars() 2239bool CalendarView::saveCalendars()
2240{ 2240{
2241 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2241 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2242 KopiCalendarFile * cal = calendars.first(); 2242 KopiCalendarFile * cal = calendars.first();
2243 mCalendar->setDefaultCalendar( 1 ); 2243 mCalendar->setDefaultCalendar( 1 );
2244 mCalendar->setDefaultCalendarEnabledOnly(); 2244 mCalendar->setDefaultCalendarEnabledOnly();
2245 saveCalendar( MainWindow::defaultFileName() ); 2245 saveCalendar( MainWindow::defaultFileName() );
2246 cal = calendars.next(); 2246 cal = calendars.next();
2247 while ( cal ) { 2247 while ( cal ) {
2248 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2248 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2249 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2249 mCalendar->setDefaultCalendar( cal->mCalNumber );
2250 mCalendar->setDefaultCalendarEnabledOnly(); 2250 mCalendar->setDefaultCalendarEnabledOnly();
2251 if ( saveCalendar( cal->mFileName ) ) 2251 if ( saveCalendar( cal->mFileName ) )
2252 cal->mLoadDt = QDateTime::currentDateTime(); 2252 cal->mLoadDt = QDateTime::currentDateTime();
2253 } 2253 }
2254 cal = calendars.next(); 2254 cal = calendars.next();
2255 } 2255 }
2256 restoreCalendarSettings(); 2256 restoreCalendarSettings();
2257 return true; 2257 return true;
2258} 2258}
2259bool CalendarView::saveCalendar( QString filename ) 2259bool CalendarView::saveCalendar( QString filename )
2260{ 2260{
2261 2261
2262 // Store back all unsaved data into calendar object 2262 // Store back all unsaved data into calendar object
2263 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2263 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2264 if ( mViewManager->currentView() ) 2264 if ( mViewManager->currentView() )
2265 mViewManager->currentView()->flushView(); 2265 mViewManager->currentView()->flushView();
2266 2266
2267 2267
2268 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2268 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2269 mStorage->setSaveFormat( new ICalFormat() ); 2269 mStorage->setSaveFormat( new ICalFormat() );
2270 mStorage->setFileName( filename ); 2270 mStorage->setFileName( filename );
2271 bool success; 2271 bool success;
2272 success = mStorage->save(); 2272 success = mStorage->save();
2273 if ( !success ) { 2273 if ( !success ) {
2274 return false; 2274 return false;
2275 } 2275 }
2276 if ( filename == MainWindow::defaultFileName() ) { 2276 if ( filename == MainWindow::defaultFileName() ) {
2277 setLoadedFileVersion( lfv ); 2277 setLoadedFileVersion( lfv );
2278 watchSavedFile(); 2278 watchSavedFile();
2279 } 2279 }
2280 return true; 2280 return true;
2281} 2281}
2282 2282
2283void CalendarView::closeCalendar() 2283void CalendarView::closeCalendar()
2284{ 2284{
2285 2285
2286 // child windows no longer valid 2286 // child windows no longer valid
2287 clearAllViews(); 2287 clearAllViews();
2288 emit closingDown(); 2288 emit closingDown();
2289 2289
2290 mCalendar->close(); 2290 mCalendar->close();
2291 setModified(false); 2291 setModified(false);
2292 updateView(); 2292 updateView();
2293} 2293}
2294 2294
2295void CalendarView::archiveCalendar() 2295void CalendarView::archiveCalendar()
2296{ 2296{
2297 mDialogManager->showArchiveDialog(); 2297 mDialogManager->showArchiveDialog();
2298} 2298}
2299 2299
2300 2300
2301void CalendarView::readSettings() 2301void CalendarView::readSettings()
2302{ 2302{
2303 2303
2304 2304
2305 // mViewManager->showAgendaView(); 2305 // mViewManager->showAgendaView();
2306 QString str; 2306 QString str;
2307 //qDebug("CalendarView::readSettings() "); 2307 //qDebug("CalendarView::readSettings() ");
2308 // read settings from the KConfig, supplying reasonable 2308 // read settings from the KConfig, supplying reasonable
2309 // defaults where none are to be found 2309 // defaults where none are to be found
2310 KConfig *config = KOGlobals::config(); 2310 KConfig *config = KOGlobals::config();
2311#ifndef KORG_NOSPLITTER 2311#ifndef KORG_NOSPLITTER
2312 config->setGroup("KOrganizer Geometry"); 2312 config->setGroup("KOrganizer Geometry");
2313 2313
2314 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2314 QValueList<int> sizes = config->readIntListEntry("Separator1");
2315 if (sizes.count() != 2) { 2315 if (sizes.count() != 2) {
2316 sizes << mDateNavigator->minimumSizeHint().width(); 2316 sizes << mDateNavigator->minimumSizeHint().width();
2317 sizes << 300; 2317 sizes << 300;
2318 } 2318 }
2319 mPanner->setSizes(sizes); 2319 mPanner->setSizes(sizes);
2320 2320
2321 sizes = config->readIntListEntry("Separator2"); 2321 sizes = config->readIntListEntry("Separator2");
2322 if ( ( mResourceView && sizes.count() == 4 ) || 2322 if ( ( mResourceView && sizes.count() == 4 ) ||
2323 ( !mResourceView && sizes.count() == 3 ) ) { 2323 ( !mResourceView && sizes.count() == 3 ) ) {
2324 mLeftSplitter->setSizes(sizes); 2324 mLeftSplitter->setSizes(sizes);
2325 } 2325 }
2326#endif 2326#endif
2327 globalFlagBlockAgenda = 1; 2327 globalFlagBlockAgenda = 1;
2328 mViewManager->showAgendaView(); 2328 mViewManager->showAgendaView();
2329 //mViewManager->readSettings( config ); 2329 //mViewManager->readSettings( config );
2330 mTodoList->restoreLayout(config,QString("Todo Layout")); 2330 mTodoList->restoreLayout(config,QString("Todo Layout"));
2331 readFilterSettings(config); 2331 readFilterSettings(config);
2332 2332
2333#ifdef DESKTOP_VERSION 2333#ifdef DESKTOP_VERSION
2334 config->setGroup("WidgetLayout"); 2334 config->setGroup("WidgetLayout");
2335 QStringList list; 2335 QStringList list;
2336 list = config->readListEntry("MainLayout"); 2336 list = config->readListEntry("MainLayout");
2337 int x,y,w,h; 2337 int x,y,w,h;
2338 if ( ! list.isEmpty() ) { 2338 if ( ! list.isEmpty() ) {
2339 x = list[0].toInt(); 2339 x = list[0].toInt();
2340 y = list[1].toInt(); 2340 y = list[1].toInt();
2341 w = list[2].toInt(); 2341 w = list[2].toInt();
2342 h = list[3].toInt(); 2342 h = list[3].toInt();
2343 KApplication::testCoords( &x,&y,&w,&h ); 2343 KApplication::testCoords( &x,&y,&w,&h );
2344 topLevelWidget()->setGeometry(x,y,w,h); 2344 topLevelWidget()->setGeometry(x,y,w,h);
2345 2345
2346 } else { 2346 } else {
2347 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2347 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2348 } 2348 }
2349 list = config->readListEntry("EditEventLayout"); 2349 list = config->readListEntry("EditEventLayout");
2350 if ( ! list.isEmpty() ) { 2350 if ( ! list.isEmpty() ) {
2351 x = list[0].toInt(); 2351 x = list[0].toInt();
2352 y = list[1].toInt(); 2352 y = list[1].toInt();
2353 w = list[2].toInt(); 2353 w = list[2].toInt();
2354 h = list[3].toInt(); 2354 h = list[3].toInt();
2355 KApplication::testCoords( &x,&y,&w,&h ); 2355 KApplication::testCoords( &x,&y,&w,&h );
2356 mEventEditor->setGeometry(x,y,w,h); 2356 mEventEditor->setGeometry(x,y,w,h);
2357 2357
2358 } 2358 }
2359 list = config->readListEntry("EditTodoLayout"); 2359 list = config->readListEntry("EditTodoLayout");
2360 if ( ! list.isEmpty() ) { 2360 if ( ! list.isEmpty() ) {
2361 x = list[0].toInt(); 2361 x = list[0].toInt();
2362 y = list[1].toInt(); 2362 y = list[1].toInt();
2363 w = list[2].toInt(); 2363 w = list[2].toInt();
2364 h = list[3].toInt(); 2364 h = list[3].toInt();
2365 KApplication::testCoords( &x,&y,&w,&h ); 2365 KApplication::testCoords( &x,&y,&w,&h );
2366 mTodoEditor->setGeometry(x,y,w,h); 2366 mTodoEditor->setGeometry(x,y,w,h);
2367 2367
2368 } 2368 }
2369 list = config->readListEntry("ViewerLayout"); 2369 list = config->readListEntry("ViewerLayout");
2370 if ( ! list.isEmpty() ) { 2370 if ( ! list.isEmpty() ) {
2371 x = list[0].toInt(); 2371 x = list[0].toInt();
2372 y = list[1].toInt(); 2372 y = list[1].toInt();
2373 w = list[2].toInt(); 2373 w = list[2].toInt();
2374 h = list[3].toInt(); 2374 h = list[3].toInt();
2375 KApplication::testCoords( &x,&y,&w,&h ); 2375 KApplication::testCoords( &x,&y,&w,&h );
2376 getEventViewerDialog()->setGeometry(x,y,w,h); 2376 getEventViewerDialog()->setGeometry(x,y,w,h);
2377 } 2377 }
2378#endif 2378#endif
2379 config->setGroup( "Views" ); 2379 config->setGroup( "Views" );
2380 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2380 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2381 2381
2382 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2382 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2383 2383
2384 int resetval = 0; 2384 int resetval = 0;
2385 int maxVal = 0; 2385 int maxVal = 0;
2386 if (sizes.count() != 3) { 2386 if (sizes.count() != 3) {
2387 if ( KOPrefs::instance()->mVerticalScreen ) { 2387 if ( KOPrefs::instance()->mVerticalScreen ) {
2388 resetval = mDateNavigator->sizeHint().width()+2; 2388 resetval = mDateNavigator->sizeHint().width()+2;
2389 } else { 2389 } else {
2390 resetval = mDateNavigator->sizeHint().height()+2; 2390 resetval = mDateNavigator->sizeHint().height()+2;
2391 } 2391 }
2392 } 2392 }
2393 if ( resetval ) { 2393 if ( resetval ) {
2394 sizes.clear(); 2394 sizes.clear();
2395 if ( KOPrefs::instance()->mVerticalScreen ) { 2395 if ( KOPrefs::instance()->mVerticalScreen ) {
2396 maxVal = QApplication::desktop()->width() -10; 2396 maxVal = QApplication::desktop()->width() -10;
2397 } else { 2397 } else {
2398 maxVal = QApplication::desktop()->height()-10; 2398 maxVal = QApplication::desktop()->height()-10;
2399 } 2399 }
2400 sizes << resetval; 2400 sizes << resetval;
2401 if ( maxVal < resetval + resetval) 2401 if ( maxVal < resetval + resetval)
2402 resetval = maxVal - resetval; 2402 resetval = maxVal - resetval;
2403 sizes << resetval; 2403 sizes << resetval;
2404 sizes << 100; 2404 sizes << 100;
2405 } 2405 }
2406 mLeftFrame->setSizes(sizes); 2406 mLeftFrame->setSizes(sizes);
2407 sizes = config->readIntListEntry("Main Splitter Frame"); 2407 sizes = config->readIntListEntry("Main Splitter Frame");
2408 resetval = 0; 2408 resetval = 0;
2409 maxVal = 0; 2409 maxVal = 0;
2410 if (sizes.count() != 2) { 2410 if (sizes.count() != 2) {
2411 if ( !KOPrefs::instance()->mVerticalScreen ) { 2411 if ( !KOPrefs::instance()->mVerticalScreen ) {
2412 resetval = mDateNavigator->sizeHint().width()+2; 2412 resetval = mDateNavigator->sizeHint().width()+2;
2413 } else { 2413 } else {
2414 resetval = mDateNavigator->sizeHint().height()+2; 2414 resetval = mDateNavigator->sizeHint().height()+2;
2415 } 2415 }
2416 } 2416 }
2417 if ( resetval ) { 2417 if ( resetval ) {
2418 sizes.clear(); 2418 sizes.clear();
2419 if ( !KOPrefs::instance()->mVerticalScreen ) { 2419 if ( !KOPrefs::instance()->mVerticalScreen ) {
2420 maxVal = QApplication::desktop()->width() -10; 2420 maxVal = QApplication::desktop()->width() -10;
2421 } else { 2421 } else {
2422 maxVal = QApplication::desktop()->height()-10; 2422 maxVal = QApplication::desktop()->height()-10;
2423 } 2423 }
2424 sizes << resetval; 2424 sizes << resetval;
2425 if ( maxVal < resetval + resetval) 2425 if ( maxVal < resetval + resetval)
2426 resetval = maxVal - resetval; 2426 resetval = maxVal - resetval;
2427 sizes << resetval; 2427 sizes << resetval;
2428 } 2428 }
2429 mMainFrame->setSizes(sizes); 2429 mMainFrame->setSizes(sizes);
2430 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2430 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2431 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2431 else if ( dateCount == 7 ) mNavigator->selectWeek();
2432 else mNavigator->selectDates( dateCount ); 2432 else mNavigator->selectDates( dateCount );
2433 // mViewManager->readSettings( config ); 2433 // mViewManager->readSettings( config );
2434 updateConfig(); 2434 updateConfig();
2435 globalFlagBlockAgenda = 2; 2435 globalFlagBlockAgenda = 2;
2436 mViewManager->readSettings( config ); 2436 mViewManager->readSettings( config );
2437 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2437 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2438} 2438}
2439 2439
2440void CalendarView::checkSuspendAlarm() 2440void CalendarView::checkSuspendAlarm()
2441{ 2441{
2442 if ( mSuspendTimer->isActive() ) { 2442 if ( mSuspendTimer->isActive() ) {
2443 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm")); 2443 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm"));
2444 } 2444 }
2445} 2445}
2446void CalendarView::writeSettings() 2446void CalendarView::writeSettings()
2447{ 2447{
2448 // kdDebug() << "CalendarView::writeSettings" << endl; 2448 // kdDebug() << "CalendarView::writeSettings" << endl;
2449 2449
2450 KConfig *config = KOGlobals::config(); 2450 KConfig *config = KOGlobals::config();
2451 2451
2452 mViewManager->writeSettings( config ); 2452 mViewManager->writeSettings( config );
2453 mTodoList->saveLayout(config,QString("Todo Layout")); 2453 mTodoList->saveLayout(config,QString("Todo Layout"));
2454 mDialogManager->writeSettings( config ); 2454 mDialogManager->writeSettings( config );
2455 //KOPrefs::instance()->usrWriteConfig(); 2455 //KOPrefs::instance()->usrWriteConfig();
2456 KOPrefs::instance()->writeConfig(); 2456 KOPrefs::instance()->writeConfig();
2457 2457
2458 writeFilterSettings(config); 2458 writeFilterSettings(config);
2459 config->setGroup( "AppRun" ); 2459 config->setGroup( "AppRun" );
2460 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2460 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2461 int days = dt.daysTo( QDate::currentDate() ); 2461 int days = dt.daysTo( QDate::currentDate() );
2462 dt = dt.addDays( days ); 2462 dt = dt.addDays( days );
2463 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2463 int secs = dt.secsTo( QDateTime::currentDateTime() );
2464 config->writeEntry( "LatestProgramStopDays", days ); 2464 config->writeEntry( "LatestProgramStopDays", days );
2465 config->writeEntry( "LatestProgramStopSecs", secs ); 2465 config->writeEntry( "LatestProgramStopSecs", secs );
2466 //qDebug("KO: Writing stop time: %d ", secs); 2466 //qDebug("KO: Writing stop time: %d ", secs);
2467 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2467 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2468 //QDateTime latest = dt.addSecs ( secs ); 2468 //QDateTime latest = dt.addSecs ( secs );
2469 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2469 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2470 config->setGroup( "Views" ); 2470 config->setGroup( "Views" );
2471 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2471 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2472 2472
2473#if 0 2473#if 0
2474 qDebug("********************* "); 2474 qDebug("********************* ");
2475 qDebug("Testcode secsto "); 2475 qDebug("Testcode secsto ");
2476 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2476 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2477 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2477 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2478 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2478 int secsto = dt_nodaylight.secsTo( dt_daylight );
2479 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2479 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2480 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2480 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2481 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2481 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2482 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2482 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2483 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2483 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2484 qDebug("********************* testcode end"); 2484 qDebug("********************* testcode end");
2485 2485
2486#endif 2486#endif
2487 2487
2488 QValueList<int> listINT = mLeftFrame->sizes(); 2488 QValueList<int> listINT = mLeftFrame->sizes();
2489 config->writeEntry("Left Splitter Frame",listINT); 2489 config->writeEntry("Left Splitter Frame",listINT);
2490 QValueList<int> listINT2 = mMainFrame->sizes(); 2490 QValueList<int> listINT2 = mMainFrame->sizes();
2491 config->writeEntry("Main Splitter Frame",listINT2); 2491 config->writeEntry("Main Splitter Frame",listINT2);
2492#ifdef DESKTOP_VERSION 2492#ifdef DESKTOP_VERSION
2493 config->setGroup("WidgetLayout"); 2493 config->setGroup("WidgetLayout");
2494 QStringList list ;//= config->readListEntry("MainLayout"); 2494 QStringList list ;//= config->readListEntry("MainLayout");
2495 int x,y,w,h; 2495 int x,y,w,h;
2496 QWidget* wid; 2496 QWidget* wid;
2497 wid = topLevelWidget(); 2497 wid = topLevelWidget();
2498 x = wid->geometry().x(); 2498 x = wid->geometry().x();
2499 y = wid->geometry().y(); 2499 y = wid->geometry().y();
2500 w = wid->width(); 2500 w = wid->width();
2501 h = wid->height(); 2501 h = wid->height();
2502 list.clear(); 2502 list.clear();
2503 list << QString::number( x ); 2503 list << QString::number( x );
2504 list << QString::number( y ); 2504 list << QString::number( y );
2505 list << QString::number( w ); 2505 list << QString::number( w );
2506 list << QString::number( h ); 2506 list << QString::number( h );
2507 config->writeEntry("MainLayout",list ); 2507 config->writeEntry("MainLayout",list );
2508 2508
2509 wid = mEventEditor; 2509 wid = mEventEditor;
2510 x = wid->geometry().x(); 2510 x = wid->geometry().x();
2511 y = wid->geometry().y(); 2511 y = wid->geometry().y();
2512 w = wid->width(); 2512 w = wid->width();
2513 h = wid->height(); 2513 h = wid->height();
2514 list.clear(); 2514 list.clear();
2515 list << QString::number( x ); 2515 list << QString::number( x );
2516 list << QString::number( y ); 2516 list << QString::number( y );
2517 list << QString::number( w ); 2517 list << QString::number( w );
2518 list << QString::number( h ); 2518 list << QString::number( h );
2519 config->writeEntry("EditEventLayout",list ); 2519 config->writeEntry("EditEventLayout",list );
2520 2520
2521 wid = mTodoEditor; 2521 wid = mTodoEditor;
2522 x = wid->geometry().x(); 2522 x = wid->geometry().x();
2523 y = wid->geometry().y(); 2523 y = wid->geometry().y();
2524 w = wid->width(); 2524 w = wid->width();
2525 h = wid->height(); 2525 h = wid->height();
2526 list.clear(); 2526 list.clear();
2527 list << QString::number( x ); 2527 list << QString::number( x );
2528 list << QString::number( y ); 2528 list << QString::number( y );
2529 list << QString::number( w ); 2529 list << QString::number( w );
2530 list << QString::number( h ); 2530 list << QString::number( h );
2531 config->writeEntry("EditTodoLayout",list ); 2531 config->writeEntry("EditTodoLayout",list );
2532 wid = getEventViewerDialog(); 2532 wid = getEventViewerDialog();
2533 x = wid->geometry().x(); 2533 x = wid->geometry().x();
2534 y = wid->geometry().y(); 2534 y = wid->geometry().y();
2535 w = wid->width(); 2535 w = wid->width();
2536 h = wid->height(); 2536 h = wid->height();
2537 list.clear(); 2537 list.clear();
2538 list << QString::number( x ); 2538 list << QString::number( x );
2539 list << QString::number( y ); 2539 list << QString::number( y );
2540 list << QString::number( w ); 2540 list << QString::number( w );
2541 list << QString::number( h ); 2541 list << QString::number( h );
2542 config->writeEntry("ViewerLayout",list ); 2542 config->writeEntry("ViewerLayout",list );
2543 wid = mDialogManager->getSearchDialog(); 2543 wid = mDialogManager->getSearchDialog();
2544 if ( wid ) { 2544 if ( wid ) {
2545 x = wid->geometry().x(); 2545 x = wid->geometry().x();
2546 y = wid->geometry().y(); 2546 y = wid->geometry().y();
2547 w = wid->width(); 2547 w = wid->width();
2548 h = wid->height(); 2548 h = wid->height();
2549 list.clear(); 2549 list.clear();
2550 list << QString::number( x ); 2550 list << QString::number( x );
2551 list << QString::number( y ); 2551 list << QString::number( y );
2552 list << QString::number( w ); 2552 list << QString::number( w );
2553 list << QString::number( h ); 2553 list << QString::number( h );
2554 config->writeEntry("SearchLayout",list ); 2554 config->writeEntry("SearchLayout",list );
2555 } 2555 }
2556#endif 2556#endif
2557 2557
2558 2558
2559 config->sync(); 2559 config->sync();
2560} 2560}
2561 2561
2562void CalendarView::readFilterSettings(KConfig *config) 2562void CalendarView::readFilterSettings(KConfig *config)
2563{ 2563{
2564 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2564 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2565 2565
2566 mFilters.clear(); 2566 mFilters.clear();
2567 2567
2568 config->setGroup("General"); 2568 config->setGroup("General");
2569 QStringList filterList = config->readListEntry("CalendarFilters"); 2569 QStringList filterList = config->readListEntry("CalendarFilters");
2570 2570
2571 QStringList::ConstIterator it = filterList.begin(); 2571 QStringList::ConstIterator it = filterList.begin();
2572 QStringList::ConstIterator end = filterList.end(); 2572 QStringList::ConstIterator end = filterList.end();
2573 while(it != end) { 2573 while(it != end) {
2574 // kdDebug() << " filter: " << (*it) << endl; 2574 // kdDebug() << " filter: " << (*it) << endl;
2575 2575
2576 CalFilter *filter; 2576 CalFilter *filter;
2577 filter = new CalFilter(*it); 2577 filter = new CalFilter(*it);
2578 config->setGroup("Filter_" + (*it).utf8()); 2578 config->setGroup("Filter_" + (*it).utf8());
2579 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2579 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2580 filter->setCriteria(config->readNumEntry("Criteria",0)); 2580 filter->setCriteria(config->readNumEntry("Criteria",0));
2581 filter->setCategoryList(config->readListEntry("CategoryList")); 2581 filter->setCategoryList(config->readListEntry("CategoryList"));
2582 mFilters.append(filter); 2582 mFilters.append(filter);
2583 2583
2584 ++it; 2584 ++it;
2585 } 2585 }
2586 2586
2587 if (mFilters.count() == 0) { 2587 if (mFilters.count() == 0) {
2588 CalFilter *filter = new CalFilter(i18n("Default")); 2588 CalFilter *filter = new CalFilter(i18n("Default"));
2589 mFilters.append(filter); 2589 mFilters.append(filter);
2590 } 2590 }
2591 mFilterView->updateFilters(); 2591 mFilterView->updateFilters();
2592 config->setGroup("FilterView"); 2592 config->setGroup("FilterView");
2593 2593
2594 mFilterView->blockSignals(true); 2594 mFilterView->blockSignals(true);
2595 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2595 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2596 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2596 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2597 mFilterView->blockSignals(false); 2597 mFilterView->blockSignals(false);
2598 // We do it manually to avoid it being done twice by the above calls 2598 // We do it manually to avoid it being done twice by the above calls
2599 updateFilter(); 2599 updateFilter();
2600} 2600}
2601 2601
2602void CalendarView::writeFilterSettings(KConfig *config) 2602void CalendarView::writeFilterSettings(KConfig *config)
2603{ 2603{
2604 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2604 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2605 2605
2606 QStringList filterList; 2606 QStringList filterList;
2607 2607
2608 CalFilter *filter = mFilters.first(); 2608 CalFilter *filter = mFilters.first();
2609 while(filter) { 2609 while(filter) {
2610 // kdDebug() << " fn: " << filter->name() << endl; 2610 // kdDebug() << " fn: " << filter->name() << endl;
2611 filterList << filter->name(); 2611 filterList << filter->name();
2612 config->setGroup("Filter_" + filter->name().utf8()); 2612 config->setGroup("Filter_" + filter->name().utf8());
2613 config->writeEntry("Criteria",filter->criteria()); 2613 config->writeEntry("Criteria",filter->criteria());
2614 config->writeEntry("CategoryList",filter->categoryList()); 2614 config->writeEntry("CategoryList",filter->categoryList());
2615 filter = mFilters.next(); 2615 filter = mFilters.next();
2616 } 2616 }
2617 config->setGroup("General"); 2617 config->setGroup("General");
2618 config->writeEntry("CalendarFilters",filterList); 2618 config->writeEntry("CalendarFilters",filterList);
2619 2619
2620 config->setGroup("FilterView"); 2620 config->setGroup("FilterView");
2621 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2621 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2622 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2622 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2623} 2623}
2624 2624
2625 2625
2626void CalendarView::goToday() 2626void CalendarView::goToday()
2627{ 2627{
2628 if ( mViewManager->currentView()->isMonthView() ) 2628 if ( mViewManager->currentView()->isMonthView() )
2629 mNavigator->selectTodayMonth(); 2629 mNavigator->selectTodayMonth();
2630 else 2630 else
2631 mNavigator->selectToday(); 2631 mNavigator->selectToday();
2632} 2632}
2633 2633
2634void CalendarView::goNext() 2634void CalendarView::goNext()
2635{ 2635{
2636 mNavigator->selectNext(); 2636 mNavigator->selectNext();
2637} 2637}
2638 2638
2639void CalendarView::goPrevious() 2639void CalendarView::goPrevious()
2640{ 2640{
2641 mNavigator->selectPrevious(); 2641 mNavigator->selectPrevious();
2642} 2642}
2643void CalendarView::goNextMonth() 2643void CalendarView::goNextMonth()
2644{ 2644{
2645 mNavigator->selectNextMonth(); 2645 mNavigator->selectNextMonth();
2646} 2646}
2647 2647
2648void CalendarView::goPreviousMonth() 2648void CalendarView::goPreviousMonth()
2649{ 2649{
2650 mNavigator->selectPreviousMonth(); 2650 mNavigator->selectPreviousMonth();
2651} 2651}
2652 2652
2653void CalendarView::updateConfig() 2653void CalendarView::updateConfig()
2654{ 2654{
2655 if ( KOPrefs::instance()->mUseAppColors ) 2655 if ( KOPrefs::instance()->mUseAppColors )
2656 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2656 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2657 emit configChanged(); 2657 emit configChanged();
2658 mTodoList->updateConfig(); 2658 mTodoList->updateConfig();
2659 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2659 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2660 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2660 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2661 // To make the "fill window" configurations work 2661 // To make the "fill window" configurations work
2662 //mViewManager->raiseCurrentView(); 2662 //mViewManager->raiseCurrentView();
2663} 2663}
2664 2664
2665 2665
2666void CalendarView::eventChanged(Event *event) 2666void CalendarView::eventChanged(Event *event)
2667{ 2667{
2668 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2668 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2669 //updateUnmanagedViews(); 2669 //updateUnmanagedViews();
2670} 2670}
2671 2671
2672void CalendarView::eventAdded(Event *event) 2672void CalendarView::eventAdded(Event *event)
2673{ 2673{
2674 changeEventDisplay(event,KOGlobals::EVENTADDED); 2674 changeEventDisplay(event,KOGlobals::EVENTADDED);
2675} 2675}
2676 2676
2677void CalendarView::eventToBeDeleted(Event *) 2677void CalendarView::eventToBeDeleted(Event *)
2678{ 2678{
2679 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2679 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2680} 2680}
2681 2681
2682void CalendarView::eventDeleted() 2682void CalendarView::eventDeleted()
2683{ 2683{
2684 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2684 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2685} 2685}
2686void CalendarView::changeTodoDisplay(Todo *which, int action) 2686void CalendarView::changeTodoDisplay(Todo *which, int action)
2687{ 2687{
2688 changeIncidenceDisplay((Incidence *)which, action); 2688 changeIncidenceDisplay((Incidence *)which, action);
2689 mDateNavigator->updateView(); //LR 2689 mDateNavigator->updateView(); //LR
2690 //mDialogManager->updateSearchDialog(); 2690 //mDialogManager->updateSearchDialog();
2691 2691
2692 if (which) { 2692 if (which) {
2693 mViewManager->updateWNview(); 2693 mViewManager->updateWNview();
2694 //mTodoList->updateView(); 2694 //mTodoList->updateView();
2695 } 2695 }
2696 2696
2697} 2697}
2698 2698
2699void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2699void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2700{ 2700{
2701 updateUnmanagedViews(); 2701 updateUnmanagedViews();
2702 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2702 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2703 if ( action == KOGlobals::EVENTDELETED ) { //delete 2703 if ( action == KOGlobals::EVENTDELETED ) { //delete
2704 mCalendar->checkAlarmForIncidence( 0, true ); 2704 mCalendar->checkAlarmForIncidence( 0, true );
2705 if ( mEventViewerDialog ) 2705 if ( mEventViewerDialog )
2706 mEventViewerDialog->hide(); 2706 mEventViewerDialog->hide();
2707 } 2707 }
2708 else 2708 else
2709 mCalendar->checkAlarmForIncidence( which , false ); 2709 mCalendar->checkAlarmForIncidence( which , false );
2710} 2710}
2711 2711
2712// most of the changeEventDisplays() right now just call the view's 2712// most of the changeEventDisplays() right now just call the view's
2713// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2713// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2714void CalendarView::changeEventDisplay(Event *which, int action) 2714void CalendarView::changeEventDisplay(Event *which, int action)
2715{ 2715{
2716 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2716 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2717 changeIncidenceDisplay((Incidence *)which, action); 2717 changeIncidenceDisplay((Incidence *)which, action);
2718 static bool clearallviews = false; 2718 static bool clearallviews = false;
2719 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2719 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2720 if ( clearallviews ) { 2720 if ( clearallviews ) {
2721 clearAllViews(); 2721 clearAllViews();
2722 clearallviews = false; 2722 clearallviews = false;
2723 } 2723 }
2724 return; 2724 return;
2725 } 2725 }
2726 clearallviews = true; 2726 clearallviews = true;
2727 mDateNavigator->updateView(); 2727 mDateNavigator->updateView();
2728 //mDialogManager->updateSearchDialog(); 2728 //mDialogManager->updateSearchDialog();
2729 if (which) { 2729 if (which) {
2730 // If there is an event view visible update the display 2730 // If there is an event view visible update the display
2731 mViewManager->currentView()->changeEventDisplay(which,action); 2731 mViewManager->currentView()->changeEventDisplay(which,action);
2732 // TODO: check, if update needed 2732 // TODO: check, if update needed
2733 // if (which->getTodoStatus()) { 2733 // if (which->getTodoStatus()) {
2734 mTodoList->updateView(); 2734 mTodoList->updateView();
2735 if ( action != KOGlobals::EVENTDELETED ) { 2735 if ( action != KOGlobals::EVENTDELETED ) {
2736 mConflictingEvent = which ; 2736 mConflictingEvent = which ;
2737 QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) ); 2737 QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) );
2738 } 2738 }
2739 // } 2739 // }
2740 } else { 2740 } else {
2741 mViewManager->currentView()->updateView(); 2741 mViewManager->currentView()->updateView();
2742 } 2742 }
2743} 2743}
2744void CalendarView::checkConflictForEvent() 2744void CalendarView::checkConflictForEvent()
2745{ 2745{
2746 2746
2747 if (!KOPrefs::instance()->mConfirm) 2747 if (!KOPrefs::instance()->mConfirm)
2748 return; 2748 return;
2749 if ( ! mConflictingEvent ) return; 2749 if ( ! mConflictingEvent ) return;
2750 if ( mConflictingEvent->doesFloat() ) { 2750 if ( mConflictingEvent->isHoliday() || mConflictingEvent->isBirthday() || mConflictingEvent->isAnniversary() ) {
2751 mConflictingEvent = 0; 2751 mConflictingEvent = 0;
2752 return; 2752 return;
2753 } 2753 }
2754 QPtrList<Event> testlist = mCalendar->events(); 2754 QPtrList<Event> testlist = mCalendar->events();
2755 Event * test = testlist.first(); 2755 Event * test = testlist.first();
2756 QDateTime conflict; 2756 QDateTime conflict;
2757 QDateTime retVal; 2757 QDateTime retVal;
2758 bool found = false; 2758 bool found = false;
2759 Event * cE = 0; 2759 Event * cE = 0;
2760 QDateTime current = QDateTime::currentDateTime(); 2760 QDateTime current = QDateTime::currentDateTime();
2761 while ( test ) { 2761 while ( test ) {
2762 if ( !test->doesFloat() ) { 2762 if ( !test->doesFloat() ) {
2763 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) { 2763 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) {
2764 if ( ! found ) { 2764 if ( ! found ) {
2765 conflict = retVal; 2765 conflict = retVal;
2766 cE = test; 2766 cE = test;
2767 } else { 2767 } else {
2768 if ( retVal < conflict ) { 2768 if ( retVal < conflict ) {
2769 conflict = retVal; 2769 conflict = retVal;
2770 cE = test; 2770 cE = test;
2771 } 2771 }
2772 } 2772 }
2773 found = true; 2773 found = true;
2774 } 2774 }
2775 } 2775 }
2776 test = testlist.next(); 2776 test = testlist.next();
2777 } 2777 }
2778 if ( found ) { 2778 if ( found ) {
2779 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ; 2779 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ;
2780 qApp->processEvents(); 2780 qApp->processEvents();
2781 int km = KMessageBox::warningContinueCancel(this,mess, 2781 int km = KMessageBox::warningContinueCancel(this,mess,
2782 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!")); 2782 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!"));
2783 if ( km != KMessageBox::Continue ) 2783 if ( km != KMessageBox::Continue )
2784 return; 2784 return;
2785 2785
2786 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 2786 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
2787 mViewManager->showDayView(); 2787 mViewManager->showDayView();
2788 mNavigator->slotDaySelect( conflict.date() ); 2788 mNavigator->slotDaySelect( conflict.date() );
2789 int hour = conflict.time().hour(); 2789 int hour = conflict.time().hour();
2790 mViewManager->agendaView()->setStartHour( hour ); 2790 mViewManager->agendaView()->setStartHour( hour );
2791 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) ); 2791 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) );
2792 return;
2793 } 2792 }
2794 2793 mConflictingEvent = 0;
2795 return; 2794 return;
2796 2795
2797} 2796}
2798 2797
2799void CalendarView::updateTodoViews() 2798void CalendarView::updateTodoViews()
2800{ 2799{
2801 mTodoList->updateView(); 2800 mTodoList->updateView();
2802 mViewManager->currentView()->updateView(); 2801 mViewManager->currentView()->updateView();
2803 2802
2804} 2803}
2805 2804
2806 2805
2807 2806
2808void CalendarView::clearAllViews() 2807void CalendarView::clearAllViews()
2809{ 2808{
2810 mTodoList->clearList(); 2809 mTodoList->clearList();
2811 mViewManager->clearAllViews(); 2810 mViewManager->clearAllViews();
2812 SearchDialog * sd = mDialogManager->getSearchDialog(); 2811 SearchDialog * sd = mDialogManager->getSearchDialog();
2813 if ( sd ) { 2812 if ( sd ) {
2814 KOListView* kol = sd->listview(); 2813 KOListView* kol = sd->listview();
2815 if ( kol ) 2814 if ( kol )
2816 kol->clearList(); 2815 kol->clearList();
2817 } 2816 }
2818} 2817}
2819void CalendarView::updateView() 2818void CalendarView::updateView()
2820{ 2819{
2821 static bool clearallviews = false; 2820 static bool clearallviews = false;
2822 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2821 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2823 if ( clearallviews ) { 2822 if ( clearallviews ) {
2824 clearAllViews(); 2823 clearAllViews();
2825 clearallviews = false; 2824 clearallviews = false;
2826 } 2825 }
2827 return; 2826 return;
2828 } 2827 }
2829 clearallviews = true; 2828 clearallviews = true;
2830 DateList tmpList = mNavigator->selectedDates(); 2829 DateList tmpList = mNavigator->selectedDates();
2831 2830
2832 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2831 if ( KOPrefs::instance()->mHideNonStartedTodos )
2833 mTodoList->updateView(); 2832 mTodoList->updateView();
2834 // We assume that the navigator only selects consecutive days. 2833 // We assume that the navigator only selects consecutive days.
2835 updateView( tmpList.first(), tmpList.last() ); 2834 updateView( tmpList.first(), tmpList.last() );
2836} 2835}
2837 2836
2838void CalendarView::updateUnmanagedViews() 2837void CalendarView::updateUnmanagedViews()
2839{ 2838{
2840 mDateNavigator->updateDayMatrix(); 2839 mDateNavigator->updateDayMatrix();
2841} 2840}
2842 2841
2843int CalendarView::msgItemDelete(const QString name) 2842int CalendarView::msgItemDelete(const QString name)
2844{ 2843{
2845 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2844 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2846 i18n("This item will be\npermanently deleted."), 2845 i18n("This item will be\npermanently deleted."),
2847 i18n("KO/Pi Confirmation"),i18n("Delete")); 2846 i18n("KO/Pi Confirmation"),i18n("Delete"));
2848} 2847}
2849 2848
2850 2849
2851void CalendarView::edit_cut() 2850void CalendarView::edit_cut()
2852{ 2851{
2853 Event *anEvent=0; 2852 Event *anEvent=0;
2854 2853
2855 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2854 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2856 2855
2857 if (mViewManager->currentView()->isEventView()) { 2856 if (mViewManager->currentView()->isEventView()) {
2858 if ( incidence && incidence->typeID() == eventID ) { 2857 if ( incidence && incidence->typeID() == eventID ) {
2859 anEvent = static_cast<Event *>(incidence); 2858 anEvent = static_cast<Event *>(incidence);
2860 } 2859 }
2861 } 2860 }
2862 2861
2863 if (!anEvent) { 2862 if (!anEvent) {
2864 KNotifyClient::beep(); 2863 KNotifyClient::beep();
2865 return; 2864 return;
2866 } 2865 }
2867 DndFactory factory( mCalendar ); 2866 DndFactory factory( mCalendar );
2868 factory.cutIncidence(anEvent); 2867 factory.cutIncidence(anEvent);
2869 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2868 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2870} 2869}
2871 2870
2872void CalendarView::edit_copy() 2871void CalendarView::edit_copy()
2873{ 2872{
2874 Event *anEvent=0; 2873 Event *anEvent=0;
2875 2874
2876 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2875 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2877 2876
2878 if (mViewManager->currentView()->isEventView()) { 2877 if (mViewManager->currentView()->isEventView()) {
2879 if ( incidence && incidence->typeID() == eventID ) { 2878 if ( incidence && incidence->typeID() == eventID ) {
2880 anEvent = static_cast<Event *>(incidence); 2879 anEvent = static_cast<Event *>(incidence);
2881 } 2880 }
2882 } 2881 }
2883 2882
2884 if (!anEvent) { 2883 if (!anEvent) {
2885 KNotifyClient::beep(); 2884 KNotifyClient::beep();
2886 return; 2885 return;
2887 } 2886 }
2888 DndFactory factory( mCalendar ); 2887 DndFactory factory( mCalendar );
2889 factory.copyIncidence(anEvent); 2888 factory.copyIncidence(anEvent);
2890} 2889}
2891 2890
2892void CalendarView::edit_paste() 2891void CalendarView::edit_paste()
2893{ 2892{
2894 QDate date = mNavigator->selectedDates().first(); 2893 QDate date = mNavigator->selectedDates().first();
2895 2894
2896 DndFactory factory( mCalendar ); 2895 DndFactory factory( mCalendar );
2897 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2896 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2898 2897
2899 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2898 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2900} 2899}
2901void CalendarView::edit_global_options() 2900void CalendarView::edit_global_options()
2902{ 2901{
2903 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2902 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2904 emit save(); 2903 emit save();
2905 emit saveStopTimer(); 2904 emit saveStopTimer();
2906 mDialogManager->showGlobalOptionsDialog(); 2905 mDialogManager->showGlobalOptionsDialog();
2907 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2906 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2908 emit saveStopTimer(); 2907 emit saveStopTimer();
2909 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"), 2908 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"),
2910 i18n("Timezone settings"),i18n("Reload"))) { 2909 i18n("Timezone settings"),i18n("Reload"))) {
2911 qDebug("KO: TZ reload cancelled "); 2910 qDebug("KO: TZ reload cancelled ");
2912 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2911 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2913 return; 2912 return;
2914 } 2913 }
2915 qDebug("KO: Timezone change "); 2914 qDebug("KO: Timezone change ");
2916 loadCalendars(); 2915 loadCalendars();
2917 setModified(true); 2916 setModified(true);
2918 } 2917 }
2919 else 2918 else
2920 qDebug("KO: No tz change "); 2919 qDebug("KO: No tz change ");
2921} 2920}
2922void CalendarView::edit_options() 2921void CalendarView::edit_options()
2923{ 2922{
2924 mDialogManager->showOptionsDialog(); 2923 mDialogManager->showOptionsDialog();
2925} 2924}
2926 2925
2927 2926
2928void CalendarView::slotSelectPickerDate( QDate d) 2927void CalendarView::slotSelectPickerDate( QDate d)
2929{ 2928{
2930 mDateFrame->hide(); 2929 mDateFrame->hide();
2931 if ( mDatePickerMode == 1 ) { 2930 if ( mDatePickerMode == 1 ) {
2932 mNavigator->slotDaySelect( d ); 2931 mNavigator->slotDaySelect( d );
2933 } else if ( mDatePickerMode == 2 ) { 2932 } else if ( mDatePickerMode == 2 ) {
2934 if ( mMoveIncidence->typeID() == todoID ) { 2933 if ( mMoveIncidence->typeID() == todoID ) {
2935 Todo * to = (Todo *) mMoveIncidence; 2934 Todo * to = (Todo *) mMoveIncidence;
2936 QTime tim; 2935 QTime tim;
2937 int len = 0; 2936 int len = 0;
2938 if ( to->hasStartDate() && to->hasDueDate() ) 2937 if ( to->hasStartDate() && to->hasDueDate() )
2939 len = to->dtStart().secsTo( to->dtDue()); 2938 len = to->dtStart().secsTo( to->dtDue());
2940 if ( to->hasDueDate() ) 2939 if ( to->hasDueDate() )
2941 tim = to->dtDue().time(); 2940 tim = to->dtDue().time();
2942 else { 2941 else {
2943 tim = QTime ( 0,0,0 ); 2942 tim = QTime ( 0,0,0 );
2944 to->setFloats( true ); 2943 to->setFloats( true );
2945 to->setHasDueDate( true ); 2944 to->setHasDueDate( true );
2946 } 2945 }
2947 QDateTime dt ( d,tim ); 2946 QDateTime dt ( d,tim );
2948 to->setDtDue( dt ); 2947 to->setDtDue( dt );
2949 2948
2950 if ( to->hasStartDate() ) { 2949 if ( to->hasStartDate() ) {
2951 if ( len>0 ) 2950 if ( len>0 )
2952 to->setDtStart(to->dtDue().addSecs( -len )); 2951 to->setDtStart(to->dtDue().addSecs( -len ));
2953 else 2952 else
2954 if (to->dtStart() > to->dtDue() ) 2953 if (to->dtStart() > to->dtDue() )
2955 to->setDtStart(to->dtDue().addDays( -3 )); 2954 to->setDtStart(to->dtDue().addDays( -3 ));
2956 } 2955 }
2957 2956
2958 todoChanged( to ); 2957 todoChanged( to );
2959 } else if ( mMoveIncidence->typeID() == eventID ) { 2958 } else if ( mMoveIncidence->typeID() == eventID ) {
2960 if ( mMoveIncidence->doesRecur() ) { 2959 if ( mMoveIncidence->doesRecur() ) {
2961#if 0 2960#if 0
2962 // PENDING implement this 2961 // PENDING implement this
2963 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 2962 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
2964 mCalendar()->addIncidence( newInc ); 2963 mCalendar()->addIncidence( newInc );
2965 if ( mMoveIncidence->typeID() == todoID ) 2964 if ( mMoveIncidence->typeID() == todoID )
2966 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 2965 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
2967 else 2966 else
2968 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 2967 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
2969 mMoveIncidence = newInc; 2968 mMoveIncidence = newInc;
2970 2969
2971#endif 2970#endif
2972 } 2971 }
2973 QTime tim = mMoveIncidence->dtStart().time(); 2972 QTime tim = mMoveIncidence->dtStart().time();
2974 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2973 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2975 QDateTime dt ( d,tim ); 2974 QDateTime dt ( d,tim );
2976 mMoveIncidence->setDtStart( dt ); 2975 mMoveIncidence->setDtStart( dt );
2977 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2976 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2978 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2977 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2979 } else if ( mMoveIncidence->typeID() == journalID ) { 2978 } else if ( mMoveIncidence->typeID() == journalID ) {
2980 QTime tim = mMoveIncidence->dtStart().time(); 2979 QTime tim = mMoveIncidence->dtStart().time();
2981 QDateTime dt ( d,tim ); 2980 QDateTime dt ( d,tim );
2982 mMoveIncidence->setDtStart( dt ); 2981 mMoveIncidence->setDtStart( dt );
2983 updateView(); 2982 updateView();
2984 } 2983 }
2985 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2984 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2986 } 2985 }
2987} 2986}
2988 2987
2989void CalendarView::removeCategories() 2988void CalendarView::removeCategories()
2990{ 2989{
2991 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2990 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2992 QStringList catList = KOPrefs::instance()->mCustomCategories; 2991 QStringList catList = KOPrefs::instance()->mCustomCategories;
2993 QStringList catIncList; 2992 QStringList catIncList;
2994 QStringList newCatList; 2993 QStringList newCatList;
2995 Incidence* inc = incList.first(); 2994 Incidence* inc = incList.first();
2996 uint i; 2995 uint i;
2997 while ( inc ) { 2996 while ( inc ) {
2998 newCatList.clear(); 2997 newCatList.clear();
2999 catIncList = inc->categories() ; 2998 catIncList = inc->categories() ;
3000 for( i = 0; i< catIncList.count(); ++i ) { 2999 for( i = 0; i< catIncList.count(); ++i ) {
3001 if ( catList.contains (catIncList[i])) 3000 if ( catList.contains (catIncList[i]))
3002 newCatList.append( catIncList[i] ); 3001 newCatList.append( catIncList[i] );
3003 } 3002 }
3004 newCatList.sort(); 3003 newCatList.sort();
3005 inc->setCategories( newCatList.join(",") ); 3004 inc->setCategories( newCatList.join(",") );
3006 inc = incList.next(); 3005 inc = incList.next();
3007 } 3006 }
3008} 3007}
3009 3008
3010int CalendarView::addCategories() 3009int CalendarView::addCategories()
3011{ 3010{
3012 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3011 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3013 QStringList catList = KOPrefs::instance()->mCustomCategories; 3012 QStringList catList = KOPrefs::instance()->mCustomCategories;
3014 QStringList catIncList; 3013 QStringList catIncList;
3015 Incidence* inc = incList.first(); 3014 Incidence* inc = incList.first();
3016 uint i; 3015 uint i;
3017 int count = 0; 3016 int count = 0;
3018 while ( inc ) { 3017 while ( inc ) {
3019 catIncList = inc->categories() ; 3018 catIncList = inc->categories() ;
3020 for( i = 0; i< catIncList.count(); ++i ) { 3019 for( i = 0; i< catIncList.count(); ++i ) {
3021 if ( !catList.contains (catIncList[i])) { 3020 if ( !catList.contains (catIncList[i])) {
3022 catList.append( catIncList[i] ); 3021 catList.append( catIncList[i] );
3023 //qDebug("add cat %s ", catIncList[i].latin1()); 3022 //qDebug("add cat %s ", catIncList[i].latin1());
3024 ++count; 3023 ++count;
3025 } 3024 }
3026 } 3025 }
3027 inc = incList.next(); 3026 inc = incList.next();
3028 } 3027 }
3029 catList.sort(); 3028 catList.sort();
3030 KOPrefs::instance()->mCustomCategories = catList; 3029 KOPrefs::instance()->mCustomCategories = catList;
3031 return count; 3030 return count;
3032} 3031}
3033 3032
3034void CalendarView::editCategories() 3033void CalendarView::editCategories()
3035{ 3034{
3036 qDebug("CalendarView::editCategories() "); 3035 qDebug("CalendarView::editCategories() ");
3037 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this ); 3036 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this );
3038 ced.exec(); 3037 ced.exec();
3039} 3038}
3040void CalendarView::manageCategories() 3039void CalendarView::manageCategories()
3041{ 3040{
3042 KOCatPrefs* cp = new KOCatPrefs(); 3041 KOCatPrefs* cp = new KOCatPrefs();
3043 cp->show(); 3042 cp->show();
3044 int w =cp->sizeHint().width() ; 3043 int w =cp->sizeHint().width() ;
3045 int h = cp->sizeHint().height() ; 3044 int h = cp->sizeHint().height() ;
3046 int dw = QApplication::desktop()->width(); 3045 int dw = QApplication::desktop()->width();
3047 int dh = QApplication::desktop()->height(); 3046 int dh = QApplication::desktop()->height();
3048 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 3047 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
3049 if ( !cp->exec() ) { 3048 if ( !cp->exec() ) {
3050 delete cp; 3049 delete cp;
3051 return; 3050 return;
3052 } 3051 }
3053 int count = 0; 3052 int count = 0;
3054 if ( cp->addCat() ) { 3053 if ( cp->addCat() ) {
3055 count = addCategories(); 3054 count = addCategories();
3056 if ( count ) { 3055 if ( count ) {
3057 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 3056 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
3058 writeSettings(); 3057 writeSettings();
3059 } else 3058 } else
3060 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 3059 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
3061 } else { 3060 } else {
3062 removeCategories(); 3061 removeCategories();
3063 updateView(); 3062 updateView();
3064 } 3063 }
3065 delete cp; 3064 delete cp;
3066} 3065}
3067 3066
3068void CalendarView::beamIncidence(Incidence * Inc) 3067void CalendarView::beamIncidence(Incidence * Inc)
3069{ 3068{
3070 QPtrList<Incidence> delSel ; 3069 QPtrList<Incidence> delSel ;
3071 delSel.append(Inc); 3070 delSel.append(Inc);
3072 beamIncidenceList( delSel ); 3071 beamIncidenceList( delSel );
3073} 3072}
3074void CalendarView::beamCalendar() 3073void CalendarView::beamCalendar()
3075{ 3074{
3076 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 3075 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
3077 //qDebug("beamCalendar() "); 3076 //qDebug("beamCalendar() ");
3078 beamIncidenceList( delSel ); 3077 beamIncidenceList( delSel );
3079} 3078}
3080void CalendarView::beamFilteredCalendar() 3079void CalendarView::beamFilteredCalendar()
3081{ 3080{
3082 QPtrList<Incidence> delSel = mCalendar->incidences(); 3081 QPtrList<Incidence> delSel = mCalendar->incidences();
3083 //qDebug("beamFilteredCalendar() "); 3082 //qDebug("beamFilteredCalendar() ");
3084 beamIncidenceList( delSel ); 3083 beamIncidenceList( delSel );
3085} 3084}
3086void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 3085void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
3087{ 3086{
3088 3087
3089 KOBeamPrefs beamDialog; 3088 KOBeamPrefs beamDialog;
3090 if ( beamDialog.exec () == QDialog::Rejected ) 3089 if ( beamDialog.exec () == QDialog::Rejected )
3091 return; 3090 return;
3092#ifdef DESKTOP_VERSION 3091#ifdef DESKTOP_VERSION
3093 QString fn = locateLocal( "tmp", "kopibeamfile" ); 3092 QString fn = locateLocal( "tmp", "kopibeamfile" );
3094#else 3093#else
3095 QString fn = "/tmp/kopibeamfile"; 3094 QString fn = "/tmp/kopibeamfile";
3096#endif 3095#endif
3097 QString mes; 3096 QString mes;
3098 bool createbup = true; 3097 bool createbup = true;
3099 if ( createbup ) { 3098 if ( createbup ) {
3100 QString description = "\n"; 3099 QString description = "\n";
3101 CalendarLocal* cal = new CalendarLocal(); 3100 CalendarLocal* cal = new CalendarLocal();
3102 if ( beamDialog.beamLocal() ) 3101 if ( beamDialog.beamLocal() )
3103 cal->setLocalTime(); 3102 cal->setLocalTime();
3104 else 3103 else
3105 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 3104 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
3106 Incidence *incidence = delSel.first(); 3105 Incidence *incidence = delSel.first();
3107 bool addText = false; 3106 bool addText = false;
3108 if ( delSel.count() < 10 ) 3107 if ( delSel.count() < 10 )
3109 addText = true; 3108 addText = true;
3110 else { 3109 else {
3111 description.sprintf(i18n(" %d items?"),delSel.count() ); 3110 description.sprintf(i18n(" %d items?"),delSel.count() );
3112 } 3111 }
3113 while ( incidence ) { 3112 while ( incidence ) {
3114 Incidence *in = incidence->clone(); 3113 Incidence *in = incidence->clone();
3115 if ( ! in->summary().isEmpty() ) { 3114 if ( ! in->summary().isEmpty() ) {
3116 in->setDescription(""); 3115 in->setDescription("");
3117 } else { 3116 } else {
3118 in->setSummary( in->description().left(20)); 3117 in->setSummary( in->description().left(20));
3119 in->setDescription(""); 3118 in->setDescription("");
3120 } 3119 }
3121 if ( addText ) 3120 if ( addText )
3122 description += in->summary() + "\n"; 3121 description += in->summary() + "\n";
3123 cal->addIncidence( in ); 3122 cal->addIncidence( in );
3124 incidence = delSel.next(); 3123 incidence = delSel.next();
3125 } 3124 }
3126 if ( beamDialog.beamVcal() ) { 3125 if ( beamDialog.beamVcal() ) {
3127 fn += ".vcs"; 3126 fn += ".vcs";
3128 FileStorage storage( cal, fn, new VCalFormat ); 3127 FileStorage storage( cal, fn, new VCalFormat );
3129 storage.save(); 3128 storage.save();
3130 } else { 3129 } else {
3131 fn += ".ics"; 3130 fn += ".ics";
3132 FileStorage storage( cal, fn, new ICalFormat( ) ); 3131 FileStorage storage( cal, fn, new ICalFormat( ) );
3133 storage.save(); 3132 storage.save();
3134 } 3133 }
3135 delete cal; 3134 delete cal;
3136 mes = i18n("KO/Pi: Ready for beaming"); 3135 mes = i18n("KO/Pi: Ready for beaming");
3137 topLevelWidget()->setCaption(mes); 3136 topLevelWidget()->setCaption(mes);
3138 KApplication::convert2latin1( fn ); 3137 KApplication::convert2latin1( fn );
3139#ifndef DESKTOP_VERSION 3138#ifndef DESKTOP_VERSION
3140 Ir *ir = new Ir( this ); 3139 Ir *ir = new Ir( this );
3141 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 3140 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
3142 ir->send( fn, description, "text/x-vCalendar" ); 3141 ir->send( fn, description, "text/x-vCalendar" );
3143#endif 3142#endif
3144 } 3143 }
3145} 3144}
3146 3145
3147#ifndef DESKTOP_VERSION 3146#ifndef DESKTOP_VERSION
3148void CalendarView::beamDone( Ir *ir ) 3147void CalendarView::beamDone( Ir *ir )
3149{ 3148{
3150 delete ir; 3149 delete ir;
3151 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 3150 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
3152 topLevelWidget()->raise(); 3151 topLevelWidget()->raise();
3153} 3152}
3154#else 3153#else
3155void CalendarView::beamDone( Ir *){;} 3154void CalendarView::beamDone( Ir *){;}
3156#endif 3155#endif
3157void CalendarView::moveIncidence(Incidence * inc ) 3156void CalendarView::moveIncidence(Incidence * inc )
3158{ 3157{
3159 if ( !inc ) return; 3158 if ( !inc ) return;
3160 showDatePickerPopup(); 3159 showDatePickerPopup();
3161 mDatePickerMode = 2; 3160 mDatePickerMode = 2;
3162 mMoveIncidence = inc ; 3161 mMoveIncidence = inc ;
3163 QDate da; 3162 QDate da;
3164 if ( mMoveIncidence->typeID() == todoID ) { 3163 if ( mMoveIncidence->typeID() == todoID ) {
3165 Todo * to = (Todo *) mMoveIncidence; 3164 Todo * to = (Todo *) mMoveIncidence;
3166 if ( to->hasDueDate() ) 3165 if ( to->hasDueDate() )
3167 da = to->dtDue().date(); 3166 da = to->dtDue().date();
3168 else 3167 else
3169 da = QDate::currentDate(); 3168 da = QDate::currentDate();
3170 } else { 3169 } else {
3171 da = mMoveIncidence->dtStart().date(); 3170 da = mMoveIncidence->dtStart().date();
3172 } 3171 }
3173 //PENDING set date for recurring incidence to date of recurrence 3172 //PENDING set date for recurring incidence to date of recurrence
3174 //mMoveIncidenceOldDate; 3173 //mMoveIncidenceOldDate;
3175 mDatePicker->setDate( da ); 3174 mDatePicker->setDate( da );
3176} 3175}
3177void CalendarView::showDatePickerPopup() 3176void CalendarView::showDatePickerPopup()
3178{ 3177{
3179 if ( mDateFrame->isVisible() ) 3178 if ( mDateFrame->isVisible() )
3180 mDateFrame->hide(); 3179 mDateFrame->hide();
3181 else { 3180 else {
3182 int offX = 0, offY = 0; 3181 int offX = 0, offY = 0;
3183#ifdef DESKTOP_VERSION 3182#ifdef DESKTOP_VERSION
3184 int w =mDatePicker->sizeHint().width() ; 3183 int w =mDatePicker->sizeHint().width() ;
3185 int h = mDatePicker->sizeHint().height() ; 3184 int h = mDatePicker->sizeHint().height() ;
3186 int dw = topLevelWidget()->width(); 3185 int dw = topLevelWidget()->width();
3187 int dh = topLevelWidget()->height(); 3186 int dh = topLevelWidget()->height();
3188 offX = topLevelWidget()->x(); 3187 offX = topLevelWidget()->x();
3189 offY = topLevelWidget()->y(); 3188 offY = topLevelWidget()->y();
3190#else 3189#else
3191 int w =mDatePicker->sizeHint().width() ; 3190 int w =mDatePicker->sizeHint().width() ;
3192 int h = mDatePicker->sizeHint().height() ; 3191 int h = mDatePicker->sizeHint().height() ;
3193 int dw = QApplication::desktop()->width(); 3192 int dw = QApplication::desktop()->width();
3194 int dh = QApplication::desktop()->height(); 3193 int dh = QApplication::desktop()->height();
3195#endif 3194#endif
3196 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 3195 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
3197 mDateFrame->show(); 3196 mDateFrame->show();
3198 } 3197 }
3199} 3198}
3200void CalendarView::showDatePicker( ) 3199void CalendarView::showDatePicker( )
3201{ 3200{
3202 showDatePickerPopup(); 3201 showDatePickerPopup();
3203 mDatePickerMode = 1; 3202 mDatePickerMode = 1;
3204 mDatePicker->setDate( mNavigator->selectedDates().first() ); 3203 mDatePicker->setDate( mNavigator->selectedDates().first() );
3205} 3204}
3206 3205
3207void CalendarView::showEventEditor() 3206void CalendarView::showEventEditor()
3208{ 3207{
3209#ifdef DESKTOP_VERSION 3208#ifdef DESKTOP_VERSION
3210 int x,y,w,h; 3209 int x,y,w,h;
3211 x = mEventEditor->geometry().x(); 3210 x = mEventEditor->geometry().x();
3212 y = mEventEditor->geometry().y(); 3211 y = mEventEditor->geometry().y();
3213 w = mEventEditor->width(); 3212 w = mEventEditor->width();
3214 h = mEventEditor->height(); 3213 h = mEventEditor->height();
3215 mEventEditor->show(); 3214 mEventEditor->show();
3216 mEventEditor->setGeometry(x,y,w,h); 3215 mEventEditor->setGeometry(x,y,w,h);
3217#else 3216#else
3218 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 3217 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
3219 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3218 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3220 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 3219 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
3221 qApp->processEvents(); 3220 qApp->processEvents();
3222 delete mEventEditor; 3221 delete mEventEditor;
3223 mEventEditor = mDialogManager->getEventEditor(); 3222 mEventEditor = mDialogManager->getEventEditor();
3224 topLevelWidget()->setCaption( i18n("") ); 3223 topLevelWidget()->setCaption( i18n("") );
3225 } 3224 }
3226 mEventEditor->showMaximized(); 3225 mEventEditor->showMaximized();
3227#endif 3226#endif
3228} 3227}
3229void CalendarView::showTodoEditor() 3228void CalendarView::showTodoEditor()
3230{ 3229{
3231#ifdef DESKTOP_VERSION 3230#ifdef DESKTOP_VERSION
3232 int x,y,w,h; 3231 int x,y,w,h;
3233 x = mTodoEditor->geometry().x(); 3232 x = mTodoEditor->geometry().x();
3234 y = mTodoEditor->geometry().y(); 3233 y = mTodoEditor->geometry().y();
3235 w = mTodoEditor->width(); 3234 w = mTodoEditor->width();
3236 h = mTodoEditor->height(); 3235 h = mTodoEditor->height();
3237 mTodoEditor->show(); 3236 mTodoEditor->show();
3238 mTodoEditor->setGeometry(x,y,w,h); 3237 mTodoEditor->setGeometry(x,y,w,h);
3239#else 3238#else
3240 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 3239 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
3241 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3240 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3242 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 3241 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
3243 qApp->processEvents(); 3242 qApp->processEvents();
3244 delete mTodoEditor; 3243 delete mTodoEditor;
3245 mTodoEditor = mDialogManager->getTodoEditor(); 3244 mTodoEditor = mDialogManager->getTodoEditor();
3246 topLevelWidget()->setCaption( i18n("") ); 3245 topLevelWidget()->setCaption( i18n("") );
3247 } 3246 }
3248 mTodoEditor->showMaximized(); 3247 mTodoEditor->showMaximized();
3249#endif 3248#endif
3250} 3249}
3251 3250
3252void CalendarView::cloneIncidence() 3251void CalendarView::cloneIncidence()
3253{ 3252{
3254 Incidence *incidence = currentSelection(); 3253 Incidence *incidence = currentSelection();
3255 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3254 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3256 if ( incidence ) { 3255 if ( incidence ) {
3257 cloneIncidence(incidence); 3256 cloneIncidence(incidence);
3258 } 3257 }
3259} 3258}
3260void CalendarView::moveIncidence() 3259void CalendarView::moveIncidence()
3261{ 3260{
3262 Incidence *incidence = currentSelection(); 3261 Incidence *incidence = currentSelection();
3263 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3262 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3264 if ( incidence ) { 3263 if ( incidence ) {
3265 moveIncidence(incidence); 3264 moveIncidence(incidence);
3266 } 3265 }
3267} 3266}
3268void CalendarView::beamIncidence() 3267void CalendarView::beamIncidence()
3269{ 3268{
3270 Incidence *incidence = currentSelection(); 3269 Incidence *incidence = currentSelection();
3271 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3270 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3272 if ( incidence ) { 3271 if ( incidence ) {
3273 beamIncidence(incidence); 3272 beamIncidence(incidence);
3274 } 3273 }
3275} 3274}
3276void CalendarView::toggleCancelIncidence() 3275void CalendarView::toggleCancelIncidence()
3277{ 3276{
3278 Incidence *incidence = currentSelection(); 3277 Incidence *incidence = currentSelection();
3279 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3278 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3280 if ( incidence ) { 3279 if ( incidence ) {
3281 cancelIncidence(incidence); 3280 cancelIncidence(incidence);
3282 } 3281 }
3283} 3282}
3284 3283
3285 3284
3286void CalendarView::cancelIncidence(Incidence * inc ) 3285void CalendarView::cancelIncidence(Incidence * inc )
3287{ 3286{
3288 inc->setCancelled( ! inc->cancelled() ); 3287 inc->setCancelled( ! inc->cancelled() );
3289 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 3288 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
3290 updateView(); 3289 updateView();
3291} 3290}
3292void CalendarView::cloneIncidence(Incidence * orgInc ) 3291void CalendarView::cloneIncidence(Incidence * orgInc )
3293{ 3292{
3294 Incidence * newInc = orgInc->clone(); 3293 Incidence * newInc = orgInc->clone();
3295 newInc->recreate(); 3294 newInc->recreate();
3296 3295
3297 if ( newInc->typeID() == todoID ) { 3296 if ( newInc->typeID() == todoID ) {
3298 Todo* t = (Todo*) newInc; 3297 Todo* t = (Todo*) newInc;
3299 bool cloneSub = false; 3298 bool cloneSub = false;
3300 if ( orgInc->relations().count() ) { 3299 if ( orgInc->relations().count() ) {
3301 int result = KMessageBox::warningYesNoCancel(this, 3300 int result = KMessageBox::warningYesNoCancel(this,
3302 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( KGlobal::formatMessage ( newInc->summary(),0 ) ), 3301 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( KGlobal::formatMessage ( newInc->summary(),0 ) ),
3303 i18n("Todo has subtodos"), 3302 i18n("Todo has subtodos"),
3304 i18n("Yes"), 3303 i18n("Yes"),
3305 i18n("No")); 3304 i18n("No"));
3306 3305
3307 if ( result == KMessageBox::Cancel ) { 3306 if ( result == KMessageBox::Cancel ) {
3308 delete t; 3307 delete t;
3309 return; 3308 return;
3310 } 3309 }
3311 if (result == KMessageBox::Yes) cloneSub = true; 3310 if (result == KMessageBox::Yes) cloneSub = true;
3312 } 3311 }
3313 showTodoEditor(); 3312 showTodoEditor();
3314 mTodoEditor->editTodo( t ); 3313 mTodoEditor->editTodo( t );
3315 if ( mTodoEditor->exec() ) { 3314 if ( mTodoEditor->exec() ) {
3316 if ( cloneSub ) { 3315 if ( cloneSub ) {
3317 orgInc->cloneRelations( t ); 3316 orgInc->cloneRelations( t );
3318 mCalendar->addIncidenceBranch( t ); 3317 mCalendar->addIncidenceBranch( t );
3319 updateView(); 3318 updateView();
3320 3319
3321 } else { 3320 } else {
3322 mCalendar->addTodo( t ); 3321 mCalendar->addTodo( t );
3323 updateView(); 3322 updateView();
3324 } 3323 }
3325 } else { 3324 } else {
3326 delete t; 3325 delete t;
3327 } 3326 }
3328 } 3327 }
3329 else if ( newInc->typeID() == eventID ) { 3328 else if ( newInc->typeID() == eventID ) {
3330 Event* e = (Event*) newInc; 3329 Event* e = (Event*) newInc;
3331 showEventEditor(); 3330 showEventEditor();
3332 mEventEditor->editEvent( e ); 3331 mEventEditor->editEvent( e );
3333 if ( mEventEditor->exec() ) { 3332 if ( mEventEditor->exec() ) {
3334 mCalendar->addEvent( e ); 3333 mCalendar->addEvent( e );
3335 updateView(); 3334 updateView();
3336 } else { 3335 } else {
3337 delete e; 3336 delete e;
3338 } 3337 }
3339 } if ( newInc->typeID() == journalID ) { 3338 } if ( newInc->typeID() == journalID ) {
3340 mCalendar->addJournal( (Journal*) newInc ); 3339 mCalendar->addJournal( (Journal*) newInc );
3341 editJournal( (Journal*) newInc ); 3340 editJournal( (Journal*) newInc );
3342 } 3341 }
3343 setActiveWindow(); 3342 setActiveWindow();
3344} 3343}
3345 3344
3346void CalendarView::newEvent() 3345void CalendarView::newEvent()
3347{ 3346{
3348 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 3347 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
3349 KOAgendaView *aView = mViewManager->agendaView(); 3348 KOAgendaView *aView = mViewManager->agendaView();
3350 if (aView) { 3349 if (aView) {
3351 if (aView->selectionStart().isValid()) { 3350 if (aView->selectionStart().isValid()) {
3352 if (aView->selectedIsAllDay()) { 3351 if (aView->selectedIsAllDay()) {
3353 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 3352 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
3354 } else { 3353 } else {
3355 newEvent(aView->selectionStart(),aView->selectionEnd()); 3354 newEvent(aView->selectionStart(),aView->selectionEnd());
3356 } 3355 }
3357 return; 3356 return;
3358 } 3357 }
3359 } 3358 }
3360 3359
3361 QDate date = mNavigator->selectedDates().first(); 3360 QDate date = mNavigator->selectedDates().first();
3362 QDateTime current = QDateTime::currentDateTime(); 3361 QDateTime current = QDateTime::currentDateTime();
3363 if ( date <= current.date() ) { 3362 if ( date <= current.date() ) {
3364 int hour = current.time().hour() +1; 3363 int hour = current.time().hour() +1;
3365 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 3364 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
3366 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3365 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3367 } else 3366 } else
3368 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 3367 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
3369 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 3368 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
3370 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3369 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3371} 3370}
3372 3371
3373void CalendarView::newEvent(QDateTime fh) 3372void CalendarView::newEvent(QDateTime fh)
3374{ 3373{
3375 newEvent(fh, 3374 newEvent(fh,
3376 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 3375 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
3377} 3376}
3378 3377
3379void CalendarView::newEvent(QDate dt) 3378void CalendarView::newEvent(QDate dt)
3380{ 3379{
3381 newEvent(QDateTime(dt, QTime(0,0,0)), 3380 newEvent(QDateTime(dt, QTime(0,0,0)),
3382 QDateTime(dt, QTime(0,0,0)), true); 3381 QDateTime(dt, QTime(0,0,0)), true);
3383} 3382}
3384void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 3383void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
3385{ 3384{
3386 newEvent(fromHint, toHint, false); 3385 newEvent(fromHint, toHint, false);
3387} 3386}
3388void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 3387void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
3389{ 3388{
3390 3389
3391 showEventEditor(); 3390 showEventEditor();
3392 mEventEditor->newEvent(fromHint,toHint,allDay); 3391 mEventEditor->newEvent(fromHint,toHint,allDay);
3393 if ( mFilterView->filtersEnabled() ) { 3392 if ( mFilterView->filtersEnabled() ) {
3394 CalFilter *filter = mFilterView->selectedFilter(); 3393 CalFilter *filter = mFilterView->selectedFilter();
3395 if (filter && filter->showCategories()) { 3394 if (filter && filter->showCategories()) {
3396 mEventEditor->setCategories(filter->categoryList().join(",") ); 3395 mEventEditor->setCategories(filter->categoryList().join(",") );
3397 } 3396 }
3398 if ( filter ) 3397 if ( filter )
3399 mEventEditor->setSecrecy( filter->getSecrecy() ); 3398 mEventEditor->setSecrecy( filter->getSecrecy() );
3400 } 3399 }
3401 mEventEditor->exec(); 3400 mEventEditor->exec();
3402 setActiveWindow(); 3401 setActiveWindow();
3403} 3402}
3404void CalendarView::todoAdded(Todo * t) 3403void CalendarView::todoAdded(Todo * t)
3405{ 3404{
3406 3405
3407 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 3406 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
3408 updateTodoViews(); 3407 updateTodoViews();
3409} 3408}
3410void CalendarView::todoChanged(Todo * t) 3409void CalendarView::todoChanged(Todo * t)
3411{ 3410{
3412 emit todoModified( t, 4 ); 3411 emit todoModified( t, 4 );
3413 // updateTodoViews(); 3412 // updateTodoViews();
3414} 3413}
3415void CalendarView::todoToBeDeleted(Todo *) 3414void CalendarView::todoToBeDeleted(Todo *)
3416{ 3415{
3417 //qDebug("todoToBeDeleted(Todo *) "); 3416 //qDebug("todoToBeDeleted(Todo *) ");
3418 updateTodoViews(); 3417 updateTodoViews();
3419} 3418}
3420void CalendarView::todoDeleted() 3419void CalendarView::todoDeleted()
3421{ 3420{
3422 //qDebug(" todoDeleted()"); 3421 //qDebug(" todoDeleted()");
3423 updateTodoViews(); 3422 updateTodoViews();
3424} 3423}
3425 3424
3426 3425
3427void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 3426void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
3428{ 3427{
3429 showTodoEditor(); 3428 showTodoEditor();
3430 mTodoEditor->newTodo(dt,0,allday); 3429 mTodoEditor->newTodo(dt,0,allday);
3431 if ( mFilterView->filtersEnabled() ) { 3430 if ( mFilterView->filtersEnabled() ) {
3432 CalFilter *filter = mFilterView->selectedFilter(); 3431 CalFilter *filter = mFilterView->selectedFilter();
3433 if (filter && filter->showCategories()) { 3432 if (filter && filter->showCategories()) {
3434 mTodoEditor->setCategories(filter->categoryList().join(",") ); 3433 mTodoEditor->setCategories(filter->categoryList().join(",") );
3435 } 3434 }
3436 if ( filter ) 3435 if ( filter )
3437 mTodoEditor->setSecrecy( filter->getSecrecy() ); 3436 mTodoEditor->setSecrecy( filter->getSecrecy() );
3438 } 3437 }
3439 mTodoEditor->exec(); 3438 mTodoEditor->exec();
3440 setActiveWindow(); 3439 setActiveWindow();
3441} 3440}
3442 3441
3443void CalendarView::newTodo() 3442void CalendarView::newTodo()
3444{ 3443{
3445 newTodoDateTime( QDateTime(),true ); 3444 newTodoDateTime( QDateTime(),true );
3446} 3445}
3447 3446
3448void CalendarView::newSubTodo() 3447void CalendarView::newSubTodo()
3449{ 3448{
3450 Todo *todo = selectedTodo(); 3449 Todo *todo = selectedTodo();
3451 if ( todo ) newSubTodo( todo ); 3450 if ( todo ) newSubTodo( todo );
3452} 3451}
3453 3452
3454void CalendarView::newSubTodo(Todo *parentEvent) 3453void CalendarView::newSubTodo(Todo *parentEvent)
3455{ 3454{
3456 3455
3457 showTodoEditor(); 3456 showTodoEditor();
3458 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 3457 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
3459 mTodoEditor->exec(); 3458 mTodoEditor->exec();
3460 setActiveWindow(); 3459 setActiveWindow();
3461} 3460}
3462 3461
3463void CalendarView::newFloatingEvent() 3462void CalendarView::newFloatingEvent()
3464{ 3463{
3465 DateList tmpList = mNavigator->selectedDates(); 3464 DateList tmpList = mNavigator->selectedDates();
3466 QDate date = tmpList.first(); 3465 QDate date = tmpList.first();
3467 3466
3468 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 3467 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
3469 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 3468 QDateTime( date, QTime( 12, 0, 0 ) ), true );
3470} 3469}
3471 3470
3472 3471
3473void CalendarView::editEvent( Event *event ) 3472void CalendarView::editEvent( Event *event )
3474{ 3473{
3475 3474
3476 if ( !event ) return; 3475 if ( !event ) return;
3477 if ( event->isReadOnly() ) { 3476 if ( event->isReadOnly() ) {
3478 showEvent( event ); 3477 showEvent( event );
3479 return; 3478 return;
3480 } 3479 }
3481 showEventEditor(); 3480 showEventEditor();
3482 mEventEditor->editEvent( event , mFlagEditDescription); 3481 mEventEditor->editEvent( event , mFlagEditDescription);
3483 mEventEditor->exec(); 3482 mEventEditor->exec();
3484 setActiveWindow(); 3483 setActiveWindow();
3485 3484
3486} 3485}
3487void CalendarView::editJournal( Journal *jour ) 3486void CalendarView::editJournal( Journal *jour )
3488{ 3487{
3489 if ( !jour ) return; 3488 if ( !jour ) return;
3490 mDialogManager->hideSearchDialog(); 3489 mDialogManager->hideSearchDialog();
3491 mViewManager->showJournalView(); 3490 mViewManager->showJournalView();
3492 mNavigator->slotDaySelect( jour->dtStart().date() ); 3491 mNavigator->slotDaySelect( jour->dtStart().date() );
3493} 3492}
3494void CalendarView::editTodo( Todo *todo ) 3493void CalendarView::editTodo( Todo *todo )
3495{ 3494{
3496 if ( !todo ) return; 3495 if ( !todo ) return;
3497 3496
3498 if ( todo->isReadOnly() ) { 3497 if ( todo->isReadOnly() ) {
3499 showTodo( todo ); 3498 showTodo( todo );
3500 return; 3499 return;
3501 } 3500 }
3502 showTodoEditor(); 3501 showTodoEditor();
3503 mTodoEditor->editTodo( todo ,mFlagEditDescription); 3502 mTodoEditor->editTodo( todo ,mFlagEditDescription);
3504 mTodoEditor->exec(); 3503 mTodoEditor->exec();
3505 setActiveWindow(); 3504 setActiveWindow();
3506 3505
3507} 3506}
3508 3507
3509KOEventViewerDialog* CalendarView::getEventViewerDialog() 3508KOEventViewerDialog* CalendarView::getEventViewerDialog()
3510{ 3509{
3511 if ( !mEventViewerDialog ) { 3510 if ( !mEventViewerDialog ) {
3512 mEventViewerDialog = new KOEventViewerDialog(0); 3511 mEventViewerDialog = new KOEventViewerDialog(0);
3513 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 3512 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
3514 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 3513 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
3515 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 3514 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
3516 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 3515 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
3517 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 3516 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
3518 viewManager(), SLOT( showAgendaView( bool ) ) ); 3517 viewManager(), SLOT( showAgendaView( bool ) ) );
3519 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 3518 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
3520 this, SLOT( slotViewerClosed() ) ); 3519 this, SLOT( slotViewerClosed() ) );
3521 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 3520 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
3522 this, SLOT( todoChanged(Todo *) ) ); 3521 this, SLOT( todoChanged(Todo *) ) );
3523 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 3522 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
3524 mEventViewerDialog->resize( 640, 480 ); 3523 mEventViewerDialog->resize( 640, 480 );
3525 3524
3526 } 3525 }
3527 return mEventViewerDialog; 3526 return mEventViewerDialog;
3528} 3527}
3529void CalendarView::showEvent(Event *event) 3528void CalendarView::showEvent(Event *event)
3530{ 3529{
3531 getEventViewerDialog()->setEvent(event); 3530 getEventViewerDialog()->setEvent(event);
3532 getEventViewerDialog()->showMe(); 3531 getEventViewerDialog()->showMe();
3533} 3532}
3534 3533
3535void CalendarView::showTodo(Todo *event) 3534void CalendarView::showTodo(Todo *event)
3536{ 3535{
3537 getEventViewerDialog()->setTodo(event); 3536 getEventViewerDialog()->setTodo(event);
3538 getEventViewerDialog()->showMe(); 3537 getEventViewerDialog()->showMe();
3539} 3538}
3540void CalendarView::showJournal( Journal *jour ) 3539void CalendarView::showJournal( Journal *jour )
3541{ 3540{
3542 getEventViewerDialog()->setJournal(jour); 3541 getEventViewerDialog()->setJournal(jour);
3543 getEventViewerDialog()->showMe(); 3542 getEventViewerDialog()->showMe();
3544 3543
3545} 3544}
3546// void CalendarView::todoModified (Todo *event, int changed) 3545// void CalendarView::todoModified (Todo *event, int changed)
3547// { 3546// {
3548// // if (mDialogList.find (event) != mDialogList.end ()) { 3547// // if (mDialogList.find (event) != mDialogList.end ()) {
3549// // kdDebug() << "Todo modified and open" << endl; 3548// // kdDebug() << "Todo modified and open" << endl;
3550// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 3549// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
3551// // temp->modified (changed); 3550// // temp->modified (changed);
3552 3551
3553// // } 3552// // }
3554 3553
3555// mViewManager->updateView(); 3554// mViewManager->updateView();
3556// } 3555// }
3557 3556
3558void CalendarView::appointment_show() 3557void CalendarView::appointment_show()
3559{ 3558{
3560 Event *anEvent = 0; 3559 Event *anEvent = 0;
3561 3560
3562 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3561 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3563 3562
3564 if (mViewManager->currentView()->isEventView()) { 3563 if (mViewManager->currentView()->isEventView()) {
3565 if ( incidence && incidence->typeID() == eventID ) { 3564 if ( incidence && incidence->typeID() == eventID ) {
3566 anEvent = static_cast<Event *>(incidence); 3565 anEvent = static_cast<Event *>(incidence);
3567 } 3566 }
3568 } 3567 }
3569 3568
3570 if (!anEvent) { 3569 if (!anEvent) {
3571 KNotifyClient::beep(); 3570 KNotifyClient::beep();
3572 return; 3571 return;
3573 } 3572 }
3574 3573
3575 showEvent(anEvent); 3574 showEvent(anEvent);
3576} 3575}
3577 3576
3578void CalendarView::appointment_edit() 3577void CalendarView::appointment_edit()
3579{ 3578{
3580 Event *anEvent = 0; 3579 Event *anEvent = 0;
3581 3580
3582 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3581 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3583 3582
3584 if (mViewManager->currentView()->isEventView()) { 3583 if (mViewManager->currentView()->isEventView()) {
3585 if ( incidence && incidence->typeID() == eventID ) { 3584 if ( incidence && incidence->typeID() == eventID ) {
3586 anEvent = static_cast<Event *>(incidence); 3585 anEvent = static_cast<Event *>(incidence);
3587 } 3586 }
3588 } 3587 }
3589 3588
3590 if (!anEvent) { 3589 if (!anEvent) {
3591 KNotifyClient::beep(); 3590 KNotifyClient::beep();
3592 return; 3591 return;
3593 } 3592 }
3594 3593
3595 editEvent(anEvent); 3594 editEvent(anEvent);
3596} 3595}
3597 3596
3598void CalendarView::appointment_delete() 3597void CalendarView::appointment_delete()
3599{ 3598{
3600 Event *anEvent = 0; 3599 Event *anEvent = 0;
3601 3600
3602 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3601 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3603 3602
3604 if (mViewManager->currentView()->isEventView()) { 3603 if (mViewManager->currentView()->isEventView()) {
3605 if ( incidence && incidence->typeID() == eventID ) { 3604 if ( incidence && incidence->typeID() == eventID ) {
3606 anEvent = static_cast<Event *>(incidence); 3605 anEvent = static_cast<Event *>(incidence);
3607 } 3606 }
3608 } 3607 }
3609 3608
3610 if (!anEvent) { 3609 if (!anEvent) {
3611 KNotifyClient::beep(); 3610 KNotifyClient::beep();
3612 return; 3611 return;
3613 } 3612 }
3614 3613
3615 deleteEvent(anEvent); 3614 deleteEvent(anEvent);
3616} 3615}
3617 3616
3618void CalendarView::todo_resub( Todo * parent, Todo * sub ) 3617void CalendarView::todo_resub( Todo * parent, Todo * sub )
3619{ 3618{
3620 if (!sub) return; 3619 if (!sub) return;
3621 if ( sub->relatedTo() == parent ) 3620 if ( sub->relatedTo() == parent )
3622 return; 3621 return;
3623 sub->setRelatedTo(parent); 3622 sub->setRelatedTo(parent);
3624 sub->updated(); 3623 sub->updated();
3625 setModified(true); 3624 setModified(true);
3626 updateView(); 3625 updateView();
3627} 3626}
3628void CalendarView::todo_unsub(Todo *anTodo ) 3627void CalendarView::todo_unsub(Todo *anTodo )
3629{ 3628{
3630 todo_resub( 0, anTodo ); 3629 todo_resub( 0, anTodo );
3631} 3630}
3632 3631
3633void CalendarView::deleteTodo(Todo *todo) 3632void CalendarView::deleteTodo(Todo *todo)
3634{ 3633{
3635 if (!todo) { 3634 if (!todo) {
3636 KNotifyClient::beep(); 3635 KNotifyClient::beep();
3637 return; 3636 return;
3638 } 3637 }
3639 if (KOPrefs::instance()->mConfirm) { 3638 if (KOPrefs::instance()->mConfirm) {
3640 QString text = KGlobal::formatMessage ( todo->summary(),0 ); 3639 QString text = KGlobal::formatMessage ( todo->summary(),0 );
3641 if (!todo->relations().isEmpty()) { 3640 if (!todo->relations().isEmpty()) {
3642 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3641 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
3643 3642
3644 } 3643 }
3645 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) { 3644 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) {
3646 case KMessageBox::Continue: // OK 3645 case KMessageBox::Continue: // OK
3647 bool deleteT = false; 3646 bool deleteT = false;
3648 if (!todo->relations().isEmpty()) { 3647 if (!todo->relations().isEmpty()) {
3649 deleteT = removeCompletedSubTodos( todo ); 3648 deleteT = removeCompletedSubTodos( todo );
3650 } 3649 }
3651 // deleteT == true: todo already deleted in removeCompletedSubTodos 3650 // deleteT == true: todo already deleted in removeCompletedSubTodos
3652 if ( !deleteT ) { 3651 if ( !deleteT ) {
3653 checkExternalId( todo ); 3652 checkExternalId( todo );
3654 calendar()->deleteTodo(todo); 3653 calendar()->deleteTodo(todo);
3655 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3654 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3656 updateView(); 3655 updateView();
3657 } 3656 }
3658 break; 3657 break;
3659 } // switch 3658 } // switch
3660 } else { 3659 } else {
3661 checkExternalId( todo ); 3660 checkExternalId( todo );
3662 mCalendar->deleteTodo(todo); 3661 mCalendar->deleteTodo(todo);
3663 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3662 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3664 updateView(); 3663 updateView();
3665 } 3664 }
3666 3665
3667 emit updateSearchDialog(); 3666 emit updateSearchDialog();
3668} 3667}
3669void CalendarView::deleteJournal(Journal *jour) 3668void CalendarView::deleteJournal(Journal *jour)
3670{ 3669{
3671 if (!jour) { 3670 if (!jour) {
3672 KNotifyClient::beep(); 3671 KNotifyClient::beep();
3673 return; 3672 return;
3674 } 3673 }
3675 if (KOPrefs::instance()->mConfirm) { 3674 if (KOPrefs::instance()->mConfirm) {
3676 3675
3677 QString des; 3676 QString des;
3678 if ( !jour->summary().isEmpty() ) { 3677 if ( !jour->summary().isEmpty() ) {
3679 des = jour->summary(); 3678 des = jour->summary();
3680 } else { 3679 } else {
3681 des = jour->description().left(30); 3680 des = jour->description().left(30);
3682 des = des.simplifyWhiteSpace (); 3681 des = des.simplifyWhiteSpace ();
3683 des.replace (QRegExp ("\\n"),"" ); 3682 des.replace (QRegExp ("\\n"),"" );
3684 des.replace (QRegExp ("\\r"),"" ); 3683 des.replace (QRegExp ("\\r"),"" );
3685 } 3684 }
3686 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) { 3685 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) {
3687 case KMessageBox::Continue: // OK 3686 case KMessageBox::Continue: // OK
3688 calendar()->deleteJournal(jour); 3687 calendar()->deleteJournal(jour);
3689 updateView(); 3688 updateView();
3690 break; 3689 break;
3691 } // switch 3690 } // switch
3692 } else { 3691 } else {
3693 calendar()->deleteJournal(jour);; 3692 calendar()->deleteJournal(jour);;
3694 updateView(); 3693 updateView();
3695 } 3694 }
3696 emit updateSearchDialog(); 3695 emit updateSearchDialog();
3697} 3696}
3698 3697
3699void CalendarView::deleteEvent(Event *anEvent) 3698void CalendarView::deleteEvent(Event *anEvent)
3700{ 3699{
3701 if (!anEvent) { 3700 if (!anEvent) {
3702 KNotifyClient::beep(); 3701 KNotifyClient::beep();
3703 return; 3702 return;
3704 } 3703 }
3705 3704
3706 if (anEvent->recurrence()->doesRecur()) { 3705 if (anEvent->recurrence()->doesRecur()) {
3707 QDate itemDate = mViewManager->currentSelectionDate(); 3706 QDate itemDate = mViewManager->currentSelectionDate();
3708 int km; 3707 int km;
3709 if (!itemDate.isValid()) { 3708 if (!itemDate.isValid()) {
3710 //kdDebug() << "Date Not Valid" << endl; 3709 //kdDebug() << "Date Not Valid" << endl;
3711 if (KOPrefs::instance()->mConfirm) { 3710 if (KOPrefs::instance()->mConfirm) {
3712 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3711 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3713 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3712 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3714 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3713 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3715 if ( km == KMessageBox::Continue ) 3714 if ( km == KMessageBox::Continue )
3716 km = KMessageBox::No; // No = all below 3715 km = KMessageBox::No; // No = all below
3717 } else 3716 } else
3718 km = KMessageBox::No; 3717 km = KMessageBox::No;
3719 } else { 3718 } else {
3720 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3719 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3721 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3720 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3722 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3721 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3723 i18n("KO/Pi Confirmation"),i18n("Current"), 3722 i18n("KO/Pi Confirmation"),i18n("Current"),
3724 i18n("All")); 3723 i18n("All"));
3725 } 3724 }
3726 switch(km) { 3725 switch(km) {
3727 3726
3728 case KMessageBox::No: // Continue // all 3727 case KMessageBox::No: // Continue // all
3729 //qDebug("KMessageBox::No "); 3728 //qDebug("KMessageBox::No ");
3730 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3729 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3731 schedule(Scheduler::Cancel,anEvent); 3730 schedule(Scheduler::Cancel,anEvent);
3732 3731
3733 checkExternalId( anEvent); 3732 checkExternalId( anEvent);
3734 mCalendar->deleteEvent(anEvent); 3733 mCalendar->deleteEvent(anEvent);
3735 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3734 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3736 break; 3735 break;
3737 3736
3738 // Disabled because it does not work 3737 // Disabled because it does not work
3739 //#if 0 3738 //#if 0
3740 case KMessageBox::Yes: // just this one 3739 case KMessageBox::Yes: // just this one
3741 //QDate qd = mNavigator->selectedDates().first(); 3740 //QDate qd = mNavigator->selectedDates().first();
3742 //if (!qd.isValid()) { 3741 //if (!qd.isValid()) {
3743 // kdDebug() << "no date selected, or invalid date" << endl; 3742 // kdDebug() << "no date selected, or invalid date" << endl;
3744 // KNotifyClient::beep(); 3743 // KNotifyClient::beep();
3745 // return; 3744 // return;
3746 //} 3745 //}
3747 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3746 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3748 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3747 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3749 anEvent->addExDate(itemDate); 3748 anEvent->addExDate(itemDate);
3750 int duration = anEvent->recurrence()->duration(); 3749 int duration = anEvent->recurrence()->duration();
3751 if ( duration > 0 ) { 3750 if ( duration > 0 ) {
3752 anEvent->recurrence()->setDuration( duration - 1 ); 3751 anEvent->recurrence()->setDuration( duration - 1 );
3753 } 3752 }
3754 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3753 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3755 } 3754 }
3756 break; 3755 break;
3757 //#endif 3756 //#endif
3758 } // switch 3757 } // switch
3759 } else { 3758 } else {
3760 if (KOPrefs::instance()->mConfirm) { 3759 if (KOPrefs::instance()->mConfirm) {
3761 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3760 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3762 i18n("\nAre you sure you want\nto delete this event?"), 3761 i18n("\nAre you sure you want\nto delete this event?"),
3763 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3762 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3764 case KMessageBox::Continue: // OK 3763 case KMessageBox::Continue: // OK
3765 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3764 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3766 schedule(Scheduler::Cancel,anEvent); 3765 schedule(Scheduler::Cancel,anEvent);
3767 checkExternalId( anEvent); 3766 checkExternalId( anEvent);
3768 mCalendar->deleteEvent(anEvent); 3767 mCalendar->deleteEvent(anEvent);
3769 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3768 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3770 break; 3769 break;
3771 } // switch 3770 } // switch
3772 } else { 3771 } else {
3773 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3772 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3774 schedule(Scheduler::Cancel,anEvent); 3773 schedule(Scheduler::Cancel,anEvent);
3775 checkExternalId( anEvent); 3774 checkExternalId( anEvent);
3776 mCalendar->deleteEvent(anEvent); 3775 mCalendar->deleteEvent(anEvent);
3777 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3776 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3778 } 3777 }
3779 } // if-else 3778 } // if-else
3780 emit updateSearchDialog(); 3779 emit updateSearchDialog();
3781} 3780}
3782 3781
3783bool CalendarView::deleteEvent(const QString &uid) 3782bool CalendarView::deleteEvent(const QString &uid)
3784{ 3783{
3785 Event *ev = mCalendar->event(uid); 3784 Event *ev = mCalendar->event(uid);
3786 if (ev) { 3785 if (ev) {
3787 deleteEvent(ev); 3786 deleteEvent(ev);
3788 return true; 3787 return true;
3789 } else { 3788 } else {
3790 return false; 3789 return false;
3791 } 3790 }
3792} 3791}
3793 3792
3794/*****************************************************************************/ 3793/*****************************************************************************/
3795 3794
3796void CalendarView::action_mail() 3795void CalendarView::action_mail()
3797{ 3796{
3798#ifndef KORG_NOMAIL 3797#ifndef KORG_NOMAIL
3799 KOMailClient mailClient; 3798 KOMailClient mailClient;
3800 3799
3801 Incidence *incidence = currentSelection(); 3800 Incidence *incidence = currentSelection();
3802 3801
3803 if (!incidence) { 3802 if (!incidence) {
3804 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3803 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3805 return; 3804 return;
3806 } 3805 }
3807 if(incidence->attendeeCount() == 0 ) { 3806 if(incidence->attendeeCount() == 0 ) {
3808 KMessageBox::sorry(this, 3807 KMessageBox::sorry(this,
3809 i18n("Can't generate mail:\nNo attendees defined.\n")); 3808 i18n("Can't generate mail:\nNo attendees defined.\n"));
3810 return; 3809 return;
3811 } 3810 }
3812 3811
3813 CalendarLocal cal_tmp; 3812 CalendarLocal cal_tmp;
3814 Event *event = 0; 3813 Event *event = 0;
3815 Event *ev = 0; 3814 Event *ev = 0;
3816 if ( incidence && incidence->typeID() == eventID ) { 3815 if ( incidence && incidence->typeID() == eventID ) {
3817 event = static_cast<Event *>(incidence); 3816 event = static_cast<Event *>(incidence);
3818 ev = new Event(*event); 3817 ev = new Event(*event);
3819 cal_tmp.addEvent(ev); 3818 cal_tmp.addEvent(ev);
3820 } 3819 }
3821 ICalFormat mForm(); 3820 ICalFormat mForm();
3822 QString attachment = mForm.toString( &cal_tmp ); 3821 QString attachment = mForm.toString( &cal_tmp );
3823 if (ev) delete(ev); 3822 if (ev) delete(ev);
3824 3823
3825 mailClient.mailAttendees(currentSelection(), attachment); 3824 mailClient.mailAttendees(currentSelection(), attachment);
3826 3825
3827#endif 3826#endif
3828 3827
3829#if 0 3828#if 0
3830 Event *anEvent = 0; 3829 Event *anEvent = 0;
3831 if (mViewManager->currentView()->isEventView()) { 3830 if (mViewManager->currentView()->isEventView()) {
3832 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3831 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3833 } 3832 }
3834 3833
3835 if (!anEvent) { 3834 if (!anEvent) {
3836 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3835 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3837 return; 3836 return;
3838 } 3837 }
3839 if(anEvent->attendeeCount() == 0 ) { 3838 if(anEvent->attendeeCount() == 0 ) {
3840 KMessageBox::sorry(this, 3839 KMessageBox::sorry(this,
3841 i18n("Can't generate mail:\nNo attendees defined.\n")); 3840 i18n("Can't generate mail:\nNo attendees defined.\n"));
3842 return; 3841 return;
3843 } 3842 }
3844 3843
3845 mailobject.emailEvent(anEvent); 3844 mailobject.emailEvent(anEvent);
3846#endif 3845#endif
3847} 3846}
3848 3847
3849 3848
3850void CalendarView::schedule_publish(Incidence *incidence) 3849void CalendarView::schedule_publish(Incidence *incidence)
3851{ 3850{
3852 Event *event = 0; 3851 Event *event = 0;
3853 Todo *todo = 0; 3852 Todo *todo = 0;
3854 3853
3855 if (incidence == 0) { 3854 if (incidence == 0) {
3856 incidence = mViewManager->currentView()->selectedIncidences().first(); 3855 incidence = mViewManager->currentView()->selectedIncidences().first();
3857 if (incidence == 0) { 3856 if (incidence == 0) {
3858 incidence = mTodoList->selectedIncidences().first(); 3857 incidence = mTodoList->selectedIncidences().first();
3859 } 3858 }
3860 } 3859 }
3861 if ( incidence && incidence->typeID() == eventID ) { 3860 if ( incidence && incidence->typeID() == eventID ) {
3862 event = static_cast<Event *>(incidence); 3861 event = static_cast<Event *>(incidence);
3863 } else { 3862 } else {
3864 if ( incidence && incidence->typeID() == todoID ) { 3863 if ( incidence && incidence->typeID() == todoID ) {
3865 todo = static_cast<Todo *>(incidence); 3864 todo = static_cast<Todo *>(incidence);
3866 } 3865 }
3867 } 3866 }
3868 3867
3869 if (!event && !todo) { 3868 if (!event && !todo) {
3870 KMessageBox::sorry(this,i18n("No event selected.")); 3869 KMessageBox::sorry(this,i18n("No event selected."));
3871 return; 3870 return;
3872 } 3871 }
3873 3872
3874 PublishDialog *publishdlg = new PublishDialog(); 3873 PublishDialog *publishdlg = new PublishDialog();
3875 if (incidence->attendeeCount()>0) { 3874 if (incidence->attendeeCount()>0) {
3876 QPtrList<Attendee> attendees = incidence->attendees(); 3875 QPtrList<Attendee> attendees = incidence->attendees();
3877 attendees.first(); 3876 attendees.first();
3878 while ( attendees.current()!=0 ) { 3877 while ( attendees.current()!=0 ) {
3879 publishdlg->addAttendee(attendees.current()); 3878 publishdlg->addAttendee(attendees.current());
3880 attendees.next(); 3879 attendees.next();
3881 } 3880 }
3882 } 3881 }
3883 bool send = true; 3882 bool send = true;
3884 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3883 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3885 if ( publishdlg->exec() != QDialog::Accepted ) 3884 if ( publishdlg->exec() != QDialog::Accepted )
3886 send = false; 3885 send = false;
3887 } 3886 }
3888 if ( send ) { 3887 if ( send ) {
3889 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3888 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3890 if ( event ) { 3889 if ( event ) {
3891 Event *ev = new Event(*event); 3890 Event *ev = new Event(*event);
3892 ev->registerObserver(0); 3891 ev->registerObserver(0);
3893 ev->clearAttendees(); 3892 ev->clearAttendees();
3894 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3893 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3895 delete(ev); 3894 delete(ev);
3896 } 3895 }
3897 } else { 3896 } else {
3898 if ( todo ) { 3897 if ( todo ) {
3899 Todo *ev = new Todo(*todo); 3898 Todo *ev = new Todo(*todo);
3900 ev->registerObserver(0); 3899 ev->registerObserver(0);
3901 ev->clearAttendees(); 3900 ev->clearAttendees();
3902 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3901 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3903 delete(ev); 3902 delete(ev);
3904 } 3903 }
3905 } 3904 }
3906 } 3905 }
3907 } 3906 }
3908 delete publishdlg; 3907 delete publishdlg;
3909} 3908}
3910 3909
3911void CalendarView::schedule_request(Incidence *incidence) 3910void CalendarView::schedule_request(Incidence *incidence)
3912{ 3911{
3913 schedule(Scheduler::Request,incidence); 3912 schedule(Scheduler::Request,incidence);
3914} 3913}
3915 3914
3916void CalendarView::schedule_refresh(Incidence *incidence) 3915void CalendarView::schedule_refresh(Incidence *incidence)
3917{ 3916{
3918 schedule(Scheduler::Refresh,incidence); 3917 schedule(Scheduler::Refresh,incidence);
3919} 3918}
3920 3919
3921void CalendarView::schedule_cancel(Incidence *incidence) 3920void CalendarView::schedule_cancel(Incidence *incidence)
3922{ 3921{
3923 schedule(Scheduler::Cancel,incidence); 3922 schedule(Scheduler::Cancel,incidence);
3924} 3923}
3925 3924
3926void CalendarView::schedule_add(Incidence *incidence) 3925void CalendarView::schedule_add(Incidence *incidence)
3927{ 3926{
3928 schedule(Scheduler::Add,incidence); 3927 schedule(Scheduler::Add,incidence);
3929} 3928}
3930 3929
3931void CalendarView::schedule_reply(Incidence *incidence) 3930void CalendarView::schedule_reply(Incidence *incidence)
3932{ 3931{
3933 schedule(Scheduler::Reply,incidence); 3932 schedule(Scheduler::Reply,incidence);
3934} 3933}
3935 3934
3936void CalendarView::schedule_counter(Incidence *incidence) 3935void CalendarView::schedule_counter(Incidence *incidence)
3937{ 3936{
3938 schedule(Scheduler::Counter,incidence); 3937 schedule(Scheduler::Counter,incidence);
3939} 3938}
3940 3939
3941void CalendarView::schedule_declinecounter(Incidence *incidence) 3940void CalendarView::schedule_declinecounter(Incidence *incidence)
3942{ 3941{
3943 schedule(Scheduler::Declinecounter,incidence); 3942 schedule(Scheduler::Declinecounter,incidence);
3944} 3943}
3945 3944
3946void CalendarView::schedule_publish_freebusy(int daysToPublish) 3945void CalendarView::schedule_publish_freebusy(int daysToPublish)
3947{ 3946{
3948 QDateTime start = QDateTime::currentDateTime(); 3947 QDateTime start = QDateTime::currentDateTime();
3949 QDateTime end = start.addDays(daysToPublish); 3948 QDateTime end = start.addDays(daysToPublish);
3950 3949
3951 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3950 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3952 freebusy->setOrganizer(KOPrefs::instance()->email()); 3951 freebusy->setOrganizer(KOPrefs::instance()->email());
3953 3952
3954 3953
3955 PublishDialog *publishdlg = new PublishDialog(); 3954 PublishDialog *publishdlg = new PublishDialog();
3956 if ( publishdlg->exec() == QDialog::Accepted ) { 3955 if ( publishdlg->exec() == QDialog::Accepted ) {
3957 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3956 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3958 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3957 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3959 delete(freebusy); 3958 delete(freebusy);
3960 } 3959 }
3961 } 3960 }
3962 delete publishdlg; 3961 delete publishdlg;
3963} 3962}
3964 3963
3965void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3964void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3966{ 3965{
3967 Event *event = 0; 3966 Event *event = 0;
3968 Todo *todo = 0; 3967 Todo *todo = 0;
3969 3968
3970 if (incidence == 0) { 3969 if (incidence == 0) {
3971 incidence = mViewManager->currentView()->selectedIncidences().first(); 3970 incidence = mViewManager->currentView()->selectedIncidences().first();
3972 if (incidence == 0) { 3971 if (incidence == 0) {
3973 incidence = mTodoList->selectedIncidences().first(); 3972 incidence = mTodoList->selectedIncidences().first();
3974 } 3973 }
3975 } 3974 }
3976 if ( incidence && incidence->typeID() == eventID ) { 3975 if ( incidence && incidence->typeID() == eventID ) {
3977 event = static_cast<Event *>(incidence); 3976 event = static_cast<Event *>(incidence);
3978 } 3977 }
3979 if ( incidence && incidence->typeID() == todoID ) { 3978 if ( incidence && incidence->typeID() == todoID ) {
3980 todo = static_cast<Todo *>(incidence); 3979 todo = static_cast<Todo *>(incidence);
3981 } 3980 }
3982 3981
3983 if (!event && !todo) { 3982 if (!event && !todo) {
3984 KMessageBox::sorry(this,i18n("No event selected.")); 3983 KMessageBox::sorry(this,i18n("No event selected."));
3985 return; 3984 return;
3986 } 3985 }
3987 3986
3988 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3987 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3989 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3988 KMessageBox::sorry(this,i18n("The event has no attendees."));
3990 return; 3989 return;
3991 } 3990 }
3992 3991
3993 Event *ev = 0; 3992 Event *ev = 0;
3994 if (event) ev = new Event(*event); 3993 if (event) ev = new Event(*event);
3995 Todo *to = 0; 3994 Todo *to = 0;
3996 if (todo) to = new Todo(*todo); 3995 if (todo) to = new Todo(*todo);
3997 3996
3998 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3997 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3999 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3998 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
4000 if (!me) { 3999 if (!me) {
4001 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 4000 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
4002 return; 4001 return;
4003 } 4002 }
4004 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 4003 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
4005 StatusDialog *statdlg = new StatusDialog(this); 4004 StatusDialog *statdlg = new StatusDialog(this);
4006 if (!statdlg->exec()==QDialog::Accepted) return; 4005 if (!statdlg->exec()==QDialog::Accepted) return;
4007 me->setStatus( statdlg->status() ); 4006 me->setStatus( statdlg->status() );
4008 delete(statdlg); 4007 delete(statdlg);
4009 } 4008 }
4010 Attendee *menew = new Attendee(*me); 4009 Attendee *menew = new Attendee(*me);
4011 if (ev) { 4010 if (ev) {
4012 ev->clearAttendees(); 4011 ev->clearAttendees();
4013 ev->addAttendee(menew,false); 4012 ev->addAttendee(menew,false);
4014 } else { 4013 } else {
4015 if (to) { 4014 if (to) {
4016 todo->clearAttendees(); 4015 todo->clearAttendees();
4017 todo->addAttendee(menew,false); 4016 todo->addAttendee(menew,false);
4018 } 4017 }
4019 } 4018 }
4020 } 4019 }
4021 4020
4022 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 4021 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
4023 if (ev) { 4022 if (ev) {
4024 if ( !dlg->addMessage(ev,method) ) delete(ev); 4023 if ( !dlg->addMessage(ev,method) ) delete(ev);
4025 } else { 4024 } else {
4026 if (to) { 4025 if (to) {
4027 if ( !dlg->addMessage(to,method) ) delete(to); 4026 if ( !dlg->addMessage(to,method) ) delete(to);
4028 } 4027 }
4029 } 4028 }
4030} 4029}
4031 4030
4032void CalendarView::openAddressbook() 4031void CalendarView::openAddressbook()
4033{ 4032{
4034 KRun::runCommand("kaddressbook"); 4033 KRun::runCommand("kaddressbook");
4035} 4034}
4036 4035
4037void CalendarView::setModified(bool modified) 4036void CalendarView::setModified(bool modified)
4038{ 4037{
4039 if ( modified ) 4038 if ( modified )
4040 emit signalmodified(); 4039 emit signalmodified();
4041 if (mModified != modified) { 4040 if (mModified != modified) {
4042 mModified = modified; 4041 mModified = modified;
4043 emit modifiedChanged(mModified); 4042 emit modifiedChanged(mModified);
4044 } 4043 }
4045} 4044}
4046 4045
4047bool CalendarView::isReadOnly() 4046bool CalendarView::isReadOnly()
4048{ 4047{
4049 return mReadOnly; 4048 return mReadOnly;
4050} 4049}
4051 4050
4052void CalendarView::setReadOnly(bool readOnly) 4051void CalendarView::setReadOnly(bool readOnly)
4053{ 4052{
4054 if (mReadOnly != readOnly) { 4053 if (mReadOnly != readOnly) {
4055 mReadOnly = readOnly; 4054 mReadOnly = readOnly;
4056 emit readOnlyChanged(mReadOnly); 4055 emit readOnlyChanged(mReadOnly);
4057 } 4056 }
4058} 4057}
4059 4058
4060bool CalendarView::isModified() 4059bool CalendarView::isModified()
4061{ 4060{
4062 return mModified; 4061 return mModified;
4063} 4062}
4064void CalendarView::slotprintSelInc() 4063void CalendarView::slotprintSelInc()
4065{ 4064{
4066 if ( currentSelection() == 0 ) { 4065 if ( currentSelection() == 0 ) {
4067 KMessageBox::sorry(this,i18n("There is nothing selected!")); 4066 KMessageBox::sorry(this,i18n("There is nothing selected!"));
4068 return; 4067 return;
4069 } 4068 }
4070 showIncidence(); 4069 showIncidence();
4071 getEventViewerDialog()->print(); 4070 getEventViewerDialog()->print();
4072 4071
4073} 4072}
4074void CalendarView::printSetup() 4073void CalendarView::printSetup()
4075{ 4074{
4076#ifndef KORG_NOPRINTER 4075#ifndef KORG_NOPRINTER
4077 createPrinter(); 4076 createPrinter();
4078 4077
4079 mCalPrinter->setupPrinter(); 4078 mCalPrinter->setupPrinter();
4080#endif 4079#endif
4081} 4080}
4082 4081
4083void CalendarView::print() 4082void CalendarView::print()
4084{ 4083{
4085#ifndef KORG_NOPRINTER 4084#ifndef KORG_NOPRINTER
4086 createPrinter(); 4085 createPrinter();
4087 4086
4088 DateList tmpDateList = mNavigator->selectedDates(); 4087 DateList tmpDateList = mNavigator->selectedDates();
4089 mCalPrinter->print(CalPrinter::Month, 4088 mCalPrinter->print(CalPrinter::Month,
4090 tmpDateList.first(), tmpDateList.last()); 4089 tmpDateList.first(), tmpDateList.last());
4091#endif 4090#endif
4092} 4091}
4093 4092
4094void CalendarView::printPreview() 4093void CalendarView::printPreview()
4095{ 4094{
4096#ifndef KORG_NOPRINTER 4095#ifndef KORG_NOPRINTER
4097 kdDebug() << "CalendarView::printPreview()" << endl; 4096 kdDebug() << "CalendarView::printPreview()" << endl;
4098 4097
4099 createPrinter(); 4098 createPrinter();
4100 4099
4101 DateList tmpDateList = mNavigator->selectedDates(); 4100 DateList tmpDateList = mNavigator->selectedDates();
4102 4101
4103 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 4102 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
4104 tmpDateList.last()); 4103 tmpDateList.last());
4105#endif 4104#endif
4106} 4105}
4107 4106
4108void CalendarView::exportICalendar() 4107void CalendarView::exportICalendar()
4109{ 4108{
4110 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 4109 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
4111 4110
4112 // Force correct extension 4111 // Force correct extension
4113 if (filename.right(4) != ".ics") filename += ".ics"; 4112 if (filename.right(4) != ".ics") filename += ".ics";
4114 4113
4115 FileStorage storage( mCalendar, filename, new ICalFormat() ); 4114 FileStorage storage( mCalendar, filename, new ICalFormat() );
4116 storage.save(); 4115 storage.save();
4117} 4116}
4118 4117
4119bool CalendarView::exportVCalendar( QString filename ) 4118bool CalendarView::exportVCalendar( QString filename )
4120{ 4119{
4121 if (mCalendar->journals().count() > 0) { 4120 if (mCalendar->journals().count() > 0) {
4122 int result = KMessageBox::warningContinueCancel(this, 4121 int result = KMessageBox::warningContinueCancel(this,
4123 i18n("The journal entries can not be\nexported to a vCalendar file."), 4122 i18n("The journal entries can not be\nexported to a vCalendar file."),
4124 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 4123 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
4125 true); 4124 true);
4126 if (result != KMessageBox::Continue) return false; 4125 if (result != KMessageBox::Continue) return false;
4127 } 4126 }
4128 4127
4129 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 4128 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
4130 4129
4131 // Force correct extension 4130 // Force correct extension
4132 if (filename.right(4) != ".vcs") filename += ".vcs"; 4131 if (filename.right(4) != ".vcs") filename += ".vcs";
4133 4132
4134 FileStorage storage( mCalendar, filename, new VCalFormat ); 4133 FileStorage storage( mCalendar, filename, new VCalFormat );
4135 return storage.save(); 4134 return storage.save();
4136 4135
4137} 4136}
4138 4137
4139void CalendarView::eventUpdated(Incidence *) 4138void CalendarView::eventUpdated(Incidence *)
4140{ 4139{
4141 setModified(); 4140 setModified();
4142 // Don't call updateView here. The code, which has caused the update of the 4141 // Don't call updateView here. The code, which has caused the update of the
4143 // event is responsible for updating the view. 4142 // event is responsible for updating the view.
4144 // updateView(); 4143 // updateView();
4145} 4144}
4146 4145
4147void CalendarView::adaptNavigationUnits() 4146void CalendarView::adaptNavigationUnits()
4148{ 4147{
4149 if (mViewManager->currentView()->isEventView()) { 4148 if (mViewManager->currentView()->isEventView()) {
4150 int days = mViewManager->currentView()->currentDateCount(); 4149 int days = mViewManager->currentView()->currentDateCount();
4151 if (days == 1) { 4150 if (days == 1) {
4152 emit changeNavStringPrev(i18n("&Previous Day")); 4151 emit changeNavStringPrev(i18n("&Previous Day"));
4153 emit changeNavStringNext(i18n("&Next Day")); 4152 emit changeNavStringNext(i18n("&Next Day"));
4154 } else { 4153 } else {
4155 emit changeNavStringPrev(i18n("&Previous Week")); 4154 emit changeNavStringPrev(i18n("&Previous Week"));
4156 emit changeNavStringNext(i18n("&Next Week")); 4155 emit changeNavStringNext(i18n("&Next Week"));
4157 } 4156 }
4158 } 4157 }
4159} 4158}
4160 4159
4161void CalendarView::processMainViewSelection( Incidence *incidence ) 4160void CalendarView::processMainViewSelection( Incidence *incidence )
4162{ 4161{
4163 if ( incidence ) mTodoList->clearSelection(); 4162 if ( incidence ) mTodoList->clearSelection();
4164 processIncidenceSelection( incidence ); 4163 processIncidenceSelection( incidence );
4165} 4164}
4166 4165
4167void CalendarView::processTodoListSelection( Incidence *incidence ) 4166void CalendarView::processTodoListSelection( Incidence *incidence )
4168{ 4167{
4169 if ( incidence && mViewManager->currentView() ) { 4168 if ( incidence && mViewManager->currentView() ) {
4170 mViewManager->currentView()->clearSelection(); 4169 mViewManager->currentView()->clearSelection();
4171 } 4170 }
4172 processIncidenceSelection( incidence ); 4171 processIncidenceSelection( incidence );
4173} 4172}
4174 4173
4175void CalendarView::processIncidenceSelection( Incidence *incidence ) 4174void CalendarView::processIncidenceSelection( Incidence *incidence )
4176{ 4175{
4177 emit incidenceSelected( incidence ); 4176 emit incidenceSelected( incidence );
4178 if ( incidence == mSelectedIncidence ) return; 4177 if ( incidence == mSelectedIncidence ) return;
4179 mSelectedIncidence = incidence; 4178 mSelectedIncidence = incidence;
4180 4179
4181 if ( incidence && incidence->typeID() == eventID ) { 4180 if ( incidence && incidence->typeID() == eventID ) {
4182 Event *event = static_cast<Event *>( incidence ); 4181 Event *event = static_cast<Event *>( incidence );
4183 if ( event->organizer() == KOPrefs::instance()->email() ) { 4182 if ( event->organizer() == KOPrefs::instance()->email() ) {
4184 emit organizerEventsSelected( true ); 4183 emit organizerEventsSelected( true );
4185 } else { 4184 } else {
4186 emit organizerEventsSelected(false); 4185 emit organizerEventsSelected(false);
4187 } 4186 }
4188 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 4187 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
4189 KOPrefs::instance()->email() ) ) { 4188 KOPrefs::instance()->email() ) ) {
4190 emit groupEventsSelected( true ); 4189 emit groupEventsSelected( true );
4191 } else { 4190 } else {
4192 emit groupEventsSelected(false); 4191 emit groupEventsSelected(false);
4193 } 4192 }
4194 return; 4193 return;
4195 } else { 4194 } else {
4196 if ( incidence && incidence->typeID() == todoID ) { 4195 if ( incidence && incidence->typeID() == todoID ) {
4197 emit todoSelected( true ); 4196 emit todoSelected( true );
4198 Todo *event = static_cast<Todo *>( incidence ); 4197 Todo *event = static_cast<Todo *>( incidence );
4199 if ( event->organizer() == KOPrefs::instance()->email() ) { 4198 if ( event->organizer() == KOPrefs::instance()->email() ) {
4200 emit organizerEventsSelected( true ); 4199 emit organizerEventsSelected( true );
4201 } else { 4200 } else {
4202 emit organizerEventsSelected(false); 4201 emit organizerEventsSelected(false);
4203 } 4202 }
4204 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 4203 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
4205 KOPrefs::instance()->email() ) ) { 4204 KOPrefs::instance()->email() ) ) {
4206 emit groupEventsSelected( true ); 4205 emit groupEventsSelected( true );
4207 } else { 4206 } else {
4208 emit groupEventsSelected(false); 4207 emit groupEventsSelected(false);
4209 } 4208 }
4210 return; 4209 return;
4211 } else { 4210 } else {
4212 emit todoSelected( false ); 4211 emit todoSelected( false );
4213 emit organizerEventsSelected(false); 4212 emit organizerEventsSelected(false);
4214 emit groupEventsSelected(false); 4213 emit groupEventsSelected(false);
4215 } 4214 }
4216 return; 4215 return;
4217 } 4216 }
4218 4217
4219 /* if ( incidence && incidence->typeID() == todoID ) { 4218 /* if ( incidence && incidence->typeID() == todoID ) {
4220 emit todoSelected( true ); 4219 emit todoSelected( true );
4221 } else { 4220 } else {
4222 emit todoSelected( false ); 4221 emit todoSelected( false );
4223 }*/ 4222 }*/
4224} 4223}
4225 4224
4226 4225
4227void CalendarView::checkClipboard() 4226void CalendarView::checkClipboard()
4228{ 4227{
4229#ifndef KORG_NODND 4228#ifndef KORG_NODND
4230 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 4229 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
4231 emit pasteEnabled(true); 4230 emit pasteEnabled(true);
4232 } else { 4231 } else {
4233 emit pasteEnabled(false); 4232 emit pasteEnabled(false);
4234 } 4233 }
4235#endif 4234#endif
4236} 4235}
4237 4236
4238void CalendarView::showDates(const DateList &selectedDates) 4237void CalendarView::showDates(const DateList &selectedDates)
4239{ 4238{
4240 // kdDebug() << "CalendarView::selectDates()" << endl; 4239 // kdDebug() << "CalendarView::selectDates()" << endl;
4241 4240
4242 4241
4243 if ( !mBlockShowDates ) { 4242 if ( !mBlockShowDates ) {
4244 if ( mViewManager->currentView() ) { 4243 if ( mViewManager->currentView() ) {
4245 updateView( selectedDates.first(), selectedDates.last() ); 4244 updateView( selectedDates.first(), selectedDates.last() );
4246 } else { 4245 } else {
4247 mViewManager->showAgendaView(); 4246 mViewManager->showAgendaView();
4248 } 4247 }
4249 } 4248 }
4250 4249
4251 QDate date = selectedDates.first(); 4250 QDate date = selectedDates.first();
4252 if ( ! date.isValid() ) { 4251 if ( ! date.isValid() ) {
4253 topLevelWidget()->setCaption(""); 4252 topLevelWidget()->setCaption("");
4254 return; 4253 return;
4255 } 4254 }
4256 4255
4257 QString selDates; 4256 QString selDates;
4258 selDates = KGlobal::locale()->formatDate( date, true); 4257 selDates = KGlobal::locale()->formatDate( date, true);
4259 if (selectedDates.first() < selectedDates.last() ) 4258 if (selectedDates.first() < selectedDates.last() )
4260 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 4259 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
4261 else { 4260 else {
4262 QString addString; 4261 QString addString;
4263 if ( date == QDateTime::currentDateTime().date() ) 4262 if ( date == QDateTime::currentDateTime().date() )
4264 addString = i18n("Today"); 4263 addString = i18n("Today");
4265 else if ( date == QDateTime::currentDateTime().date().addDays(1) ) 4264 else if ( date == QDateTime::currentDateTime().date().addDays(1) )
4266 addString = i18n("Tomorrow"); 4265 addString = i18n("Tomorrow");
4267 else if ( date == QDateTime::currentDateTime().date().addDays(-1) ) 4266 else if ( date == QDateTime::currentDateTime().date().addDays(-1) )
4268 addString = i18n("Yesterday"); 4267 addString = i18n("Yesterday");
4269 else if ( date == QDateTime::currentDateTime().date().addDays(-2) ) 4268 else if ( date == QDateTime::currentDateTime().date().addDays(-2) )
4270 addString = i18n("Day before yesterday"); 4269 addString = i18n("Day before yesterday");
4271 else if ( date == QDateTime::currentDateTime().date().addDays(2) ) 4270 else if ( date == QDateTime::currentDateTime().date().addDays(2) )
4272 addString = i18n("Day after tomorrow"); 4271 addString = i18n("Day after tomorrow");
4273 if ( !addString.isEmpty() ) { 4272 if ( !addString.isEmpty() ) {
4274 topLevelWidget()->setCaption( addString+", " + selDates ); 4273 topLevelWidget()->setCaption( addString+", " + selDates );
4275 return; 4274 return;
4276 } 4275 }
4277 } 4276 }
4278 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 4277 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
4279 4278
4280} 4279}
4281 4280
4282QPtrList<CalFilter> CalendarView::filters() 4281QPtrList<CalFilter> CalendarView::filters()
4283{ 4282{
4284 return mFilters; 4283 return mFilters;
4285 4284
4286} 4285}
4287void CalendarView::editFilters() 4286void CalendarView::editFilters()
4288{ 4287{
4289 // kdDebug() << "CalendarView::editFilters()" << endl; 4288 // kdDebug() << "CalendarView::editFilters()" << endl;
4290 4289
4291 CalFilter *filter = mFilters.first(); 4290 CalFilter *filter = mFilters.first();
4292 while(filter) { 4291 while(filter) {
4293 filter = mFilters.next(); 4292 filter = mFilters.next();
4294 } 4293 }
4295 4294
4296 mDialogManager->showFilterEditDialog(&mFilters); 4295 mDialogManager->showFilterEditDialog(&mFilters);
4297 updateFilter(); 4296 updateFilter();
4298} 4297}
4299void CalendarView::toggleFilter() 4298void CalendarView::toggleFilter()
4300{ 4299{
4301 if ( mLeftFrame->isHidden() ) { 4300 if ( mLeftFrame->isHidden() ) {
4302 toggleExpand(); 4301 toggleExpand();
4303 showFilter( true ); 4302 showFilter( true );
4304 } else 4303 } else
4305 showFilter(! mCalEditView->isVisible()); 4304 showFilter(! mCalEditView->isVisible());
4306} 4305}
4307 4306
4308KOFilterView *CalendarView::filterView() 4307KOFilterView *CalendarView::filterView()
4309{ 4308{
4310 return mFilterView; 4309 return mFilterView;
4311} 4310}
4312void CalendarView::selectFilter( int fil ) 4311void CalendarView::selectFilter( int fil )
4313{ 4312{
4314 mFilterView->setSelectedFilter( fil ); 4313 mFilterView->setSelectedFilter( fil );
4315 updateUnmanagedViews(); 4314 updateUnmanagedViews();
4316} 4315}
4317void CalendarView::showFilter(bool visible) 4316void CalendarView::showFilter(bool visible)
4318{ 4317{
4319#if 1 4318#if 1
4320 if (visible) { 4319 if (visible) {
4321 mCalEditView->readConfig(); 4320 mCalEditView->readConfig();
4322 mCalEditView->show(); 4321 mCalEditView->show();
4323 QValueList<int> sizes; 4322 QValueList<int> sizes;
4324 sizes = mLeftFrame->sizes(); 4323 sizes = mLeftFrame->sizes();
4325 if ( sizes.count() == 4 && sizes[3] < 20 ) { 4324 if ( sizes.count() == 4 && sizes[3] < 20 ) {
4326 sizes.clear(); 4325 sizes.clear();
4327 sizes << 100; 4326 sizes << 100;
4328 sizes << 0; 4327 sizes << 0;
4329 sizes << 0; 4328 sizes << 0;
4330 sizes << 100; 4329 sizes << 100;