diff --git a/include/MainWindow.h b/include/MainWindow.h index 9bc125dbf..a76fc320c 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -27,6 +27,7 @@ #define _MAIN_WINDOW_H #include +#include #include #include #include @@ -160,6 +161,7 @@ private: QList m_tools; QBasicTimer m_updateTimer; + QTimer m_autoSaveTimer; friend class engine; @@ -173,6 +175,8 @@ private slots: void updateRecentlyOpenedProjectsMenu( void ); + void autoSave(); + signals: void periodicUpdate( void ); diff --git a/src/core/main.cpp b/src/core/main.cpp index d7b1b22f0..17fb61113 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -25,6 +25,7 @@ #include "lmmsconfig.h" #include "lmmsversion.h" +#include #include #include #include @@ -414,6 +415,13 @@ int main( int argc, char * * argv ) // srandom() calls in their init procedure srand( getpid() + time( 0 ) ); + // recover a file? + QString recoveryFile = QDir(configManager::inst()->workingDir()).absoluteFilePath("recover.mmp"); + if( QFileInfo(recoveryFile).exists() ) + { + file_to_load = recoveryFile; + } + // we try to load given file if( !file_to_load.isEmpty() ) { diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 1eb8edd90..7c8d18c63 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -72,7 +72,8 @@ MainWindow::MainWindow( void ) : m_workspace( NULL ), m_templatesMenu( NULL ), m_recentlyOpenedProjectsMenu( NULL ), - m_toolsMenu( NULL ) + m_toolsMenu( NULL ), + m_autoSaveTimer( this ) { setAttribute( Qt::WA_DeleteOnClose ); @@ -182,6 +183,10 @@ MainWindow::MainWindow( void ) : m_updateTimer.start( 1000 / 20, this ); // 20 fps + + // connect auto save + connect(&m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSave())); + m_autoSaveTimer.start(1000 * 60); // 1 minute } @@ -898,6 +903,9 @@ void MainWindow::closeEvent( QCloseEvent * _ce ) { if( mayChangeProject() ) { + // delete recovery file + QDir working(configManager::inst()->workingDir()); + working.remove("recover.mmp"); _ce->accept(); } else @@ -969,7 +977,7 @@ void MainWindow::keyReleaseEvent( QKeyEvent * _ke ) -void MainWindow::timerEvent( QTimerEvent * ) +void MainWindow::timerEvent( QTimerEvent * _te) { emit periodicUpdate(); } @@ -1037,6 +1045,13 @@ void MainWindow::browseHelp( void ) +void MainWindow::autoSave() +{ + QDir work(configManager::inst()->workingDir()); + engine::getSong()->saveProjectAs(work.absoluteFilePath("recover.mmp")); +} + + #include "moc_MainWindow.cxx"