Skip to content

Commit

Permalink
Apply proxy patch that let select the proxy type in the option dialog
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@9939 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 7, 2009
1 parent 64e9d93 commit b092ae7
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 34 deletions.
23 changes: 0 additions & 23 deletions src/app/qgisapp.cpp
Expand Up @@ -345,7 +345,6 @@ QgisApp::QgisApp( QSplashScreen *splash, QWidget * parent, Qt::WFlags fl )
createLegend();
createOverview();
createMapTips();
setupProxy();
readSettings();
updateRecentProjectPaths();

Expand Down Expand Up @@ -4293,8 +4292,6 @@ void QgisApp::options()
int action = mySettings.value( "/qgis/wheel_action", 0 ).toInt();
double zoomFactor = mySettings.value( "/qgis/zoom_factor", 2 ).toDouble();
mMapCanvas->setWheelAction(( QgsMapCanvas::WheelAction ) action, zoomFactor );

setupProxy();
}
}

Expand Down Expand Up @@ -5506,26 +5503,6 @@ void QgisApp::oldProjectVersionWarning( 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 );
}

QIcon QgisApp::getThemeIcon( const QString theName )
{
QString myPreferredPath = QgsApplication::activeThemePath() + QDir::separator() + theName;
Expand Down
12 changes: 12 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -62,6 +62,16 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
leProxyPort->setText( settings.value( "proxy/proxyPort", "" ).toString() );
leProxyUser->setText( settings.value( "proxy/proxyUser", "" ).toString() );
leProxyPassword->setText( settings.value( "proxy/proxyPassword", "" ).toString() );

//available proxy types
mProxyTypeComboBox->insertItem(0, "DefaultProxy");
mProxyTypeComboBox->insertItem(1, "Socks5Proxy");
mProxyTypeComboBox->insertItem(2, "HttpProxy");
mProxyTypeComboBox->insertItem(3, "HttpCachingProxy");
mProxyTypeComboBox->insertItem(4, "FtpCachingProxy");
QString settingProxyType = settings.value("proxy/proxyType", "DefaultProxy").toString();
mProxyTypeComboBox->setCurrentIndex(mProxyTypeComboBox->findText(settingProxyType));

// set the current theme
cmbTheme->setItemText( cmbTheme->currentIndex(), settings.value( "/Themes" ).toString() );

Expand Down Expand Up @@ -261,6 +271,8 @@ void QgsOptions::saveOptions()
settings.setValue( "proxy/proxyPort", leProxyPort->text() );
settings.setValue( "proxy/proxyUser", leProxyUser->text() );
settings.setValue( "proxy/proxyPassword", leProxyPassword->text() );
settings.setValue( "proxy/proxyType", mProxyTypeComboBox->currentText());

//general settings
settings.setValue( "/Map/identifyRadius", spinBoxIdentifyValue->value() );
settings.setValue( "/qgis/showLegendClassifiers", cbxLegendClassifiers->isChecked() );
Expand Down
6 changes: 4 additions & 2 deletions src/core/qgshttptransaction.cpp
Expand Up @@ -37,13 +37,15 @@ QgsHttpTransaction::QgsHttpTransaction( QString uri,
QString proxyHost,
int proxyPort,
QString proxyUser,
QString proxyPass )
QString proxyPass,
QNetworkProxy::ProxyType proxyType)
: httpresponsecontenttype( 0 ),
httpurl( uri ),
httphost( proxyHost ),
httpport( proxyPort ),
httpuser( proxyUser ),
httppass( proxyPass ),
mProxyType(proxyType),
mError( 0 )
{

Expand Down Expand Up @@ -105,7 +107,7 @@ bool QgsHttpTransaction::getSynchronously( QByteArray &respondedContent, int red
else
{
// Insert proxy username and password authentication
http->setProxy( httphost, httpport, httpuser, httppass );
http->setProxy( QNetworkProxy(mProxyType, httphost, httpport, httpuser, httppass) );
}

// int httpid1 = http->setHost( qurl.host(), qurl.port() );
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgshttptransaction.h
Expand Up @@ -23,6 +23,7 @@
#define QGSHTTPTRANSACTION_H

#include <QHttp>
#include <QNetworkProxy>
#include <QString>

class QTimer;
Expand All @@ -46,7 +47,8 @@ class CORE_EXPORT QgsHttpTransaction : public QObject
QString proxyHost = QString(),
int proxyPort = 80,
QString proxyUser = QString(),
QString proxyPass = QString() );
QString proxyPass = QString(),
QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy);

