Skip to content

Commit

Permalink
Potential fix for trac-ticket #8.
Browse files Browse the repository at this point in the history
* Propagate proxy information from the Server Selection dialog to the WMS provider (used by the QgsRasterLayer).

Possible bonus feature:

* Proxy information is saved and restored from the project file.

I cannot test this locally, so would appreciate somebody else giving it a go.



git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5716 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Aug 21, 2006
1 parent 4a21ccc commit c2db9e6
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 8 deletions.
22 changes: 22 additions & 0 deletions src/core/qgsrasterdataprovider.h
Expand Up @@ -61,6 +61,28 @@ class QgsRasterDataProvider : public QgsDataProvider

virtual ~QgsRasterDataProvider() {};


/**
* Gets the HTTP proxy host used for this connection
*/
virtual QString proxyHost() const = 0;

/**
* Gets the HTTP proxy port used for this connection
*/
virtual int proxyPort() const = 0;

/**
* Gets the HTTP proxy user name used for this connection
*/
virtual QString proxyUser() const = 0;

/**
* Gets the HTTP proxy user password used for this connection
*/
virtual QString proxyPass() const = 0;


/**
*
* Sets a proxy for the URL given in the constructor
Expand Down
25 changes: 25 additions & 0 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -146,6 +146,31 @@ QgsWmsProvider::~QgsWmsProvider()

}


QString QgsWmsProvider::proxyHost() const
{
return mHttpProxyHost;
}


int QgsWmsProvider::proxyPort() const
{
return mHttpProxyPort;
}


QString QgsWmsProvider::proxyUser() const
{
return mHttpProxyUser;
}


QString QgsWmsProvider::proxyPass() const
{
return mHttpProxyPass;
}


bool QgsWmsProvider::setProxy(QString const & host,
int port,
QString const & user,
Expand Down
20 changes: 20 additions & 0 deletions src/providers/wms/qgswmsprovider.h
Expand Up @@ -356,6 +356,26 @@ class QgsWmsProvider : public QgsRasterDataProvider
//! Destructor
virtual ~QgsWmsProvider();

/**
* Gets the HTTP proxy host used for this connection
*/
virtual QString proxyHost() const;

/**
* Gets the HTTP proxy port used for this connection
*/
virtual int proxyPort() const;

/**
* Gets the HTTP proxy user name used for this connection
*/
virtual QString proxyUser() const;

/**
* Gets the HTTP proxy user password used for this connection
*/
virtual QString proxyPass() const;

