Skip to content
Permalink
Browse files

prompt the user to load backup when load project fails

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 87d742d18daf2a19997ec106967a6707155cd752
Showing with 25 additions and 3 deletions.
  1. +25 −3 src/app/qgisapp.cpp
@@ -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();

0 comments on commit 87d742d

Please sign in to comment.
You can’t perform that action at this time.