From 4a10d4c6dcd04eb2496257754782150793ce53b1 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 25 Feb 2012 20:59:18 +0100 Subject: Fix addrProxy setting Before 0.6 addrProxy was a CAddress, but netbase changed it to CService. Retain compatibility by wrapping/unwrapping with a CAddress when saving or loading. This commit retains compatibility with 0.6.0rc1 (which wrote the setting as a CService) by trying to parse twice. --- src/qt/optionsmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/qt') diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index edc1d61e9d..dd69093897 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -91,7 +91,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in if (addr.IsValid()) { addrProxy.SetIP(addr); - walletdb.WriteSetting("addrProxy", addrProxy); + walletdb.WriteSetting("addrProxy", CAddress(addrProxy)); } else { @@ -105,7 +105,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in if (nPort > 0 && nPort < std::numeric_limits::max()) { addrProxy.SetPort(nPort); - walletdb.WriteSetting("addrProxy", addrProxy); + walletdb.WriteSetting("addrProxy", CAddress(addrProxy)); } else { -- cgit v1.2.3 From 3f8cb2c565b24635d2967c9900cf5f2aa8b1d632 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Thu, 16 Feb 2012 21:09:41 -0500 Subject: Reworked QT settings --- src/qt/bitcoin.cpp | 27 +++++++++-- src/qt/optionsmodel.cpp | 124 ++++++++++++++++++++++++++++++++++++++---------- src/qt/optionsmodel.h | 13 +++-- 3 files changed, 131 insertions(+), 33 deletions(-) (limited to 'src/qt') diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 03b89f06fc..5e79f6ec98 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -152,8 +152,28 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(bitcoin); QApplication app(argc, argv); + // Command-line options take precedence: ParseParameters(argc, argv); + // ... then bitcoin.conf: + if (!ReadConfigFile(mapArgs, mapMultiArgs)) + { + fprintf(stderr, "Error: Specified directory does not exist\n"); + return 1; + } + + // Application identification (must be set before OptionsModel is initialized, + // as it is used to locate QSettings) + app.setOrganizationName("Bitcoin"); + app.setOrganizationDomain("bitcoin.org"); + if(GetBoolArg("-testnet")) // Separate UI settings for testnet + app.setApplicationName("Bitcoin-Qt-testnet"); + else + app.setApplicationName("Bitcoin-Qt"); + + // ... then GUI settings: + OptionsModel optionsModel; + // Get desired locale ("en_US") from command line or system locale QString lang_territory = QString::fromStdString(GetArg("-lang", QLocale::system().name().toStdString())); // Load language files for configured locale: @@ -180,8 +200,6 @@ int main(int argc, char *argv[]) if (!translator.isEmpty()) app.installTranslator(&translator); - app.setApplicationName(QApplication::translate("main", "Bitcoin-Qt")); - QSplashScreen splash(QPixmap(":/images/splash"), 0); if (GetBoolArg("-splash", true) && !GetBoolArg("-min")) { @@ -201,10 +219,13 @@ int main(int argc, char *argv[]) { // Put this in a block, so that BitcoinGUI is cleaned up properly before // calling Shutdown() in case of exceptions. + + optionsModel.Upgrade(); // Must be done after AppInit2 + BitcoinGUI window; if (splashref) splash.finish(&window); - OptionsModel optionsModel(pwalletMain); + ClientModel clientModel(&optionsModel); WalletModel walletModel(pwalletMain, &optionsModel); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index dd69093897..417e2b8646 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -1,21 +1,94 @@ #include "optionsmodel.h" #include "bitcoinunits.h" +#include #include "headers.h" #include "init.h" -OptionsModel::OptionsModel(CWallet *wallet, QObject *parent) : - QAbstractListModel(parent), - wallet(wallet), - nDisplayUnit(BitcoinUnits::BTC), - bDisplayAddresses(false) +OptionsModel::OptionsModel(QObject *parent) : + QAbstractListModel(parent) { - // Read our specific settings from the wallet db - CWalletDB walletdb(wallet->strWalletFile); - walletdb.ReadSetting("nDisplayUnit", nDisplayUnit); - walletdb.ReadSetting("bDisplayAddresses", bDisplayAddresses); + Init(); } +void OptionsModel::Init() +{ + QSettings settings; + + // These are QT-only settings: + nDisplayUnit = settings.value("nDisplayUnit", BitcoinUnits::BTC).toInt(); + bDisplayAddresses = settings.value("bDisplayAddresses", false).toBool(); + fMinimizeToTray = settings.value("fMinimizeToTray", false).toBool(); + fMinimizeOnClose = settings.value("fMinimizeOnClose", false).toBool(); + nTransactionFee = settings.value("nTransactionFee").toLongLong(); + + // These are shared with core bitcoin; we want + // command-line options to override the GUI settings: + if (settings.contains("fUseUPnP")) + SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()); + if (settings.contains("addrProxy") && settings.value("fUseProxy").toBool()) + SoftSetArg("-proxy", settings.value("addrProxy").toString().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("wallet.dat"); + + QList 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 boolOptions; + boolOptions << "bDisplayAddresses" << "fMinimizeToTray" << "fMinimizeOnClose" << "fUseProxy" << "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; + if (walletdb.ReadSetting("addrProxy", addrProxyAddress)) + { + addrProxy = addrProxyAddress; + settings.setValue("addrProxy", addrProxy.ToStringIP().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 + if (walletdb.ReadSetting("addrProxy", addrProxy)) + { + settings.setValue("addrProxy", addrProxy.ToStringIP().c_str()); + walletdb.EraseSetting("addrProxy"); + } + } + Init(); + + return true; +} + + int OptionsModel::rowCount(const QModelIndex & parent) const { return OptionIDRowCount; @@ -25,6 +98,7 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const { if(role == Qt::EditRole) { + QSettings settings; switch(index.row()) { case StartAtStartup: @@ -32,11 +106,11 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const case MinimizeToTray: return QVariant(fMinimizeToTray); case MapPortUPnP: - return QVariant(fUseUPnP); + return settings.value("fUseUPnP", GetBoolArg("-upnp", true)); case MinimizeOnClose: return QVariant(fMinimizeOnClose); case ConnectSOCKS4: - return QVariant(fUseProxy); + return settings.value("fUseProxy", false); case ProxyIP: return QVariant(QString::fromStdString(addrProxy.ToStringIP())); case ProxyPort: @@ -59,7 +133,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in bool successful = true; /* set to false on parse error */ if(role == Qt::EditRole) { - CWalletDB walletdb(wallet->strWalletFile); + QSettings settings; switch(index.row()) { case StartAtStartup: @@ -67,22 +141,22 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in break; case MinimizeToTray: fMinimizeToTray = value.toBool(); - walletdb.WriteSetting("fMinimizeToTray", fMinimizeToTray); + settings.setValue("fMinimizeToTray", fMinimizeToTray); break; case MapPortUPnP: - fUseUPnP = value.toBool(); - walletdb.WriteSetting("fUseUPnP", fUseUPnP); -#ifdef USE_UPNP - MapPort(fUseUPnP); -#endif + { + bool bUseUPnP = value.toBool(); + settings.setValue("fUseUPnP", bUseUPnP); + MapPort(bUseUPnP); + } break; case MinimizeOnClose: fMinimizeOnClose = value.toBool(); - walletdb.WriteSetting("fMinimizeOnClose", fMinimizeOnClose); + settings.setValue("fMinimizeOnClose", fMinimizeOnClose); break; case ConnectSOCKS4: fUseProxy = value.toBool(); - walletdb.WriteSetting("fUseProxy", fUseProxy); + settings.setValue("fUseProxy", fUseProxy); break; case ProxyIP: { @@ -91,7 +165,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in if (addr.IsValid()) { addrProxy.SetIP(addr); - walletdb.WriteSetting("addrProxy", CAddress(addrProxy)); + settings.setValue("addrProxy", addrProxy.ToStringIP().c_str()); } else { @@ -105,7 +179,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in if (nPort > 0 && nPort < std::numeric_limits::max()) { addrProxy.SetPort(nPort); - walletdb.WriteSetting("addrProxy", CAddress(addrProxy)); + settings.setValue("addrProxy", addrProxy.ToStringIP().c_str()); } else { @@ -115,18 +189,18 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in break; case Fee: { nTransactionFee = value.toLongLong(); - walletdb.WriteSetting("nTransactionFee", nTransactionFee); + settings.setValue("nTransactionFee", nTransactionFee); } break; case DisplayUnit: { int unit = value.toInt(); nDisplayUnit = unit; - walletdb.WriteSetting("nDisplayUnit", nDisplayUnit); + settings.setValue("nDisplayUnit", nDisplayUnit); emit displayUnitChanged(unit); } case DisplayAddresses: { bDisplayAddresses = value.toBool(); - walletdb.WriteSetting("bDisplayAddresses", bDisplayAddresses); + settings.setValue("bDisplayAddresses", bDisplayAddresses); } default: break; diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 775362d636..0be70f8935 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -3,8 +3,6 @@ #include -class CWallet; - /** Interface from QT to configuration data structure for bitcoin client. To QT, the options are presented as a list with the different options laid out vertically. @@ -15,7 +13,7 @@ class OptionsModel : public QAbstractListModel { Q_OBJECT public: - explicit OptionsModel(CWallet *wallet, QObject *parent = 0); + explicit OptionsModel(QObject *parent = 0); enum OptionID { StartAtStartup, // bool @@ -31,6 +29,11 @@ public: OptionIDRowCount }; + void Init(); + + /* Migrate settings from wallet.dat after app initialization */ + bool Upgrade(); /* returns true if settings upgraded */ + int rowCount(const QModelIndex & parent = QModelIndex()) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); @@ -42,10 +45,10 @@ public: int getDisplayUnit(); bool getDisplayAddresses(); private: - // Wallet stores persistent options - CWallet *wallet; int nDisplayUnit; bool bDisplayAddresses; + bool fMinimizeToTray; + bool fMinimizeOnClose; signals: void displayUnitChanged(int unit); -- cgit v1.2.3 From 42c8b56f62af171ee1e14963df301358970b1525 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 26 Feb 2012 23:39:32 +0100 Subject: Store addrProxy port in settings --- src/qt/optionsmodel.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/qt') diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 417e2b8646..ed2225cbf5 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -70,7 +70,7 @@ bool OptionsModel::Upgrade() if (walletdb.ReadSetting("addrProxy", addrProxyAddress)) { addrProxy = addrProxyAddress; - settings.setValue("addrProxy", addrProxy.ToStringIP().c_str()); + settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str()); walletdb.EraseSetting("addrProxy"); } } @@ -79,7 +79,7 @@ bool OptionsModel::Upgrade() // 0.6.0rc1 saved this as a CService, which causes failure when parsing as a CAddress if (walletdb.ReadSetting("addrProxy", addrProxy)) { - settings.setValue("addrProxy", addrProxy.ToStringIP().c_str()); + settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str()); walletdb.EraseSetting("addrProxy"); } } @@ -165,7 +165,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in if (addr.IsValid()) { addrProxy.SetIP(addr); - settings.setValue("addrProxy", addrProxy.ToStringIP().c_str()); + settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str()); } else { @@ -179,7 +179,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in if (nPort > 0 && nPort < std::numeric_limits::max()) { addrProxy.SetPort(nPort); - settings.setValue("addrProxy", addrProxy.ToStringIP().c_str()); + settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str()); } else { -- cgit v1.2.3