Use uint16_t for port number.
[novacoin.git] / src / qt / optionsmodel.cpp
index 07a2072..56e1df4 100644 (file)
@@ -91,6 +91,14 @@ void OptionsModel::Init()
         SoftSetArg("-tor", settings.value("addrTor").toString().toStdString());
         if (settings.value("fTorOnly").toBool())
             SoftSetArg("-onlynet", "tor");
+
+        if (settings.value("TorName").toString().length() == 22) {
+            std::string strTorName = settings.value("TorName").toString().toStdString();
+
+            CService addrTorName(strTorName, GetListenPort());
+            if (addrTorName.IsValid())
+                SoftSetArg("-torname", strTorName);
+        }
     }
 
     if (settings.contains("detachDB"))
@@ -99,80 +107,6 @@ void OptionsModel::Init()
         SoftSetArg("-lang", language.toStdString());
 }
 
-bool OptionsModel::Upgrade()
-{
-    QSettings settings;
-
-    if (settings.contains("bImportFinished"))
-        return false; // Already upgraded
-
-    settings.setValue("bImportFinished", true);
-
-    // Move settings from old wallet.dat (if any):
-    CWalletDB walletdb(strWalletFileName);
-
-    QList<QString> intOptions;
-    intOptions << "nDisplayUnit" << "nTransactionFee";
-    foreach(QString key, intOptions)
-    {
-        int value = 0;
-        if (walletdb.ReadSetting(key.toStdString(), value))
-        {
-            settings.setValue(key, value);
-            walletdb.EraseSetting(key.toStdString());
-        }
-    }
-    QList<QString> boolOptions;
-    boolOptions << "bDisplayAddresses" << "fMinimizeToTray" << "fMinimizeOnClose" << "fUseProxy" << "fUseTor" << "fTorOnly" << "fUseUPnP";
-    foreach(QString key, boolOptions)
-    {
-        bool value = false;
-        if (walletdb.ReadSetting(key.toStdString(), value))
-        {
-            settings.setValue(key, value);
-            walletdb.EraseSetting(key.toStdString());
-        }
-    }
-    try
-    {
-        CAddress addrProxyAddress, addrTorAddress;
-        if (walletdb.ReadSetting("addrProxy", addrProxyAddress))
-        {
-            settings.setValue("addrProxy", addrProxyAddress.ToStringIPPort().c_str());
-            walletdb.EraseSetting("addrProxy");
-        }
-
-        if (walletdb.ReadSetting("addrTor", addrTorAddress))
-        {
-            settings.setValue("addrTor", addrTorAddress.ToStringIPPort().c_str());
-            walletdb.EraseSetting("addrTor");
-        }
-    }
-    catch (std::ios_base::failure &e)
-    {
-        // 0.6.0rc1 saved this as a CService, which causes failure when parsing as a CAddress
-        CService addrProxy, addrTor;
-        if (walletdb.ReadSetting("addrProxy", addrProxy))
-        {
-            settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str());
-            walletdb.EraseSetting("addrProxy");
-        }
-
-        if (walletdb.ReadSetting("addrTor", addrTor))
-        {
-            settings.setValue("addrTor", addrTor.ToStringIPPort().c_str());
-            walletdb.EraseSetting("addrTor");
-        }
-    }
-
-    ApplyProxySettings();
-    ApplyTorSettings();
-    Init();
-
-    return true;
-}
-
-
 int OptionsModel::rowCount(const QModelIndex & parent) const
 {
     return OptionIDRowCount;
@@ -207,7 +141,7 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
             if (GetProxy(NET_IPV4, proxy))
                 return QVariant(proxy.first.GetPort());
             else
-                return QVariant(9050);
+                return QVariant(nSocksDefault);
         }
         case ProxySocksVersion:
             return settings.value("nSocksVersion", 5);
@@ -225,10 +159,12 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
             if (GetProxy(NET_TOR, proxy))
                 return QVariant(proxy.first.GetPort());
             else
-                return QVariant(9050);
+                return QVariant(nSocksDefault);
         }
         case TorOnly:
             return settings.value("fTorOnly", false);
+        case TorName:
+            return settings.value("TorName", "");
         case Fee:
             return QVariant(static_cast<qlonglong>(nTransactionFee));
         case DisplayUnit:
@@ -280,7 +216,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
             break;
         case ProxyIP: {
             proxyType proxy;
-            proxy.first = CService("127.0.0.1", 9050);
+            proxy.first = CService("127.0.0.1", nSocksDefault);
             GetProxy(NET_IPV4, proxy);
 
             CNetAddr addr(value.toString().toStdString());
@@ -291,7 +227,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
         break;
         case ProxyPort: {
             proxyType proxy;
-            proxy.first = CService("127.0.0.1", 9050);
+            proxy.first = CService("127.0.0.1", nSocksDefault);
             GetProxy(NET_IPV4, proxy);
 
             proxy.first.SetPort(value.toInt());
@@ -316,8 +252,8 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
         break;
         case TorIP: {
             proxyType proxy;
-            proxy.first = CService("127.0.0.1", 9050);
-            GetProxy(NET_IPV4, proxy);
+            proxy.first = CService("127.0.0.1", nSocksDefault);
+            GetProxy(NET_TOR, proxy);
 
             CNetAddr addr(value.toString().toStdString());
             proxy.first.SetIP(addr);
@@ -327,10 +263,10 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
         break;
         case TorPort: {
             proxyType proxy;
-            proxy.first = CService("127.0.0.1", 9050);
-            GetProxy(NET_IPV4, proxy);
+            proxy.first = CService("127.0.0.1", nSocksDefault);
+            GetProxy(NET_TOR, proxy);
 
-            proxy.first.SetPort(value.toInt());
+            proxy.first.SetPort((uint16_t)value.toUInt());
             settings.setValue("addrTor", proxy.first.ToStringIPPort().c_str());
             successful = ApplyTorSettings();
         }
@@ -339,6 +275,9 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
             settings.setValue("fTorOnly", value.toBool());
             ApplyTorSettings();
         }
+        case TorName: {
+            settings.setValue("TorName", value.toString());
+        }
         break;
         case Fee:
             nTransactionFee = value.toLongLong();