autoproxy detection for given URL in GUI
This commit is contained in:
@@ -67,7 +67,7 @@ namespace proxy {
|
||||
platform's implementation.
|
||||
|
||||
@code
|
||||
proxy::Auto pf; // keep for program life time (because of caching)
|
||||
proxy::Face pf; // keep for program life time (because of caching)
|
||||
proxy::List pf.proxies("http://swisssign.com");
|
||||
[...] // set proxy, read from http://swisssign.com
|
||||
@endcode
|
||||
|
@@ -8,10 +8,12 @@
|
||||
#ifndef PROXY_HXX
|
||||
#define PROXY_HXX
|
||||
|
||||
#include <autoproxy.hxx>
|
||||
#include <ui_proxy.h>
|
||||
#include <QtGui/QDialog>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtNetwork/QNetworkProxy>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
@@ -22,12 +24,14 @@ class Proxy: public QDialog, private Ui::Proxy {
|
||||
|
||||
public:
|
||||
|
||||
Proxy(QWidget* p=0): QDialog(p) {
|
||||
Proxy(QString testUrl, QWidget* p=0): QDialog(p), _testUrl(testUrl){
|
||||
setupUi(this);
|
||||
QSettings s("SwissSign", "ProxySettings");
|
||||
_type->setCurrentIndex(s.value("default-type", 0).toInt());
|
||||
_url->setText(s.value("default-server", QString()).toString());
|
||||
_port->setValue(s.value("default-port", 80).toInt());
|
||||
connect(&_auto, SIGNAL(proxyFound(const QUrl&, const QNetworkProxy&)),
|
||||
SLOT(proxyFound(const QUrl&, const QNetworkProxy&)));
|
||||
accept();
|
||||
}
|
||||
|
||||
@@ -36,8 +40,12 @@ class Proxy: public QDialog, private Ui::Proxy {
|
||||
void acceptValues() {
|
||||
QNetworkProxy::ProxyType type(QNetworkProxy::NoProxy);
|
||||
switch (_type->currentIndex()) {
|
||||
case 0: type=QNetworkProxy::HttpProxy; break;
|
||||
case 1: type=QNetworkProxy::Socks5Proxy; break;
|
||||
case 0: try {
|
||||
type=QNetworkProxy::NoProxy;
|
||||
_auto.proxy(_testUrl);
|
||||
} catch (...) {} break;
|
||||
case 1: type=QNetworkProxy::HttpProxy; break;
|
||||
case 2: type=QNetworkProxy::Socks5Proxy; break;
|
||||
}
|
||||
QNetworkProxy::setApplicationProxy
|
||||
(QNetworkProxy(type, _url->text(), _port->value()));
|
||||
@@ -64,6 +72,10 @@ class Proxy: public QDialog, private Ui::Proxy {
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
void proxyFound(const QUrl&, const QNetworkProxy& p) {
|
||||
QNetworkProxy::setApplicationProxy(p);
|
||||
}
|
||||
|
||||
void on__save_clicked(bool=false) {
|
||||
QSettings s("SwissSign", "ProxySettings");
|
||||
s.setValue("default-type", _type->currentIndex());
|
||||
@@ -86,6 +98,11 @@ class Proxy: public QDialog, private Ui::Proxy {
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
proxy::Face _auto;
|
||||
QUrl _testUrl;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user