X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Fclientmodel.cpp;h=284bee0e8e1a93e5472a99fd2eef90bf0bd904d9;hb=a20c0d0f6792acf532309eee2e9f29120c801ee4;hp=822c03d9495404a2b668b915ebd1694e03b577ba;hpb=7df70c000a5f687953335a5ab397ab4c74a40dd4;p=novacoin.git diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 822c03d..284bee0 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -1,43 +1,18 @@ #include "clientmodel.h" -#include "main.h" #include "guiconstants.h" #include "optionsmodel.h" #include "addresstablemodel.h" #include "transactiontablemodel.h" -#include +#include "headers.h" -ClientModel::ClientModel(QObject *parent) : - QObject(parent), optionsModel(0), addressTableModel(0), - transactionTableModel(0) -{ - // Until signal notifications is built into the bitcoin core, - // simply update everything after polling using a timer. - QTimer *timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(update())); - timer->start(MODEL_UPDATE_DELAY); - - optionsModel = new OptionsModel(this); - addressTableModel = new AddressTableModel(this); - transactionTableModel = new TransactionTableModel(this); -} - -qint64 ClientModel::getBalance() const -{ - return GetBalance(); -} +#include -QString ClientModel::getAddress() const +ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) : + QObject(parent), optionsModel(optionsModel), + cachedNumConnections(0), cachedNumBlocks(0) { - std::vector vchPubKey; - if (CWalletDB("r").ReadDefaultKey(vchPubKey)) - { - return QString::fromStdString(PubKeyToAddress(vchPubKey)); - } - else - { - return QString(); - } + numBlocksAtStartup = -1; } int ClientModel::getNumConnections() const @@ -50,92 +25,43 @@ int ClientModel::getNumBlocks() const return nBestHeight; } -int ClientModel::getNumTransactions() const +int ClientModel::getNumBlocksAtStartup() { - int numTransactions = 0; - CRITICAL_BLOCK(cs_mapWallet) - { - numTransactions = mapWallet.size(); - } - return numTransactions; + if (numBlocksAtStartup == -1) numBlocksAtStartup = getNumBlocks(); + return numBlocksAtStartup; } -void ClientModel::update() +QDateTime ClientModel::getLastBlockDate() const { - // Plainly emit all signals for now. To be more efficient this should check - // whether the values actually changed first. - emit balanceChanged(getBalance()); - emit addressChanged(getAddress()); - emit numConnectionsChanged(getNumConnections()); - emit numBlocksChanged(getNumBlocks()); - emit numTransactionsChanged(getNumTransactions()); + return QDateTime::fromTime_t(pindexBest->GetBlockTime()); } -void ClientModel::setAddress(const QString &defaultAddress) -{ - uint160 hash160; - std::string strAddress = defaultAddress.toStdString(); - if (!AddressToHash160(strAddress, hash160)) - return; - if (!mapPubKeys.count(hash160)) - return; - CWalletDB().WriteDefaultKey(mapPubKeys[hash160]); -} - -ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payAmount) +void ClientModel::update() { - uint160 hash160 = 0; - bool valid = false; + int newNumConnections = getNumConnections(); + int newNumBlocks = getNumBlocks(); + QString newStatusBar = getStatusBarWarnings(); - if(!AddressToHash160(payTo.toUtf8().constData(), hash160)) + if(cachedNumConnections != newNumConnections) + emit numConnectionsChanged(newNumConnections); + if(cachedNumBlocks != newNumBlocks || cachedStatusBar != newStatusBar) { - return InvalidAddress; + // Simply emit a numBlocksChanged for now in case the status message changes, + // so that the view updates the status bar. + // TODO: It should send a notification. + // (However, this might generate looped notifications and needs to be thought through and tested carefully) + // error(tr("Network Alert"), newStatusBar); + emit numBlocksChanged(newNumBlocks); } - if(payAmount <= 0) - { - return InvalidAmount; - } - - if(payAmount > getBalance()) - { - return AmountExceedsBalance; - } - - if((payAmount + nTransactionFee) > getBalance()) - { - return AmountWithFeeExceedsBalance; - } - - CRITICAL_BLOCK(cs_main) - { - // Send to bitcoin address - CWalletTx wtx; - CScript scriptPubKey; - scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG; - - std::string strError = SendMoney(scriptPubKey, payAmount, wtx, true); - if (strError == "") - { - return OK; - } - else if (strError == "ABORTED") - { - return Aborted; - } - else - { - emit error(tr("Sending..."), QString::fromStdString(strError)); - return MiscError; - } - } - // Add addresses that we've sent to to the address book - std::string strAddress = payTo.toStdString(); - CRITICAL_BLOCK(cs_mapAddressBook) - if (!mapAddressBook.count(strAddress)) - SetAddressBookName(strAddress, ""); + cachedNumConnections = newNumConnections; + cachedNumBlocks = newNumBlocks; + cachedStatusBar = newStatusBar; +} - return OK; +bool ClientModel::isTestNet() const +{ + return fTestNet; } bool ClientModel::inInitialBlockDownload() const @@ -143,17 +69,27 @@ bool ClientModel::inInitialBlockDownload() const return IsInitialBlockDownload(); } +int ClientModel::getNumBlocksOfPeers() const +{ + return GetNumBlocksOfPeers(); +} + +QString ClientModel::getStatusBarWarnings() const +{ + return QString::fromStdString(GetWarnings("statusbar")); +} + OptionsModel *ClientModel::getOptionsModel() { return optionsModel; } -AddressTableModel *ClientModel::getAddressTableModel() +QString ClientModel::formatFullVersion() const { - return addressTableModel; + return QString::fromStdString(FormatFullVersion()); } -TransactionTableModel *ClientModel::getTransactionTableModel() +QString ClientModel::formatBuildDate() const { - return transactionTableModel; + return QString::fromStdString(CLIENT_DATE); }