Skip to content
Permalink
Browse files

Implemented proxy support to be application global rather than set on…

… a per connection basis

git-svn-id: http://svn.osgeo.org/qgis/trunk@8649 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux
timlinux committed Jun 15, 2008
1 parent 1131288 commit 0fa8024605c79c78e81fbe9b788e19d4d976c247
@@ -29,40 +29,6 @@ public:

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
*
*
* \retval TRUE if proxy setting is successful (if indeed it is supported)
*/
virtual bool setProxy(const QString & host,
int port,
const QString & user,
const QString & pass);


/**
* Add the list of WMS layer names to be rendered by this server
*/
@@ -535,35 +535,17 @@ public:
const QStringList & layers = QStringList(),
const QStringList & styles = QStringList(),
const QString & format = QString(),
const QString & crs = QString(),
const QString & proxyHost = QString(),
int proxyPort = 80,
const QString & proxyUser = QString(),
const QString & proxyPass = QString());
const QString & crs = QString());

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

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

/**
* Sets a proxy for the path given in the constructor
*
* \retval TRUE if proxy setting is successful (if indeed it is supported)
*/
bool setProxy(const QString & host = 0,
int port = 80,
const QString & user = 0,
const QString & pass = 0);

//! Which provider is being used for this Raster Layer?
QString providerKey();

@@ -45,6 +45,7 @@
#include <QMenuBar>
#include <QMenuItem>
#include <QMessageBox>
#include <QNetworkProxy>
#include <QPainter>
#include <QPictureIO>
#include <QPixmap>
@@ -331,6 +332,7 @@ static void customSrsValidation_(QgsSpatialRefSys* srs)
createLegend();
createOverview();
createMapTips();
setupProxy();

mComposer = new QgsComposer(this); // Map composer
mInternalClipboard = new QgsClipboard; // create clipboard
@@ -2216,12 +2218,7 @@ void QgisApp::addWmsLayer()
wmss->selectedLayers(),
wmss->selectedStylesForSelectedLayers(),
wmss->selectedImageEncoding(),
wmss->selectedCrs(),
wmss->connProxyHost(),
wmss->connProxyPort(),
wmss->connProxyUser(),
wmss->connProxyPass()
);
wmss->selectedCrs());
}
}

@@ -4355,6 +4352,7 @@ void QgisApp::options()
// bool splitterRedraw = mySettings.value("/qgis/splitterRedraw", true).toBool();
// canvasLegendSplit->setOpaqueResize(splitterRedraw);
// legendOverviewSplit->setOpaqueResize(splitterRedraw);
setupProxy();
}
}

@@ -5221,11 +5219,7 @@ QgsRasterLayer* QgisApp::addRasterLayer(QString const & rasterLayerPath,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs,
QString const & proxyHost,
int proxyPort,
QString const & proxyUser,
QString const & proxyPassword)
QString const & crs)
{
QgsDebugMsg("about to get library for " + providerKey);

@@ -5254,8 +5248,7 @@ QgsRasterLayer* QgisApp::addRasterLayer(QString const & rasterLayerPath,
+ " and CRS of " + crs );

// TODO: Remove the 0 when the raster layer becomes a full provider gateway.
layer = new QgsRasterLayer(0, rasterLayerPath, baseName, providerKey, layers, styles, format, crs,
proxyHost, proxyPort, proxyUser, proxyPassword);
layer = new QgsRasterLayer(0, rasterLayerPath, baseName, providerKey, layers, styles, format, crs);

QgsDebugMsg("Constructed new layer.");

@@ -5521,3 +5514,23 @@ void QgisApp::warnOlderProjectVersion(QString oldVersion)
}
return;
}

void QgisApp::setupProxy()
{
QSettings mySettings;
bool myFlag = mySettings.value("proxy/proxyEnabled", "0").toBool();
QNetworkProxy myProxy;
if (myFlag)
{
myProxy.setType(QNetworkProxy::HttpProxy);
myProxy.setHostName(mySettings.value("proxy/proxyHost", "").toString());
myProxy.setPort(mySettings.value("proxy/proxyPort", "").toInt());
myProxy.setUser(mySettings.value("proxy/proxyUser", "").toString());
myProxy.setPassword(mySettings.value("proxy/proxyPassword", "").toString());
}
else
{
// otherwise leave it blank to disable proxy usage
}
QNetworkProxy::setApplicationProxy(myProxy);
}
@@ -102,11 +102,7 @@ class QgisApp : public QMainWindow
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs,
QString const & proxyHost = QString(),
int proxyPort = 80,
QString const & proxyUser = QString(),
QString const & proxyPassword = QString());
QString const & crs);

