diff --git a/include/MainWindow.h b/include/MainWindow.h index 80357e8d5..f021076b7 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -26,6 +26,7 @@ #define _MAIN_WINDOW_H #include +#include #include #include #include @@ -208,6 +209,7 @@ private: QList m_tools; QBasicTimer m_updateTimer; + QTimer m_autoSaveTimer; ResourceBrowser * m_resourceBrowser; @@ -244,6 +246,8 @@ private slots: void playAndRecord(); void stop(); + void autoSave(); + signals: void periodicUpdate(); diff --git a/include/song.h b/include/song.h index 858f577f5..7406bdc22 100644 --- a/include/song.h +++ b/include/song.h @@ -151,9 +151,10 @@ public: // file management void createNewProject(); void createNewProjectFromTemplate( const QString & _template ); - void loadProject( const QString & _file_name ); - bool saveProject(); - bool saveProjectAs( const QString & _file_name ); + void loadProject( const QString & _filename ); + bool guiSaveProject(); + bool guiSaveProjectAs( const QString & _filename ); + bool saveProjectFile( const QString & _filename ); inline const QString & projectFileName() const { return m_fileName; diff --git a/src/core/main.cpp b/src/core/main.cpp index 41227025f..96019ce37 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() ) { @@ -523,7 +531,7 @@ int main( int argc, char * * argv ) } else { - engine::getSong()->saveProjectAs( file_to_save ); + engine::getSong()->saveProjectFile( file_to_save ); return( 0 ); } } diff --git a/src/core/song.cpp b/src/core/song.cpp index 6b3ff3cc5..0d2d95558 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -1009,10 +1009,8 @@ void song::loadProject( const QString & _file_name ) } - - -// save current song -bool song::saveProject() +// only save current song as _filename and do nothing else +bool song::saveProjectFile( const QString & _filename ) { multimediaProject mmp( multimediaProject::SongProject ); @@ -1021,7 +1019,6 @@ bool song::saveProject() m_masterVolumeModel.saveSettings( mmp, mmp.head(), "mastervol" ); m_masterPitchModel.saveSettings( mmp, mmp.head(), "masterpitch" ); - saveState( mmp, mmp.content() ); m_globalAutomationTrack->saveState( mmp, mmp.content() ); @@ -1039,8 +1036,17 @@ bool song::saveProject() saveControllerStates( mmp, mmp.content() ); + return mmp.writeFile( _filename ); +} + + + +// save current song and update the gui +bool song::guiSaveProject() +{ + multimediaProject mmp( multimediaProject::SongProject ); m_fileName = mmp.nameWithExtension( m_fileName ); - if( mmp.writeFile( m_fileName ) == true && engine::hasGUI() ) + if( saveProjectFile( m_fileName ) && engine::hasGUI() ) { textFloat::displayMessage( tr( "Project saved" ), tr( "The project %1 is now saved." @@ -1067,12 +1073,12 @@ bool song::saveProject() // save current song in given filename -bool song::saveProjectAs( const QString & _file_name ) +bool song::guiSaveProjectAs( const QString & _file_name ) { QString o = m_oldFileName; m_oldFileName = m_fileName; m_fileName = _file_name; - if( saveProject() == false ) + if( guiSaveProject() == false ) { m_fileName = m_oldFileName; m_oldFileName = o; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 453193dbd..4d8683192 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -84,7 +84,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 ); @@ -154,6 +155,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 ); } @@ -1007,7 +1012,7 @@ bool MainWindow::saveProject() } else { - engine::getSong()->saveProject(); + engine::getSong()->guiSaveProject(); } return true; } @@ -1036,7 +1041,7 @@ bool MainWindow::saveProjectAs() if( sfd.exec () == QFileDialog::Accepted && !sfd.selectedFiles().isEmpty() && sfd.selectedFiles()[0] != "" ) { - engine::getSong()->saveProjectAs( + engine::getSong()->guiSaveProjectAs( sfd.selectedFiles()[0] ); return true; } @@ -1195,6 +1200,9 @@ void MainWindow::closeEvent( QCloseEvent * _ce ) { if( mayChangeProject() ) { + // delete recovery file + QDir working(configManager::inst()->workingDir()); + working.remove("recover.mmp"); _ce->accept(); } else @@ -1400,7 +1408,7 @@ void MainWindow::keyReleaseEvent( QKeyEvent * _ke ) -void MainWindow::timerEvent( QTimerEvent * ) +void MainWindow::timerEvent( QTimerEvent * _te) { emit periodicUpdate(); } @@ -1570,6 +1578,13 @@ void MainWindow::toggleRecordAutomation( bool _recording ) +void MainWindow::autoSave() +{ + QDir work(configManager::inst()->workingDir()); + engine::getSong()->saveProjectFile(work.absoluteFilePath("recover.mmp")); +} + + #include "moc_MainWindow.cxx" /* vim: set tw=0 noexpandtab: */