Skip to content
Permalink
Browse files

warn user when trying to add sqlite connection to browser and a conne…

…ction with sae name already exists (#9404)
  • Loading branch information
etiennesky committed Jan 22, 2014
1 parent 5d02020 commit fbdf34c2b26e90f7c6e077eb54be53cae03d100f
Showing with 10 additions and 3 deletions.
  1. +10 −3 src/providers/spatialite/qgsspatialitesourceselect.cpp
@@ -279,6 +279,7 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
QFileInfo myFI( myFile );
QString myPath = myFI.path();
QString myName = myFI.fileName();
QString baseKey = "/SpatiaLite/connections/";

// TODO: keep the test
//handle = openSpatiaLiteDb( myFI.canonicalFilePath() );
@@ -287,13 +288,19 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
// OK, this one is a valid SpatiaLite DB
//closeSpatiaLiteDb( handle );

// if there is already a connection with this name, warn user (#9404) and do nothing
// ideally, user should be able to change item name so that several sqlite files with same name can co-exist
if ( ! settings.value( baseKey + myName + "/sqlitepath", "" ).toString().isEmpty() )
{
QMessageBox::critical( parent, tr( "Error" ), tr( "Cannot add connection '%1' : a connection with the same name already exists." ).arg( myName ) );
return false;
}

// Persist last used SpatiaLite dir
settings.setValue( "/UI/lastSpatiaLiteDir", myPath );
// inserting this SQLite DB path
QString baseKey = "/SpatiaLite/connections/";
settings.setValue( baseKey + "selected", myName );
baseKey += myName;
settings.setValue( baseKey + "/sqlitepath", myFI.canonicalFilePath() );
settings.setValue( baseKey + myName + "/sqlitepath", myFI.canonicalFilePath() );
return true;
}

0 comments on commit fbdf34c

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