/** open a raster layer for the given file
@returns false if unable to open a raster layer for rasterFile
@@ -150,6 +146,22 @@ class QgisApp : public QMainWindow

void dropEvent(QDropEvent *);

/** Setup the proxy settings from the QSettings environment.
* This is not called by default in the constructor. Rather,
* the application must explicitly call setupProx(). If
* you write your own application and wish to explicitly
* set up your own proxy rather, you should e.g.
* QNetworkProxy proxy;
* proxy.setType(QNetworkProxy::Socks5Proxy);
* proxy.setHostName("proxy.example.com");
* proxy.setPort(1080);
* proxy.setUser("username");
* proxy.setPassword("password");
* QNetworkProxy::setApplicationProxy(proxy);
*
* (as documented in Qt documentation.
*/
void setupProxy();
//private slots:
public slots:
//! About QGis
@@ -19,61 +19,48 @@
#include "qgscontexthelp.h"
#include <QSettings>

QgsNewHttpConnection::QgsNewHttpConnection(QWidget *parent, const QString& baseKey, const QString& connName, Qt::WFlags fl): QDialog(parent, fl), mBaseKey(baseKey), mOriginalConnName(connName)
QgsNewHttpConnection::QgsNewHttpConnection(
QWidget *parent, const QString& baseKey, const QString& connName, Qt::WFlags fl):
QDialog(parent, fl),
mBaseKey(baseKey),
mOriginalConnName(connName)
{
setupUi(this);
connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
connect(btnOk, SIGNAL(clicked()), this, SLOT(saveConnection()));

if (!connName.isEmpty())
{
// populate the dialog with the information stored for the connection
// populate the fields with the stored setting parameters

QSettings settings;
{
// populate the dialog with the information stored for the connection
// populate the fields with the stored setting parameters

QString key = mBaseKey + connName;
txtName->setText (connName);
txtUrl->setText (settings.value(key + "/url").toString());
txtProxyHost->setText(settings.value(key + "/proxyhost").toString());
txtProxyPort->setText(settings.value(key + "/proxyport").toString());
txtProxyUser->setText(settings.value(key + "/proxyuser").toString());
txtProxyPass->setText(settings.value(key + "/proxypassword").toString());
}
}
QSettings settings;

QgsNewHttpConnection::~QgsNewHttpConnection()
{
QString key = mBaseKey + connName;
txtName->setText (connName);
txtUrl->setText (settings.value(key + "/url").toString());
}
connect(buttonBox, SIGNAL(helpRequested()), this, SLOT(helpRequested()));
}

void QgsNewHttpConnection::testConnection()
QgsNewHttpConnection::~QgsNewHttpConnection()
{
// following line uses Qt SQL plugin - currently not used
// QSqlDatabase *testCon = QSqlDatabase::addDatabase("QPSQL7","testconnection");


}

void QgsNewHttpConnection::saveConnection()
void QgsNewHttpConnection::accept()
{
QSettings settings;
QString key = mBaseKey + txtName->text();

//delete original entry first
if(!mOriginalConnName.isNull() && mOriginalConnName != key)
{
settings.remove(mBaseKey + mOriginalConnName);
}
{
settings.remove(mBaseKey + mOriginalConnName);
}
settings.setValue(key + "/url", txtUrl->text().trimmed());
settings.setValue(key + "/proxyhost", txtProxyHost->text().trimmed());
settings.setValue(key + "/proxyport", txtProxyPort->text().trimmed());
settings.setValue(key + "/proxyuser", txtProxyUser->text().trimmed());
settings.setValue(key + "/proxypassword", txtProxyPass->text().trimmed());

accept();

QDialog::accept();
}

void QgsNewHttpConnection::on_btnHelp_clicked()
void QgsNewHttpConnection::helpRequested()
{
QgsContextHelp::run(context_id);
}
@@ -31,13 +31,11 @@ class QgsNewHttpConnection : public QDialog, private Ui::QgsNewHttpConnectionBas
QgsNewHttpConnection(QWidget *parent = 0, const QString& baseKey = "/Qgis/connections-wms/", const QString& connName = QString::null, Qt::WFlags fl = QgisGui::ModalDialogFlags);
//! Destructor
~QgsNewHttpConnection();
//! Tests the connection using the parameters supplied
void testConnection();
public slots:
//! Saves the connection to ~/.qt/qgisrc
void saveConnection();
void accept();
//! Show context help
void on_btnHelp_clicked();
void helpRequested();
private:
QString mBaseKey;
QString mOriginalConnName; //store initial name to delete entry in case of rename

0 comments on commit 0fa8024

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