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.
(cherry picked from comit f73ccadc17)
This commit is contained in:
committed by
Tobias Doerffel
parent
6280fd9faf
commit
d75677b9d3
@@ -27,6 +27,7 @@
|
||||
#define _MAIN_WINDOW_H
|
||||
|
||||
#include <QtCore/QBasicTimer>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QList>
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtGui/QWhatsThis>
|
||||
@@ -160,6 +161,7 @@ private:
|
||||
QList<PluginView *> 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 );
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "lmmsconfig.h"
|
||||
#include "lmmsversion.h"
|
||||
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QLocale>
|
||||
#include <QtCore/QProcess>
|
||||
@@ -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() )
|
||||
{
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user