author | zautrix <zautrix> | 2005-11-28 03:27:16 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-11-28 03:27:16 (UTC) |
commit | b7522a13b64225bb91bdab4a21b44282f8c3e3b4 (patch) (side-by-side diff) | |
tree | 3aa005036dd83f3d0e5f57dd398dc260666daea1 | |
parent | 084180efc1bccba341bf3f2f718fd10cdfdaf18e (diff) | |
download | kdepimpi-b7522a13b64225bb91bdab4a21b44282f8c3e3b4.zip kdepimpi-b7522a13b64225bb91bdab4a21b44282f8c3e3b4.tar.gz kdepimpi-b7522a13b64225bb91bdab4a21b44282f8c3e3b4.tar.bz2 |
sync
-rw-r--r-- | korganizer/calendarview.cpp | 24 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 23 |
2 files changed, 29 insertions, 18 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 filter = mFilters.next(); } int w = 300; if ( QApplication::desktop()->width() < 320 ) w = 220; int h = bar.sizeHint().height() ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); bar.show(); int modulo = (er.count()/10)+1; int incCounter = 0; while ( inR ) { if ( ! bar.isVisible() ) return false; if ( incCounter % modulo == 0 ) bar.setProgress( incCounter ); ++incCounter; uid = inR->uid(); bool skipIncidence = false; if ( uid.left(15) == QString("last-syncEvent-") ) skipIncidence = true; QString idS; qApp->processEvents(); if ( !skipIncidence ) { int hasCalId = 0; inL = local->incidenceForUid( uid , false , true, &hasCalId ); if ( hasCalId && !inL ) inL = local->incidenceForUid( uid , false , true, &hasCalId ); else hasCalId = 0; if ( inL ) { // maybe conflict - same uid in both calendars - if ( hasCalId ) - qDebug("KO: Cal id %d conflict detected: %s ", hasCalId, inL->summary().latin1()); + if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { //qDebug("take %d %s ", take, inL->summary().latin1()); if ( take == 3 ) return false; if ( take == 1 ) {// take local ********************** if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); else idS = inR->IDStr(); int calID = inR->calID(); remote->deleteIncidence( inR ); + if ( !hasCalId ) { inR = inL->clone(); inR->setCalID_block( calID ); inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) inR->setIDStr( idS ); remote->addIncidence( inR ); if ( mSyncManager->syncWithDesktop() ) inR->setPilotId( 2 ); ++changedRemote; + } else + ++deletedEventR; } else {// take remote ********************** if ( !inL->isReadOnly() ) { idS = inL->IDStr(); int pid = inL->pilotId(); int calID = inL->calID(); if ( hasCalId ) - calID = hasCalId; + calID = 0;// add to default calendar local->deleteIncidence( inL ); inL = inR->clone(); inL->setCalID_block( calID ); if ( mSyncManager->syncWithDesktop() ) inL->setPilotId( pid ); inL->setIDStr( idS ); if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); } local->addIncidence( inL ); ++changedLocal; } } } else { // take == 0; events equal - if ( hasCalId ) - qDebug("EV EQUALLLL **************************** "); + if ( hasCalId ) { + qDebug("KO: Changing Cal id %d to %d for : %s ", hasCalId, local->defaultCalendar(),inL->summary().latin1()); + inL->setCalID( local->defaultCalendar() ); + } } + + } else { // no conflict ********** add or delete remote if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { QString des = eventLSync->description(); QString pref = "e"; if ( inR->typeID() == todoID ) pref = "t"; if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); //remote->deleteIncidence( inR ); ++deletedEventR; } else { inR->setLastModified( modifiedCalendar ); inL = inR->clone(); inL->setIDStr( ":" ); inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); inL->setCalID_block( 0 );// add to default cal local->addIncidence( inL ); ++addedEvent; } } else { if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { inR->setLastModified( modifiedCalendar ); inL = inR->clone(); inL->setIDStr( ":" ); inL->setCalID_block( 0 );// add to default cal local->addIncidence( inL ); ++addedEvent; @@ -2453,74 +2459,70 @@ bool CalendarView::openCalendar(QString filename, bool merge) setSyncEventsReadOnly(); updateUnmanagedViews(); updateView(); } return false; } void CalendarView::mergeFile( QString fn ) { clearAllViews(); mCalendar->mergeCalendarFile( fn ); mCalendar->reInitAlarmSettings(); setSyncEventsReadOnly(); updateUnmanagedViews(); updateView(); } void CalendarView::mergeFileResource( QString fn ,QString resource ) { if ( resource == "ALL" ) { mCalendar->setAllCalendarEnabled( true ); mergeFile( fn ); restoreCalendarSettings(); return; } int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); if ( !exclusiveResource ) { qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() ); return; } clearAllViews(); mCalendar->setCalendarRemove( exclusiveResource ); - int def = mCalendar->defaultCalendar(); mCalendar->setDefaultCalendar(exclusiveResource); + mCalendar->setAllCalendarEnabled( true ); if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) { qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() ); } - mCalendar->setDefaultCalendar( def ); - mCalendar->reInitAlarmSettings(); - setSyncEventsReadOnly(); - updateUnmanagedViews(); - updateView(); + restoreCalendarSettings(); } void CalendarView::showOpenError() { KMessageBox::error(this,i18n("Couldn't load calendar\n.")); } void CalendarView::setLoadedFileVersion(QDateTime dt) { loadedFileVersion = dt; } bool CalendarView::checkFileChanged(QString fn) { QFileInfo finf ( fn ); if ( !finf.exists() ) return true; QDateTime dt = finf.lastModified (); if ( dt <= loadedFileVersion ) return false; return true; } void CalendarView::watchSavedFile() { QFileInfo finf ( MainWindow::defaultFileName()); if ( !finf.exists() ) return; QDateTime dt = finf.lastModified (); if ( dt < loadedFileVersion ) { //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); return; } loadedFileVersion = dt; diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 980663f..8a5a76f 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp @@ -230,112 +230,121 @@ bool CalendarLocal::addCalendarFile( QString name, int id ) if ( calendar.load( name ) ) { addCalendar( &calendar ); return true; } return false; } void CalendarLocal::setSyncEventsEnabled() { Event * ev; ev = mEventList.first(); while ( ev ) { if ( ev->uid().left(15) == QString("last-syncEvent-") ) ev->setCalEnabled( true ); ev = mEventList.next(); } } void CalendarLocal::setSyncEventsReadOnly() { Event * ev; ev = mEventList.first(); while ( ev ) { if ( ev->uid().left(15) == QString("last-syncEvent-") ) { ev->setReadOnly( true ); } ev = mEventList.next(); } } void CalendarLocal::addCalendar( Calendar* cal ) { cal->setDontDeleteIncidencesOnClose(); setSyncEventsEnabled(); + QPtrList<Incidence> incList; { QPtrList<Event> EventList = cal->rawEvents(); - QPtrList<Event> el; Event * ev = EventList.first(); while ( ev ) { if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { - Event * se = event( ev->uid() ); - if ( se ) - el.append( se ); ev->setCalID_block( 1 ); } + Event * se = event( ev->uid() ); + if ( se ) + incList.append( se ); ev->unRegisterObserver( cal ); ev->registerObserver( this ); mEventList.append( ev ); ev = EventList.next(); } - for ( ev = el.first(); ev; ev = el.next() ) { - deleteIncidence ( ev ); - } + } { QPtrList<Todo> TodoList = cal->rawTodos(); Todo * ev = TodoList.first(); while ( ev ) { ev->resetRelatedTo(); ev = TodoList.next(); } //TodoList = cal->rawTodos(); ev = TodoList.first(); while ( ev ) { + Todo * se = todo( ev->uid() ); + if ( se ) + incList.append( se ); ev->unRegisterObserver( cal ); ev->registerObserver( this ); mTodoList.append( ev ); setupRelations( ev ); ev = TodoList.next(); } } { QPtrList<Journal> JournalList = cal->journals(); Journal * ev = JournalList.first(); while ( ev ) { + Journal * se = journal( ev->uid() ); + if ( se ) + incList.append( se ); ev->unRegisterObserver( cal ); ev->registerObserver( this ); mJournalList.append( ev ); ev = JournalList.next(); } } + { + for (Incidence * ev = incList.first(); ev; ev = incList.next() ) { + deleteIncidence ( ev ); + } + } setModified( true ); } bool CalendarLocal::load( const QString &fileName ) { FileStorage storage( this, fileName ); return storage.load(); } bool CalendarLocal::save( const QString &fileName, CalFormat *format ) { FileStorage storage( this, fileName, format ); return storage.save(); } void CalendarLocal::stopAllTodos() { for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) it->setRunning( false ); } void CalendarLocal::close() { Todo * i; for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); mEventList.setAutoDelete( true ); mTodoList.setAutoDelete( true ); mJournalList.setAutoDelete( true ); mEventList.clear(); mTodoList.clear(); |