/**
*
* Sets an HTTP proxy for the URL given in the constructor
Expand Down
53 changes: 49 additions & 4 deletions src/raster/qgsrasterlayer.cpp
Expand Up @@ -4533,7 +4533,14 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )
QString crs = QString("EPSG:%1")
.arg(mCoordinateTransform->sourceSRS().epsg());

setDataProvider( mProviderKey, layers, styles, format, crs );
// Collect proxy information
QString proxyHost = rpNode.namedItem("wmsProxyHost").toElement().text();
int proxyPort = rpNode.namedItem("wmsProxyPort").toElement().text().toInt();
QString proxyUser = rpNode.namedItem("wmsProxyUser").toElement().text();
QString proxyPass = rpNode.namedItem("wmsProxyPass").toElement().text();

setDataProvider( mProviderKey, layers, styles, format, crs,
proxyHost, proxyPort, proxyUser, proxyPass );
}
else
{
Expand Down Expand Up @@ -4668,6 +4675,34 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )
document.createTextNode(dataProvider->imageEncoding());
formatElement.appendChild(formatText);
rasterPropertiesElement.appendChild(formatElement);

// <rasterproperties><wmsProxyHost>
QDomElement proxyHostElement = document.createElement("wmsProxyHost");
QDomText proxyHostText =
document.createTextNode(dataProvider->proxyHost());
proxyHostElement.appendChild(proxyHostText);
rasterPropertiesElement.appendChild(proxyHostElement);

// <rasterproperties><wmsProxyPort>
QDomElement proxyPortElement = document.createElement("wmsProxyPort");
QDomText proxyPortText =
document.createTextNode( QString::number(dataProvider->proxyPort()) );
proxyPortElement.appendChild(proxyPortText);
rasterPropertiesElement.appendChild(proxyPortElement);

// <rasterproperties><wmsProxyUser>
QDomElement proxyUserElement = document.createElement("wmsProxyUser");
QDomText proxyUserText =
document.createTextNode(dataProvider->proxyUser());
proxyUserElement.appendChild(proxyUserText);
rasterPropertiesElement.appendChild(proxyUserElement);

// <rasterproperties><wmsProxyPass>
QDomElement proxyPassElement = document.createElement("wmsProxyPass");
QDomText proxyPassText =
document.createTextNode(dataProvider->proxyPass());
proxyPassElement.appendChild(proxyPassText);
rasterPropertiesElement.appendChild(proxyPassElement);
}

// <showDebugOverlayFlag>
Expand Down Expand Up @@ -4903,7 +4938,11 @@ QgsRasterLayer::QgsRasterLayer(int dummy,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs )
QString const & crs,
QString const & proxyHost,
int proxyPort,
QString const & proxyUser,
QString const & proxyPass )
: QgsMapLayer(RASTER, baseName, rasterLayerPath),
rasterXDimInt( std::numeric_limits<int>::max() ),
rasterYDimInt( std::numeric_limits<int>::max() ),
Expand Down Expand Up @@ -4933,7 +4972,8 @@ QgsRasterLayer::QgsRasterLayer(int dummy,
// if we're given a provider type, try to create and bind one to this layer
if ( ! providerKey.isEmpty() )
{
setDataProvider( providerKey, layers, styles, format, crs );
setDataProvider( providerKey, layers, styles, format, crs,
proxyHost, proxyPort, proxyUser, proxyPass );
}

// Default for the popup menu
Expand Down Expand Up @@ -4972,7 +5012,11 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs )
QString const & crs,
QString const & proxyHost,
int proxyPort,
QString const & proxyUser,
QString const & proxyPass )
{
// XXX should I check for and possibly delete any pre-existing providers?
// XXX How often will that scenario occur?
Expand Down Expand Up @@ -5039,6 +5083,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
dataProvider->addLayers(layers, styles);
dataProvider->setImageEncoding(format);
dataProvider->setImageCrs(crs);
dataProvider->setProxy(proxyHost, proxyPort, proxyUser, proxyPass);

// get the extent
QgsRect *mbr = dataProvider->extent();
Expand Down
16 changes: 12 additions & 4 deletions src/raster/qgsrasterlayer.h
Expand Up @@ -18,8 +18,8 @@

/** \file qgsrasterlayer.h
* \brief This class provides qgis with the ability to render raster datasets
* onto the mapcanvas..
*
* onto the mapcanvas
*
* The qgsrasterlayer class makes use of gdal for data io, and thus supports
* any gdal supported format. The constructor attemtps to infer what type of
* file (RASTER_LAYER_TYPE) is being opened - not in terms of the file format (tif, ascii grid etc.)
Expand Down Expand Up @@ -1061,13 +1061,21 @@ public slots:
QStringList const & layers = QStringList(),
QStringList const & styles = QStringList(),
QString const & format = QString(),
QString const & crs = QString());
QString const & crs = QString(),
QString const & proxyHost = QString(),
int proxyPort = 80,
QString const & proxyUser = QString(),
QString const & proxyPass = QString());

void setDataProvider( QString const & provider,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs );
QString const & crs,
QString const & proxyHost,
int proxyPort,
QString const & proxyUser,
QString const & proxyPass );

//! Does this layer use a provider for setting/retrieving data?
bool usesProvider();
Expand Down

0 comments on commit c2db9e6

Please sign in to comment.