diff options
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/optionsdialog.cpp | 2 | ||||
-rw-r--r-- | src/qt/optionsmodel.cpp | 70 | ||||
-rw-r--r-- | src/qt/optionsmodel.h | 3 |
3 files changed, 58 insertions, 17 deletions
diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 7c6ad087cb..50374ddc4b 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -390,7 +390,7 @@ void NetworkOptionsPage::setMapper(MonitoredDataMapper *mapper) { // Map model to widgets mapper->addMapping(map_port_upnp, OptionsModel::MapPortUPnP); - mapper->addMapping(connect_socks4, OptionsModel::ConnectSOCKS4); + mapper->addMapping(connect_socks4, OptionsModel::ProxyUse); mapper->addMapping(proxy_ip, OptionsModel::ProxyIP); mapper->addMapping(proxy_port, OptionsModel::ProxyPort); } 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 { diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index c0374689c6..c74a8dfb43 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -20,7 +20,8 @@ public: MinimizeToTray, // bool MapPortUPnP, // bool MinimizeOnClose, // bool - ConnectSOCKS4, // bool + ProxyUse, // bool + ProxySocksVersion, // int ProxyIP, // QString ProxyPort, // QString Fee, // qint64 |