Skip to content

Commit

Permalink
network manager: support system proxy settings on windows (fixes #8600)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 16, 2014
1 parent ba47c9f commit 7f9a755
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 24 deletions.
66 changes: 42 additions & 24 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5765,8 +5765,8 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
if ( pkAttrList.contains( dst ) )
{
dstAttr[ dst ] = pasteVectorLayer->dataProvider()->defaultValue( dst );
if( !dstAttr[ dst ].isNull() )
continue;
if ( !dstAttr[ dst ].isNull() )
continue;
}

dstAttr[ dst ] = srcAttr[ src ];
Expand Down Expand Up @@ -7251,7 +7251,7 @@ void QgisApp::openURL( QString url, bool useQgisDocDirectory )
OSStatus status = LSOpenCFURLRef( urlRef, NULL );
status = 0; //avoid compiler warning
CFRelease( urlRef );
#elif defined(WIN32)
#elif defined(Q_OS_WIN)
if ( url.startsWith( "file://", Qt::CaseInsensitive ) )
ShellExecute( 0, 0, url.mid( 7 ).toLocal8Bit().constData(), 0, 0, SW_SHOWNORMAL );
else
Expand Down Expand Up @@ -9190,7 +9190,7 @@ void QgisApp::keyPressEvent( QKeyEvent * e )
{
stopRendering();
}
#if defined(Q_OS_WIN)&& defined(QGISDEBUG)
#if defined(Q_OS_WIN) && defined(QGISDEBUG)
else if ( e->key() == Qt::Key_Backslash && e->modifiers() & Qt::ControlModifier )
{
qgisCrashDump( 0 );
Expand Down Expand Up @@ -9480,6 +9480,14 @@ void QgisApp::namAuthenticationRequired( QNetworkReply *reply, QAuthenticator *a

void QgisApp::namProxyAuthenticationRequired( const QNetworkProxy &proxy, QAuthenticator *auth )
{
QSettings settings;
if ( !settings.value( "proxy/proxyEnabled", false ).toBool() ||
settings.value( "proxy/proxyType", "" ).toString() == "DefaultProxy" )
{
auth->setUser( "" );
return;
}

QString username = auth->user();
QString password = auth->password();

Expand Down Expand Up @@ -9554,29 +9562,39 @@ void QgisApp::namUpdate()
if ( proxyTypeString == "DefaultProxy" )
{
proxyType = QNetworkProxy::DefaultProxy;

#if defined(Q_OS_WIN)
QNetworkProxyFactory::setUseSystemConfiguration( true );
QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery();
if ( !proxies.isEmpty() )
{
proxy = proxies.first();
}
#endif

QgsDebugMsg( "setting default proxy" );
}
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" )
else
{
proxyType = QNetworkProxy::FtpCachingProxy;
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;
}

proxy = QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword );
}
QgsDebugMsg( QString( "setting proxy %1 %2:%3 %4/%5" )
.arg( proxyType )
.arg( proxyHost ).arg( proxyPort )
.arg( proxyUser ).arg( proxyPassword )
);
proxy = QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword );
}

#if QT_VERSION >= 0x40500
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsnetworkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ const QNetworkProxy &QgsNetworkAccessManager::fallbackProxy() const

void QgsNetworkAccessManager::setFallbackProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes )
{
QgsDebugMsg( QString( "proxy settings: (type:%1 host: %2:%3, user:%4, password:%5" )
.arg( proxy.type() == QNetworkProxy::DefaultProxy ? "DefaultProxy" :
proxy.type() == QNetworkProxy::Socks5Proxy ? "Socks5Proxy" :
proxy.type() == QNetworkProxy::NoProxy ? "NoProxy" :
proxy.type() == QNetworkProxy::HttpProxy ? "HttpProxy" :
proxy.type() == QNetworkProxy::HttpCachingProxy ? "HttpCachingProxy" :
proxy.type() == QNetworkProxy::FtpCachingProxy ? "FtpCachingProxy" :
"Undefined" )
.arg( proxy.hostName() )
.arg( proxy.port() )
.arg( proxy.user() )
.arg( proxy.password().isEmpty() ? "not set" : "set" ) );

mFallbackProxy = proxy;
mExcludedURLs = excludes;
}
Expand Down

0 comments on commit 7f9a755

Please sign in to comment.