-rw-r--r-- | korganizer/calendarview.cpp | 2 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 25 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 1 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 5 |
5 files changed, 29 insertions, 5 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 307027a..e45240a 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -1467,385 +1467,385 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b | |||
1467 | 1467 | ||
1468 | // ************************************************ | 1468 | // ************************************************ |
1469 | // ************************************************ | 1469 | // ************************************************ |
1470 | // ************************************************ | 1470 | // ************************************************ |
1471 | // We may have that lastSync > remoteMod AND lastSync > localMod | 1471 | // We may have that lastSync > remoteMod AND lastSync > localMod |
1472 | // BUT remoteMod != localMod | 1472 | // BUT remoteMod != localMod |
1473 | 1473 | ||
1474 | 1474 | ||
1475 | if ( full && mode < SYNC_PREF_NEWEST ) | 1475 | if ( full && mode < SYNC_PREF_NEWEST ) |
1476 | mode = SYNC_PREF_ASK; | 1476 | mode = SYNC_PREF_ASK; |
1477 | 1477 | ||
1478 | switch( mode ) { | 1478 | switch( mode ) { |
1479 | case SYNC_PREF_LOCAL: | 1479 | case SYNC_PREF_LOCAL: |
1480 | if ( lastSync > remoteMod ) | 1480 | if ( lastSync > remoteMod ) |
1481 | return 1; | 1481 | return 1; |
1482 | if ( lastSync > localMod ) | 1482 | if ( lastSync > localMod ) |
1483 | return 2; | 1483 | return 2; |
1484 | return 1; | 1484 | return 1; |
1485 | break; | 1485 | break; |
1486 | case SYNC_PREF_REMOTE: | 1486 | case SYNC_PREF_REMOTE: |
1487 | if ( lastSync > localMod ) | 1487 | if ( lastSync > localMod ) |
1488 | return 2; | 1488 | return 2; |
1489 | if ( lastSync > remoteMod ) | 1489 | if ( lastSync > remoteMod ) |
1490 | return 1; | 1490 | return 1; |
1491 | return 2; | 1491 | return 2; |
1492 | break; | 1492 | break; |
1493 | case SYNC_PREF_NEWEST: | 1493 | case SYNC_PREF_NEWEST: |
1494 | if ( localMod >= remoteMod ) | 1494 | if ( localMod >= remoteMod ) |
1495 | return 1; | 1495 | return 1; |
1496 | else | 1496 | else |
1497 | return 2; | 1497 | return 2; |
1498 | break; | 1498 | break; |
1499 | case SYNC_PREF_ASK: | 1499 | case SYNC_PREF_ASK: |
1500 | qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 1500 | qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
1501 | if ( lastSync > remoteMod && lastSync > localMod) | 1501 | if ( lastSync > remoteMod && lastSync > localMod) |
1502 | return 0; | 1502 | return 0; |
1503 | if ( lastSync > remoteMod ) | 1503 | if ( lastSync > remoteMod ) |
1504 | return 1; | 1504 | return 1; |
1505 | if ( lastSync > localMod ) | 1505 | if ( lastSync > localMod ) |
1506 | return 2; | 1506 | return 2; |
1507 | qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 1507 | qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
1508 | localIsNew = localMod >= remoteMod; | 1508 | localIsNew = localMod >= remoteMod; |
1509 | if ( localIsNew ) | 1509 | if ( localIsNew ) |
1510 | getEventViewerDialog()->setColorMode( 1 ); | 1510 | getEventViewerDialog()->setColorMode( 1 ); |
1511 | else | 1511 | else |
1512 | getEventViewerDialog()->setColorMode( 2 ); | 1512 | getEventViewerDialog()->setColorMode( 2 ); |
1513 | getEventViewerDialog()->setIncidence(local); | 1513 | getEventViewerDialog()->setIncidence(local); |
1514 | if ( localIsNew ) | 1514 | if ( localIsNew ) |
1515 | getEventViewerDialog()->setColorMode( 2 ); | 1515 | getEventViewerDialog()->setColorMode( 2 ); |
1516 | else | 1516 | else |
1517 | getEventViewerDialog()->setColorMode( 1 ); | 1517 | getEventViewerDialog()->setColorMode( 1 ); |
1518 | getEventViewerDialog()->addIncidence(remote); | 1518 | getEventViewerDialog()->addIncidence(remote); |
1519 | getEventViewerDialog()->setColorMode( 0 ); | 1519 | getEventViewerDialog()->setColorMode( 0 ); |
1520 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); | 1520 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); |
1521 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); | 1521 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); |
1522 | getEventViewerDialog()->showMe(); | 1522 | getEventViewerDialog()->showMe(); |
1523 | result = getEventViewerDialog()->executeS( localIsNew ); | 1523 | result = getEventViewerDialog()->executeS( localIsNew ); |
1524 | return result; | 1524 | return result; |
1525 | 1525 | ||
1526 | break; | 1526 | break; |
1527 | case SYNC_PREF_FORCE_LOCAL: | 1527 | case SYNC_PREF_FORCE_LOCAL: |
1528 | return 1; | 1528 | return 1; |
1529 | break; | 1529 | break; |
1530 | case SYNC_PREF_FORCE_REMOTE: | 1530 | case SYNC_PREF_FORCE_REMOTE: |
1531 | return 2; | 1531 | return 2; |
1532 | break; | 1532 | break; |
1533 | 1533 | ||
1534 | default: | 1534 | default: |
1535 | // SYNC_PREF_TAKE_BOTH not implemented | 1535 | // SYNC_PREF_TAKE_BOTH not implemented |
1536 | break; | 1536 | break; |
1537 | } | 1537 | } |
1538 | return 0; | 1538 | return 0; |
1539 | } | 1539 | } |
1540 | Event* CalendarView::getLastSyncEvent() | 1540 | Event* CalendarView::getLastSyncEvent() |
1541 | { | 1541 | { |
1542 | Event* lse; | 1542 | Event* lse; |
1543 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 1543 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
1544 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); | 1544 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); |
1545 | if (!lse) { | 1545 | if (!lse) { |
1546 | lse = new Event(); | 1546 | lse = new Event(); |
1547 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 1547 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
1548 | QString sum = ""; | 1548 | QString sum = ""; |
1549 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 1549 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
1550 | sum = "E: "; | 1550 | sum = "E: "; |
1551 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 1551 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
1552 | lse->setDtStart( mLastCalendarSync ); | 1552 | lse->setDtStart( mLastCalendarSync ); |
1553 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 1553 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
1554 | lse->setCategories( i18n("SyncEvent") ); | 1554 | lse->setCategories( i18n("SyncEvent") ); |
1555 | lse->setReadOnly( true ); | 1555 | lse->setReadOnly( true ); |
1556 | lse->setCalID( 1 ); | 1556 | lse->setCalID( 1 ); |
1557 | mCalendar->addEvent( lse ); | 1557 | mCalendar->addEvent( lse ); |
1558 | } | 1558 | } |
1559 | 1559 | ||
1560 | return lse; | 1560 | return lse; |
1561 | 1561 | ||
1562 | } | 1562 | } |
1563 | 1563 | ||
1564 | // we check, if the to delete event has a id for a profile | 1564 | // we check, if the to delete event has a id for a profile |
1565 | // if yes, we set this id in the profile to delete | 1565 | // if yes, we set this id in the profile to delete |
1566 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 1566 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
1567 | { | 1567 | { |
1568 | if ( lastSync.count() == 0 ) { | 1568 | if ( lastSync.count() == 0 ) { |
1569 | //qDebug(" lastSync.count() == 0"); | 1569 | //qDebug(" lastSync.count() == 0"); |
1570 | return; | 1570 | return; |
1571 | } | 1571 | } |
1572 | if ( toDelete->typeID() == journalID ) | 1572 | if ( toDelete->typeID() == journalID ) |
1573 | return; | 1573 | return; |
1574 | 1574 | ||
1575 | Event* eve = lastSync.first(); | 1575 | Event* eve = lastSync.first(); |
1576 | 1576 | ||
1577 | while ( eve ) { | 1577 | while ( eve ) { |
1578 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 1578 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
1579 | if ( !id.isEmpty() ) { | 1579 | if ( !id.isEmpty() ) { |
1580 | QString des = eve->description(); | 1580 | QString des = eve->description(); |
1581 | QString pref = "e"; | 1581 | QString pref = "e"; |
1582 | if ( toDelete->typeID() == todoID ) | 1582 | if ( toDelete->typeID() == todoID ) |
1583 | pref = "t"; | 1583 | pref = "t"; |
1584 | des += pref+ id + ","; | 1584 | des += pref+ id + ","; |
1585 | eve->setReadOnly( false ); | 1585 | eve->setReadOnly( false ); |
1586 | eve->setDescription( des ); | 1586 | eve->setDescription( des ); |
1587 | //qDebug("setdes %s ", des.latin1()); | 1587 | //qDebug("setdes %s ", des.latin1()); |
1588 | eve->setReadOnly( true ); | 1588 | eve->setReadOnly( true ); |
1589 | } | 1589 | } |
1590 | eve = lastSync.next(); | 1590 | eve = lastSync.next(); |
1591 | } | 1591 | } |
1592 | 1592 | ||
1593 | } | 1593 | } |
1594 | void CalendarView::checkExternalId( Incidence * inc ) | 1594 | void CalendarView::checkExternalId( Incidence * inc ) |
1595 | { | 1595 | { |
1596 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 1596 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
1597 | checkExternSyncEvent( lastSync, inc ); | 1597 | checkExternSyncEvent( lastSync, inc ); |
1598 | 1598 | ||
1599 | } | 1599 | } |
1600 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 1600 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
1601 | { | 1601 | { |
1602 | bool syncOK = true; | 1602 | bool syncOK = true; |
1603 | int addedEvent = 0; | 1603 | int addedEvent = 0; |
1604 | int addedEventR = 0; | 1604 | int addedEventR = 0; |
1605 | int deletedEventR = 0; | 1605 | int deletedEventR = 0; |
1606 | int deletedEventL = 0; | 1606 | int deletedEventL = 0; |
1607 | int changedLocal = 0; | 1607 | int changedLocal = 0; |
1608 | int changedRemote = 0; | 1608 | int changedRemote = 0; |
1609 | int filteredIN = 0; | 1609 | int filteredIN = 0; |
1610 | int filteredOUT = 0; | 1610 | int filteredOUT = 0; |
1611 | //QPtrList<Event> el = local->rawEvents(); | 1611 | //QPtrList<Event> el = local->rawEvents(); |
1612 | Event* eventR; | 1612 | Event* eventR; |
1613 | QString uid; | 1613 | QString uid; |
1614 | int take; | 1614 | int take; |
1615 | Event* eventRSync; | 1615 | Event* eventRSync; |
1616 | Event* eventLSync; | 1616 | Event* eventLSync; |
1617 | clearAllViews(); | 1617 | clearAllViews(); |
1618 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); | 1618 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); |
1619 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); | 1619 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); |
1620 | bool fullDateRange = false; | 1620 | bool fullDateRange = false; |
1621 | local->resetTempSyncStat(); | 1621 | local->resetTempSyncStat(); |
1622 | mLastCalendarSync = QDateTime::currentDateTime(); | 1622 | mLastCalendarSync = QDateTime::currentDateTime(); |
1623 | if ( mSyncManager->syncWithDesktop() ) { | 1623 | if ( mSyncManager->syncWithDesktop() ) { |
1624 | remote->resetPilotStat(1); | 1624 | remote->resetPilotStat(1); |
1625 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1625 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1626 | mLastCalendarSync = KSyncManager::mRequestedSyncEvent; | 1626 | mLastCalendarSync = KSyncManager::mRequestedSyncEvent; |
1627 | qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); | 1627 | qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); |
1628 | } else { | 1628 | } else { |
1629 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); | 1629 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); |
1630 | } | 1630 | } |
1631 | } | 1631 | } |
1632 | QDateTime modifiedCalendar = mLastCalendarSync; | 1632 | QDateTime modifiedCalendar = mLastCalendarSync; |
1633 | eventLSync = getLastSyncEvent(); | 1633 | eventLSync = getLastSyncEvent(); |
1634 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); | 1634 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); |
1635 | if ( eventR ) { | 1635 | if ( eventR ) { |
1636 | qDebug("last-syncEvent on remote found "); | 1636 | qDebug("last-syncEvent on remote found "); |
1637 | eventRSync = (Event*) eventR->clone(); | 1637 | eventRSync = (Event*) eventR->clone(); |
1638 | remote->deleteEvent(eventR ); | 1638 | remote->deleteEvent(eventR ); |
1639 | 1639 | ||
1640 | } else { | 1640 | } else { |
1641 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { | 1641 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { |
1642 | eventRSync = (Event*)eventLSync->clone(); | 1642 | eventRSync = (Event*)eventLSync->clone(); |
1643 | } else { | 1643 | } else { |
1644 | fullDateRange = true; | 1644 | fullDateRange = true; |
1645 | eventRSync = new Event(); | 1645 | eventRSync = new Event(); |
1646 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); | 1646 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); |
1647 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); | 1647 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); |
1648 | eventRSync->setDtStart( mLastCalendarSync ); | 1648 | eventRSync->setDtStart( mLastCalendarSync ); |
1649 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 1649 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
1650 | eventRSync->setCategories( i18n("SyncEvent") ); | 1650 | eventRSync->setCategories( i18n("SyncEvent") ); |
1651 | } | 1651 | } |
1652 | } | 1652 | } |
1653 | if ( eventLSync->dtStart() == mLastCalendarSync ) | 1653 | if ( eventLSync->dtStart() == mLastCalendarSync ) |
1654 | fullDateRange = true; | 1654 | fullDateRange = true; |
1655 | 1655 | ||
1656 | if ( ! fullDateRange ) { | 1656 | if ( ! fullDateRange ) { |
1657 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { | 1657 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { |
1658 | 1658 | ||
1659 | qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); | 1659 | qDebug("KO: Sync: Set fulldate to true! Local: %s --- Remote: %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); |
1660 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); | 1660 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); |
1661 | fullDateRange = true; | 1661 | fullDateRange = true; |
1662 | } | 1662 | } |
1663 | } | 1663 | } |
1664 | if ( mSyncManager->syncWithDesktop() ) { | 1664 | if ( mSyncManager->syncWithDesktop() ) { |
1665 | fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); | 1665 | fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); |
1666 | } | 1666 | } |
1667 | if ( fullDateRange ) | 1667 | if ( fullDateRange ) |
1668 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | 1668 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); |
1669 | else | 1669 | else |
1670 | mLastCalendarSync = eventLSync->dtStart(); | 1670 | mLastCalendarSync = eventLSync->dtStart(); |
1671 | // for resyncing if own file has changed | 1671 | // for resyncing if own file has changed |
1672 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 1672 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
1673 | mLastCalendarSync = loadedFileVersion; | 1673 | mLastCalendarSync = loadedFileVersion; |
1674 | //qDebug("setting mLastCalendarSync "); | 1674 | //qDebug("setting mLastCalendarSync "); |
1675 | } | 1675 | } |
1676 | //qDebug("*************************** "); | 1676 | //qDebug("*************************** "); |
1677 | qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); | 1677 | qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); |
1678 | QPtrList<Incidence> er = remote->rawIncidences(); | 1678 | QPtrList<Incidence> er = remote->rawIncidences(); |
1679 | Incidence* inR = er.first(); | 1679 | Incidence* inR = er.first(); |
1680 | Incidence* inL; | 1680 | Incidence* inL; |
1681 | QProgressBar bar( er.count(),0 ); | 1681 | QProgressBar bar( er.count(),0 ); |
1682 | bar.setCaption (i18n("Syncing - close to abort!") ); | 1682 | bar.setCaption (i18n("Syncing - close to abort!") ); |
1683 | 1683 | ||
1684 | // ************** setting up filter ************* | 1684 | // ************** setting up filter ************* |
1685 | CalFilter *filterIN = 0; | 1685 | CalFilter *filterIN = 0; |
1686 | CalFilter *filterOUT = 0; | 1686 | CalFilter *filterOUT = 0; |
1687 | CalFilter *filter = mFilters.first(); | 1687 | CalFilter *filter = mFilters.first(); |
1688 | while(filter) { | 1688 | while(filter) { |
1689 | if ( filter->name() == mSyncManager->mFilterInCal ) | 1689 | if ( filter->name() == mSyncManager->mFilterInCal ) |
1690 | filterIN = filter; | 1690 | filterIN = filter; |
1691 | if ( filter->name() == mSyncManager->mFilterOutCal ) | 1691 | if ( filter->name() == mSyncManager->mFilterOutCal ) |
1692 | filterOUT = filter; | 1692 | filterOUT = filter; |
1693 | filter = mFilters.next(); | 1693 | filter = mFilters.next(); |
1694 | } | 1694 | } |
1695 | int w = 300; | 1695 | int w = 300; |
1696 | if ( QApplication::desktop()->width() < 320 ) | 1696 | if ( QApplication::desktop()->width() < 320 ) |
1697 | w = 220; | 1697 | w = 220; |
1698 | int h = bar.sizeHint().height() ; | 1698 | int h = bar.sizeHint().height() ; |
1699 | int dw = QApplication::desktop()->width(); | 1699 | int dw = QApplication::desktop()->width(); |
1700 | int dh = QApplication::desktop()->height(); | 1700 | int dh = QApplication::desktop()->height(); |
1701 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1701 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1702 | bar.show(); | 1702 | bar.show(); |
1703 | int modulo = (er.count()/10)+1; | 1703 | int modulo = (er.count()/10)+1; |
1704 | int incCounter = 0; | 1704 | int incCounter = 0; |
1705 | while ( inR ) { | 1705 | while ( inR ) { |
1706 | if ( ! bar.isVisible() ) | 1706 | if ( ! bar.isVisible() ) |
1707 | return false; | 1707 | return false; |
1708 | if ( incCounter % modulo == 0 ) | 1708 | if ( incCounter % modulo == 0 ) |
1709 | bar.setProgress( incCounter ); | 1709 | bar.setProgress( incCounter ); |
1710 | ++incCounter; | 1710 | ++incCounter; |
1711 | uid = inR->uid(); | 1711 | uid = inR->uid(); |
1712 | bool skipIncidence = false; | 1712 | bool skipIncidence = false; |
1713 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1713 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1714 | skipIncidence = true; | 1714 | skipIncidence = true; |
1715 | QString idS; | 1715 | QString idS; |
1716 | qApp->processEvents(); | 1716 | qApp->processEvents(); |
1717 | if ( !skipIncidence ) { | 1717 | if ( !skipIncidence ) { |
1718 | inL = local->incidenceForUid( uid , false ); | 1718 | inL = local->incidenceForUid( uid , false ); |
1719 | if ( inL ) { // maybe conflict - same uid in both calendars | 1719 | if ( inL ) { // maybe conflict - same uid in both calendars |
1720 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1720 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1721 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1721 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1722 | if ( take == 3 ) | 1722 | if ( take == 3 ) |
1723 | return false; | 1723 | return false; |
1724 | if ( take == 1 ) {// take local ********************** | 1724 | if ( take == 1 ) {// take local ********************** |
1725 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 1725 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
1726 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1726 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1727 | else | 1727 | else |
1728 | idS = inR->IDStr(); | 1728 | idS = inR->IDStr(); |
1729 | int calID = inR->calID(); | 1729 | int calID = inR->calID(); |
1730 | remote->deleteIncidence( inR ); | 1730 | remote->deleteIncidence( inR ); |
1731 | inR = inL->clone(); | 1731 | inR = inL->clone(); |
1732 | inR->setCalID( calID ); | 1732 | inR->setCalID( calID ); |
1733 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1733 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1734 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | 1734 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) |
1735 | inR->setIDStr( idS ); | 1735 | inR->setIDStr( idS ); |
1736 | remote->addIncidence( inR ); | 1736 | remote->addIncidence( inR ); |
1737 | if ( mSyncManager->syncWithDesktop() ) | 1737 | if ( mSyncManager->syncWithDesktop() ) |
1738 | inR->setPilotId( 2 ); | 1738 | inR->setPilotId( 2 ); |
1739 | ++changedRemote; | 1739 | ++changedRemote; |
1740 | } else {// take remote ********************** | 1740 | } else {// take remote ********************** |
1741 | if ( !inL->isReadOnly() ) { | 1741 | if ( !inL->isReadOnly() ) { |
1742 | idS = inL->IDStr(); | 1742 | idS = inL->IDStr(); |
1743 | int pid = inL->pilotId(); | 1743 | int pid = inL->pilotId(); |
1744 | int calID = inL->calID(); | 1744 | int calID = inL->calID(); |
1745 | local->deleteIncidence( inL ); | 1745 | local->deleteIncidence( inL ); |
1746 | inL = inR->clone(); | 1746 | inL = inR->clone(); |
1747 | inL->setCalID( calID ); | 1747 | inL->setCalID( calID ); |
1748 | if ( mSyncManager->syncWithDesktop() ) | 1748 | if ( mSyncManager->syncWithDesktop() ) |
1749 | inL->setPilotId( pid ); | 1749 | inL->setPilotId( pid ); |
1750 | inL->setIDStr( idS ); | 1750 | inL->setIDStr( idS ); |
1751 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1751 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1752 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1752 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1753 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1753 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1754 | } | 1754 | } |
1755 | local->addIncidence( inL ); | 1755 | local->addIncidence( inL ); |
1756 | ++changedLocal; | 1756 | ++changedLocal; |
1757 | } | 1757 | } |
1758 | } | 1758 | } |
1759 | } | 1759 | } |
1760 | } else { // no conflict ********** add or delete remote | 1760 | } else { // no conflict ********** add or delete remote |
1761 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ | 1761 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ |
1762 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1762 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1763 | QString des = eventLSync->description(); | 1763 | QString des = eventLSync->description(); |
1764 | QString pref = "e"; | 1764 | QString pref = "e"; |
1765 | if ( inR->typeID() == todoID ) | 1765 | if ( inR->typeID() == todoID ) |
1766 | pref = "t"; | 1766 | pref = "t"; |
1767 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1767 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1768 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1768 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1769 | //remote->deleteIncidence( inR ); | 1769 | //remote->deleteIncidence( inR ); |
1770 | ++deletedEventR; | 1770 | ++deletedEventR; |
1771 | } else { | 1771 | } else { |
1772 | inR->setLastModified( modifiedCalendar ); | 1772 | inR->setLastModified( modifiedCalendar ); |
1773 | inL = inR->clone(); | 1773 | inL = inR->clone(); |
1774 | inL->setIDStr( ":" ); | 1774 | inL->setIDStr( ":" ); |
1775 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1775 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1776 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1776 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1777 | 1777 | ||
1778 | inL->setCalID( 0 );// add to default cal | 1778 | inL->setCalID( 0 );// add to default cal |
1779 | local->addIncidence( inL ); | 1779 | local->addIncidence( inL ); |
1780 | ++addedEvent; | 1780 | ++addedEvent; |
1781 | 1781 | ||
1782 | } | 1782 | } |
1783 | } else { | 1783 | } else { |
1784 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1784 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1785 | inR->setLastModified( modifiedCalendar ); | 1785 | inR->setLastModified( modifiedCalendar ); |
1786 | inL = inR->clone(); | 1786 | inL = inR->clone(); |
1787 | inL->setIDStr( ":" ); | 1787 | inL->setIDStr( ":" ); |
1788 | inL->setCalID( 0 );// add to default cal | 1788 | inL->setCalID( 0 );// add to default cal |
1789 | local->addIncidence( inL ); | 1789 | local->addIncidence( inL ); |
1790 | ++addedEvent; | 1790 | ++addedEvent; |
1791 | 1791 | ||
1792 | } else { | 1792 | } else { |
1793 | checkExternSyncEvent(eventRSyncSharp, inR); | 1793 | checkExternSyncEvent(eventRSyncSharp, inR); |
1794 | remote->deleteIncidence( inR ); | 1794 | remote->deleteIncidence( inR ); |
1795 | ++deletedEventR; | 1795 | ++deletedEventR; |
1796 | } | 1796 | } |
1797 | } | 1797 | } |
1798 | } else { | 1798 | } else { |
1799 | ++filteredIN; | 1799 | ++filteredIN; |
1800 | } | 1800 | } |
1801 | } | 1801 | } |
1802 | } | 1802 | } |
1803 | inR = er.next(); | 1803 | inR = er.next(); |
1804 | } | 1804 | } |
1805 | QPtrList<Incidence> el = local->rawIncidences(); | 1805 | QPtrList<Incidence> el = local->rawIncidences(); |
1806 | inL = el.first(); | 1806 | inL = el.first(); |
1807 | modulo = (el.count()/10)+1; | 1807 | modulo = (el.count()/10)+1; |
1808 | bar.setCaption (i18n("Add / remove events") ); | 1808 | bar.setCaption (i18n("Add / remove events") ); |
1809 | bar.setTotalSteps ( el.count() ) ; | 1809 | bar.setTotalSteps ( el.count() ) ; |
1810 | bar.show(); | 1810 | bar.show(); |
1811 | incCounter = 0; | 1811 | incCounter = 0; |
1812 | 1812 | ||
1813 | while ( inL ) { | 1813 | while ( inL ) { |
1814 | 1814 | ||
1815 | qApp->processEvents(); | 1815 | qApp->processEvents(); |
1816 | if ( ! bar.isVisible() ) | 1816 | if ( ! bar.isVisible() ) |
1817 | return false; | 1817 | return false; |
1818 | if ( incCounter % modulo == 0 ) | 1818 | if ( incCounter % modulo == 0 ) |
1819 | bar.setProgress( incCounter ); | 1819 | bar.setProgress( incCounter ); |
1820 | ++incCounter; | 1820 | ++incCounter; |
1821 | uid = inL->uid(); | 1821 | uid = inL->uid(); |
1822 | bool skipIncidence = false; | 1822 | bool skipIncidence = false; |
1823 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1823 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1824 | skipIncidence = true; | 1824 | skipIncidence = true; |
1825 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) | 1825 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) |
1826 | skipIncidence = true; | 1826 | skipIncidence = true; |
1827 | if ( !skipIncidence ) { | 1827 | if ( !skipIncidence ) { |
1828 | inR = remote->incidenceForUid( uid , true ); | 1828 | inR = remote->incidenceForUid( uid , true ); |
1829 | if ( ! inR ) { | 1829 | if ( ! inR ) { |
1830 | if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ | 1830 | if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ |
1831 | // no conflict ********** add or delete local | 1831 | // no conflict ********** add or delete local |
1832 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1832 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1833 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1833 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1834 | checkExternSyncEvent(eventLSyncSharp, inL); | 1834 | checkExternSyncEvent(eventLSyncSharp, inL); |
1835 | local->deleteIncidence( inL ); | 1835 | local->deleteIncidence( inL ); |
1836 | ++deletedEventL; | 1836 | ++deletedEventL; |
1837 | } else { | 1837 | } else { |
1838 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1838 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1839 | inL->removeID(mCurrentSyncDevice ); | 1839 | inL->removeID(mCurrentSyncDevice ); |
1840 | ++addedEventR; | 1840 | ++addedEventR; |
1841 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); | 1841 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); |
1842 | inL->setLastModified( modifiedCalendar ); | 1842 | inL->setLastModified( modifiedCalendar ); |
1843 | inR = inL->clone(); | 1843 | inR = inL->clone(); |
1844 | inR->setIDStr( ":" ); | 1844 | inR->setIDStr( ":" ); |
1845 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1845 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1846 | inR->setCalID( 0 );// add to default cal | 1846 | inR->setCalID( 0 );// add to default cal |
1847 | remote->addIncidence( inR ); | 1847 | remote->addIncidence( inR ); |
1848 | } | 1848 | } |
1849 | } | 1849 | } |
1850 | } else { | 1850 | } else { |
1851 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1851 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 0a94914..66836a1 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -127,257 +127,258 @@ public: | |||
127 | /** | 127 | /** |
128 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 128 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
129 | values). | 129 | values). |
130 | */ | 130 | */ |
131 | void setTimeZoneId( const QString & ); | 131 | void setTimeZoneId( const QString & ); |
132 | /** | 132 | /** |
133 | Return time zone id. | 133 | Return time zone id. |
134 | */ | 134 | */ |
135 | QString timeZoneId() const; | 135 | QString timeZoneId() const; |
136 | /** | 136 | /** |
137 | Use local time, not UTC or a time zone. | 137 | Use local time, not UTC or a time zone. |
138 | */ | 138 | */ |
139 | void setLocalTime(); | 139 | void setLocalTime(); |
140 | /** | 140 | /** |
141 | Return whether local time is being used. | 141 | Return whether local time is being used. |
142 | */ | 142 | */ |
143 | bool isLocalTime() const; | 143 | bool isLocalTime() const; |
144 | 144 | ||
145 | /** | 145 | /** |
146 | Add an incidence to calendar. | 146 | Add an incidence to calendar. |
147 | 147 | ||
148 | @return true on success, false on error. | 148 | @return true on success, false on error. |
149 | */ | 149 | */ |
150 | virtual bool addIncidence( Incidence * ); | 150 | virtual bool addIncidence( Incidence * ); |
151 | 151 | ||
152 | // Adds an incidence and all relatedto incidences to the cal | 152 | // Adds an incidence and all relatedto incidences to the cal |
153 | void addIncidenceBranch( Incidence * ); | 153 | void addIncidenceBranch( Incidence * ); |
154 | /** | 154 | /** |
155 | Return filtered list of all incidences of this calendar. | 155 | Return filtered list of all incidences of this calendar. |
156 | */ | 156 | */ |
157 | virtual QPtrList<Incidence> incidences(); | 157 | virtual QPtrList<Incidence> incidences(); |
158 | 158 | ||
159 | /** | 159 | /** |
160 | Return unfiltered list of all incidences of this calendar. | 160 | Return unfiltered list of all incidences of this calendar. |
161 | */ | 161 | */ |
162 | virtual QPtrList<Incidence> rawIncidences(); | 162 | virtual QPtrList<Incidence> rawIncidences(); |
163 | 163 | ||
164 | /** | 164 | /** |
165 | Adds a Event to this calendar object. | 165 | Adds a Event to this calendar object. |
166 | @param anEvent a pointer to the event to add | 166 | @param anEvent a pointer to the event to add |
167 | 167 | ||
168 | @return true on success, false on error. | 168 | @return true on success, false on error. |
169 | */ | 169 | */ |
170 | virtual bool addEventNoDup( Event *event ) = 0; | 170 | virtual bool addEventNoDup( Event *event ) = 0; |
171 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 171 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
172 | virtual bool addEvent( Event *anEvent ) = 0; | 172 | virtual bool addEvent( Event *anEvent ) = 0; |
173 | /** | 173 | /** |
174 | Delete event from calendar. | 174 | Delete event from calendar. |
175 | */ | 175 | */ |
176 | virtual void deleteEvent( Event * ) = 0; | 176 | virtual void deleteEvent( Event * ) = 0; |
177 | /** | 177 | /** |
178 | Retrieves an event on the basis of the unique string ID. | 178 | Retrieves an event on the basis of the unique string ID. |
179 | */ | 179 | */ |
180 | virtual Event *event( const QString &UniqueStr ) = 0; | 180 | virtual Event *event( const QString &UniqueStr ) = 0; |
181 | virtual Event *event( QString, QString ) = 0; | 181 | virtual Event *event( QString, QString ) = 0; |
182 | /** | 182 | /** |
183 | Builds and then returns a list of all events that match for the | 183 | Builds and then returns a list of all events that match for the |
184 | date specified. useful for dayView, etc. etc. | 184 | date specified. useful for dayView, etc. etc. |
185 | The calendar filter is applied. | 185 | The calendar filter is applied. |
186 | */ | 186 | */ |
187 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 187 | QPtrList<Event> events( const QDate &date, bool sorted = false); |
188 | /** | 188 | /** |
189 | Get events, which occur on the given date. | 189 | Get events, which occur on the given date. |
190 | The calendar filter is applied. | 190 | The calendar filter is applied. |
191 | */ | 191 | */ |
192 | QPtrList<Event> events( const QDateTime &qdt ); | 192 | QPtrList<Event> events( const QDateTime &qdt ); |
193 | /** | 193 | /** |
194 | Get events in a range of dates. If inclusive is set to true, only events | 194 | Get events in a range of dates. If inclusive is set to true, only events |
195 | are returned, which are completely included in the range. | 195 | are returned, which are completely included in the range. |
196 | The calendar filter is applied. | 196 | The calendar filter is applied. |
197 | */ | 197 | */ |
198 | QPtrList<Event> events( const QDate &start, const QDate &end, | 198 | QPtrList<Event> events( const QDate &start, const QDate &end, |
199 | bool inclusive = false); | 199 | bool inclusive = false); |
200 | /** | 200 | /** |
201 | Return filtered list of all events in calendar. | 201 | Return filtered list of all events in calendar. |
202 | */ | 202 | */ |
203 | virtual QPtrList<Event> events(); | 203 | virtual QPtrList<Event> events(); |
204 | /** | 204 | /** |
205 | Return unfiltered list of all events in calendar. | 205 | Return unfiltered list of all events in calendar. |
206 | */ | 206 | */ |
207 | virtual QPtrList<Event> rawEvents() = 0; | 207 | virtual QPtrList<Event> rawEvents() = 0; |
208 | 208 | ||
209 | /** | 209 | /** |
210 | Add a todo to the todolist. | 210 | Add a todo to the todolist. |
211 | 211 | ||
212 | @return true on success, false on error. | 212 | @return true on success, false on error. |
213 | */ | 213 | */ |
214 | virtual bool addTodo( Todo *todo ) = 0; | 214 | virtual bool addTodo( Todo *todo ) = 0; |
215 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 215 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
216 | /** | 216 | /** |
217 | Remove a todo from the todolist. | 217 | Remove a todo from the todolist. |
218 | */ | 218 | */ |
219 | virtual void deleteTodo( Todo * ) = 0; | 219 | virtual void deleteTodo( Todo * ) = 0; |
220 | virtual void deleteJournal( Journal * ) = 0; | 220 | virtual void deleteJournal( Journal * ) = 0; |
221 | /** | 221 | /** |
222 | Return filterd list of todos. | 222 | Return filterd list of todos. |
223 | */ | 223 | */ |
224 | virtual QPtrList<Todo> todos(); | 224 | virtual QPtrList<Todo> todos(); |
225 | /** | 225 | /** |
226 | Searches todolist for an event with this unique string identifier, | 226 | Searches todolist for an event with this unique string identifier, |
227 | returns a pointer or null. | 227 | returns a pointer or null. |
228 | */ | 228 | */ |
229 | virtual Todo *todo( const QString &uid ) = 0; | 229 | virtual Todo *todo( const QString &uid ) = 0; |
230 | virtual Todo *todo( QString, QString ) = 0; | 230 | virtual Todo *todo( QString, QString ) = 0; |
231 | /** | 231 | /** |
232 | Returns list of todos due on the specified date. | 232 | Returns list of todos due on the specified date. |
233 | */ | 233 | */ |
234 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 234 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; |
235 | /** | 235 | /** |
236 | Return unfiltered list of todos. | 236 | Return unfiltered list of todos. |
237 | */ | 237 | */ |
238 | virtual QPtrList<Todo> rawTodos() = 0; | 238 | virtual QPtrList<Todo> rawTodos() = 0; |
239 | 239 | ||
240 | /** | 240 | /** |
241 | Add a Journal entry to calendar. | 241 | Add a Journal entry to calendar. |
242 | 242 | ||
243 | @return true on success, false on error. | 243 | @return true on success, false on error. |
244 | */ | 244 | */ |
245 | virtual bool addJournal( Journal * ) = 0; | 245 | virtual bool addJournal( Journal * ) = 0; |
246 | /** | 246 | /** |
247 | Return Journal for given date. | 247 | Return Journal for given date. |
248 | */ | 248 | */ |
249 | virtual Journal *journal( const QDate & ) = 0; | 249 | virtual Journal *journal( const QDate & ) = 0; |
250 | virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; | 250 | virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; |
251 | /** | 251 | /** |
252 | Return Journal with given UID. | 252 | Return Journal with given UID. |
253 | */ | 253 | */ |
254 | virtual Journal *journal( const QString &UID ) = 0; | 254 | virtual Journal *journal( const QString &UID ) = 0; |
255 | /** | 255 | /** |
256 | Return list of all Journal entries. | 256 | Return list of all Journal entries. |
257 | */ | 257 | */ |
258 | virtual QPtrList<Journal> journals() = 0; | 258 | virtual QPtrList<Journal> journals() = 0; |
259 | 259 | ||
260 | /** | 260 | /** |
261 | Searches all incidence types for an incidence with this unique | 261 | Searches all incidence types for an incidence with this unique |
262 | string identifier, returns a pointer or null. | 262 | string identifier, returns a pointer or null. |
263 | */ | 263 | */ |
264 | Incidence* incidence( const QString&UID ); | 264 | Incidence* incidence( const QString&UID ); |
265 | 265 | ||
266 | /** | 266 | /** |
267 | Setup relations for an incidence. | 267 | Setup relations for an incidence. |
268 | */ | 268 | */ |
269 | virtual void setupRelations( Incidence * ); | 269 | virtual void setupRelations( Incidence * ); |
270 | /** | 270 | /** |
271 | Remove all relations to an incidence | 271 | Remove all relations to an incidence |
272 | */ | 272 | */ |
273 | virtual void removeRelations( Incidence * ); | 273 | virtual void removeRelations( Incidence * ); |
274 | 274 | ||
275 | /** | 275 | /** |
276 | Set calendar filter, which filters events for the events() functions. | 276 | Set calendar filter, which filters events for the events() functions. |
277 | The Filter object is owned by the caller. | 277 | The Filter object is owned by the caller. |
278 | */ | 278 | */ |
279 | void setFilter( CalFilter * ); | 279 | void setFilter( CalFilter * ); |
280 | /** | 280 | /** |
281 | Return calendar filter. | 281 | Return calendar filter. |
282 | */ | 282 | */ |
283 | CalFilter *filter(); | 283 | CalFilter *filter(); |
284 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 284 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
285 | virtual QString nextSummary( ) const = 0; | 285 | virtual QString nextSummary( ) const = 0; |
286 | virtual void reInitAlarmSettings() = 0; | 286 | virtual void reInitAlarmSettings() = 0; |
287 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 287 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
288 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 288 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
289 | /** | 289 | /** |
290 | Return all alarms, which ocur in the given time interval. | 290 | Return all alarms, which ocur in the given time interval. |
291 | */ | 291 | */ |
292 | virtual Alarm::List alarms( const QDateTime &from, | 292 | virtual Alarm::List alarms( const QDateTime &from, |
293 | const QDateTime &to ) = 0; | 293 | const QDateTime &to ) = 0; |
294 | 294 | ||
295 | class Observer { | 295 | class Observer { |
296 | public: | 296 | public: |
297 | virtual void calendarModified( bool, Calendar * ) = 0; | 297 | virtual void calendarModified( bool, Calendar * ) = 0; |
298 | }; | 298 | }; |
299 | 299 | ||
300 | void registerObserver( Observer * ); | 300 | void registerObserver( Observer * ); |
301 | 301 | ||
302 | void setModified( bool ); | 302 | void setModified( bool ); |
303 | 303 | ||
304 | /** | 304 | /** |
305 | Set product id returned by loadedProductId(). This function is only | 305 | Set product id returned by loadedProductId(). This function is only |
306 | useful for the calendar loading code. | 306 | useful for the calendar loading code. |
307 | */ | 307 | */ |
308 | void setLoadedProductId( const QString & ); | 308 | void setLoadedProductId( const QString & ); |
309 | /** | 309 | /** |
310 | Return product id taken from file that has been loaded. Returns | 310 | Return product id taken from file that has been loaded. Returns |
311 | QString::null, if no calendar has been loaded. | 311 | QString::null, if no calendar has been loaded. |
312 | */ | 312 | */ |
313 | QString loadedProductId(); | 313 | QString loadedProductId(); |
314 | int defaultCalendar(); | 314 | int defaultCalendar(); |
315 | void setDontDeleteIncidencesOnClose (); | 315 | void setDontDeleteIncidencesOnClose (); |
316 | public slots: | 316 | public slots: |
317 | void setDefaultCalendar( int ); | 317 | void setDefaultCalendar( int ); |
318 | virtual void setCalendarEnabled( int id, bool enable ) = 0; | 318 | virtual void setCalendarEnabled( int id, bool enable ) = 0; |
319 | virtual void setAllCalendarEnabled( bool enable ) = 0; | ||
319 | virtual void setAlarmEnabled( int id, bool enable ) = 0; | 320 | virtual void setAlarmEnabled( int id, bool enable ) = 0; |
320 | virtual void setReadOnly( int id, bool enable ) = 0; | 321 | virtual void setReadOnly( int id, bool enable ) = 0; |
321 | virtual void setDefaultCalendarEnabledOnly() = 0; | 322 | virtual void setDefaultCalendarEnabledOnly() = 0; |
322 | virtual void setCalendarRemove( int id ) = 0; | 323 | virtual void setCalendarRemove( int id ) = 0; |
323 | virtual void getIncidenceCount( int calId, int& events, int & todos, int & journals) = 0; | 324 | virtual void getIncidenceCount( int calId, int& events, int & todos, int & journals) = 0; |
324 | 325 | ||
325 | signals: | 326 | signals: |
326 | void calendarChanged(); | 327 | void calendarChanged(); |
327 | void calendarSaved(); | 328 | void calendarSaved(); |
328 | void calendarLoaded(); | 329 | void calendarLoaded(); |
329 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 330 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
330 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 331 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
331 | 332 | ||
332 | protected: | 333 | protected: |
333 | /** | 334 | /** |
334 | Get unfiltered events, which occur on the given date. | 335 | Get unfiltered events, which occur on the given date. |
335 | */ | 336 | */ |
336 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 337 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
337 | /** | 338 | /** |
338 | Get unfiltered events, which occur on the given date. | 339 | Get unfiltered events, which occur on the given date. |
339 | */ | 340 | */ |
340 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 341 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, |
341 | bool sorted = false ) = 0; | 342 | bool sorted = false ) = 0; |
342 | /** | 343 | /** |
343 | Get events in a range of dates. If inclusive is set to true, only events | 344 | Get events in a range of dates. If inclusive is set to true, only events |
344 | are returned, which are completely included in the range. | 345 | are returned, which are completely included in the range. |
345 | */ | 346 | */ |
346 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 347 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
347 | bool inclusive = false ) = 0; | 348 | bool inclusive = false ) = 0; |
348 | 349 | ||
349 | Incidence *mNextAlarmIncidence; | 350 | Incidence *mNextAlarmIncidence; |
350 | Incidence *mUndoIncidence; | 351 | Incidence *mUndoIncidence; |
351 | int mDefaultCalendar; | 352 | int mDefaultCalendar; |
352 | bool mDeleteIncidencesOnClose; | 353 | bool mDeleteIncidencesOnClose; |
353 | 354 | ||
354 | private: | 355 | private: |
355 | void init(); | 356 | void init(); |
356 | 357 | ||
357 | QString mOwner; // who the calendar belongs to | 358 | QString mOwner; // who the calendar belongs to |
358 | QString mOwnerEmail; // email address of the owner | 359 | QString mOwnerEmail; // email address of the owner |
359 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 360 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
360 | bool mLocalTime; // use local time, not UTC or a time zone | 361 | bool mLocalTime; // use local time, not UTC or a time zone |
361 | 362 | ||
362 | 363 | ||
363 | CalFilter *mFilter; | 364 | CalFilter *mFilter; |
364 | CalFilter *mDefaultFilter; | 365 | CalFilter *mDefaultFilter; |
365 | 366 | ||
366 | 367 | ||
367 | QString mTimeZoneId; | 368 | QString mTimeZoneId; |
368 | 369 | ||
369 | Observer *mObserver; | 370 | Observer *mObserver; |
370 | bool mNewObserver; | 371 | bool mNewObserver; |
371 | 372 | ||
372 | bool mModified; | 373 | bool mModified; |
373 | 374 | ||
374 | QString mLoadedProductId; | 375 | QString mLoadedProductId; |
375 | 376 | ||
376 | // This list is used to put together related todos | 377 | // This list is used to put together related todos |
377 | QDict<Incidence> mOrphans; | 378 | QDict<Incidence> mOrphans; |
378 | QDict<Incidence> mOrphanUids; | 379 | QDict<Incidence> mOrphanUids; |
379 | }; | 380 | }; |
380 | 381 | ||
381 | } | 382 | } |
382 | 383 | ||
383 | #endif | 384 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 45e3128..2a57724 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,401 +1,411 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | registerObserver( 0 ); | 68 | registerObserver( 0 ); |
69 | if ( mDeleteIncidencesOnClose ) | 69 | if ( mDeleteIncidencesOnClose ) |
70 | close(); | 70 | close(); |
71 | } | 71 | } |
72 | bool CalendarLocal::mergeCalendarFile( QString name ) | 72 | bool CalendarLocal::mergeCalendarFile( QString name ) |
73 | { | 73 | { |
74 | CalendarLocal calendar( timeZoneId() ); | 74 | CalendarLocal calendar( timeZoneId() ); |
75 | calendar.setDefaultCalendar( 1 ); | 75 | calendar.setDefaultCalendar( 1 ); |
76 | if ( calendar.load( name ) ) { | 76 | if ( calendar.load( name ) ) { |
77 | mergeCalendar( &calendar ); | 77 | mergeCalendar( &calendar ); |
78 | return true; | 78 | return true; |
79 | } | 79 | } |
80 | return false; | 80 | return false; |
81 | } | 81 | } |
82 | 82 | ||
83 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) | 83 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) |
84 | { | 84 | { |
85 | Todo *todo;; | 85 | Todo *todo;; |
86 | Incidence *retVal = 0; | 86 | Incidence *retVal = 0; |
87 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 87 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
88 | if ( todo->uid() == uid ) { | 88 | if ( todo->uid() == uid ) { |
89 | if ( doNotCheckDuplicates ) return todo; | 89 | if ( doNotCheckDuplicates ) return todo; |
90 | if ( retVal ) { | 90 | if ( retVal ) { |
91 | if ( retVal->calID() > todo->calID() ) { | 91 | if ( retVal->calID() > todo->calID() ) { |
92 | retVal = todo; | 92 | retVal = todo; |
93 | } | 93 | } |
94 | } else { | 94 | } else { |
95 | retVal = todo; | 95 | retVal = todo; |
96 | } | 96 | } |
97 | } | 97 | } |
98 | } | 98 | } |
99 | if ( retVal ) return retVal; | 99 | if ( retVal ) return retVal; |
100 | Event *event; | 100 | Event *event; |
101 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 101 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
102 | if ( event->uid() == uid ) { | 102 | if ( event->uid() == uid ) { |
103 | if ( doNotCheckDuplicates ) return event; | 103 | if ( doNotCheckDuplicates ) return event; |
104 | if ( retVal ) { | 104 | if ( retVal ) { |
105 | if ( retVal->calID() > event->calID() ) { | 105 | if ( retVal->calID() > event->calID() ) { |
106 | retVal = event; | 106 | retVal = event; |
107 | } | 107 | } |
108 | } else { | 108 | } else { |
109 | retVal = event; | 109 | retVal = event; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | } | 112 | } |
113 | if ( retVal ) return retVal; | 113 | if ( retVal ) return retVal; |
114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
115 | if ( it->uid() == uid ) { | 115 | if ( it->uid() == uid ) { |
116 | if ( doNotCheckDuplicates ) return it; | 116 | if ( doNotCheckDuplicates ) return it; |
117 | if ( retVal ) { | 117 | if ( retVal ) { |
118 | if ( retVal->calID() > it->calID() ) { | 118 | if ( retVal->calID() > it->calID() ) { |
119 | retVal = it; | 119 | retVal = it; |
120 | } | 120 | } |
121 | } else { | 121 | } else { |
122 | retVal = it; | 122 | retVal = it; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | return retVal; | 125 | return retVal; |
126 | } | 126 | } |
127 | 127 | ||
128 | bool CalendarLocal::mergeCalendar( Calendar* remote ) | 128 | bool CalendarLocal::mergeCalendar( Calendar* remote ) |
129 | { | 129 | { |
130 | // 1 look for raw inc in local | 130 | // 1 look for raw inc in local |
131 | // if inc not in remote, delete in local | 131 | // if inc not in remote, delete in local |
132 | // 2 look for raw inc in remote | 132 | // 2 look for raw inc in remote |
133 | // if inc in local, replace it | 133 | // if inc in local, replace it |
134 | // if not in local, add it to default calendar | 134 | // if not in local, add it to default calendar |
135 | QPtrList<Incidence> localInc = rawIncidences(); | 135 | QPtrList<Incidence> localInc = rawIncidences(); |
136 | Incidence* inL = localInc.first(); | 136 | Incidence* inL = localInc.first(); |
137 | while ( inL ) { | 137 | while ( inL ) { |
138 | if ( ! inL->isReadOnly () ) | 138 | if ( ! inL->isReadOnly () ) |
139 | if ( !remote->incidenceForUid( inL->uid(), true )) | 139 | if ( !remote->incidenceForUid( inL->uid(), true )) |
140 | deleteIncidence( inL ); | 140 | deleteIncidence( inL ); |
141 | inL = localInc.next(); | 141 | inL = localInc.next(); |
142 | } | 142 | } |
143 | QPtrList<Incidence> er = remote->rawIncidences(); | 143 | QPtrList<Incidence> er = remote->rawIncidences(); |
144 | Incidence* inR = er.first(); | 144 | Incidence* inR = er.first(); |
145 | while ( inR ) { | 145 | while ( inR ) { |
146 | inL = incidenceForUid( inR->uid(),false ); | 146 | inL = incidenceForUid( inR->uid(),false ); |
147 | if ( inL ) { | 147 | if ( inL ) { |
148 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { | 148 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { |
149 | int calID = inL->calID(); | 149 | int calID = inL->calID(); |
150 | deleteIncidence( inL ); | 150 | deleteIncidence( inL ); |
151 | inL = inR->clone(); | 151 | inL = inR->clone(); |
152 | inL->setCalID( calID ); | 152 | inL->setCalID( calID ); |
153 | addIncidence( inL ); | 153 | addIncidence( inL ); |
154 | } | 154 | } |
155 | } else { | 155 | } else { |
156 | inL = inR->clone(); | 156 | inL = inR->clone(); |
157 | inL->setCalID( 0 );// add to default cal | 157 | inL->setCalID( 0 );// add to default cal |
158 | addIncidence( inL ); | 158 | addIncidence( inL ); |
159 | } | 159 | } |
160 | inR = er.next(); | 160 | inR = er.next(); |
161 | } | 161 | } |
162 | return true; | 162 | return true; |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 166 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
167 | { | 167 | { |
168 | CalendarLocal calendar( timeZoneId() ); | 168 | CalendarLocal calendar( timeZoneId() ); |
169 | calendar.setDefaultCalendar( id ); | 169 | calendar.setDefaultCalendar( id ); |
170 | if ( calendar.load( name ) ) { | 170 | if ( calendar.load( name ) ) { |
171 | addCalendar( &calendar ); | 171 | addCalendar( &calendar ); |
172 | return true; | 172 | return true; |
173 | } | 173 | } |
174 | return false; | 174 | return false; |
175 | } | 175 | } |
176 | void CalendarLocal::setSyncEventsEnabled() | 176 | void CalendarLocal::setSyncEventsEnabled() |
177 | { | 177 | { |
178 | Event * ev; | 178 | Event * ev; |
179 | ev = mEventList.first(); | 179 | ev = mEventList.first(); |
180 | while ( ev ) { | 180 | while ( ev ) { |
181 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 181 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
182 | ev->setCalEnabled( true ); | 182 | ev->setCalEnabled( true ); |
183 | ev = mEventList.next(); | 183 | ev = mEventList.next(); |
184 | } | 184 | } |
185 | } | 185 | } |
186 | void CalendarLocal::setSyncEventsReadOnly() | 186 | void CalendarLocal::setSyncEventsReadOnly() |
187 | { | 187 | { |
188 | Event * ev; | 188 | Event * ev; |
189 | ev = mEventList.first(); | 189 | ev = mEventList.first(); |
190 | while ( ev ) { | 190 | while ( ev ) { |
191 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { | 191 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { |
192 | ev->setReadOnly( true ); | 192 | ev->setReadOnly( true ); |
193 | ev->setCalID( 1 ); | ||
194 | } | 193 | } |
195 | ev = mEventList.next(); | 194 | ev = mEventList.next(); |
196 | } | 195 | } |
197 | } | 196 | } |
197 | |||
198 | void CalendarLocal::addCalendar( Calendar* cal ) | 198 | void CalendarLocal::addCalendar( Calendar* cal ) |
199 | { | 199 | { |
200 | cal->setDontDeleteIncidencesOnClose(); | 200 | cal->setDontDeleteIncidencesOnClose(); |
201 | setSyncEventsEnabled(); | ||
201 | { | 202 | { |
202 | QPtrList<Event> EventList = cal->rawEvents(); | 203 | QPtrList<Event> EventList = cal->rawEvents(); |
204 | QPtrList<Event> el; | ||
203 | Event * ev = EventList.first(); | 205 | Event * ev = EventList.first(); |
204 | while ( ev ) { | 206 | while ( ev ) { |
207 | if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { | ||
208 | Event * se = event( ev->uid() ); | ||
209 | if ( se ) | ||
210 | el.append( se ); | ||
211 | } | ||
205 | ev->unRegisterObserver( cal ); | 212 | ev->unRegisterObserver( cal ); |
206 | ev->registerObserver( this ); | 213 | ev->registerObserver( this ); |
207 | mEventList.append( ev ); | 214 | mEventList.append( ev ); |
208 | ev = EventList.next(); | 215 | ev = EventList.next(); |
209 | } | 216 | } |
217 | for ( ev = el.first(); ev; ev = el.next() ) { | ||
218 | deleteIncidence ( ev ); | ||
219 | } | ||
210 | } | 220 | } |
211 | { | 221 | { |
212 | 222 | ||
213 | QPtrList<Todo> TodoList = cal->rawTodos(); | 223 | QPtrList<Todo> TodoList = cal->rawTodos(); |
214 | Todo * ev = TodoList.first(); | 224 | Todo * ev = TodoList.first(); |
215 | while ( ev ) { | 225 | while ( ev ) { |
216 | QString rel = ev->relatedToUid(); | 226 | QString rel = ev->relatedToUid(); |
217 | if ( !rel.isEmpty() ){ | 227 | if ( !rel.isEmpty() ){ |
218 | ev->setRelatedTo ( 0 ); | 228 | ev->setRelatedTo ( 0 ); |
219 | ev->setRelatedToUid( rel ); | 229 | ev->setRelatedToUid( rel ); |
220 | } | 230 | } |
221 | ev = TodoList.next(); | 231 | ev = TodoList.next(); |
222 | } | 232 | } |
223 | //TodoList = cal->rawTodos(); | 233 | //TodoList = cal->rawTodos(); |
224 | ev = TodoList.first(); | 234 | ev = TodoList.first(); |
225 | while ( ev ) { | 235 | while ( ev ) { |
226 | ev->unRegisterObserver( cal ); | 236 | ev->unRegisterObserver( cal ); |
227 | ev->registerObserver( this ); | 237 | ev->registerObserver( this ); |
228 | mTodoList.append( ev ); | 238 | mTodoList.append( ev ); |
229 | setupRelations( ev ); | 239 | setupRelations( ev ); |
230 | ev = TodoList.next(); | 240 | ev = TodoList.next(); |
231 | } | 241 | } |
232 | } | 242 | } |
233 | { | 243 | { |
234 | QPtrList<Journal> JournalList = cal->journals(); | 244 | QPtrList<Journal> JournalList = cal->journals(); |
235 | Journal * ev = JournalList.first(); | 245 | Journal * ev = JournalList.first(); |
236 | while ( ev ) { | 246 | while ( ev ) { |
237 | ev->unRegisterObserver( cal ); | 247 | ev->unRegisterObserver( cal ); |
238 | ev->registerObserver( this ); | 248 | ev->registerObserver( this ); |
239 | mJournalList.append( ev ); | 249 | mJournalList.append( ev ); |
240 | ev = JournalList.next(); | 250 | ev = JournalList.next(); |
241 | } | 251 | } |
242 | } | 252 | } |
243 | setModified( true ); | 253 | setModified( true ); |
244 | } | 254 | } |
245 | bool CalendarLocal::load( const QString &fileName ) | 255 | bool CalendarLocal::load( const QString &fileName ) |
246 | { | 256 | { |
247 | FileStorage storage( this, fileName ); | 257 | FileStorage storage( this, fileName ); |
248 | return storage.load(); | 258 | return storage.load(); |
249 | } | 259 | } |
250 | 260 | ||
251 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 261 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
252 | { | 262 | { |
253 | FileStorage storage( this, fileName, format ); | 263 | FileStorage storage( this, fileName, format ); |
254 | return storage.save(); | 264 | return storage.save(); |
255 | } | 265 | } |
256 | 266 | ||
257 | void CalendarLocal::stopAllTodos() | 267 | void CalendarLocal::stopAllTodos() |
258 | { | 268 | { |
259 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 269 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
260 | it->setRunning( false ); | 270 | it->setRunning( false ); |
261 | 271 | ||
262 | } | 272 | } |
263 | void CalendarLocal::close() | 273 | void CalendarLocal::close() |
264 | { | 274 | { |
265 | 275 | ||
266 | Todo * i; | 276 | Todo * i; |
267 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 277 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
268 | 278 | ||
269 | mEventList.setAutoDelete( true ); | 279 | mEventList.setAutoDelete( true ); |
270 | mTodoList.setAutoDelete( true ); | 280 | mTodoList.setAutoDelete( true ); |
271 | mJournalList.setAutoDelete( true ); | 281 | mJournalList.setAutoDelete( true ); |
272 | 282 | ||
273 | mEventList.clear(); | 283 | mEventList.clear(); |
274 | mTodoList.clear(); | 284 | mTodoList.clear(); |
275 | mJournalList.clear(); | 285 | mJournalList.clear(); |
276 | 286 | ||
277 | mEventList.setAutoDelete( false ); | 287 | mEventList.setAutoDelete( false ); |
278 | mTodoList.setAutoDelete( false ); | 288 | mTodoList.setAutoDelete( false ); |
279 | mJournalList.setAutoDelete( false ); | 289 | mJournalList.setAutoDelete( false ); |
280 | 290 | ||
281 | setModified( false ); | 291 | setModified( false ); |
282 | } | 292 | } |
283 | 293 | ||
284 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 294 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
285 | { | 295 | { |
286 | QString cat; | 296 | QString cat; |
287 | bool isBirthday = true; | 297 | bool isBirthday = true; |
288 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 298 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
289 | isBirthday = false; | 299 | isBirthday = false; |
290 | cat = i18n( "Anniversary" ); | 300 | cat = i18n( "Anniversary" ); |
291 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 301 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
292 | isBirthday = true; | 302 | isBirthday = true; |
293 | cat = i18n( "Birthday" ); | 303 | cat = i18n( "Birthday" ); |
294 | } else { | 304 | } else { |
295 | qDebug("addAnniversaryNoDup called without fitting category! "); | 305 | qDebug("addAnniversaryNoDup called without fitting category! "); |
296 | return false; | 306 | return false; |
297 | } | 307 | } |
298 | Event * eve; | 308 | Event * eve; |
299 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 309 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
300 | if ( !(eve->categories().contains( cat ) )) | 310 | if ( !(eve->categories().contains( cat ) )) |
301 | continue; | 311 | continue; |
302 | // now we have an event with fitting category | 312 | // now we have an event with fitting category |
303 | if ( eve->dtStart().date() != event->dtStart().date() ) | 313 | if ( eve->dtStart().date() != event->dtStart().date() ) |
304 | continue; | 314 | continue; |
305 | // now we have an event with fitting category+date | 315 | // now we have an event with fitting category+date |
306 | if ( eve->summary() != event->summary() ) | 316 | if ( eve->summary() != event->summary() ) |
307 | continue; | 317 | continue; |
308 | // now we have an event with fitting category+date+summary | 318 | // now we have an event with fitting category+date+summary |
309 | return false; | 319 | return false; |
310 | } | 320 | } |
311 | return addEvent( event ); | 321 | return addEvent( event ); |
312 | 322 | ||
313 | } | 323 | } |
314 | bool CalendarLocal::addEventNoDup( Event *event ) | 324 | bool CalendarLocal::addEventNoDup( Event *event ) |
315 | { | 325 | { |
316 | Event * eve; | 326 | Event * eve; |
317 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 327 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
318 | if ( *eve == *event ) { | 328 | if ( *eve == *event ) { |
319 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 329 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
320 | return false; | 330 | return false; |
321 | } | 331 | } |
322 | } | 332 | } |
323 | return addEvent( event ); | 333 | return addEvent( event ); |
324 | } | 334 | } |
325 | 335 | ||
326 | bool CalendarLocal::addEvent( Event *event ) | 336 | bool CalendarLocal::addEvent( Event *event ) |
327 | { | 337 | { |
328 | insertEvent( event ); | 338 | insertEvent( event ); |
329 | 339 | ||
330 | event->registerObserver( this ); | 340 | event->registerObserver( this ); |
331 | 341 | ||
332 | setModified( true ); | 342 | setModified( true ); |
333 | if ( event->calID() == 0 ) | 343 | if ( event->calID() == 0 ) |
334 | event->setCalID( mDefaultCalendar ); | 344 | event->setCalID( mDefaultCalendar ); |
335 | event->setCalEnabled( true ); | 345 | event->setCalEnabled( true ); |
336 | 346 | ||
337 | return true; | 347 | return true; |
338 | } | 348 | } |
339 | 349 | ||
340 | void CalendarLocal::deleteEvent( Event *event ) | 350 | void CalendarLocal::deleteEvent( Event *event ) |
341 | { | 351 | { |
342 | clearUndo(event); | 352 | clearUndo(event); |
343 | if ( mEventList.removeRef( event ) ) { | 353 | if ( mEventList.removeRef( event ) ) { |
344 | setModified( true ); | 354 | setModified( true ); |
345 | } | 355 | } |
346 | } | 356 | } |
347 | 357 | ||
348 | 358 | ||
349 | Event *CalendarLocal::event( const QString &uid ) | 359 | Event *CalendarLocal::event( const QString &uid ) |
350 | { | 360 | { |
351 | Event *event; | 361 | Event *event; |
352 | Event *retVal = 0; | 362 | Event *retVal = 0; |
353 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 363 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
354 | if ( event->calEnabled() && event->uid() == uid ) { | 364 | if ( event->calEnabled() && event->uid() == uid ) { |
355 | if ( retVal ) { | 365 | if ( retVal ) { |
356 | if ( retVal->calID() > event->calID() ) { | 366 | if ( retVal->calID() > event->calID() ) { |
357 | retVal = event; | 367 | retVal = event; |
358 | } | 368 | } |
359 | } else { | 369 | } else { |
360 | retVal = event; | 370 | retVal = event; |
361 | } | 371 | } |
362 | } | 372 | } |
363 | } | 373 | } |
364 | return retVal; | 374 | return retVal; |
365 | } | 375 | } |
366 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 376 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
367 | { | 377 | { |
368 | Todo * eve; | 378 | Todo * eve; |
369 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 379 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
370 | if ( *eve == *todo ) { | 380 | if ( *eve == *todo ) { |
371 | //qDebug("duplicate todo found! not inserted! "); | 381 | //qDebug("duplicate todo found! not inserted! "); |
372 | return false; | 382 | return false; |
373 | } | 383 | } |
374 | } | 384 | } |
375 | return addTodo( todo ); | 385 | return addTodo( todo ); |
376 | } | 386 | } |
377 | bool CalendarLocal::addTodo( Todo *todo ) | 387 | bool CalendarLocal::addTodo( Todo *todo ) |
378 | { | 388 | { |
379 | mTodoList.append( todo ); | 389 | mTodoList.append( todo ); |
380 | 390 | ||
381 | todo->registerObserver( this ); | 391 | todo->registerObserver( this ); |
382 | 392 | ||
383 | // Set up subtask relations | 393 | // Set up subtask relations |
384 | setupRelations( todo ); | 394 | setupRelations( todo ); |
385 | 395 | ||
386 | setModified( true ); | 396 | setModified( true ); |
387 | if ( todo->calID() == 0 ) | 397 | if ( todo->calID() == 0 ) |
388 | todo->setCalID( mDefaultCalendar ); | 398 | todo->setCalID( mDefaultCalendar ); |
389 | todo->setCalEnabled( true ); | 399 | todo->setCalEnabled( true ); |
390 | return true; | 400 | return true; |
391 | } | 401 | } |
392 | 402 | ||
393 | void CalendarLocal::deleteTodo( Todo *todo ) | 403 | void CalendarLocal::deleteTodo( Todo *todo ) |
394 | { | 404 | { |
395 | // Handle orphaned children | 405 | // Handle orphaned children |
396 | removeRelations( todo ); | 406 | removeRelations( todo ); |
397 | clearUndo(todo); | 407 | clearUndo(todo); |
398 | 408 | ||
399 | if ( mTodoList.removeRef( todo ) ) { | 409 | if ( mTodoList.removeRef( todo ) ) { |
400 | setModified( true ); | 410 | setModified( true ); |
401 | } | 411 | } |
@@ -814,243 +824,256 @@ QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | |||
814 | } | 824 | } |
815 | 825 | ||
816 | 826 | ||
817 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 827 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
818 | bool inclusive ) | 828 | bool inclusive ) |
819 | { | 829 | { |
820 | Event *event = 0; | 830 | Event *event = 0; |
821 | 831 | ||
822 | QPtrList<Event> eventList; | 832 | QPtrList<Event> eventList; |
823 | 833 | ||
824 | // Get non-recurring events | 834 | // Get non-recurring events |
825 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 835 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
826 | if ( !event->calEnabled() ) continue; | 836 | if ( !event->calEnabled() ) continue; |
827 | if ( event->doesRecur() ) { | 837 | if ( event->doesRecur() ) { |
828 | QDate rStart = event->dtStart().date(); | 838 | QDate rStart = event->dtStart().date(); |
829 | bool found = false; | 839 | bool found = false; |
830 | if ( inclusive ) { | 840 | if ( inclusive ) { |
831 | if ( rStart >= start && rStart <= end ) { | 841 | if ( rStart >= start && rStart <= end ) { |
832 | // Start date of event is in range. Now check for end date. | 842 | // Start date of event is in range. Now check for end date. |
833 | // if duration is negative, event recurs forever, so do not include it. | 843 | // if duration is negative, event recurs forever, so do not include it. |
834 | if ( event->recurrence()->duration() == 0 ) { // End date set | 844 | if ( event->recurrence()->duration() == 0 ) { // End date set |
835 | QDate rEnd = event->recurrence()->endDate(); | 845 | QDate rEnd = event->recurrence()->endDate(); |
836 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 846 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
837 | found = true; | 847 | found = true; |
838 | } | 848 | } |
839 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 849 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
840 | // TODO: Calculate end date from duration. Should be done in Event | 850 | // TODO: Calculate end date from duration. Should be done in Event |
841 | // For now exclude all events with a duration. | 851 | // For now exclude all events with a duration. |
842 | } | 852 | } |
843 | } | 853 | } |
844 | } else { | 854 | } else { |
845 | bool founOne; | 855 | bool founOne; |
846 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 856 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
847 | if ( founOne ) { | 857 | if ( founOne ) { |
848 | if ( next <= end ) { | 858 | if ( next <= end ) { |
849 | found = true; | 859 | found = true; |
850 | } | 860 | } |
851 | } | 861 | } |
852 | 862 | ||
853 | /* | 863 | /* |
854 | // crap !!! | 864 | // crap !!! |
855 | if ( rStart <= end ) { // Start date not after range | 865 | if ( rStart <= end ) { // Start date not after range |
856 | if ( rStart >= start ) { // Start date within range | 866 | if ( rStart >= start ) { // Start date within range |
857 | found = true; | 867 | found = true; |
858 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 868 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
859 | found = true; | 869 | found = true; |
860 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 870 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
861 | QDate rEnd = event->recurrence()->endDate(); | 871 | QDate rEnd = event->recurrence()->endDate(); |
862 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 872 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
863 | found = true; | 873 | found = true; |
864 | } | 874 | } |
865 | } else { // Duration set | 875 | } else { // Duration set |
866 | // TODO: Calculate end date from duration. Should be done in Event | 876 | // TODO: Calculate end date from duration. Should be done in Event |
867 | // For now include all events with a duration. | 877 | // For now include all events with a duration. |
868 | found = true; | 878 | found = true; |
869 | } | 879 | } |
870 | } | 880 | } |
871 | */ | 881 | */ |
872 | 882 | ||
873 | } | 883 | } |
874 | 884 | ||
875 | if ( found ) eventList.append( event ); | 885 | if ( found ) eventList.append( event ); |
876 | } else { | 886 | } else { |
877 | QDate s = event->dtStart().date(); | 887 | QDate s = event->dtStart().date(); |
878 | QDate e = event->dtEnd().date(); | 888 | QDate e = event->dtEnd().date(); |
879 | 889 | ||
880 | if ( inclusive ) { | 890 | if ( inclusive ) { |
881 | if ( s >= start && e <= end ) { | 891 | if ( s >= start && e <= end ) { |
882 | eventList.append( event ); | 892 | eventList.append( event ); |
883 | } | 893 | } |
884 | } else { | 894 | } else { |
885 | if ( ( e >= start && s <= end ) ) { | 895 | if ( ( e >= start && s <= end ) ) { |
886 | eventList.append( event ); | 896 | eventList.append( event ); |
887 | } | 897 | } |
888 | } | 898 | } |
889 | } | 899 | } |
890 | } | 900 | } |
891 | 901 | ||
892 | return eventList; | 902 | return eventList; |
893 | } | 903 | } |
894 | 904 | ||
895 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 905 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
896 | { | 906 | { |
897 | return rawEventsForDate( qdt.date() ); | 907 | return rawEventsForDate( qdt.date() ); |
898 | } | 908 | } |
899 | 909 | ||
900 | QPtrList<Event> CalendarLocal::rawEvents() | 910 | QPtrList<Event> CalendarLocal::rawEvents() |
901 | { | 911 | { |
902 | QPtrList<Event> el; | 912 | QPtrList<Event> el; |
903 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 913 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
904 | if ( it->calEnabled() ) el.append( it ); | 914 | if ( it->calEnabled() ) el.append( it ); |
905 | return el; | 915 | return el; |
906 | } | 916 | } |
907 | 917 | ||
908 | bool CalendarLocal::addJournal(Journal *journal) | 918 | bool CalendarLocal::addJournal(Journal *journal) |
909 | { | 919 | { |
910 | mJournalList.append(journal); | 920 | mJournalList.append(journal); |
911 | 921 | ||
912 | journal->registerObserver( this ); | 922 | journal->registerObserver( this ); |
913 | 923 | ||
914 | setModified( true ); | 924 | setModified( true ); |
915 | if ( journal->calID() == 0 ) | 925 | if ( journal->calID() == 0 ) |
916 | journal->setCalID( mDefaultCalendar ); | 926 | journal->setCalID( mDefaultCalendar ); |
917 | journal->setCalEnabled( true ); | 927 | journal->setCalEnabled( true ); |
918 | return true; | 928 | return true; |
919 | } | 929 | } |
920 | 930 | ||
921 | void CalendarLocal::deleteJournal( Journal *journal ) | 931 | void CalendarLocal::deleteJournal( Journal *journal ) |
922 | { | 932 | { |
923 | clearUndo(journal); | 933 | clearUndo(journal); |
924 | if ( mJournalList.removeRef(journal) ) { | 934 | if ( mJournalList.removeRef(journal) ) { |
925 | setModified( true ); | 935 | setModified( true ); |
926 | } | 936 | } |
927 | } | 937 | } |
928 | 938 | ||
929 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) | 939 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) |
930 | { | 940 | { |
931 | QPtrList<Journal> el; | 941 | QPtrList<Journal> el; |
932 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 942 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
933 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); | 943 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); |
934 | return el; | 944 | return el; |
935 | } | 945 | } |
936 | Journal *CalendarLocal::journal( const QDate &date ) | 946 | Journal *CalendarLocal::journal( const QDate &date ) |
937 | { | 947 | { |
938 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 948 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
939 | 949 | ||
940 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 950 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
941 | if ( it->calEnabled() && it->dtStart().date() == date ) | 951 | if ( it->calEnabled() && it->dtStart().date() == date ) |
942 | return it; | 952 | return it; |
943 | 953 | ||
944 | return 0; | 954 | return 0; |
945 | } | 955 | } |
946 | 956 | ||
947 | Journal *CalendarLocal::journal( const QString &uid ) | 957 | Journal *CalendarLocal::journal( const QString &uid ) |
948 | { | 958 | { |
949 | Journal * retVal = 0; | 959 | Journal * retVal = 0; |
950 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 960 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
951 | if ( it->calEnabled() && it->uid() == uid ) { | 961 | if ( it->calEnabled() && it->uid() == uid ) { |
952 | if ( retVal ) { | 962 | if ( retVal ) { |
953 | if ( retVal->calID() > it->calID() ) { | 963 | if ( retVal->calID() > it->calID() ) { |
954 | retVal = it; | 964 | retVal = it; |
955 | } | 965 | } |
956 | } else { | 966 | } else { |
957 | retVal = it; | 967 | retVal = it; |
958 | } | 968 | } |
959 | } | 969 | } |
960 | return retVal; | 970 | return retVal; |
961 | } | 971 | } |
962 | 972 | ||
963 | QPtrList<Journal> CalendarLocal::journals() | 973 | QPtrList<Journal> CalendarLocal::journals() |
964 | { | 974 | { |
965 | QPtrList<Journal> el; | 975 | QPtrList<Journal> el; |
966 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 976 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
967 | if ( it->calEnabled() ) el.append( it ); | 977 | if ( it->calEnabled() ) el.append( it ); |
968 | return el; | 978 | return el; |
969 | } | 979 | } |
970 | void CalendarLocal::setCalendarRemove( int id ) | 980 | void CalendarLocal::setCalendarRemove( int id ) |
971 | { | 981 | { |
972 | 982 | ||
973 | { | 983 | { |
974 | QPtrList<Event> EventList = mEventList; | 984 | QPtrList<Event> EventList = mEventList; |
975 | Event * ev = EventList.first(); | 985 | Event * ev = EventList.first(); |
976 | while ( ev ) { | 986 | while ( ev ) { |
977 | if ( ev->calID() == id ) | 987 | if ( ev->calID() == id ) |
978 | deleteEvent( ev ); | 988 | deleteEvent( ev ); |
979 | ev = EventList.next(); | 989 | ev = EventList.next(); |
980 | } | 990 | } |
981 | } | 991 | } |
982 | { | 992 | { |
983 | 993 | ||
984 | QPtrList<Todo> TodoList = mTodoList; | 994 | QPtrList<Todo> TodoList = mTodoList; |
985 | Todo * ev = TodoList.first(); | 995 | Todo * ev = TodoList.first(); |
986 | while ( ev ) { | 996 | while ( ev ) { |
987 | if ( ev->calID() == id ) | 997 | if ( ev->calID() == id ) |
988 | deleteTodo( ev ); | 998 | deleteTodo( ev ); |
989 | ev = TodoList.next(); | 999 | ev = TodoList.next(); |
990 | } | 1000 | } |
991 | } | 1001 | } |
992 | { | 1002 | { |
993 | QPtrList<Journal> JournalList = mJournalList; | 1003 | QPtrList<Journal> JournalList = mJournalList; |
994 | Journal * ev = JournalList.first(); | 1004 | Journal * ev = JournalList.first(); |
995 | while ( ev ) { | 1005 | while ( ev ) { |
996 | if ( ev->calID() == id ) | 1006 | if ( ev->calID() == id ) |
997 | deleteJournal( ev ); | 1007 | deleteJournal( ev ); |
998 | ev = JournalList.next(); | 1008 | ev = JournalList.next(); |
999 | } | 1009 | } |
1000 | } | 1010 | } |
1001 | 1011 | ||
1002 | clearUndo(0); | 1012 | clearUndo(0); |
1003 | 1013 | ||
1004 | } | 1014 | } |
1005 | 1015 | ||
1016 | void CalendarLocal::setAllCalendarEnabled( bool enable ) | ||
1017 | { | ||
1018 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | ||
1019 | it->setCalEnabled( enable ); | ||
1020 | |||
1021 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | ||
1022 | it->setCalEnabled( enable ); | ||
1023 | |||
1024 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | ||
1025 | it->setCalEnabled( enable ); | ||
1026 | |||
1027 | |||
1028 | } | ||
1006 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 1029 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
1007 | { | 1030 | { |
1008 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1031 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1009 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1032 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1010 | 1033 | ||
1011 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1034 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1012 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1035 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1013 | 1036 | ||
1014 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1037 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1015 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1038 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1016 | 1039 | ||
1017 | } | 1040 | } |
1018 | 1041 | ||
1019 | void CalendarLocal::setReadOnly( int id, bool enable ) | 1042 | void CalendarLocal::setReadOnly( int id, bool enable ) |
1020 | { | 1043 | { |
1021 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1044 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1022 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1045 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1023 | 1046 | ||
1024 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1047 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1025 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1048 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1026 | 1049 | ||
1027 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1050 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1028 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1051 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1029 | 1052 | ||
1030 | } | 1053 | } |
1031 | 1054 | ||
1032 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 1055 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
1033 | { | 1056 | { |
1034 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1057 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1035 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1058 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1036 | 1059 | ||
1037 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1060 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1038 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1061 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1039 | 1062 | ||
1040 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1063 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1041 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1064 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1042 | reInitAlarmSettings(); | 1065 | reInitAlarmSettings(); |
1043 | 1066 | ||
1044 | } | 1067 | } |
1045 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 1068 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
1046 | { | 1069 | { |
1047 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1070 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1048 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 1071 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
1049 | 1072 | ||
1050 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1073 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1051 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1074 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1052 | 1075 | ||
1053 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1076 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1054 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1077 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1055 | 1078 | ||
1056 | } | 1079 | } |
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index eb7bf34..b70f0c9 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -5,228 +5,229 @@ | |||
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | #ifndef KCAL_CALENDARLOCAL_H | 22 | #ifndef KCAL_CALENDARLOCAL_H |
23 | #define KCAL_CALENDARLOCAL_H | 23 | #define KCAL_CALENDARLOCAL_H |
24 | 24 | ||
25 | #include "calendar.h" | 25 | #include "calendar.h" |
26 | 26 | ||
27 | namespace KCal { | 27 | namespace KCal { |
28 | 28 | ||
29 | class CalFormat; | 29 | class CalFormat; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | This class provides a calendar stored as a local file. | 32 | This class provides a calendar stored as a local file. |
33 | */ | 33 | */ |
34 | class CalendarLocal : public Calendar | 34 | class CalendarLocal : public Calendar |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | /** | 37 | /** |
38 | Constructs a new calendar, with variables initialized to sane values. | 38 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 39 | */ |
40 | CalendarLocal(); | 40 | CalendarLocal(); |
41 | /** | 41 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 42 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 43 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 44 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 45 | ~CalendarLocal(); |
46 | void addCalendar( Calendar* ); | 46 | void addCalendar( Calendar* ); |
47 | bool addCalendarFile( QString name, int id ); | 47 | bool addCalendarFile( QString name, int id ); |
48 | bool mergeCalendarFile( QString name ); | 48 | bool mergeCalendarFile( QString name ); |
49 | bool mergeCalendar( Calendar* cal ); | 49 | bool mergeCalendar( Calendar* cal ); |
50 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ); | 50 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ); |
51 | void setSyncEventsReadOnly(); | 51 | void setSyncEventsReadOnly(); |
52 | void setSyncEventsEnabled(); | 52 | void setSyncEventsEnabled(); |
53 | void stopAllTodos(); | 53 | void stopAllTodos(); |
54 | /** | 54 | /** |
55 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 55 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
56 | calendar. Any information already present is lost. | 56 | calendar. Any information already present is lost. |
57 | @return true, if successfull, false on error. | 57 | @return true, if successfull, false on error. |
58 | @param fileName the name of the calendar on disk. | 58 | @param fileName the name of the calendar on disk. |
59 | */ | 59 | */ |
60 | bool load( const QString &fileName ); | 60 | bool load( const QString &fileName ); |
61 | /** | 61 | /** |
62 | Writes out the calendar to disk in the specified \a format. | 62 | Writes out the calendar to disk in the specified \a format. |
63 | CalendarLocal takes ownership of the CalFormat object. | 63 | CalendarLocal takes ownership of the CalFormat object. |
64 | @return true, if successfull, false on error. | 64 | @return true, if successfull, false on error. |
65 | @param fileName the name of the file | 65 | @param fileName the name of the file |
66 | */ | 66 | */ |
67 | bool save( const QString &fileName, CalFormat *format = 0 ); | 67 | bool save( const QString &fileName, CalFormat *format = 0 ); |
68 | 68 | ||
69 | /** | 69 | /** |
70 | Clears out the current calendar, freeing all used memory etc. etc. | 70 | Clears out the current calendar, freeing all used memory etc. etc. |
71 | */ | 71 | */ |
72 | void close(); | 72 | void close(); |
73 | 73 | ||
74 | void save() {} | 74 | void save() {} |
75 | 75 | ||
76 | /** | 76 | /** |
77 | Add Event to calendar. | 77 | Add Event to calendar. |
78 | */ | 78 | */ |
79 | void removeSyncInfo( QString syncProfile); | 79 | void removeSyncInfo( QString syncProfile); |
80 | bool addAnniversaryNoDup( Event *event ); | 80 | bool addAnniversaryNoDup( Event *event ); |
81 | bool addEventNoDup( Event *event ); | 81 | bool addEventNoDup( Event *event ); |
82 | bool addEvent( Event *event ); | 82 | bool addEvent( Event *event ); |
83 | /** | 83 | /** |
84 | Deletes an event from this calendar. | 84 | Deletes an event from this calendar. |
85 | */ | 85 | */ |
86 | void deleteEvent( Event *event ); | 86 | void deleteEvent( Event *event ); |
87 | 87 | ||
88 | /** | 88 | /** |
89 | Retrieves an event on the basis of the unique string ID. | 89 | Retrieves an event on the basis of the unique string ID. |
90 | */ | 90 | */ |
91 | Event *event( const QString &uid ); | 91 | Event *event( const QString &uid ); |
92 | /** | 92 | /** |
93 | Return unfiltered list of all events in calendar. | 93 | Return unfiltered list of all events in calendar. |
94 | */ | 94 | */ |
95 | QPtrList<Event> rawEvents(); | 95 | QPtrList<Event> rawEvents(); |
96 | QPtrList<Event> getExternLastSyncEvents(); | 96 | QPtrList<Event> getExternLastSyncEvents(); |
97 | /** | 97 | /** |
98 | Add a todo to the todolist. | 98 | Add a todo to the todolist. |
99 | */ | 99 | */ |
100 | bool addTodo( Todo *todo ); | 100 | bool addTodo( Todo *todo ); |
101 | bool addTodoNoDup( Todo *todo ); | 101 | bool addTodoNoDup( Todo *todo ); |
102 | /** | 102 | /** |
103 | Remove a todo from the todolist. | 103 | Remove a todo from the todolist. |
104 | */ | 104 | */ |
105 | void deleteTodo( Todo * ); | 105 | void deleteTodo( Todo * ); |
106 | /** | 106 | /** |
107 | Searches todolist for an event with this unique string identifier, | 107 | Searches todolist for an event with this unique string identifier, |
108 | returns a pointer or null. | 108 | returns a pointer or null. |
109 | */ | 109 | */ |
110 | Todo *todo( const QString &uid ); | 110 | Todo *todo( const QString &uid ); |
111 | /** | 111 | /** |
112 | Return list of all todos. | 112 | Return list of all todos. |
113 | */ | 113 | */ |
114 | QPtrList<Todo> rawTodos(); | 114 | QPtrList<Todo> rawTodos(); |
115 | /** | 115 | /** |
116 | Returns list of todos due on the specified date. | 116 | Returns list of todos due on the specified date. |
117 | */ | 117 | */ |
118 | QPtrList<Todo> todos( const QDate &date ); | 118 | QPtrList<Todo> todos( const QDate &date ); |
119 | /** | 119 | /** |
120 | Return list of all todos. | 120 | Return list of all todos. |
121 | 121 | ||
122 | Workaround because compiler does not recognize function of base class. | 122 | Workaround because compiler does not recognize function of base class. |
123 | */ | 123 | */ |
124 | QPtrList<Todo> todos() { return Calendar::todos(); } | 124 | QPtrList<Todo> todos() { return Calendar::todos(); } |
125 | 125 | ||
126 | /** | 126 | /** |
127 | Add a Journal entry to calendar. | 127 | Add a Journal entry to calendar. |
128 | */ | 128 | */ |
129 | bool addJournal( Journal * ); | 129 | bool addJournal( Journal * ); |
130 | /** | 130 | /** |
131 | Remove a Journal from the calendar. | 131 | Remove a Journal from the calendar. |
132 | */ | 132 | */ |
133 | void deleteJournal( Journal * ); | 133 | void deleteJournal( Journal * ); |
134 | /** | 134 | /** |
135 | Return Journal for given date. | 135 | Return Journal for given date. |
136 | */ | 136 | */ |
137 | Journal *journal( const QDate & ); | 137 | Journal *journal( const QDate & ); |
138 | QPtrList<Journal> journals4Date( const QDate & ); | 138 | QPtrList<Journal> journals4Date( const QDate & ); |
139 | /** | 139 | /** |
140 | Return Journal with given UID. | 140 | Return Journal with given UID. |
141 | */ | 141 | */ |
142 | Journal *journal( const QString &uid ); | 142 | Journal *journal( const QString &uid ); |
143 | /** | 143 | /** |
144 | Return list of all Journals stored in calendar. | 144 | Return list of all Journals stored in calendar. |
145 | */ | 145 | */ |
146 | QPtrList<Journal> journals(); | 146 | QPtrList<Journal> journals(); |
147 | 147 | ||
148 | /** | 148 | /** |
149 | Return all alarms, which ocur in the given time interval. | 149 | Return all alarms, which ocur in the given time interval. |
150 | */ | 150 | */ |
151 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); | 151 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); |
152 | 152 | ||
153 | /** | 153 | /** |
154 | Return all alarms, which ocur before given date. | 154 | Return all alarms, which ocur before given date. |
155 | */ | 155 | */ |
156 | Alarm::List alarmsTo( const QDateTime &to ); | 156 | Alarm::List alarmsTo( const QDateTime &to ); |
157 | 157 | ||
158 | QDateTime nextAlarm( int daysTo ) ; | 158 | QDateTime nextAlarm( int daysTo ) ; |
159 | QDateTime nextAlarmEventDateTime() const; | 159 | QDateTime nextAlarmEventDateTime() const; |
160 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; | 160 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; |
161 | void registerAlarm(); | 161 | void registerAlarm(); |
162 | void deRegisterAlarm(); | 162 | void deRegisterAlarm(); |
163 | QString getAlarmNotification(); | 163 | QString getAlarmNotification(); |
164 | QString nextSummary() const ; | 164 | QString nextSummary() const ; |
165 | /** | 165 | /** |
166 | This method should be called whenever a Event is modified directly | 166 | This method should be called whenever a Event is modified directly |
167 | via it's pointer. It makes sure that the calendar is internally | 167 | via it's pointer. It makes sure that the calendar is internally |
168 | consistent. | 168 | consistent. |
169 | */ | 169 | */ |
170 | void update( IncidenceBase *incidence ); | 170 | void update( IncidenceBase *incidence ); |
171 | 171 | ||
172 | /** | 172 | /** |
173 | Builds and then returns a list of all events that match for the | 173 | Builds and then returns a list of all events that match for the |
174 | date specified. useful for dayView, etc. etc. | 174 | date specified. useful for dayView, etc. etc. |
175 | */ | 175 | */ |
176 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); | 176 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); |
177 | /** | 177 | /** |
178 | Get unfiltered events for date \a qdt. | 178 | Get unfiltered events for date \a qdt. |
179 | */ | 179 | */ |
180 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); | 180 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); |
181 | /** | 181 | /** |
182 | Get unfiltered events in a range of dates. If inclusive is set to true, | 182 | Get unfiltered events in a range of dates. If inclusive is set to true, |
183 | only events are returned, which are completely included in the range. | 183 | only events are returned, which are completely included in the range. |
184 | */ | 184 | */ |
185 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 185 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
186 | bool inclusive = false ); | 186 | bool inclusive = false ); |
187 | Todo *todo( QString, QString ); | 187 | Todo *todo( QString, QString ); |
188 | Event *event( QString, QString ); | 188 | Event *event( QString, QString ); |
189 | void getIncidenceCount( int calId, int& events, int & todos, int & journals); | 189 | void getIncidenceCount( int calId, int& events, int & todos, int & journals); |
190 | 190 | ||
191 | public slots: | 191 | public slots: |
192 | void setCalendarEnabled( int id, bool enable ); | 192 | void setCalendarEnabled( int id, bool enable ); |
193 | void setAlarmEnabled( int id, bool enable ); | 193 | void setAlarmEnabled( int id, bool enable ); |
194 | void setReadOnly( int id, bool enable ); | 194 | void setReadOnly( int id, bool enable ); |
195 | void setDefaultCalendarEnabledOnly(); | 195 | void setDefaultCalendarEnabledOnly(); |
196 | void setCalendarRemove( int id ); | 196 | void setCalendarRemove( int id ); |
197 | void setAllCalendarEnabled( bool enable ); | ||
197 | 198 | ||
198 | protected: | 199 | protected: |
199 | 200 | ||
200 | // Event* mNextAlarmEvent; | 201 | // Event* mNextAlarmEvent; |
201 | QString mNextSummary; | 202 | QString mNextSummary; |
202 | QString mNextAlarmEventDateTimeString; | 203 | QString mNextAlarmEventDateTimeString; |
203 | QString mLastAlarmNotificationString; | 204 | QString mLastAlarmNotificationString; |
204 | QDateTime mNextAlarmEventDateTime; | 205 | QDateTime mNextAlarmEventDateTime; |
205 | QDateTime mNextAlarmDateTime; | 206 | QDateTime mNextAlarmDateTime; |
206 | void reInitAlarmSettings(); | 207 | void reInitAlarmSettings(); |
207 | 208 | ||
208 | /** Notification function of IncidenceBase::Observer. */ | 209 | /** Notification function of IncidenceBase::Observer. */ |
209 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } | 210 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } |
210 | 211 | ||
211 | /** inserts an event into its "proper place" in the calendar. */ | 212 | /** inserts an event into its "proper place" in the calendar. */ |
212 | void insertEvent( Event *event ); | 213 | void insertEvent( Event *event ); |
213 | 214 | ||
214 | /** Append alarms of incidence in interval to list of alarms. */ | 215 | /** Append alarms of incidence in interval to list of alarms. */ |
215 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, | 216 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, |
216 | const QDateTime &from, const QDateTime &to ); | 217 | const QDateTime &from, const QDateTime &to ); |
217 | 218 | ||
218 | /** Append alarms of recurring events in interval to list of alarms. */ | 219 | /** Append alarms of recurring events in interval to list of alarms. */ |
219 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, | 220 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, |
220 | const QDateTime &from, const QDateTime &to ); | 221 | const QDateTime &from, const QDateTime &to ); |
221 | 222 | ||
222 | private: | 223 | private: |
223 | void init(); | 224 | void init(); |
224 | 225 | ||
225 | QPtrList<Event> mEventList; | 226 | QPtrList<Event> mEventList; |
226 | QPtrList<Todo> mTodoList; | 227 | QPtrList<Todo> mTodoList; |
227 | QPtrList<Journal> mJournalList; | 228 | QPtrList<Journal> mJournalList; |
228 | }; | 229 | }; |
229 | 230 | ||
230 | } | 231 | } |
231 | 232 | ||
232 | #endif | 233 | #endif |
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 795cd30..d2cb71b 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -951,403 +951,402 @@ void KSyncManager::syncKDE() | |||
951 | if ( ! QFile::exists ( commandpath+commandfile ) ) | 951 | if ( ! QFile::exists ( commandpath+commandfile ) ) |
952 | command = commandfile; | 952 | command = commandfile; |
953 | else | 953 | else |
954 | command = commandpath+commandfile; | 954 | command = commandpath+commandfile; |
955 | 955 | ||
956 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; | 956 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; |
957 | int result = system ( command.latin1()); | 957 | int result = system ( command.latin1()); |
958 | qDebug("AB dump 33 command call result: %d ", result); | 958 | qDebug("AB dump 33 command call result: %d ", result); |
959 | if ( result != 0 ) { | 959 | if ( result != 0 ) { |
960 | qDebug("Calling AB dump version 33 failed. Trying 34... "); | 960 | qDebug("Calling AB dump version 33 failed. Trying 34... "); |
961 | commandfile = "kdeabdump34"; | 961 | commandfile = "kdeabdump34"; |
962 | if ( ! QFile::exists ( commandpath+commandfile ) ) | 962 | if ( ! QFile::exists ( commandpath+commandfile ) ) |
963 | command = commandfile; | 963 | command = commandfile; |
964 | else | 964 | else |
965 | command = commandpath+commandfile; | 965 | command = commandpath+commandfile; |
966 | result = system ( command.latin1()); | 966 | result = system ( command.latin1()); |
967 | qDebug("AB dump 34 command call result: %d ", result); | 967 | qDebug("AB dump 34 command call result: %d ", result); |
968 | if ( result != 0 ) { | 968 | if ( result != 0 ) { |
969 | KMessageBox::error( 0, i18n("Error accessing KDE addressbook data.\nMake sure the file\n%1kdeabdump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); | 969 | KMessageBox::error( 0, i18n("Error accessing KDE addressbook data.\nMake sure the file\n%1kdeabdump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); |
970 | return; | 970 | return; |
971 | } | 971 | } |
972 | } | 972 | } |
973 | if ( syncWithFile( fileName,true ) ) { | 973 | if ( syncWithFile( fileName,true ) ) { |
974 | if ( mWriteBackFile ) { | 974 | if ( mWriteBackFile ) { |
975 | command += " --read"; | 975 | command += " --read"; |
976 | system ( command.latin1()); | 976 | system ( command.latin1()); |
977 | } | 977 | } |
978 | } | 978 | } |
979 | 979 | ||
980 | } | 980 | } |
981 | break; | 981 | break; |
982 | case (KOPI): | 982 | case (KOPI): |
983 | { | 983 | { |
984 | #ifdef DESKTOP_VERSION | 984 | #ifdef DESKTOP_VERSION |
985 | QString command = "kdecaldump33"; | 985 | QString command = "kdecaldump33"; |
986 | QString commandfile = "kdecaldump33"; | 986 | QString commandfile = "kdecaldump33"; |
987 | QString commandpath = qApp->applicationDirPath () + "/"; | 987 | QString commandpath = qApp->applicationDirPath () + "/"; |
988 | #else | 988 | #else |
989 | QString command = "kdecaldump33"; | 989 | QString command = "kdecaldump33"; |
990 | QString commandfile = "kdecaldump33"; | 990 | QString commandfile = "kdecaldump33"; |
991 | QString commandpath = QDir::homeDirPath ()+"/"; | 991 | QString commandpath = QDir::homeDirPath ()+"/"; |
992 | #endif | 992 | #endif |
993 | if ( ! QFile::exists ( commandpath+commandfile ) ) | 993 | if ( ! QFile::exists ( commandpath+commandfile ) ) |
994 | command = commandfile; | 994 | command = commandfile; |
995 | else | 995 | else |
996 | command = commandpath+commandfile; | 996 | command = commandpath+commandfile; |
997 | 997 | ||
998 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; | 998 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; |
999 | int result = system ( command.latin1()); | 999 | int result = system ( command.latin1()); |
1000 | qDebug("Cal dump 33 command call result result: %d ", result); | 1000 | qDebug("Cal dump 33 command call result result: %d ", result); |
1001 | if ( result != 0 ) { | 1001 | if ( result != 0 ) { |
1002 | qDebug("Calling CAL dump version 33 failed. Trying 34... "); | 1002 | qDebug("Calling CAL dump version 33 failed. Trying 34... "); |
1003 | commandfile = "kdecaldump34"; | 1003 | commandfile = "kdecaldump34"; |
1004 | if ( ! QFile::exists ( commandpath+commandfile ) ) | 1004 | if ( ! QFile::exists ( commandpath+commandfile ) ) |
1005 | command = commandfile; | 1005 | command = commandfile; |
1006 | else | 1006 | else |
1007 | command = commandpath+commandfile; | 1007 | command = commandpath+commandfile; |
1008 | result = system ( command.latin1()); | 1008 | result = system ( command.latin1()); |
1009 | qDebug("Cal dump 34 command call result result: %d ", result); | 1009 | qDebug("Cal dump 34 command call result result: %d ", result); |
1010 | if ( result != 0 ) { | 1010 | if ( result != 0 ) { |
1011 | KMessageBox::error( 0, i18n("Error accessing KDE calendar data.\nMake sure the file\n%1kdecaldump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); | 1011 | KMessageBox::error( 0, i18n("Error accessing KDE calendar data.\nMake sure the file\n%1kdecaldump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); |
1012 | return; | 1012 | return; |
1013 | } | 1013 | } |
1014 | } | 1014 | } |
1015 | if ( syncWithFile( fileName,true ) ) { | 1015 | if ( syncWithFile( fileName,true ) ) { |
1016 | if ( mWriteBackFile ) { | 1016 | if ( mWriteBackFile ) { |
1017 | command += " --read"; | 1017 | command += " --read"; |
1018 | system ( command.latin1()); | 1018 | system ( command.latin1()); |
1019 | } | 1019 | } |
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | } | 1022 | } |
1023 | break; | 1023 | break; |
1024 | case (PWMPI): | 1024 | case (PWMPI): |
1025 | 1025 | ||
1026 | break; | 1026 | break; |
1027 | default: | 1027 | default: |
1028 | qDebug("KSM::slotSyncMenu: invalid apptype selected"); | 1028 | qDebug("KSM::slotSyncMenu: invalid apptype selected"); |
1029 | break; | 1029 | break; |
1030 | 1030 | ||
1031 | } | 1031 | } |
1032 | } | 1032 | } |
1033 | 1033 | ||
1034 | void KSyncManager::syncSharp() | 1034 | void KSyncManager::syncSharp() |
1035 | { | 1035 | { |
1036 | 1036 | ||
1037 | if ( ! syncExternalApplication("sharp") ) | 1037 | if ( ! syncExternalApplication("sharp") ) |
1038 | qDebug("KSM::ERROR sync sharp "); | 1038 | qDebug("KSM::ERROR sync sharp "); |
1039 | } | 1039 | } |
1040 | 1040 | ||
1041 | bool KSyncManager::syncExternalApplication(QString resource) | 1041 | bool KSyncManager::syncExternalApplication(QString resource) |
1042 | { | 1042 | { |
1043 | 1043 | ||
1044 | emit save(); | 1044 | emit save(); |
1045 | 1045 | ||
1046 | if ( mAskForPreferences ) | 1046 | if ( mAskForPreferences ) |
1047 | if ( !edit_sync_options()) { | 1047 | if ( !edit_sync_options()) { |
1048 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1048 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
1049 | return false; | 1049 | return false; |
1050 | } | 1050 | } |
1051 | 1051 | ||
1052 | qDebug("KSM::Sync extern %s", resource.latin1()); | 1052 | qDebug("KSM::Sync extern %s", resource.latin1()); |
1053 | 1053 | ||
1054 | bool syncOK = mImplementation->syncExternal(this, resource); | 1054 | bool syncOK = mImplementation->syncExternal(this, resource); |
1055 | 1055 | ||
1056 | return syncOK; | 1056 | return syncOK; |
1057 | 1057 | ||
1058 | } | 1058 | } |
1059 | 1059 | ||
1060 | void KSyncManager::syncPhone() | 1060 | void KSyncManager::syncPhone() |
1061 | { | 1061 | { |
1062 | 1062 | ||
1063 | syncExternalApplication("phone"); | 1063 | syncExternalApplication("phone"); |
1064 | 1064 | ||
1065 | } | 1065 | } |
1066 | 1066 | ||
1067 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) | 1067 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) |
1068 | { | 1068 | { |
1069 | if (!bar->isVisible()) | 1069 | if (!bar->isVisible()) |
1070 | { | 1070 | { |
1071 | int w = 300; | 1071 | int w = 300; |
1072 | if ( QApplication::desktop()->width() < 320 ) | 1072 | if ( QApplication::desktop()->width() < 320 ) |
1073 | w = 220; | 1073 | w = 220; |
1074 | int h = bar->sizeHint().height() ; | 1074 | int h = bar->sizeHint().height() ; |
1075 | int dw = QApplication::desktop()->width(); | 1075 | int dw = QApplication::desktop()->width(); |
1076 | int dh = QApplication::desktop()->height(); | 1076 | int dh = QApplication::desktop()->height(); |
1077 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1077 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1078 | bar->setCaption (caption); | 1078 | bar->setCaption (caption); |
1079 | bar->setTotalSteps ( total ) ; | 1079 | bar->setTotalSteps ( total ) ; |
1080 | bar->show(); | 1080 | bar->show(); |
1081 | } | 1081 | } |
1082 | bar->raise(); | 1082 | bar->raise(); |
1083 | bar->setProgress( percentage ); | 1083 | bar->setProgress( percentage ); |
1084 | qApp->processEvents(); | 1084 | qApp->processEvents(); |
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | void KSyncManager::hideProgressBar() | 1087 | void KSyncManager::hideProgressBar() |
1088 | { | 1088 | { |
1089 | bar->hide(); | 1089 | bar->hide(); |
1090 | qApp->processEvents(); | 1090 | qApp->processEvents(); |
1091 | } | 1091 | } |
1092 | 1092 | ||
1093 | bool KSyncManager::isProgressBarCanceled() | 1093 | bool KSyncManager::isProgressBarCanceled() |
1094 | { | 1094 | { |
1095 | return !bar->isVisible(); | 1095 | return !bar->isVisible(); |
1096 | } | 1096 | } |
1097 | 1097 | ||
1098 | QString KSyncManager::syncFileName() | 1098 | QString KSyncManager::syncFileName() |
1099 | { | 1099 | { |
1100 | 1100 | ||
1101 | QString fn = "tempfile"; | 1101 | QString fn = "tempfile"; |
1102 | switch(mTargetApp) | 1102 | switch(mTargetApp) |
1103 | { | 1103 | { |
1104 | case (KAPI): | 1104 | case (KAPI): |
1105 | fn = "tempsyncab.vcf"; | 1105 | fn = "tempsyncab.vcf"; |
1106 | break; | 1106 | break; |
1107 | case (KOPI): | 1107 | case (KOPI): |
1108 | fn = "tempsynccal.ics"; | 1108 | fn = "tempsynccal.ics"; |
1109 | break; | 1109 | break; |
1110 | case (PWMPI): | 1110 | case (PWMPI): |
1111 | fn = "tempsyncpw.pwm"; | 1111 | fn = "tempsyncpw.pwm"; |
1112 | break; | 1112 | break; |
1113 | default: | 1113 | default: |
1114 | break; | 1114 | break; |
1115 | } | 1115 | } |
1116 | #ifdef DESKTOP_VERSION | 1116 | #ifdef DESKTOP_VERSION |
1117 | return locateLocal( "tmp", fn ); | 1117 | return locateLocal( "tmp", fn ); |
1118 | #else | 1118 | #else |
1119 | return (QString( "/tmp/" )+ fn ); | 1119 | return (QString( "/tmp/" )+ fn ); |
1120 | #endif | 1120 | #endif |
1121 | } | 1121 | } |
1122 | 1122 | ||
1123 | void KSyncManager::syncPi() | 1123 | void KSyncManager::syncPi() |
1124 | { | 1124 | { |
1125 | mIsKapiFile = true; | 1125 | mIsKapiFile = true; |
1126 | mPisyncFinished = false; | 1126 | mPisyncFinished = false; |
1127 | qApp->processEvents(); | 1127 | qApp->processEvents(); |
1128 | if ( mAskForPreferences ) | 1128 | if ( mAskForPreferences ) |
1129 | if ( !edit_pisync_options()) { | 1129 | if ( !edit_pisync_options()) { |
1130 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1130 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
1131 | mPisyncFinished = true; | 1131 | mPisyncFinished = true; |
1132 | return; | 1132 | return; |
1133 | } | 1133 | } |
1134 | bool ok; | 1134 | bool ok; |
1135 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 1135 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
1136 | if ( ! ok ) { | 1136 | if ( ! ok ) { |
1137 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1137 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
1138 | mPisyncFinished = true; | 1138 | mPisyncFinished = true; |
1139 | return; | 1139 | return; |
1140 | } | 1140 | } |
1141 | mCurrentResourceLocal = ""; | 1141 | mCurrentResourceLocal = ""; |
1142 | mCurrentResourceRemote = ""; | 1142 | mCurrentResourceRemote = ""; |
1143 | qDebug ( "KSM: sync pi %d",mSpecificResources.count() ); | ||
1144 | if ( mSpecificResources.count() ) { | 1143 | if ( mSpecificResources.count() ) { |
1145 | int lastSyncRes = mSpecificResources.count()/2; | 1144 | int lastSyncRes = mSpecificResources.count()/2; |
1146 | int ccc = mSpecificResources.count()-1; | 1145 | int ccc = mSpecificResources.count()-1; |
1147 | while ( lastSyncRes > 0 && ccc > 0 && mSpecificResources[ ccc ].isEmpty() ) { | 1146 | while ( lastSyncRes > 0 && ccc > 0 && mSpecificResources[ ccc ].isEmpty() ) { |
1148 | --ccc; | 1147 | --ccc; |
1149 | --lastSyncRes; | 1148 | --lastSyncRes; |
1150 | qDebug ( "KSM: sync pi %d",ccc ); | 1149 | //qDebug ( "KSM: sync pi %d",ccc ); |
1151 | } | 1150 | } |
1152 | int startLocal = 0; | 1151 | int startLocal = 0; |
1153 | int startRemote = mSpecificResources.count()/2; | 1152 | int startRemote = mSpecificResources.count()/2; |
1154 | emit multiResourceSyncStart( true ); | 1153 | emit multiResourceSyncStart( true ); |
1155 | while ( startLocal < mSpecificResources.count()/2 ) { | 1154 | while ( startLocal < mSpecificResources.count()/2 ) { |
1156 | if ( startLocal+1 >= lastSyncRes ) | 1155 | if ( startLocal+1 >= lastSyncRes ) |
1157 | emit multiResourceSyncStart( false ); | 1156 | emit multiResourceSyncStart( false ); |
1158 | mPisyncFinished = false; | 1157 | mPisyncFinished = false; |
1159 | mCurrentResourceLocal = mSpecificResources[ startLocal ]; | 1158 | mCurrentResourceLocal = mSpecificResources[ startLocal ]; |
1160 | mCurrentResourceRemote = mSpecificResources[ startRemote ]; | 1159 | mCurrentResourceRemote = mSpecificResources[ startRemote ]; |
1161 | qDebug ( "KSM: AAASyncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); | 1160 | //qDebug ( "KSM: AAASyncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); |
1162 | if ( !mCurrentResourceRemote.isEmpty() ) { | 1161 | if ( !mCurrentResourceRemote.isEmpty() ) { |
1163 | qDebug ( "KSM: Syncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); | 1162 | qDebug ( "KSM: Syncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); |
1164 | KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); | 1163 | KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); |
1165 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1164 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1166 | commandSocket->readFile( syncFileName() ); | 1165 | commandSocket->readFile( syncFileName() ); |
1167 | while ( !mPisyncFinished ) { | 1166 | while ( !mPisyncFinished ) { |
1168 | //qDebug("waiting "); | 1167 | //qDebug("waiting "); |
1169 | qApp->processEvents(); | 1168 | qApp->processEvents(); |
1170 | } | 1169 | } |
1171 | } | 1170 | } |
1172 | ++startRemote; | 1171 | ++startRemote; |
1173 | ++startLocal; | 1172 | ++startLocal; |
1174 | } | 1173 | } |
1175 | mPisyncFinished = true; | 1174 | mPisyncFinished = true; |
1176 | } else { | 1175 | } else { |
1177 | KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); | 1176 | KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); |
1178 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1177 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1179 | commandSocket->readFile( syncFileName() ); | 1178 | commandSocket->readFile( syncFileName() ); |
1180 | } | 1179 | } |
1181 | } | 1180 | } |
1182 | 1181 | ||
1183 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1182 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
1184 | { | 1183 | { |
1185 | //enum { success, errorW, errorR, quiet }; | 1184 | //enum { success, errorW, errorR, quiet }; |
1186 | 1185 | ||
1187 | 1186 | ||
1188 | 1187 | ||
1189 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || | 1188 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || |
1190 | state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { | 1189 | state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { |
1191 | if ( state == KCommandSocket::errorPW ) | 1190 | if ( state == KCommandSocket::errorPW ) |
1192 | mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); | 1191 | mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); |
1193 | else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) | 1192 | else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) |
1194 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1193 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
1195 | else if ( state == KCommandSocket::errorCA ) | 1194 | else if ( state == KCommandSocket::errorCA ) |
1196 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); | 1195 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); |
1197 | else if ( state == KCommandSocket::errorFI ) | 1196 | else if ( state == KCommandSocket::errorFI ) |
1198 | mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); | 1197 | mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); |
1199 | else if ( state == KCommandSocket::errorED ) | 1198 | else if ( state == KCommandSocket::errorED ) |
1200 | mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); | 1199 | mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); |
1201 | else if ( state == KCommandSocket::errorUN ) | 1200 | else if ( state == KCommandSocket::errorUN ) |
1202 | mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); | 1201 | mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); |
1203 | delete s; | 1202 | delete s; |
1204 | if ( state == KCommandSocket::errorR ) { | 1203 | if ( state == KCommandSocket::errorR ) { |
1205 | KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); | 1204 | KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); |
1206 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1205 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1207 | commandSocket->sendStop(); | 1206 | commandSocket->sendStop(); |
1208 | } | 1207 | } |
1209 | mPisyncFinished = true; | 1208 | mPisyncFinished = true; |
1210 | return; | 1209 | return; |
1211 | 1210 | ||
1212 | } else if ( state == KCommandSocket::errorW ) { | 1211 | } else if ( state == KCommandSocket::errorW ) { |
1213 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1212 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
1214 | mPisyncFinished = true; | 1213 | mPisyncFinished = true; |
1215 | 1214 | ||
1216 | } else if ( state == KCommandSocket::successR ) { | 1215 | } else if ( state == KCommandSocket::successR ) { |
1217 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 1216 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
1218 | 1217 | ||
1219 | } else if ( state == KCommandSocket::successW ) { | 1218 | } else if ( state == KCommandSocket::successW ) { |
1220 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); | 1219 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); |
1221 | mPisyncFinished = true; | 1220 | mPisyncFinished = true; |
1222 | } else if ( state == KCommandSocket::quiet ){ | 1221 | } else if ( state == KCommandSocket::quiet ){ |
1223 | qDebug("KSS: quiet "); | 1222 | qDebug("KSS: quiet "); |
1224 | mPisyncFinished = true; | 1223 | mPisyncFinished = true; |
1225 | } else { | 1224 | } else { |
1226 | qDebug("KSS: Error: unknown state: %d ", state); | 1225 | qDebug("KSS: Error: unknown state: %d ", state); |
1227 | mPisyncFinished = true; | 1226 | mPisyncFinished = true; |
1228 | } | 1227 | } |
1229 | 1228 | ||
1230 | delete s; | 1229 | delete s; |
1231 | } | 1230 | } |
1232 | 1231 | ||
1233 | void KSyncManager::readFileFromSocket() | 1232 | void KSyncManager::readFileFromSocket() |
1234 | { | 1233 | { |
1235 | QString fileName = syncFileName(); | 1234 | QString fileName = syncFileName(); |
1236 | bool syncOK = true; | 1235 | bool syncOK = true; |
1237 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1236 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1238 | if ( ! syncWithFile( fileName , true ) ) { | 1237 | if ( ! syncWithFile( fileName , true ) ) { |
1239 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1238 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1240 | syncOK = false; | 1239 | syncOK = false; |
1241 | } | 1240 | } |
1242 | KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); | 1241 | KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); |
1243 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1242 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1244 | if ( mWriteBackFile && syncOK ) { | 1243 | if ( mWriteBackFile && syncOK ) { |
1245 | mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); | 1244 | mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); |
1246 | commandSocket->writeFile( fileName ); | 1245 | commandSocket->writeFile( fileName ); |
1247 | } | 1246 | } |
1248 | else { | 1247 | else { |
1249 | commandSocket->sendStop(); | 1248 | commandSocket->sendStop(); |
1250 | if ( syncOK ) | 1249 | if ( syncOK ) |
1251 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1250 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1252 | mPisyncFinished = true; | 1251 | mPisyncFinished = true; |
1253 | } | 1252 | } |
1254 | } | 1253 | } |
1255 | 1254 | ||
1256 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1255 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1257 | { | 1256 | { |
1258 | mPassWord = pw; | 1257 | mPassWord = pw; |
1259 | mSocket = 0; | 1258 | mSocket = 0; |
1260 | mSyncActionDialog = 0; | 1259 | mSyncActionDialog = 0; |
1261 | blockRC = false; | 1260 | blockRC = false; |
1262 | mErrorMessage = 0; | 1261 | mErrorMessage = 0; |
1263 | } | 1262 | } |
1264 | 1263 | ||
1265 | void KServerSocket::newConnection ( int socket ) | 1264 | void KServerSocket::newConnection ( int socket ) |
1266 | { | 1265 | { |
1267 | // qDebug("KServerSocket:New connection %d ", socket); | 1266 | // qDebug("KServerSocket:New connection %d ", socket); |
1268 | if ( mSocket ) { | 1267 | if ( mSocket ) { |
1269 | qDebug("KSS::newConnection Socket deleted! "); | 1268 | qDebug("KSS::newConnection Socket deleted! "); |
1270 | delete mSocket; | 1269 | delete mSocket; |
1271 | mSocket = 0; | 1270 | mSocket = 0; |
1272 | } | 1271 | } |
1273 | mSocket = new QSocket( this ); | 1272 | mSocket = new QSocket( this ); |
1274 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1273 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1275 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1274 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1276 | mSocket->setSocket( socket ); | 1275 | mSocket->setSocket( socket ); |
1277 | } | 1276 | } |
1278 | 1277 | ||
1279 | void KServerSocket::discardClient() | 1278 | void KServerSocket::discardClient() |
1280 | { | 1279 | { |
1281 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1280 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1282 | } | 1281 | } |
1283 | void KServerSocket::deleteSocket() | 1282 | void KServerSocket::deleteSocket() |
1284 | { | 1283 | { |
1285 | qDebug("KSS::deleteSocket"); | 1284 | qDebug("KSS::deleteSocket"); |
1286 | if ( mSocket ) { | 1285 | if ( mSocket ) { |
1287 | delete mSocket; | 1286 | delete mSocket; |
1288 | mSocket = 0; | 1287 | mSocket = 0; |
1289 | } | 1288 | } |
1290 | if ( mErrorMessage ) | 1289 | if ( mErrorMessage ) |
1291 | QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); | 1290 | QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); |
1292 | } | 1291 | } |
1293 | void KServerSocket::readClient() | 1292 | void KServerSocket::readClient() |
1294 | { | 1293 | { |
1295 | if ( blockRC ) | 1294 | if ( blockRC ) |
1296 | return; | 1295 | return; |
1297 | if ( mSocket == 0 ) { | 1296 | if ( mSocket == 0 ) { |
1298 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); | 1297 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); |
1299 | return; | 1298 | return; |
1300 | } | 1299 | } |
1301 | if ( mErrorMessage ) { | 1300 | if ( mErrorMessage ) { |
1302 | mErrorMessage = 999; | 1301 | mErrorMessage = 999; |
1303 | error_connect("ERROR_ED\r\n\r\n"); | 1302 | error_connect("ERROR_ED\r\n\r\n"); |
1304 | return; | 1303 | return; |
1305 | } | 1304 | } |
1306 | mResource = ""; | 1305 | mResource = ""; |
1307 | mErrorMessage = 0; | 1306 | mErrorMessage = 0; |
1308 | //qDebug("KServerSocket::readClient()"); | 1307 | //qDebug("KServerSocket::readClient()"); |
1309 | if ( mSocket->canReadLine() ) { | 1308 | if ( mSocket->canReadLine() ) { |
1310 | QString line = mSocket->readLine(); | 1309 | QString line = mSocket->readLine(); |
1311 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1310 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1312 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1311 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1313 | if ( tokens[0] == "GET" ) { | 1312 | if ( tokens[0] == "GET" ) { |
1314 | if ( tokens[1] == mPassWord ) { | 1313 | if ( tokens[1] == mPassWord ) { |
1315 | //emit sendFile( mSocket ); | 1314 | //emit sendFile( mSocket ); |
1316 | bool ok = false; | 1315 | bool ok = false; |
1317 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | 1316 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); |
1318 | if ( ok ) { | 1317 | if ( ok ) { |
1319 | KSyncManager::mRequestedSyncEvent = dt; | 1318 | KSyncManager::mRequestedSyncEvent = dt; |
1320 | } | 1319 | } |
1321 | else | 1320 | else |
1322 | KSyncManager::mRequestedSyncEvent = QDateTime(); | 1321 | KSyncManager::mRequestedSyncEvent = QDateTime(); |
1323 | mResource =tokens[3]; | 1322 | mResource =tokens[3]; |
1324 | send_file(); | 1323 | send_file(); |
1325 | } | 1324 | } |
1326 | else { | 1325 | else { |
1327 | mErrorMessage = 1; | 1326 | mErrorMessage = 1; |
1328 | error_connect("ERROR_PW\r\n\r\n"); | 1327 | error_connect("ERROR_PW\r\n\r\n"); |
1329 | } | 1328 | } |
1330 | } | 1329 | } |
1331 | if ( tokens[0] == "PUT" ) { | 1330 | if ( tokens[0] == "PUT" ) { |
1332 | if ( tokens[1] == mPassWord ) { | 1331 | if ( tokens[1] == mPassWord ) { |
1333 | //emit getFile( mSocket ); | 1332 | //emit getFile( mSocket ); |
1334 | blockRC = true; | 1333 | blockRC = true; |
1335 | mResource =tokens[2]; | 1334 | mResource =tokens[2]; |
1336 | get_file(); | 1335 | get_file(); |
1337 | } | 1336 | } |
1338 | else { | 1337 | else { |
1339 | mErrorMessage = 2; | 1338 | mErrorMessage = 2; |
1340 | error_connect("ERROR_PW\r\n\r\n"); | 1339 | error_connect("ERROR_PW\r\n\r\n"); |
1341 | end_connect(); | 1340 | end_connect(); |
1342 | } | 1341 | } |
1343 | } | 1342 | } |
1344 | if ( tokens[0] == "STOP" ) { | 1343 | if ( tokens[0] == "STOP" ) { |
1345 | //emit endConnect(); | 1344 | //emit endConnect(); |
1346 | end_connect(); | 1345 | end_connect(); |
1347 | } | 1346 | } |
1348 | } | 1347 | } |
1349 | } | 1348 | } |
1350 | void KServerSocket::displayErrorMessage() | 1349 | void KServerSocket::displayErrorMessage() |
1351 | { | 1350 | { |
1352 | if ( mErrorMessage == 1 ) { | 1351 | if ( mErrorMessage == 1 ) { |
1353 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error")); | 1352 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error")); |