Skip to content

Commit

Permalink
new http connection: parse service less fragile (fixes #16653; followup
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jun 2, 2017
1 parent b365e5e commit 1178660
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
14 changes: 7 additions & 7 deletions src/core/qgsowsconnection.cpp
Expand Up @@ -42,8 +42,8 @@ QgsOwsConnection::QgsOwsConnection( const QString &service, const QString &connN

QgsSettings settings;

QString key = "qgis//connections-" + mService.toLower() + '/' + mConnName;
QString credentialsKey = "qgis//" + mService + '/' + mConnName;
QString key = "qgis/connections-" + mService.toLower() + '/' + mConnName;
QString credentialsKey = "qgis/" + mService + '/' + mConnName;

QStringList connStringParts;

Expand Down Expand Up @@ -99,25 +99,25 @@ QgsDataSourceUri QgsOwsConnection::uri() const
QStringList QgsOwsConnection::connectionList( const QString &service )
{
QgsSettings settings;
settings.beginGroup( "qgis//connections-" + service.toLower() );
settings.beginGroup( "qgis/connections-" + service.toLower() );
return settings.childGroups();
}

QString QgsOwsConnection::selectedConnection( const QString &service )
{
QgsSettings settings;
return settings.value( "qgis//connections-" + service.toLower() + "/selected" ).toString();
return settings.value( "qgis/connections-" + service.toLower() + "/selected" ).toString();
}

void QgsOwsConnection::setSelectedConnection( const QString &service, const QString &name )
{
QgsSettings settings;
settings.setValue( "qgis//connections-" + service.toLower() + "/selected", name );
settings.setValue( "qgis/connections-" + service.toLower() + "/selected", name );
}

void QgsOwsConnection::deleteConnection( const QString &service, const QString &name )
{
QgsSettings settings;
settings.remove( "qgis//connections-" + service.toLower() + '/' + name );
settings.remove( "qgis//" + service + '/' + name );
settings.remove( "qgis/connections-" + service.toLower() + '/' + name );
settings.remove( "qgis/" + service + '/' + name );
}
36 changes: 19 additions & 17 deletions src/gui/qgsnewhttpconnection.cpp
Expand Up @@ -22,6 +22,7 @@
#include <QMessageBox>
#include <QUrl>
#include <QPushButton>
#include <QRegExp>
#include <QRegExpValidator>

QgsNewHttpConnection::QgsNewHttpConnection(
Expand All @@ -33,8 +34,9 @@ QgsNewHttpConnection::QgsNewHttpConnection(
{
setupUi( this );

QString service = baseKey.mid( 18, 3 ).toUpper();
setWindowTitle( tr( "Create a new %1 connection" ).arg( service ) );
QRegExp rx( "/connections-([^/]+)/" );
rx.indexIn( baseKey );
setWindowTitle( tr( "Create a new %1 connection" ).arg( rx.cap( 1 ).toUpper() ) );

// It would be obviously much better to use mBaseKey also for credentials,
// but for some strange reason a different hardcoded key was used instead.
Expand Down Expand Up @@ -69,7 +71,7 @@ QgsNewHttpConnection::QgsNewHttpConnection(
QgsSettings settings;

QString key = mBaseKey + connName;
QString credentialsKey = "qgis//" + mCredentialsBaseKey + '/' + connName;
QString credentialsKey = "qgis/" + mCredentialsBaseKey + '/' + connName;
txtName->setText( connName );
txtUrl->setText( settings.value( key + "/url" ).toString() );

Expand Down Expand Up @@ -124,23 +126,23 @@ QgsNewHttpConnection::QgsNewHttpConnection(
}
}

if ( mBaseKey != QLatin1String( "qgis//connections-wms/" ) )
if ( mBaseKey != QLatin1String( "qgis/connections-wms/" ) )
{
if ( mBaseKey != QLatin1String( "qgis//connections-wcs/" ) &&
mBaseKey != QLatin1String( "qgis//connections-wfs/" ) )
if ( mBaseKey != QLatin1String( "qgis/connections-wcs/" ) &&
mBaseKey != QLatin1String( "qgis/connections-wfs/" ) )
{
cbxIgnoreAxisOrientation->setVisible( false );
cbxInvertAxisOrientation->setVisible( false );
mGroupBox->layout()->removeWidget( cbxIgnoreAxisOrientation );
mGroupBox->layout()->removeWidget( cbxInvertAxisOrientation );
}

if ( mBaseKey == QLatin1String( "qgis//connections-wfs/" ) )
if ( mBaseKey == QLatin1String( "qgis/connections-wfs/" ) )
{
cbxIgnoreAxisOrientation->setText( tr( "Ignore axis orientation (WFS 1.1/WFS 2.0)" ) );
}

if ( mBaseKey == QLatin1String( "qgis//connections-wcs/" ) )
if ( mBaseKey == QLatin1String( "qgis/connections-wcs/" ) )
{
cbxIgnoreGetMapURI->setText( tr( "Ignore GetCoverage URI reported in capabilities" ) );
cbxIgnoreAxisOrientation->setText( tr( "Ignore axis orientation" ) );
Expand All @@ -167,7 +169,7 @@ QgsNewHttpConnection::QgsNewHttpConnection(
mGroupBox->layout()->removeWidget( lblReferer );
}

if ( mBaseKey != QLatin1String( "qgis//connections-wfs/" ) )
if ( mBaseKey != QLatin1String( "qgis/connections-wfs/" ) )
{
cmbVersion->setVisible( false );
mGroupBox->layout()->removeWidget( cmbVersion );
Expand Down Expand Up @@ -201,7 +203,7 @@ void QgsNewHttpConnection::accept()
{
QgsSettings settings;
QString key = mBaseKey + txtName->text();
QString credentialsKey = "qgis//" + mCredentialsBaseKey + '/' + txtName->text();
QString credentialsKey = "qgis/" + mCredentialsBaseKey + '/' + txtName->text();

// warn if entry was renamed to an existing connection
if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( txtName->text(), Qt::CaseInsensitive ) != 0 ) &&
Expand All @@ -227,7 +229,7 @@ void QgsNewHttpConnection::accept()
if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
{
settings.remove( mBaseKey + mOriginalConnName );
settings.remove( "qgis//" + mCredentialsBaseKey + '/' + mOriginalConnName );
settings.remove( "qgis/" + mCredentialsBaseKey + '/' + mOriginalConnName );
settings.sync();
}

Expand Down Expand Up @@ -255,15 +257,15 @@ void QgsNewHttpConnection::accept()

settings.setValue( key + "/url", url.toString() );

if ( mBaseKey == QLatin1String( "qgis//connections-wms/" ) ||
mBaseKey == QLatin1String( "qgis//connections-wcs/" ) ||
mBaseKey == QLatin1String( "qgis//connections-wfs/" ) )
if ( mBaseKey == QLatin1String( "qgis/connections-wms/" ) ||
mBaseKey == QLatin1String( "qgis/connections-wcs/" ) ||
mBaseKey == QLatin1String( "qgis/connections-wfs/" ) )
{
settings.setValue( key + "/ignoreAxisOrientation", cbxIgnoreAxisOrientation->isChecked() );
settings.setValue( key + "/invertAxisOrientation", cbxInvertAxisOrientation->isChecked() );
}

if ( mBaseKey == QLatin1String( "qgis//connections-wms/" ) || mBaseKey == QLatin1String( "qgis//connections-wcs/" ) )
if ( mBaseKey == QLatin1String( "qgis/connections-wms/" ) || mBaseKey == QLatin1String( "qgis/connections-wcs/" ) )
{
settings.setValue( key + "/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
settings.setValue( key + "/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
Expand All @@ -290,11 +292,11 @@ void QgsNewHttpConnection::accept()

settings.setValue( key + "/dpiMode", dpiMode );
}
if ( mBaseKey == QLatin1String( "qgis//connections-wms/" ) )
if ( mBaseKey == QLatin1String( "qgis/connections-wms/" ) )
{
settings.setValue( key + "/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
}
if ( mBaseKey == QLatin1String( "qgis//connections-wfs/" ) )
if ( mBaseKey == QLatin1String( "qgis/connections-wfs/" ) )
{
QString version = QStringLiteral( "auto" );
switch ( cmbVersion->currentIndex() )
Expand Down

0 comments on commit 1178660

Please sign in to comment.