Skip to content
Permalink
Browse files

new http connection: parse service less fragile (fixes #16653; followup

  • Loading branch information
jef-n committed Jun 2, 2017
1 parent b365e5e commit 11786603b2cfc9092895128afaa9e5fecbeb26be
Showing with 26 additions and 24 deletions.
  1. +7 −7 src/core/qgsowsconnection.cpp
  2. +19 −17 src/gui/qgsnewhttpconnection.cpp
@@ -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;

@@ -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 );
}
@@ -22,6 +22,7 @@
#include <QMessageBox>
#include <QUrl>
#include <QPushButton>
#include <QRegExp>
#include <QRegExpValidator>

QgsNewHttpConnection::QgsNewHttpConnection(
@@ -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.
@@ -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() );

@@ -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" ) );
@@ -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 );
@@ -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 ) &&
@@ -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();
}

@@ -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() );
@@ -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() )

0 comments on commit 1178660

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