auto-saves every minute and recovers upon crash
auto-save time is not configurable yet. saves "recover.mmp" to WORKING_DIR every 60 seconds. Deletes recover.mmp on successful close of LMMS. If recover.mmp is found upon start, it loads that project.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#define _MAIN_WINDOW_H
|
||||
|
||||
#include <QtCore/QBasicTimer>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QList>
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtGui/QWhatsThis>
|
||||
@@ -207,6 +208,7 @@ private:
|
||||
QList<PluginView *> 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();
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QLocale>
|
||||
#include <QtCore/QProcess>
|
||||
@@ -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() )
|
||||
{
|
||||
|
||||
@@ -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: */
|
||||
|
||||
Reference in New Issue
Block a user