author | zautrix <zautrix> | 2005-11-28 03:27:16 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-11-28 03:27:16 (UTC) |
commit | b7522a13b64225bb91bdab4a21b44282f8c3e3b4 (patch) (unidiff) | |
tree | 3aa005036dd83f3d0e5f57dd398dc260666daea1 /korganizer | |
parent | 084180efc1bccba341bf3f2f718fd10cdfdaf18e (diff) | |
download | kdepimpi-b7522a13b64225bb91bdab4a21b44282f8c3e3b4.zip kdepimpi-b7522a13b64225bb91bdab4a21b44282f8c3e3b4.tar.gz kdepimpi-b7522a13b64225bb91bdab4a21b44282f8c3e3b4.tar.bz2 |
sync
-rw-r--r-- | korganizer/calendarview.cpp | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 1800cf2..8385bcc 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -1702,113 +1702,119 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int | |||
1702 | filter = mFilters.next(); | 1702 | filter = mFilters.next(); |
1703 | } | 1703 | } |
1704 | int w = 300; | 1704 | int w = 300; |
1705 | if ( QApplication::desktop()->width() < 320 ) | 1705 | if ( QApplication::desktop()->width() < 320 ) |
1706 | w = 220; | 1706 | w = 220; |
1707 | int h = bar.sizeHint().height() ; | 1707 | int h = bar.sizeHint().height() ; |
1708 | int dw = QApplication::desktop()->width(); | 1708 | int dw = QApplication::desktop()->width(); |
1709 | int dh = QApplication::desktop()->height(); | 1709 | int dh = QApplication::desktop()->height(); |
1710 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1710 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1711 | bar.show(); | 1711 | bar.show(); |
1712 | int modulo = (er.count()/10)+1; | 1712 | int modulo = (er.count()/10)+1; |
1713 | int incCounter = 0; | 1713 | int incCounter = 0; |
1714 | while ( inR ) { | 1714 | while ( inR ) { |
1715 | if ( ! bar.isVisible() ) | 1715 | if ( ! bar.isVisible() ) |
1716 | return false; | 1716 | return false; |
1717 | if ( incCounter % modulo == 0 ) | 1717 | if ( incCounter % modulo == 0 ) |
1718 | bar.setProgress( incCounter ); | 1718 | bar.setProgress( incCounter ); |
1719 | ++incCounter; | 1719 | ++incCounter; |
1720 | uid = inR->uid(); | 1720 | uid = inR->uid(); |
1721 | bool skipIncidence = false; | 1721 | bool skipIncidence = false; |
1722 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1722 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1723 | skipIncidence = true; | 1723 | skipIncidence = true; |
1724 | QString idS; | 1724 | QString idS; |
1725 | qApp->processEvents(); | 1725 | qApp->processEvents(); |
1726 | if ( !skipIncidence ) { | 1726 | if ( !skipIncidence ) { |
1727 | int hasCalId = 0; | 1727 | int hasCalId = 0; |
1728 | inL = local->incidenceForUid( uid , false , true, &hasCalId ); | 1728 | inL = local->incidenceForUid( uid , false , true, &hasCalId ); |
1729 | if ( hasCalId && !inL ) | 1729 | if ( hasCalId && !inL ) |
1730 | inL = local->incidenceForUid( uid , false , true, &hasCalId ); | 1730 | inL = local->incidenceForUid( uid , false , true, &hasCalId ); |
1731 | else | 1731 | else |
1732 | hasCalId = 0; | 1732 | hasCalId = 0; |
1733 | if ( inL ) { // maybe conflict - same uid in both calendars | 1733 | if ( inL ) { // maybe conflict - same uid in both calendars |
1734 | if ( hasCalId ) | 1734 | |
1735 | qDebug("KO: Cal id %d conflict detected: %s ", hasCalId, inL->summary().latin1()); | ||
1736 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1735 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1737 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1736 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1738 | if ( take == 3 ) | 1737 | if ( take == 3 ) |
1739 | return false; | 1738 | return false; |
1740 | if ( take == 1 ) {// take local ********************** | 1739 | if ( take == 1 ) {// take local ********************** |
1741 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 1740 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
1742 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1741 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1743 | else | 1742 | else |
1744 | idS = inR->IDStr(); | 1743 | idS = inR->IDStr(); |
1745 | int calID = inR->calID(); | 1744 | int calID = inR->calID(); |
1746 | remote->deleteIncidence( inR ); | 1745 | remote->deleteIncidence( inR ); |
1747 | inR = inL->clone(); | 1746 | if ( !hasCalId ) { |
1748 | inR->setCalID_block( calID ); | 1747 | inR = inL->clone(); |
1749 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1748 | inR->setCalID_block( calID ); |
1750 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | 1749 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1751 | inR->setIDStr( idS ); | 1750 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) |
1752 | remote->addIncidence( inR ); | 1751 | inR->setIDStr( idS ); |
1753 | if ( mSyncManager->syncWithDesktop() ) | 1752 | remote->addIncidence( inR ); |
1754 | inR->setPilotId( 2 ); | 1753 | if ( mSyncManager->syncWithDesktop() ) |
1755 | ++changedRemote; | 1754 | inR->setPilotId( 2 ); |
1755 | ++changedRemote; | ||
1756 | } else | ||
1757 | ++deletedEventR; | ||
1756 | } else {// take remote ********************** | 1758 | } else {// take remote ********************** |
1757 | if ( !inL->isReadOnly() ) { | 1759 | if ( !inL->isReadOnly() ) { |
1758 | idS = inL->IDStr(); | 1760 | idS = inL->IDStr(); |
1759 | int pid = inL->pilotId(); | 1761 | int pid = inL->pilotId(); |
1760 | int calID = inL->calID(); | 1762 | int calID = inL->calID(); |
1761 | if ( hasCalId ) | 1763 | if ( hasCalId ) |
1762 | calID = hasCalId; | 1764 | calID = 0;// add to default calendar |
1763 | local->deleteIncidence( inL ); | 1765 | local->deleteIncidence( inL ); |
1764 | inL = inR->clone(); | 1766 | inL = inR->clone(); |
1765 | inL->setCalID_block( calID ); | 1767 | inL->setCalID_block( calID ); |
1766 | if ( mSyncManager->syncWithDesktop() ) | 1768 | if ( mSyncManager->syncWithDesktop() ) |
1767 | inL->setPilotId( pid ); | 1769 | inL->setPilotId( pid ); |
1768 | inL->setIDStr( idS ); | 1770 | inL->setIDStr( idS ); |
1769 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1771 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1770 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1772 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1771 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1773 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1772 | } | 1774 | } |
1773 | local->addIncidence( inL ); | 1775 | local->addIncidence( inL ); |
1774 | ++changedLocal; | 1776 | ++changedLocal; |
1775 | } | 1777 | } |
1776 | } | 1778 | } |
1777 | } else { | 1779 | } else { |
1778 | // take == 0; events equal | 1780 | // take == 0; events equal |
1779 | if ( hasCalId ) | 1781 | if ( hasCalId ) { |
1780 | qDebug("EV EQUALLLL **************************** "); | 1782 | qDebug("KO: Changing Cal id %d to %d for : %s ", hasCalId, local->defaultCalendar(),inL->summary().latin1()); |
1783 | inL->setCalID( local->defaultCalendar() ); | ||
1784 | } | ||
1781 | 1785 | ||
1782 | } | 1786 | } |
1787 | |||
1788 | |||
1783 | } else { // no conflict ********** add or delete remote | 1789 | } else { // no conflict ********** add or delete remote |
1784 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ | 1790 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ |
1785 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1791 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1786 | QString des = eventLSync->description(); | 1792 | QString des = eventLSync->description(); |
1787 | QString pref = "e"; | 1793 | QString pref = "e"; |
1788 | if ( inR->typeID() == todoID ) | 1794 | if ( inR->typeID() == todoID ) |
1789 | pref = "t"; | 1795 | pref = "t"; |
1790 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1796 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1791 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1797 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1792 | //remote->deleteIncidence( inR ); | 1798 | //remote->deleteIncidence( inR ); |
1793 | ++deletedEventR; | 1799 | ++deletedEventR; |
1794 | } else { | 1800 | } else { |
1795 | inR->setLastModified( modifiedCalendar ); | 1801 | inR->setLastModified( modifiedCalendar ); |
1796 | inL = inR->clone(); | 1802 | inL = inR->clone(); |
1797 | inL->setIDStr( ":" ); | 1803 | inL->setIDStr( ":" ); |
1798 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1804 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1799 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1805 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1800 | 1806 | ||
1801 | inL->setCalID_block( 0 );// add to default cal | 1807 | inL->setCalID_block( 0 );// add to default cal |
1802 | local->addIncidence( inL ); | 1808 | local->addIncidence( inL ); |
1803 | ++addedEvent; | 1809 | ++addedEvent; |
1804 | 1810 | ||
1805 | } | 1811 | } |
1806 | } else { | 1812 | } else { |
1807 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1813 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1808 | inR->setLastModified( modifiedCalendar ); | 1814 | inR->setLastModified( modifiedCalendar ); |
1809 | inL = inR->clone(); | 1815 | inL = inR->clone(); |
1810 | inL->setIDStr( ":" ); | 1816 | inL->setIDStr( ":" ); |
1811 | inL->setCalID_block( 0 );// add to default cal | 1817 | inL->setCalID_block( 0 );// add to default cal |
1812 | local->addIncidence( inL ); | 1818 | local->addIncidence( inL ); |
1813 | ++addedEvent; | 1819 | ++addedEvent; |
1814 | 1820 | ||
@@ -2453,74 +2459,70 @@ bool CalendarView::openCalendar(QString filename, bool merge) | |||
2453 | setSyncEventsReadOnly(); | 2459 | setSyncEventsReadOnly(); |
2454 | updateUnmanagedViews(); | 2460 | updateUnmanagedViews(); |
2455 | updateView(); | 2461 | updateView(); |
2456 | } | 2462 | } |
2457 | return false; | 2463 | return false; |
2458 | } | 2464 | } |
2459 | void CalendarView::mergeFile( QString fn ) | 2465 | void CalendarView::mergeFile( QString fn ) |
2460 | { | 2466 | { |
2461 | clearAllViews(); | 2467 | clearAllViews(); |
2462 | mCalendar->mergeCalendarFile( fn ); | 2468 | mCalendar->mergeCalendarFile( fn ); |
2463 | mCalendar->reInitAlarmSettings(); | 2469 | mCalendar->reInitAlarmSettings(); |
2464 | setSyncEventsReadOnly(); | 2470 | setSyncEventsReadOnly(); |
2465 | updateUnmanagedViews(); | 2471 | updateUnmanagedViews(); |
2466 | updateView(); | 2472 | updateView(); |
2467 | } | 2473 | } |
2468 | void CalendarView::mergeFileResource( QString fn ,QString resource ) | 2474 | void CalendarView::mergeFileResource( QString fn ,QString resource ) |
2469 | { | 2475 | { |
2470 | 2476 | ||
2471 | if ( resource == "ALL" ) { | 2477 | if ( resource == "ALL" ) { |
2472 | mCalendar->setAllCalendarEnabled( true ); | 2478 | mCalendar->setAllCalendarEnabled( true ); |
2473 | mergeFile( fn ); | 2479 | mergeFile( fn ); |
2474 | restoreCalendarSettings(); | 2480 | restoreCalendarSettings(); |
2475 | return; | 2481 | return; |
2476 | } | 2482 | } |
2477 | 2483 | ||
2478 | int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); | 2484 | int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); |
2479 | if ( !exclusiveResource ) { | 2485 | if ( !exclusiveResource ) { |
2480 | qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() ); | 2486 | qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() ); |
2481 | return; | 2487 | return; |
2482 | } | 2488 | } |
2483 | clearAllViews(); | 2489 | clearAllViews(); |
2484 | mCalendar->setCalendarRemove( exclusiveResource ); | 2490 | mCalendar->setCalendarRemove( exclusiveResource ); |
2485 | int def = mCalendar->defaultCalendar(); | ||
2486 | mCalendar->setDefaultCalendar(exclusiveResource); | 2491 | mCalendar->setDefaultCalendar(exclusiveResource); |
2492 | mCalendar->setAllCalendarEnabled( true ); | ||
2487 | if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) { | 2493 | if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) { |
2488 | qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() ); | 2494 | qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() ); |
2489 | } | 2495 | } |
2490 | mCalendar->setDefaultCalendar( def ); | 2496 | restoreCalendarSettings(); |
2491 | mCalendar->reInitAlarmSettings(); | ||
2492 | setSyncEventsReadOnly(); | ||
2493 | updateUnmanagedViews(); | ||
2494 | updateView(); | ||
2495 | } | 2497 | } |
2496 | void CalendarView::showOpenError() | 2498 | void CalendarView::showOpenError() |
2497 | { | 2499 | { |
2498 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); | 2500 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); |
2499 | } | 2501 | } |
2500 | void CalendarView::setLoadedFileVersion(QDateTime dt) | 2502 | void CalendarView::setLoadedFileVersion(QDateTime dt) |
2501 | { | 2503 | { |
2502 | loadedFileVersion = dt; | 2504 | loadedFileVersion = dt; |
2503 | } | 2505 | } |
2504 | bool CalendarView::checkFileChanged(QString fn) | 2506 | bool CalendarView::checkFileChanged(QString fn) |
2505 | { | 2507 | { |
2506 | QFileInfo finf ( fn ); | 2508 | QFileInfo finf ( fn ); |
2507 | if ( !finf.exists() ) | 2509 | if ( !finf.exists() ) |
2508 | return true; | 2510 | return true; |
2509 | QDateTime dt = finf.lastModified (); | 2511 | QDateTime dt = finf.lastModified (); |
2510 | if ( dt <= loadedFileVersion ) | 2512 | if ( dt <= loadedFileVersion ) |
2511 | return false; | 2513 | return false; |
2512 | return true; | 2514 | return true; |
2513 | 2515 | ||
2514 | } | 2516 | } |
2515 | void CalendarView::watchSavedFile() | 2517 | void CalendarView::watchSavedFile() |
2516 | { | 2518 | { |
2517 | QFileInfo finf ( MainWindow::defaultFileName()); | 2519 | QFileInfo finf ( MainWindow::defaultFileName()); |
2518 | if ( !finf.exists() ) | 2520 | if ( !finf.exists() ) |
2519 | return; | 2521 | return; |
2520 | QDateTime dt = finf.lastModified (); | 2522 | QDateTime dt = finf.lastModified (); |
2521 | if ( dt < loadedFileVersion ) { | 2523 | if ( dt < loadedFileVersion ) { |
2522 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); | 2524 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); |
2523 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); | 2525 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); |
2524 | return; | 2526 | return; |
2525 | } | 2527 | } |
2526 | loadedFileVersion = dt; | 2528 | loadedFileVersion = dt; |