Commit e63aaf3b authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Basic crash recovery

If VLMC crashes, the project can be recovered, but some functionnalities
are still lacking.
parent 58d5bd39
......@@ -80,11 +80,6 @@ MainWindow::MainWindow( QWidget *parent ) :
createProjectPreferences();
initializeMenuKeyboardShortcut();
// Wizard
m_pWizard = new ProjectWizard( this );
m_pWizard->setModal( true );
m_pWizard->show();
// Translations
connect( this, SIGNAL( translateDockWidgetTitle() ),
DockWidgetManager::instance(), SLOT( transLateWidgetTitle() ) );
......@@ -102,11 +97,14 @@ MainWindow::MainWindow( QWidget *parent ) :
connect( ProjectManager::getInstance(), SIGNAL( projectUpdated( const QString&, bool ) ),
this, SLOT( projectUpdated( const QString&, bool ) ) );
QSettings s;
// Restore the geometry
restoreGeometry( s.value( "MainWindowGeometry" ).toByteArray() );
// Restore the layout
restoreState( s.value( "MainWindowState" ).toByteArray() );
// Wizard
m_pWizard = new ProjectWizard( this );
m_pWizard->setModal( true );
if ( restoreSession() == false )
{
m_pWizard->show();
}
}
MainWindow::~MainWindow()
......@@ -116,6 +114,7 @@ MainWindow::~MainWindow()
s.setValue( "MainWindowGeometry", saveGeometry() );
// Save the current layout
s.setValue( "MainWindowState", saveState() );
s.setValue( "CleanQuit", true );
s.sync();
if ( m_renderer )
......@@ -492,3 +491,44 @@ void MainWindow::on_actionCrash_triggered()
{
int test = 1 / 0;
}
bool MainWindow::restoreSession()
{
QSettings s;
bool cleanQuit = s.value( "CleanQuit", false ).toBool();
bool ret = false;
// Restore the geometry
restoreGeometry( s.value( "MainWindowGeometry" ).toByteArray() );
// Restore the layout
restoreState( s.value( "MainWindowState" ).toByteArray() );
if ( cleanQuit == false )
{
QMessageBox::StandardButton res = QMessageBox::question( this, tr( "Crash recovery" ), tr( "VLMC didn't closed nicely. Do you wan't to recover your project ?" ),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
if ( res == QMessageBox::Yes )
{
QStringList recentProjects = s.value( "RecentsProjects" ).toStringList();
if ( recentProjects.count() == 0 )
{
qDebug() << "No old project";
}
else
{
QString lastProject = recentProjects.first() + "backup";
if ( QFile::exists( lastProject ) == true )
{
ProjectManager::getInstance()->loadProject( lastProject );
ret = true;
}
else
QMessageBox::warning( this, tr( "Can't restore project" ), tr( "VLMC didn't manage to restore your project. We appology for the inconvenience" ) );
}
}
}
s.setValue( "CleanQuit", false );
s.sync();
return ret;
}
......@@ -67,6 +67,13 @@ private:
void createGlobalPreferences();
void createProjectPreferences();
void initializeMenuKeyboardShortcut();
/**
* \brief Will check if vlmc closed nicely or crashed.
* If so, the emergency backup will be opened.
* \return true if a project was restored. If so, the wizzard should
* not be opened.
*/
bool restoreSession();
Ui::MainWindow m_ui;
QSlider* m_zoomSlider;
......
......@@ -122,6 +122,7 @@ void ProjectManager::loadProject( const QString& fileName )
QSettings s;
s.setValue( "RecentsProjects", m_recentsProjects );
s.sync();
m_projectFile = new QFile( fileName );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment