summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-11-28 03:27:16 (UTC)
committer zautrix <zautrix>2005-11-28 03:27:16 (UTC)
commitb7522a13b64225bb91bdab4a21b44282f8c3e3b4 (patch) (unidiff)
tree3aa005036dd83f3d0e5f57dd398dc260666daea1 /korganizer
parent084180efc1bccba341bf3f2f718fd10cdfdaf18e (diff)
downloadkdepimpi-b7522a13b64225bb91bdab4a21b44282f8c3e3b4.zip
kdepimpi-b7522a13b64225bb91bdab4a21b44282f8c3e3b4.tar.gz
kdepimpi-b7522a13b64225bb91bdab4a21b44282f8c3e3b4.tar.bz2
sync
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 1800cf2..8385bcc 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1350,1529 +1350,1531 @@ void CalendarView::selectWeekNum ( int num )
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;