Skip to content

Commit

Permalink
prompt the user to load backup when load project fails
Browse files Browse the repository at this point in the history
If an error occurs while loading the project file, prompt the user to load the backup file instead, if it exists.
  • Loading branch information
SebDieBln committed Dec 25, 2015
1 parent e158642 commit 87d742d
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -4312,13 +4312,35 @@ bool QgisApp::addProject( const QString& projectFile )

if ( !QgsProject::instance()->read( projectFile ) )
{
QString backupFile = projectFile + "~";
QString loadBackupPrompt;
QMessageBox::StandardButtons buttons;
if ( QFile( backupFile ).exists() )
{
loadBackupPrompt = "\n\n" + tr( "Do you want to open the backup file\n%1\ninstead?" ).arg( backupFile );
buttons |= QMessageBox::Yes;
buttons |= QMessageBox::No;
}
else
{
buttons |= QMessageBox::Ok;
}
QApplication::restoreOverrideCursor();
statusBar()->clearMessage();

QMessageBox::critical( this,
tr( "Unable to open project" ),
QgsProject::instance()->error() );
int r = QMessageBox::critical( this,
tr( "Unable to open project" ),
QgsProject::instance()->error() + loadBackupPrompt,
buttons );

if ( QMessageBox::Yes == r && addProject( backupFile ) )
{
// We loaded data from the backup file, but we pretend to work on the original project file.
QgsProject::instance()->setFileName( projectFile );
QgsProject::instance()->setDirty( true );
mProjectLastModified = pfi.lastModified();
return true;
}

mMapCanvas->freeze( false );
mMapCanvas->refresh();
Expand Down

0 comments on commit 87d742d

Please sign in to comment.