diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoinrpc.cpp | 12 | ||||
-rw-r--r-- | src/db.cpp | 33 | ||||
-rw-r--r-- | src/db.h | 8 | ||||
-rw-r--r-- | src/init.cpp | 33 | ||||
-rw-r--r-- | src/main.cpp | 39 | ||||
-rw-r--r-- | src/main.h | 20 | ||||
-rw-r--r-- | src/net.cpp | 12 | ||||
-rw-r--r-- | src/qt/bitcoin.cpp | 27 | ||||
-rw-r--r-- | src/qt/bitcoingui.cpp | 53 | ||||
-rw-r--r-- | src/qt/bitcoingui.h | 7 | ||||
-rw-r--r-- | src/qt/optionsmodel.cpp | 124 | ||||
-rw-r--r-- | src/qt/optionsmodel.h | 13 | ||||
-rw-r--r-- | src/qt/qtipcserver.cpp | 5 | ||||
-rw-r--r-- | src/util.cpp | 18 | ||||
-rw-r--r-- | src/util.h | 2 |
15 files changed, 230 insertions, 176 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index c677b174ca..68cc17b518 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -301,7 +301,7 @@ Value getgenerate(const Array& params, bool fHelp) "getgenerate\n" "Returns true or false."); - return (bool)fGenerateBitcoins; + return GetBoolArg("-gen"); } @@ -320,13 +320,11 @@ Value setgenerate(const Array& params, bool fHelp) if (params.size() > 1) { int nGenProcLimit = params[1].get_int(); - fLimitProcessors = (nGenProcLimit != -1); - WriteSetting("fLimitProcessors", fLimitProcessors); - if (nGenProcLimit != -1) - WriteSetting("nLimitProcessors", nLimitProcessors = nGenProcLimit); + mapArgs["-genproclimit"] = itostr(nGenProcLimit); if (nGenProcLimit == 0) fGenerate = false; } + mapArgs["-gen"] = (fGenerate ? "1" : "0"); GenerateBitcoins(fGenerate, pwalletMain); return Value::null; @@ -385,8 +383,8 @@ Value getmininginfo(const Array& params, bool fHelp) obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx)); obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("errors", GetWarnings("statusbar"))); - obj.push_back(Pair("generate", (bool)fGenerateBitcoins)); - obj.push_back(Pair("genproclimit", (int)(fLimitProcessors ? nLimitProcessors : -1))); + obj.push_back(Pair("generate", GetBoolArg("-gen"))); + obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1))); obj.push_back(Pair("hashespersec", gethashespersec(params, false))); obj.push_back(Pair("pooledtx", (uint64_t)nPooledTx)); obj.push_back(Pair("testnet", fTestNet)); diff --git a/src/db.cpp b/src/db.cpp index ea6d46a6e5..b77a038b41 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -768,13 +768,6 @@ int CWalletDB::LoadWallet(CWallet* pwallet) vector<uint256> vWalletUpgrade; bool fIsEncrypted = false; - // Modify defaults -#ifndef WIN32 - // Tray icon sometimes disappears on 9.10 karmic koala 64-bit, leaving no way to access the program - fMinimizeToTray = false; - fMinimizeOnClose = false; -#endif - //// todo: shouldn't we catch exceptions and try to recover and continue? CRITICAL_BLOCK(pwallet->cs_wallet) { @@ -916,24 +909,6 @@ int CWalletDB::LoadWallet(CWallet* pwallet) if (nFileVersion == 10300) nFileVersion = 300; } - else if (strType == "setting") - { - string strKey; - ssKey >> strKey; - - // Options -#ifndef QT_GUI - if (strKey == "fGenerateBitcoins") ssValue >> fGenerateBitcoins; -#endif - if (strKey == "nTransactionFee") ssValue >> nTransactionFee; - if (strKey == "fLimitProcessors") ssValue >> fLimitProcessors; - if (strKey == "nLimitProcessors") ssValue >> nLimitProcessors; - if (strKey == "fMinimizeToTray") ssValue >> fMinimizeToTray; - if (strKey == "fMinimizeOnClose") ssValue >> fMinimizeOnClose; - if (strKey == "fUseProxy") ssValue >> fUseProxy; - if (strKey == "addrProxy") ssValue >> addrProxy; - if (fHaveUPnP && strKey == "fUseUPnP") ssValue >> fUseUPnP; - } else if (strType == "minversion") { int nMinVersion = 0; @@ -959,14 +934,6 @@ int CWalletDB::LoadWallet(CWallet* pwallet) WriteTx(hash, pwallet->mapWallet[hash]); printf("nFileVersion = %d\n", nFileVersion); - printf("fGenerateBitcoins = %d\n", fGenerateBitcoins); - printf("nTransactionFee = %"PRI64d"\n", nTransactionFee); - printf("fMinimizeToTray = %d\n", fMinimizeToTray); - printf("fMinimizeOnClose = %d\n", fMinimizeOnClose); - printf("fUseProxy = %d\n", fUseProxy); - printf("addrProxy = %s\n", addrProxy.ToString().c_str()); - if (fHaveUPnP) - printf("fUseUPnP = %d\n", fUseUPnP); // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc: @@ -473,18 +473,24 @@ public: return Erase(std::make_pair(std::string("pool"), nPool)); } + // Settings are no longer stored in wallet.dat; these are + // used only for backwards compatibility: template<typename T> bool ReadSetting(const std::string& strKey, T& value) { return Read(std::make_pair(std::string("setting"), strKey), value); } - template<typename T> bool WriteSetting(const std::string& strKey, const T& value) { nWalletDBUpdated++; return Write(std::make_pair(std::string("setting"), strKey), value); } + bool EraseSetting(const std::string& strKey) + { + nWalletDBUpdated++; + return Erase(std::make_pair(std::string("setting"), strKey)); + } bool WriteMinVersion(int nVersion) { diff --git a/src/init.cpp b/src/init.cpp index 3a8fcdf524..8fe0f90b19 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -150,27 +150,15 @@ bool AppInit2(int argc, char* argv[]) // // Parameters // - // If Qt is used, parameters are parsed in qt/bitcoin.cpp's main() + // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main() #if !defined(QT_GUI) ParseParameters(argc, argv); -#endif - - if (mapArgs.count("-datadir")) + if (!ReadConfigFile(mapArgs, mapMultiArgs)) { - if (filesystem::is_directory(filesystem::system_complete(mapArgs["-datadir"]))) - { - filesystem::path pathDataDir = filesystem::system_complete(mapArgs["-datadir"]); - strlcpy(pszSetDataDir, pathDataDir.string().c_str(), sizeof(pszSetDataDir)); - } - else - { - fprintf(stderr, "Error: Specified directory does not exist\n"); - Shutdown(NULL); - } + fprintf(stderr, "Error: Specified directory does not exist\n"); + Shutdown(NULL); } - - - ReadConfigFile(mapArgs, mapMultiArgs); // Must be done after processing datadir +#endif if (mapArgs.count("-?") || mapArgs.count("--help")) { @@ -473,8 +461,6 @@ bool AppInit2(int argc, char* argv[]) return false; } - fGenerateBitcoins = GetBoolArg("-gen"); - if (mapArgs.count("-proxy")) { fUseProxy = true; @@ -507,7 +493,7 @@ bool AppInit2(int argc, char* argv[]) if (fTestNet) SoftSetArg("-paytoscripthashtime", "1329264000"); // Feb 15 else - SoftSetArg("-paytoscripthashtime", "1330578000"); // Mar 1 + SoftSetArg("-paytoscripthashtime", "1333238400"); // April 1 2012 // Put "/P2SH/" in the coinbase so everybody can tell when // a majority of miners support it @@ -520,13 +506,6 @@ bool AppInit2(int argc, char* argv[]) COINBASE_FLAGS << std::vector<unsigned char>(pszP2SH, pszP2SH+strlen(pszP2SH)); } - // Command-line args override in-wallet settings: -#if USE_UPNP - fUseUPnP = GetBoolArg("-upnp", true); -#else - fUseUPnP = GetBoolArg("-upnp", false); -#endif - if (!fNoListen) { std::string strError; diff --git a/src/main.cpp b/src/main.cpp index a9311e2ceb..5de4b8c3b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,22 +57,12 @@ CScript COINBASE_FLAGS; const string strMessageMagic = "Bitcoin Signed Message:\n"; - double dHashesPerSec; int64 nHPSTimerStart; // Settings -int fGenerateBitcoins = false; int64 nTransactionFee = 0; -int fLimitProcessors = false; -int nLimitProcessors = 1; -int fMinimizeToTray = true; -int fMinimizeOnClose = true; -#if USE_UPNP -int fUseUPnP = true; -#else -int fUseUPnP = false; -#endif + ////////////////////////////////////////////////////////////////////////////// @@ -1138,7 +1128,14 @@ bool CTransaction::ConnectInputs(MapPrevTx inputs, { // Verify signature if (!VerifySignature(txPrev, *this, i, fStrictPayToScriptHash, 0)) + { + // only during transition phase for P2SH: do not invoke anti-DoS code for + // potentially old clients relaying bad P2SH transactions + if (fStrictPayToScriptHash && VerifySignature(txPrev, *this, i, false, 0)) + return error("ConnectInputs() : %s P2SH VerifySignature failed", GetHash().ToString().substr(0,10).c_str()); + return DoS(100,error("ConnectInputs() : %s VerifySignature failed", GetHash().ToString().substr(0,10).c_str())); + } } // Mark outpoints as spent @@ -2107,7 +2104,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe; if (pfrom->nVersion < 209) { - // Since Februari 20, 2012, the protocol is initiated at version 209, + // Since February 20, 2012, the protocol is initiated at version 209, // and earlier versions are no longer supported printf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString().c_str(), pfrom->nVersion); pfrom->fDisconnect = true; @@ -3289,6 +3286,10 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey) void static ThreadBitcoinMiner(void* parg); +static bool fGenerateBitcoins = false; +static bool fLimitProcessors = false; +static int nLimitProcessors = -1; + void static BitcoinMiner(CWallet *pwallet) { printf("BitcoinMiner started\n"); @@ -3464,13 +3465,13 @@ void static ThreadBitcoinMiner(void* parg) void GenerateBitcoins(bool fGenerate, CWallet* pwallet) { - if (fGenerateBitcoins != fGenerate) - { - fGenerateBitcoins = fGenerate; - WriteSetting("fGenerateBitcoins", fGenerateBitcoins); - MainFrameRepaint(); - } - if (fGenerateBitcoins) + fGenerateBitcoins = fGenerate; + nLimitProcessors = GetArg("-genproclimit", -1); + if (nLimitProcessors == 0) + fGenerateBitcoins = false; + fLimitProcessors = (nLimitProcessors != -1); + + if (fGenerate) { int nProcessors = boost::thread::hardware_concurrency(); printf("%d processors\n", nProcessors); diff --git a/src/main.h b/src/main.h index d9f976c217..ac6d624e40 100644 --- a/src/main.h +++ b/src/main.h @@ -77,13 +77,7 @@ extern CCriticalSection cs_setpwalletRegistered; extern std::set<CWallet*> setpwalletRegistered; // Settings -extern int fGenerateBitcoins; extern int64 nTransactionFee; -extern int fLimitProcessors; -extern int nLimitProcessors; -extern int fMinimizeToTray; -extern int fMinimizeOnClose; -extern int fUseUPnP; @@ -127,20 +121,6 @@ std::string GetWarnings(std::string strFor); bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut); -template<typename T> -bool WriteSetting(const std::string& strKey, const T& value) -{ - bool fOk = false; - BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) - { - std::string strWalletFile; - if (!GetWalletFile(pwallet, strWalletFile)) - continue; - fOk |= CWalletDB(strWalletFile).WriteSetting(strKey, value); - } - return fOk; -} - class CDiskTxPos { diff --git a/src/net.cpp b/src/net.cpp index 546bc6adc8..5d45e10d05 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -43,6 +43,7 @@ bool OpenNetworkConnection(const CAddress& addrConnect); // bool fClient = false; bool fAllowDNS = false; +static bool fUseUPnP = false; uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK); CAddress addrLocalHost(CService("0.0.0.0", 0), nLocalServices); static CNode* pnodeLocalHost = NULL; @@ -1102,7 +1103,6 @@ void MapPort(bool fMapPort) if (fUseUPnP != fMapPort) { fUseUPnP = fMapPort; - WriteSetting("fUseUPnP", fUseUPnP); } if (fUseUPnP && vnThreadsRunning[THREAD_UPNP] < 1) { @@ -1711,6 +1711,14 @@ bool BindListenPort(string& strError) void StartNode(void* parg) { +#ifdef USE_UPNP +#if USE_UPNP + fUseUPnP = GetBoolArg("-upnp", true); +#else + fUseUPnP = GetBoolArg("-upnp", false); +#endif +#endif + if (pnodeLocalHost == NULL) pnodeLocalHost = new CNode(INVALID_SOCKET, CAddress(CService("127.0.0.1", 0), nLocalServices)); @@ -1812,7 +1820,7 @@ void StartNode(void* parg) printf("Error: CreateThread(ThreadMessageHandler) failed\n"); // Generate coins in the background - GenerateBitcoins(fGenerateBitcoins, pwalletMain); + GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain); } bool StopNode() 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/bitcoingui.cpp b/src/qt/bitcoingui.cpp index cd3cb443da..abf2c381a5 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -58,7 +58,6 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): QMainWindow(parent), clientModel(0), walletModel(0), - dummyWidget(0), encryptWalletAction(0), changePassphraseAction(0), aboutQtAction(0), @@ -88,9 +87,6 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): // Create the tray icon (or setup the dock icon) createTrayIcon(); - // Dummy widget used when restoring window state after minimization - dummyWidget = new QWidget(); - // Create tabs overviewPage = new OverviewPage(); @@ -170,7 +166,6 @@ BitcoinGUI::~BitcoinGUI() #ifdef Q_WS_MAC delete appMenuBar; #endif - delete dummyWidget; } void BitcoinGUI::createActions() @@ -214,17 +209,17 @@ void BitcoinGUI::createActions() #endif tabGroup->addAction(messageAction); - connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormal())); + connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage())); - connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormal())); + connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage())); - connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormal())); + connect(addressBookAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(addressBookAction, SIGNAL(triggered()), this, SLOT(gotoAddressBookPage())); - connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormal())); + connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage())); - connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormal())); + connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage())); - connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormal())); + connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage())); quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this); @@ -256,7 +251,7 @@ void BitcoinGUI::createActions() connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); - connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormal())); + connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool))); connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet())); connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase())); @@ -274,17 +269,17 @@ void BitcoinGUI::createMenuBar() // Configure the menus QMenu *file = appMenuBar->addMenu(tr("&File")); + file->addAction(backupWalletAction); file->addAction(exportAction); #ifndef FIRST_CLASS_MESSAGING file->addAction(messageAction); - file->addSeparator(); #endif + file->addSeparator(); file->addAction(quitAction); QMenu *settings = appMenuBar->addMenu(tr("&Settings")); settings->addAction(encryptWalletAction); settings->addAction(changePassphraseAction); - settings->addAction(backupWalletAction); settings->addSeparator(); settings->addAction(optionsAction); @@ -422,14 +417,6 @@ void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason) } #endif -void BitcoinGUI::showNormal() -{ - // Reparent window to the desktop (in case it was hidden on minimize) - if(parent() != NULL) - setParent(NULL, Qt::Window); - QMainWindow::showNormal(); -} - void BitcoinGUI::optionsClicked() { if(!clientModel || !clientModel->getOptionsModel()) @@ -576,15 +563,19 @@ void BitcoinGUI::changeEvent(QEvent *e) { if(clientModel && clientModel->getOptionsModel()->getMinimizeToTray()) { - if(isMinimized()) + QWindowStateChangeEvent *wsevt = static_cast<QWindowStateChangeEvent*>(e); + bool wasMinimized = wsevt->oldState() & Qt::WindowMinimized; + bool isMinimized = windowState() & Qt::WindowMinimized; + if(!wasMinimized && isMinimized) { - // Hiding the window from taskbar - setParent(dummyWidget, Qt::SubWindow); + // Minimized, hide the window from taskbar + setWindowFlags(windowFlags() | Qt::Tool); return; } - else + else if(wasMinimized && !isMinimized) { - showNormal(); + // Unminimized, show the window in taskbar + setWindowFlags(windowFlags() &~ Qt::Tool); } } } @@ -822,3 +813,11 @@ void BitcoinGUI::unlockWallet() dlg.exec(); } } + +void BitcoinGUI::showNormalIfMinimized() +{ + if(!isVisible()) // Show, if hidden + show(); + if(isMinimized()) // Unminimize, if minimized + showNormal(); +} diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index a522429000..dbc32640b8 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -58,8 +58,6 @@ private: QStackedWidget *centralWidget; - QWidget *dummyWidget; - OverviewPage *overviewPage; QWidget *transactionsPage; AddressBookPage *addressBookPage; @@ -134,8 +132,6 @@ public slots: void gotoMessagePage(); void gotoMessagePage(QString); - void showNormal(); - private slots: /** Switch to overview (home) page */ void gotoOverviewPage(); @@ -169,6 +165,9 @@ private slots: void changePassphrase(); /** Ask for pass phrase to unlock wallet temporarily */ void unlockWallet(); + + /** Show window if hidden, unminimize when minimized */ + void showNormalIfMinimized(); }; #endif diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index edc1d61e9d..ed2225cbf5 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -1,21 +1,94 @@ #include "optionsmodel.h" #include "bitcoinunits.h" +#include <QSettings> #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<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" << "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.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 + if (walletdb.ReadSetting("addrProxy", addrProxy)) + { + settings.setValue("addrProxy", addrProxy.ToStringIPPort().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", addrProxy); + settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str()); } else { @@ -105,7 +179,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in if (nPort > 0 && nPort < std::numeric_limits<unsigned short>::max()) { addrProxy.SetPort(nPort); - walletdb.WriteSetting("addrProxy", addrProxy); + settings.setValue("addrProxy", addrProxy.ToStringIPPort().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 <QAbstractListModel> -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); diff --git a/src/qt/qtipcserver.cpp b/src/qt/qtipcserver.cpp index 018461a9b2..7f5d040338 100644 --- a/src/qt/qtipcserver.cpp +++ b/src/qt/qtipcserver.cpp @@ -44,6 +44,11 @@ void ipcThread(void* parg) void ipcInit() { +#ifdef MAC_OSX + // TODO: implement bitcoin: URI handling the Mac Way + return; +#endif + message_queue* mq; char strBuf[257]; size_t nSize; diff --git a/src/util.cpp b/src/util.cpp index 41a4ac1a07..1623fe84ef 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -885,15 +885,28 @@ string GetConfigFile() return pathConfig.string(); } -void ReadConfigFile(map<string, string>& mapSettingsRet, +bool ReadConfigFile(map<string, string>& mapSettingsRet, map<string, vector<string> >& mapMultiSettingsRet) { namespace fs = boost::filesystem; namespace pod = boost::program_options::detail; + if (mapSettingsRet.count("-datadir")) + { + if (fs::is_directory(fs::system_complete(mapSettingsRet["-datadir"]))) + { + fs::path pathDataDir = fs::system_complete(mapSettingsRet["-datadir"]); + strlcpy(pszSetDataDir, pathDataDir.string().c_str(), sizeof(pszSetDataDir)); + } + else + { + return false; + } + } + fs::ifstream streamConfig(GetConfigFile()); if (!streamConfig.good()) - return; + return true; // No bitcoin.conf file is OK set<string> setOptions; setOptions.insert("*"); @@ -910,6 +923,7 @@ void ReadConfigFile(map<string, string>& mapSettingsRet, } mapMultiSettingsRet[strKey].push_back(it->value[0]); } + return true; } string GetPidFile() diff --git a/src/util.h b/src/util.h index ddc8791b38..31d3275290 100644 --- a/src/util.h +++ b/src/util.h @@ -151,7 +151,7 @@ void GetDataDir(char* pszDirRet); std::string GetConfigFile(); std::string GetPidFile(); void CreatePidFile(std::string pidFile, pid_t pid); -void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet); +bool ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet); #ifdef WIN32 std::string MyGetSpecialFolderPath(int nFolder, bool fCreate); #endif |