Browse Source

optionsmodel cleanup

- cleanup optionsmodel before adding new proxy options
- place SOCKS version stuff below proxy port (IP, Port, SOCKS version)
- simplyfy some parts of the code (e.g. don't check IP and port, as this
  is done in optionsdialog anyway, remove unneeded {} in switch/case)
- small cosmetic changes in the header for better readability
0.8
Philip Kaufmann 13 years ago
parent
commit
144bfd9c53
  1. 48
      src/qt/optionsmodel.cpp
  2. 8
      src/qt/optionsmodel.h

48
src/qt/optionsmodel.cpp

@ -144,8 +144,6 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return QVariant(fMinimizeOnClose); return QVariant(fMinimizeOnClose);
case ProxyUse: case ProxyUse:
return settings.value("fUseProxy", false); return settings.value("fUseProxy", false);
case ProxySocksVersion:
return settings.value("nSocksVersion", 5);
case ProxyIP: { case ProxyIP: {
CService addrProxy; CService addrProxy;
if (GetProxy(NET_IPV4, addrProxy)) if (GetProxy(NET_IPV4, addrProxy))
@ -160,6 +158,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
else else
return 9050; return 9050;
} }
case ProxySocksVersion:
return settings.value("nSocksVersion", 5);
case Fee: case Fee:
return QVariant(nTransactionFee); return QVariant(nTransactionFee);
case DisplayUnit: case DisplayUnit:
@ -192,11 +192,9 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
settings.setValue("fMinimizeToTray", fMinimizeToTray); settings.setValue("fMinimizeToTray", fMinimizeToTray);
break; break;
case MapPortUPnP: case MapPortUPnP:
{
fUseUPnP = value.toBool(); fUseUPnP = value.toBool();
settings.setValue("fUseUPnP", fUseUPnP); settings.setValue("fUseUPnP", fUseUPnP);
MapPort(); MapPort();
}
break; break;
case MinimizeOnClose: case MinimizeOnClose:
fMinimizeOnClose = value.toBool(); fMinimizeOnClose = value.toBool();
@ -206,60 +204,41 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
settings.setValue("fUseProxy", value.toBool()); settings.setValue("fUseProxy", value.toBool());
ApplyProxySettings(); ApplyProxySettings();
break; break;
case ProxySocksVersion:
settings.setValue("nSocksVersion", value.toInt());
ApplyProxySettings();
break;
case ProxyIP: case ProxyIP:
{ {
CService addrProxy("127.0.0.1", 9050); CService addrProxy("127.0.0.1", 9050);
GetProxy(NET_IPV4, addrProxy); GetProxy(NET_IPV4, addrProxy);
CNetAddr addr(value.toString().toStdString()); CNetAddr addr(value.toString().toStdString());
if (addr.IsValid())
{
addrProxy.SetIP(addr); addrProxy.SetIP(addr);
settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str()); settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str());
successful = ApplyProxySettings(); successful = ApplyProxySettings();
} }
else
{
successful = false;
}
}
break; break;
case ProxyPort: case ProxyPort:
{ {
CService addrProxy("127.0.0.1", 9050); CService addrProxy("127.0.0.1", 9050);
GetProxy(NET_IPV4, addrProxy); GetProxy(NET_IPV4, addrProxy);
int nPort = atoi(value.toString().toAscii().data()); addrProxy.SetPort(value.toInt());
if (nPort > 0 && nPort < std::numeric_limits<unsigned short>::max())
{
addrProxy.SetPort(nPort);
settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str()); settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str());
successful = ApplyProxySettings(); successful = ApplyProxySettings();
} }
else
{
successful = false;
}
}
break; break;
case Fee: { case ProxySocksVersion:
settings.setValue("nSocksVersion", value.toInt());
ApplyProxySettings();
break;
case Fee:
nTransactionFee = value.toLongLong(); nTransactionFee = value.toLongLong();
settings.setValue("nTransactionFee", nTransactionFee); settings.setValue("nTransactionFee", nTransactionFee);
}
break; break;
case DisplayUnit: { case DisplayUnit:
int unit = value.toInt(); nDisplayUnit = value.toInt();
nDisplayUnit = unit;
settings.setValue("nDisplayUnit", nDisplayUnit); settings.setValue("nDisplayUnit", nDisplayUnit);
emit displayUnitChanged(unit); emit displayUnitChanged(nDisplayUnit);
}
break; break;
case DisplayAddresses: { case DisplayAddresses:
bDisplayAddresses = value.toBool(); bDisplayAddresses = value.toBool();
settings.setValue("bDisplayAddresses", bDisplayAddresses); settings.setValue("bDisplayAddresses", bDisplayAddresses);
}
break; break;
case DetachDatabases: { case DetachDatabases: {
bool fDetachDB = value.toBool(); bool fDetachDB = value.toBool();
@ -267,9 +246,8 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
settings.setValue("detachDB", fDetachDB); settings.setValue("detachDB", fDetachDB);
} }
break; break;
case Language: { case Language:
settings.setValue("language", value); settings.setValue("language", value);
}
break; break;
default: default:
break; break;

8
src/qt/optionsmodel.h

@ -12,6 +12,7 @@
class OptionsModel : public QAbstractListModel class OptionsModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit OptionsModel(QObject *parent = 0); explicit OptionsModel(QObject *parent = 0);
@ -21,9 +22,9 @@ public:
MapPortUPnP, // bool MapPortUPnP, // bool
MinimizeOnClose, // bool MinimizeOnClose, // bool
ProxyUse, // bool ProxyUse, // bool
ProxySocksVersion, // int
ProxyIP, // QString ProxyIP, // QString
ProxyPort, // int ProxyPort, // int
ProxySocksVersion, // int
Fee, // qint64 Fee, // qint64
DisplayUnit, // BitcoinUnits::Unit DisplayUnit, // BitcoinUnits::Unit
DisplayAddresses, // bool DisplayAddresses, // bool
@ -48,17 +49,16 @@ public:
int getDisplayUnit(); int getDisplayUnit();
bool getDisplayAddresses(); bool getDisplayAddresses();
QString getLanguage() { return language; } QString getLanguage() { return language; }
private: private:
int nDisplayUnit; int nDisplayUnit;
bool bDisplayAddresses; bool bDisplayAddresses;
bool fMinimizeToTray; bool fMinimizeToTray;
bool fMinimizeOnClose; bool fMinimizeOnClose;
QString language; QString language;
signals: signals:
void displayUnitChanged(int unit); void displayUnitChanged(int unit);
public slots:
}; };
#endif // OPTIONSMODEL_H #endif // OPTIONSMODEL_H

Loading…
Cancel
Save