diff --git a/include/MainWindow.h b/include/MainWindow.h index 5916893fc..3a7a770ed 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -26,6 +26,7 @@ #define _MAIN_WINDOW_H #include +#include #include #include #include @@ -207,6 +208,7 @@ private: QList m_tools; QBasicTimer m_updateTimer; + QTimer m_autoSaveTimer; ResourceBrowser * m_resourceBrowser; @@ -243,6 +245,8 @@ private slots: void playAndRecord(); void stop(); + void autoSave(); + signals: void periodicUpdate(); diff --git a/src/core/main.cpp b/src/core/main.cpp index 41227025f..cb05bbecb 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -23,6 +23,7 @@ */ +#include #include #include #include @@ -449,6 +450,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 dfb101be6..6d92b5ae7 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -83,7 +83,8 @@ MainWindow::MainWindow() : m_workspace( NULL ), m_templatesMenu( NULL ), m_recentlyOpenedProjectsMenu( NULL ), - m_toolsMenu( NULL ) + m_toolsMenu( NULL ), + m_autoSaveTimer( this ) { setAttribute( Qt::WA_DeleteOnClose ); @@ -153,6 +154,10 @@ MainWindow::MainWindow() : 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 + m_welcomeScreen = new WelcomeScreen( this ); m_welcomeScreen->setVisible( false ); } @@ -1182,6 +1187,9 @@ void MainWindow::closeEvent( QCloseEvent * _ce ) { if( mayChangeProject() ) { + // delete recovery file + QDir working(configManager::inst()->workingDir()); + working.remove("recover.mmp"); _ce->accept(); } else @@ -1387,7 +1395,7 @@ void MainWindow::keyReleaseEvent( QKeyEvent * _ke ) -void MainWindow::timerEvent( QTimerEvent * ) +void MainWindow::timerEvent( QTimerEvent * _te) { emit periodicUpdate(); } @@ -1557,6 +1565,13 @@ void MainWindow::toggleRecordAutomation( bool _recording ) +void MainWindow::autoSave() +{ + QDir work(configManager::inst()->workingDir()); + engine::getSong()->saveProjectAs(work.absoluteFilePath("recover.mmp")); +} + + #include "moc_MainWindow.cxx" /* vim: set tw=0 noexpandtab: */