Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Do not silently load existing profile
  • Loading branch information
YoannQDQ authored and nyalldawson committed Jan 23, 2023
1 parent 6f83470 commit 59fa8cb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
25 changes: 21 additions & 4 deletions src/app/qgisapp.cpp
Expand Up @@ -15664,12 +15664,29 @@ void QgisApp::keyPressEvent( QKeyEvent *e )

void QgisApp::newProfile()
{
QString text = QInputDialog::getText( this, tr( "New profile name" ), tr( "New profile name" ) );
if ( text.isEmpty() )
QgsNewNameDialog dlg( QString(), QString(), QStringList(), userProfileManager()->allProfiles(), Qt::CaseInsensitive, this );
dlg.setConflictingNameWarning( tr( "A profile with this name already exists" ) );
dlg.setOverwriteEnabled( false );
dlg.setHintString( tr( "New profile name" ) );
dlg.setWindowTitle( tr( "New profile name" ) );

// Prevent from entering slashes and backslashes
dlg.setRegularExpression( "[^/\\\\]+" );

if ( dlg.exec() != QDialog::Accepted )
return;

userProfileManager()->createUserProfile( text );
userProfileManager()->loadUserProfile( text );
QString profileName = dlg.name();
QgsError error = userProfileManager()->createUserProfile( profileName );
if ( error.isEmpty() )
{
userProfileManager()->loadUserProfile( profileName );
}
else
{
QMessageBox::warning( this, tr( "New Profile" ), tr( "Cannot create folder '%1'" ).arg( profileName ) );
return;
}
}

void QgisApp::onTaskCompleteShowNotify( long taskId, int status )
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsuserprofilemanager.cpp
Expand Up @@ -142,7 +142,11 @@ QgsError QgsUserProfileManager::createUserProfile( const QString &name )
const QDir folder( mRootProfilePath + QDir::separator() + name );
if ( !folder.exists() )
{
QDir().mkpath( folder.absolutePath() );
if ( !QDir().mkpath( folder.absolutePath() ) )
{
error.append( tr( "Cannot write '%1'" ).arg( folder.absolutePath() ) );
return error;
}
}

QFile qgisPrivateDbFile( folder.absolutePath() + QDir::separator() + "qgis.db" );
Expand Down

0 comments on commit 59fa8cb

Please sign in to comment.