Skip to content

Commit 68e09d4

Browse files
committedJan 10, 2017
add support for proxies
1 parent b74aefd commit 68e09d4

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
 

‎src/gui/qgshelp.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <QFileInfo>
2222
#include <QTcpSocket>
2323
#include <QDesktopServices>
24+
#include <QNetworkProxy>
25+
#include <QNetworkProxyFactory>
2426

2527
#include "qgis.h"
2628
#include "qgsapplication.h"
@@ -104,6 +106,50 @@ bool QgsHelp::urlExists( const QString& url )
104106
QUrl helpUrl( url );
105107
QTcpSocket socket;
106108

109+
QSettings settings;
110+
bool proxyEnabled = settings.value( QStringLiteral( "proxy/proxyEnabled" ), false ).toBool();
111+
if ( proxyEnabled )
112+
{
113+
QNetworkProxy proxy;
114+
QString proxyHost = settings.value( QStringLiteral( "proxy/proxyHost" ), QString() ).toString();
115+
int proxyPort = settings.value( QStringLiteral( "proxy/proxyPort" ), QString() ).toString().toInt();
116+
QString proxyUser = settings.value( QStringLiteral( "proxy/proxyUser" ), QString() ).toString();
117+
QString proxyPassword = settings.value( QStringLiteral( "proxy/proxyPassword" ), QString() ).toString();
118+
119+
QString proxyTypeString = settings.value( QStringLiteral( "proxy/proxyType" ), QString() ).toString();
120+
121+
if ( proxyTypeString == QLatin1String( "DefaultProxy" ) )
122+
{
123+
QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery();
124+
if ( !proxies.isEmpty() )
125+
{
126+
proxy = proxies.first();
127+
}
128+
}
129+
else
130+
{
131+
QNetworkProxy::ProxyType proxyType = QNetworkProxy::DefaultProxy;
132+
if ( proxyTypeString == QLatin1String( "Socks5Proxy" ) )
133+
{
134+
proxyType = QNetworkProxy::Socks5Proxy;
135+
}
136+
else if ( proxyTypeString == QLatin1String( "HttpProxy" ) )
137+
{
138+
proxyType = QNetworkProxy::HttpProxy;
139+
}
140+
else if ( proxyTypeString == QLatin1String( "HttpCachingProxy" ) )
141+
{
142+
proxyType = QNetworkProxy::HttpCachingProxy;
143+
}
144+
else if ( proxyTypeString == QLatin1String( "FtpCachingProxy" ) )
145+
{
146+
proxyType = QNetworkProxy::FtpCachingProxy;
147+
}
148+
proxy = QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword );
149+
}
150+
socket.setProxy( proxy );
151+
}
152+
107153
socket.connectToHost( helpUrl.host(), 80 );
108154
if ( socket.waitForConnected() )
109155
{

‎src/gui/qgshelp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include <QtCore>
2020

21+
#include "qgis_gui.h"
22+
2123
/** \ingroup gui
2224
* \class QgsHelp
2325
* @brief Helper class for showing help topic URI for the given key.

0 commit comments

Comments
 (0)
Please sign in to comment.