-rw-r--r-- | korganizer/calendarview.cpp | 4 | ||||
-rw-r--r-- | korganizer/mainwindow.cpp | 22 | ||||
-rw-r--r-- | korganizer/mainwindow.h | 2 |
3 files changed, 23 insertions, 5 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 14094bb..79fb727 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -2491,26 +2491,26 @@ bool CalendarView::checkAllFileVersions() } cal = calendars.next(); } loadedFileVersion = storeTemp; return true; } bool CalendarView::checkFileVersion(QString fn) { QFileInfo finf ( fn ); if ( !finf.exists() ) return true; QDateTime dt = finf.lastModified (); - qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); - qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); + //qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); + //qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); if ( dt <= loadedFileVersion ) return true; int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non 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(KGlobal::formatMessage(fn,0)).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" ); diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index 70baf5c..2af605f 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -393,25 +393,26 @@ MainWindow::MainWindow( QWidget *parent, const char *name ) : #ifndef DESKTOP_VERSION infrared = 0; #endif updateFilterToolbar(); updateWeek( mView->startDate() ); connect( mView->dateNavigator(), SIGNAL( datesSelected( const KCal::DateList & ) ), SLOT( updateWeekNum( const KCal::DateList & ) ) ); mBRdisabled = false; //toggleBeamReceive(); setCaption(i18n("Loading calendar files ... please wait" )); - QTimer::singleShot( 10, this, SLOT ( loadDataAfterStart() )); + mSaveDelay = 0; + QTimer::singleShot( 1, this, SLOT ( loadDataAfterStart() )); } MainWindow::~MainWindow() { //qDebug("MainWindow::~MainWindow() "); //save toolbar location delete mCalendar; delete mSyncManager; #ifndef DESKTOP_VERSION if ( infrared ) delete infrared; #endif @@ -1957,24 +1958,26 @@ void MainWindow::slotModifiedChanged( bool ) int msec; if ( mCalendarModifiedFlag ) { //qDebug(" MainWindow timer is running "); return; } // we store the changes after 1 minute, // and for safety reasons after 10 minutes again if ( !mSyncManager->blockSave() ) msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000; else msec = 1000 * 600; mSaveTimer.start( msec, true ); // 1 minute + mSaveTime.restart(); + mSaveDelay = msec/1000; qDebug("KO: Saving File in %d secs!", msec/1000); mCalendarModifiedFlag = true; } void MainWindow::saveStopTimer() { mSaveTimer.stop(); } void MainWindow::backupAllFiles() { QDate reference ( 2000,1,1); int daysTo = reference.daysTo ( QDate::currentDate() ); setCaption(i18n("Creating backup ... please wait ..." )); @@ -2004,52 +2007,65 @@ void MainWindow::backupAllFiles() KOPrefs::instance()->mLastBackupDate = daysTo; setCaption(i18n("Backup succesfully finished" )); } else if ( retval == 2 ){ setCaption(i18n("Backup globally disabled" )); qDebug("KO: Backup globally cancelled."); // backup globally cancelled KPimGlobalPrefs::instance()->mBackupEnabled = false; } // retval == 3: do nothing, try again later } void MainWindow::save() { + if ( mSaveDelay ) { + if ( mSaveDelay + 60 < mSaveTime.elapsed()/1000 ) { + qDebug("KO: Save delay %d. Elapsed save time %d ", mSaveDelay, mSaveTime.elapsed()/1000 ); + qDebug("KO: Restarting save timer"); + int msec = 10000; + mSaveTimer.start( msec, true ); // 1 minute + mSaveTime.restart(); + mSaveDelay = msec/1000; + return; + } + } if ( mView->viewManager()->journalView() ) mView->viewManager()->journalView()->checkModified(); if ( !mCalendarModifiedFlag ) { qDebug("KO: Calendar not modified. Nothing saved."); return; } if ( mSyncManager->blockSave() ) { slotModifiedChanged( true ); return; } + mSaveDelay = 0; mSyncManager->setBlockSave(true); if ( mView->checkAllFileVersions() ) { if ( KPimGlobalPrefs::instance()->mBackupEnabled ){ QDate reference ( 2000,1,1); int daysTo = reference.daysTo ( QDate::currentDate() ); if ( daysTo - KPimGlobalPrefs::instance()->mBackupDayCount >= KOPrefs::instance()->mLastBackupDate ) { backupAllFiles(); } ; // KPimGlobalPrefs::instance()->mLastBackupDate } - QTime neededSaveTime = QDateTime::currentDateTime().time(); + QTime neededSaveTime; + neededSaveTime.start(); if ( !isMinimized () ) setCaption(i18n("KO/Pi:Saving Data to File ..." )); qDebug("KO: Start saving data to file!"); if ( mView->saveCalendars() ) mCalendarModifiedFlag = false; - int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() ); + int msNeeded = neededSaveTime.elapsed(); 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 ); if ( !isMinimized () ) setCaption(savemes); else qDebug(savemes); } else { setCaption(i18n("Saving cancelled!")); mCalendarModifiedFlag = false; slotModifiedChanged( true ); } diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h index fdcf7c4..657c0a8 100644 --- a/korganizer/mainwindow.h +++ b/korganizer/mainwindow.h @@ -165,20 +165,22 @@ class MainWindow : public QMainWindow QAction *mMoveAction; QAction *mBeamAction; QAction *mCancelAction; QAction *mPrintSelAction; QAction *mToggleNav; QAction *mToggleFilter; QAction *mToggleAllday; QAction *actionFilterMenuTB; void closeEvent( QCloseEvent* ce ); QTimer mSaveTimer; + QTime mSaveTime; + int mSaveDelay; //bool mBlockSaveFlag; bool mCalendarModifiedFlag; QPixmap loadPixmap( QString ); QPixmap listviewPix, listviewPix0, listviewPix20, listviewPix40, listviewPix60, listviewPix80, journalPix; }; #endif |