summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/calendarview.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 8d024c1..1800cf2 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1559,96 +1559,97 @@ Event* CalendarView::getLastSyncEvent()
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"));
@@ -1678,137 +1679,151 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
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();