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. 25
      src/qt/paymentserver.cpp

3
src/qt/optionsdialog.cpp

@ -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();
} }

24
src/qt/optionsmodel.cpp

@ -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;
} }

6
src/qt/optionsmodel.h

@ -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; }

25
src/qt/paymentserver.cpp

@ -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*)));

Loading…
Cancel
Save