Merge pull request #3452

1ba3560 [Qt] let OptionsModel::getProxySettings() directly query proxy (Philip Kaufmann)
This commit is contained in:
Wladimir J. van der Laan 2014-01-22 08:55:43 +01:00
commit 2f06b5965a
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
4 changed files with 39 additions and 19 deletions

View File

@ -53,7 +53,6 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool))); connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool)));
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool))); connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool)));
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->socksVersion, SLOT(setEnabled(bool))); connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->socksVersion, SLOT(setEnabled(bool)));
connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning_Proxy()));
ui->proxyIp->installEventFilter(this); ui->proxyIp->installEventFilter(this);
@ -204,7 +203,7 @@ void OptionsDialog::on_resetButton_clicked()
if(btnRetVal == QMessageBox::Cancel) if(btnRetVal == QMessageBox::Cancel)
return; return;
/* reset all options and close Bitcoin-Qt */ /* reset all options and close GUI */
model->Reset(); model->Reset();
QApplication::quit(); QApplication::quit();
} }

View File

@ -19,6 +19,7 @@
#include "walletdb.h" #include "walletdb.h"
#endif #endif
#include <QNetworkProxy>
#include <QSettings> #include <QSettings>
#include <QStringList> #include <QStringList>
@ -375,14 +376,25 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
return successful; return successful;
} }
bool OptionsModel::getProxySettings(QString& proxyIP, quint16 &proxyPort) const bool OptionsModel::getProxySettings(QNetworkProxy& proxy) const
{ {
std::string proxy = GetArg("-proxy", ""); // Directly query current base proxy, because
if (proxy.empty()) return false; // GUI settings can be overridden with -proxy.
proxyType curProxy;
if (GetProxy(NET_IPV4, curProxy)) {
if (curProxy.second == 5) {
proxy.setType(QNetworkProxy::Socks5Proxy);
proxy.setHostName(QString::fromStdString(curProxy.first.ToStringIP()));
proxy.setPort(curProxy.first.GetPort());
return true;
}
else
return false;
}
else
proxy.setType(QNetworkProxy::NoProxy);
CService addrProxy(proxy);
proxyIP = QString(addrProxy.ToStringIP().c_str());
proxyPort = addrProxy.GetPort();
return true; return true;
} }

View File

@ -7,6 +7,10 @@
#include <QAbstractListModel> #include <QAbstractListModel>
QT_BEGIN_NAMESPACE
class QNetworkProxy;
QT_END_NAMESPACE
/** Interface from Qt to configuration data structure for Bitcoin client. /** Interface from Qt to configuration data structure for Bitcoin client.
To Qt, the options are presented as a list with the different options To Qt, the options are presented as a list with the different options
laid out vertically. laid out vertically.
@ -54,7 +58,7 @@ public:
bool getMinimizeOnClose() { return fMinimizeOnClose; } bool getMinimizeOnClose() { return fMinimizeOnClose; }
int getDisplayUnit() { return nDisplayUnit; } int getDisplayUnit() { return nDisplayUnit; }
bool getDisplayAddresses() { return bDisplayAddresses; } bool getDisplayAddresses() { return bDisplayAddresses; }
bool getProxySettings(QString& proxyIP, quint16 &proxyPort) const; bool getProxySettings(QNetworkProxy& proxy) const;
bool getCoinControlFeatures() { return fCoinControlFeatures; } bool getCoinControlFeatures() { return fCoinControlFeatures; }
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; } const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }

View File

@ -335,17 +335,22 @@ void PaymentServer::initNetManager()
// netManager is used to fetch paymentrequests given in bitcoin: URIs // netManager is used to fetch paymentrequests given in bitcoin: URIs
netManager = new QNetworkAccessManager(this); netManager = new QNetworkAccessManager(this);
// Use proxy settings from optionsModel QNetworkProxy proxy;
QString proxyIP;
quint16 proxyPort; // Query active proxy (fails if no SOCKS5 proxy)
if (optionsModel->getProxySettings(proxyIP, proxyPort)) if (optionsModel->getProxySettings(proxy)) {
{ if (proxy.type() == QNetworkProxy::Socks5Proxy) {
QNetworkProxy proxy; netManager->setProxy(proxy);
proxy.setType(QNetworkProxy::Socks5Proxy);
proxy.setHostName(proxyIP); qDebug() << "PaymentServer::initNetManager : Using SOCKS5 proxy" << proxy.hostName() << ":" << proxy.port();
proxy.setPort(proxyPort); }
netManager->setProxy(proxy); else
qDebug() << "PaymentServer::initNetManager : No active proxy server found.";
} }
else
emit message(tr("Net manager warning"),
tr("Your active proxy doesn't support SOCKS5, which is required for payment requests via proxy."),
CClientUIInterface::MSG_WARNING);
connect(netManager, SIGNAL(finished(QNetworkReply*)), connect(netManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(netRequestFinished(QNetworkReply*))); this, SLOT(netRequestFinished(QNetworkReply*)));