-rw-r--r-- | korganizer/calendarview.cpp | 17 | ||||
-rw-r--r-- | korganizer/calendarview.h | 1 | ||||
-rw-r--r-- | korganizer/mainwindow.cpp | 3 |
3 files changed, 18 insertions, 3 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 3635cfa..eaea040 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -1505,25 +1505,25 @@ bool CalendarView::openCalendar(QString filename, bool merge) //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() ) + if ( filename != MainWindow::defaultFileName() ) saveCalendar( MainWindow::defaultFileName() ); loadedFileVersion = QDateTime::currentDateTime(); return true; } else { // while failing to load, the calendar object could // have become partially populated. Clear it out. if ( !merge ) mCalendar->close(); KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); globalFlagBlockAgenda = 2; updateView(); @@ -1536,35 +1536,48 @@ 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 ) { + QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); + return; + } + loadedFileVersion = dt; +} + 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, false)) , + 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)) , i18n("KO/Pi Warning"),i18n("Overwrite"), i18n("Sync+save")); if ( km == KMessageBox::Cancel ) return false; if ( km == KMessageBox::Yes ) return true; setSyncDevice("deleteaftersync" ); KOPrefs::instance()->mAskForPreferences = true; KOPrefs::instance()->mSyncAlgoPrefs = 3; KOPrefs::instance()->mWriteBackFile = false; diff --git a/korganizer/calendarview.h b/korganizer/calendarview.h index a3315ad..355bb84 100644 --- a/korganizer/calendarview.h +++ b/korganizer/calendarview.h @@ -163,24 +163,25 @@ class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Obser /** Emitted, when the number of outgoing messages has changed. */ void numOutgoingChanged(int); /** Send status message, which can e.g. be displayed in the status bar. */ void statusMessage(const QString &); void calendarViewExpanded( bool ); void updateSearchDialog(); public slots: + void watchSavedFile(); void recheckTimerAlarm(); void checkNextTimerAlarm(); void addAlarm(const QDateTime &qdt, const QString ¬i ); void addSuspendAlarm(const QDateTime &qdt, const QString ¬i ); void removeAlarm(const QDateTime &qdt, const QString ¬i ); /** options dialog made a changed to the configuration. we catch this * and notify all widgets which need to update their configuration. */ void updateConfig(); /** Load calendar from file \a filename. If \a merge is true, load diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index 1c4a186..6315c64 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -1399,28 +1399,29 @@ void MainWindow::slotModifiedChanged( bool changed ) #include <qfileinfo.h> void MainWindow::save() { if ( mBlockSaveFlag ) return; bool store = mBlockSaveFlag; mBlockSaveFlag = true; if ( mView->checkFileVersion( defaultFileName()) ) { QTime neededSaveTime = QDateTime::currentDateTime().time(); setCaption(i18n("KO/Pi:Saving Data to File ..." )); qDebug("KO: Start saving data to file!"); + mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); mView->saveCalendar( defaultFileName() ); int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() ); - mView->setLoadedFileVersion(QDateTime::currentDateTime()); + mView->watchSavedFile(); qDebug("KO: Needed %d ms for saving.",msNeeded ); QString savemes; savemes.sprintf(i18n("KO/Pi:File Saved. Needed %d sec, %d ms"),(msNeeded/1000)%100,msNeeded%1000 ); setCaption(savemes); } else setCaption(i18n("Saving cancelled!")); mCalendarModifiedFlag = false; mBlockSaveFlag = store; } void MainWindow::keyReleaseEvent ( QKeyEvent * e) { |