summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--korganizer/calendarview.cpp17
-rw-r--r--libkcal/calendar.cpp9
-rw-r--r--libkcal/calendar.h3
-rw-r--r--libkcal/calendarlocal.cpp77
-rw-r--r--libkcal/calendarlocal.h3
-rw-r--r--libkcal/incidence.cpp6
-rw-r--r--libkcal/incidence.h1
7 files changed, 97 insertions, 19 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 8d024c1..1800cf2 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1511,352 +1511,367 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
1511 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1511 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1512 localIsNew = localMod >= remoteMod; 1512 localIsNew = localMod >= remoteMod;
1513 if ( localIsNew ) 1513 if ( localIsNew )
1514 getEventViewerDialog()->setColorMode( 1 ); 1514 getEventViewerDialog()->setColorMode( 1 );
1515 else 1515 else
1516 getEventViewerDialog()->setColorMode( 2 ); 1516 getEventViewerDialog()->setColorMode( 2 );
1517 getEventViewerDialog()->setIncidence(local); 1517 getEventViewerDialog()->setIncidence(local);
1518 if ( localIsNew ) 1518 if ( localIsNew )
1519 getEventViewerDialog()->setColorMode( 2 ); 1519 getEventViewerDialog()->setColorMode( 2 );
1520 else 1520 else
1521 getEventViewerDialog()->setColorMode( 1 ); 1521 getEventViewerDialog()->setColorMode( 1 );
1522 getEventViewerDialog()->addIncidence(remote); 1522 getEventViewerDialog()->addIncidence(remote);
1523 getEventViewerDialog()->setColorMode( 0 ); 1523 getEventViewerDialog()->setColorMode( 0 );
1524 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1524 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1525 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1525 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1526 getEventViewerDialog()->showMe(); 1526 getEventViewerDialog()->showMe();
1527 result = getEventViewerDialog()->executeS( localIsNew ); 1527 result = getEventViewerDialog()->executeS( localIsNew );
1528 return result; 1528 return result;
1529 1529
1530 break; 1530 break;
1531 case SYNC_PREF_FORCE_LOCAL: 1531 case SYNC_PREF_FORCE_LOCAL:
1532 return 1; 1532 return 1;
1533 break; 1533 break;
1534 case SYNC_PREF_FORCE_REMOTE: 1534 case SYNC_PREF_FORCE_REMOTE:
1535 return 2; 1535 return 2;
1536 break; 1536 break;
1537 1537
1538 default: 1538 default:
1539 // SYNC_PREF_TAKE_BOTH not implemented 1539 // SYNC_PREF_TAKE_BOTH not implemented
1540 break; 1540 break;
1541 } 1541 }
1542 return 0; 1542 return 0;
1543} 1543}
1544Event* CalendarView::getLastSyncEvent() 1544Event* CalendarView::getLastSyncEvent()
1545{ 1545{
1546 Event* lse; 1546 Event* lse;
1547 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1547 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1548 mCalendar->setSyncEventsEnabled(); 1548 mCalendar->setSyncEventsEnabled();
1549 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1549 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1550 if (!lse) { 1550 if (!lse) {
1551 qDebug("KO: New last Syncevent created for local: %s",mCurrentSyncDevice.latin1() ); 1551 qDebug("KO: New last Syncevent created for local: %s",mCurrentSyncDevice.latin1() );
1552 lse = new Event(); 1552 lse = new Event();
1553 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1553 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1554 QString sum = ""; 1554 QString sum = "";
1555 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1555 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1556 sum = "E: "; 1556 sum = "E: ";
1557 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1557 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1558 lse->setDtStart( mLastCalendarSync ); 1558 lse->setDtStart( mLastCalendarSync );
1559 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1559 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1560 lse->setCategories( i18n("SyncEvent") ); 1560 lse->setCategories( i18n("SyncEvent") );
1561 lse->setReadOnly( true ); 1561 lse->setReadOnly( true );
1562 lse->setCalID( 1 ); 1562 lse->setCalID( 1 );
1563 mCalendar->addEvent( lse ); 1563 mCalendar->addEvent( lse );
1564 } else 1564 } else
1565 qDebug("KO: Last Syncevent on local found"); 1565 qDebug("KO: Last Syncevent on local found");
1566 1566
1567 return lse; 1567 return lse;
1568 1568
1569} 1569}
1570 1570
1571// we check, if the to delete event has a id for a profile 1571// we check, if the to delete event has a id for a profile
1572// if yes, we set this id in the profile to delete 1572// if yes, we set this id in the profile to delete
1573void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1573void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1574{ 1574{
1575 if ( lastSync.count() == 0 ) { 1575 if ( lastSync.count() == 0 ) {
1576 //qDebug(" lastSync.count() == 0"); 1576 //qDebug(" lastSync.count() == 0");
1577 return; 1577 return;
1578 } 1578 }
1579 if ( toDelete->typeID() == journalID ) 1579 if ( toDelete->typeID() == journalID )
1580 return; 1580 return;
1581 1581
1582 Event* eve = lastSync.first(); 1582 Event* eve = lastSync.first();
1583 1583
1584 while ( eve ) { 1584 while ( eve ) {
1585 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1585 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1586 if ( !id.isEmpty() ) { 1586 if ( !id.isEmpty() ) {
1587 QString des = eve->description(); 1587 QString des = eve->description();
1588 QString pref = "e"; 1588 QString pref = "e";
1589 if ( toDelete->typeID() == todoID ) 1589 if ( toDelete->typeID() == todoID )
1590 pref = "t"; 1590 pref = "t";
1591 des += pref+ id + ","; 1591 des += pref+ id + ",";
1592 eve->setReadOnly( false ); 1592 eve->setReadOnly( false );
1593 eve->setDescription( des ); 1593 eve->setDescription( des );
1594 //qDebug("setdes %s ", des.latin1()); 1594 //qDebug("setdes %s ", des.latin1());
1595 eve->setReadOnly( true ); 1595 eve->setReadOnly( true );
1596 } 1596 }
1597 eve = lastSync.next(); 1597 eve = lastSync.next();
1598 } 1598 }
1599 1599
1600} 1600}
1601void CalendarView::checkExternalId( Incidence * inc ) 1601void CalendarView::checkExternalId( Incidence * inc )
1602{ 1602{
1603 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1603 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1604 checkExternSyncEvent( lastSync, inc ); 1604 checkExternSyncEvent( lastSync, inc );
1605 1605
1606} 1606}
1607// SSSSSSSSSSSSSSSSSSSSSS
1607bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1608bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1608{ 1609{
1609 1610
1610 bool syncOK = true; 1611 bool syncOK = true;
1611 int addedEvent = 0; 1612 int addedEvent = 0;
1612 int addedEventR = 0; 1613 int addedEventR = 0;
1613 int deletedEventR = 0; 1614 int deletedEventR = 0;
1614 int deletedEventL = 0; 1615 int deletedEventL = 0;
1615 int changedLocal = 0; 1616 int changedLocal = 0;
1616 int changedRemote = 0; 1617 int changedRemote = 0;
1617 int filteredIN = 0; 1618 int filteredIN = 0;
1618 int filteredOUT = 0; 1619 int filteredOUT = 0;
1619 //QPtrList<Event> el = local->rawEvents(); 1620 //QPtrList<Event> el = local->rawEvents();
1620 Event* eventR; 1621 Event* eventR;
1621 QString uid; 1622 QString uid;
1622 int take; 1623 int take;
1623 Event* eventRSync; 1624 Event* eventRSync;
1624 Event* eventLSync; 1625 Event* eventLSync;
1625 clearAllViews(); 1626 clearAllViews();
1626 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1627 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1627 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1628 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1628 bool fullDateRange = false; 1629 bool fullDateRange = false;
1629 local->resetTempSyncStat(); 1630 local->resetTempSyncStat();
1630 mLastCalendarSync = QDateTime::currentDateTime(); 1631 mLastCalendarSync = QDateTime::currentDateTime();
1631 if ( mSyncManager->syncWithDesktop() ) { 1632 if ( mSyncManager->syncWithDesktop() ) {
1632 remote->resetPilotStat(1); 1633 remote->resetPilotStat(1);
1633 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1634 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1634 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1635 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1635 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1636 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1636 } else { 1637 } else {
1637 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1638 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1638 } 1639 }
1639 } 1640 }
1640 QDateTime modifiedCalendar = mLastCalendarSync; 1641 QDateTime modifiedCalendar = mLastCalendarSync;
1641 eventLSync = getLastSyncEvent(); 1642 eventLSync = getLastSyncEvent();
1642 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1643 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1643 if ( eventR ) { 1644 if ( eventR ) {
1644 qDebug("KO: Last-syncEvent on remote found "); 1645 qDebug("KO: Last-syncEvent on remote found ");
1645 eventRSync = (Event*) eventR->clone(); 1646 eventRSync = (Event*) eventR->clone();
1646 remote->deleteEvent(eventR ); 1647 remote->deleteEvent(eventR );
1647 1648
1648 } else { 1649 } else {
1649 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1650 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1650 eventRSync = (Event*)eventLSync->clone(); 1651 eventRSync = (Event*)eventLSync->clone();
1651 } else { 1652 } else {
1652 fullDateRange = true; 1653 fullDateRange = true;
1653 eventRSync = new Event(); 1654 eventRSync = new Event();
1654 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1655 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1655 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1656 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1656 eventRSync->setDtStart( mLastCalendarSync ); 1657 eventRSync->setDtStart( mLastCalendarSync );
1657 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1658 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1658 eventRSync->setCategories( i18n("SyncEvent") ); 1659 eventRSync->setCategories( i18n("SyncEvent") );
1659 } 1660 }
1660 } 1661 }
1661 if ( eventLSync->dtStart() == mLastCalendarSync ) 1662 if ( eventLSync->dtStart() == mLastCalendarSync )
1662 fullDateRange = true; 1663 fullDateRange = true;
1663 1664
1664 if ( ! fullDateRange ) { 1665 if ( ! fullDateRange ) {
1665 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1666 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1666 1667
1667 qDebug("KO: Sync: Set fulldate to true! Local: %s --- Remote: %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1668 qDebug("KO: Sync: Set fulldate to true! Local: %s --- Remote: %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1668 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1669 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1669 fullDateRange = true; 1670 fullDateRange = true;
1670 } 1671 }
1671 } 1672 }
1672 if ( mSyncManager->syncWithDesktop() ) { 1673 if ( mSyncManager->syncWithDesktop() ) {
1673 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1674 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1674 } 1675 }
1675 if ( fullDateRange ) 1676 if ( fullDateRange )
1676 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1677 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1677 else 1678 else
1678 mLastCalendarSync = eventLSync->dtStart(); 1679 mLastCalendarSync = eventLSync->dtStart();
1679 // for resyncing if own file has changed 1680 // for resyncing if own file has changed
1680 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1681 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1681 mLastCalendarSync = loadedFileVersion; 1682 mLastCalendarSync = loadedFileVersion;
1682 //qDebug("setting mLastCalendarSync "); 1683 //qDebug("setting mLastCalendarSync ");
1683 } 1684 }
1684 //qDebug("*************************** "); 1685 //qDebug("*************************** ");
1685 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1686 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1686 QPtrList<Incidence> er = remote->rawIncidences(); 1687 QPtrList<Incidence> er = remote->rawIncidences();
1687 Incidence* inR = er.first(); 1688 Incidence* inR = er.first();
1688 Incidence* inL; 1689 Incidence* inL;
1689 QProgressBar bar( er.count(),0 ); 1690 QProgressBar bar( er.count(),0 );
1690 bar.setCaption (i18n("Syncing - close to abort!") ); 1691 bar.setCaption (i18n("Syncing - close to abort!") );
1691 1692
1692 // ************** setting up filter ************* 1693 // ************** setting up filter *************
1693 CalFilter *filterIN = 0; 1694 CalFilter *filterIN = 0;
1694 CalFilter *filterOUT = 0; 1695 CalFilter *filterOUT = 0;
1695 CalFilter *filter = mFilters.first(); 1696 CalFilter *filter = mFilters.first();
1696 while(filter) { 1697 while(filter) {
1697 if ( filter->name() == mSyncManager->mFilterInCal ) 1698 if ( filter->name() == mSyncManager->mFilterInCal )
1698 filterIN = filter; 1699 filterIN = filter;
1699 if ( filter->name() == mSyncManager->mFilterOutCal ) 1700 if ( filter->name() == mSyncManager->mFilterOutCal )
1700 filterOUT = filter; 1701 filterOUT = filter;
1701 filter = mFilters.next(); 1702 filter = mFilters.next();
1702 } 1703 }
1703 int w = 300; 1704 int w = 300;
1704 if ( QApplication::desktop()->width() < 320 ) 1705 if ( QApplication::desktop()->width() < 320 )
1705 w = 220; 1706 w = 220;
1706 int h = bar.sizeHint().height() ; 1707 int h = bar.sizeHint().height() ;
1707 int dw = QApplication::desktop()->width(); 1708 int dw = QApplication::desktop()->width();
1708 int dh = QApplication::desktop()->height(); 1709 int dh = QApplication::desktop()->height();
1709 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1710 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1710 bar.show(); 1711 bar.show();
1711 int modulo = (er.count()/10)+1; 1712 int modulo = (er.count()/10)+1;
1712 int incCounter = 0; 1713 int incCounter = 0;
1713 while ( inR ) { 1714 while ( inR ) {
1714 if ( ! bar.isVisible() ) 1715 if ( ! bar.isVisible() )
1715 return false; 1716 return false;
1716 if ( incCounter % modulo == 0 ) 1717 if ( incCounter % modulo == 0 )
1717 bar.setProgress( incCounter ); 1718 bar.setProgress( incCounter );
1718 ++incCounter; 1719 ++incCounter;
1719 uid = inR->uid(); 1720 uid = inR->uid();
1720 bool skipIncidence = false; 1721 bool skipIncidence = false;
1721 if ( uid.left(15) == QString("last-syncEvent-") ) 1722 if ( uid.left(15) == QString("last-syncEvent-") )
1722 skipIncidence = true; 1723 skipIncidence = true;
1723 QString idS; 1724 QString idS;
1724 qApp->processEvents(); 1725 qApp->processEvents();
1725 if ( !skipIncidence ) { 1726 if ( !skipIncidence ) {
1726 inL = local->incidenceForUid( uid , false , true ); 1727 int hasCalId = 0;
1728 inL = local->incidenceForUid( uid , false , true, &hasCalId );
1729 if ( hasCalId && !inL )
1730 inL = local->incidenceForUid( uid , false , true, &hasCalId );
1731 else
1732 hasCalId = 0;
1727 if ( inL ) { // maybe conflict - same uid in both calendars 1733 if ( inL ) { // maybe conflict - same uid in both calendars
1734 if ( hasCalId )
1735 qDebug("KO: Cal id %d conflict detected: %s ", hasCalId, inL->summary().latin1());
1728 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1736 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1729 //qDebug("take %d %s ", take, inL->summary().latin1()); 1737 //qDebug("take %d %s ", take, inL->summary().latin1());
1730 if ( take == 3 ) 1738 if ( take == 3 )
1731 return false; 1739 return false;
1732 if ( take == 1 ) {// take local ********************** 1740 if ( take == 1 ) {// take local **********************
1733 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1741 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1734 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1742 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1735 else 1743 else
1736 idS = inR->IDStr(); 1744 idS = inR->IDStr();
1737 int calID = inR->calID(); 1745 int calID = inR->calID();
1738 remote->deleteIncidence( inR ); 1746 remote->deleteIncidence( inR );
1739 inR = inL->clone(); 1747 inR = inL->clone();
1740 inR->setCalID_block( calID ); 1748 inR->setCalID_block( calID );
1741 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1749 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1742 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1750 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1743 inR->setIDStr( idS ); 1751 inR->setIDStr( idS );
1744 remote->addIncidence( inR ); 1752 remote->addIncidence( inR );
1745 if ( mSyncManager->syncWithDesktop() ) 1753 if ( mSyncManager->syncWithDesktop() )
1746 inR->setPilotId( 2 ); 1754 inR->setPilotId( 2 );
1747 ++changedRemote; 1755 ++changedRemote;
1748 } else {// take remote ********************** 1756 } else {// take remote **********************
1749 if ( !inL->isReadOnly() ) { 1757 if ( !inL->isReadOnly() ) {
1750 idS = inL->IDStr(); 1758 idS = inL->IDStr();
1751 int pid = inL->pilotId(); 1759 int pid = inL->pilotId();
1752 int calID = inL->calID(); 1760 int calID = inL->calID();
1761 if ( hasCalId )
1762 calID = hasCalId;
1753 local->deleteIncidence( inL ); 1763 local->deleteIncidence( inL );
1754 inL = inR->clone(); 1764 inL = inR->clone();
1755 inL->setCalID_block( calID ); 1765 inL->setCalID_block( calID );
1756 if ( mSyncManager->syncWithDesktop() ) 1766 if ( mSyncManager->syncWithDesktop() )
1757 inL->setPilotId( pid ); 1767 inL->setPilotId( pid );
1758 inL->setIDStr( idS ); 1768 inL->setIDStr( idS );
1759 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1769 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1760 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1770 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1761 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1771 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1762 } 1772 }
1763 local->addIncidence( inL ); 1773 local->addIncidence( inL );
1764 ++changedLocal; 1774 ++changedLocal;
1765 } 1775 }
1766 } 1776 }
1777 } else {
1778 // take == 0; events equal
1779 if ( hasCalId )
1780 qDebug("EV EQUALLLL **************************** ");
1781
1767 } 1782 }
1768 } else { // no conflict ********** add or delete remote 1783 } else { // no conflict ********** add or delete remote
1769 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1784 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1770 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1785 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1771 QString des = eventLSync->description(); 1786 QString des = eventLSync->description();
1772 QString pref = "e"; 1787 QString pref = "e";
1773 if ( inR->typeID() == todoID ) 1788 if ( inR->typeID() == todoID )
1774 pref = "t"; 1789 pref = "t";
1775 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1790 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1776 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1791 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1777 //remote->deleteIncidence( inR ); 1792 //remote->deleteIncidence( inR );
1778 ++deletedEventR; 1793 ++deletedEventR;
1779 } else { 1794 } else {
1780 inR->setLastModified( modifiedCalendar ); 1795 inR->setLastModified( modifiedCalendar );
1781 inL = inR->clone(); 1796 inL = inR->clone();
1782 inL->setIDStr( ":" ); 1797 inL->setIDStr( ":" );
1783 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1798 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1784 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1799 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1785 1800
1786 inL->setCalID_block( 0 );// add to default cal 1801 inL->setCalID_block( 0 );// add to default cal
1787 local->addIncidence( inL ); 1802 local->addIncidence( inL );
1788 ++addedEvent; 1803 ++addedEvent;
1789 1804
1790 } 1805 }
1791 } else { 1806 } else {
1792 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1807 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1793 inR->setLastModified( modifiedCalendar ); 1808 inR->setLastModified( modifiedCalendar );
1794 inL = inR->clone(); 1809 inL = inR->clone();
1795 inL->setIDStr( ":" ); 1810 inL->setIDStr( ":" );
1796 inL->setCalID_block( 0 );// add to default cal 1811 inL->setCalID_block( 0 );// add to default cal
1797 local->addIncidence( inL ); 1812 local->addIncidence( inL );
1798 ++addedEvent; 1813 ++addedEvent;
1799 1814
1800 } else { 1815 } else {
1801 checkExternSyncEvent(eventRSyncSharp, inR); 1816 checkExternSyncEvent(eventRSyncSharp, inR);
1802 remote->deleteIncidence( inR ); 1817 remote->deleteIncidence( inR );
1803 ++deletedEventR; 1818 ++deletedEventR;
1804 } 1819 }
1805 } 1820 }
1806 } else { 1821 } else {
1807 ++filteredIN; 1822 ++filteredIN;
1808 } 1823 }
1809 } 1824 }
1810 } 1825 }
1811 inR = er.next(); 1826 inR = er.next();
1812 } 1827 }
1813 QPtrList<Incidence> el = local->rawIncidences(); 1828 QPtrList<Incidence> el = local->rawIncidences();
1814 inL = el.first(); 1829 inL = el.first();
1815 modulo = (el.count()/10)+1; 1830 modulo = (el.count()/10)+1;
1816 bar.setCaption (i18n("Add / remove events") ); 1831 bar.setCaption (i18n("Add / remove events") );
1817 bar.setTotalSteps ( el.count() ) ; 1832 bar.setTotalSteps ( el.count() ) ;
1818 bar.show(); 1833 bar.show();
1819 incCounter = 0; 1834 incCounter = 0;
1820 1835
1821 while ( inL ) { 1836 while ( inL ) {
1822 1837
1823 qApp->processEvents(); 1838 qApp->processEvents();
1824 if ( ! bar.isVisible() ) 1839 if ( ! bar.isVisible() )
1825 return false; 1840 return false;
1826 if ( incCounter % modulo == 0 ) 1841 if ( incCounter % modulo == 0 )
1827 bar.setProgress( incCounter ); 1842 bar.setProgress( incCounter );
1828 ++incCounter; 1843 ++incCounter;
1829 uid = inL->uid(); 1844 uid = inL->uid();
1830 bool skipIncidence = false; 1845 bool skipIncidence = false;
1831 if ( uid.left(15) == QString("last-syncEvent-") ) 1846 if ( uid.left(15) == QString("last-syncEvent-") )
1832 skipIncidence = true; 1847 skipIncidence = true;
1833 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1848 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1834 skipIncidence = true; 1849 skipIncidence = true;
1835 if ( !skipIncidence ) { 1850 if ( !skipIncidence ) {
1836 inR = remote->incidenceForUid( uid , true, true ); 1851 inR = remote->incidenceForUid( uid , true, true );
1837 if ( ! inR ) { 1852 if ( ! inR ) {
1838 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1853 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1839 // no conflict ********** add or delete local 1854 // no conflict ********** add or delete local
1840 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1855 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1841 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1856 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1842 checkExternSyncEvent(eventLSyncSharp, inL); 1857 checkExternSyncEvent(eventLSyncSharp, inL);
1843 local->deleteIncidence( inL ); 1858 local->deleteIncidence( inL );
1844 ++deletedEventL; 1859 ++deletedEventL;
1845 } else { 1860 } else {
1846 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1861 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1847 inL->removeID(mCurrentSyncDevice ); 1862 inL->removeID(mCurrentSyncDevice );
1848 ++addedEventR; 1863 ++addedEventR;
1849 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1864 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1850 inL->setLastModified( modifiedCalendar ); 1865 inL->setLastModified( modifiedCalendar );
1851 inR = inL->clone(); 1866 inR = inL->clone();
1852 inR->setIDStr( ":" ); 1867 inR->setIDStr( ":" );
1853 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1868 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1854 inR->setCalID_block( 0 );// add to default cal 1869 inR->setCalID_block( 0 );// add to default cal
1855 remote->addIncidence( inR ); 1870 remote->addIncidence( inR );
1856 } 1871 }
1857 } 1872 }
1858 } else { 1873 } else {
1859 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1874 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1860 checkExternSyncEvent(eventLSyncSharp, inL); 1875 checkExternSyncEvent(eventLSyncSharp, inL);
1861 local->deleteIncidence( inL ); 1876 local->deleteIncidence( inL );
1862 ++deletedEventL; 1877 ++deletedEventL;
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 8535191..1350f6d 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,106 +1,105 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 13 Library General Public License for more details.
15 14
16 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
20*/ 19*/
21 20
22#include <stdlib.h> 21#include <stdlib.h>
23#include <time.h> 22#include <time.h>
24 23
25#include <kdebug.h> 24#include <kdebug.h>
26#include <kglobal.h> 25#include <kglobal.h>
27#include <klocale.h> 26#include <klocale.h>
28 27
29#include "exceptions.h" 28#include "exceptions.h"
30#include "calfilter.h" 29#include "calfilter.h"
31 30
32#include "calendar.h" 31#include "calendar.h"
33#include "syncdefines.h" 32#include "syncdefines.h"
34 33
35using namespace KCal; 34using namespace KCal;
36 35
37Calendar::Calendar() 36Calendar::Calendar()
38{ 37{
39 38
40 init(); 39 init();
41 setTimeZoneId( " 00:00 Europe/London(UTC)" ); 40 setTimeZoneId( " 00:00 Europe/London(UTC)" );
42} 41}
43 42
44Calendar::Calendar( const QString &timeZoneId ) 43Calendar::Calendar( const QString &timeZoneId )
45{ 44{
46 45
47 init(); 46 init();
48 setTimeZoneId(timeZoneId); 47 setTimeZoneId(timeZoneId);
49} 48}
50 49
51void Calendar::init() 50void Calendar::init()
52{ 51{
53 mObserver = 0; 52 mObserver = 0;
54 mNewObserver = false; 53 mNewObserver = false;
55 mUndoIncidence = 0; 54 mUndoIncidence = 0;
56 mDeleteIncidencesOnClose = true; 55 mDeleteIncidencesOnClose = true;
57 mModified = false; 56 mModified = false;
58 mDefaultCalendar = 1; 57 mDefaultCalendar = 1;
59 // Setup default filter, which does nothing 58 // Setup default filter, which does nothing
60 mDefaultFilter = new CalFilter; 59 mDefaultFilter = new CalFilter;
61 mFilter = mDefaultFilter; 60 mFilter = mDefaultFilter;
62 mFilter->setEnabled(false); 61 mFilter->setEnabled(false);
63 62
64 // initialize random numbers. This is a hack, and not 63 // initialize random numbers. This is a hack, and not
65 // even that good of one at that. 64 // even that good of one at that.
66// srandom(time(0)); 65// srandom(time(0));
67 66
68 // user information... 67 // user information...
69 setOwner(i18n("Unknown Name")); 68 setOwner(i18n("Unknown Name"));
70 setEmail(i18n("unknown@nowhere")); 69 setEmail(i18n("unknown@nowhere"));
71 70
72#if 0 71#if 0
73 tmpStr = KOPrefs::instance()->mTimeZone; 72 tmpStr = KOPrefs::instance()->mTimeZone;
74// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; 73// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
75 int dstSetting = KOPrefs::instance()->mDaylightSavings; 74 int dstSetting = KOPrefs::instance()->mDaylightSavings;
76 extern long int timezone; 75 extern long int timezone;
77 struct tm *now; 76 struct tm *now;
78 time_t curtime; 77 time_t curtime;
79 curtime = time(0); 78 curtime = time(0);
80 now = localtime(&curtime); 79 now = localtime(&curtime);
81 int hourOff = - ((timezone / 60) / 60); 80 int hourOff = - ((timezone / 60) / 60);
82 if (now->tm_isdst) 81 if (now->tm_isdst)
83 hourOff += 1; 82 hourOff += 1;
84 QString tzStr; 83 QString tzStr;
85 tzStr.sprintf("%.2d%.2d", 84 tzStr.sprintf("%.2d%.2d",
86 hourOff, 85 hourOff,
87 abs((timezone / 60) % 60)); 86 abs((timezone / 60) % 60));
88 87
89 // if no time zone was in the config file, write what we just discovered. 88 // if no time zone was in the config file, write what we just discovered.
90 if (tmpStr.isEmpty()) { 89 if (tmpStr.isEmpty()) {
91// KOPrefs::instance()->mTimeZone = tzStr; 90// KOPrefs::instance()->mTimeZone = tzStr;
92 } else { 91 } else {
93 tzStr = tmpStr; 92 tzStr = tmpStr;
94 } 93 }
95 94
96 // if daylight savings has changed since last load time, we need 95 // if daylight savings has changed since last load time, we need
97 // to rewrite these settings to the config file. 96 // to rewrite these settings to the config file.
98 if ((now->tm_isdst && !dstSetting) || 97 if ((now->tm_isdst && !dstSetting) ||
99 (!now->tm_isdst && dstSetting)) { 98 (!now->tm_isdst && dstSetting)) {
100 KOPrefs::instance()->mTimeZone = tzStr; 99 KOPrefs::instance()->mTimeZone = tzStr;
101 KOPrefs::instance()->mDaylightSavings = now->tm_isdst; 100 KOPrefs::instance()->mDaylightSavings = now->tm_isdst;
102 } 101 }
103 102
104 setTimeZone(tzStr); 103 setTimeZone(tzStr);
105#endif 104#endif
106 105
@@ -327,197 +326,201 @@ QPtrList<Incidence> Calendar::rawIncidences()
327 Incidence *i; 326 Incidence *i;
328 327
329 QPtrList<Event> e = rawEvents(); 328 QPtrList<Event> e = rawEvents();
330 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 329 for( i = e.first(); i; i = e.next() ) incidences.append( i );
331 330
332 QPtrList<Todo> t = rawTodos(); 331 QPtrList<Todo> t = rawTodos();
333 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 332 for( i = t.first(); i; i = t.next() ) incidences.append( i );
334 333
335 QPtrList<Journal> j = journals(); 334 QPtrList<Journal> j = journals();
336 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 335 for( i = j.first(); i; i = j.next() ) incidences.append( i );
337 336
338 return incidences; 337 return incidences;
339} 338}
340 339
341QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 340QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
342{ 341{
343 QPtrList<Event> el = rawEventsForDate(date,sorted); 342 QPtrList<Event> el = rawEventsForDate(date,sorted);
344 mFilter->apply(&el); 343 mFilter->apply(&el);
345 return el; 344 return el;
346} 345}
347 346
348QPtrList<Event> Calendar::events( const QDateTime &qdt ) 347QPtrList<Event> Calendar::events( const QDateTime &qdt )
349{ 348{
350 QPtrList<Event> el = rawEventsForDate(qdt); 349 QPtrList<Event> el = rawEventsForDate(qdt);
351 mFilter->apply(&el); 350 mFilter->apply(&el);
352 return el; 351 return el;
353} 352}
354 353
355QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 354QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
356 bool inclusive) 355 bool inclusive)
357{ 356{
358 QPtrList<Event> el = rawEvents(start,end,inclusive); 357 QPtrList<Event> el = rawEvents(start,end,inclusive);
359 mFilter->apply(&el); 358 mFilter->apply(&el);
360 return el; 359 return el;
361} 360}
362 361
363QPtrList<Event> Calendar::events() 362QPtrList<Event> Calendar::events()
364{ 363{
365 QPtrList<Event> el = rawEvents(); 364 QPtrList<Event> el = rawEvents();
366 mFilter->apply(&el); 365 mFilter->apply(&el);
367 return el; 366 return el;
368} 367}
369void Calendar::addIncidenceBranch(Incidence *i) 368void Calendar::addIncidenceBranch(Incidence *i)
370{ 369{
371 addIncidence( i ); 370 addIncidence( i );
372 Incidence * inc; 371 Incidence * inc;
373 QPtrList<Incidence> Relations = i->relations(); 372 QPtrList<Incidence> Relations = i->relations();
374 for (inc=Relations.first();inc;inc=Relations.next()) { 373 for (inc=Relations.first();inc;inc=Relations.next()) {
375 addIncidenceBranch( inc ); 374 addIncidenceBranch( inc );
376 } 375 }
377} 376}
378 377
379bool Calendar::addIncidence(Incidence *i) 378bool Calendar::addIncidence(Incidence *i)
380{ 379{
381 Incidence::AddVisitor<Calendar> v(this); 380 Incidence::AddVisitor<Calendar> v(this);
382 if ( i->calID() == 0 ) 381 if ( i->calID() == 0 )
383 i->setCalID_block( mDefaultCalendar ); 382 i->setCalID_block( mDefaultCalendar );
384 i->setCalEnabled( true ); 383 i->setCalEnabled( true );
385 return i->accept(v); 384 return i->accept(v);
386} 385}
387void Calendar::deleteIncidence(Incidence *in) 386void Calendar::deleteIncidence(Incidence *in)
388{ 387{
389 if ( in->typeID() == eventID ) 388 if ( in->typeID() == eventID )
390 deleteEvent( (Event*) in ); 389 deleteEvent( (Event*) in );
391 else if ( in->typeID() == todoID ) 390 else if ( in->typeID() == todoID )
392 deleteTodo( (Todo*) in); 391 deleteTodo( (Todo*) in);
393 else if ( in->typeID() == journalID ) 392 else if ( in->typeID() == journalID )
394 deleteJournal( (Journal*) in ); 393 deleteJournal( (Journal*) in );
395} 394}
396 395
397Incidence* Calendar::incidence( const QString& uid ) 396Incidence* Calendar::incidence( const QString& uid )
398{ 397{
399 Incidence* i; 398 Incidence* i;
400 399
401 if( (i = todo( uid )) != 0 ) 400 if( (i = todo( uid )) != 0 )
402 return i; 401 return i;
403 if( (i = event( uid )) != 0 ) 402 if( (i = event( uid )) != 0 )
404 return i; 403 return i;
405 if( (i = journal( uid )) != 0 ) 404 if( (i = journal( uid )) != 0 )
406 return i; 405 return i;
407 406
408 return 0; 407 return 0;
409} 408}
410 409
411QPtrList<Todo> Calendar::todos() 410QPtrList<Todo> Calendar::todos()
412{ 411{
413 QPtrList<Todo> tl = rawTodos(); 412 QPtrList<Todo> tl = rawTodos();
414 mFilter->apply( &tl ); 413 mFilter->apply( &tl );
415 return tl; 414 return tl;
416} 415}
417 416
418// When this is called, the todo have already been added to the calendar. 417// When this is called, the todo have already been added to the calendar.
419// This method is only about linking related todos 418// This method is only about linking related todos
420void Calendar::setupRelations( Incidence *incidence ) 419void Calendar::setupRelations( Incidence *incidence )
421{ 420{
422 QString uid = incidence->uid(); 421 QString uid = incidence->uid();
423 //qDebug("Calendar::setupRelations "); 422 //qDebug("Calendar::setupRelations %s", incidence->summary().latin1());
424 // First, go over the list of orphans and see if this is their parent 423 // First, go over the list of orphans and see if this is their parent
425 while( Incidence* i = mOrphans[ uid ] ) { 424 while( Incidence* i = mOrphans[ uid ] ) {
426 mOrphans.remove( uid ); 425 mOrphans.remove( uid );
427 i->setRelatedTo( incidence ); 426 i->setRelatedTo( incidence );
427 //qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1());
428 incidence->addRelation( i ); 428 incidence->addRelation( i );
429 mOrphanUids.remove( i->uid() ); 429 mOrphanUids.remove( i->uid() );
430 } 430 }
431 431
432 // Now see about this incidences parent 432 // Now see about this incidences parent
433 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 433 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
434 // This incidence has a uid it is related to, but is not registered to it yet 434 // This incidence has a uid it is related to, but is not registered to it yet
435 // Try to find it 435 // Try to find it
436 Incidence* parent = this->incidence( incidence->relatedToUid() ); 436 //qDebug("Test parent for %s", incidence->summary().latin1());
437 Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true );
437 if( parent ) { 438 if( parent ) {
438 // Found it 439 // Found it
440 // qDebug("parent found for for %s", incidence->summary().latin1());
439 incidence->setRelatedTo( parent ); 441 incidence->setRelatedTo( parent );
440 parent->addRelation( incidence ); 442 parent->addRelation( incidence );
441 } else { 443 } else {
444 // qDebug("NO parent found for for %s", incidence->summary().latin1());
442 // Not found, put this in the mOrphans list 445 // Not found, put this in the mOrphans list
443 mOrphans.insert( incidence->relatedToUid(), incidence ); 446 mOrphans.insert( incidence->relatedToUid(), incidence );
444 mOrphanUids.insert( incidence->uid(), incidence ); 447 mOrphanUids.insert( incidence->uid(), incidence );
445 } 448 }
446 } 449 }
447} 450}
448 451
449// If a task with subtasks is deleted, move it's subtasks to the orphans list 452// If a task with subtasks is deleted, move it's subtasks to the orphans list
450void Calendar::removeRelations( Incidence *incidence ) 453void Calendar::removeRelations( Incidence *incidence )
451{ 454{
452 // qDebug("Calendar::removeRelations "); 455 // qDebug("Calendar::removeRelations ");
453 QString uid = incidence->uid(); 456 QString uid = incidence->uid();
454 457
455 QPtrList<Incidence> relations = incidence->relations(); 458 QPtrList<Incidence> relations = incidence->relations();
456 for( Incidence* i = relations.first(); i; i = relations.next() ) 459 for( Incidence* i = relations.first(); i; i = relations.next() )
457 if( !mOrphanUids.find( i->uid() ) ) { 460 if( !mOrphanUids.find( i->uid() ) ) {
458 mOrphans.insert( uid, i ); 461 mOrphans.insert( uid, i );
459 mOrphanUids.insert( i->uid(), i ); 462 mOrphanUids.insert( i->uid(), i );
460 i->setRelatedTo( 0 ); 463 i->setRelatedTo( 0 );
461 i->setRelatedToUid( uid ); 464 i->setRelatedToUid( uid );
462 } 465 }
463 466
464 // If this incidence is related to something else, tell that about it 467 // If this incidence is related to something else, tell that about it
465 if( incidence->relatedTo() ) 468 if( incidence->relatedTo() )
466 incidence->relatedTo()->removeRelation( incidence ); 469 incidence->relatedTo()->removeRelation( incidence );
467 470
468 // Remove this one from the orphans list 471 // Remove this one from the orphans list
469 if( mOrphanUids.remove( uid ) ) { 472 if( mOrphanUids.remove( uid ) ) {
470 QString r2uid = incidence->relatedToUid(); 473 QString r2uid = incidence->relatedToUid();
471 QPtrList<Incidence> tempList; 474 QPtrList<Incidence> tempList;
472 while( Incidence* i = mOrphans[ r2uid ] ) { 475 while( Incidence* i = mOrphans[ r2uid ] ) {
473 mOrphans.remove( r2uid ); 476 mOrphans.remove( r2uid );
474 if ( i != incidence ) tempList.append( i ); 477 if ( i != incidence ) tempList.append( i );
475 } 478 }
476 Incidence* inc = tempList.first(); 479 Incidence* inc = tempList.first();
477 while ( inc ) { 480 while ( inc ) {
478 mOrphans.insert( r2uid, inc ); 481 mOrphans.insert( r2uid, inc );
479 inc = tempList.next(); 482 inc = tempList.next();
480 } 483 }
481 } 484 }
482 // LR: and another big bad bug found 485 // LR: and another big bad bug found
483#if 0 486#if 0
484 // This incidence is located in the orphans list - it should be removed 487 // This incidence is located in the orphans list - it should be removed
485 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 488 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
486 // Removing wasn't that easy 489 // Removing wasn't that easy
487 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 490 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
488 if( it.current()->uid() == uid ) { 491 if( it.current()->uid() == uid ) {
489 mOrphans.remove( it.currentKey() ); 492 mOrphans.remove( it.currentKey() );
490 break; 493 break;
491 } 494 }
492 } 495 }
493 } 496 }
494#endif 497#endif
495} 498}
496 499
497void Calendar::registerObserver( Observer *observer ) 500void Calendar::registerObserver( Observer *observer )
498{ 501{
499 mObserver = observer; 502 mObserver = observer;
500 mNewObserver = true; 503 mNewObserver = true;
501} 504}
502 505
503void Calendar::setModified( bool modified ) 506void Calendar::setModified( bool modified )
504{ 507{
505 if ( mObserver ) mObserver->calendarModified( modified, this ); 508 if ( mObserver ) mObserver->calendarModified( modified, this );
506 if ( modified != mModified || mNewObserver ) { 509 if ( modified != mModified || mNewObserver ) {
507 mNewObserver = false; 510 mNewObserver = false;
508 // if ( mObserver ) mObserver->calendarModified( modified, this ); 511 // if ( mObserver ) mObserver->calendarModified( modified, this );
509 mModified = modified; 512 mModified = modified;
510 } 513 }
511} 514}
512 515
513void Calendar::setLoadedProductId( const QString &id ) 516void Calendar::setLoadedProductId( const QString &id )
514{ 517{
515 mLoadedProductId = id; 518 mLoadedProductId = id;
516} 519}
517 520
518QString Calendar::loadedProductId() 521QString Calendar::loadedProductId()
519{ 522{
520 return mLoadedProductId; 523 return mLoadedProductId;
521} 524}
522 525
523//#include "calendar.moc" 526//#include "calendar.moc"
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index f301768..fbc40ad 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -1,176 +1,177 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#ifndef CALENDAR_H 22#ifndef CALENDAR_H
23#define CALENDAR_H 23#define CALENDAR_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qptrlist.h> 28#include <qptrlist.h>
29#include <qdict.h> 29#include <qdict.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "event.h" 32#include "event.h"
33#include "todo.h" 33#include "todo.h"
34#include "journal.h" 34#include "journal.h"
35#include "calfilter.h" 35#include "calfilter.h"
36 36
37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ 37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */
38 38
39class KConfig; 39class KConfig;
40 40
41namespace KCal { 41namespace KCal {
42 42
43 43
44/** 44/**
45 This is the main "calendar" object class for KOrganizer. It holds 45 This is the main "calendar" object class for KOrganizer. It holds
46 information like all appointments/events, user information, etc. etc. 46 information like all appointments/events, user information, etc. etc.
47 one calendar is associated with each CalendarView (@see calendarview.h). 47 one calendar is associated with each CalendarView (@see calendarview.h).
48 This is an abstract base class defining the interface to a calendar. It is 48 This is an abstract base class defining the interface to a calendar. It is
49 implemented by subclasses like @see CalendarLocal, which use different 49 implemented by subclasses like @see CalendarLocal, which use different
50 methods to store and access the data. 50 methods to store and access the data.
51 51
52 Ownership of events etc. is handled by the following policy: As soon as an 52 Ownership of events etc. is handled by the following policy: As soon as an
53 event (or any other subclass of IncidenceBase) object is added to the 53 event (or any other subclass of IncidenceBase) object is added to the
54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes 54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes
55 care of deleting it. All Events returned by the query functions are returned 55 care of deleting it. All Events returned by the query functions are returned
56 as pointers, that means all changes to the returned events are immediately 56 as pointers, that means all changes to the returned events are immediately
57 visible in the Calendar. You shouldn't delete any Event object you get from 57 visible in the Calendar. You shouldn't delete any Event object you get from
58 Calendar. 58 Calendar.
59*/ 59*/
60class Calendar : public QObject, public CustomProperties, 60class Calendar : public QObject, public CustomProperties,
61 public IncidenceBase::Observer 61 public IncidenceBase::Observer
62{ 62{
63 Q_OBJECT 63 Q_OBJECT
64public: 64public:
65 Calendar(); 65 Calendar();
66 Calendar(const QString &timeZoneId); 66 Calendar(const QString &timeZoneId);
67 virtual ~Calendar(); 67 virtual ~Calendar();
68 Incidence * undoIncidence() { return mUndoIncidence; }; 68 Incidence * undoIncidence() { return mUndoIncidence; };
69 bool undoDeleteIncidence(); 69 bool undoDeleteIncidence();
70 void deleteIncidence(Incidence *in); 70 void deleteIncidence(Incidence *in);
71 void resetTempSyncStat(); 71 void resetTempSyncStat();
72 void resetPilotStat(int id); 72 void resetPilotStat(int id);
73 /** 73 /**
74 Clears out the current calendar, freeing all used memory etc. 74 Clears out the current calendar, freeing all used memory etc.
75 */ 75 */
76 virtual void close() = 0; 76 virtual void close() = 0;
77 virtual void addCalendar( Calendar* ) = 0; 77 virtual void addCalendar( Calendar* ) = 0;
78 virtual bool addCalendarFile( QString name, int id ) = 0; 78 virtual bool addCalendarFile( QString name, int id ) = 0;
79 virtual bool mergeCalendarFile( QString name ) = 0; 79 virtual bool mergeCalendarFile( QString name ) = 0;
80 virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ) = 0; 80 virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ,int * isDup = 0 ) = 0;
81 virtual Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0) = 0;
81 virtual void setSyncEventsReadOnly() = 0; 82 virtual void setSyncEventsReadOnly() = 0;
82 virtual void setSyncEventsEnabled() = 0; 83 virtual void setSyncEventsEnabled() = 0;
83 virtual void stopAllTodos() = 0; 84 virtual void stopAllTodos() = 0;
84 virtual void clearUndo( Incidence * newUndo ); 85 virtual void clearUndo( Incidence * newUndo );
85 86
86 /** 87 /**
87 Sync changes in memory to persistant storage. 88 Sync changes in memory to persistant storage.
88 */ 89 */
89 virtual void save() = 0; 90 virtual void save() = 0;
90 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 91 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
91 virtual void removeSyncInfo( QString syncProfile) = 0; 92 virtual void removeSyncInfo( QString syncProfile) = 0;
92 virtual bool isSaving() { return false; } 93 virtual bool isSaving() { return false; }
93 94
94 /** 95 /**
95 Return the owner of the calendar's full name. 96 Return the owner of the calendar's full name.
96 */ 97 */
97 const QString &getOwner() const; 98 const QString &getOwner() const;
98 /** 99 /**
99 Set the owner of the calendar. Should be owner's full name. 100 Set the owner of the calendar. Should be owner's full name.
100 */ 101 */
101 void setOwner( const QString &os ); 102 void setOwner( const QString &os );
102 /** 103 /**
103 Return the email address of the calendar owner. 104 Return the email address of the calendar owner.
104 */ 105 */
105 const QString &getEmail(); 106 const QString &getEmail();
106 /** 107 /**
107 Set the email address of the calendar owner. 108 Set the email address of the calendar owner.
108 */ 109 */
109 void setEmail( const QString & ); 110 void setEmail( const QString & );
110 111
111 /** 112 /**
112 Set time zone from a timezone string (e.g. -2:00) 113 Set time zone from a timezone string (e.g. -2:00)
113 */ 114 */
114 void setTimeZone( const QString &tz ); 115 void setTimeZone( const QString &tz );
115 /** 116 /**
116 Set time zone from a minutes value (e.g. -60) 117 Set time zone from a minutes value (e.g. -60)
117 */ 118 */
118 void setTimeZone( int tz ); 119 void setTimeZone( int tz );
119 /** 120 /**
120 Return time zone as offest in minutes. 121 Return time zone as offest in minutes.
121 */ 122 */
122 int getTimeZone() const; 123 int getTimeZone() const;
123 /** 124 /**
124 Compute an ISO 8601 format string from the time zone. 125 Compute an ISO 8601 format string from the time zone.
125 */ 126 */
126 QString getTimeZoneStr() const; 127 QString getTimeZoneStr() const;
127 /** 128 /**
128 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal 129 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal
129 values). 130 values).
130 */ 131 */
131 void setTimeZoneId( const QString & ); 132 void setTimeZoneId( const QString & );
132 /** 133 /**
133 Return time zone id. 134 Return time zone id.
134 */ 135 */
135 QString timeZoneId() const; 136 QString timeZoneId() const;
136 /** 137 /**
137 Use local time, not UTC or a time zone. 138 Use local time, not UTC or a time zone.
138 */ 139 */
139 void setLocalTime(); 140 void setLocalTime();
140 /** 141 /**
141 Return whether local time is being used. 142 Return whether local time is being used.
142 */ 143 */
143 bool isLocalTime() const; 144 bool isLocalTime() const;
144 145
145 /** 146 /**
146 Add an incidence to calendar. 147 Add an incidence to calendar.
147 148
148 @return true on success, false on error. 149 @return true on success, false on error.
149 */ 150 */
150 virtual bool addIncidence( Incidence * ); 151 virtual bool addIncidence( Incidence * );
151 152
152 // Adds an incidence and all relatedto incidences to the cal 153 // Adds an incidence and all relatedto incidences to the cal
153 void addIncidenceBranch( Incidence * ); 154 void addIncidenceBranch( Incidence * );
154 /** 155 /**
155 Return filtered list of all incidences of this calendar. 156 Return filtered list of all incidences of this calendar.
156 */ 157 */
157 virtual QPtrList<Incidence> incidences(); 158 virtual QPtrList<Incidence> incidences();
158 159
159 /** 160 /**
160 Return unfiltered list of all incidences of this calendar. 161 Return unfiltered list of all incidences of this calendar.
161 */ 162 */
162 virtual QPtrList<Incidence> rawIncidences(); 163 virtual QPtrList<Incidence> rawIncidences();
163 164
164 /** 165 /**
165 Adds a Event to this calendar object. 166 Adds a Event to this calendar object.
166 @param anEvent a pointer to the event to add 167 @param anEvent a pointer to the event to add
167 168
168 @return true on success, false on error. 169 @return true on success, false on error.
169 */ 170 */
170 virtual bool addEventNoDup( Event *event ) = 0; 171 virtual bool addEventNoDup( Event *event ) = 0;
171 virtual bool addAnniversaryNoDup( Event *event ) = 0; 172 virtual bool addAnniversaryNoDup( Event *event ) = 0;
172 virtual bool addEvent( Event *anEvent ) = 0; 173 virtual bool addEvent( Event *anEvent ) = 0;
173 /** 174 /**
174 Delete event from calendar. 175 Delete event from calendar.
175 */ 176 */
176 virtual void deleteEvent( Event * ) = 0; 177 virtual void deleteEvent( Event * ) = 0;
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index ad8ace3..980663f 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,517 +1,568 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 registerObserver( 0 ); 68 registerObserver( 0 );
69 if ( mDeleteIncidencesOnClose ) 69 if ( mDeleteIncidencesOnClose )
70 close(); 70 close();
71} 71}
72bool CalendarLocal::mergeCalendarFile( QString name ) 72bool CalendarLocal::mergeCalendarFile( QString name )
73{ 73{
74 CalendarLocal calendar( timeZoneId() ); 74 CalendarLocal calendar( timeZoneId() );
75 calendar.setDefaultCalendar( 1 ); 75 calendar.setDefaultCalendar( 1 );
76 if ( calendar.load( name ) ) { 76 if ( calendar.load( name ) ) {
77 mergeCalendar( &calendar ); 77 mergeCalendar( &calendar );
78 return true; 78 return true;
79 } 79 }
80 return false; 80 return false;
81} 81}
82 82
83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly ) 83Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup )
84{ 84{
85
86 int calID = 0;
87 if ( isDup && *isDup > 0 )
88 calID = *isDup;
85 Todo *todo;; 89 Todo *todo;;
86 Incidence *retVal = 0; 90 Todo *retVal = 0;
87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 91 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
88 if ( todo->uid() == uid ) { 92 if ( todo->uid() == uid ) {
89 if ( enabledOnly ) 93 if( calID ) {
90 if ( !todo->calEnabled() ) 94 if ( todo->calID() != calID )
95 continue;
96 }
97 else {
98 if ( enabledOnly ) {
99 if ( !todo->calEnabled() ) {
100 if ( isDup )
101 *isDup = todo->calID();
91 continue; 102 continue;
103 }
104 }
105 }
92 if ( doNotCheckDuplicates ) return todo; 106 if ( doNotCheckDuplicates ) return todo;
93 if ( retVal ) { 107 if ( retVal ) {
94 if ( retVal->calID() > todo->calID() ) { 108 if ( retVal->calID() > todo->calID() ) {
109 if ( isDup )
110 *isDup = retVal->calID();
95 retVal = todo; 111 retVal = todo;
96 } 112 }
97 } else { 113 } else {
98 retVal = todo; 114 retVal = todo;
99 } 115 }
100 } 116 }
101 } 117 }
118 return retVal;
119}
120//if ( isDup) and * isDup == 0: store duplicate found cal id in isDup
121//if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly
122
123Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup )
124{
125 int calID = 0;
126 if ( isDup && *isDup > 0 )
127 calID = *isDup;
128 Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup );
102 if ( retVal ) return retVal; 129 if ( retVal ) return retVal;
103 Event *event; 130 Event *event;
104 for ( event = mEventList.first(); event; event = mEventList.next() ) { 131 for ( event = mEventList.first(); event; event = mEventList.next() ) {
105 if ( event->uid() == uid ) { 132 if ( event->uid() == uid ) {
106 if ( enabledOnly ) 133 if( calID ) {
107 if ( !event->calEnabled() ) 134 if ( event->calID() != calID )
108 continue; 135 continue;
136 }
137 else {
138 if ( enabledOnly ) {
139 if ( !event->calEnabled() ) {
140 if ( isDup )
141 *isDup =event->calID() ;
142 continue;
143 }
144 }
145 }
109 if ( doNotCheckDuplicates ) return event; 146 if ( doNotCheckDuplicates ) return event;
110 if ( retVal ) { 147 if ( retVal ) {
111 if ( retVal->calID() > event->calID() ) { 148 if ( retVal->calID() > event->calID() ) {
149 if ( isDup )
150 *isDup = retVal->calID();
112 retVal = event; 151 retVal = event;
113 } 152 }
114 } else { 153 } else {
115 retVal = event; 154 retVal = event;
116 } 155 }
117 } 156 }
118 } 157 }
119 if ( retVal ) return retVal; 158 if ( retVal ) return retVal;
120 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 159 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
121 if ( it->uid() == uid ) { 160 if ( it->uid() == uid ) {
122 if ( enabledOnly ) 161 if( calID ) {
123 if ( !it->calEnabled() ) 162 if ( event->calID() != calID )
124 continue; 163 continue;
164 }
165 else {
166 if ( enabledOnly ) {
167 if ( !it->calEnabled() ) {
168 if ( isDup )
169 *isDup = it->calID();
170 continue;
171 }
172 }
173 }
125 if ( doNotCheckDuplicates ) return it; 174 if ( doNotCheckDuplicates ) return it;
126 if ( retVal ) { 175 if ( retVal ) {
127 if ( retVal->calID() > it->calID() ) { 176 if ( retVal->calID() > it->calID() ) {
177 if ( isDup )
178 *isDup = retVal->calID();
128 retVal = it; 179 retVal = it;
129 } 180 }
130 } else { 181 } else {
131 retVal = it; 182 retVal = it;
132 } 183 }
133 } 184 }
134 return retVal; 185 return retVal;
135} 186}
136 187
137bool CalendarLocal::mergeCalendar( Calendar* remote ) 188bool CalendarLocal::mergeCalendar( Calendar* remote )
138{ 189{
139 // 1 look for raw inc in local 190 // 1 look for raw inc in local
140 // if inc not in remote, delete in local 191 // if inc not in remote, delete in local
141 // 2 look for raw inc in remote 192 // 2 look for raw inc in remote
142 // if inc in local, replace it 193 // if inc in local, replace it
143 // if not in local, add it to default calendar 194 // if not in local, add it to default calendar
144 QPtrList<Incidence> localInc = rawIncidences(); 195 QPtrList<Incidence> localInc = rawIncidences();
145 Incidence* inL = localInc.first(); 196 Incidence* inL = localInc.first();
146 while ( inL ) { 197 while ( inL ) {
147 if ( ! inL->isReadOnly () ) 198 if ( ! inL->isReadOnly () )
148 if ( !remote->incidenceForUid( inL->uid(), true )) 199 if ( !remote->incidenceForUid( inL->uid(), true ))
149 deleteIncidence( inL ); 200 deleteIncidence( inL );
150 inL = localInc.next(); 201 inL = localInc.next();
151 } 202 }
152 QPtrList<Incidence> er = remote->rawIncidences(); 203 QPtrList<Incidence> er = remote->rawIncidences();
153 Incidence* inR = er.first(); 204 Incidence* inR = er.first();
154 while ( inR ) { 205 while ( inR ) {
155 inL = incidenceForUid( inR->uid(),false ); 206 inL = incidenceForUid( inR->uid(),false );
156 if ( inL ) { 207 if ( inL ) {
157 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { 208 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
158 int calID = inL->calID(); 209 int calID = inL->calID();
159 deleteIncidence( inL ); 210 deleteIncidence( inL );
160 inL = inR->clone(); 211 inL = inR->clone();
161 inL->setCalID_block( calID ); 212 inL->setCalID_block( calID );
162 addIncidence( inL ); 213 addIncidence( inL );
163 } 214 }
164 } else { 215 } else {
165 inL = inR->clone(); 216 inL = inR->clone();
166 inL->setCalID_block( 0 );// add to default cal 217 inL->setCalID_block( 0 );// add to default cal
167 addIncidence( inL ); 218 addIncidence( inL );
168 } 219 }
169 inR = er.next(); 220 inR = er.next();
170 } 221 }
171 return true; 222 return true;
172} 223}
173 224
174 225
175bool CalendarLocal::addCalendarFile( QString name, int id ) 226bool CalendarLocal::addCalendarFile( QString name, int id )
176{ 227{
177 CalendarLocal calendar( timeZoneId() ); 228 CalendarLocal calendar( timeZoneId() );
178 calendar.setDefaultCalendar( id ); 229 calendar.setDefaultCalendar( id );
179 if ( calendar.load( name ) ) { 230 if ( calendar.load( name ) ) {
180 addCalendar( &calendar ); 231 addCalendar( &calendar );
181 return true; 232 return true;
182 } 233 }
183 return false; 234 return false;
184} 235}
185void CalendarLocal::setSyncEventsEnabled() 236void CalendarLocal::setSyncEventsEnabled()
186{ 237{
187 Event * ev; 238 Event * ev;
188 ev = mEventList.first(); 239 ev = mEventList.first();
189 while ( ev ) { 240 while ( ev ) {
190 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 241 if ( ev->uid().left(15) == QString("last-syncEvent-") )
191 ev->setCalEnabled( true ); 242 ev->setCalEnabled( true );
192 ev = mEventList.next(); 243 ev = mEventList.next();
193 } 244 }
194} 245}
195void CalendarLocal::setSyncEventsReadOnly() 246void CalendarLocal::setSyncEventsReadOnly()
196{ 247{
197 Event * ev; 248 Event * ev;
198 ev = mEventList.first(); 249 ev = mEventList.first();
199 while ( ev ) { 250 while ( ev ) {
200 if ( ev->uid().left(15) == QString("last-syncEvent-") ) { 251 if ( ev->uid().left(15) == QString("last-syncEvent-") ) {
201 ev->setReadOnly( true ); 252 ev->setReadOnly( true );
202 } 253 }
203 ev = mEventList.next(); 254 ev = mEventList.next();
204 } 255 }
205} 256}
206 257
207void CalendarLocal::addCalendar( Calendar* cal ) 258void CalendarLocal::addCalendar( Calendar* cal )
208{ 259{
209 cal->setDontDeleteIncidencesOnClose(); 260 cal->setDontDeleteIncidencesOnClose();
210 setSyncEventsEnabled(); 261 setSyncEventsEnabled();
211 { 262 {
212 QPtrList<Event> EventList = cal->rawEvents(); 263 QPtrList<Event> EventList = cal->rawEvents();
213 QPtrList<Event> el; 264 QPtrList<Event> el;
214 Event * ev = EventList.first(); 265 Event * ev = EventList.first();
215 while ( ev ) { 266 while ( ev ) {
216 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { 267 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) {
217 Event * se = event( ev->uid() ); 268 Event * se = event( ev->uid() );
218 if ( se ) 269 if ( se )
219 el.append( se ); 270 el.append( se );
220 ev->setCalID_block( 1 ); 271 ev->setCalID_block( 1 );
221 } 272 }
222 ev->unRegisterObserver( cal ); 273 ev->unRegisterObserver( cal );
223 ev->registerObserver( this ); 274 ev->registerObserver( this );
224 mEventList.append( ev ); 275 mEventList.append( ev );
225 ev = EventList.next(); 276 ev = EventList.next();
226 } 277 }
227 for ( ev = el.first(); ev; ev = el.next() ) { 278 for ( ev = el.first(); ev; ev = el.next() ) {
228 deleteIncidence ( ev ); 279 deleteIncidence ( ev );
229 } 280 }
230 } 281 }
231 { 282 {
232 283
233 QPtrList<Todo> TodoList = cal->rawTodos(); 284 QPtrList<Todo> TodoList = cal->rawTodos();
234 Todo * ev = TodoList.first(); 285 Todo * ev = TodoList.first();
235 while ( ev ) { 286 while ( ev ) {
236 QString rel = ev->relatedToUid(); 287 ev->resetRelatedTo();
237 if ( !rel.isEmpty() ){
238 ev->setRelatedTo ( 0 );
239 ev->setRelatedToUid( rel );
240 }
241 ev = TodoList.next(); 288 ev = TodoList.next();
242 } 289 }
243 //TodoList = cal->rawTodos(); 290 //TodoList = cal->rawTodos();
244 ev = TodoList.first(); 291 ev = TodoList.first();
245 while ( ev ) { 292 while ( ev ) {
246 ev->unRegisterObserver( cal ); 293 ev->unRegisterObserver( cal );
247 ev->registerObserver( this ); 294 ev->registerObserver( this );
248 mTodoList.append( ev ); 295 mTodoList.append( ev );
249 setupRelations( ev ); 296 setupRelations( ev );
250 ev = TodoList.next(); 297 ev = TodoList.next();
251 } 298 }
252 } 299 }
253 { 300 {
254 QPtrList<Journal> JournalList = cal->journals(); 301 QPtrList<Journal> JournalList = cal->journals();
255 Journal * ev = JournalList.first(); 302 Journal * ev = JournalList.first();
256 while ( ev ) { 303 while ( ev ) {
257 ev->unRegisterObserver( cal ); 304 ev->unRegisterObserver( cal );
258 ev->registerObserver( this ); 305 ev->registerObserver( this );
259 mJournalList.append( ev ); 306 mJournalList.append( ev );
260 ev = JournalList.next(); 307 ev = JournalList.next();
261 } 308 }
262 } 309 }
263 setModified( true ); 310 setModified( true );
264} 311}
265bool CalendarLocal::load( const QString &fileName ) 312bool CalendarLocal::load( const QString &fileName )
266{ 313{
267 FileStorage storage( this, fileName ); 314 FileStorage storage( this, fileName );
268 return storage.load(); 315 return storage.load();
269} 316}
270 317
271bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 318bool CalendarLocal::save( const QString &fileName, CalFormat *format )
272{ 319{
273 FileStorage storage( this, fileName, format ); 320 FileStorage storage( this, fileName, format );
274 return storage.save(); 321 return storage.save();
275} 322}
276 323
277void CalendarLocal::stopAllTodos() 324void CalendarLocal::stopAllTodos()
278{ 325{
279 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 326 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
280 it->setRunning( false ); 327 it->setRunning( false );
281 328
282} 329}
283void CalendarLocal::close() 330void CalendarLocal::close()
284{ 331{
285 332
286 Todo * i; 333 Todo * i;
287 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 334 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
288 335
289 mEventList.setAutoDelete( true ); 336 mEventList.setAutoDelete( true );
290 mTodoList.setAutoDelete( true ); 337 mTodoList.setAutoDelete( true );
291 mJournalList.setAutoDelete( true ); 338 mJournalList.setAutoDelete( true );
292 339
293 mEventList.clear(); 340 mEventList.clear();
294 mTodoList.clear(); 341 mTodoList.clear();
295 mJournalList.clear(); 342 mJournalList.clear();
296 343
297 mEventList.setAutoDelete( false ); 344 mEventList.setAutoDelete( false );
298 mTodoList.setAutoDelete( false ); 345 mTodoList.setAutoDelete( false );
299 mJournalList.setAutoDelete( false ); 346 mJournalList.setAutoDelete( false );
300 347
301 setModified( false ); 348 setModified( false );
302} 349}
303 350
304bool CalendarLocal::addAnniversaryNoDup( Event *event ) 351bool CalendarLocal::addAnniversaryNoDup( Event *event )
305{ 352{
306 QString cat; 353 QString cat;
307 bool isBirthday = true; 354 bool isBirthday = true;
308 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 355 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
309 isBirthday = false; 356 isBirthday = false;
310 cat = i18n( "Anniversary" ); 357 cat = i18n( "Anniversary" );
311 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 358 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
312 isBirthday = true; 359 isBirthday = true;
313 cat = i18n( "Birthday" ); 360 cat = i18n( "Birthday" );
314 } else { 361 } else {
315 qDebug("addAnniversaryNoDup called without fitting category! "); 362 qDebug("addAnniversaryNoDup called without fitting category! ");
316 return false; 363 return false;
317 } 364 }
318 Event * eve; 365 Event * eve;
319 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 366 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
320 if ( !(eve->categories().contains( cat ) )) 367 if ( !(eve->categories().contains( cat ) ))
321 continue; 368 continue;
322 // now we have an event with fitting category 369 // now we have an event with fitting category
323 if ( eve->dtStart().date() != event->dtStart().date() ) 370 if ( eve->dtStart().date() != event->dtStart().date() )
324 continue; 371 continue;
325 // now we have an event with fitting category+date 372 // now we have an event with fitting category+date
326 if ( eve->summary() != event->summary() ) 373 if ( eve->summary() != event->summary() )
327 continue; 374 continue;
328 // now we have an event with fitting category+date+summary 375 // now we have an event with fitting category+date+summary
329 return false; 376 return false;
330 } 377 }
331 return addEvent( event ); 378 return addEvent( event );
332 379
333} 380}
334bool CalendarLocal::addEventNoDup( Event *event ) 381bool CalendarLocal::addEventNoDup( Event *event )
335{ 382{
336 Event * eve; 383 Event * eve;
337 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 384 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
338 if ( *eve == *event ) { 385 if ( *eve == *event ) {
339 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 386 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
340 return false; 387 return false;
341 } 388 }
342 } 389 }
343 return addEvent( event ); 390 return addEvent( event );
344} 391}
345 392
346bool CalendarLocal::addEvent( Event *event ) 393bool CalendarLocal::addEvent( Event *event )
347{ 394{
348 insertEvent( event ); 395 insertEvent( event );
349 396
350 event->registerObserver( this ); 397 event->registerObserver( this );
351 398
352 setModified( true ); 399 setModified( true );
353 if ( event->calID() == 0 ) 400 if ( event->calID() == 0 )
354 event->setCalID_block( mDefaultCalendar ); 401 event->setCalID_block( mDefaultCalendar );
355 event->setCalEnabled( true ); 402 event->setCalEnabled( true );
356 403
357 return true; 404 return true;
358} 405}
359 406
360void CalendarLocal::deleteEvent( Event *event ) 407void CalendarLocal::deleteEvent( Event *event )
361{ 408{
362 clearUndo(event); 409 clearUndo(event);
363 if ( mEventList.removeRef( event ) ) { 410 if ( mEventList.removeRef( event ) ) {
364 setModified( true ); 411 setModified( true );
365 } 412 }
366} 413}
367 414
368 415
369Event *CalendarLocal::event( const QString &uid ) 416Event *CalendarLocal::event( const QString &uid )
370{ 417{
371 Event *event; 418 Event *event;
372 Event *retVal = 0; 419 Event *retVal = 0;
373 for ( event = mEventList.first(); event; event = mEventList.next() ) { 420 for ( event = mEventList.first(); event; event = mEventList.next() ) {
374 if ( event->calEnabled() && event->uid() == uid ) { 421 if ( event->calEnabled() && event->uid() == uid ) {
375 if ( retVal ) { 422 if ( retVal ) {
376 if ( retVal->calID() > event->calID() ) { 423 if ( retVal->calID() > event->calID() ) {
377 retVal = event; 424 retVal = event;
378 } 425 }
379 } else { 426 } else {
380 retVal = event; 427 retVal = event;
381 } 428 }
382 } 429 }
383 } 430 }
384 return retVal; 431 return retVal;
385} 432}
386bool CalendarLocal::addTodoNoDup( Todo *todo ) 433bool CalendarLocal::addTodoNoDup( Todo *todo )
387{ 434{
388 Todo * eve; 435 Todo * eve;
389 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 436 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
390 if ( *eve == *todo ) { 437 if ( *eve == *todo ) {
391 //qDebug("duplicate todo found! not inserted! "); 438 //qDebug("duplicate todo found! not inserted! ");
392 return false; 439 return false;
393 } 440 }
394 } 441 }
395 return addTodo( todo ); 442 return addTodo( todo );
396} 443}
397bool CalendarLocal::addTodo( Todo *todo ) 444bool CalendarLocal::addTodo( Todo *todo )
398{ 445{
399 mTodoList.append( todo ); 446 mTodoList.append( todo );
400 447
401 todo->registerObserver( this ); 448 todo->registerObserver( this );
402 449
403 // Set up subtask relations 450 // Set up subtask relations
404 setupRelations( todo ); 451 setupRelations( todo );
405 452
406 setModified( true ); 453 setModified( true );
407 if ( todo->calID() == 0 ) 454 if ( todo->calID() == 0 )
408 todo->setCalID_block( mDefaultCalendar ); 455 todo->setCalID_block( mDefaultCalendar );
409 todo->setCalEnabled( true ); 456 todo->setCalEnabled( true );
410 return true; 457 return true;
411} 458}
412 459
413void CalendarLocal::deleteTodo( Todo *todo ) 460void CalendarLocal::deleteTodo( Todo *todo )
414{ 461{
462 QString uid = todo->uid();
415 // Handle orphaned children 463 // Handle orphaned children
416 removeRelations( todo ); 464 removeRelations( todo );
417 clearUndo(todo); 465 clearUndo(todo);
418 466
419 if ( mTodoList.removeRef( todo ) ) { 467 if ( mTodoList.removeRef( todo ) ) {
420 setModified( true ); 468 setModified( true );
421 } 469 }
470 Todo* dup = todoForUid( uid );
471 if ( dup )
472 setupRelations( dup );
422} 473}
423 474
424QPtrList<Todo> CalendarLocal::rawTodos() 475QPtrList<Todo> CalendarLocal::rawTodos()
425{ 476{
426 QPtrList<Todo> el; 477 QPtrList<Todo> el;
427 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 478 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
428 if ( it->calEnabled() ) el.append( it ); 479 if ( it->calEnabled() ) el.append( it );
429 return el; 480 return el;
430} 481}
431Todo *CalendarLocal::todo( QString syncProf, QString id ) 482Todo *CalendarLocal::todo( QString syncProf, QString id )
432{ 483{
433 Todo *todo; 484 Todo *todo;
434 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 485 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
435 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 486 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
436 } 487 }
437 488
438 return 0; 489 return 0;
439} 490}
440void CalendarLocal::removeSyncInfo( QString syncProfile) 491void CalendarLocal::removeSyncInfo( QString syncProfile)
441{ 492{
442 QPtrList<Incidence> all = rawIncidences() ; 493 QPtrList<Incidence> all = rawIncidences() ;
443 Incidence *inc; 494 Incidence *inc;
444 for ( inc = all.first(); inc; inc = all.next() ) { 495 for ( inc = all.first(); inc; inc = all.next() ) {
445 inc->removeID( syncProfile ); 496 inc->removeID( syncProfile );
446 } 497 }
447 if ( syncProfile.isEmpty() ) { 498 if ( syncProfile.isEmpty() ) {
448 QPtrList<Event> el; 499 QPtrList<Event> el;
449 Event *todo; 500 Event *todo;
450 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 501 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
451 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 502 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
452 el.append( todo ); 503 el.append( todo );
453 } 504 }
454 for ( todo = el.first(); todo; todo = el.next() ) { 505 for ( todo = el.first(); todo; todo = el.next() ) {
455 deleteIncidence ( todo ); 506 deleteIncidence ( todo );
456 } 507 }
457 } else { 508 } else {
458 Event *lse = event( "last-syncEvent-"+ syncProfile); 509 Event *lse = event( "last-syncEvent-"+ syncProfile);
459 if ( lse ) 510 if ( lse )
460 deleteIncidence ( lse ); 511 deleteIncidence ( lse );
461 } 512 }
462} 513}
463QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 514QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
464{ 515{
465 QPtrList<Event> el; 516 QPtrList<Event> el;
466 Event *todo; 517 Event *todo;
467 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 518 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
468 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 519 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
469 if ( todo->summary().left(3) == "E: " ) 520 if ( todo->summary().left(3) == "E: " )
470 el.append( todo ); 521 el.append( todo );
471 } 522 }
472 523
473 return el; 524 return el;
474 525
475} 526}
476Event *CalendarLocal::event( QString syncProf, QString id ) 527Event *CalendarLocal::event( QString syncProf, QString id )
477{ 528{
478 Event *todo; 529 Event *todo;
479 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 530 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
480 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 531 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
481 } 532 }
482 533
483 return 0; 534 return 0;
484} 535}
485Todo *CalendarLocal::todo( const QString &uid ) 536Todo *CalendarLocal::todo( const QString &uid )
486{ 537{
487 Todo *todo; 538 Todo *todo;
488 Todo *retVal = 0; 539 Todo *retVal = 0;
489 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 540 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
490 if ( todo->calEnabled() && todo->uid() == uid ) { 541 if ( todo->calEnabled() && todo->uid() == uid ) {
491 if ( retVal ) { 542 if ( retVal ) {
492 if ( retVal->calID() > todo->calID() ) { 543 if ( retVal->calID() > todo->calID() ) {
493 retVal = todo; 544 retVal = todo;
494 } 545 }
495 } else { 546 } else {
496 retVal = todo; 547 retVal = todo;
497 } 548 }
498 } 549 }
499 } 550 }
500 return retVal; 551 return retVal;
501} 552}
502void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) 553void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals)
503{ 554{
504 events = 0; 555 events = 0;
505 todos = 0; 556 todos = 0;
506 journals = 0; 557 journals = 0;
507 { 558 {
508 Todo *todo; 559 Todo *todo;
509 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 560 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
510 if ( todo->calID() == calId ) 561 if ( todo->calID() == calId )
511 ++todos; 562 ++todos;
512 } 563 }
513 } 564 }
514 { 565 {
515 Event *todo; 566 Event *todo;
516 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 567 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
517 if ( todo->calID() == calId ) 568 if ( todo->calID() == calId )
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index b611704..1ceabce 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -1,146 +1,147 @@
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#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
27namespace KCal { 27namespace KCal {
28 28
29class CalFormat; 29class 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*/
34class CalendarLocal : public Calendar 34class 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, bool enabledOnly = false ); 50 Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly = false,int * isDup = 0 );
51 Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0 );
51 void setSyncEventsReadOnly(); 52 void setSyncEventsReadOnly();
52 void setSyncEventsEnabled(); 53 void setSyncEventsEnabled();
53 void stopAllTodos(); 54 void stopAllTodos();
54 /** 55 /**
55 Loads a calendar on disk in vCalendar or iCalendar format into the current 56 Loads a calendar on disk in vCalendar or iCalendar format into the current
56 calendar. Any information already present is lost. 57 calendar. Any information already present is lost.
57 @return true, if successfull, false on error. 58 @return true, if successfull, false on error.
58 @param fileName the name of the calendar on disk. 59 @param fileName the name of the calendar on disk.
59 */ 60 */
60 bool load( const QString &fileName ); 61 bool load( const QString &fileName );
61 /** 62 /**
62 Writes out the calendar to disk in the specified \a format. 63 Writes out the calendar to disk in the specified \a format.
63 CalendarLocal takes ownership of the CalFormat object. 64 CalendarLocal takes ownership of the CalFormat object.
64 @return true, if successfull, false on error. 65 @return true, if successfull, false on error.
65 @param fileName the name of the file 66 @param fileName the name of the file
66 */ 67 */
67 bool save( const QString &fileName, CalFormat *format = 0 ); 68 bool save( const QString &fileName, CalFormat *format = 0 );
68 69
69 /** 70 /**
70 Clears out the current calendar, freeing all used memory etc. etc. 71 Clears out the current calendar, freeing all used memory etc. etc.
71 */ 72 */
72 void close(); 73 void close();
73 74
74 void save() {} 75 void save() {}
75 76
76 /** 77 /**
77 Add Event to calendar. 78 Add Event to calendar.
78 */ 79 */
79 void removeSyncInfo( QString syncProfile); 80 void removeSyncInfo( QString syncProfile);
80 bool addAnniversaryNoDup( Event *event ); 81 bool addAnniversaryNoDup( Event *event );
81 bool addEventNoDup( Event *event ); 82 bool addEventNoDup( Event *event );
82 bool addEvent( Event *event ); 83 bool addEvent( Event *event );
83 /** 84 /**
84 Deletes an event from this calendar. 85 Deletes an event from this calendar.
85 */ 86 */
86 void deleteEvent( Event *event ); 87 void deleteEvent( Event *event );
87 88
88 /** 89 /**
89 Retrieves an event on the basis of the unique string ID. 90 Retrieves an event on the basis of the unique string ID.
90 */ 91 */
91 Event *event( const QString &uid ); 92 Event *event( const QString &uid );
92 /** 93 /**
93 Return unfiltered list of all events in calendar. 94 Return unfiltered list of all events in calendar.
94 */ 95 */
95 QPtrList<Event> rawEvents(); 96 QPtrList<Event> rawEvents();
96 QPtrList<Event> getExternLastSyncEvents(); 97 QPtrList<Event> getExternLastSyncEvents();
97 /** 98 /**
98 Add a todo to the todolist. 99 Add a todo to the todolist.
99 */ 100 */
100 bool addTodo( Todo *todo ); 101 bool addTodo( Todo *todo );
101 bool addTodoNoDup( Todo *todo ); 102 bool addTodoNoDup( Todo *todo );
102 /** 103 /**
103 Remove a todo from the todolist. 104 Remove a todo from the todolist.
104 */ 105 */
105 void deleteTodo( Todo * ); 106 void deleteTodo( Todo * );
106 /** 107 /**
107 Searches todolist for an event with this unique string identifier, 108 Searches todolist for an event with this unique string identifier,
108 returns a pointer or null. 109 returns a pointer or null.
109 */ 110 */
110 Todo *todo( const QString &uid ); 111 Todo *todo( const QString &uid );
111 /** 112 /**
112 Return list of all todos. 113 Return list of all todos.
113 */ 114 */
114 QPtrList<Todo> rawTodos(); 115 QPtrList<Todo> rawTodos();
115 /** 116 /**
116 Returns list of todos due on the specified date. 117 Returns list of todos due on the specified date.
117 */ 118 */
118 QPtrList<Todo> todos( const QDate &date ); 119 QPtrList<Todo> todos( const QDate &date );
119 /** 120 /**
120 Return list of all todos. 121 Return list of all todos.
121 122
122 Workaround because compiler does not recognize function of base class. 123 Workaround because compiler does not recognize function of base class.
123 */ 124 */
124 QPtrList<Todo> todos() { return Calendar::todos(); } 125 QPtrList<Todo> todos() { return Calendar::todos(); }
125 126
126 /** 127 /**
127 Add a Journal entry to calendar. 128 Add a Journal entry to calendar.
128 */ 129 */
129 bool addJournal( Journal * ); 130 bool addJournal( Journal * );
130 /** 131 /**
131 Remove a Journal from the calendar. 132 Remove a Journal from the calendar.
132 */ 133 */
133 void deleteJournal( Journal * ); 134 void deleteJournal( Journal * );
134 /** 135 /**
135 Return Journal for given date. 136 Return Journal for given date.
136 */ 137 */
137 Journal *journal( const QDate & ); 138 Journal *journal( const QDate & );
138 QPtrList<Journal> journals4Date( const QDate & ); 139 QPtrList<Journal> journals4Date( const QDate & );
139 /** 140 /**
140 Return Journal with given UID. 141 Return Journal with given UID.
141 */ 142 */
142 Journal *journal( const QString &uid ); 143 Journal *journal( const QString &uid );
143 /** 144 /**
144 Return list of all Journals stored in calendar. 145 Return list of all Journals stored in calendar.
145 */ 146 */
146 QPtrList<Journal> journals(); 147 QPtrList<Journal> journals();
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index fe9f854..7dd9bd2 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -427,192 +427,198 @@ void Incidence::setSummary(const QString &summary)
427QString Incidence::summary() const 427QString Incidence::summary() const
428{ 428{
429 return mSummary; 429 return mSummary;
430} 430}
431void Incidence::checkCategories() 431void Incidence::checkCategories()
432{ 432{
433 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); 433 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday"));
434 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); 434 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday"));
435 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); 435 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary"));
436} 436}
437 437
438void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false 438void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false
439{ 439{
440 if (mReadOnly) return; 440 if (mReadOnly) return;
441 int i; 441 int i;
442 for( i = 0; i < categories.count(); ++i ) { 442 for( i = 0; i < categories.count(); ++i ) {
443 if ( !mCategories.contains (categories[i])) 443 if ( !mCategories.contains (categories[i]))
444 mCategories.append( categories[i] ); 444 mCategories.append( categories[i] );
445 } 445 }
446 checkCategories(); 446 checkCategories();
447 updated(); 447 updated();
448 if ( addToRelations ) { 448 if ( addToRelations ) {
449 Incidence * inc; 449 Incidence * inc;
450 QPtrList<Incidence> Relations = relations(); 450 QPtrList<Incidence> Relations = relations();
451 for (inc=Relations.first();inc;inc=Relations.next()) { 451 for (inc=Relations.first();inc;inc=Relations.next()) {
452 inc->addCategories( categories, true ); 452 inc->addCategories( categories, true );
453 } 453 }
454 } 454 }
455} 455}
456 456
457void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false 457void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false
458{ 458{
459 if (mReadOnly) return; 459 if (mReadOnly) return;
460 mCategories = categories; 460 mCategories = categories;
461 checkCategories(); 461 checkCategories();
462 updated(); 462 updated();
463 if ( setForRelations ) { 463 if ( setForRelations ) {
464 Incidence * inc; 464 Incidence * inc;
465 QPtrList<Incidence> Relations = relations(); 465 QPtrList<Incidence> Relations = relations();
466 for (inc=Relations.first();inc;inc=Relations.next()) { 466 for (inc=Relations.first();inc;inc=Relations.next()) {
467 inc->setCategories( categories, true ); 467 inc->setCategories( categories, true );
468 } 468 }
469 } 469 }
470} 470}
471 471
472// TODO: remove setCategories(QString) function 472// TODO: remove setCategories(QString) function
473void Incidence::setCategories(const QString &catStr) 473void Incidence::setCategories(const QString &catStr)
474{ 474{
475 if (mReadOnly) return; 475 if (mReadOnly) return;
476 mCategories.clear(); 476 mCategories.clear();
477 477
478 if (catStr.isEmpty()) return; 478 if (catStr.isEmpty()) return;
479 479
480 mCategories = QStringList::split(",",catStr); 480 mCategories = QStringList::split(",",catStr);
481 481
482 QStringList::Iterator it; 482 QStringList::Iterator it;
483 for(it = mCategories.begin();it != mCategories.end(); ++it) { 483 for(it = mCategories.begin();it != mCategories.end(); ++it) {
484 *it = (*it).stripWhiteSpace(); 484 *it = (*it).stripWhiteSpace();
485 } 485 }
486 checkCategories(); 486 checkCategories();
487 updated(); 487 updated();
488} 488}
489// using this makes filtering 3 times faster 489// using this makes filtering 3 times faster
490QStringList* Incidence::categoriesP() 490QStringList* Incidence::categoriesP()
491{ 491{
492 return &mCategories; 492 return &mCategories;
493} 493}
494 494
495QStringList Incidence::categories() const 495QStringList Incidence::categories() const
496{ 496{
497 return mCategories; 497 return mCategories;
498} 498}
499 499
500QString Incidence::categoriesStr() 500QString Incidence::categoriesStr()
501{ 501{
502 return mCategories.join(","); 502 return mCategories.join(",");
503} 503}
504QString Incidence::categoriesStrWithSpace() 504QString Incidence::categoriesStrWithSpace()
505{ 505{
506 return mCategories.join(", "); 506 return mCategories.join(", ");
507} 507}
508 508
509void Incidence::setRelatedToUid(const QString &relatedToUid) 509void Incidence::setRelatedToUid(const QString &relatedToUid)
510{ 510{
511 if (mReadOnly) return; 511 if (mReadOnly) return;
512 mRelatedToUid = relatedToUid; 512 mRelatedToUid = relatedToUid;
513} 513}
514void Incidence::clearRelations() 514void Incidence::clearRelations()
515{ 515{
516 mRelatedTo = 0; 516 mRelatedTo = 0;
517 mRelations.clear(); 517 mRelations.clear();
518} 518}
519QString Incidence::relatedToUid() const 519QString Incidence::relatedToUid() const
520{ 520{
521 return mRelatedToUid; 521 return mRelatedToUid;
522} 522}
523void Incidence::resetRelatedTo()
524{
525 QString store = mRelatedToUid;
526 setRelatedTo( 0 );
527 mRelatedToUid = store;
528}
523 529
524void Incidence::setRelatedTo(Incidence *relatedTo) 530void Incidence::setRelatedTo(Incidence *relatedTo)
525{ 531{
526 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 532 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
527 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 533 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
528 if (mReadOnly || mRelatedTo == relatedTo) return; 534 if (mReadOnly || mRelatedTo == relatedTo) return;
529 if(mRelatedTo) { 535 if(mRelatedTo) {
530 // updated(); 536 // updated();
531 mRelatedTo->removeRelation(this); 537 mRelatedTo->removeRelation(this);
532 } 538 }
533 mRelatedTo = relatedTo; 539 mRelatedTo = relatedTo;
534 if (mRelatedTo) { 540 if (mRelatedTo) {
535 mRelatedTo->addRelation(this); 541 mRelatedTo->addRelation(this);
536 mRelatedToUid = mRelatedTo->uid(); 542 mRelatedToUid = mRelatedTo->uid();
537 } else { 543 } else {
538 mRelatedToUid = ""; 544 mRelatedToUid = "";
539 } 545 }
540} 546}
541 547
542Incidence *Incidence::relatedTo() const 548Incidence *Incidence::relatedTo() const
543{ 549{
544 return mRelatedTo; 550 return mRelatedTo;
545} 551}
546 552
547QPtrList<Incidence> Incidence::relations() const 553QPtrList<Incidence> Incidence::relations() const
548{ 554{
549 return mRelations; 555 return mRelations;
550} 556}
551 557
552void Incidence::addRelationsToList(QPtrList<Incidence> *rel) 558void Incidence::addRelationsToList(QPtrList<Incidence> *rel)
553{ 559{
554 Incidence* inc; 560 Incidence* inc;
555 QPtrList<Incidence> Relations = relations(); 561 QPtrList<Incidence> Relations = relations();
556 for (inc=Relations.first();inc;inc=Relations.next()) { 562 for (inc=Relations.first();inc;inc=Relations.next()) {
557 inc->addRelationsToList( rel ); 563 inc->addRelationsToList( rel );
558 } 564 }
559 if ( rel->findRef( this ) == -1 ) 565 if ( rel->findRef( this ) == -1 )
560 rel->append( this ); 566 rel->append( this );
561} 567}
562 568
563void Incidence::addRelation(Incidence *event) 569void Incidence::addRelation(Incidence *event)
564{ 570{
565 setLastModifiedSubInvalid(); 571 setLastModifiedSubInvalid();
566 if( mRelations.findRef( event ) == -1 ) { 572 if( mRelations.findRef( event ) == -1 ) {
567 mRelations.append(event); 573 mRelations.append(event);
568 //updated(); 574 //updated();
569 } 575 }
570} 576}
571 577
572void Incidence::removeRelation(Incidence *event) 578void Incidence::removeRelation(Incidence *event)
573{ 579{
574 setLastModifiedSubInvalid(); 580 setLastModifiedSubInvalid();
575 mRelations.removeRef(event); 581 mRelations.removeRef(event);
576// if (event->getRelatedTo() == this) event->setRelatedTo(0); 582// if (event->getRelatedTo() == this) event->setRelatedTo(0);
577} 583}
578 584
579bool Incidence::recursOn(const QDate &qd) const 585bool Incidence::recursOn(const QDate &qd) const
580{ 586{
581 if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true; 587 if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true;
582 else return false; 588 else return false;
583} 589}
584 590
585void Incidence::setExDates(const DateList &exDates) 591void Incidence::setExDates(const DateList &exDates)
586{ 592{
587 if (mReadOnly) return; 593 if (mReadOnly) return;
588 mExDates = exDates; 594 mExDates = exDates;
589 recurrence()->setRecurExDatesCount(mExDates.count()); 595 recurrence()->setRecurExDatesCount(mExDates.count());
590 596
591 updated(); 597 updated();
592} 598}
593 599
594void Incidence::addExDate(const QDate &date) 600void Incidence::addExDate(const QDate &date)
595{ 601{
596 if (mReadOnly) return; 602 if (mReadOnly) return;
597 mExDates.append(date); 603 mExDates.append(date);
598 604
599 recurrence()->setRecurExDatesCount(mExDates.count()); 605 recurrence()->setRecurExDatesCount(mExDates.count());
600 606
601 updated(); 607 updated();
602} 608}
603 609
604DateList Incidence::exDates() const 610DateList Incidence::exDates() const
605{ 611{
606 return mExDates; 612 return mExDates;
607} 613}
608 614
609bool Incidence::isException(const QDate &date) const 615bool Incidence::isException(const QDate &date) const
610{ 616{
611 DateList::ConstIterator it; 617 DateList::ConstIterator it;
612 for( it = mExDates.begin(); it != mExDates.end(); ++it ) { 618 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
613 if ( (*it) == date ) { 619 if ( (*it) == date ) {
614 return true; 620 return true;
615 } 621 }
616 } 622 }
617 623
618 return false; 624 return false;
diff --git a/libkcal/incidence.h b/libkcal/incidence.h
index dc49640..f89942f 100644
--- a/libkcal/incidence.h
+++ b/libkcal/incidence.h
@@ -80,192 +80,193 @@ class Incidence : public IncidenceBase
80 80
81 /** 81 /**
82 This class implements a visitor for adding an Incidence to a resource 82 This class implements a visitor for adding an Incidence to a resource
83 supporting addEvent(), addTodo() and addJournal() calls. 83 supporting addEvent(), addTodo() and addJournal() calls.
84 */ 84 */
85 template<class T> 85 template<class T>
86 class AddVisitor : public Visitor 86 class AddVisitor : public Visitor
87 { 87 {
88 public: 88 public:
89 AddVisitor( T *r ) : mResource( r ) {} 89 AddVisitor( T *r ) : mResource( r ) {}
90 bool visit( Event *e ) { return mResource->addEvent( e ); } 90 bool visit( Event *e ) { return mResource->addEvent( e ); }
91 bool visit( Todo *t ) { return mResource->addTodo( t ); } 91 bool visit( Todo *t ) { return mResource->addTodo( t ); }
92 bool visit( Journal *j ) { return mResource->addJournal( j ); } 92 bool visit( Journal *j ) { return mResource->addJournal( j ); }
93 93
94 private: 94 private:
95 T *mResource; 95 T *mResource;
96 }; 96 };
97 97
98 /** enumeration for describing an event's secrecy. */ 98 /** enumeration for describing an event's secrecy. */
99 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; 99 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 };
100 typedef ListBase<Incidence> List; 100 typedef ListBase<Incidence> List;
101 Incidence(); 101 Incidence();
102 Incidence(const Incidence &); 102 Incidence(const Incidence &);
103 ~Incidence(); 103 ~Incidence();
104 104
105 /** 105 /**
106 Accept IncidenceVisitor. A class taking part in the visitor mechanism has to 106 Accept IncidenceVisitor. A class taking part in the visitor mechanism has to
107 provide this implementation: 107 provide this implementation:
108 <pre> 108 <pre>
109 bool accept(Visitor &v) { return v.visit(this); } 109 bool accept(Visitor &v) { return v.visit(this); }
110 </pre> 110 </pre>
111 */ 111 */
112 virtual bool accept(Visitor &) { return false; } 112 virtual bool accept(Visitor &) { return false; }
113 113
114 virtual Incidence *clone() = 0; 114 virtual Incidence *clone() = 0;
115 virtual void cloneRelations( Incidence * ); 115 virtual void cloneRelations( Incidence * );
116 void addRelationsToList(QPtrList<Incidence> *rel); 116 void addRelationsToList(QPtrList<Incidence> *rel);
117 void clearRelations(); 117 void clearRelations();
118 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; 118 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0;
119 void setReadOnly( bool ); 119 void setReadOnly( bool );
120 120
121 /** 121 /**
122 Recreate event. The event is made a new unique event, but already stored 122 Recreate event. The event is made a new unique event, but already stored
123 event information is preserved. Sets uniquie id, creation date, last 123 event information is preserved. Sets uniquie id, creation date, last
124 modification date and revision number. 124 modification date and revision number.
125 */ 125 */
126 void recreate(); 126 void recreate();
127 Incidence* recreateCloneException(QDate); 127 Incidence* recreateCloneException(QDate);
128 128
129 /** set creation date */ 129 /** set creation date */
130 void setCreated(QDateTime); 130 void setCreated(QDateTime);
131 /** return time and date of creation. */ 131 /** return time and date of creation. */
132 QDateTime created() const; 132 QDateTime created() const;
133 133
134 /** set the number of revisions this event has seen */ 134 /** set the number of revisions this event has seen */
135 void setRevision(int rev); 135 void setRevision(int rev);
136 /** return the number of revisions this event has seen */ 136 /** return the number of revisions this event has seen */
137 int revision() const; 137 int revision() const;
138 138
139 /** Set starting date/time. */ 139 /** Set starting date/time. */
140 virtual void setDtStart(const QDateTime &dtStart); 140 virtual void setDtStart(const QDateTime &dtStart);
141 /** Return the incidence's ending date/time as a QDateTime. */ 141 /** Return the incidence's ending date/time as a QDateTime. */
142 virtual QDateTime dtEnd() const { return QDateTime(); } 142 virtual QDateTime dtEnd() const { return QDateTime(); }
143 143
144 /** sets the event's lengthy description. */ 144 /** sets the event's lengthy description. */
145 void setDescription(const QString &description); 145 void setDescription(const QString &description);
146 /** returns a reference to the event's description. */ 146 /** returns a reference to the event's description. */
147 QString description() const; 147 QString description() const;
148 148
149 /** sets the event's short summary. */ 149 /** sets the event's short summary. */
150 void setSummary(const QString &summary); 150 void setSummary(const QString &summary);
151 /** returns a reference to the event's summary. */ 151 /** returns a reference to the event's summary. */
152 QString summary() const; 152 QString summary() const;
153 153
154 /** set event's applicable categories */ 154 /** set event's applicable categories */
155 void setCategories(const QStringList &categories, bool setForRelations = false); 155 void setCategories(const QStringList &categories, bool setForRelations = false);
156 void addCategories(const QStringList &categories, bool addToRelations = false); 156 void addCategories(const QStringList &categories, bool addToRelations = false);
157 /** set event's categories based on a comma delimited string */ 157 /** set event's categories based on a comma delimited string */
158 void setCategories(const QString &catStr); 158 void setCategories(const QString &catStr);
159 /** return categories in a list */ 159 /** return categories in a list */
160 QStringList categories() const; 160 QStringList categories() const;
161 QStringList* categoriesP(); 161 QStringList* categoriesP();
162 /** return categories as a comma separated string */ 162 /** return categories as a comma separated string */
163 QString categoriesStr(); 163 QString categoriesStr();
164 QString categoriesStrWithSpace(); 164 QString categoriesStrWithSpace();
165 165
166 /** point at some other event to which the event relates. This function should 166 /** point at some other event to which the event relates. This function should
167 * only be used when constructing a calendar before the related Event 167 * only be used when constructing a calendar before the related Event
168 * exists. */ 168 * exists. */
169 void setRelatedToUid(const QString &); 169 void setRelatedToUid(const QString &);
170 /** what event does this one relate to? This function should 170 /** what event does this one relate to? This function should
171 * only be used when constructing a calendar before the related Event 171 * only be used when constructing a calendar before the related Event
172 * exists. */ 172 * exists. */
173 QString relatedToUid() const; 173 QString relatedToUid() const;
174 /** point at some other event to which the event relates */ 174 /** point at some other event to which the event relates */
175 void setRelatedTo(Incidence *relatedTo); 175 void setRelatedTo(Incidence *relatedTo);
176 void resetRelatedTo();
176 /** what event does this one relate to? */ 177 /** what event does this one relate to? */
177 Incidence *relatedTo() const; 178 Incidence *relatedTo() const;
178 /** All events that are related to this event */ 179 /** All events that are related to this event */
179 QPtrList<Incidence> relations() const; 180 QPtrList<Incidence> relations() const;
180 /** Add an event which is related to this event */ 181 /** Add an event which is related to this event */
181 void addRelation(Incidence *); 182 void addRelation(Incidence *);
182 /** Remove event that is related to this event */ 183 /** Remove event that is related to this event */
183 void removeRelation(Incidence *); 184 void removeRelation(Incidence *);
184 185
185 /** returns the list of dates which are exceptions to the recurrence rule */ 186 /** returns the list of dates which are exceptions to the recurrence rule */
186 DateList exDates() const; 187 DateList exDates() const;
187 /** sets the list of dates which are exceptions to the recurrence rule */ 188 /** sets the list of dates which are exceptions to the recurrence rule */
188 void setExDates(const DateList &_exDates); 189 void setExDates(const DateList &_exDates);
189 void setExDates(const char *dates); 190 void setExDates(const char *dates);
190 /** Add a date to the list of exceptions of the recurrence rule. */ 191 /** Add a date to the list of exceptions of the recurrence rule. */
191 void addExDate(const QDate &date); 192 void addExDate(const QDate &date);
192 193
193 /** returns true if there is an exception for this date in the recurrence 194 /** returns true if there is an exception for this date in the recurrence
194 rule set, or false otherwise. */ 195 rule set, or false otherwise. */
195 bool isException(const QDate &qd) const; 196 bool isException(const QDate &qd) const;
196 197
197 /** add attachment to this event */ 198 /** add attachment to this event */
198 void addAttachment(Attachment *attachment); 199 void addAttachment(Attachment *attachment);
199 /** remove and delete a specific attachment */ 200 /** remove and delete a specific attachment */
200 void deleteAttachment(Attachment *attachment); 201 void deleteAttachment(Attachment *attachment);
201 /** remove and delete all attachments with this mime type */ 202 /** remove and delete all attachments with this mime type */
202 void deleteAttachments(const QString& mime); 203 void deleteAttachments(const QString& mime);
203 /** return list of all associated attachments */ 204 /** return list of all associated attachments */
204 QPtrList<Attachment> attachments() const; 205 QPtrList<Attachment> attachments() const;
205 /** find a list of attachments with this mime type */ 206 /** find a list of attachments with this mime type */
206 QPtrList<Attachment> attachments(const QString& mime) const; 207 QPtrList<Attachment> attachments(const QString& mime) const;
207 208
208 /** sets the event's status the value specified. See the enumeration 209 /** sets the event's status the value specified. See the enumeration
209 * above for possible values. */ 210 * above for possible values. */
210 void setSecrecy(int); 211 void setSecrecy(int);
211 /** return the event's secrecy. */ 212 /** return the event's secrecy. */
212 int secrecy() const; 213 int secrecy() const;
213 /** return the event's secrecy in string format. */ 214 /** return the event's secrecy in string format. */
214 QString secrecyStr() const; 215 QString secrecyStr() const;
215 /** return list of all availbale secrecy classes */ 216 /** return list of all availbale secrecy classes */
216 static QStringList secrecyList(); 217 static QStringList secrecyList();
217 /** return human-readable name of secrecy class */ 218 /** return human-readable name of secrecy class */
218 static QString secrecyName(int); 219 static QString secrecyName(int);
219 220
220 /** returns TRUE if the date specified is one on which the event will 221 /** returns TRUE if the date specified is one on which the event will
221 * recur. */ 222 * recur. */
222 bool recursOn(const QDate &qd) const; 223 bool recursOn(const QDate &qd) const;
223 224
224 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): 225 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?):
225 226
226 /** set resources used, such as Office, Car, etc. */ 227 /** set resources used, such as Office, Car, etc. */
227 void setResources(const QStringList &resources); 228 void setResources(const QStringList &resources);
228 /** return list of current resources */ 229 /** return list of current resources */
229 QStringList resources() const; 230 QStringList resources() const;
230 231
231 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ 232 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */
232 void setPriority(int priority); 233 void setPriority(int priority);
233 /** get the event's priority */ 234 /** get the event's priority */
234 int priority() const; 235 int priority() const;
235 236
236 /** All alarms that are associated with this incidence */ 237 /** All alarms that are associated with this incidence */
237 QPtrList<Alarm> alarms() const; 238 QPtrList<Alarm> alarms() const;
238 /** Create a new alarm which is associated with this incidence */ 239 /** Create a new alarm which is associated with this incidence */
239 Alarm* newAlarm(); 240 Alarm* newAlarm();
240 /** Add an alarm which is associated with this incidence */ 241 /** Add an alarm which is associated with this incidence */
241 void addAlarm(Alarm*); 242 void addAlarm(Alarm*);
242 /** Remove an alarm that is associated with this incidence */ 243 /** Remove an alarm that is associated with this incidence */
243 void removeAlarm(Alarm*); 244 void removeAlarm(Alarm*);
244 /** Remove all alarms that are associated with this incidence */ 245 /** Remove all alarms that are associated with this incidence */
245 void clearAlarms(); 246 void clearAlarms();
246 /** return whether any alarm associated with this incidence is enabled */ 247 /** return whether any alarm associated with this incidence is enabled */
247 bool isAlarmEnabled() const; 248 bool isAlarmEnabled() const;
248 249
249 /** 250 /**
250 Return the recurrence rule associated with this incidence. If there is 251 Return the recurrence rule associated with this incidence. If there is
251 none, returns an appropriate (non-0) object. 252 none, returns an appropriate (non-0) object.
252 */ 253 */
253 Recurrence *recurrence(); 254 Recurrence *recurrence();
254 void setRecurrence(Recurrence * r); 255 void setRecurrence(Recurrence * r);
255 /** 256 /**
256 Forward to Recurrence::doesRecur(). 257 Forward to Recurrence::doesRecur().
257 */ 258 */
258 ushort doesRecur() const; 259 ushort doesRecur() const;
259 260
260 /** set the event's/todo's location. Do _not_ use it with journal */ 261 /** set the event's/todo's location. Do _not_ use it with journal */
261 void setLocation(const QString &location); 262 void setLocation(const QString &location);
262 /** return the event's/todo's location. Do _not_ use it with journal */ 263 /** return the event's/todo's location. Do _not_ use it with journal */
263 QString location() const; 264 QString location() const;
264 /** returns TRUE or FALSE depending on whether the todo has a start date */ 265 /** returns TRUE or FALSE depending on whether the todo has a start date */
265 bool hasStartDate() const; 266 bool hasStartDate() const;
266 /** sets the event's hasStartDate value. */ 267 /** sets the event's hasStartDate value. */
267 void setHasStartDate(bool f); 268 void setHasStartDate(bool f);
268 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; 269 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const;
269 bool cancelled() const; 270 bool cancelled() const;
270 void setCancelled( bool b ); 271 void setCancelled( bool b );
271 272