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