-rw-r--r-- | korganizer/calendarview.cpp | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 6e60c56..b0be340 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -1858,53 +1858,56 @@ bool CalendarView::loadCalendars() setSyncEventsReadOnly(); updateUnmanagedViews(); updateView(); } bool CalendarView::restoreCalendarSettings() { QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; KopiCalendarFile * cal = calendars.first(); while ( cal ) { mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); if ( cal->isStandard ) mCalendar->setDefaultCalendar( cal->mCalNumber ); cal = calendars.next(); } } void CalendarView::addCalendarId( int id ) { KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); addCalendar( cal ); } bool CalendarView::addCalendar( KopiCalendarFile * cal ) { - - if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) + cal->mErrorOnLoad = false; + if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { + cal->mLoadDt = QDateTime::currentDateTime(); return true; + } qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() ); KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName)); + cal->mErrorOnLoad = true; return false; } bool CalendarView::openCalendar(QString filename, bool merge) { if (filename.isEmpty()) { return false; } if (!QFile::exists(filename)) { KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); return false; } globalFlagBlockAgenda = 1; clearAllViews(); if (!merge) { mViewManager->setDocumentId( filename ); mCalendar->close(); } mStorage->setFileName( filename ); if ( mStorage->load() ) { if ( merge ) ;//setModified( true ); @@ -1962,94 +1965,120 @@ void CalendarView::setLoadedFileVersion(QDateTime 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 ( !checkFileVersion(MainWindow::defaultFileName())) + return false; + cal = calendars.next(); + QDateTime storeTemp = loadedFileVersion; + while ( cal ) { + if ( !cal->mErrorOnLoad ) { + mCalendar->setDefaultCalendar( cal->mCalNumber ); + mCalendar->setDefaultCalendarEnabledOnly(); + loadedFileVersion = cal->mLoadDt.addSecs( 15 ); + if ( !checkFileVersion(cal->mFileName )) { + loadedFileVersion = storeTemp; + updateView(); + return false; + } + } + cal = calendars.next(); + } + loadedFileVersion = storeTemp; + updateView(); + return true; +} bool CalendarView::checkFileVersion(QString fn) { QFileInfo finf ( fn ); if ( !finf.exists() ) return true; QDateTime dt = finf.lastModified (); //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); //qDebug("file on disk version %s",dt.toString().latin1()); if ( dt <= loadedFileVersion ) return true; - int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , + int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , i18n("KO/Pi Warning"),i18n("Overwrite"), i18n("Sync+save")); if ( km == KMessageBox::Cancel ) return false; if ( km == KMessageBox::Yes ) return true; setSyncDevice("deleteaftersync" ); mSyncManager->mAskForPreferences = true; mSyncManager->mSyncAlgoPrefs = 3; mSyncManager->mWriteBackFile = false; mSyncManager->mWriteBackExistingOnly = false; mSyncManager->mShowSyncSummary = false; syncCalendar( fn, 3 ); Event * e = getLastSyncEvent(); if ( e ) - deleteEvent ( e ); - updateView(); + mCalendar->deleteEvent( e ); return true; } bool CalendarView::saveCalendars() { QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; KopiCalendarFile * cal = calendars.first(); mCalendar->setDefaultCalendar( 1 ); mCalendar->setDefaultCalendarEnabledOnly(); saveCalendar( MainWindow::defaultFileName() ); cal = calendars.next(); while ( cal ) { - if ( !cal->isReadOnly ) { + if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { mCalendar->setDefaultCalendar( cal->mCalNumber ); mCalendar->setDefaultCalendarEnabledOnly(); - saveCalendar( cal->mFileName ); + if ( saveCalendar( cal->mFileName ) ) + cal->mLoadDt = QDateTime::currentDateTime(); } cal = calendars.next(); } restoreCalendarSettings(); } bool CalendarView::saveCalendar( QString filename ) { // Store back all unsaved data into calendar object // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); if ( mViewManager->currentView() ) mViewManager->currentView()->flushView(); QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); mStorage->setSaveFormat( new ICalFormat() ); mStorage->setFileName( filename ); bool success; success = mStorage->save(); if ( !success ) { return false; } if ( filename == MainWindow::defaultFileName() ) { setLoadedFileVersion( lfv ); |