summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp44
-rw-r--r--libkcal/calendarlocal.cpp27
2 files changed, 41 insertions, 30 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 1800cf2..8385bcc 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1222,1785 +1222,1787 @@ void CalendarView::computeAlarm( QString msg )
1222 return; 1222 return;
1223#endif 1223#endif
1224 1224
1225 return; 1225 return;
1226 } 1226 }
1227 1227
1228 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 1228 //qDebug("+++++++system command %s ",tempfilename.latin1() );
1229 } 1229 }
1230 if ( mess.left( 11 ) == "audio_alarm") { 1230 if ( mess.left( 11 ) == "audio_alarm") {
1231 bool error = false; 1231 bool error = false;
1232 int len = mess.mid( 11 ).find("+++"); 1232 int len = mess.mid( 11 ).find("+++");
1233 if ( len < 2 ) 1233 if ( len < 2 )
1234 error = true; 1234 error = true;
1235 else { 1235 else {
1236 tempfilename = mess.mid( 11, len ); 1236 tempfilename = mess.mid( 11, len );
1237 if ( !QFile::exists( tempfilename ) ) 1237 if ( !QFile::exists( tempfilename ) )
1238 error = true; 1238 error = true;
1239 } 1239 }
1240 if ( ! error ) { 1240 if ( ! error ) {
1241 filename = tempfilename; 1241 filename = tempfilename;
1242 } 1242 }
1243 mAlarmMessage = mess.mid( 11+len+3+9 ); 1243 mAlarmMessage = mess.mid( 11+len+3+9 );
1244 //qDebug("audio file command %s ",tempfilename.latin1() ); 1244 //qDebug("audio file command %s ",tempfilename.latin1() );
1245 } 1245 }
1246 if ( mess.left( 9 ) == "cal_alarm") { 1246 if ( mess.left( 9 ) == "cal_alarm") {
1247 mAlarmMessage = mess.mid( 9 ) ; 1247 mAlarmMessage = mess.mid( 9 ) ;
1248 } 1248 }
1249 1249
1250 startAlarm( mAlarmMessage, filename ); 1250 startAlarm( mAlarmMessage, filename );
1251 1251
1252 1252
1253} 1253}
1254 1254
1255void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 1255void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
1256{ 1256{
1257 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1257 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1258 1258
1259 mSuspendAlarmNotification = noti; 1259 mSuspendAlarmNotification = noti;
1260 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 1260 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
1261 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 1261 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
1262 mSuspendTimer->start( ms , true ); 1262 mSuspendTimer->start( ms , true );
1263#ifdef DESKTOP_VERSION 1263#ifdef DESKTOP_VERSION
1264 if ( QApplication::desktop()->width() < 1024 ) { 1264 if ( QApplication::desktop()->width() < 1024 ) {
1265 QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti; 1265 QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti;
1266 //qDebug("nextsuspendalarm = \n%s ",mess.latin1() ); 1266 //qDebug("nextsuspendalarm = \n%s ",mess.latin1() );
1267 QString fn = QDir::homeDirPath() + "/.kopi_suspend_alarm"; 1267 QString fn = QDir::homeDirPath() + "/.kopi_suspend_alarm";
1268 QFile file( fn ); 1268 QFile file( fn );
1269 if (!file.open( IO_WriteOnly ) ) { 1269 if (!file.open( IO_WriteOnly ) ) {
1270 qDebug("KO: Error writing next suspend alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1()); 1270 qDebug("KO: Error writing next suspend alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1());
1271 } else { 1271 } else {
1272 QTextStream ts( &file ); 1272 QTextStream ts( &file );
1273 ts << mess; 1273 ts << mess;
1274 file.close(); 1274 file.close();
1275 } 1275 }
1276 } 1276 }
1277#endif 1277#endif
1278 1278
1279} 1279}
1280 1280
1281void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 1281void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
1282{ 1282{
1283 mNextAlarmDateTime = qdt; 1283 mNextAlarmDateTime = qdt;
1284 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1284 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1285 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1285 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1286#ifndef DESKTOP_VERSION 1286#ifndef DESKTOP_VERSION
1287 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); 1287 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
1288#endif 1288#endif
1289 return; 1289 return;
1290 } 1290 }
1291#ifdef DESKTOP_VERSION 1291#ifdef DESKTOP_VERSION
1292 if ( QApplication::desktop()->width() < 1024 ) { 1292 if ( QApplication::desktop()->width() < 1024 ) {
1293 QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti; 1293 QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti;
1294 //qDebug("nextalarm = \n%s ",mess.latin1() ); 1294 //qDebug("nextalarm = \n%s ",mess.latin1() );
1295 QString fn = QDir::homeDirPath() + "/.kopi_next_alarm"; 1295 QString fn = QDir::homeDirPath() + "/.kopi_next_alarm";
1296 QFile file( fn ); 1296 QFile file( fn );
1297 if (!file.open( IO_WriteOnly ) ) { 1297 if (!file.open( IO_WriteOnly ) ) {
1298 qDebug("KO: Error writing next alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1()); 1298 qDebug("KO: Error writing next alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1());
1299 } else { 1299 } else {
1300 QTextStream ts( &file ); 1300 QTextStream ts( &file );
1301 ts << mess; 1301 ts << mess;
1302 file.close(); 1302 file.close();
1303 } 1303 }
1304 } 1304 }
1305#endif 1305#endif
1306 int maxSec; 1306 int maxSec;
1307 //maxSec = 5; //testing only 1307 //maxSec = 5; //testing only
1308 maxSec = 86400+3600; // one day+1hour 1308 maxSec = 86400+3600; // one day+1hour
1309 mAlarmNotification = noti; 1309 mAlarmNotification = noti;
1310 int sec = QDateTime::currentDateTime().secsTo( qdt ); 1310 int sec = QDateTime::currentDateTime().secsTo( qdt );
1311 if ( sec > maxSec ) { 1311 if ( sec > maxSec ) {
1312 mRecheckAlarmTimer->start( maxSec * 1000 ); 1312 mRecheckAlarmTimer->start( maxSec * 1000 );
1313 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 1313 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
1314 return; 1314 return;
1315 } else { 1315 } else {
1316 mRecheckAlarmTimer->stop(); 1316 mRecheckAlarmTimer->stop();
1317 } 1317 }
1318 //qDebug("Alarm timer started with secs: %d ", sec); 1318 //qDebug("Alarm timer started with secs: %d ", sec);
1319 mAlarmTimer->start( sec * 1000 , true ); 1319 mAlarmTimer->start( sec * 1000 , true );
1320 1320
1321} 1321}
1322// called by mRecheckAlarmTimer to get next alarm 1322// called by mRecheckAlarmTimer to get next alarm
1323// we need this, because a QTimer has only a max range of 25 days 1323// we need this, because a QTimer has only a max range of 25 days
1324void CalendarView::recheckTimerAlarm() 1324void CalendarView::recheckTimerAlarm()
1325{ 1325{
1326 mAlarmTimer->stop(); 1326 mAlarmTimer->stop();
1327 mRecheckAlarmTimer->stop(); 1327 mRecheckAlarmTimer->stop();
1328 mCalendar->checkAlarmForIncidence( 0, true ); 1328 mCalendar->checkAlarmForIncidence( 0, true );
1329} 1329}
1330#ifndef DESKTOP_VERSION 1330#ifndef DESKTOP_VERSION
1331void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 1331void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
1332#else 1332#else
1333void CalendarView::removeAlarm(const QDateTime &, const QString & ) 1333void CalendarView::removeAlarm(const QDateTime &, const QString & )
1334#endif 1334#endif
1335{ 1335{
1336 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1336 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1337 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1337 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1338#ifndef DESKTOP_VERSION 1338#ifndef DESKTOP_VERSION
1339 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); 1339 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() );
1340#endif 1340#endif
1341 return; 1341 return;
1342 } 1342 }
1343 mAlarmTimer->stop(); 1343 mAlarmTimer->stop();
1344} 1344}
1345void CalendarView::selectWeekNum ( int num ) 1345void CalendarView::selectWeekNum ( int num )
1346{ 1346{
1347 dateNavigator()->blockSignals( true ); 1347 dateNavigator()->blockSignals( true );
1348 dateNavigator()->selectWeek( num ); 1348 dateNavigator()->selectWeek( num );
1349 dateNavigator()->blockSignals( false ); 1349 dateNavigator()->blockSignals( false );
1350 mViewManager->showWeekView(); 1350 mViewManager->showWeekView();
1351} 1351}
1352KOViewManager *CalendarView::viewManager() 1352KOViewManager *CalendarView::viewManager()
1353{ 1353{
1354 return mViewManager; 1354 return mViewManager;
1355} 1355}
1356 1356
1357KODialogManager *CalendarView::dialogManager() 1357KODialogManager *CalendarView::dialogManager()
1358{ 1358{
1359 return mDialogManager; 1359 return mDialogManager;
1360} 1360}
1361 1361
1362QDate CalendarView::startDate() 1362QDate CalendarView::startDate()
1363{ 1363{
1364 DateList dates = mNavigator->selectedDates(); 1364 DateList dates = mNavigator->selectedDates();
1365 1365
1366 return dates.first(); 1366 return dates.first();
1367} 1367}
1368 1368
1369QDate CalendarView::endDate() 1369QDate CalendarView::endDate()
1370{ 1370{
1371 DateList dates = mNavigator->selectedDates(); 1371 DateList dates = mNavigator->selectedDates();
1372 1372
1373 return dates.last(); 1373 return dates.last();
1374} 1374}
1375 1375
1376 1376
1377void CalendarView::createPrinter() 1377void CalendarView::createPrinter()
1378{ 1378{
1379#ifndef KORG_NOPRINTER 1379#ifndef KORG_NOPRINTER
1380 if (!mCalPrinter) { 1380 if (!mCalPrinter) {
1381 mCalPrinter = new CalPrinter(this, mCalendar); 1381 mCalPrinter = new CalPrinter(this, mCalendar);
1382 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 1382 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
1383 } 1383 }
1384#endif 1384#endif
1385} 1385}
1386 1386
1387 1387
1388//KOPrefs::instance()->mWriteBackFile 1388//KOPrefs::instance()->mWriteBackFile
1389//KOPrefs::instance()->mWriteBackExistingOnly 1389//KOPrefs::instance()->mWriteBackExistingOnly
1390 1390
1391// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 1391// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
1392// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 1392// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
1393// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 1393// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
1394// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 1394// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
1395// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 1395// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
1396// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 1396// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
1397 1397
1398int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 1398int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
1399{ 1399{
1400 1400
1401 // 0 equal 1401 // 0 equal
1402 // 1 take local 1402 // 1 take local
1403 // 2 take remote 1403 // 2 take remote
1404 // 3 cancel 1404 // 3 cancel
1405 QDateTime lastSync = mLastCalendarSync; 1405 QDateTime lastSync = mLastCalendarSync;
1406 QDateTime localMod = local->lastModified(); 1406 QDateTime localMod = local->lastModified();
1407 QDateTime remoteMod = remote->lastModified(); 1407 QDateTime remoteMod = remote->lastModified();
1408 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1408 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1409 bool remCh, locCh; 1409 bool remCh, locCh;
1410 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 1410 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
1411 //if ( remCh ) 1411 //if ( remCh )
1412 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 1412 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
1413 locCh = ( localMod > mLastCalendarSync ); 1413 locCh = ( localMod > mLastCalendarSync );
1414 if ( !remCh && ! locCh ) { 1414 if ( !remCh && ! locCh ) {
1415 //qDebug("both not changed "); 1415 //qDebug("both not changed ");
1416 lastSync = localMod.addDays(1); 1416 lastSync = localMod.addDays(1);
1417 if ( mode <= SYNC_PREF_ASK ) 1417 if ( mode <= SYNC_PREF_ASK )
1418 return 0; 1418 return 0;
1419 } else { 1419 } else {
1420 if ( locCh ) { 1420 if ( locCh ) {
1421 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 1421 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
1422 lastSync = localMod.addDays( -1 ); 1422 lastSync = localMod.addDays( -1 );
1423 if ( !remCh ) 1423 if ( !remCh )
1424 remoteMod = ( lastSync.addDays( -1 ) ); 1424 remoteMod = ( lastSync.addDays( -1 ) );
1425 } else { 1425 } else {
1426 //qDebug(" not loc changed "); 1426 //qDebug(" not loc changed ");
1427 lastSync = localMod.addDays( 1 ); 1427 lastSync = localMod.addDays( 1 );
1428 if ( remCh ) 1428 if ( remCh )
1429 remoteMod =( lastSync.addDays( 1 ) ); 1429 remoteMod =( lastSync.addDays( 1 ) );
1430 1430
1431 } 1431 }
1432 } 1432 }
1433 full = true; 1433 full = true;
1434 if ( mode < SYNC_PREF_ASK ) 1434 if ( mode < SYNC_PREF_ASK )
1435 mode = SYNC_PREF_ASK; 1435 mode = SYNC_PREF_ASK;
1436 } else { 1436 } else {
1437 if ( localMod == remoteMod ) 1437 if ( localMod == remoteMod )
1438 // if ( local->revision() == remote->revision() ) 1438 // if ( local->revision() == remote->revision() )
1439 return 0; 1439 return 0;
1440 1440
1441 } 1441 }
1442 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 1442 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
1443 1443
1444 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 1444 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
1445 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 1445 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
1446 //full = true; //debug only 1446 //full = true; //debug only
1447 if ( full ) { 1447 if ( full ) {
1448 bool equ = false; 1448 bool equ = false;
1449 if ( local->typeID() == eventID ) { 1449 if ( local->typeID() == eventID ) {
1450 equ = (*((Event*) local) == *((Event*) remote)); 1450 equ = (*((Event*) local) == *((Event*) remote));
1451 } 1451 }
1452 else if ( local->typeID() == todoID ) 1452 else if ( local->typeID() == todoID )
1453 equ = (*((Todo*) local) == (*(Todo*) remote)); 1453 equ = (*((Todo*) local) == (*(Todo*) remote));
1454 else if ( local->typeID() == journalID ) 1454 else if ( local->typeID() == journalID )
1455 equ = (*((Journal*) local) == *((Journal*) remote)); 1455 equ = (*((Journal*) local) == *((Journal*) remote));
1456 if ( equ ) { 1456 if ( equ ) {
1457 //qDebug("equal "); 1457 //qDebug("equal ");
1458 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1458 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1459 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 1459 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
1460 } 1460 }
1461 if ( mode < SYNC_PREF_FORCE_LOCAL ) 1461 if ( mode < SYNC_PREF_FORCE_LOCAL )
1462 return 0; 1462 return 0;
1463 1463
1464 }//else //debug only 1464 }//else //debug only
1465 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 1465 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
1466 } 1466 }
1467 int result; 1467 int result;
1468 bool localIsNew; 1468 bool localIsNew;
1469 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 1469 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
1470 1470
1471 1471
1472 // ************************************************ 1472 // ************************************************
1473 // ************************************************ 1473 // ************************************************
1474 // ************************************************ 1474 // ************************************************
1475 // We may have that lastSync > remoteMod AND lastSync > localMod 1475 // We may have that lastSync > remoteMod AND lastSync > localMod
1476 // BUT remoteMod != localMod 1476 // BUT remoteMod != localMod
1477 1477
1478 1478
1479 if ( full && mode < SYNC_PREF_NEWEST ) 1479 if ( full && mode < SYNC_PREF_NEWEST )
1480 mode = SYNC_PREF_ASK; 1480 mode = SYNC_PREF_ASK;
1481 1481
1482 switch( mode ) { 1482 switch( mode ) {
1483 case SYNC_PREF_LOCAL: 1483 case SYNC_PREF_LOCAL:
1484 if ( lastSync > remoteMod ) 1484 if ( lastSync > remoteMod )
1485 return 1; 1485 return 1;
1486 if ( lastSync > localMod ) 1486 if ( lastSync > localMod )
1487 return 2; 1487 return 2;
1488 return 1; 1488 return 1;
1489 break; 1489 break;
1490 case SYNC_PREF_REMOTE: 1490 case SYNC_PREF_REMOTE:
1491 if ( lastSync > localMod ) 1491 if ( lastSync > localMod )
1492 return 2; 1492 return 2;
1493 if ( lastSync > remoteMod ) 1493 if ( lastSync > remoteMod )
1494 return 1; 1494 return 1;
1495 return 2; 1495 return 2;
1496 break; 1496 break;
1497 case SYNC_PREF_NEWEST: 1497 case SYNC_PREF_NEWEST:
1498 if ( localMod >= remoteMod ) 1498 if ( localMod >= remoteMod )
1499 return 1; 1499 return 1;
1500 else 1500 else
1501 return 2; 1501 return 2;
1502 break; 1502 break;
1503 case SYNC_PREF_ASK: 1503 case SYNC_PREF_ASK:
1504 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1504 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1505 if ( lastSync > remoteMod && lastSync > localMod) 1505 if ( lastSync > remoteMod && lastSync > localMod)
1506 return 0; 1506 return 0;
1507 if ( lastSync > remoteMod ) 1507 if ( lastSync > remoteMod )
1508 return 1; 1508 return 1;
1509 if ( lastSync > localMod ) 1509 if ( lastSync > localMod )
1510 return 2; 1510 return 2;
1511 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1511 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1512 localIsNew = localMod >= remoteMod; 1512 localIsNew = localMod >= remoteMod;
1513 if ( localIsNew ) 1513 if ( localIsNew )
1514 getEventViewerDialog()->setColorMode( 1 ); 1514 getEventViewerDialog()->setColorMode( 1 );
1515 else 1515 else
1516 getEventViewerDialog()->setColorMode( 2 ); 1516 getEventViewerDialog()->setColorMode( 2 );
1517 getEventViewerDialog()->setIncidence(local); 1517 getEventViewerDialog()->setIncidence(local);
1518 if ( localIsNew ) 1518 if ( localIsNew )
1519 getEventViewerDialog()->setColorMode( 2 ); 1519 getEventViewerDialog()->setColorMode( 2 );
1520 else 1520 else
1521 getEventViewerDialog()->setColorMode( 1 ); 1521 getEventViewerDialog()->setColorMode( 1 );
1522 getEventViewerDialog()->addIncidence(remote); 1522 getEventViewerDialog()->addIncidence(remote);
1523 getEventViewerDialog()->setColorMode( 0 ); 1523 getEventViewerDialog()->setColorMode( 0 );
1524 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1524 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1525 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1525 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1526 getEventViewerDialog()->showMe(); 1526 getEventViewerDialog()->showMe();
1527 result = getEventViewerDialog()->executeS( localIsNew ); 1527 result = getEventViewerDialog()->executeS( localIsNew );
1528 return result; 1528 return result;
1529 1529
1530 break; 1530 break;
1531 case SYNC_PREF_FORCE_LOCAL: 1531 case SYNC_PREF_FORCE_LOCAL:
1532 return 1; 1532 return 1;
1533 break; 1533 break;
1534 case SYNC_PREF_FORCE_REMOTE: 1534 case SYNC_PREF_FORCE_REMOTE:
1535 return 2; 1535 return 2;
1536 break; 1536 break;
1537 1537
1538 default: 1538 default:
1539 // SYNC_PREF_TAKE_BOTH not implemented 1539 // SYNC_PREF_TAKE_BOTH not implemented
1540 break; 1540 break;
1541 } 1541 }
1542 return 0; 1542 return 0;
1543} 1543}
1544Event* CalendarView::getLastSyncEvent() 1544Event* CalendarView::getLastSyncEvent()
1545{ 1545{
1546 Event* lse; 1546 Event* lse;
1547 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1547 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1548 mCalendar->setSyncEventsEnabled(); 1548 mCalendar->setSyncEventsEnabled();
1549 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1549 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1550 if (!lse) { 1550 if (!lse) {
1551 qDebug("KO: New last Syncevent created for local: %s",mCurrentSyncDevice.latin1() ); 1551 qDebug("KO: New last Syncevent created for local: %s",mCurrentSyncDevice.latin1() );
1552 lse = new Event(); 1552 lse = new Event();
1553 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1553 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1554 QString sum = ""; 1554 QString sum = "";
1555 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1555 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1556 sum = "E: "; 1556 sum = "E: ";
1557 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1557 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1558 lse->setDtStart( mLastCalendarSync ); 1558 lse->setDtStart( mLastCalendarSync );
1559 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1559 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1560 lse->setCategories( i18n("SyncEvent") ); 1560 lse->setCategories( i18n("SyncEvent") );
1561 lse->setReadOnly( true ); 1561 lse->setReadOnly( true );
1562 lse->setCalID( 1 ); 1562 lse->setCalID( 1 );
1563 mCalendar->addEvent( lse ); 1563 mCalendar->addEvent( lse );
1564 } else 1564 } else
1565 qDebug("KO: Last Syncevent on local found"); 1565 qDebug("KO: Last Syncevent on local found");
1566 1566
1567 return lse; 1567 return lse;
1568 1568
1569} 1569}
1570 1570
1571// we check, if the to delete event has a id for a profile 1571// we check, if the to delete event has a id for a profile
1572// if yes, we set this id in the profile to delete 1572// if yes, we set this id in the profile to delete
1573void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1573void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1574{ 1574{
1575 if ( lastSync.count() == 0 ) { 1575 if ( lastSync.count() == 0 ) {
1576 //qDebug(" lastSync.count() == 0"); 1576 //qDebug(" lastSync.count() == 0");
1577 return; 1577 return;
1578 } 1578 }
1579 if ( toDelete->typeID() == journalID ) 1579 if ( toDelete->typeID() == journalID )
1580 return; 1580 return;
1581 1581
1582 Event* eve = lastSync.first(); 1582 Event* eve = lastSync.first();
1583 1583
1584 while ( eve ) { 1584 while ( eve ) {
1585 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1585 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1586 if ( !id.isEmpty() ) { 1586 if ( !id.isEmpty() ) {
1587 QString des = eve->description(); 1587 QString des = eve->description();
1588 QString pref = "e"; 1588 QString pref = "e";
1589 if ( toDelete->typeID() == todoID ) 1589 if ( toDelete->typeID() == todoID )
1590 pref = "t"; 1590 pref = "t";
1591 des += pref+ id + ","; 1591 des += pref+ id + ",";
1592 eve->setReadOnly( false ); 1592 eve->setReadOnly( false );
1593 eve->setDescription( des ); 1593 eve->setDescription( des );
1594 //qDebug("setdes %s ", des.latin1()); 1594 //qDebug("setdes %s ", des.latin1());
1595 eve->setReadOnly( true ); 1595 eve->setReadOnly( true );
1596 } 1596 }
1597 eve = lastSync.next(); 1597 eve = lastSync.next();
1598 } 1598 }
1599 1599
1600} 1600}
1601void CalendarView::checkExternalId( Incidence * inc ) 1601void CalendarView::checkExternalId( Incidence * inc )
1602{ 1602{
1603 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1603 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1604 checkExternSyncEvent( lastSync, inc ); 1604 checkExternSyncEvent( lastSync, inc );
1605 1605
1606} 1606}
1607// SSSSSSSSSSSSSSSSSSSSSS 1607// SSSSSSSSSSSSSSSSSSSSSS
1608bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1608bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1609{ 1609{
1610 1610
1611 bool syncOK = true; 1611 bool syncOK = true;
1612 int addedEvent = 0; 1612 int addedEvent = 0;
1613 int addedEventR = 0; 1613 int addedEventR = 0;
1614 int deletedEventR = 0; 1614 int deletedEventR = 0;
1615 int deletedEventL = 0; 1615 int deletedEventL = 0;
1616 int changedLocal = 0; 1616 int changedLocal = 0;
1617 int changedRemote = 0; 1617 int changedRemote = 0;
1618 int filteredIN = 0; 1618 int filteredIN = 0;
1619 int filteredOUT = 0; 1619 int filteredOUT = 0;
1620 //QPtrList<Event> el = local->rawEvents(); 1620 //QPtrList<Event> el = local->rawEvents();
1621 Event* eventR; 1621 Event* eventR;
1622 QString uid; 1622 QString uid;
1623 int take; 1623 int take;
1624 Event* eventRSync; 1624 Event* eventRSync;
1625 Event* eventLSync; 1625 Event* eventLSync;
1626 clearAllViews(); 1626 clearAllViews();
1627 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1627 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1628 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1628 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1629 bool fullDateRange = false; 1629 bool fullDateRange = false;
1630 local->resetTempSyncStat(); 1630 local->resetTempSyncStat();
1631 mLastCalendarSync = QDateTime::currentDateTime(); 1631 mLastCalendarSync = QDateTime::currentDateTime();
1632 if ( mSyncManager->syncWithDesktop() ) { 1632 if ( mSyncManager->syncWithDesktop() ) {
1633 remote->resetPilotStat(1); 1633 remote->resetPilotStat(1);
1634 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1634 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1635 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1635 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1636 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1636 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1637 } else { 1637 } else {
1638 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1638 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1639 } 1639 }
1640 } 1640 }
1641 QDateTime modifiedCalendar = mLastCalendarSync; 1641 QDateTime modifiedCalendar = mLastCalendarSync;
1642 eventLSync = getLastSyncEvent(); 1642 eventLSync = getLastSyncEvent();
1643 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1643 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1644 if ( eventR ) { 1644 if ( eventR ) {
1645 qDebug("KO: Last-syncEvent on remote found "); 1645 qDebug("KO: Last-syncEvent on remote found ");
1646 eventRSync = (Event*) eventR->clone(); 1646 eventRSync = (Event*) eventR->clone();
1647 remote->deleteEvent(eventR ); 1647 remote->deleteEvent(eventR );
1648 1648
1649 } else { 1649 } else {
1650 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1650 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1651 eventRSync = (Event*)eventLSync->clone(); 1651 eventRSync = (Event*)eventLSync->clone();
1652 } else { 1652 } else {
1653 fullDateRange = true; 1653 fullDateRange = true;
1654 eventRSync = new Event(); 1654 eventRSync = new Event();
1655 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1655 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1656 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1656 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1657 eventRSync->setDtStart( mLastCalendarSync ); 1657 eventRSync->setDtStart( mLastCalendarSync );
1658 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1658 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1659 eventRSync->setCategories( i18n("SyncEvent") ); 1659 eventRSync->setCategories( i18n("SyncEvent") );
1660 } 1660 }
1661 } 1661 }
1662 if ( eventLSync->dtStart() == mLastCalendarSync ) 1662 if ( eventLSync->dtStart() == mLastCalendarSync )
1663 fullDateRange = true; 1663 fullDateRange = true;
1664 1664
1665 if ( ! fullDateRange ) { 1665 if ( ! fullDateRange ) {
1666 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1666 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1667 1667
1668 qDebug("KO: Sync: Set fulldate to true! Local: %s --- Remote: %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1668 qDebug("KO: Sync: Set fulldate to true! Local: %s --- Remote: %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1669 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1669 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1670 fullDateRange = true; 1670 fullDateRange = true;
1671 } 1671 }
1672 } 1672 }
1673 if ( mSyncManager->syncWithDesktop() ) { 1673 if ( mSyncManager->syncWithDesktop() ) {
1674 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1674 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1675 } 1675 }
1676 if ( fullDateRange ) 1676 if ( fullDateRange )
1677 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1677 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1678 else 1678 else
1679 mLastCalendarSync = eventLSync->dtStart(); 1679 mLastCalendarSync = eventLSync->dtStart();
1680 // for resyncing if own file has changed 1680 // for resyncing if own file has changed
1681 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1681 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1682 mLastCalendarSync = loadedFileVersion; 1682 mLastCalendarSync = loadedFileVersion;
1683 //qDebug("setting mLastCalendarSync "); 1683 //qDebug("setting mLastCalendarSync ");
1684 } 1684 }
1685 //qDebug("*************************** "); 1685 //qDebug("*************************** ");
1686 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1686 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1687 QPtrList<Incidence> er = remote->rawIncidences(); 1687 QPtrList<Incidence> er = remote->rawIncidences();
1688 Incidence* inR = er.first(); 1688 Incidence* inR = er.first();
1689 Incidence* inL; 1689 Incidence* inL;
1690 QProgressBar bar( er.count(),0 ); 1690 QProgressBar bar( er.count(),0 );
1691 bar.setCaption (i18n("Syncing - close to abort!") ); 1691 bar.setCaption (i18n("Syncing - close to abort!") );
1692 1692
1693 // ************** setting up filter ************* 1693 // ************** setting up filter *************
1694 CalFilter *filterIN = 0; 1694 CalFilter *filterIN = 0;
1695 CalFilter *filterOUT = 0; 1695 CalFilter *filterOUT = 0;
1696 CalFilter *filter = mFilters.first(); 1696 CalFilter *filter = mFilters.first();
1697 while(filter) { 1697 while(filter) {
1698 if ( filter->name() == mSyncManager->mFilterInCal ) 1698 if ( filter->name() == mSyncManager->mFilterInCal )
1699 filterIN = filter; 1699 filterIN = filter;
1700 if ( filter->name() == mSyncManager->mFilterOutCal ) 1700 if ( filter->name() == mSyncManager->mFilterOutCal )
1701 filterOUT = filter; 1701 filterOUT = filter;
1702 filter = mFilters.next(); 1702 filter = mFilters.next();
1703 } 1703 }
1704 int w = 300; 1704 int w = 300;
1705 if ( QApplication::desktop()->width() < 320 ) 1705 if ( QApplication::desktop()->width() < 320 )
1706 w = 220; 1706 w = 220;
1707 int h = bar.sizeHint().height() ; 1707 int h = bar.sizeHint().height() ;
1708 int dw = QApplication::desktop()->width(); 1708 int dw = QApplication::desktop()->width();
1709 int dh = QApplication::desktop()->height(); 1709 int dh = QApplication::desktop()->height();
1710 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1710 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1711 bar.show(); 1711 bar.show();
1712 int modulo = (er.count()/10)+1; 1712 int modulo = (er.count()/10)+1;
1713 int incCounter = 0; 1713 int incCounter = 0;
1714 while ( inR ) { 1714 while ( inR ) {
1715 if ( ! bar.isVisible() ) 1715 if ( ! bar.isVisible() )
1716 return false; 1716 return false;
1717 if ( incCounter % modulo == 0 ) 1717 if ( incCounter % modulo == 0 )
1718 bar.setProgress( incCounter ); 1718 bar.setProgress( incCounter );
1719 ++incCounter; 1719 ++incCounter;
1720 uid = inR->uid(); 1720 uid = inR->uid();
1721 bool skipIncidence = false; 1721 bool skipIncidence = false;
1722 if ( uid.left(15) == QString("last-syncEvent-") ) 1722 if ( uid.left(15) == QString("last-syncEvent-") )
1723 skipIncidence = true; 1723 skipIncidence = true;
1724 QString idS; 1724 QString idS;
1725 qApp->processEvents(); 1725 qApp->processEvents();
1726 if ( !skipIncidence ) { 1726 if ( !skipIncidence ) {
1727 int hasCalId = 0; 1727 int hasCalId = 0;
1728 inL = local->incidenceForUid( uid , false , true, &hasCalId ); 1728 inL = local->incidenceForUid( uid , false , true, &hasCalId );
1729 if ( hasCalId && !inL ) 1729 if ( hasCalId && !inL )
1730 inL = local->incidenceForUid( uid , false , true, &hasCalId ); 1730 inL = local->incidenceForUid( uid , false , true, &hasCalId );
1731 else 1731 else
1732 hasCalId = 0; 1732 hasCalId = 0;
1733 if ( inL ) { // maybe conflict - same uid in both calendars 1733 if ( inL ) { // maybe conflict - same uid in both calendars
1734 if ( hasCalId ) 1734
1735 qDebug("KO: Cal id %d conflict detected: %s ", hasCalId, inL->summary().latin1());
1736 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1735 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1737 //qDebug("take %d %s ", take, inL->summary().latin1()); 1736 //qDebug("take %d %s ", take, inL->summary().latin1());
1738 if ( take == 3 ) 1737 if ( take == 3 )
1739 return false; 1738 return false;
1740 if ( take == 1 ) {// take local ********************** 1739 if ( take == 1 ) {// take local **********************
1741 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1740 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1742 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1741 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1743 else 1742 else
1744 idS = inR->IDStr(); 1743 idS = inR->IDStr();
1745 int calID = inR->calID(); 1744 int calID = inR->calID();
1746 remote->deleteIncidence( inR ); 1745 remote->deleteIncidence( inR );
1747 inR = inL->clone(); 1746 if ( !hasCalId ) {
1748 inR->setCalID_block( calID ); 1747 inR = inL->clone();
1749 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1748 inR->setCalID_block( calID );
1750 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1749 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1751 inR->setIDStr( idS ); 1750 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1752 remote->addIncidence( inR ); 1751 inR->setIDStr( idS );
1753 if ( mSyncManager->syncWithDesktop() ) 1752 remote->addIncidence( inR );
1754 inR->setPilotId( 2 ); 1753 if ( mSyncManager->syncWithDesktop() )
1755 ++changedRemote; 1754 inR->setPilotId( 2 );
1755 ++changedRemote;
1756 } else
1757 ++deletedEventR;
1756 } else {// take remote ********************** 1758 } else {// take remote **********************
1757 if ( !inL->isReadOnly() ) { 1759 if ( !inL->isReadOnly() ) {
1758 idS = inL->IDStr(); 1760 idS = inL->IDStr();
1759 int pid = inL->pilotId(); 1761 int pid = inL->pilotId();
1760 int calID = inL->calID(); 1762 int calID = inL->calID();
1761 if ( hasCalId ) 1763 if ( hasCalId )
1762 calID = hasCalId; 1764 calID = 0;// add to default calendar
1763 local->deleteIncidence( inL ); 1765 local->deleteIncidence( inL );
1764 inL = inR->clone(); 1766 inL = inR->clone();
1765 inL->setCalID_block( calID ); 1767 inL->setCalID_block( calID );
1766 if ( mSyncManager->syncWithDesktop() ) 1768 if ( mSyncManager->syncWithDesktop() )
1767 inL->setPilotId( pid ); 1769 inL->setPilotId( pid );
1768 inL->setIDStr( idS ); 1770 inL->setIDStr( idS );
1769 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1771 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1770 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1772 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1771 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1773 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1772 } 1774 }
1773 local->addIncidence( inL ); 1775 local->addIncidence( inL );
1774 ++changedLocal; 1776 ++changedLocal;
1775 } 1777 }
1776 } 1778 }
1777 } else { 1779 } else {
1778 // take == 0; events equal 1780 // take == 0; events equal
1779 if ( hasCalId ) 1781 if ( hasCalId ) {
1780 qDebug("EV EQUALLLL **************************** "); 1782 qDebug("KO: Changing Cal id %d to %d for : %s ", hasCalId, local->defaultCalendar(),inL->summary().latin1());
1783 inL->setCalID( local->defaultCalendar() );
1784 }
1781 1785
1782 } 1786 }
1787
1788
1783 } else { // no conflict ********** add or delete remote 1789 } else { // no conflict ********** add or delete remote
1784 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1790 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1785 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1791 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1786 QString des = eventLSync->description(); 1792 QString des = eventLSync->description();
1787 QString pref = "e"; 1793 QString pref = "e";
1788 if ( inR->typeID() == todoID ) 1794 if ( inR->typeID() == todoID )
1789 pref = "t"; 1795 pref = "t";
1790 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1796 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1791 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1797 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1792 //remote->deleteIncidence( inR ); 1798 //remote->deleteIncidence( inR );
1793 ++deletedEventR; 1799 ++deletedEventR;
1794 } else { 1800 } else {
1795 inR->setLastModified( modifiedCalendar ); 1801 inR->setLastModified( modifiedCalendar );
1796 inL = inR->clone(); 1802 inL = inR->clone();
1797 inL->setIDStr( ":" ); 1803 inL->setIDStr( ":" );
1798 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1804 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1799 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1805 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1800 1806
1801 inL->setCalID_block( 0 );// add to default cal 1807 inL->setCalID_block( 0 );// add to default cal
1802 local->addIncidence( inL ); 1808 local->addIncidence( inL );
1803 ++addedEvent; 1809 ++addedEvent;
1804 1810
1805 } 1811 }
1806 } else { 1812 } else {
1807 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1813 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1808 inR->setLastModified( modifiedCalendar ); 1814 inR->setLastModified( modifiedCalendar );
1809 inL = inR->clone(); 1815 inL = inR->clone();
1810 inL->setIDStr( ":" ); 1816 inL->setIDStr( ":" );
1811 inL->setCalID_block( 0 );// add to default cal 1817 inL->setCalID_block( 0 );// add to default cal
1812 local->addIncidence( inL ); 1818 local->addIncidence( inL );
1813 ++addedEvent; 1819 ++addedEvent;
1814 1820
1815 } else { 1821 } else {
1816 checkExternSyncEvent(eventRSyncSharp, inR); 1822 checkExternSyncEvent(eventRSyncSharp, inR);
1817 remote->deleteIncidence( inR ); 1823 remote->deleteIncidence( inR );
1818 ++deletedEventR; 1824 ++deletedEventR;
1819 } 1825 }
1820 } 1826 }
1821 } else { 1827 } else {
1822 ++filteredIN; 1828 ++filteredIN;
1823 } 1829 }
1824 } 1830 }
1825 } 1831 }
1826 inR = er.next(); 1832 inR = er.next();
1827 } 1833 }
1828 QPtrList<Incidence> el = local->rawIncidences(); 1834 QPtrList<Incidence> el = local->rawIncidences();
1829 inL = el.first(); 1835 inL = el.first();
1830 modulo = (el.count()/10)+1; 1836 modulo = (el.count()/10)+1;
1831 bar.setCaption (i18n("Add / remove events") ); 1837 bar.setCaption (i18n("Add / remove events") );
1832 bar.setTotalSteps ( el.count() ) ; 1838 bar.setTotalSteps ( el.count() ) ;
1833 bar.show(); 1839 bar.show();
1834 incCounter = 0; 1840 incCounter = 0;
1835 1841
1836 while ( inL ) { 1842 while ( inL ) {
1837 1843
1838 qApp->processEvents(); 1844 qApp->processEvents();
1839 if ( ! bar.isVisible() ) 1845 if ( ! bar.isVisible() )
1840 return false; 1846 return false;
1841 if ( incCounter % modulo == 0 ) 1847 if ( incCounter % modulo == 0 )
1842 bar.setProgress( incCounter ); 1848 bar.setProgress( incCounter );
1843 ++incCounter; 1849 ++incCounter;
1844 uid = inL->uid(); 1850 uid = inL->uid();
1845 bool skipIncidence = false; 1851 bool skipIncidence = false;
1846 if ( uid.left(15) == QString("last-syncEvent-") ) 1852 if ( uid.left(15) == QString("last-syncEvent-") )
1847 skipIncidence = true; 1853 skipIncidence = true;
1848 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1854 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1849 skipIncidence = true; 1855 skipIncidence = true;
1850 if ( !skipIncidence ) { 1856 if ( !skipIncidence ) {
1851 inR = remote->incidenceForUid( uid , true, true ); 1857 inR = remote->incidenceForUid( uid , true, true );
1852 if ( ! inR ) { 1858 if ( ! inR ) {
1853 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1859 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1854 // no conflict ********** add or delete local 1860 // no conflict ********** add or delete local
1855 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1861 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1856 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1862 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1857 checkExternSyncEvent(eventLSyncSharp, inL); 1863 checkExternSyncEvent(eventLSyncSharp, inL);
1858 local->deleteIncidence( inL ); 1864 local->deleteIncidence( inL );
1859 ++deletedEventL; 1865 ++deletedEventL;
1860 } else { 1866 } else {
1861 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1867 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1862 inL->removeID(mCurrentSyncDevice ); 1868 inL->removeID(mCurrentSyncDevice );
1863 ++addedEventR; 1869 ++addedEventR;
1864 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1870 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1865 inL->setLastModified( modifiedCalendar ); 1871 inL->setLastModified( modifiedCalendar );
1866 inR = inL->clone(); 1872 inR = inL->clone();
1867 inR->setIDStr( ":" ); 1873 inR->setIDStr( ":" );
1868 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1874 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1869 inR->setCalID_block( 0 );// add to default cal 1875 inR->setCalID_block( 0 );// add to default cal
1870 remote->addIncidence( inR ); 1876 remote->addIncidence( inR );
1871 } 1877 }
1872 } 1878 }
1873 } else { 1879 } else {
1874 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1880 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1875 checkExternSyncEvent(eventLSyncSharp, inL); 1881 checkExternSyncEvent(eventLSyncSharp, inL);
1876 local->deleteIncidence( inL ); 1882 local->deleteIncidence( inL );
1877 ++deletedEventL; 1883 ++deletedEventL;
1878 } else { 1884 } else {
1879 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1885 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1880 ++addedEventR; 1886 ++addedEventR;
1881 inL->setLastModified( modifiedCalendar ); 1887 inL->setLastModified( modifiedCalendar );
1882 inR = inL->clone(); 1888 inR = inL->clone();
1883 inR->setIDStr( ":" ); 1889 inR->setIDStr( ":" );
1884 inR->setCalID_block( 0 );// add to default cal 1890 inR->setCalID_block( 0 );// add to default cal
1885 remote->addIncidence( inR ); 1891 remote->addIncidence( inR );
1886 } 1892 }
1887 } 1893 }
1888 } 1894 }
1889 } else { 1895 } else {
1890 ++filteredOUT; 1896 ++filteredOUT;
1891 } 1897 }
1892 } 1898 }
1893 } 1899 }
1894 inL = el.next(); 1900 inL = el.next();
1895 } 1901 }
1896 int delFut = 0; 1902 int delFut = 0;
1897 int remRem = 0; 1903 int remRem = 0;
1898 if ( mSyncManager->mWriteBackInFuture ) { 1904 if ( mSyncManager->mWriteBackInFuture ) {
1899 er = remote->rawIncidences(); 1905 er = remote->rawIncidences();
1900 remRem = er.count(); 1906 remRem = er.count();
1901 inR = er.first(); 1907 inR = er.first();
1902 QDateTime dt; 1908 QDateTime dt;
1903 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1909 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1904 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1910 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1905 while ( inR ) { 1911 while ( inR ) {
1906 if ( inR->typeID() == todoID ) { 1912 if ( inR->typeID() == todoID ) {
1907 Todo * t = (Todo*)inR; 1913 Todo * t = (Todo*)inR;
1908 if ( t->hasDueDate() ) 1914 if ( t->hasDueDate() )
1909 dt = t->dtDue(); 1915 dt = t->dtDue();
1910 else 1916 else
1911 dt = cur.addSecs( 62 ); 1917 dt = cur.addSecs( 62 );
1912 } 1918 }
1913 else if (inR->typeID() == eventID ) { 1919 else if (inR->typeID() == eventID ) {
1914 bool ok; 1920 bool ok;
1915 dt = inR->getNextOccurence( cur, &ok ); 1921 dt = inR->getNextOccurence( cur, &ok );
1916 if ( !ok ) 1922 if ( !ok )
1917 dt = cur.addSecs( -62 ); 1923 dt = cur.addSecs( -62 );
1918 } 1924 }
1919 else 1925 else
1920 dt = inR->dtStart(); 1926 dt = inR->dtStart();
1921 if ( dt < cur || dt > end ) { 1927 if ( dt < cur || dt > end ) {
1922 remote->deleteIncidence( inR ); 1928 remote->deleteIncidence( inR );
1923 ++delFut; 1929 ++delFut;
1924 } 1930 }
1925 inR = er.next(); 1931 inR = er.next();
1926 } 1932 }
1927 } 1933 }
1928 bar.hide(); 1934 bar.hide();
1929 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1935 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1930 if ( mMultiResourceSync ) { 1936 if ( mMultiResourceSync ) {
1931 remote->removeSyncInfo( "" ); //all 1937 remote->removeSyncInfo( "" ); //all
1932 qDebug("KO: Remoing all sync info on remote "); 1938 qDebug("KO: Remoing all sync info on remote ");
1933 } else { 1939 } else {
1934 eventLSync->setReadOnly( false ); 1940 eventLSync->setReadOnly( false );
1935 eventLSync->setDtStart( mLastCalendarSync ); 1941 eventLSync->setDtStart( mLastCalendarSync );
1936 eventRSync->setDtStart( mLastCalendarSync ); 1942 eventRSync->setDtStart( mLastCalendarSync );
1937 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1943 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1938 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1944 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1939 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1945 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1940 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1946 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1941 eventLSync->setReadOnly( true ); 1947 eventLSync->setReadOnly( true );
1942 } 1948 }
1943 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1949 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1944 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop() && !mMultiResourceSync ) // kde is abnormal... 1950 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop() && !mMultiResourceSync ) // kde is abnormal...
1945 remote->addEvent( eventRSync ); 1951 remote->addEvent( eventRSync );
1946 else 1952 else
1947 delete eventRSync; 1953 delete eventRSync;
1948 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1954 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1949 QString mes; 1955 QString mes;
1950 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 ); 1956 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 );
1951 QString delmess; 1957 QString delmess;
1952 if ( delFut ) { 1958 if ( delFut ) {
1953 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); 1959 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);
1954 mes += delmess; 1960 mes += delmess;
1955 } 1961 }
1956 mes = i18n("Local calendar changed!\n") +mes; 1962 mes = i18n("Local calendar changed!\n") +mes;
1957 mCalendar->checkAlarmForIncidence( 0, true ); 1963 mCalendar->checkAlarmForIncidence( 0, true );
1958 qDebug( mes ); 1964 qDebug( mes );
1959 if ( mSyncManager->mShowSyncSummary ) { 1965 if ( mSyncManager->mShowSyncSummary ) {
1960 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1966 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1961 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1967 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1962 qDebug("KO: WB cancelled "); 1968 qDebug("KO: WB cancelled ");
1963 mSyncManager->mWriteBackFile = false; 1969 mSyncManager->mWriteBackFile = false;
1964 return syncOK; 1970 return syncOK;
1965 } 1971 }
1966 } 1972 }
1967 return syncOK; 1973 return syncOK;
1968} 1974}
1969 1975
1970void CalendarView::setSyncDevice( QString s ) 1976void CalendarView::setSyncDevice( QString s )
1971{ 1977{
1972 mCurrentSyncDevice= s; 1978 mCurrentSyncDevice= s;
1973} 1979}
1974void CalendarView::setSyncName( QString s ) 1980void CalendarView::setSyncName( QString s )
1975{ 1981{
1976 mCurrentSyncName= s; 1982 mCurrentSyncName= s;
1977} 1983}
1978bool CalendarView::syncCalendar(QString filename, int mode) 1984bool CalendarView::syncCalendar(QString filename, int mode)
1979{ 1985{
1980 //qDebug("syncCalendar %s ", filename.latin1()); 1986 //qDebug("syncCalendar %s ", filename.latin1());
1981 mGlobalSyncMode = SYNC_MODE_NORMAL; 1987 mGlobalSyncMode = SYNC_MODE_NORMAL;
1982 CalendarLocal* calendar = new CalendarLocal(); 1988 CalendarLocal* calendar = new CalendarLocal();
1983 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1989 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1984 FileStorage* storage = new FileStorage( calendar ); 1990 FileStorage* storage = new FileStorage( calendar );
1985 bool syncOK = false; 1991 bool syncOK = false;
1986 storage->setFileName( filename ); 1992 storage->setFileName( filename );
1987 // qDebug("loading ... "); 1993 // qDebug("loading ... ");
1988 if ( storage->load() ) { 1994 if ( storage->load() ) {
1989 getEventViewerDialog()->setSyncMode( true ); 1995 getEventViewerDialog()->setSyncMode( true );
1990 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1996 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1991 getEventViewerDialog()->setSyncMode( false ); 1997 getEventViewerDialog()->setSyncMode( false );
1992 if ( syncOK ) { 1998 if ( syncOK ) {
1993 if ( mSyncManager->mWriteBackFile ) 1999 if ( mSyncManager->mWriteBackFile )
1994 { 2000 {
1995 storage->setSaveFormat( new ICalFormat() ); 2001 storage->setSaveFormat( new ICalFormat() );
1996 storage->save(); 2002 storage->save();
1997 } 2003 }
1998 } 2004 }
1999 setModified( true ); 2005 setModified( true );
2000 } 2006 }
2001 delete storage; 2007 delete storage;
2002 delete calendar; 2008 delete calendar;
2003 if ( syncOK ) 2009 if ( syncOK )
2004 updateView(); 2010 updateView();
2005 return syncOK; 2011 return syncOK;
2006} 2012}
2007 2013
2008void CalendarView::syncExternal( int mode ) 2014void CalendarView::syncExternal( int mode )
2009{ 2015{
2010 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2016 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2011 qApp->processEvents(); 2017 qApp->processEvents();
2012 CalendarLocal* calendar = new CalendarLocal(); 2018 CalendarLocal* calendar = new CalendarLocal();
2013 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2019 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2014 bool syncOK = false; 2020 bool syncOK = false;
2015 bool loadSuccess = false; 2021 bool loadSuccess = false;
2016 PhoneFormat* phoneFormat = 0; 2022 PhoneFormat* phoneFormat = 0;
2017 emit tempDisableBR(true); 2023 emit tempDisableBR(true);
2018#ifndef DESKTOP_VERSION 2024#ifndef DESKTOP_VERSION
2019 SharpFormat* sharpFormat = 0; 2025 SharpFormat* sharpFormat = 0;
2020 if ( mode == 0 ) { // sharp 2026 if ( mode == 0 ) { // sharp
2021 sharpFormat = new SharpFormat () ; 2027 sharpFormat = new SharpFormat () ;
2022 loadSuccess = sharpFormat->load( calendar, mCalendar ); 2028 loadSuccess = sharpFormat->load( calendar, mCalendar );
2023 2029
2024 } else 2030 } else
2025#endif 2031#endif
2026 if ( mode == 1 ) { // phone 2032 if ( mode == 1 ) { // phone
2027 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 2033 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
2028 mSyncManager->mPhoneDevice, 2034 mSyncManager->mPhoneDevice,
2029 mSyncManager->mPhoneConnection, 2035 mSyncManager->mPhoneConnection,
2030 mSyncManager->mPhoneModel); 2036 mSyncManager->mPhoneModel);
2031 loadSuccess = phoneFormat->load( calendar,mCalendar); 2037 loadSuccess = phoneFormat->load( calendar,mCalendar);
2032 2038
2033 } else { 2039 } else {
2034 emit tempDisableBR(false); 2040 emit tempDisableBR(false);
2035 return; 2041 return;
2036 } 2042 }
2037 if ( loadSuccess ) { 2043 if ( loadSuccess ) {
2038 getEventViewerDialog()->setSyncMode( true ); 2044 getEventViewerDialog()->setSyncMode( true );
2039 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2045 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2040 getEventViewerDialog()->setSyncMode( false ); 2046 getEventViewerDialog()->setSyncMode( false );
2041 qApp->processEvents(); 2047 qApp->processEvents();
2042 if ( syncOK ) { 2048 if ( syncOK ) {
2043 if ( mSyncManager->mWriteBackFile ) 2049 if ( mSyncManager->mWriteBackFile )
2044 { 2050 {
2045 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 2051 QPtrList<Incidence> iL = mCalendar->rawIncidences();
2046 Incidence* inc = iL.first(); 2052 Incidence* inc = iL.first();
2047 if ( phoneFormat ) { 2053 if ( phoneFormat ) {
2048 while ( inc ) { 2054 while ( inc ) {
2049 inc->removeID(mCurrentSyncDevice); 2055 inc->removeID(mCurrentSyncDevice);
2050 inc = iL.next(); 2056 inc = iL.next();
2051 } 2057 }
2052 } 2058 }
2053#ifndef DESKTOP_VERSION 2059#ifndef DESKTOP_VERSION
2054 if ( sharpFormat ) 2060 if ( sharpFormat )
2055 sharpFormat->save(calendar); 2061 sharpFormat->save(calendar);
2056#endif 2062#endif
2057 if ( phoneFormat ) 2063 if ( phoneFormat )
2058 phoneFormat->save(calendar); 2064 phoneFormat->save(calendar);
2059 iL = calendar->rawIncidences(); 2065 iL = calendar->rawIncidences();
2060 inc = iL.first(); 2066 inc = iL.first();
2061 Incidence* loc; 2067 Incidence* loc;
2062 while ( inc ) { 2068 while ( inc ) {
2063 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 2069 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
2064 loc = mCalendar->incidence(inc->uid() ); 2070 loc = mCalendar->incidence(inc->uid() );
2065 if ( loc ) { 2071 if ( loc ) {
2066 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 2072 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
2067 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 2073 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
2068 } 2074 }
2069 } 2075 }
2070 inc = iL.next(); 2076 inc = iL.next();
2071 } 2077 }
2072 Incidence* lse = getLastSyncEvent(); 2078 Incidence* lse = getLastSyncEvent();
2073 if ( lse ) { 2079 if ( lse ) {
2074 lse->setReadOnly( false ); 2080 lse->setReadOnly( false );
2075 lse->setDescription( "" ); 2081 lse->setDescription( "" );
2076 lse->setReadOnly( true ); 2082 lse->setReadOnly( true );
2077 } 2083 }
2078 } 2084 }
2079 } else { 2085 } else {
2080 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 2086 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
2081 } 2087 }
2082 setModified( true ); 2088 setModified( true );
2083 } else { 2089 } else {
2084 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 2090 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
2085 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 2091 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
2086 question, i18n("Ok")) ; 2092 question, i18n("Ok")) ;
2087 2093
2088 } 2094 }
2089 delete calendar; 2095 delete calendar;
2090 updateView(); 2096 updateView();
2091 emit tempDisableBR(false); 2097 emit tempDisableBR(false);
2092 return ;//syncOK; 2098 return ;//syncOK;
2093 2099
2094} 2100}
2095 2101
2096bool CalendarView::importBday() 2102bool CalendarView::importBday()
2097{ 2103{
2098#ifndef KORG_NOKABC 2104#ifndef KORG_NOKABC
2099 2105
2100#ifdef DESKTOP_VERSION 2106#ifdef DESKTOP_VERSION
2101 int curCal = mCalendar->defaultCalendar(); 2107 int curCal = mCalendar->defaultCalendar();
2102 int bd = mCalEditView->getBirtdayID(); 2108 int bd = mCalEditView->getBirtdayID();
2103 if ( bd == 0 ) 2109 if ( bd == 0 )
2104 return false; 2110 return false;
2105 mCalendar->setDefaultCalendar( bd ); 2111 mCalendar->setDefaultCalendar( bd );
2106 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 2112 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
2107 KABC::AddressBook::Iterator it; 2113 KABC::AddressBook::Iterator it;
2108 int count = 0; 2114 int count = 0;
2109 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 2115 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
2110 ++count; 2116 ++count;
2111 } 2117 }
2112 QProgressBar bar(count,0 ); 2118 QProgressBar bar(count,0 );
2113 int w = 300; 2119 int w = 300;
2114 if ( QApplication::desktop()->width() < 320 ) 2120 if ( QApplication::desktop()->width() < 320 )
2115 w = 220; 2121 w = 220;
2116 int h = bar.sizeHint().height() ; 2122 int h = bar.sizeHint().height() ;
2117 int dw = QApplication::desktop()->width(); 2123 int dw = QApplication::desktop()->width();
2118 int dh = QApplication::desktop()->height(); 2124 int dh = QApplication::desktop()->height();
2119 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2125 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2120 bar.show(); 2126 bar.show();
2121 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 2127 bar.setCaption (i18n("Reading addressbook - close to abort!") );
2122 qApp->processEvents(); 2128 qApp->processEvents();
2123 count = 0; 2129 count = 0;
2124 int addCount = 0; 2130 int addCount = 0;
2125 KCal::Attendee* a = 0; 2131 KCal::Attendee* a = 0;
2126 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 2132 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
2127 if ( ! bar.isVisible() ) 2133 if ( ! bar.isVisible() )
2128 return false; 2134 return false;
2129 bar.setProgress( count++ ); 2135 bar.setProgress( count++ );
2130 qApp->processEvents(); 2136 qApp->processEvents();
2131 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 2137 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
2132 if ( (*it).birthday().date().isValid() ){ 2138 if ( (*it).birthday().date().isValid() ){
2133 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 2139 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
2134 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 2140 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
2135 ++addCount; 2141 ++addCount;
2136 } 2142 }
2137 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 2143 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
2138 if ( anni.isValid() ){ 2144 if ( anni.isValid() ){
2139 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 2145 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
2140 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 2146 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
2141 ++addCount; 2147 ++addCount;
2142 } 2148 }
2143 } 2149 }
2144 mCalendar->setDefaultCalendar( curCal ); 2150 mCalendar->setDefaultCalendar( curCal );
2145 updateView(); 2151 updateView();
2146 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 2152 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
2147#else //DESKTOP_VERSION 2153#else //DESKTOP_VERSION
2148 2154
2149 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 2155 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
2150 // the result should now arrive through method insertBirthdays 2156 // the result should now arrive through method insertBirthdays
2151 2157
2152#endif //DESKTOP_VERSION 2158#endif //DESKTOP_VERSION
2153 2159
2154#endif //KORG_NOKABC 2160#endif //KORG_NOKABC
2155 2161
2156 2162
2157 return true; 2163 return true;
2158} 2164}
2159 2165
2160// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 2166// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
2161void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 2167void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
2162 const QStringList& anniversaryList, const QStringList& realNameList, 2168 const QStringList& anniversaryList, const QStringList& realNameList,
2163 const QStringList& emailList, const QStringList& assembledNameList, 2169 const QStringList& emailList, const QStringList& assembledNameList,
2164 const QStringList& uidList) 2170 const QStringList& uidList)
2165{ 2171{
2166 2172
2167 //qDebug("KO::CalendarView::insertBirthdays"); 2173 //qDebug("KO::CalendarView::insertBirthdays");
2168 if (uid == this->name()) 2174 if (uid == this->name())
2169 { 2175 {
2170 int curCal = mCalendar->defaultCalendar(); 2176 int curCal = mCalendar->defaultCalendar();
2171 int bd = mCalEditView->getBirtdayID(); 2177 int bd = mCalEditView->getBirtdayID();
2172 if ( bd == 0 ) 2178 if ( bd == 0 )
2173 return; 2179 return;
2174 mCalendar->setDefaultCalendar( bd ); 2180 mCalendar->setDefaultCalendar( bd );
2175 2181
2176 2182
2177 int count = birthdayList.count(); 2183 int count = birthdayList.count();
2178 int addCount = 0; 2184 int addCount = 0;
2179 KCal::Attendee* a = 0; 2185 KCal::Attendee* a = 0;
2180 2186
2181 //qDebug("CalView 1 %i", count); 2187 //qDebug("CalView 1 %i", count);
2182 2188
2183 QProgressBar bar(count,0 ); 2189 QProgressBar bar(count,0 );
2184 int w = 300; 2190 int w = 300;
2185 if ( QApplication::desktop()->width() < 320 ) 2191 if ( QApplication::desktop()->width() < 320 )
2186 w = 220; 2192 w = 220;
2187 int h = bar.sizeHint().height() ; 2193 int h = bar.sizeHint().height() ;
2188 int dw = QApplication::desktop()->width(); 2194 int dw = QApplication::desktop()->width();
2189 int dh = QApplication::desktop()->height(); 2195 int dh = QApplication::desktop()->height();
2190 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2196 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2191 bar.show(); 2197 bar.show();
2192 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 2198 bar.setCaption (i18n("inserting birthdays - close to abort!") );
2193 qApp->processEvents(); 2199 qApp->processEvents();
2194 2200
2195 QDate birthday; 2201 QDate birthday;
2196 QDate anniversary; 2202 QDate anniversary;
2197 QString realName; 2203 QString realName;
2198 QString email; 2204 QString email;
2199 QString assembledName; 2205 QString assembledName;
2200 QString uid; 2206 QString uid;
2201 bool ok = true; 2207 bool ok = true;
2202 for ( int i = 0; i < count; i++) 2208 for ( int i = 0; i < count; i++)
2203 { 2209 {
2204 if ( ! bar.isVisible() ) 2210 if ( ! bar.isVisible() )
2205 return; 2211 return;
2206 bar.setProgress( i ); 2212 bar.setProgress( i );
2207 qApp->processEvents(); 2213 qApp->processEvents();
2208 2214
2209 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 2215 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
2210 if (!ok) { 2216 if (!ok) {
2211 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 2217 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
2212 } 2218 }
2213 2219
2214 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 2220 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
2215 if (!ok) { 2221 if (!ok) {
2216 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 2222 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
2217 } 2223 }
2218 realName = realNameList[i]; 2224 realName = realNameList[i];
2219 email = emailList[i]; 2225 email = emailList[i];
2220 assembledName = assembledNameList[i]; 2226 assembledName = assembledNameList[i];
2221 uid = uidList[i]; 2227 uid = uidList[i];
2222 //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() ); 2228 //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() );
2223 2229
2224 if ( birthday.isValid() ){ 2230 if ( birthday.isValid() ){
2225 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 2231 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
2226 KCal::Attendee::ReqParticipant,uid) ; 2232 KCal::Attendee::ReqParticipant,uid) ;
2227 if ( addAnniversary( birthday, assembledName, a, true ) ) 2233 if ( addAnniversary( birthday, assembledName, a, true ) )
2228 ++addCount; 2234 ++addCount;
2229 } 2235 }
2230 2236
2231 if ( anniversary.isValid() ){ 2237 if ( anniversary.isValid() ){
2232 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 2238 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
2233 KCal::Attendee::ReqParticipant,uid) ; 2239 KCal::Attendee::ReqParticipant,uid) ;
2234 if ( addAnniversary( anniversary, assembledName, a, false ) ) 2240 if ( addAnniversary( anniversary, assembledName, a, false ) )
2235 ++addCount; 2241 ++addCount;
2236 } 2242 }
2237 } 2243 }
2238 2244
2239 mCalendar->setDefaultCalendar( curCal ); 2245 mCalendar->setDefaultCalendar( curCal );
2240 updateView(); 2246 updateView();
2241 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 2247 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
2242 2248
2243 } 2249 }
2244 2250
2245} 2251}
2246 2252
2247 2253
2248 2254
2249bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 2255bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
2250{ 2256{
2251 //qDebug("addAnni "); 2257 //qDebug("addAnni ");
2252 Event * ev = new Event(); 2258 Event * ev = new Event();
2253 ev->setOrganizer(KOPrefs::instance()->email()); 2259 ev->setOrganizer(KOPrefs::instance()->email());
2254 if ( a ) { 2260 if ( a ) {
2255 ev->addAttendee( a ); 2261 ev->addAttendee( a );
2256 } 2262 }
2257 QString kind; 2263 QString kind;
2258 if ( birthday ) { 2264 if ( birthday ) {
2259 kind = i18n( "Birthday" ); 2265 kind = i18n( "Birthday" );
2260 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 2266 ev->setSummary( name + " (" + QString::number(date.year()) +")");
2261 } 2267 }
2262 else { 2268 else {
2263 kind = i18n( "Anniversary" ); 2269 kind = i18n( "Anniversary" );
2264 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 2270 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
2265 } 2271 }
2266 ev->setCategories( kind ); 2272 ev->setCategories( kind );
2267 ev->setDtStart( QDateTime(date) ); 2273 ev->setDtStart( QDateTime(date) );
2268 ev->setDtEnd( QDateTime(date) ); 2274 ev->setDtEnd( QDateTime(date) );
2269 ev->setFloats( true ); 2275 ev->setFloats( true );
2270 Recurrence * rec = ev->recurrence(); 2276 Recurrence * rec = ev->recurrence();
2271 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 2277 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
2272 rec->addYearlyNum( date.month() ); 2278 rec->addYearlyNum( date.month() );
2273 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 2279 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
2274 delete ev; 2280 delete ev;
2275 return false; 2281 return false;
2276 } 2282 }
2277 return true; 2283 return true;
2278 2284
2279} 2285}
2280bool CalendarView::importQtopia( const QString &categories, 2286bool CalendarView::importQtopia( const QString &categories,
2281 const QString &datebook, 2287 const QString &datebook,
2282 const QString &todolist ) 2288 const QString &todolist )
2283{ 2289{
2284 2290
2285 QtopiaFormat qtopiaFormat; 2291 QtopiaFormat qtopiaFormat;
2286 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2292 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2287 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 2293 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
2288 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 2294 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
2289 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 2295 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
2290 2296
2291 updateView(); 2297 updateView();
2292 return true; 2298 return true;
2293 2299
2294#if 0 2300#if 0
2295 mGlobalSyncMode = SYNC_MODE_QTOPIA; 2301 mGlobalSyncMode = SYNC_MODE_QTOPIA;
2296 mCurrentSyncDevice = "qtopia-XML"; 2302 mCurrentSyncDevice = "qtopia-XML";
2297 if ( mSyncManager->mAskForPreferences ) 2303 if ( mSyncManager->mAskForPreferences )
2298 edit_sync_options(); 2304 edit_sync_options();
2299 qApp->processEvents(); 2305 qApp->processEvents();
2300 CalendarLocal* calendar = new CalendarLocal(); 2306 CalendarLocal* calendar = new CalendarLocal();
2301 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2307 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2302 bool syncOK = false; 2308 bool syncOK = false;
2303 QtopiaFormat qtopiaFormat; 2309 QtopiaFormat qtopiaFormat;
2304 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2310 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2305 bool loadOk = true; 2311 bool loadOk = true;
2306 if ( !categories.isEmpty() ) 2312 if ( !categories.isEmpty() )
2307 loadOk = qtopiaFormat.load( calendar, categories ); 2313 loadOk = qtopiaFormat.load( calendar, categories );
2308 if ( loadOk && !datebook.isEmpty() ) 2314 if ( loadOk && !datebook.isEmpty() )
2309 loadOk = qtopiaFormat.load( calendar, datebook ); 2315 loadOk = qtopiaFormat.load( calendar, datebook );
2310 if ( loadOk && !todolist.isEmpty() ) 2316 if ( loadOk && !todolist.isEmpty() )
2311 loadOk = qtopiaFormat.load( calendar, todolist ); 2317 loadOk = qtopiaFormat.load( calendar, todolist );
2312 2318
2313 if ( loadOk ) { 2319 if ( loadOk ) {
2314 getEventViewerDialog()->setSyncMode( true ); 2320 getEventViewerDialog()->setSyncMode( true );
2315 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2321 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2316 getEventViewerDialog()->setSyncMode( false ); 2322 getEventViewerDialog()->setSyncMode( false );
2317 qApp->processEvents(); 2323 qApp->processEvents();
2318 if ( syncOK ) { 2324 if ( syncOK ) {
2319 if ( mSyncManager->mWriteBackFile ) 2325 if ( mSyncManager->mWriteBackFile )
2320 { 2326 {
2321 // write back XML file 2327 // write back XML file
2322 2328
2323 } 2329 }
2324 setModified( true ); 2330 setModified( true );
2325 } 2331 }
2326 } else { 2332 } else {
2327 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 2333 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
2328 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 2334 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
2329 question, i18n("Ok")) ; 2335 question, i18n("Ok")) ;
2330 } 2336 }
2331 delete calendar; 2337 delete calendar;
2332 updateView(); 2338 updateView();
2333 return syncOK; 2339 return syncOK;
2334 2340
2335 2341
2336#endif 2342#endif
2337 2343
2338} 2344}
2339 2345
2340void CalendarView::setSyncEventsReadOnly() 2346void CalendarView::setSyncEventsReadOnly()
2341{ 2347{
2342 mCalendar->setSyncEventsReadOnly(); 2348 mCalendar->setSyncEventsReadOnly();
2343} 2349}
2344 2350
2345bool CalendarView::loadCalendars() 2351bool CalendarView::loadCalendars()
2346{ 2352{
2347 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2353 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2348 KopiCalendarFile * cal = calendars.first(); 2354 KopiCalendarFile * cal = calendars.first();
2349 mCalendar->setDefaultCalendar( 1 ); 2355 mCalendar->setDefaultCalendar( 1 );
2350 openCalendar( MainWindow::defaultFileName(), false ); 2356 openCalendar( MainWindow::defaultFileName(), false );
2351 cal = calendars.next(); 2357 cal = calendars.next();
2352 while ( cal ) { 2358 while ( cal ) {
2353 addCalendar( cal ); 2359 addCalendar( cal );
2354 cal = calendars.next(); 2360 cal = calendars.next();
2355 } 2361 }
2356 restoreCalendarSettings(); 2362 restoreCalendarSettings();
2357 return true; 2363 return true;
2358} 2364}
2359bool CalendarView::restoreCalendarSettings() 2365bool CalendarView::restoreCalendarSettings()
2360{ 2366{
2361 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2367 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2362 KopiCalendarFile * cal = calendars.first(); 2368 KopiCalendarFile * cal = calendars.first();
2363 while ( cal ) { 2369 while ( cal ) {
2364 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 2370 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
2365 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 2371 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
2366 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 2372 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
2367 if ( cal->isStandard ) 2373 if ( cal->isStandard )
2368 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2374 mCalendar->setDefaultCalendar( cal->mCalNumber );
2369 cal = calendars.next(); 2375 cal = calendars.next();
2370 } 2376 }
2371 setSyncEventsReadOnly(); 2377 setSyncEventsReadOnly();
2372 mCalendar->reInitAlarmSettings(); 2378 mCalendar->reInitAlarmSettings();
2373 updateUnmanagedViews(); 2379 updateUnmanagedViews();
2374 updateView(); 2380 updateView();
2375 return true; 2381 return true;
2376} 2382}
2377void CalendarView::addCalendarId( int id ) 2383void CalendarView::addCalendarId( int id )
2378{ 2384{
2379 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 2385 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
2380 if ( cal ) 2386 if ( cal )
2381 addCalendar( cal ); 2387 addCalendar( cal );
2382} 2388}
2383bool CalendarView::addCalendar( KopiCalendarFile * cal ) 2389bool CalendarView::addCalendar( KopiCalendarFile * cal )
2384{ 2390{
2385 cal->mErrorOnLoad = false; 2391 cal->mErrorOnLoad = false;
2386 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 2392 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
2387 cal->mLoadDt = QDateTime::currentDateTime(); 2393 cal->mLoadDt = QDateTime::currentDateTime();
2388 return true; 2394 return true;
2389 } 2395 }
2390 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); 2396 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() );
2391 cal->mErrorOnLoad = true; 2397 cal->mErrorOnLoad = true;
2392 return false; 2398 return false;
2393} 2399}
2394bool CalendarView::openCalendar(QString filename, bool merge) 2400bool CalendarView::openCalendar(QString filename, bool merge)
2395{ 2401{
2396 2402
2397 if (filename.isEmpty()) { 2403 if (filename.isEmpty()) {
2398 return false; 2404 return false;
2399 } 2405 }
2400 2406
2401 if (!QFile::exists(filename)) { 2407 if (!QFile::exists(filename)) {
2402 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 2408 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
2403 return false; 2409 return false;
2404 } 2410 }
2405 2411
2406 globalFlagBlockAgenda = 1; 2412 globalFlagBlockAgenda = 1;
2407 clearAllViews(); 2413 clearAllViews();
2408 if (!merge) { 2414 if (!merge) {
2409 mViewManager->setDocumentId( filename ); 2415 mViewManager->setDocumentId( filename );
2410 mCalendar->close(); 2416 mCalendar->close();
2411 } 2417 }
2412 mStorage->setFileName( filename ); 2418 mStorage->setFileName( filename );
2413 2419
2414 if ( mStorage->load() ) { 2420 if ( mStorage->load() ) {
2415 if ( merge ) ;//setModified( true ); 2421 if ( merge ) ;//setModified( true );
2416 else { 2422 else {
2417 //setModified( true ); 2423 //setModified( true );
2418 mViewManager->setDocumentId( filename ); 2424 mViewManager->setDocumentId( filename );
2419 mDialogManager->setDocumentId( filename ); 2425 mDialogManager->setDocumentId( filename );
2420 mTodoList->setDocumentId( filename ); 2426 mTodoList->setDocumentId( filename );
2421 } 2427 }
2422 globalFlagBlockAgenda = 2; 2428 globalFlagBlockAgenda = 2;
2423 // if ( getLastSyncEvent() ) 2429 // if ( getLastSyncEvent() )
2424 // getLastSyncEvent()->setReadOnly( true ); 2430 // getLastSyncEvent()->setReadOnly( true );
2425 mCalendar->reInitAlarmSettings(); 2431 mCalendar->reInitAlarmSettings();
2426 setSyncEventsReadOnly(); 2432 setSyncEventsReadOnly();
2427 //updateUnmanagedViews(); 2433 //updateUnmanagedViews();
2428 //updateView(); 2434 //updateView();
2429 if ( filename != MainWindow::defaultFileName() ) { 2435 if ( filename != MainWindow::defaultFileName() ) {
2430 saveCalendar( MainWindow::defaultFileName() ); 2436 saveCalendar( MainWindow::defaultFileName() );
2431 } else { 2437 } else {
2432 QFileInfo finf ( MainWindow::defaultFileName()); 2438 QFileInfo finf ( MainWindow::defaultFileName());
2433 if ( finf.exists() ) { 2439 if ( finf.exists() ) {
2434 setLoadedFileVersion( finf.lastModified () ); 2440 setLoadedFileVersion( finf.lastModified () );
2435 } 2441 }
2436 } 2442 }
2437 return true; 2443 return true;
2438 } else { 2444 } else {
2439 // while failing to load, the calendar object could 2445 // while failing to load, the calendar object could
2440 // have become partially populated. Clear it out. 2446 // have become partially populated. Clear it out.
2441 if ( !merge ) { 2447 if ( !merge ) {
2442 mCalendar->close(); 2448 mCalendar->close();
2443 mViewManager->setDocumentId( filename ); 2449 mViewManager->setDocumentId( filename );
2444 mDialogManager->setDocumentId( filename ); 2450 mDialogManager->setDocumentId( filename );
2445 mTodoList->setDocumentId( filename ); 2451 mTodoList->setDocumentId( filename );
2446 } 2452 }
2447 2453
2448 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 2454 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
2449 2455
2450 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 2456 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
2451 globalFlagBlockAgenda = 2; 2457 globalFlagBlockAgenda = 2;
2452 mCalendar->reInitAlarmSettings(); 2458 mCalendar->reInitAlarmSettings();
2453 setSyncEventsReadOnly(); 2459 setSyncEventsReadOnly();
2454 updateUnmanagedViews(); 2460 updateUnmanagedViews();
2455 updateView(); 2461 updateView();
2456 } 2462 }
2457 return false; 2463 return false;
2458} 2464}
2459void CalendarView::mergeFile( QString fn ) 2465void CalendarView::mergeFile( QString fn )
2460{ 2466{
2461 clearAllViews(); 2467 clearAllViews();
2462 mCalendar->mergeCalendarFile( fn ); 2468 mCalendar->mergeCalendarFile( fn );
2463 mCalendar->reInitAlarmSettings(); 2469 mCalendar->reInitAlarmSettings();
2464 setSyncEventsReadOnly(); 2470 setSyncEventsReadOnly();
2465 updateUnmanagedViews(); 2471 updateUnmanagedViews();
2466 updateView(); 2472 updateView();
2467} 2473}
2468void CalendarView::mergeFileResource( QString fn ,QString resource ) 2474void CalendarView::mergeFileResource( QString fn ,QString resource )
2469{ 2475{
2470 2476
2471 if ( resource == "ALL" ) { 2477 if ( resource == "ALL" ) {
2472 mCalendar->setAllCalendarEnabled( true ); 2478 mCalendar->setAllCalendarEnabled( true );
2473 mergeFile( fn ); 2479 mergeFile( fn );
2474 restoreCalendarSettings(); 2480 restoreCalendarSettings();
2475 return; 2481 return;
2476 } 2482 }
2477 2483
2478 int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); 2484 int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource );
2479 if ( !exclusiveResource ) { 2485 if ( !exclusiveResource ) {
2480 qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() ); 2486 qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() );
2481 return; 2487 return;
2482 } 2488 }
2483 clearAllViews(); 2489 clearAllViews();
2484 mCalendar->setCalendarRemove( exclusiveResource ); 2490 mCalendar->setCalendarRemove( exclusiveResource );
2485 int def = mCalendar->defaultCalendar();
2486 mCalendar->setDefaultCalendar(exclusiveResource); 2491 mCalendar->setDefaultCalendar(exclusiveResource);
2492 mCalendar->setAllCalendarEnabled( true );
2487 if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) { 2493 if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) {
2488 qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() ); 2494 qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() );
2489 } 2495 }
2490 mCalendar->setDefaultCalendar( def ); 2496 restoreCalendarSettings();
2491 mCalendar->reInitAlarmSettings();
2492 setSyncEventsReadOnly();
2493 updateUnmanagedViews();
2494 updateView();
2495} 2497}
2496void CalendarView::showOpenError() 2498void CalendarView::showOpenError()
2497{ 2499{
2498 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 2500 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
2499} 2501}
2500void CalendarView::setLoadedFileVersion(QDateTime dt) 2502void CalendarView::setLoadedFileVersion(QDateTime dt)
2501{ 2503{
2502 loadedFileVersion = dt; 2504 loadedFileVersion = dt;
2503} 2505}
2504bool CalendarView::checkFileChanged(QString fn) 2506bool CalendarView::checkFileChanged(QString fn)
2505{ 2507{
2506 QFileInfo finf ( fn ); 2508 QFileInfo finf ( fn );
2507 if ( !finf.exists() ) 2509 if ( !finf.exists() )
2508 return true; 2510 return true;
2509 QDateTime dt = finf.lastModified (); 2511 QDateTime dt = finf.lastModified ();
2510 if ( dt <= loadedFileVersion ) 2512 if ( dt <= loadedFileVersion )
2511 return false; 2513 return false;
2512 return true; 2514 return true;
2513 2515
2514} 2516}
2515void CalendarView::watchSavedFile() 2517void CalendarView::watchSavedFile()
2516{ 2518{
2517 QFileInfo finf ( MainWindow::defaultFileName()); 2519 QFileInfo finf ( MainWindow::defaultFileName());
2518 if ( !finf.exists() ) 2520 if ( !finf.exists() )
2519 return; 2521 return;
2520 QDateTime dt = finf.lastModified (); 2522 QDateTime dt = finf.lastModified ();
2521 if ( dt < loadedFileVersion ) { 2523 if ( dt < loadedFileVersion ) {
2522 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 2524 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
2523 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 2525 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
2524 return; 2526 return;
2525 } 2527 }
2526 loadedFileVersion = dt; 2528 loadedFileVersion = dt;
2527} 2529}
2528bool CalendarView::checkAllFileVersions() 2530bool CalendarView::checkAllFileVersions()
2529{ 2531{
2530 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2532 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2531 KopiCalendarFile * cal = calendars.first(); 2533 KopiCalendarFile * cal = calendars.first();
2532 mCalendar->setDefaultCalendar( 1 ); 2534 mCalendar->setDefaultCalendar( 1 );
2533 mCalendar->setDefaultCalendarEnabledOnly(); 2535 mCalendar->setDefaultCalendarEnabledOnly();
2534 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2536 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2535 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2537 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2536 restoreCalendarSettings(); 2538 restoreCalendarSettings();
2537 return false; 2539 return false;
2538 } 2540 }
2539 } 2541 }
2540 cal = calendars.next(); 2542 cal = calendars.next();
2541 QDateTime storeTemp = loadedFileVersion; 2543 QDateTime storeTemp = loadedFileVersion;
2542 while ( cal ) { 2544 while ( cal ) {
2543 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2545 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2544 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2546 mCalendar->setDefaultCalendar( cal->mCalNumber );
2545 mCalendar->setDefaultCalendarEnabledOnly(); 2547 mCalendar->setDefaultCalendarEnabledOnly();
2546 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2548 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2547 if ( !checkFileVersion(cal->mFileName )) { 2549 if ( !checkFileVersion(cal->mFileName )) {
2548 loadedFileVersion = storeTemp; 2550 loadedFileVersion = storeTemp;
2549 restoreCalendarSettings(); 2551 restoreCalendarSettings();
2550 return false; 2552 return false;
2551 } 2553 }
2552 } 2554 }
2553 cal = calendars.next(); 2555 cal = calendars.next();
2554 } 2556 }
2555 loadedFileVersion = storeTemp; 2557 loadedFileVersion = storeTemp;
2556 return true; 2558 return true;
2557} 2559}
2558bool CalendarView::checkFileVersion(QString fn) 2560bool CalendarView::checkFileVersion(QString fn)
2559{ 2561{
2560 QFileInfo finf ( fn ); 2562 QFileInfo finf ( fn );
2561 if ( !finf.exists() ) 2563 if ( !finf.exists() )
2562 return true; 2564 return true;
2563 QDateTime dt = finf.lastModified (); 2565 QDateTime dt = finf.lastModified ();
2564 //qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2566 //qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2565 //qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2567 //qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2566 if ( dt <= loadedFileVersion ) 2568 if ( dt <= loadedFileVersion )
2567 return true; 2569 return true;
2568 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)) , 2570 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)) ,
2569 i18n("KO/Pi Warning"),i18n("Overwrite"), 2571 i18n("KO/Pi Warning"),i18n("Overwrite"),
2570 i18n("Sync+save")); 2572 i18n("Sync+save"));
2571 2573
2572 if ( km == KMessageBox::Cancel ) 2574 if ( km == KMessageBox::Cancel )
2573 return false; 2575 return false;
2574 if ( km == KMessageBox::Yes ) 2576 if ( km == KMessageBox::Yes )
2575 return true; 2577 return true;
2576 2578
2577 setSyncDevice("deleteaftersync" ); 2579 setSyncDevice("deleteaftersync" );
2578 mSyncManager->mAskForPreferences = true; 2580 mSyncManager->mAskForPreferences = true;
2579 mSyncManager->mSyncAlgoPrefs = 3; 2581 mSyncManager->mSyncAlgoPrefs = 3;
2580 mSyncManager->mWriteBackFile = false; 2582 mSyncManager->mWriteBackFile = false;
2581 mSyncManager->mWriteBackExistingOnly = false; 2583 mSyncManager->mWriteBackExistingOnly = false;
2582 mSyncManager->mShowSyncSummary = false; 2584 mSyncManager->mShowSyncSummary = false;
2583 mMultiResourceSync = false; 2585 mMultiResourceSync = false;
2584 syncCalendar( fn, 3 ); 2586 syncCalendar( fn, 3 );
2585 Event * e = getLastSyncEvent(); 2587 Event * e = getLastSyncEvent();
2586 if ( e ) 2588 if ( e )
2587 mCalendar->deleteEvent( e ); 2589 mCalendar->deleteEvent( e );
2588 return true; 2590 return true;
2589} 2591}
2590bool CalendarView::saveCalendars() 2592bool CalendarView::saveCalendars()
2591{ 2593{
2592 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2594 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2593 KopiCalendarFile * cal = calendars.first(); 2595 KopiCalendarFile * cal = calendars.first();
2594 mCalendar->setDefaultCalendar( 1 ); 2596 mCalendar->setDefaultCalendar( 1 );
2595 mCalendar->setDefaultCalendarEnabledOnly(); 2597 mCalendar->setDefaultCalendarEnabledOnly();
2596 QString saveError; 2598 QString saveError;
2597 if ( !saveCalendar( MainWindow::defaultFileName() ) ) 2599 if ( !saveCalendar( MainWindow::defaultFileName() ) )
2598 saveError = cal->mName +"\n"; 2600 saveError = cal->mName +"\n";
2599 cal = calendars.next(); 2601 cal = calendars.next();
2600 while ( cal ) { 2602 while ( cal ) {
2601 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2603 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2602 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2604 mCalendar->setDefaultCalendar( cal->mCalNumber );
2603 mCalendar->setDefaultCalendarEnabledOnly(); 2605 mCalendar->setDefaultCalendarEnabledOnly();
2604 if ( saveCalendar( cal->mFileName ) ) 2606 if ( saveCalendar( cal->mFileName ) )
2605 cal->mLoadDt = QDateTime::currentDateTime(); 2607 cal->mLoadDt = QDateTime::currentDateTime();
2606 else 2608 else
2607 saveError += cal->mName + "\n"; 2609 saveError += cal->mName + "\n";
2608 } 2610 }
2609 cal = calendars.next(); 2611 cal = calendars.next();
2610 } 2612 }
2611 restoreCalendarSettings(); 2613 restoreCalendarSettings();
2612 //saveError = "test error"; 2614 //saveError = "test error";
2613 if ( !saveError.isEmpty() ) { 2615 if ( !saveError.isEmpty() ) {
2614 saveError = KGlobal::formatMessage( i18n("Calendar(s) not saved:"),0 )+"\n" + saveError; 2616 saveError = KGlobal::formatMessage( i18n("Calendar(s) not saved:"),0 )+"\n" + saveError;
2615 KMessageBox::error(this, saveError, i18n("Error saving data")); 2617 KMessageBox::error(this, saveError, i18n("Error saving data"));
2616 return false; 2618 return false;
2617 } 2619 }
2618 return true; 2620 return true;
2619} 2621}
2620bool CalendarView::saveCalendarResource(QString filename, QString resource) 2622bool CalendarView::saveCalendarResource(QString filename, QString resource)
2621{ 2623{
2622 if ( resource == "ALL" ) { 2624 if ( resource == "ALL" ) {
2623 mCalendar->setAllCalendarEnabled( true ); 2625 mCalendar->setAllCalendarEnabled( true );
2624 bool retval = saveCalendar( filename ); 2626 bool retval = saveCalendar( filename );
2625 restoreCalendarSettings(); 2627 restoreCalendarSettings();
2626 return retval; 2628 return retval;
2627 } 2629 }
2628 int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); 2630 int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource );
2629 if ( !exclusiveResource ) { 2631 if ( !exclusiveResource ) {
2630 qDebug("KO: CalendarView::saveCalendarResource: resource not found %s", resource.latin1() ); 2632 qDebug("KO: CalendarView::saveCalendarResource: resource not found %s", resource.latin1() );
2631 return false; 2633 return false;
2632 } 2634 }
2633 mCalendar->setDefaultCalendar( exclusiveResource ); 2635 mCalendar->setDefaultCalendar( exclusiveResource );
2634 mCalendar->setDefaultCalendarEnabledOnly(); 2636 mCalendar->setDefaultCalendarEnabledOnly();
2635 mCalendar->setSyncEventsEnabled(); 2637 mCalendar->setSyncEventsEnabled();
2636 bool res = saveCalendar( filename ); 2638 bool res = saveCalendar( filename );
2637 restoreCalendarSettings(); 2639 restoreCalendarSettings();
2638 return res; 2640 return res;
2639 2641
2640} 2642}
2641bool CalendarView::saveCalendar( QString filename ) 2643bool CalendarView::saveCalendar( QString filename )
2642{ 2644{
2643 2645
2644 // Store back all unsaved data into calendar object 2646 // Store back all unsaved data into calendar object
2645 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2647 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2646 if ( mViewManager->currentView() ) 2648 if ( mViewManager->currentView() )
2647 mViewManager->currentView()->flushView(); 2649 mViewManager->currentView()->flushView();
2648 2650
2649 2651
2650 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2652 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2651 mStorage->setSaveFormat( new ICalFormat() ); 2653 mStorage->setSaveFormat( new ICalFormat() );
2652 mStorage->setFileName( filename ); 2654 mStorage->setFileName( filename );
2653 bool success; 2655 bool success;
2654 success = mStorage->save(); 2656 success = mStorage->save();
2655 if ( !success ) { 2657 if ( !success ) {
2656 return false; 2658 return false;
2657 } 2659 }
2658 if ( filename == MainWindow::defaultFileName() ) { 2660 if ( filename == MainWindow::defaultFileName() ) {
2659 setLoadedFileVersion( lfv ); 2661 setLoadedFileVersion( lfv );
2660 watchSavedFile(); 2662 watchSavedFile();
2661 } 2663 }
2662 return true; 2664 return true;
2663} 2665}
2664 2666
2665void CalendarView::closeCalendar() 2667void CalendarView::closeCalendar()
2666{ 2668{
2667 2669
2668 // child windows no longer valid 2670 // child windows no longer valid
2669 clearAllViews(); 2671 clearAllViews();
2670 emit closingDown(); 2672 emit closingDown();
2671 2673
2672 mCalendar->close(); 2674 mCalendar->close();
2673 setModified(false); 2675 setModified(false);
2674 updateView(); 2676 updateView();
2675} 2677}
2676 2678
2677void CalendarView::archiveCalendar() 2679void CalendarView::archiveCalendar()
2678{ 2680{
2679 mDialogManager->showArchiveDialog(); 2681 mDialogManager->showArchiveDialog();
2680} 2682}
2681 2683
2682 2684
2683void CalendarView::readSettings() 2685void CalendarView::readSettings()
2684{ 2686{
2685 2687
2686 2688
2687 // mViewManager->showAgendaView(); 2689 // mViewManager->showAgendaView();
2688 QString str; 2690 QString str;
2689 //qDebug("CalendarView::readSettings() "); 2691 //qDebug("CalendarView::readSettings() ");
2690 // read settings from the KConfig, supplying reasonable 2692 // read settings from the KConfig, supplying reasonable
2691 // defaults where none are to be found 2693 // defaults where none are to be found
2692 KConfig *config = KOGlobals::config(); 2694 KConfig *config = KOGlobals::config();
2693#ifndef KORG_NOSPLITTER 2695#ifndef KORG_NOSPLITTER
2694 config->setGroup("KOrganizer Geometry"); 2696 config->setGroup("KOrganizer Geometry");
2695 2697
2696 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2698 QValueList<int> sizes = config->readIntListEntry("Separator1");
2697 if (sizes.count() != 2) { 2699 if (sizes.count() != 2) {
2698 sizes << mDateNavigator->minimumSizeHint().width(); 2700 sizes << mDateNavigator->minimumSizeHint().width();
2699 sizes << 300; 2701 sizes << 300;
2700 } 2702 }
2701 mPanner->setSizes(sizes); 2703 mPanner->setSizes(sizes);
2702 2704
2703 sizes = config->readIntListEntry("Separator2"); 2705 sizes = config->readIntListEntry("Separator2");
2704 if ( ( mResourceView && sizes.count() == 4 ) || 2706 if ( ( mResourceView && sizes.count() == 4 ) ||
2705 ( !mResourceView && sizes.count() == 3 ) ) { 2707 ( !mResourceView && sizes.count() == 3 ) ) {
2706 mLeftSplitter->setSizes(sizes); 2708 mLeftSplitter->setSizes(sizes);
2707 } 2709 }
2708#endif 2710#endif
2709 globalFlagBlockAgenda = 1; 2711 globalFlagBlockAgenda = 1;
2710 mViewManager->showAgendaView(); 2712 mViewManager->showAgendaView();
2711 //mViewManager->readSettings( config ); 2713 //mViewManager->readSettings( config );
2712 mTodoList->restoreLayout(config,QString("Todo Layout")); 2714 mTodoList->restoreLayout(config,QString("Todo Layout"));
2713 readFilterSettings(config); 2715 readFilterSettings(config);
2714 2716
2715#ifdef DESKTOP_VERSION 2717#ifdef DESKTOP_VERSION
2716 config->setGroup("WidgetLayout"); 2718 config->setGroup("WidgetLayout");
2717 QStringList list; 2719 QStringList list;
2718 list = config->readListEntry("MainLayout"); 2720 list = config->readListEntry("MainLayout");
2719 int x,y,w,h; 2721 int x,y,w,h;
2720 if ( ! list.isEmpty() ) { 2722 if ( ! list.isEmpty() ) {
2721 x = list[0].toInt(); 2723 x = list[0].toInt();
2722 y = list[1].toInt(); 2724 y = list[1].toInt();
2723 w = list[2].toInt(); 2725 w = list[2].toInt();
2724 h = list[3].toInt(); 2726 h = list[3].toInt();
2725 KApplication::testCoords( &x,&y,&w,&h ); 2727 KApplication::testCoords( &x,&y,&w,&h );
2726 topLevelWidget()->setGeometry(x,y,w,h); 2728 topLevelWidget()->setGeometry(x,y,w,h);
2727 2729
2728 } else { 2730 } else {
2729 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2731 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2730 } 2732 }
2731 list = config->readListEntry("EditEventLayout"); 2733 list = config->readListEntry("EditEventLayout");
2732 if ( ! list.isEmpty() ) { 2734 if ( ! list.isEmpty() ) {
2733 x = list[0].toInt(); 2735 x = list[0].toInt();
2734 y = list[1].toInt(); 2736 y = list[1].toInt();
2735 w = list[2].toInt(); 2737 w = list[2].toInt();
2736 h = list[3].toInt(); 2738 h = list[3].toInt();
2737 KApplication::testCoords( &x,&y,&w,&h ); 2739 KApplication::testCoords( &x,&y,&w,&h );
2738 mEventEditor->setGeometry(x,y,w,h); 2740 mEventEditor->setGeometry(x,y,w,h);
2739 2741
2740 } 2742 }
2741 list = config->readListEntry("EditTodoLayout"); 2743 list = config->readListEntry("EditTodoLayout");
2742 if ( ! list.isEmpty() ) { 2744 if ( ! list.isEmpty() ) {
2743 x = list[0].toInt(); 2745 x = list[0].toInt();
2744 y = list[1].toInt(); 2746 y = list[1].toInt();
2745 w = list[2].toInt(); 2747 w = list[2].toInt();
2746 h = list[3].toInt(); 2748 h = list[3].toInt();
2747 KApplication::testCoords( &x,&y,&w,&h ); 2749 KApplication::testCoords( &x,&y,&w,&h );
2748 mTodoEditor->setGeometry(x,y,w,h); 2750 mTodoEditor->setGeometry(x,y,w,h);
2749 2751
2750 } 2752 }
2751 list = config->readListEntry("ViewerLayout"); 2753 list = config->readListEntry("ViewerLayout");
2752 if ( ! list.isEmpty() ) { 2754 if ( ! list.isEmpty() ) {
2753 x = list[0].toInt(); 2755 x = list[0].toInt();
2754 y = list[1].toInt(); 2756 y = list[1].toInt();
2755 w = list[2].toInt(); 2757 w = list[2].toInt();
2756 h = list[3].toInt(); 2758 h = list[3].toInt();
2757 KApplication::testCoords( &x,&y,&w,&h ); 2759 KApplication::testCoords( &x,&y,&w,&h );
2758 getEventViewerDialog()->setGeometry(x,y,w,h); 2760 getEventViewerDialog()->setGeometry(x,y,w,h);
2759 } 2761 }
2760#endif 2762#endif
2761 config->setGroup( "Views" ); 2763 config->setGroup( "Views" );
2762 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2764 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2763 2765
2764 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2766 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2765 2767
2766 int resetval = 0; 2768 int resetval = 0;
2767 int maxVal = 0; 2769 int maxVal = 0;
2768 if (sizes.count() != 3) { 2770 if (sizes.count() != 3) {
2769 if ( KOPrefs::instance()->mVerticalScreen ) { 2771 if ( KOPrefs::instance()->mVerticalScreen ) {
2770 resetval = mDateNavigator->sizeHint().width()+2; 2772 resetval = mDateNavigator->sizeHint().width()+2;
2771 } else { 2773 } else {
2772 resetval = mDateNavigator->sizeHint().height()+2; 2774 resetval = mDateNavigator->sizeHint().height()+2;
2773 } 2775 }
2774 } 2776 }
2775 if ( resetval ) { 2777 if ( resetval ) {
2776 sizes.clear(); 2778 sizes.clear();
2777 if ( KOPrefs::instance()->mVerticalScreen ) { 2779 if ( KOPrefs::instance()->mVerticalScreen ) {
2778 maxVal = QApplication::desktop()->width() -10; 2780 maxVal = QApplication::desktop()->width() -10;
2779 } else { 2781 } else {
2780 maxVal = QApplication::desktop()->height()-10; 2782 maxVal = QApplication::desktop()->height()-10;
2781 } 2783 }
2782 sizes << resetval; 2784 sizes << resetval;
2783 if ( maxVal < resetval + resetval) 2785 if ( maxVal < resetval + resetval)
2784 resetval = maxVal - resetval; 2786 resetval = maxVal - resetval;
2785 sizes << resetval; 2787 sizes << resetval;
2786 sizes << 100; 2788 sizes << 100;
2787 } 2789 }
2788 mLeftFrame->setSizes(sizes); 2790 mLeftFrame->setSizes(sizes);
2789 sizes = config->readIntListEntry("Main Splitter Frame"); 2791 sizes = config->readIntListEntry("Main Splitter Frame");
2790 resetval = 0; 2792 resetval = 0;
2791 maxVal = 0; 2793 maxVal = 0;
2792 if (sizes.count() != 2) { 2794 if (sizes.count() != 2) {
2793 if ( !KOPrefs::instance()->mVerticalScreen ) { 2795 if ( !KOPrefs::instance()->mVerticalScreen ) {
2794 resetval = mDateNavigator->sizeHint().width()+2; 2796 resetval = mDateNavigator->sizeHint().width()+2;
2795 } else { 2797 } else {
2796 resetval = mDateNavigator->sizeHint().height()+2; 2798 resetval = mDateNavigator->sizeHint().height()+2;
2797 } 2799 }
2798 } 2800 }
2799 if ( resetval ) { 2801 if ( resetval ) {
2800 sizes.clear(); 2802 sizes.clear();
2801 if ( !KOPrefs::instance()->mVerticalScreen ) { 2803 if ( !KOPrefs::instance()->mVerticalScreen ) {
2802 maxVal = QApplication::desktop()->width() -10; 2804 maxVal = QApplication::desktop()->width() -10;
2803 } else { 2805 } else {
2804 maxVal = QApplication::desktop()->height()-10; 2806 maxVal = QApplication::desktop()->height()-10;
2805 } 2807 }
2806 sizes << resetval; 2808 sizes << resetval;
2807 if ( maxVal < resetval + resetval) 2809 if ( maxVal < resetval + resetval)
2808 resetval = maxVal - resetval; 2810 resetval = maxVal - resetval;
2809 sizes << resetval; 2811 sizes << resetval;
2810 } 2812 }
2811 mMainFrame->setSizes(sizes); 2813 mMainFrame->setSizes(sizes);
2812 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2814 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2813 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2815 else if ( dateCount == 7 ) mNavigator->selectWeek();
2814 else mNavigator->selectDates( dateCount ); 2816 else mNavigator->selectDates( dateCount );
2815 // mViewManager->readSettings( config ); 2817 // mViewManager->readSettings( config );
2816 updateConfig(); 2818 updateConfig();
2817 globalFlagBlockAgenda = 2; 2819 globalFlagBlockAgenda = 2;
2818 mViewManager->readSettings( config ); 2820 mViewManager->readSettings( config );
2819 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2821 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2820} 2822}
2821 2823
2822void CalendarView::checkSuspendAlarm() 2824void CalendarView::checkSuspendAlarm()
2823{ 2825{
2824 if ( mSuspendTimer->isActive() ) { 2826 if ( mSuspendTimer->isActive() ) {
2825 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm")); 2827 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm"));
2826 } 2828 }
2827} 2829}
2828void CalendarView::writeSettings() 2830void CalendarView::writeSettings()
2829{ 2831{
2830 // kdDebug() << "CalendarView::writeSettings" << endl; 2832 // kdDebug() << "CalendarView::writeSettings" << endl;
2831 2833
2832 KConfig *config = KOGlobals::config(); 2834 KConfig *config = KOGlobals::config();
2833 2835
2834 mViewManager->writeSettings( config ); 2836 mViewManager->writeSettings( config );
2835 mTodoList->saveLayout(config,QString("Todo Layout")); 2837 mTodoList->saveLayout(config,QString("Todo Layout"));
2836 mDialogManager->writeSettings( config ); 2838 mDialogManager->writeSettings( config );
2837 //KOPrefs::instance()->usrWriteConfig(); 2839 //KOPrefs::instance()->usrWriteConfig();
2838 KOPrefs::instance()->writeConfig(); 2840 KOPrefs::instance()->writeConfig();
2839 2841
2840 writeFilterSettings(config); 2842 writeFilterSettings(config);
2841 config->setGroup( "AppRun" ); 2843 config->setGroup( "AppRun" );
2842 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2844 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2843 int days = dt.daysTo( QDate::currentDate() ); 2845 int days = dt.daysTo( QDate::currentDate() );
2844 dt = dt.addDays( days ); 2846 dt = dt.addDays( days );
2845 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2847 int secs = dt.secsTo( QDateTime::currentDateTime() );
2846 config->writeEntry( "LatestProgramStopDays", days ); 2848 config->writeEntry( "LatestProgramStopDays", days );
2847 config->writeEntry( "LatestProgramStopSecs", secs ); 2849 config->writeEntry( "LatestProgramStopSecs", secs );
2848 //qDebug("KO: Writing stop time: %d ", secs); 2850 //qDebug("KO: Writing stop time: %d ", secs);
2849 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2851 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2850 //QDateTime latest = dt.addSecs ( secs ); 2852 //QDateTime latest = dt.addSecs ( secs );
2851 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2853 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2852 config->setGroup( "Views" ); 2854 config->setGroup( "Views" );
2853 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2855 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2854 2856
2855#if 0 2857#if 0
2856 qDebug("********************* "); 2858 qDebug("********************* ");
2857 qDebug("Testcode secsto "); 2859 qDebug("Testcode secsto ");
2858 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2860 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2859 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2861 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2860 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2862 int secsto = dt_nodaylight.secsTo( dt_daylight );
2861 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2863 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2862 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2864 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2863 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2865 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2864 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2866 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2865 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2867 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2866 qDebug("********************* testcode end"); 2868 qDebug("********************* testcode end");
2867 2869
2868#endif 2870#endif
2869 2871
2870 QValueList<int> listINT = mLeftFrame->sizes(); 2872 QValueList<int> listINT = mLeftFrame->sizes();
2871 config->writeEntry("Left Splitter Frame",listINT); 2873 config->writeEntry("Left Splitter Frame",listINT);
2872 QValueList<int> listINT2 = mMainFrame->sizes(); 2874 QValueList<int> listINT2 = mMainFrame->sizes();
2873 config->writeEntry("Main Splitter Frame",listINT2); 2875 config->writeEntry("Main Splitter Frame",listINT2);
2874#ifdef DESKTOP_VERSION 2876#ifdef DESKTOP_VERSION
2875 config->setGroup("WidgetLayout"); 2877 config->setGroup("WidgetLayout");
2876 QStringList list ;//= config->readListEntry("MainLayout"); 2878 QStringList list ;//= config->readListEntry("MainLayout");
2877 int x,y,w,h; 2879 int x,y,w,h;
2878 QWidget* wid; 2880 QWidget* wid;
2879 wid = topLevelWidget(); 2881 wid = topLevelWidget();
2880 x = wid->geometry().x(); 2882 x = wid->geometry().x();
2881 y = wid->geometry().y(); 2883 y = wid->geometry().y();
2882 w = wid->width(); 2884 w = wid->width();
2883 h = wid->height(); 2885 h = wid->height();
2884 list.clear(); 2886 list.clear();
2885 list << QString::number( x ); 2887 list << QString::number( x );
2886 list << QString::number( y ); 2888 list << QString::number( y );
2887 list << QString::number( w ); 2889 list << QString::number( w );
2888 list << QString::number( h ); 2890 list << QString::number( h );
2889 config->writeEntry("MainLayout",list ); 2891 config->writeEntry("MainLayout",list );
2890 2892
2891 wid = mEventEditor; 2893 wid = mEventEditor;
2892 x = wid->geometry().x(); 2894 x = wid->geometry().x();
2893 y = wid->geometry().y(); 2895 y = wid->geometry().y();
2894 w = wid->width(); 2896 w = wid->width();
2895 h = wid->height(); 2897 h = wid->height();
2896 list.clear(); 2898 list.clear();
2897 list << QString::number( x ); 2899 list << QString::number( x );
2898 list << QString::number( y ); 2900 list << QString::number( y );
2899 list << QString::number( w ); 2901 list << QString::number( w );
2900 list << QString::number( h ); 2902 list << QString::number( h );
2901 config->writeEntry("EditEventLayout",list ); 2903 config->writeEntry("EditEventLayout",list );
2902 2904
2903 wid = mTodoEditor; 2905 wid = mTodoEditor;
2904 x = wid->geometry().x(); 2906 x = wid->geometry().x();
2905 y = wid->geometry().y(); 2907 y = wid->geometry().y();
2906 w = wid->width(); 2908 w = wid->width();
2907 h = wid->height(); 2909 h = wid->height();
2908 list.clear(); 2910 list.clear();
2909 list << QString::number( x ); 2911 list << QString::number( x );
2910 list << QString::number( y ); 2912 list << QString::number( y );
2911 list << QString::number( w ); 2913 list << QString::number( w );
2912 list << QString::number( h ); 2914 list << QString::number( h );
2913 config->writeEntry("EditTodoLayout",list ); 2915 config->writeEntry("EditTodoLayout",list );
2914 wid = getEventViewerDialog(); 2916 wid = getEventViewerDialog();
2915 x = wid->geometry().x(); 2917 x = wid->geometry().x();
2916 y = wid->geometry().y(); 2918 y = wid->geometry().y();
2917 w = wid->width(); 2919 w = wid->width();
2918 h = wid->height(); 2920 h = wid->height();
2919 list.clear(); 2921 list.clear();
2920 list << QString::number( x ); 2922 list << QString::number( x );
2921 list << QString::number( y ); 2923 list << QString::number( y );
2922 list << QString::number( w ); 2924 list << QString::number( w );
2923 list << QString::number( h ); 2925 list << QString::number( h );
2924 config->writeEntry("ViewerLayout",list ); 2926 config->writeEntry("ViewerLayout",list );
2925 wid = mDialogManager->getSearchDialog(); 2927 wid = mDialogManager->getSearchDialog();
2926 if ( wid ) { 2928 if ( wid ) {
2927 x = wid->geometry().x(); 2929 x = wid->geometry().x();
2928 y = wid->geometry().y(); 2930 y = wid->geometry().y();
2929 w = wid->width(); 2931 w = wid->width();
2930 h = wid->height(); 2932 h = wid->height();
2931 list.clear(); 2933 list.clear();
2932 list << QString::number( x ); 2934 list << QString::number( x );
2933 list << QString::number( y ); 2935 list << QString::number( y );
2934 list << QString::number( w ); 2936 list << QString::number( w );
2935 list << QString::number( h ); 2937 list << QString::number( h );
2936 config->writeEntry("SearchLayout",list ); 2938 config->writeEntry("SearchLayout",list );
2937 } 2939 }
2938#endif 2940#endif
2939 2941
2940 2942
2941 config->sync(); 2943 config->sync();
2942} 2944}
2943 2945
2944void CalendarView::readFilterSettings(KConfig *config) 2946void CalendarView::readFilterSettings(KConfig *config)
2945{ 2947{
2946 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2948 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2947 2949
2948 mFilters.clear(); 2950 mFilters.clear();
2949 2951
2950 config->setGroup("General"); 2952 config->setGroup("General");
2951 QStringList filterList = config->readListEntry("CalendarFilters"); 2953 QStringList filterList = config->readListEntry("CalendarFilters");
2952 2954
2953 QStringList::ConstIterator it = filterList.begin(); 2955 QStringList::ConstIterator it = filterList.begin();
2954 QStringList::ConstIterator end = filterList.end(); 2956 QStringList::ConstIterator end = filterList.end();
2955 while(it != end) { 2957 while(it != end) {
2956 // kdDebug() << " filter: " << (*it) << endl; 2958 // kdDebug() << " filter: " << (*it) << endl;
2957 2959
2958 CalFilter *filter; 2960 CalFilter *filter;
2959 filter = new CalFilter(*it); 2961 filter = new CalFilter(*it);
2960 config->setGroup("Filter_" + (*it).utf8()); 2962 config->setGroup("Filter_" + (*it).utf8());
2961 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2963 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2962 filter->setCriteria(config->readNumEntry("Criteria",0)); 2964 filter->setCriteria(config->readNumEntry("Criteria",0));
2963 filter->setCategoryList(config->readListEntry("CategoryList")); 2965 filter->setCategoryList(config->readListEntry("CategoryList"));
2964 mFilters.append(filter); 2966 mFilters.append(filter);
2965 2967
2966 ++it; 2968 ++it;
2967 } 2969 }
2968 2970
2969 if (mFilters.count() == 0) { 2971 if (mFilters.count() == 0) {
2970 CalFilter *filter = new CalFilter(i18n("Default")); 2972 CalFilter *filter = new CalFilter(i18n("Default"));
2971 mFilters.append(filter); 2973 mFilters.append(filter);
2972 } 2974 }
2973 mFilterView->updateFilters(); 2975 mFilterView->updateFilters();
2974 config->setGroup("FilterView"); 2976 config->setGroup("FilterView");
2975 2977
2976 mFilterView->blockSignals(true); 2978 mFilterView->blockSignals(true);
2977 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2979 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2978 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2980 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2979 mFilterView->blockSignals(false); 2981 mFilterView->blockSignals(false);
2980 // We do it manually to avoid it being done twice by the above calls 2982 // We do it manually to avoid it being done twice by the above calls
2981 updateFilter(); 2983 updateFilter();
2982} 2984}
2983 2985
2984void CalendarView::writeFilterSettings(KConfig *config) 2986void CalendarView::writeFilterSettings(KConfig *config)
2985{ 2987{
2986 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2988 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2987 2989
2988 QStringList filterList; 2990 QStringList filterList;
2989 2991
2990 CalFilter *filter = mFilters.first(); 2992 CalFilter *filter = mFilters.first();
2991 while(filter) { 2993 while(filter) {
2992 // kdDebug() << " fn: " << filter->name() << endl; 2994 // kdDebug() << " fn: " << filter->name() << endl;
2993 filterList << filter->name(); 2995 filterList << filter->name();
2994 config->setGroup("Filter_" + filter->name().utf8()); 2996 config->setGroup("Filter_" + filter->name().utf8());
2995 config->writeEntry("Criteria",filter->criteria()); 2997 config->writeEntry("Criteria",filter->criteria());
2996 config->writeEntry("CategoryList",filter->categoryList()); 2998 config->writeEntry("CategoryList",filter->categoryList());
2997 filter = mFilters.next(); 2999 filter = mFilters.next();
2998 } 3000 }
2999 config->setGroup("General"); 3001 config->setGroup("General");
3000 config->writeEntry("CalendarFilters",filterList); 3002 config->writeEntry("CalendarFilters",filterList);
3001 3003
3002 config->setGroup("FilterView"); 3004 config->setGroup("FilterView");
3003 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 3005 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
3004 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 3006 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
3005} 3007}
3006 3008
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 980663f..8a5a76f 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,821 +1,830 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 registerObserver( 0 ); 68 registerObserver( 0 );
69 if ( mDeleteIncidencesOnClose ) 69 if ( mDeleteIncidencesOnClose )
70 close(); 70 close();
71} 71}
72bool CalendarLocal::mergeCalendarFile( QString name ) 72bool CalendarLocal::mergeCalendarFile( QString name )
73{ 73{
74 CalendarLocal calendar( timeZoneId() ); 74 CalendarLocal calendar( timeZoneId() );
75 calendar.setDefaultCalendar( 1 ); 75 calendar.setDefaultCalendar( 1 );
76 if ( calendar.load( name ) ) { 76 if ( calendar.load( name ) ) {
77 mergeCalendar( &calendar ); 77 mergeCalendar( &calendar );
78 return true; 78 return true;
79 } 79 }
80 return false; 80 return false;
81} 81}
82 82
83Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup ) 83Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup )
84{ 84{
85 85
86 int calID = 0; 86 int calID = 0;
87 if ( isDup && *isDup > 0 ) 87 if ( isDup && *isDup > 0 )
88 calID = *isDup; 88 calID = *isDup;
89 Todo *todo;; 89 Todo *todo;;
90 Todo *retVal = 0; 90 Todo *retVal = 0;
91 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 91 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
92 if ( todo->uid() == uid ) { 92 if ( todo->uid() == uid ) {
93 if( calID ) { 93 if( calID ) {
94 if ( todo->calID() != calID ) 94 if ( todo->calID() != calID )
95 continue; 95 continue;
96 } 96 }
97 else { 97 else {
98 if ( enabledOnly ) { 98 if ( enabledOnly ) {
99 if ( !todo->calEnabled() ) { 99 if ( !todo->calEnabled() ) {
100 if ( isDup ) 100 if ( isDup )
101 *isDup = todo->calID(); 101 *isDup = todo->calID();
102 continue; 102 continue;
103 } 103 }
104 } 104 }
105 } 105 }
106 if ( doNotCheckDuplicates ) return todo; 106 if ( doNotCheckDuplicates ) return todo;
107 if ( retVal ) { 107 if ( retVal ) {
108 if ( retVal->calID() > todo->calID() ) { 108 if ( retVal->calID() > todo->calID() ) {
109 if ( isDup ) 109 if ( isDup )
110 *isDup = retVal->calID(); 110 *isDup = retVal->calID();
111 retVal = todo; 111 retVal = todo;
112 } 112 }
113 } else { 113 } else {
114 retVal = todo; 114 retVal = todo;
115 } 115 }
116 } 116 }
117 } 117 }
118 return retVal; 118 return retVal;
119} 119}
120//if ( isDup) and * isDup == 0: store duplicate found cal id in isDup 120//if ( isDup) and * isDup == 0: store duplicate found cal id in isDup
121//if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly 121//if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly
122 122
123Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup ) 123Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup )
124{ 124{
125 int calID = 0; 125 int calID = 0;
126 if ( isDup && *isDup > 0 ) 126 if ( isDup && *isDup > 0 )
127 calID = *isDup; 127 calID = *isDup;
128 Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup ); 128 Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup );
129 if ( retVal ) return retVal; 129 if ( retVal ) return retVal;
130 Event *event; 130 Event *event;
131 for ( event = mEventList.first(); event; event = mEventList.next() ) { 131 for ( event = mEventList.first(); event; event = mEventList.next() ) {
132 if ( event->uid() == uid ) { 132 if ( event->uid() == uid ) {
133 if( calID ) { 133 if( calID ) {
134 if ( event->calID() != calID ) 134 if ( event->calID() != calID )
135 continue; 135 continue;
136 } 136 }
137 else { 137 else {
138 if ( enabledOnly ) { 138 if ( enabledOnly ) {
139 if ( !event->calEnabled() ) { 139 if ( !event->calEnabled() ) {
140 if ( isDup ) 140 if ( isDup )
141 *isDup =event->calID() ; 141 *isDup =event->calID() ;
142 continue; 142 continue;
143 } 143 }
144 } 144 }
145 } 145 }
146 if ( doNotCheckDuplicates ) return event; 146 if ( doNotCheckDuplicates ) return event;
147 if ( retVal ) { 147 if ( retVal ) {
148 if ( retVal->calID() > event->calID() ) { 148 if ( retVal->calID() > event->calID() ) {
149 if ( isDup ) 149 if ( isDup )
150 *isDup = retVal->calID(); 150 *isDup = retVal->calID();
151 retVal = event; 151 retVal = event;
152 } 152 }
153 } else { 153 } else {
154 retVal = event; 154 retVal = event;
155 } 155 }
156 } 156 }
157 } 157 }
158 if ( retVal ) return retVal; 158 if ( retVal ) return retVal;
159 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 159 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
160 if ( it->uid() == uid ) { 160 if ( it->uid() == uid ) {
161 if( calID ) { 161 if( calID ) {
162 if ( event->calID() != calID ) 162 if ( event->calID() != calID )
163 continue; 163 continue;
164 } 164 }
165 else { 165 else {
166 if ( enabledOnly ) { 166 if ( enabledOnly ) {
167 if ( !it->calEnabled() ) { 167 if ( !it->calEnabled() ) {
168 if ( isDup ) 168 if ( isDup )
169 *isDup = it->calID(); 169 *isDup = it->calID();
170 continue; 170 continue;
171 } 171 }
172 } 172 }
173 } 173 }
174 if ( doNotCheckDuplicates ) return it; 174 if ( doNotCheckDuplicates ) return it;
175 if ( retVal ) { 175 if ( retVal ) {
176 if ( retVal->calID() > it->calID() ) { 176 if ( retVal->calID() > it->calID() ) {
177 if ( isDup ) 177 if ( isDup )
178 *isDup = retVal->calID(); 178 *isDup = retVal->calID();
179 retVal = it; 179 retVal = it;
180 } 180 }
181 } else { 181 } else {
182 retVal = it; 182 retVal = it;
183 } 183 }
184 } 184 }
185 return retVal; 185 return retVal;
186} 186}
187 187
188bool CalendarLocal::mergeCalendar( Calendar* remote ) 188bool CalendarLocal::mergeCalendar( Calendar* remote )
189{ 189{
190 // 1 look for raw inc in local 190 // 1 look for raw inc in local
191 // if inc not in remote, delete in local 191 // if inc not in remote, delete in local
192 // 2 look for raw inc in remote 192 // 2 look for raw inc in remote
193 // if inc in local, replace it 193 // if inc in local, replace it
194 // if not in local, add it to default calendar 194 // if not in local, add it to default calendar
195 QPtrList<Incidence> localInc = rawIncidences(); 195 QPtrList<Incidence> localInc = rawIncidences();
196 Incidence* inL = localInc.first(); 196 Incidence* inL = localInc.first();
197 while ( inL ) { 197 while ( inL ) {
198 if ( ! inL->isReadOnly () ) 198 if ( ! inL->isReadOnly () )
199 if ( !remote->incidenceForUid( inL->uid(), true )) 199 if ( !remote->incidenceForUid( inL->uid(), true ))
200 deleteIncidence( inL ); 200 deleteIncidence( inL );
201 inL = localInc.next(); 201 inL = localInc.next();
202 } 202 }
203 QPtrList<Incidence> er = remote->rawIncidences(); 203 QPtrList<Incidence> er = remote->rawIncidences();
204 Incidence* inR = er.first(); 204 Incidence* inR = er.first();
205 while ( inR ) { 205 while ( inR ) {
206 inL = incidenceForUid( inR->uid(),false ); 206 inL = incidenceForUid( inR->uid(),false );
207 if ( inL ) { 207 if ( inL ) {
208 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { 208 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
209 int calID = inL->calID(); 209 int calID = inL->calID();
210 deleteIncidence( inL ); 210 deleteIncidence( inL );
211 inL = inR->clone(); 211 inL = inR->clone();
212 inL->setCalID_block( calID ); 212 inL->setCalID_block( calID );
213 addIncidence( inL ); 213 addIncidence( inL );
214 } 214 }
215 } else { 215 } else {
216 inL = inR->clone(); 216 inL = inR->clone();
217 inL->setCalID_block( 0 );// add to default cal 217 inL->setCalID_block( 0 );// add to default cal
218 addIncidence( inL ); 218 addIncidence( inL );
219 } 219 }
220 inR = er.next(); 220 inR = er.next();
221 } 221 }
222 return true; 222 return true;
223} 223}
224 224
225 225
226bool CalendarLocal::addCalendarFile( QString name, int id ) 226bool CalendarLocal::addCalendarFile( QString name, int id )
227{ 227{
228 CalendarLocal calendar( timeZoneId() ); 228 CalendarLocal calendar( timeZoneId() );
229 calendar.setDefaultCalendar( id ); 229 calendar.setDefaultCalendar( id );
230 if ( calendar.load( name ) ) { 230 if ( calendar.load( name ) ) {
231 addCalendar( &calendar ); 231 addCalendar( &calendar );
232 return true; 232 return true;
233 } 233 }
234 return false; 234 return false;
235} 235}
236void CalendarLocal::setSyncEventsEnabled() 236void CalendarLocal::setSyncEventsEnabled()
237{ 237{
238 Event * ev; 238 Event * ev;
239 ev = mEventList.first(); 239 ev = mEventList.first();
240 while ( ev ) { 240 while ( ev ) {
241 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 241 if ( ev->uid().left(15) == QString("last-syncEvent-") )
242 ev->setCalEnabled( true ); 242 ev->setCalEnabled( true );
243 ev = mEventList.next(); 243 ev = mEventList.next();
244 } 244 }
245} 245}
246void CalendarLocal::setSyncEventsReadOnly() 246void CalendarLocal::setSyncEventsReadOnly()
247{ 247{
248 Event * ev; 248 Event * ev;
249 ev = mEventList.first(); 249 ev = mEventList.first();
250 while ( ev ) { 250 while ( ev ) {
251 if ( ev->uid().left(15) == QString("last-syncEvent-") ) { 251 if ( ev->uid().left(15) == QString("last-syncEvent-") ) {
252 ev->setReadOnly( true ); 252 ev->setReadOnly( true );
253 } 253 }
254 ev = mEventList.next(); 254 ev = mEventList.next();
255 } 255 }
256} 256}
257 257
258void CalendarLocal::addCalendar( Calendar* cal ) 258void CalendarLocal::addCalendar( Calendar* cal )
259{ 259{
260 cal->setDontDeleteIncidencesOnClose(); 260 cal->setDontDeleteIncidencesOnClose();
261 setSyncEventsEnabled(); 261 setSyncEventsEnabled();
262 QPtrList<Incidence> incList;
262 { 263 {
263 QPtrList<Event> EventList = cal->rawEvents(); 264 QPtrList<Event> EventList = cal->rawEvents();
264 QPtrList<Event> el;
265 Event * ev = EventList.first(); 265 Event * ev = EventList.first();
266 while ( ev ) { 266 while ( ev ) {
267 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { 267 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) {
268 Event * se = event( ev->uid() );
269 if ( se )
270 el.append( se );
271 ev->setCalID_block( 1 ); 268 ev->setCalID_block( 1 );
272 } 269 }
270 Event * se = event( ev->uid() );
271 if ( se )
272 incList.append( se );
273 ev->unRegisterObserver( cal ); 273 ev->unRegisterObserver( cal );
274 ev->registerObserver( this ); 274 ev->registerObserver( this );
275 mEventList.append( ev ); 275 mEventList.append( ev );
276 ev = EventList.next(); 276 ev = EventList.next();
277 } 277 }
278 for ( ev = el.first(); ev; ev = el.next() ) { 278
279 deleteIncidence ( ev );
280 }
281 } 279 }
282 { 280 {
283 281
284 QPtrList<Todo> TodoList = cal->rawTodos(); 282 QPtrList<Todo> TodoList = cal->rawTodos();
285 Todo * ev = TodoList.first(); 283 Todo * ev = TodoList.first();
286 while ( ev ) { 284 while ( ev ) {
287 ev->resetRelatedTo(); 285 ev->resetRelatedTo();
288 ev = TodoList.next(); 286 ev = TodoList.next();
289 } 287 }
290 //TodoList = cal->rawTodos(); 288 //TodoList = cal->rawTodos();
291 ev = TodoList.first(); 289 ev = TodoList.first();
292 while ( ev ) { 290 while ( ev ) {
291 Todo * se = todo( ev->uid() );
292 if ( se )
293 incList.append( se );
293 ev->unRegisterObserver( cal ); 294 ev->unRegisterObserver( cal );
294 ev->registerObserver( this ); 295 ev->registerObserver( this );
295 mTodoList.append( ev ); 296 mTodoList.append( ev );
296 setupRelations( ev ); 297 setupRelations( ev );
297 ev = TodoList.next(); 298 ev = TodoList.next();
298 } 299 }
299 } 300 }
300 { 301 {
301 QPtrList<Journal> JournalList = cal->journals(); 302 QPtrList<Journal> JournalList = cal->journals();
302 Journal * ev = JournalList.first(); 303 Journal * ev = JournalList.first();
303 while ( ev ) { 304 while ( ev ) {
305 Journal * se = journal( ev->uid() );
306 if ( se )
307 incList.append( se );
304 ev->unRegisterObserver( cal ); 308 ev->unRegisterObserver( cal );
305 ev->registerObserver( this ); 309 ev->registerObserver( this );
306 mJournalList.append( ev ); 310 mJournalList.append( ev );
307 ev = JournalList.next(); 311 ev = JournalList.next();
308 } 312 }
309 } 313 }
314 {
315 for (Incidence * ev = incList.first(); ev; ev = incList.next() ) {
316 deleteIncidence ( ev );
317 }
318 }
310 setModified( true ); 319 setModified( true );
311} 320}
312bool CalendarLocal::load( const QString &fileName ) 321bool CalendarLocal::load( const QString &fileName )
313{ 322{
314 FileStorage storage( this, fileName ); 323 FileStorage storage( this, fileName );
315 return storage.load(); 324 return storage.load();
316} 325}
317 326
318bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 327bool CalendarLocal::save( const QString &fileName, CalFormat *format )
319{ 328{
320 FileStorage storage( this, fileName, format ); 329 FileStorage storage( this, fileName, format );
321 return storage.save(); 330 return storage.save();
322} 331}
323 332
324void CalendarLocal::stopAllTodos() 333void CalendarLocal::stopAllTodos()
325{ 334{
326 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 335 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
327 it->setRunning( false ); 336 it->setRunning( false );
328 337
329} 338}
330void CalendarLocal::close() 339void CalendarLocal::close()
331{ 340{
332 341
333 Todo * i; 342 Todo * i;
334 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 343 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
335 344
336 mEventList.setAutoDelete( true ); 345 mEventList.setAutoDelete( true );
337 mTodoList.setAutoDelete( true ); 346 mTodoList.setAutoDelete( true );
338 mJournalList.setAutoDelete( true ); 347 mJournalList.setAutoDelete( true );
339 348
340 mEventList.clear(); 349 mEventList.clear();
341 mTodoList.clear(); 350 mTodoList.clear();
342 mJournalList.clear(); 351 mJournalList.clear();
343 352
344 mEventList.setAutoDelete( false ); 353 mEventList.setAutoDelete( false );
345 mTodoList.setAutoDelete( false ); 354 mTodoList.setAutoDelete( false );
346 mJournalList.setAutoDelete( false ); 355 mJournalList.setAutoDelete( false );
347 356
348 setModified( false ); 357 setModified( false );
349} 358}
350 359
351bool CalendarLocal::addAnniversaryNoDup( Event *event ) 360bool CalendarLocal::addAnniversaryNoDup( Event *event )
352{ 361{
353 QString cat; 362 QString cat;
354 bool isBirthday = true; 363 bool isBirthday = true;
355 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 364 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
356 isBirthday = false; 365 isBirthday = false;
357 cat = i18n( "Anniversary" ); 366 cat = i18n( "Anniversary" );
358 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 367 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
359 isBirthday = true; 368 isBirthday = true;
360 cat = i18n( "Birthday" ); 369 cat = i18n( "Birthday" );
361 } else { 370 } else {
362 qDebug("addAnniversaryNoDup called without fitting category! "); 371 qDebug("addAnniversaryNoDup called without fitting category! ");
363 return false; 372 return false;
364 } 373 }
365 Event * eve; 374 Event * eve;
366 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 375 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
367 if ( !(eve->categories().contains( cat ) )) 376 if ( !(eve->categories().contains( cat ) ))
368 continue; 377 continue;
369 // now we have an event with fitting category 378 // now we have an event with fitting category
370 if ( eve->dtStart().date() != event->dtStart().date() ) 379 if ( eve->dtStart().date() != event->dtStart().date() )
371 continue; 380 continue;
372 // now we have an event with fitting category+date 381 // now we have an event with fitting category+date
373 if ( eve->summary() != event->summary() ) 382 if ( eve->summary() != event->summary() )
374 continue; 383 continue;
375 // now we have an event with fitting category+date+summary 384 // now we have an event with fitting category+date+summary
376 return false; 385 return false;
377 } 386 }
378 return addEvent( event ); 387 return addEvent( event );
379 388
380} 389}
381bool CalendarLocal::addEventNoDup( Event *event ) 390bool CalendarLocal::addEventNoDup( Event *event )
382{ 391{
383 Event * eve; 392 Event * eve;
384 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 393 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
385 if ( *eve == *event ) { 394 if ( *eve == *event ) {
386 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 395 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
387 return false; 396 return false;
388 } 397 }
389 } 398 }
390 return addEvent( event ); 399 return addEvent( event );
391} 400}
392 401
393bool CalendarLocal::addEvent( Event *event ) 402bool CalendarLocal::addEvent( Event *event )
394{ 403{
395 insertEvent( event ); 404 insertEvent( event );
396 405
397 event->registerObserver( this ); 406 event->registerObserver( this );
398 407
399 setModified( true ); 408 setModified( true );
400 if ( event->calID() == 0 ) 409 if ( event->calID() == 0 )
401 event->setCalID_block( mDefaultCalendar ); 410 event->setCalID_block( mDefaultCalendar );
402 event->setCalEnabled( true ); 411 event->setCalEnabled( true );
403 412
404 return true; 413 return true;
405} 414}
406 415
407void CalendarLocal::deleteEvent( Event *event ) 416void CalendarLocal::deleteEvent( Event *event )
408{ 417{
409 clearUndo(event); 418 clearUndo(event);
410 if ( mEventList.removeRef( event ) ) { 419 if ( mEventList.removeRef( event ) ) {
411 setModified( true ); 420 setModified( true );
412 } 421 }
413} 422}
414 423
415 424
416Event *CalendarLocal::event( const QString &uid ) 425Event *CalendarLocal::event( const QString &uid )
417{ 426{
418 Event *event; 427 Event *event;
419 Event *retVal = 0; 428 Event *retVal = 0;
420 for ( event = mEventList.first(); event; event = mEventList.next() ) { 429 for ( event = mEventList.first(); event; event = mEventList.next() ) {
421 if ( event->calEnabled() && event->uid() == uid ) { 430 if ( event->calEnabled() && event->uid() == uid ) {
422 if ( retVal ) { 431 if ( retVal ) {
423 if ( retVal->calID() > event->calID() ) { 432 if ( retVal->calID() > event->calID() ) {
424 retVal = event; 433 retVal = event;
425 } 434 }
426 } else { 435 } else {
427 retVal = event; 436 retVal = event;
428 } 437 }
429 } 438 }
430 } 439 }
431 return retVal; 440 return retVal;
432} 441}
433bool CalendarLocal::addTodoNoDup( Todo *todo ) 442bool CalendarLocal::addTodoNoDup( Todo *todo )
434{ 443{
435 Todo * eve; 444 Todo * eve;
436 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 445 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
437 if ( *eve == *todo ) { 446 if ( *eve == *todo ) {
438 //qDebug("duplicate todo found! not inserted! "); 447 //qDebug("duplicate todo found! not inserted! ");
439 return false; 448 return false;
440 } 449 }
441 } 450 }
442 return addTodo( todo ); 451 return addTodo( todo );
443} 452}
444bool CalendarLocal::addTodo( Todo *todo ) 453bool CalendarLocal::addTodo( Todo *todo )
445{ 454{
446 mTodoList.append( todo ); 455 mTodoList.append( todo );
447 456
448 todo->registerObserver( this ); 457 todo->registerObserver( this );
449 458
450 // Set up subtask relations 459 // Set up subtask relations
451 setupRelations( todo ); 460 setupRelations( todo );
452 461
453 setModified( true ); 462 setModified( true );
454 if ( todo->calID() == 0 ) 463 if ( todo->calID() == 0 )
455 todo->setCalID_block( mDefaultCalendar ); 464 todo->setCalID_block( mDefaultCalendar );
456 todo->setCalEnabled( true ); 465 todo->setCalEnabled( true );
457 return true; 466 return true;
458} 467}
459 468
460void CalendarLocal::deleteTodo( Todo *todo ) 469void CalendarLocal::deleteTodo( Todo *todo )
461{ 470{
462 QString uid = todo->uid(); 471 QString uid = todo->uid();
463 // Handle orphaned children 472 // Handle orphaned children
464 removeRelations( todo ); 473 removeRelations( todo );
465 clearUndo(todo); 474 clearUndo(todo);
466 475
467 if ( mTodoList.removeRef( todo ) ) { 476 if ( mTodoList.removeRef( todo ) ) {
468 setModified( true ); 477 setModified( true );
469 } 478 }
470 Todo* dup = todoForUid( uid ); 479 Todo* dup = todoForUid( uid );
471 if ( dup ) 480 if ( dup )
472 setupRelations( dup ); 481 setupRelations( dup );
473} 482}
474 483
475QPtrList<Todo> CalendarLocal::rawTodos() 484QPtrList<Todo> CalendarLocal::rawTodos()
476{ 485{
477 QPtrList<Todo> el; 486 QPtrList<Todo> el;
478 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 487 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
479 if ( it->calEnabled() ) el.append( it ); 488 if ( it->calEnabled() ) el.append( it );
480 return el; 489 return el;
481} 490}
482Todo *CalendarLocal::todo( QString syncProf, QString id ) 491Todo *CalendarLocal::todo( QString syncProf, QString id )
483{ 492{
484 Todo *todo; 493 Todo *todo;
485 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 494 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
486 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 495 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
487 } 496 }
488 497
489 return 0; 498 return 0;
490} 499}
491void CalendarLocal::removeSyncInfo( QString syncProfile) 500void CalendarLocal::removeSyncInfo( QString syncProfile)
492{ 501{
493 QPtrList<Incidence> all = rawIncidences() ; 502 QPtrList<Incidence> all = rawIncidences() ;
494 Incidence *inc; 503 Incidence *inc;
495 for ( inc = all.first(); inc; inc = all.next() ) { 504 for ( inc = all.first(); inc; inc = all.next() ) {
496 inc->removeID( syncProfile ); 505 inc->removeID( syncProfile );
497 } 506 }
498 if ( syncProfile.isEmpty() ) { 507 if ( syncProfile.isEmpty() ) {
499 QPtrList<Event> el; 508 QPtrList<Event> el;
500 Event *todo; 509 Event *todo;
501 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 510 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
502 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 511 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
503 el.append( todo ); 512 el.append( todo );
504 } 513 }
505 for ( todo = el.first(); todo; todo = el.next() ) { 514 for ( todo = el.first(); todo; todo = el.next() ) {
506 deleteIncidence ( todo ); 515 deleteIncidence ( todo );
507 } 516 }
508 } else { 517 } else {
509 Event *lse = event( "last-syncEvent-"+ syncProfile); 518 Event *lse = event( "last-syncEvent-"+ syncProfile);
510 if ( lse ) 519 if ( lse )
511 deleteIncidence ( lse ); 520 deleteIncidence ( lse );
512 } 521 }
513} 522}
514QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 523QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
515{ 524{
516 QPtrList<Event> el; 525 QPtrList<Event> el;
517 Event *todo; 526 Event *todo;
518 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 527 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
519 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 528 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
520 if ( todo->summary().left(3) == "E: " ) 529 if ( todo->summary().left(3) == "E: " )
521 el.append( todo ); 530 el.append( todo );
522 } 531 }
523 532
524 return el; 533 return el;
525 534
526} 535}
527Event *CalendarLocal::event( QString syncProf, QString id ) 536Event *CalendarLocal::event( QString syncProf, QString id )
528{ 537{
529 Event *todo; 538 Event *todo;
530 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 539 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
531 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 540 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
532 } 541 }
533 542
534 return 0; 543 return 0;
535} 544}
536Todo *CalendarLocal::todo( const QString &uid ) 545Todo *CalendarLocal::todo( const QString &uid )
537{ 546{
538 Todo *todo; 547 Todo *todo;
539 Todo *retVal = 0; 548 Todo *retVal = 0;
540 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 549 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
541 if ( todo->calEnabled() && todo->uid() == uid ) { 550 if ( todo->calEnabled() && todo->uid() == uid ) {
542 if ( retVal ) { 551 if ( retVal ) {
543 if ( retVal->calID() > todo->calID() ) { 552 if ( retVal->calID() > todo->calID() ) {
544 retVal = todo; 553 retVal = todo;
545 } 554 }
546 } else { 555 } else {
547 retVal = todo; 556 retVal = todo;
548 } 557 }
549 } 558 }
550 } 559 }
551 return retVal; 560 return retVal;
552} 561}
553void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) 562void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals)
554{ 563{
555 events = 0; 564 events = 0;
556 todos = 0; 565 todos = 0;
557 journals = 0; 566 journals = 0;
558 { 567 {
559 Todo *todo; 568 Todo *todo;
560 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 569 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
561 if ( todo->calID() == calId ) 570 if ( todo->calID() == calId )
562 ++todos; 571 ++todos;
563 } 572 }
564 } 573 }
565 { 574 {
566 Event *todo; 575 Event *todo;
567 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 576 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
568 if ( todo->calID() == calId ) 577 if ( todo->calID() == calId )
569 ++events; 578 ++events;
570 579
571 } 580 }
572 } 581 }
573 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 582 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
574 if ( it->calID() == calId ) ++journals; 583 if ( it->calID() == calId ) ++journals;
575 584
576} 585}
577QString CalendarLocal::nextSummary() const 586QString CalendarLocal::nextSummary() const
578{ 587{
579 return mNextSummary; 588 return mNextSummary;
580} 589}
581QDateTime CalendarLocal::nextAlarmEventDateTime() const 590QDateTime CalendarLocal::nextAlarmEventDateTime() const
582{ 591{
583 return mNextAlarmEventDateTime; 592 return mNextAlarmEventDateTime;
584} 593}
585void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 594void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
586{ 595{
587 //mNextAlarmIncidence 596 //mNextAlarmIncidence
588 //mNextAlarmDateTime 597 //mNextAlarmDateTime
589 //return mNextSummary; 598 //return mNextSummary;
590 //return mNextAlarmEventDateTime; 599 //return mNextAlarmEventDateTime;
591 bool newNextAlarm = false; 600 bool newNextAlarm = false;
592 bool computeNextAlarm = false; 601 bool computeNextAlarm = false;
593 bool ok; 602 bool ok;
594 int offset; 603 int offset;
595 QDateTime nextA; 604 QDateTime nextA;
596 // QString nextSum; 605 // QString nextSum;
597 //QDateTime nextEvent; 606 //QDateTime nextEvent;
598 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 607 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
599 computeNextAlarm = true; 608 computeNextAlarm = true;
600 } else { 609 } else {
601 if ( ! deleted ) { 610 if ( ! deleted ) {
602 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 611 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
603 if ( ok ) { 612 if ( ok ) {
604 if ( nextA < mNextAlarmDateTime ) { 613 if ( nextA < mNextAlarmDateTime ) {
605 deRegisterAlarm(); 614 deRegisterAlarm();
606 mNextAlarmDateTime = nextA; 615 mNextAlarmDateTime = nextA;
607 mNextSummary = incidence->summary(); 616 mNextSummary = incidence->summary();
608 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 617 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
609 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 618 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
610 newNextAlarm = true; 619 newNextAlarm = true;
611 mNextAlarmIncidence = incidence; 620 mNextAlarmIncidence = incidence;
612 } else { 621 } else {
613 if ( incidence == mNextAlarmIncidence ) { 622 if ( incidence == mNextAlarmIncidence ) {
614 computeNextAlarm = true; 623 computeNextAlarm = true;
615 } 624 }
616 } 625 }
617 } else { 626 } else {
618 if ( mNextAlarmIncidence == incidence ) { 627 if ( mNextAlarmIncidence == incidence ) {
619 computeNextAlarm = true; 628 computeNextAlarm = true;
620 } 629 }
621 } 630 }
622 } else { // deleted 631 } else { // deleted
623 if ( incidence == mNextAlarmIncidence ) { 632 if ( incidence == mNextAlarmIncidence ) {
624 computeNextAlarm = true; 633 computeNextAlarm = true;
625 } 634 }
626 } 635 }
627 } 636 }
628 if ( computeNextAlarm ) { 637 if ( computeNextAlarm ) {
629 deRegisterAlarm(); 638 deRegisterAlarm();
630 nextA = nextAlarm( 1000 ); 639 nextA = nextAlarm( 1000 );
631 if (! mNextAlarmIncidence ) { 640 if (! mNextAlarmIncidence ) {
632 return; 641 return;
633 } 642 }
634 newNextAlarm = true; 643 newNextAlarm = true;
635 } 644 }
636 if ( newNextAlarm ) 645 if ( newNextAlarm )
637 registerAlarm(); 646 registerAlarm();
638} 647}
639QString CalendarLocal:: getAlarmNotification() 648QString CalendarLocal:: getAlarmNotification()
640{ 649{
641 QString ret; 650 QString ret;
642 // this should not happen 651 // this should not happen
643 if (! mNextAlarmIncidence ) 652 if (! mNextAlarmIncidence )
644 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 653 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
645 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 654 Alarm* alarm = mNextAlarmIncidence->alarms().first();
646 if ( alarm->type() == Alarm::Procedure ) { 655 if ( alarm->type() == Alarm::Procedure ) {
647 ret = "proc_alarm" + alarm->programFile()+"+++"; 656 ret = "proc_alarm" + alarm->programFile()+"+++";
648 } else { 657 } else {
649 ret = "audio_alarm" +alarm->audioFile() +"+++"; 658 ret = "audio_alarm" +alarm->audioFile() +"+++";
650 } 659 }
651 ret += "cal_alarm"+ mNextSummary.left( 25 ); 660 ret += "cal_alarm"+ mNextSummary.left( 25 );
652 if ( mNextSummary.length() > 25 ) 661 if ( mNextSummary.length() > 25 )
653 ret += "\n" + mNextSummary.mid(25, 25 ); 662 ret += "\n" + mNextSummary.mid(25, 25 );
654 ret+= "\n"+mNextAlarmEventDateTimeString; 663 ret+= "\n"+mNextAlarmEventDateTimeString;
655 return ret; 664 return ret;
656} 665}
657void CalendarLocal::registerAlarm() 666void CalendarLocal::registerAlarm()
658{ 667{
659 mLastAlarmNotificationString = getAlarmNotification(); 668 mLastAlarmNotificationString = getAlarmNotification();
660 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 669 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
661 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 670 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
662// #ifndef DESKTOP_VERSION 671// #ifndef DESKTOP_VERSION
663// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 672// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
664// #endif 673// #endif
665} 674}
666void CalendarLocal::deRegisterAlarm() 675void CalendarLocal::deRegisterAlarm()
667{ 676{
668 if ( mLastAlarmNotificationString.isNull() ) 677 if ( mLastAlarmNotificationString.isNull() )
669 return; 678 return;
670 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 679 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
671 680
672 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 681 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
673 mNextAlarmEventDateTime = QDateTime(); 682 mNextAlarmEventDateTime = QDateTime();
674// #ifndef DESKTOP_VERSION 683// #ifndef DESKTOP_VERSION
675// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 684// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
676// #endif 685// #endif
677} 686}
678 687
679QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 688QPtrList<Todo> CalendarLocal::todos( const QDate &date )
680{ 689{
681 QPtrList<Todo> todos; 690 QPtrList<Todo> todos;
682 691
683 Todo *todo; 692 Todo *todo;
684 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 693 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
685 if ( !todo->calEnabled() ) continue; 694 if ( !todo->calEnabled() ) continue;
686 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 695 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
687 todos.append( todo ); 696 todos.append( todo );
688 } 697 }
689 } 698 }
690 699
691 filter()->apply( &todos ); 700 filter()->apply( &todos );
692 return todos; 701 return todos;
693} 702}
694void CalendarLocal::reInitAlarmSettings() 703void CalendarLocal::reInitAlarmSettings()
695{ 704{
696 if ( !mNextAlarmIncidence ) { 705 if ( !mNextAlarmIncidence ) {
697 nextAlarm( 1000 ); 706 nextAlarm( 1000 );
698 } 707 }
699 deRegisterAlarm(); 708 deRegisterAlarm();
700 mNextAlarmIncidence = 0; 709 mNextAlarmIncidence = 0;
701 checkAlarmForIncidence( 0, false ); 710 checkAlarmForIncidence( 0, false );
702 711
703} 712}
704 713
705 714
706 715
707QDateTime CalendarLocal::nextAlarm( int daysTo ) 716QDateTime CalendarLocal::nextAlarm( int daysTo )
708{ 717{
709 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 718 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
710 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 719 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
711 QDateTime next; 720 QDateTime next;
712 Event *e; 721 Event *e;
713 bool ok; 722 bool ok;
714 bool found = false; 723 bool found = false;
715 int offset; 724 int offset;
716 mNextAlarmIncidence = 0; 725 mNextAlarmIncidence = 0;
717 for( e = mEventList.first(); e; e = mEventList.next() ) { 726 for( e = mEventList.first(); e; e = mEventList.next() ) {
718 if ( !e->calEnabled() ) continue; 727 if ( !e->calEnabled() ) continue;
719 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 728 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
720 if ( ok ) { 729 if ( ok ) {
721 if ( next < nextA ) { 730 if ( next < nextA ) {
722 nextA = next; 731 nextA = next;
723 found = true; 732 found = true;
724 mNextSummary = e->summary(); 733 mNextSummary = e->summary();
725 mNextAlarmEventDateTime = next.addSecs(offset ) ; 734 mNextAlarmEventDateTime = next.addSecs(offset ) ;
726 mNextAlarmIncidence = (Incidence *) e; 735 mNextAlarmIncidence = (Incidence *) e;
727 } 736 }
728 } 737 }
729 } 738 }
730 Todo *t; 739 Todo *t;
731 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 740 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
732 if ( !t->calEnabled() ) continue; 741 if ( !t->calEnabled() ) continue;
733 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 742 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
734 if ( ok ) { 743 if ( ok ) {
735 if ( next < nextA ) { 744 if ( next < nextA ) {
736 nextA = next; 745 nextA = next;
737 found = true; 746 found = true;
738 mNextSummary = t->summary(); 747 mNextSummary = t->summary();
739 mNextAlarmEventDateTime = next.addSecs(offset ); 748 mNextAlarmEventDateTime = next.addSecs(offset );
740 mNextAlarmIncidence = (Incidence *) t; 749 mNextAlarmIncidence = (Incidence *) t;
741 } 750 }
742 } 751 }
743 } 752 }
744 if ( mNextAlarmIncidence ) { 753 if ( mNextAlarmIncidence ) {
745 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 754 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
746 mNextAlarmDateTime = nextA; 755 mNextAlarmDateTime = nextA;
747 } 756 }
748 return nextA; 757 return nextA;
749} 758}
750Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 759Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
751{ 760{
752 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 761 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
753} 762}
754 763
755Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 764Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
756{ 765{
757 766
758 Alarm::List alarms; 767 Alarm::List alarms;
759 768
760 Event *e; 769 Event *e;
761 770
762 for( e = mEventList.first(); e; e = mEventList.next() ) { 771 for( e = mEventList.first(); e; e = mEventList.next() ) {
763 if ( !e->calEnabled() ) continue; 772 if ( !e->calEnabled() ) continue;
764 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 773 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
765 else appendAlarms( alarms, e, from, to ); 774 else appendAlarms( alarms, e, from, to );
766 } 775 }
767 776
768 Todo *t; 777 Todo *t;
769 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 778 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
770 if ( !t->calEnabled() ) continue; 779 if ( !t->calEnabled() ) continue;
771 appendAlarms( alarms, t, from, to ); 780 appendAlarms( alarms, t, from, to );
772 } 781 }
773 782
774 return alarms; 783 return alarms;
775} 784}
776 785
777void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 786void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
778 const QDateTime &from, const QDateTime &to ) 787 const QDateTime &from, const QDateTime &to )
779{ 788{
780 QPtrList<Alarm> alarmList = incidence->alarms(); 789 QPtrList<Alarm> alarmList = incidence->alarms();
781 Alarm *alarm; 790 Alarm *alarm;
782 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 791 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
783// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 792// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
784// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 793// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
785 if ( alarm->enabled() ) { 794 if ( alarm->enabled() ) {
786 if ( alarm->time() >= from && alarm->time() <= to ) { 795 if ( alarm->time() >= from && alarm->time() <= to ) {
787 alarms.append( alarm ); 796 alarms.append( alarm );
788 } 797 }
789 } 798 }
790 } 799 }
791} 800}
792 801
793void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 802void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
794 Incidence *incidence, 803 Incidence *incidence,
795 const QDateTime &from, 804 const QDateTime &from,
796 const QDateTime &to ) 805 const QDateTime &to )
797{ 806{
798 807
799 QPtrList<Alarm> alarmList = incidence->alarms(); 808 QPtrList<Alarm> alarmList = incidence->alarms();
800 Alarm *alarm; 809 Alarm *alarm;
801 QDateTime qdt; 810 QDateTime qdt;
802 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 811 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
803 if (incidence->recursOn(from.date())) { 812 if (incidence->recursOn(from.date())) {
804 qdt.setTime(alarm->time().time()); 813 qdt.setTime(alarm->time().time());
805 qdt.setDate(from.date()); 814 qdt.setDate(from.date());
806 } 815 }
807 else qdt = alarm->time(); 816 else qdt = alarm->time();
808 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 817 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
809 if ( alarm->enabled() ) { 818 if ( alarm->enabled() ) {
810 if ( qdt >= from && qdt <= to ) { 819 if ( qdt >= from && qdt <= to ) {
811 alarms.append( alarm ); 820 alarms.append( alarm );
812 } 821 }
813 } 822 }
814 } 823 }
815} 824}
816 825
817 826
818/****************************** PROTECTED METHODS ****************************/ 827/****************************** PROTECTED METHODS ****************************/
819 828
820// after changes are made to an event, this should be called. 829// after changes are made to an event, this should be called.
821void CalendarLocal::update( IncidenceBase *incidence ) 830void CalendarLocal::update( IncidenceBase *incidence )