//! Destructor
virtual ~QgsHttpTransaction();
Expand Down Expand Up @@ -187,6 +189,8 @@ class CORE_EXPORT QgsHttpTransaction : public QObject
*/
int httpredirections;

QNetworkProxy::ProxyType mProxyType;

/**
* Indicates the associated QTimer object - used to detect network timeouts
*/
Expand Down
42 changes: 41 additions & 1 deletion src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -32,6 +32,7 @@
#include <QUrl>
#include <QImage>
#include <QSet>
#include <QSettings>

#ifdef _MSC_VER
#include <float.h>
Expand Down Expand Up @@ -636,7 +637,46 @@ bool QgsWmsProvider::retrieveServerCapabilities( bool forceRefresh )
QByteArray QgsWmsProvider::retrieveUrl( QString url )
{
QgsDebugMsg( "WMS request Url: " + url );
QgsHttpTransaction http( url );

//read proxy settings
QSettings settings;
QString proxyHost, proxyUser, proxyPassword;
int proxyPort;
QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;

bool proxyEnabled = settings.value( "proxy/proxyEnabled", "0" ).toBool();
if(proxyEnabled)
{
proxyHost = settings.value( "proxy/proxyHost", "" ).toString();
proxyPort = settings.value( "proxy/proxyPort", "" ).toString().toInt();
proxyUser = settings.value( "proxy/proxyUser", "" ).toString();
proxyPassword = settings.value( "proxy/proxyPassword", "" ).toString();
QString proxyTypeString = settings.value( "proxy/proxyType", "" ).toString();
if(proxyTypeString == "DefaultProxy")
{
proxyType = QNetworkProxy::DefaultProxy;
}
else if(proxyTypeString == "Socks5Proxy")
{
proxyType = QNetworkProxy::Socks5Proxy;
}
else if(proxyTypeString == "HttpProxy")
{
proxyType = QNetworkProxy::HttpProxy;
}
else if(proxyTypeString == "HttpCachingProxy")
{
proxyType = QNetworkProxy::HttpCachingProxy;
}
else if(proxyTypeString == "FtpCachingProxy")
{
proxyType = QNetworkProxy::FtpCachingProxy;
}
}


QgsHttpTransaction http(url, proxyHost, proxyPort, proxyUser, proxyPassword, proxyType );


// Do a passthrough for the status bar text
connect(
Expand Down
37 changes: 30 additions & 7 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -25,7 +25,7 @@
<item row="0" column="0" >
<widget class="QTabWidget" name="tabWidget" >
<property name="currentIndex" >
<number>0</number>
<number>6</number>
</property>
<widget class="QWidget" name="tabGeneral" >
<attribute name="title" >
Expand Down Expand Up @@ -1000,7 +1000,7 @@
</property>
</widget>
</item>
<item row="0" column="1" >
<item row="0" column="1" colspan="2" >
<widget class="QLineEdit" name="leProxyHost" />
</item>
<item row="1" column="0" >
Expand All @@ -1013,7 +1013,7 @@
</property>
</widget>
</item>
<item row="1" column="1" >
<item row="1" column="1" colspan="2" >
<widget class="QLineEdit" name="leProxyPort" />
</item>
<item row="2" column="0" >
Expand All @@ -1026,7 +1026,7 @@
</property>
</widget>
</item>
<item row="2" column="1" >
<item row="2" column="1" colspan="2" >
<widget class="QLineEdit" name="leProxyUser" >
<property name="toolTip" >
<string>Leave this blank if no proxy username / password are required</string>
Expand All @@ -1043,7 +1043,7 @@
</property>
</widget>
</item>
<item row="3" column="1" >
<item row="3" column="1" colspan="2" >
<widget class="QLineEdit" name="leProxyPassword" >
<property name="toolTip" >
<string>Leave this blank if no proxy username / password are required</string>
Expand All @@ -1053,6 +1053,29 @@
</property>
</widget>
</item>
<item row="4" column="0" >
<widget class="QLabel" name="mTypeLabel" >
<property name="text" >
<string>Proxy type</string>
</property>
</widget>
</item>
<item row="4" column="1" >
<widget class="QComboBox" name="mProxyTypeComboBox" />
</item>
<item row="4" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>241</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
Expand All @@ -1063,8 +1086,8 @@
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
<width>577</width>
<height>251</height>
</size>
</property>
</spacer>
Expand Down

0 comments on commit b092ae7

Please sign in to comment.