gui namespace

master
Marc Wäckerlin 16 years ago
parent ceb2bcca7e
commit 121637835c
  1. 244
      proxyface/proxy.hxx

@ -18,131 +18,135 @@
#include <QtCore/QDebug>
class Proxy: public QDialog, public Ui::Proxy {
namespace gui {
class Proxy: public QDialog, public Ui::Proxy {
Q_OBJECT
Q_OBJECT
public:
public:
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", 0).toInt());
connect(&_auto, SIGNAL(proxyFound(const QUrl&, const QNetworkProxy&)),
SIGNAL(proxyFound(const QUrl&, const QNetworkProxy&)));
connect(&_auto, SIGNAL(proxyFound(const QUrl&, const QNetworkProxy&)),
SLOT(proxyFoundSlot(const QUrl&, const QNetworkProxy&)));
connect(&_auto, SIGNAL(proxyError(QNetworkReply::NetworkError)),
SIGNAL(proxyError(QNetworkReply::NetworkError)));
accept();
}
void checkUrl(const QString& url) {
_testUrl = url;
accept();
}
void acceptValues() {
QNetworkProxy::ProxyType type(QNetworkProxy::NoProxy);
switch (_type->currentIndex()) {
case 0: try {
_url->setEnabled(false);
_port->setEnabled(false);
type=QNetworkProxy::NoProxy;
_auto.proxy(_testUrl);
} catch (...) {} break;
case 1: type=QNetworkProxy::HttpProxy; break;
case 2: type=QNetworkProxy::Socks5Proxy; break;
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", 0).toInt());
connect(&_auto, SIGNAL(proxyFound(const QUrl&, const QNetworkProxy&)),
SIGNAL(proxyFound(const QUrl&, const QNetworkProxy&)));
connect(&_auto, SIGNAL(proxyFound(const QUrl&, const QNetworkProxy&)),
SLOT(proxyFoundSlot(const QUrl&, const QNetworkProxy&)));
connect(&_auto, SIGNAL(proxyError(QNetworkReply::NetworkError)),
SIGNAL(proxyError(QNetworkReply::NetworkError)));
accept();
}
void checkUrl(const QString& url) {
_testUrl = url;
accept();
}
void acceptValues() {
QNetworkProxy::ProxyType type(QNetworkProxy::NoProxy);
switch (_type->currentIndex()) {
case 0: try {
_url->setEnabled(false);
_port->setEnabled(false);
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()));
qDebug()<<"Proxy:"
<<(QNetworkProxy::applicationProxy().type()
==QNetworkProxy::NoProxy
?trUtf8("Kein Proxy")
:QNetworkProxy::applicationProxy().type()
==QNetworkProxy::HttpProxy
?trUtf8("HTTP:")
:QNetworkProxy::applicationProxy().type()
==QNetworkProxy::Socks5Proxy
?trUtf8("Socks5Proxy:")
:trUtf8("System"))
<<(QNetworkProxy::applicationProxy().type()
==QNetworkProxy::NoProxy ||
QNetworkProxy::applicationProxy().type()
==QNetworkProxy::DefaultProxy
?QString()
:trUtf8("%1:%2", "proxy host/port")
.arg(QNetworkProxy::applicationProxy().hostName())
.arg(QNetworkProxy::applicationProxy().port()));
}
Q_SIGNALS:
void proxyFound(const QUrl&, const QNetworkProxy&);
void proxyError(QNetworkReply::NetworkError);
public Q_SLOTS:
void proxyFoundSlot(const QUrl&, const QNetworkProxy& p) {
QNetworkProxy::setApplicationProxy(p);
_url->setText(p.hostName());
_port->setValue(p.port());
qDebug()<<"Auto Proxy Found:"
<<(QNetworkProxy::applicationProxy().type()
==QNetworkProxy::NoProxy
?trUtf8("Kein Proxy")
:QNetworkProxy::applicationProxy().type()
==QNetworkProxy::HttpProxy
?trUtf8("HTTP:")
:QNetworkProxy::applicationProxy().type()
==QNetworkProxy::Socks5Proxy
?trUtf8("Socks5Proxy:")
:trUtf8("System"))
<<(QNetworkProxy::applicationProxy().type()
==QNetworkProxy::NoProxy ||
QNetworkProxy::applicationProxy().type()
==QNetworkProxy::DefaultProxy
?QString()
:trUtf8("%1:%2", "proxy host/port")
.arg(QNetworkProxy::applicationProxy().hostName())
.arg(QNetworkProxy::applicationProxy().port()));
}
void on__type_currentIndexChanged(int index) {
_url->setEnabled(index!=0);
_port->setEnabled(index!=0);
}
void on__save_clicked(bool=false) {
QSettings s("SwissSign", "ProxySettings");
s.setValue("default-type", _type->currentIndex());
s.setValue("default-server", _url->text());
s.setValue("default-port", _port->value());
acceptValues();
}
void on__clear_clicked(bool=false) {
QSettings s("SwissSign", "ProxySettings");
s.clear();
_type->setCurrentIndex(0);
_url->setText("");
_port->setValue(80);
acceptValues();
}
virtual void accept() {
acceptValues();
QDialog::accept();
}
QNetworkProxy::setApplicationProxy
(QNetworkProxy(type, _url->text(), _port->value()));
qDebug()<<"Proxy:"
<<(QNetworkProxy::applicationProxy().type()
==QNetworkProxy::NoProxy
?trUtf8("Kein Proxy")
:QNetworkProxy::applicationProxy().type()
==QNetworkProxy::HttpProxy
?trUtf8("HTTP:")
:QNetworkProxy::applicationProxy().type()
==QNetworkProxy::Socks5Proxy
?trUtf8("Socks5Proxy:")
:trUtf8("System"))
<<(QNetworkProxy::applicationProxy().type()
==QNetworkProxy::NoProxy ||
QNetworkProxy::applicationProxy().type()
==QNetworkProxy::DefaultProxy
?QString()
:trUtf8("%1:%2", "proxy host/port")
.arg(QNetworkProxy::applicationProxy().hostName())
.arg(QNetworkProxy::applicationProxy().port()));
}
Q_SIGNALS:
void proxyFound(const QUrl&, const QNetworkProxy&);
void proxyError(QNetworkReply::NetworkError);
public Q_SLOTS:
void proxyFoundSlot(const QUrl&, const QNetworkProxy& p) {
QNetworkProxy::setApplicationProxy(p);
_url->setText(p.hostName());
_port->setValue(p.port());
qDebug()<<"Auto Proxy Found:"
<<(QNetworkProxy::applicationProxy().type()
==QNetworkProxy::NoProxy
?trUtf8("Kein Proxy")
:QNetworkProxy::applicationProxy().type()
==QNetworkProxy::HttpProxy
?trUtf8("HTTP:")
:QNetworkProxy::applicationProxy().type()
==QNetworkProxy::Socks5Proxy
?trUtf8("Socks5Proxy:")
:trUtf8("System"))
<<(QNetworkProxy::applicationProxy().type()
==QNetworkProxy::NoProxy ||
QNetworkProxy::applicationProxy().type()
==QNetworkProxy::DefaultProxy
?QString()
:trUtf8("%1:%2", "proxy host/port")
.arg(QNetworkProxy::applicationProxy().hostName())
.arg(QNetworkProxy::applicationProxy().port()));
}
void on__type_currentIndexChanged(int index) {
_url->setEnabled(index!=0);
_port->setEnabled(index!=0);
}
void on__save_clicked(bool=false) {
QSettings s("SwissSign", "ProxySettings");
s.setValue("default-type", _type->currentIndex());
s.setValue("default-server", _url->text());
s.setValue("default-port", _port->value());
acceptValues();
}
void on__clear_clicked(bool=false) {
QSettings s("SwissSign", "ProxySettings");
s.clear();
_type->setCurrentIndex(0);
_url->setText("");
_port->setValue(80);
acceptValues();
}
virtual void accept() {
acceptValues();
QDialog::accept();
}
private:
proxy::Face _auto;
QUrl _testUrl;
private:
};
proxy::Face _auto;
QUrl _testUrl;
};
}
#endif

Loading…
Cancel
Save