aboutsummaryrefslogtreecommitdiff
path: root/src/qt/optionsmodel.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-06-04 14:15:19 -0400
committerGavin Andresen <gavinandresen@gmail.com>2012-06-04 14:15:19 -0400
commit46e06b875d861661c4a3002e8ae3d080b5893053 (patch)
treea22d1310831e7cd5494141a4e07e6e8182854d6f /src/qt/optionsmodel.cpp
parent9f46a3e32abf516fafabeda08a21cc69af876113 (diff)
parent587f929c6462698a674fe8add2f301161219d05a (diff)
Merge branch 'netopt' of https://github.com/sipa/bitcoin
Diffstat (limited to 'src/qt/optionsmodel.cpp')
-rw-r--r--src/qt/optionsmodel.cpp70
1 files changed, 55 insertions, 15 deletions
diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp
index e110cfa6af..e65694bb52 100644
--- a/src/qt/optionsmodel.cpp
+++ b/src/qt/optionsmodel.cpp
@@ -12,6 +12,29 @@ OptionsModel::OptionsModel(QObject *parent) :
Init();
}
+bool static ApplyProxySettings()
+{
+ QSettings settings;
+ CService addrProxy(settings.value("addrProxy", "127.0.0.1:9050").toString().toStdString());
+ int nSocksVersion(settings.value("nSocksVersion", 5).toInt());
+ if (!settings.value("fUseProxy", false).toBool()) {
+ addrProxy = CService();
+ nSocksVersion = 0;
+ }
+ if (nSocksVersion && !addrProxy.IsValid())
+ return false;
+ if (!IsLimited(NET_IPV4))
+ SetProxy(NET_IPV4, addrProxy, nSocksVersion);
+ if (nSocksVersion > 4) {
+#ifdef USE_IPV6
+ if (!IsLimited(NET_IPV6))
+ SetProxy(NET_IPV6, addrProxy, nSocksVersion);
+#endif
+ SetNameProxy(addrProxy, nSocksVersion);
+ }
+ return true;
+}
+
void OptionsModel::Init()
{
QSettings settings;
@@ -75,20 +98,21 @@ bool OptionsModel::Upgrade()
CAddress addrProxyAddress;
if (walletdb.ReadSetting("addrProxy", addrProxyAddress))
{
- addrProxy = addrProxyAddress;
- settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str());
+ settings.setValue("addrProxy", addrProxyAddress.ToStringIPPort().c_str());
walletdb.EraseSetting("addrProxy");
}
}
catch (std::ios_base::failure &e)
{
// 0.6.0rc1 saved this as a CService, which causes failure when parsing as a CAddress
+ CService addrProxy;
if (walletdb.ReadSetting("addrProxy", addrProxy))
{
settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str());
walletdb.EraseSetting("addrProxy");
}
}
+ ApplyProxySettings();
Init();
return true;
@@ -115,12 +139,24 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return settings.value("fUseUPnP", GetBoolArg("-upnp", true));
case MinimizeOnClose:
return QVariant(fMinimizeOnClose);
- case ConnectSOCKS4:
+ case ProxyUse:
return settings.value("fUseProxy", false);
- case ProxyIP:
- return QVariant(QString::fromStdString(addrProxy.ToStringIP()));
- case ProxyPort:
- return QVariant(addrProxy.GetPort());
+ case ProxySocksVersion:
+ return settings.value("nSocksVersion", false);
+ case ProxyIP: {
+ CService addrProxy;
+ if (GetProxy(NET_IPV4, addrProxy))
+ return QVariant(QString::fromStdString(addrProxy.ToStringIP()));
+ else
+ return QVariant(QString::fromStdString("localhost"));
+ }
+ case ProxyPort: {
+ CService addrProxy;
+ if (GetProxy(NET_IPV4, addrProxy))
+ return QVariant(addrProxy.GetPort());
+ else
+ return 9050;
+ }
case Fee:
return QVariant(nTransactionFee);
case DisplayUnit:
@@ -137,7 +173,6 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
}
return QVariant();
}
-
bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
bool successful = true; /* set to false on parse error */
@@ -155,27 +190,29 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
break;
case MapPortUPnP:
{
- bool bUseUPnP = value.toBool();
- settings.setValue("fUseUPnP", bUseUPnP);
- MapPort(bUseUPnP);
+ fUseUPnP = value.toBool();
+ settings.setValue("fUseUPnP", fUseUPnP);
+ MapPort();
}
break;
case MinimizeOnClose:
fMinimizeOnClose = value.toBool();
settings.setValue("fMinimizeOnClose", fMinimizeOnClose);
break;
- case ConnectSOCKS4:
- fUseProxy = value.toBool();
- settings.setValue("fUseProxy", fUseProxy);
+ case ProxyUse:
+ settings.setValue("fUseProxy", value.toBool());
+ ApplyProxySettings();
break;
case ProxyIP:
{
- // Use CAddress to parse and check IP
+ CService addrProxy("127.0.0.1", 9050);
+ GetProxy(NET_IPV4, addrProxy);
CNetAddr addr(value.toString().toStdString());
if (addr.IsValid())
{
addrProxy.SetIP(addr);
settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str());
+ successful = ApplyProxySettings();
}
else
{
@@ -185,11 +222,14 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
break;
case ProxyPort:
{
+ CService addrProxy("127.0.0.1", 9050);
+ GetProxy(NET_IPV4, addrProxy);
int nPort = atoi(value.toString().toAscii().data());
if (nPort > 0 && nPort < std::numeric_limits<unsigned short>::max())
{
addrProxy.SetPort(nPort);
settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str());
+ successful = ApplyProxySettings();
}
else
{