Skip to content

Commit

Permalink
add support for proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jan 10, 2017
1 parent b74aefd commit 68e09d4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/gui/qgshelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <QFileInfo>
#include <QTcpSocket>
#include <QDesktopServices>
#include <QNetworkProxy>
#include <QNetworkProxyFactory>

#include "qgis.h"
#include "qgsapplication.h"
Expand Down Expand Up @@ -104,6 +106,50 @@ bool QgsHelp::urlExists( const QString& url )
QUrl helpUrl( url );
QTcpSocket socket;

QSettings settings;
bool proxyEnabled = settings.value( QStringLiteral( "proxy/proxyEnabled" ), false ).toBool();
if ( proxyEnabled )
{
QNetworkProxy proxy;
QString proxyHost = settings.value( QStringLiteral( "proxy/proxyHost" ), QString() ).toString();
int proxyPort = settings.value( QStringLiteral( "proxy/proxyPort" ), QString() ).toString().toInt();
QString proxyUser = settings.value( QStringLiteral( "proxy/proxyUser" ), QString() ).toString();
QString proxyPassword = settings.value( QStringLiteral( "proxy/proxyPassword" ), QString() ).toString();

QString proxyTypeString = settings.value( QStringLiteral( "proxy/proxyType" ), QString() ).toString();

if ( proxyTypeString == QLatin1String( "DefaultProxy" ) )
{
QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery();
if ( !proxies.isEmpty() )
{
proxy = proxies.first();
}
}
else
{
QNetworkProxy::ProxyType proxyType = QNetworkProxy::DefaultProxy;
if ( proxyTypeString == QLatin1String( "Socks5Proxy" ) )
{
proxyType = QNetworkProxy::Socks5Proxy;
}
else if ( proxyTypeString == QLatin1String( "HttpProxy" ) )
{
proxyType = QNetworkProxy::HttpProxy;
}
else if ( proxyTypeString == QLatin1String( "HttpCachingProxy" ) )
{
proxyType = QNetworkProxy::HttpCachingProxy;
}
else if ( proxyTypeString == QLatin1String( "FtpCachingProxy" ) )
{
proxyType = QNetworkProxy::FtpCachingProxy;
}
proxy = QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword );
}
socket.setProxy( proxy );
}

socket.connectToHost( helpUrl.host(), 80 );
if ( socket.waitForConnected() )
{
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgshelp.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <QtCore>

#include "qgis_gui.h"

/** \ingroup gui
* \class QgsHelp
* @brief Helper class for showing help topic URI for the given key.
Expand Down

0 comments on commit 68e09d4

Please sign in to comment.