X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Fclientmodel.cpp;h=284bee0e8e1a93e5472a99fd2eef90bf0bd904d9;hb=a20c0d0f6792acf532309eee2e9f29120c801ee4;hp=97391e09381017f02b56ffa04e46a53b0ea3ad7c;hpb=ba4081c1fcaddf361abd61b2721994eff5475bb3;p=novacoin.git diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 97391e0..284bee0 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -1,143 +1,82 @@ #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) +#include + +ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) : + QObject(parent), optionsModel(optionsModel), + cachedNumConnections(0), cachedNumBlocks(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); + numBlocksAtStartup = -1; } -qint64 ClientModel::getBalance() +int ClientModel::getNumConnections() const { - return GetBalance(); + return vNodes.size(); } -QString ClientModel::getAddress() +int ClientModel::getNumBlocks() const { - std::vector vchPubKey; - if (CWalletDB("r").ReadDefaultKey(vchPubKey)) - { - return QString::fromStdString(PubKeyToAddress(vchPubKey)); - } - else - { - return QString(); - } + return nBestHeight; } -int ClientModel::getNumConnections() +int ClientModel::getNumBlocksAtStartup() { - return vNodes.size(); + if (numBlocksAtStartup == -1) numBlocksAtStartup = getNumBlocks(); + return numBlocksAtStartup; } -int ClientModel::getNumBlocks() +QDateTime ClientModel::getLastBlockDate() const { - return nBestHeight; + return QDateTime::fromTime_t(pindexBest->GetBlockTime()); } -int ClientModel::getNumTransactions() +void ClientModel::update() { - int numTransactions = 0; - CRITICAL_BLOCK(cs_mapWallet) + int newNumConnections = getNumConnections(); + int newNumBlocks = getNumBlocks(); + QString newStatusBar = getStatusBarWarnings(); + + if(cachedNumConnections != newNumConnections) + emit numConnectionsChanged(newNumConnections); + if(cachedNumBlocks != newNumBlocks || cachedStatusBar != newStatusBar) { - numTransactions = mapWallet.size(); + // 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); } - return numTransactions; + + cachedNumConnections = newNumConnections; + cachedNumBlocks = newNumBlocks; + cachedStatusBar = newStatusBar; } -void ClientModel::update() +bool ClientModel::isTestNet() const { - /* Plainly emit all signals for now. To be precise this should check - wether the values actually changed first. - */ - emit balanceChanged(getBalance()); - emit addressChanged(getAddress()); - emit numConnectionsChanged(getNumConnections()); - emit numBlocksChanged(getNumBlocks()); - emit numTransactionsChanged(getNumTransactions()); + return fTestNet; } -void ClientModel::setAddress(const QString &defaultAddress) +bool ClientModel::inInitialBlockDownload() const { - uint160 hash160; - std::string strAddress = defaultAddress.toStdString(); - if (!AddressToHash160(strAddress, hash160)) - return; - if (!mapPubKeys.count(hash160)) - return; - CWalletDB().WriteDefaultKey(mapPubKeys[hash160]); + return IsInitialBlockDownload(); } -ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payAmount) +int ClientModel::getNumBlocksOfPeers() const { - uint160 hash160 = 0; - bool valid = false; - - if(!AddressToHash160(payTo.toUtf8().constData(), hash160)) - { - return InvalidAddress; - } - - 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, ""); + return GetNumBlocksOfPeers(); +} - return OK; +QString ClientModel::getStatusBarWarnings() const +{ + return QString::fromStdString(GetWarnings("statusbar")); } OptionsModel *ClientModel::getOptionsModel() @@ -145,12 +84,12 @@ 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); }