diff options
author | David Faure <faure@kde.org> | 2009-08-05 16:05:53 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-31 16:33:33 (GMT) |
commit | aecf60446a0b7f02c3728b0f653ab04f1f45d11c (patch) | |
tree | a4eea5534b249d2118c2b66c64c3a144033b5772 /src/network | |
parent | 25ae1b6fc4d277f337639bc90c3f7df893b867f3 (diff) | |
download | Qt-aecf60446a0b7f02c3728b0f653ab04f1f45d11c.zip Qt-aecf60446a0b7f02c3728b0f653ab04f1f45d11c.tar.gz Qt-aecf60446a0b7f02c3728b0f653ab04f1f45d11c.tar.bz2 |
Add QNetworkProxyFactory::setUseSystemConfigurationEnabled(true)
Simply following the system configuration for the proxy used to require
writing a QNetworkProxyFactory subclass. The static setter makes this
easier, so apps can in one line say "I want to use the system proxy
settings". Solution and method name suggested by Thiago.
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/kernel/qnetworkproxy.cpp | 24 | ||||
-rw-r--r-- | src/network/kernel/qnetworkproxy.h | 1 | ||||
-rw-r--r-- | src/network/kernel/qnetworkproxy_p.h | 85 |
3 files changed, 110 insertions, 0 deletions
diff --git a/src/network/kernel/qnetworkproxy.cpp b/src/network/kernel/qnetworkproxy.cpp index af8d6fb..908f01f 100644 --- a/src/network/kernel/qnetworkproxy.cpp +++ b/src/network/kernel/qnetworkproxy.cpp @@ -220,6 +220,7 @@ #ifndef QT_NO_NETWORKPROXY +#include "private/qnetworkproxy_p.h" #include "private/qsocks5socketengine_p.h" #include "private/qhttpsocketengine_p.h" #include "qauthenticator.h" @@ -1156,6 +1157,29 @@ QNetworkProxyFactory::~QNetworkProxyFactory() { } + +/*! + Enables the use of the platform-specific proxy settings, and only those. + See systemProxyForQuery() for more information. + + Internally, this method (when called with \a enable set to true) + sets an application-wide proxy factory. For this reason, this method + is mutually exclusive with setApplicationProxyFactory: calling + setApplicationProxyFactory overrides the use of the system-wide proxy, + and calling setUseSystemConfigurationEnabled overrides any + application proxy or proxy factory that was previously set. + + \since 4.6 +*/ +void QNetworkProxyFactory::setUseSystemConfigurationEnabled(bool enable) +{ + if (enable) { + setApplicationProxyFactory(new QSystemConfigurationProxyFactory); + } else { + setApplicationProxyFactory(0); + } +} + /*! Sets the application-wide proxy factory to be \a factory. This function will take ownership of that object and will delete it diff --git a/src/network/kernel/qnetworkproxy.h b/src/network/kernel/qnetworkproxy.h index d64ba09..01a88b8 100644 --- a/src/network/kernel/qnetworkproxy.h +++ b/src/network/kernel/qnetworkproxy.h @@ -171,6 +171,7 @@ public: virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery()) = 0; + static void setUseSystemConfigurationEnabled(bool enable); static void setApplicationProxyFactory(QNetworkProxyFactory *factory); static QList<QNetworkProxy> proxyForQuery(const QNetworkProxyQuery &query); static QList<QNetworkProxy> systemProxyForQuery(const QNetworkProxyQuery &query = QNetworkProxyQuery()); diff --git a/src/network/kernel/qnetworkproxy_p.h b/src/network/kernel/qnetworkproxy_p.h new file mode 100644 index 0000000..dce8c84 --- /dev/null +++ b/src/network/kernel/qnetworkproxy_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKPROXY_P_H +#define QNETWORKPROXY_P_H + + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the QLibrary class. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QT_NO_NETWORKPROXY + +QT_BEGIN_NAMESPACE + +class QSystemConfigurationProxyFactory : public QNetworkProxyFactory +{ +public: + QSystemConfigurationProxyFactory() : QNetworkProxyFactory() {} + + virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery& query) + { + QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(query); + + // Make sure NoProxy is in the list, so that QTcpServer can work: + // it searches for the first proxy that can has the ListeningCapability capability + // if none have (as is the case with HTTP proxies), it fails to bind. + // NoProxy allows it to fallback to the 'no proxy' case and bind. + proxies.append(QNetworkProxy::NoProxy); + + return proxies; + } +}; + +QT_END_NAMESPACE + +#endif // QT_NO_NETWORKINTERFACE + +#endif + |