new dialog and new library, refs #6
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <QtNetwork/QNetworkProxy>
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QtNetwork/QAuthenticator>
|
||||
#include <QtNetwork/QSslError>
|
||||
#include <QtNetwork/QHostInfo>
|
||||
#include <QtCore/QTimer>
|
||||
@@ -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<QSslError>&)),
|
||||
SLOT(sslErrors(QNetworkReply*, const QList<QSslError>&)));
|
||||
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<QSslError>&)),
|
||||
SLOT(sslErrors(QNetworkReply*, const QList<QSslError>&))))
|
||||
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,
|
||||
SLOT(proxyAuthenticationRequired(const QNetworkProxy&,
|
||||
QAuthenticator*)));
|
||||
SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&,
|
||||
QAuthenticator*)));
|
||||
disconnect(manager,
|
||||
SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&,
|
||||
QAuthenticator*)),
|
||||
this,
|
||||
SLOT(proxyAuthenticationRequiredLog(const QNetworkProxy&,
|
||||
QAuthenticator*)));
|
||||
disconnect(manager,
|
||||
SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)),
|
||||
this,
|
||||
@@ -263,6 +316,13 @@ namespace proxy {
|
||||
//delete manager;
|
||||
}
|
||||
private Q_SLOTS:
|
||||
void proxyAuthenticationRequiredLog(const QNetworkProxy&,
|
||||
QAuthenticator* auth) {
|
||||
qDebug()<<"proxyAuthenticationRequired for "<<auth->realm();
|
||||
}
|
||||
void bullshit() {
|
||||
qDebug()<<"SCHEISSE";
|
||||
}
|
||||
void timeout() {
|
||||
PROXYFACE_LOG;
|
||||
reset();
|
||||
@@ -297,14 +357,6 @@ namespace proxy {
|
||||
<<"url="<<url<<"proxy="<<toString(prxy);
|
||||
proxyFound(url, prxy);
|
||||
}
|
||||
void authenticationRequired(QNetworkReply*, QAuthenticator*) {
|
||||
PROXYFACE_LOG;
|
||||
qDebug()<<"## "<<__PRETTY_FUNCTION__;
|
||||
}
|
||||
void proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*) {
|
||||
PROXYFACE_LOG;
|
||||
qDebug()<<"## "<<__PRETTY_FUNCTION__;
|
||||
}
|
||||
void sslErrors(QNetworkReply*, const QList<QSslError>& 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
|
||||
|
@@ -10,14 +10,18 @@
|
||||
|
||||
#include <proxyface/autoproxy.hxx>
|
||||
#include <proxyface/ui_proxy.hxx>
|
||||
#include <proxyface/proxyauth.hxx>
|
||||
|
||||
#include <QtGui/QMovie>
|
||||
#include <QtGui/QDialog>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtNetwork/QNetworkProxy>
|
||||
#include <QtNetwork/QAuthenticator>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <cassert>
|
||||
|
||||
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:"
|
||||
<<auth->user()<<auth->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();
|
||||
}
|
||||
|
||||
|
@@ -150,6 +150,39 @@
|
||||
<translation type="obsolete">Entfernen</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ProxyAuth</name>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="14"/>
|
||||
<location filename="ui_proxyauth.hxx" line="106"/>
|
||||
<source>Proxy Authentication</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="20"/>
|
||||
<location filename="ui_proxyauth.hxx" line="107"/>
|
||||
<source>Please logon to:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="27"/>
|
||||
<location filename="ui_proxyauth.hxx" line="108"/>
|
||||
<source>...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="36"/>
|
||||
<location filename="ui_proxyauth.hxx" line="109"/>
|
||||
<source>Username:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="46"/>
|
||||
<location filename="ui_proxyauth.hxx" line="110"/>
|
||||
<source>Password:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>gui::Proxy</name>
|
||||
<message>
|
||||
|
@@ -150,6 +150,39 @@
|
||||
<translation type="obsolete">Remove</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ProxyAuth</name>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="14"/>
|
||||
<location filename="ui_proxyauth.hxx" line="106"/>
|
||||
<source>Proxy Authentication</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="20"/>
|
||||
<location filename="ui_proxyauth.hxx" line="107"/>
|
||||
<source>Please logon to:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="27"/>
|
||||
<location filename="ui_proxyauth.hxx" line="108"/>
|
||||
<source>...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="36"/>
|
||||
<location filename="ui_proxyauth.hxx" line="109"/>
|
||||
<source>Username:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="46"/>
|
||||
<location filename="ui_proxyauth.hxx" line="110"/>
|
||||
<source>Password:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>gui::Proxy</name>
|
||||
<message>
|
||||
|
@@ -150,6 +150,39 @@
|
||||
<translation type="obsolete">Enlever</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ProxyAuth</name>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="14"/>
|
||||
<location filename="ui_proxyauth.hxx" line="106"/>
|
||||
<source>Proxy Authentication</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="20"/>
|
||||
<location filename="ui_proxyauth.hxx" line="107"/>
|
||||
<source>Please logon to:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="27"/>
|
||||
<location filename="ui_proxyauth.hxx" line="108"/>
|
||||
<source>...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="36"/>
|
||||
<location filename="ui_proxyauth.hxx" line="109"/>
|
||||
<source>Username:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="46"/>
|
||||
<location filename="ui_proxyauth.hxx" line="110"/>
|
||||
<source>Password:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>gui::Proxy</name>
|
||||
<message>
|
||||
|
@@ -150,6 +150,39 @@
|
||||
<translation type="obsolete">Eliminazione</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ProxyAuth</name>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="14"/>
|
||||
<location filename="ui_proxyauth.hxx" line="106"/>
|
||||
<source>Proxy Authentication</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="20"/>
|
||||
<location filename="ui_proxyauth.hxx" line="107"/>
|
||||
<source>Please logon to:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="27"/>
|
||||
<location filename="ui_proxyauth.hxx" line="108"/>
|
||||
<source>...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="36"/>
|
||||
<location filename="ui_proxyauth.hxx" line="109"/>
|
||||
<source>Username:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="proxyauth.ui" line="46"/>
|
||||
<location filename="ui_proxyauth.hxx" line="110"/>
|
||||
<source>Password:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>gui::Proxy</name>
|
||||
<message>
|
||||
|
@@ -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()<<QString("************ QTPROXY: %1:%2")
|
||||
.arg(proxy->hostName()).arg(proxy->port());
|
||||
res.push_back
|
||||
(Proxy(type, proxy->hostName().toStdString(), proxy->port()));
|
||||
}
|
||||
|
Reference in New Issue
Block a user