Browse Source

[Qt] let OptionsModel::getProxySettings() directly query proxy

- as a proxy set via GUI can be overridden via -proxy, directly query the
  core to get active proxy
- give a warning, if active proxy is not SOCKS5 (needs to be SOCKS5 for
  the Qt networking code to work)
- also remove an obsolete connect() call from optionsdialog.cpp and a
  reference to Bitcoin-Qt (now just GUI)
0.10
Philip Kaufmann 11 years ago
parent
commit
1ba3560fe8
  1. 3
      src/qt/optionsdialog.cpp
  2. 24
      src/qt/optionsmodel.cpp
  3. 6
      src/qt/optionsmodel.h
  4. 21
      src/qt/paymentserver.cpp

3
src/qt/optionsdialog.cpp

@ -53,7 +53,6 @@ OptionsDialog::OptionsDialog(QWidget *parent) : @@ -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->proxyPort, 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);
@ -204,7 +203,7 @@ void OptionsDialog::on_resetButton_clicked() @@ -204,7 +203,7 @@ void OptionsDialog::on_resetButton_clicked()
if(btnRetVal == QMessageBox::Cancel)
return;
/* reset all options and close Bitcoin-Qt */
/* reset all options and close GUI */
model->Reset();
QApplication::quit();
}

24
src/qt/optionsmodel.cpp

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
#include "walletdb.h"
#endif
#include <QNetworkProxy>
#include <QSettings>
#include <QStringList>
@ -375,14 +376,25 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in @@ -375,14 +376,25 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
return successful;
}
bool OptionsModel::getProxySettings(QString& proxyIP, quint16 &proxyPort) const
bool OptionsModel::getProxySettings(QNetworkProxy& proxy) const
{
std::string proxy = GetArg("-proxy", "");
if (proxy.empty()) return false;
// Directly query current base proxy, because
// 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;
}

6
src/qt/optionsmodel.h

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

21
src/qt/paymentserver.cpp

@ -335,17 +335,22 @@ void PaymentServer::initNetManager() @@ -335,17 +335,22 @@ void PaymentServer::initNetManager()
// netManager is used to fetch paymentrequests given in bitcoin: URIs
netManager = new QNetworkAccessManager(this);
// Use proxy settings from optionsModel
QString proxyIP;
quint16 proxyPort;
if (optionsModel->getProxySettings(proxyIP, proxyPort))
{
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::Socks5Proxy);
proxy.setHostName(proxyIP);
proxy.setPort(proxyPort);
// Query active proxy (fails if no SOCKS5 proxy)
if (optionsModel->getProxySettings(proxy)) {
if (proxy.type() == QNetworkProxy::Socks5Proxy) {
netManager->setProxy(proxy);
qDebug() << "PaymentServer::initNetManager : Using SOCKS5 proxy" << proxy.hostName() << ":" << proxy.port();
}
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*)),
this, SLOT(netRequestFinished(QNetworkReply*)));

Loading…
Cancel
Save