author | zautrix <zautrix> | 2005-07-09 08:48:32 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-07-09 08:48:32 (UTC) |
commit | f731dd9fc5b3f14c44d4de26eb5370a79c63887c (patch) (side-by-side diff) | |
tree | e3d7b3929cc8819a5451bd04c9698bc0767e49b1 /korganizer/calendarview.cpp | |
parent | e27ad31c6016152449bbdaf4f9f387fa61183c37 (diff) | |
download | kdepimpi-f731dd9fc5b3f14c44d4de26eb5370a79c63887c.zip kdepimpi-f731dd9fc5b3f14c44d4de26eb5370a79c63887c.tar.gz kdepimpi-f731dd9fc5b3f14c44d4de26eb5370a79c63887c.tar.bz2 |
fixi
-rw-r--r-- | korganizer/calendarview.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 940ea91..ccacc52 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -1406,218 +1406,227 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int QProgressBar bar( er.count(),0 ); bar.setCaption (i18n("Syncing - close to abort!") ); // ************** setting up filter ************* CalFilter *filterIN = 0; CalFilter *filterOUT = 0; CalFilter *filter = mFilters.first(); while(filter) { if ( filter->name() == mSyncManager->mFilterInCal ) filterIN = filter; if ( filter->name() == mSyncManager->mFilterOutCal ) filterOUT = filter; 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 ) { inL = local->incidence( uid ); if ( inL ) { // maybe conflict - same uid in both calendars 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 ); inR = inL->clone(); + inR->setCalID( 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 {// take remote ********************** idS = inL->IDStr(); int pid = inL->pilotId(); + int calID = inL->calID(); local->deleteIncidence( inL ); inL = inR->clone(); + inL->setCalID( 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 { // 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( 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( 0 );// add to default cal local->addIncidence( inL ); ++addedEvent; } else { checkExternSyncEvent(eventRSyncSharp, inR); remote->deleteIncidence( inR ); ++deletedEventR; } } } else { ++filteredIN; } } } inR = er.next(); } QPtrList<Incidence> el = local->rawIncidences(); inL = el.first(); modulo = (el.count()/10)+1; bar.setCaption (i18n("Add / remove events") ); bar.setTotalSteps ( el.count() ) ; bar.show(); incCounter = 0; while ( inL ) { qApp->processEvents(); if ( ! bar.isVisible() ) return false; if ( incCounter % modulo == 0 ) bar.setProgress( incCounter ); ++incCounter; uid = inL->uid(); bool skipIncidence = false; if ( uid.left(15) == QString("last-syncEvent-") ) skipIncidence = true; if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) skipIncidence = true; if ( !skipIncidence ) { inR = remote->incidence( uid ); if ( ! inR ) { if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ // no conflict ********** add or delete local if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { checkExternSyncEvent(eventLSyncSharp, inL); local->deleteIncidence( inL ); ++deletedEventL; } else { if ( ! mSyncManager->mWriteBackExistingOnly ) { inL->removeID(mCurrentSyncDevice ); ++addedEventR; //qDebug("remote added Incidence %s ", inL->summary().latin1()); inL->setLastModified( modifiedCalendar ); inR = inL->clone(); inR->setIDStr( ":" ); inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); + inR->setCalID( 0 );// add to default cal remote->addIncidence( inR ); } } } else { if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { checkExternSyncEvent(eventLSyncSharp, inL); local->deleteIncidence( inL ); ++deletedEventL; } else { if ( ! mSyncManager->mWriteBackExistingOnly ) { ++addedEventR; inL->setLastModified( modifiedCalendar ); inR = inL->clone(); inR->setIDStr( ":" ); + inR->setCalID( 0 );// add to default cal remote->addIncidence( inR ); } } } } else { ++filteredOUT; } } } inL = el.next(); } int delFut = 0; int remRem = 0; if ( mSyncManager->mWriteBackInFuture ) { er = remote->rawIncidences(); remRem = er.count(); inR = er.first(); QDateTime dt; QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); while ( inR ) { if ( inR->typeID() == todoID ) { Todo * t = (Todo*)inR; if ( t->hasDueDate() ) dt = t->dtDue(); else dt = cur.addSecs( 62 ); } else if (inR->typeID() == eventID ) { bool ok; dt = inR->getNextOccurence( cur, &ok ); if ( !ok ) dt = cur.addSecs( -62 ); } else dt = inR->dtStart(); if ( dt < cur || dt > end ) { remote->deleteIncidence( inR ); ++delFut; } inR = er.next(); } } bar.hide(); mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); eventLSync->setReadOnly( false ); eventLSync->setDtStart( mLastCalendarSync ); eventRSync->setDtStart( mLastCalendarSync ); @@ -2098,96 +2107,105 @@ bool CalendarView::openCalendar(QString filename, bool merge) } mStorage->setFileName( filename ); if ( mStorage->load() ) { if ( merge ) ;//setModified( true ); else { //setModified( true ); mViewManager->setDocumentId( filename ); mDialogManager->setDocumentId( filename ); mTodoList->setDocumentId( filename ); } globalFlagBlockAgenda = 2; // if ( getLastSyncEvent() ) // getLastSyncEvent()->setReadOnly( true ); mCalendar->reInitAlarmSettings(); setSyncEventsReadOnly(); updateUnmanagedViews(); updateView(); if ( filename != MainWindow::defaultFileName() ) { saveCalendar( MainWindow::defaultFileName() ); } else { QFileInfo finf ( MainWindow::defaultFileName()); if ( finf.exists() ) { setLoadedFileVersion( finf.lastModified () ); } } return true; } else { // while failing to load, the calendar object could // have become partially populated. Clear it out. if ( !merge ) { mCalendar->close(); mViewManager->setDocumentId( filename ); mDialogManager->setDocumentId( filename ); mTodoList->setDocumentId( filename ); } //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); globalFlagBlockAgenda = 2; mCalendar->reInitAlarmSettings(); setSyncEventsReadOnly(); updateUnmanagedViews(); updateView(); } return false; } +void CalendarView::mergeFile( QString fn ) +{ + clearAllViews(); + mCalendar->mergeCalendarFile( fn ); + mCalendar->reInitAlarmSettings(); + setSyncEventsReadOnly(); + updateUnmanagedViews(); + updateView(); +} 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; } bool CalendarView::checkAllFileVersions() { QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; KopiCalendarFile * cal = calendars.first(); mCalendar->setDefaultCalendar( 1 ); mCalendar->setDefaultCalendarEnabledOnly(); if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { if ( !checkFileVersion(MainWindow::defaultFileName())) { restoreCalendarSettings(); return false; } } cal = calendars.next(); QDateTime storeTemp = loadedFileVersion; while ( cal ) { if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { @@ -3313,102 +3331,104 @@ void CalendarView::cloneIncidence(Incidence * orgInc ) mTodoEditor->editTodo( t ); if ( mTodoEditor->exec() ) { if ( cloneSub ) { orgInc->cloneRelations( t ); mCalendar->addIncidenceBranch( t ); updateView(); } else { mCalendar->addTodo( t ); updateView(); } } else { delete t; } } else if ( newInc->typeID() == eventID ) { Event* e = (Event*) newInc; showEventEditor(); mEventEditor->editEvent( e ); if ( mEventEditor->exec() ) { mCalendar->addEvent( e ); updateView(); } else { delete e; } } if ( newInc->typeID() == journalID ) { mCalendar->addJournal( (Journal*) newInc ); editJournal( (Journal*) newInc ); } setActiveWindow(); } void CalendarView::newEvent() { // TODO: Replace this code by a common eventDurationHint of KOBaseView. KOAgendaView *aView = mViewManager->agendaView(); if (aView) { if (aView->selectionStart().isValid()) { if (aView->selectedIsAllDay()) { newEvent(aView->selectionStart(),aView->selectionEnd(),true); } else { newEvent(aView->selectionStart(),aView->selectionEnd()); } return; } } QDate date = mNavigator->selectedDates().first(); +#if 0 QDateTime current = QDateTime::currentDateTime(); if ( date <= current.date() ) { int hour = current.time().hour() +1; newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); } else +#endif newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), QDateTime( date, QTime( KOPrefs::instance()->mStartTime + KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); } void CalendarView::newEvent(QDateTime fh) { newEvent(fh, QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); } void CalendarView::newEvent(QDate dt) { newEvent(QDateTime(dt, QTime(0,0,0)), QDateTime(dt, QTime(0,0,0)), true); } void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) { newEvent(fromHint, toHint, false); } void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) { showEventEditor(); mEventEditor->newEvent(fromHint,toHint,allDay); if ( mFilterView->filtersEnabled() ) { CalFilter *filter = mFilterView->selectedFilter(); if (filter && filter->showCategories()) { mEventEditor->setCategories(filter->categoryList().join(",") ); } if ( filter ) mEventEditor->setSecrecy( filter->getSecrecy() ); } mEventEditor->exec(); setActiveWindow(); } void CalendarView::todoAdded(Todo * t) { changeTodoDisplay ( t ,KOGlobals::EVENTADDED); updateTodoViews(); } void CalendarView::todoChanged(Todo * t) { emit todoModified( t, 4 ); // updateTodoViews(); } void CalendarView::todoToBeDeleted(Todo *) |