Merge branch 'auto-save'

* auto-save:
  don't change the current project when auto-saving
  auto-saves every minute and recovers upon crash
  don't show WelcomeScreen when importing/loading

Conflicts:
	src/gui/MainWindow.cpp
This commit is contained in:
Tobias Doerffel
2009-11-29 23:21:54 +01:00
5 changed files with 50 additions and 16 deletions

View File

@@ -26,6 +26,7 @@
#define _MAIN_WINDOW_H
#include <QtCore/QBasicTimer>
#include <QtCore/QTimer>
#include <QtCore/QList>
#include <QtGui/QMainWindow>
#include <QtGui/QWhatsThis>
@@ -208,6 +209,7 @@ private:
QList<PluginView *> 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();

View File

@@ -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;

View File

@@ -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() )
{
@@ -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 );
}
}

View File

@@ -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;

View File

@@ -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: */