author | zautrix <zautrix> | 2005-09-17 22:07:21 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-09-17 22:07:21 (UTC) |
commit | 64199073c047a30f3cff85fe6ee30691ff0db2f7 (patch) (side-by-side diff) | |
tree | 5ff49088999f2c02fb2a40760b881c02f50cfc35 /korganizer/mainwindow.cpp | |
parent | e228113016abd6f75824633da9520c1ec1763f23 (diff) | |
download | kdepimpi-64199073c047a30f3cff85fe6ee30691ff0db2f7.zip kdepimpi-64199073c047a30f3cff85fe6ee30691ff0db2f7.tar.gz kdepimpi-64199073c047a30f3cff85fe6ee30691ff0db2f7.tar.bz2 |
savetimer
-rw-r--r-- | korganizer/mainwindow.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index 70baf5c..2af605f 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -389,33 +389,34 @@ MainWindow::MainWindow( QWidget *parent, const char *name ) : mView->dialogManager()->showSyncOptions(); } //US listen for result adressed from Ka/Pi #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 } void MainWindow::loadDataAfterStart() @@ -1953,32 +1954,34 @@ void MainWindow::slotModifiedChanged( bool ) { if ( mBlockAtStartup ) return; 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 ..." )); qDebug("KO: Last backup was %d days ago ", daysTo - KOPrefs::instance()->mLastBackupDate); // we need the file path, the backup dir and the number of bups as param QString bupDir = KPimGlobalPrefs::instance()->mBackupDatadir; if ( KPimGlobalPrefs::instance()->mBackupUseDefaultDir) @@ -2000,60 +2003,73 @@ void MainWindow::backupAllFiles() KApplication::createBackup( cal->mFileName, bupDir, KPimGlobalPrefs::instance()->mBackupNumbers ); } cal = calendars.next(); } 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 ); } mSyncManager->setBlockSave( false ); } void MainWindow::keyReleaseEvent ( QKeyEvent * e) |