diff --git a/autoproxy.hxx b/autoproxy.hxx index 4929639..9635a13 100644 --- a/autoproxy.hxx +++ b/autoproxy.hxx @@ -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 diff --git a/proxyface/gui/proxy.hxx b/proxyface/gui/proxy.hxx index c41cf85..8ca9ba7 100644 --- a/proxyface/gui/proxy.hxx +++ b/proxyface/gui/proxy.hxx @@ -8,10 +8,12 @@ #ifndef PROXY_HXX #define PROXY_HXX +#include #include #include #include #include +#include #include #include @@ -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