From d38de9cacf2cb956fa7d3783137d79ce48a46164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Tue, 3 Aug 2010 14:12:04 +0000 Subject: [PATCH] new dialog and new library, refs #6 --- proxyface/autoproxy.hxx | 102 ++++++++++++++++++++++++++++++---------- proxyface/proxy.hxx | 78 +++++++++++++++++++++++------- proxyface/proxy_de.ts | 33 +++++++++++++ proxyface/proxy_en.ts | 33 +++++++++++++ proxyface/proxy_fr.ts | 33 +++++++++++++ proxyface/proxy_it.ts | 33 +++++++++++++ proxyface/qtproxy.hxx | 5 ++ 7 files changed, 277 insertions(+), 40 deletions(-) diff --git a/proxyface/autoproxy.hxx b/proxyface/autoproxy.hxx index 6595ba1..7479cb0 100644 --- a/proxyface/autoproxy.hxx +++ b/proxyface/autoproxy.hxx @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,8 @@ //! auto proxy configuration namespace proxy { + + std::string version(); //! exceptions namespace exc { @@ -95,7 +98,11 @@ namespace proxy { #endif public: //! Keep your instance as long as possible, because of caching. - Interface() { + Interface() +#ifdef QT_NETWORK_LIB + : _timeout1Paused(false), _timeout2Paused(false) +#endif + { #ifdef QT_NETWORK_LIB PROXYFACE_LOG; if (!connect(&_timeout1, SIGNAL(timeout()), SLOT(timeout()))) @@ -121,6 +128,35 @@ namespace proxy { clean(it->second.first); _requests.clear(); } + + //! Pause timeouts and restart them later. + /*! Use while waiting for user input at proxy authentication. + @see restart() */ + void pause() { + if (_timeout1.isActive()) { + _timeout1.stop(); + _timeout1Paused = true; + } + if (_timeout2.isActive()) { + _timeout2.stop(); + _timeout2Paused = true; + } + } + + //! Restart paused timeouts. + /*! Use while waiting for user input at proxy authentication. + @see pause() */ + void restart() { + if (_timeout1Paused) { + _timeout1.start(); + _timeout1Paused = false; + } + if (_timeout2Paused) { + _timeout2.start(); + _timeout2Paused = false; + } + } + //! Network Ping: Check access to a given address using default proxy. void ping(const std::string& url, int timeout2=30000) { if (_requests.size() || _timeout1.isActive() || _timeout2.isActive()) @@ -214,6 +250,8 @@ namespace proxy { void proxyError(QNetworkReply::NetworkError); //! Signals an error during proxy detection. void temporaryError(QNetworkReply::NetworkError, QString, QString); + void authenticationRequired(QNetworkReply*, QAuthenticator*); + void proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*); private: void setupProxyCheck(const QNetworkProxy& prxy, const std::string& url) { PROXYFACE_LOG; @@ -223,17 +261,26 @@ namespace proxy { if (!connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(replyFinished(QNetworkReply*)))) qFatal("connect failed"); - connect(manager, - SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), - SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*))); - connect(manager, - SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, - QAuthenticator*)), - SLOT(proxyAuthenticationRequired(const QNetworkProxy&, - QAuthenticator*))); - connect(manager, - SIGNAL(sslErrors(QNetworkReply*, const QList&)), - SLOT(sslErrors(QNetworkReply*, const QList&))); + if (!connect(manager, + SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), + SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)))) + qFatal("connect failed"); + if (!connect(manager, + SIGNAL(proxyAuthenticationRequired + (const QNetworkProxy&, QAuthenticator*)), + SIGNAL(proxyAuthenticationRequired + (const QNetworkProxy&, QAuthenticator*)))) + qFatal("connect failed"); + if (!connect(manager, + SIGNAL(proxyAuthenticationRequired + (const QNetworkProxy&, QAuthenticator*)), + SLOT(proxyAuthenticationRequiredLog + (const QNetworkProxy&, QAuthenticator*)))) + qFatal("connect failed"); + if (!connect(manager, + SIGNAL(sslErrors(QNetworkReply*, const QList&)), + SLOT(sslErrors(QNetworkReply*, const QList&)))) + qFatal("connect failed"); _requests.insert (std::make_pair(manager->head (QNetworkRequest @@ -248,14 +295,20 @@ namespace proxy { SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), this, - SLOT(authenticationRequired(QNetworkReply*, - QAuthenticator*))); + SIGNAL(authenticationRequired(QNetworkReply*, + QAuthenticator*))); + disconnect(manager, + SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, + QAuthenticator*)), + this, + SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, + QAuthenticator*))); disconnect(manager, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)), this, - SLOT(proxyAuthenticationRequired(const QNetworkProxy&, - QAuthenticator*))); + SLOT(proxyAuthenticationRequiredLog(const QNetworkProxy&, + QAuthenticator*))); disconnect(manager, SIGNAL(sslErrors(QNetworkReply*, const QList&)), this, @@ -263,6 +316,13 @@ namespace proxy { //delete manager; } private Q_SLOTS: + void proxyAuthenticationRequiredLog(const QNetworkProxy&, + QAuthenticator* auth) { + qDebug()<<"proxyAuthenticationRequired for "<realm(); + } + void bullshit() { + qDebug()<<"SCHEISSE"; + } void timeout() { PROXYFACE_LOG; reset(); @@ -297,14 +357,6 @@ namespace proxy { <<"url="<& l) { PROXYFACE_LOG; qDebug()<<"## "<<__PRETTY_FUNCTION__; @@ -344,6 +396,8 @@ namespace proxy { bool _direct; QTimer _timeout1; QTimer _timeout2; + bool _timeout1Paused; + bool _timeout2Paused; List _proxies; std::string _url; #endif diff --git a/proxyface/proxy.hxx b/proxyface/proxy.hxx index b689e7a..67383aa 100644 --- a/proxyface/proxy.hxx +++ b/proxyface/proxy.hxx @@ -10,14 +10,18 @@ #include #include +#include + #include #include #include #include +#include #include #include #include +#include namespace gui { @@ -31,13 +35,18 @@ namespace gui { QDialog(p), _lastDefaultProxy(QNetworkProxy()) { setupUi(this); _testUrl->insertItem(0, testUrl); - QMovie *m(new QMovie(":/icons/indicator.gif")); - _internetWait->setMovie(m); - m->start(); + _internetWait->setPixmap(QPixmap(":/icons/indicator.gif")); + _internetWait->setMovie(new QMovie(":/icons/indicator.gif")); + _internetWait->movie()->start(); QSettings s("SwissSign", "ProxySettings"); + _save->setChecked(s.contains("default-type")); _type->setCurrentIndex(s.value("default-type", 0).toInt()); _url->setText(s.value("default-server", QString()).toString()); _port->setValue(s.value("default-port", 0).toInt()); + _lastDefaultProxy = QNetworkProxy(); + _lastType = _type->currentIndex(); + _lastUrl = _url->text(); + _lastPort = _port->value(); connect(&_auto, SIGNAL(proxyFound(const QUrl&, const QNetworkProxy&)), SIGNAL(proxyFound(const QUrl&, const QNetworkProxy&))); connect(&_auto, SIGNAL(proxyFound(const QUrl&, const QNetworkProxy&)), @@ -50,6 +59,14 @@ namespace gui { QString, QString)), SIGNAL(temporaryError(QNetworkReply::NetworkError, QString, QString))); + connect(&_auto, SIGNAL(proxyAuthenticationRequired + (const QNetworkProxy&, QAuthenticator*)), + SLOT(proxyAuthenticationRequired(const QNetworkProxy&, + QAuthenticator*))); + connect(&_auto, SIGNAL(authenticationRequired + (const QNetworkProxy&, QAuthenticator*)), + SLOT(authenticationRequired(const QNetworkProxy&, + QAuthenticator*))); acceptValues(); } @@ -65,10 +82,18 @@ namespace gui { } void retry() { - acceptValues(true); + on__test_clicked(); + } + + void reset() { + _type->setCurrentIndex(_lastType); + _url->setText(_lastUrl); + _port->setValue(_lastPort); + QNetworkProxy::setApplicationProxy(_lastDefaultProxy); + acceptValues(); } - void acceptValues(bool retry=false) { + void acceptValues() { on__test_clicked(); switch (_type->currentIndex()) { case 0: try { @@ -91,10 +116,6 @@ namespace gui { _lastType = _type->currentIndex(); _lastUrl = _url->text(); _lastPort = _port->value(); - if (!retry) { - _stackInternet->setCurrentIndex(WAITING_FOR_SERVER); - detecting(); - } } Q_SIGNALS: @@ -105,14 +126,40 @@ namespace gui { void temporaryError(QNetworkReply::NetworkError, QString, QString); public Q_SLOTS: - + + void proxyAuthenticationRequired(const QNetworkProxy& p, + QAuthenticator* auth) { + static ProxyAuth proxyAuth(this); + proxyAuth._realm->setText(auth->realm()); + _auto.pause(); + qDebug()<<"---> proxyAuthenticationRequired"; + if (proxyAuth.exec()==QDialog::Accepted) { + auth->setUser(proxyAuth._username->text()); + auth->setPassword(proxyAuth._password->text()); + qDebug()<<"Setting authentication to:" + <user()<password(); + } + qDebug()<<"---> done: proxyAuthenticationRequired"; + _auto.restart(); + } + + void authenticationRequired(const QNetworkProxy& p, + QAuthenticator* auth) { + static ProxyAuth proxyAuth(this); + proxyAuth._realm->setText(auth->realm()); + if (proxyAuth.exec()) { + auth->setUser(proxyAuth._username->text()); + auth->setPassword(proxyAuth._password->text()); + } + } + void proxyFoundSlot(const QUrl&, const QNetworkProxy& p) { _stackInternet->setCurrentIndex(SERVER_FOUND); QNetworkProxy prx(p.type()==QNetworkProxy::DefaultProxy ?QNetworkProxy::applicationProxy():p); if (prx.type()==QNetworkProxy::DefaultProxy) return; - _url->setText(prx.hostName()); - _port->setValue(prx.port()); + if (!_url->isEnabled()) _url->setText(prx.hostName()); + if (!_port->isEnabled()) _port->setValue(prx.port()); if (p.type()==QNetworkProxy::DefaultProxy) return; QNetworkProxy::setApplicationProxy(prx); } @@ -128,6 +175,8 @@ namespace gui { void on__test_clicked() { _auto.reset(); + _stackInternet->setCurrentIndex(WAITING_FOR_SERVER); + detecting(); switch (_type->currentIndex()) { case 0: try { QNetworkProxy::setApplicationProxy @@ -155,10 +204,7 @@ namespace gui { } virtual void reject() { - _type->setCurrentIndex(_lastType); - _url->setText(_lastUrl); - _port->setValue(_lastPort); - QNetworkProxy::setApplicationProxy(_lastDefaultProxy); + reset(); QDialog::reject(); } diff --git a/proxyface/proxy_de.ts b/proxyface/proxy_de.ts index ebddbc0..600b03a 100644 --- a/proxyface/proxy_de.ts +++ b/proxyface/proxy_de.ts @@ -150,6 +150,39 @@ Entfernen + + ProxyAuth + + + + Proxy Authentication + + + + + + Please logon to: + + + + + + ... + + + + + + Username: + + + + + + Password: + + + gui::Proxy diff --git a/proxyface/proxy_en.ts b/proxyface/proxy_en.ts index 308453a..b8c3595 100644 --- a/proxyface/proxy_en.ts +++ b/proxyface/proxy_en.ts @@ -150,6 +150,39 @@ Remove + + ProxyAuth + + + + Proxy Authentication + + + + + + Please logon to: + + + + + + ... + + + + + + Username: + + + + + + Password: + + + gui::Proxy diff --git a/proxyface/proxy_fr.ts b/proxyface/proxy_fr.ts index 42d8ed4..f028b50 100644 --- a/proxyface/proxy_fr.ts +++ b/proxyface/proxy_fr.ts @@ -150,6 +150,39 @@ Enlever + + ProxyAuth + + + + Proxy Authentication + + + + + + Please logon to: + + + + + + ... + + + + + + Username: + + + + + + Password: + + + gui::Proxy diff --git a/proxyface/proxy_it.ts b/proxyface/proxy_it.ts index f6c5352..804a491 100644 --- a/proxyface/proxy_it.ts +++ b/proxyface/proxy_it.ts @@ -150,6 +150,39 @@ Eliminazione + + ProxyAuth + + + + Proxy Authentication + + + + + + Please logon to: + + + + + + ... + + + + + + Username: + + + + + + Password: + + + gui::Proxy diff --git a/proxyface/qtproxy.hxx b/proxyface/qtproxy.hxx index e7cae2e..c87f174 100644 --- a/proxyface/qtproxy.hxx +++ b/proxyface/qtproxy.hxx @@ -26,6 +26,9 @@ namespace proxy { //! Implemented using Qt System Proxy virtual List proxies(const std::string& url) { + + qDebug()<<"************ QTPROXY ********************"; + qDebug()<<"************ QTPROXY ********************"; List res; @@ -45,6 +48,8 @@ namespace proxy { case QNetworkProxy::FtpCachingProxy: type=HTTP; } + qDebug()<hostName()).arg(proxy->port()); res.push_back (Proxy(type, proxy->hostName().toStdString(), proxy->port())); }