Mercurial > hg > bitcoin
changeset 1262:ee115fab6952 draft
QtUI code cleanup / comment improvements
author | Wladimir J. van der Laan <laanwj@gmail.com> |
---|---|
date | Mon, 08 Aug 2011 17:38:17 +0200 |
parents | 432d5fa8c185 |
children | 32d9404d58dc |
files | src/qt/addresstablemodel.cpp src/qt/bitcoin.cpp src/qt/bitcoinamountfield.cpp src/qt/bitcoingui.cpp src/qt/bitcoinunits.h src/qt/clientmodel.h src/qt/guiutil.cpp src/qt/guiutil.h src/qt/overviewpage.cpp src/qt/transactiondesc.cpp src/qt/transactiondesc.h src/qt/transactiontablemodel.cpp src/qt/transactiontablemodel.h src/qt/transactionview.h src/qt/walletmodel.cpp src/qt/walletmodel.h |
diffstat | 16 files changed, 110 insertions(+), 152 deletions(-) [+] |
line wrap: on
line diff
--- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -161,13 +161,13 @@ rec->label = value.toString(); break; case Address: - // Refuse to set invalid address + // Refuse to set invalid address, set error status and return false if(!walletModel->validateAddress(value.toString())) { editStatus = INVALID_ADDRESS; return false; } - // Double-check that we're not overwriting receiving address + // Double-check that we're not overwriting a receiving address if(rec->type == AddressTableEntry::Sending) { CRITICAL_BLOCK(wallet->cs_mapAddressBook) @@ -234,7 +234,7 @@ void AddressTableModel::updateList() { - // Update internal model from Bitcoin core + // Update address book model from Bitcoin core beginResetModel(); priv->refreshAddressTable(); endResetModel(); @@ -247,7 +247,6 @@ editStatus = OK; - if(type == Send) { if(!walletModel->validateAddress(address)) @@ -255,7 +254,7 @@ editStatus = INVALID_ADDRESS; return QString(); } - // Check for duplicate + // Check for duplicate addresses CRITICAL_BLOCK(wallet->cs_mapAddressBook) { if(wallet->mapAddressBook.count(strAddress))
--- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -135,7 +135,7 @@ { { // Put this in a block, so that BitcoinGUI is cleaned up properly before - // calling shutdown. + // calling Shutdown(). BitcoinGUI window; splash.finish(&window); OptionsModel optionsModel(pwalletMain);
--- a/src/qt/bitcoinamountfield.cpp +++ b/src/qt/bitcoinamountfield.cpp @@ -44,7 +44,7 @@ connect(decimals, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged())); connect(unit, SIGNAL(currentIndexChanged(int)), this, SLOT(unitChanged(int))); - // TODO: set default based on configuration + // Set default based on configuration unitChanged(unit->currentIndex()); } @@ -67,7 +67,6 @@ { amount->clear(); decimals->clear(); - // TODO: set default based on configuration unit->setCurrentIndex(0); }
--- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -52,6 +52,8 @@ resize(850, 550); setWindowTitle(tr("Bitcoin Wallet")); setWindowIcon(QIcon(":icons/bitcoin")); + // Accept D&D of URIs + setAcceptDrops(true); createActions(); @@ -68,8 +70,8 @@ QMenu *help = menuBar()->addMenu("&Help"); help->addAction(aboutAction); - // Toolbar - QToolBar *toolbar = addToolBar("Main toolbar"); + // Toolbars + QToolBar *toolbar = addToolBar(tr("Tabs toolbar")); toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); toolbar->addAction(overviewAction); toolbar->addAction(sendCoinsAction); @@ -77,19 +79,17 @@ toolbar->addAction(historyAction); toolbar->addAction(addressBookAction); - QToolBar *toolbar2 = addToolBar("Transactions toolbar"); + QToolBar *toolbar2 = addToolBar(tr("Actions toolbar")); toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); toolbar2->addAction(exportAction); - // Overview page + // Create tabs overviewPage = new OverviewPage(); - QVBoxLayout *vbox = new QVBoxLayout(); - - transactionView = new TransactionView(this); - connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails())); - vbox->addWidget(transactionView); transactionsPage = new QWidget(this); + QVBoxLayout *vbox = new QVBoxLayout(); + transactionView = new TransactionView(this); + vbox->addWidget(transactionView); transactionsPage->setLayout(vbox); addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab); @@ -109,7 +109,7 @@ // Create status bar statusBar(); - // Status bar "Blocks" notification + // Status bar notification icons QFrame *frameBlocks = new QFrame(); //frameBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken); frameBlocks->setContentsMargins(0,0,0,0); @@ -141,10 +141,11 @@ syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this); - // Clicking on a transaction simply sends you to transaction history page + // Clicking on a transaction on the overview page simply sends you to transaction history page connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage())); - setAcceptDrops(true); + // Doubleclicking on a transaction on the transaction history page shows details + connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails())); gotoOverviewPage(); } @@ -252,7 +253,6 @@ { QMenu *trayIconMenu = new QMenu(this); trayIconMenu->addAction(openBitcoinAction); - trayIconMenu->addAction(sendCoinsAction); trayIconMenu->addAction(optionsAction); trayIconMenu->addSeparator(); trayIconMenu->addAction(quitAction); @@ -268,7 +268,7 @@ void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason) { - if(reason == QSystemTrayIcon::DoubleClick) + if(reason == QSystemTrayIcon::Trigger) { // Doubleclick on system tray icon triggers "open bitcoin" openBitcoinAction->trigger(); @@ -347,31 +347,22 @@ text = tr("%n day(s) ago","",secs/(60*60*24)); } - // In the label we want to be less specific - bool spinning = true; + // Set icon state: spinning if catching up, tick otherwise if(secs < 30*60) { tooltip = tr("Up to date") + QString("\n") + tooltip; - spinning = false; + labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(16,16)); } else { tooltip = tr("Catching up...") + QString("\n") + tooltip; + labelBlocksIcon->setMovie(syncIconMovie); + syncIconMovie->start(); } tooltip += QString("\n"); tooltip += tr("Last received block was generated %1.").arg(text); - if(spinning) - { - labelBlocksIcon->setMovie(syncIconMovie); - syncIconMovie->start(); - } - else - { - labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(16,16)); - } - labelBlocksIcon->setToolTip(tooltip); progressBarLabel->setToolTip(tooltip); progressBar->setToolTip(tooltip); @@ -439,12 +430,14 @@ void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end) { + if(start == end) + return; TransactionTableModel *ttm = walletModel->getTransactionTableModel(); qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent) .data(Qt::EditRole).toULongLong(); if(!clientModel->inInitialBlockDownload()) { - // On incoming transaction, make an info balloon + // On new transaction, make an info balloon // Unless the initial block download is in progress, to prevent balloon-spam QString date = ttm->index(start, TransactionTableModel::Date, parent) .data().toString();
--- a/src/qt/bitcoinunits.h +++ b/src/qt/bitcoinunits.h @@ -4,7 +4,8 @@ #include <QString> #include <QAbstractListModel> -// Bitcoin unit definitions +// Bitcoin unit definitions, encapsulates parsing and formatting +// and serves as list model for dropdown selection boxes. class BitcoinUnits: public QAbstractListModel { public:
--- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -12,7 +12,7 @@ class QDateTime; QT_END_NAMESPACE -// Interface to Bitcoin network client +// Model for Bitcoin network client class ClientModel : public QObject { Q_OBJECT
--- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -12,12 +12,12 @@ #include <QLineEdit> #include <QUrl> -QString GUIUtil::DateTimeStr(qint64 nTime) +QString GUIUtil::dateTimeStr(qint64 nTime) { - return DateTimeStr(QDateTime::fromTime_t((qint32)nTime)); + return dateTimeStr(QDateTime::fromTime_t((qint32)nTime)); } -QString GUIUtil::DateTimeStr(const QDateTime &date) +QString GUIUtil::dateTimeStr(const QDateTime &date) { return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + date.toString("hh:mm"); } @@ -61,8 +61,6 @@ } else // Amount is non-empty { - // TODO: support <n>X<nexp> (exp = 8-nexp) (https://en.bitcoin.it/wiki/URI_Scheme) - // TODO: support <n>E<exp> if(!BitcoinUnits::parse(BitcoinUnits::BTC, amount, &rv.amount)) { return false;
--- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -16,8 +16,8 @@ { public: // Create human-readable string from date - static QString DateTimeStr(qint64 nTime); - static QString DateTimeStr(const QDateTime &datetime); + static QString dateTimeStr(qint64 nTime); + static QString dateTimeStr(const QDateTime &datetime); // Render bitcoin addresses in monospace font static QFont bitcoinAddressFont();
--- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -74,7 +74,7 @@ painter->drawText(amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText); painter->setPen(option.palette.color(QPalette::Text)); - painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::DateTimeStr(date)); + painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr(date)); painter->restore(); }
--- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -1,79 +1,55 @@ #include <transactiondesc.h> #include "guiutil.h" +#include "bitcoinunits.h" #include "headers.h" #include "qtui.h" #include <QString> - -// Taken straight from ui.cpp -// TODO: Convert to use QStrings, Qt::Escape and tr() -// or: refactor and put describeAsHTML() into bitcoin core but that is unneccesary with better -// UI<->core API, no need to put display logic in core. +#include <QTextDocument> // For Qt::escape using namespace std; -static string HtmlEscape(const char* psz, bool fMultiLine=false) +QString TransactionDesc::HtmlEscape(const QString& str, bool fMultiLine) { - int len = 0; - for (const char* p = psz; *p; p++) + QString escaped = Qt::escape(str); + if(fMultiLine) { - if (*p == '<') len += 4; - else if (*p == '>') len += 4; - else if (*p == '&') len += 5; - else if (*p == '"') len += 6; - else if (*p == ' ' && p > psz && p[-1] == ' ' && p[1] == ' ') len += 6; - else if (*p == '\n' && fMultiLine) len += 5; - else - len++; + escaped = escaped.replace("\n", "<br>\n"); } - string str; - str.reserve(len); - for (const char* p = psz; *p; p++) - { - if (*p == '<') str += "<"; - else if (*p == '>') str += ">"; - else if (*p == '&') str += "&"; - else if (*p == '"') str += """; - else if (*p == ' ' && p > psz && p[-1] == ' ' && p[1] == ' ') str += " "; - else if (*p == '\n' && fMultiLine) str += "<br>\n"; - else - str += *p; - } - return str; + return escaped; } -static string HtmlEscape(const string& str, bool fMultiLine=false) +QString TransactionDesc::HtmlEscape(const std::string& str, bool fMultiLine) { - return HtmlEscape(str.c_str(), fMultiLine); + return HtmlEscape(QString::fromStdString(str), fMultiLine); } -static string FormatTxStatus(const CWalletTx& wtx) +QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx) { - // Status if (!wtx.IsFinal()) { - if (wtx.nLockTime < 500000000) - return strprintf(_("Open for %d blocks"), nBestHeight - wtx.nLockTime); + if (wtx.nLockTime < LOCKTIME_THRESHOLD) + return tr("Open for %1 blocks").arg(nBestHeight - wtx.nLockTime); else - return strprintf(_("Open until %s"), GUIUtil::DateTimeStr(wtx.nLockTime).toStdString().c_str()); + return tr("Open until %1").arg(GUIUtil::dateTimeStr(wtx.nLockTime)); } else { int nDepth = wtx.GetDepthInMainChain(); if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) - return strprintf(_("%d/offline?"), nDepth); + return tr("%1/offline?").arg(nDepth); else if (nDepth < 6) - return strprintf(_("%d/unconfirmed"), nDepth); + return tr("%1/unconfirmed").arg(nDepth); else - return strprintf(_("%d confirmations"), nDepth); + return tr("%1 confirmations").arg(nDepth); } } -string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) +QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) { - string strHTML; + QString strHTML; CRITICAL_BLOCK(wallet->cs_mapAddressBook) { strHTML.reserve(4000); @@ -84,36 +60,33 @@ int64 nDebit = wtx.GetDebit(); int64 nNet = nCredit - nDebit; - - - strHTML += _("<b>Status:</b> ") + FormatTxStatus(wtx); + strHTML += tr("<b>Status:</b> ") + FormatTxStatus(wtx); int nRequests = wtx.GetRequestCount(); if (nRequests != -1) { if (nRequests == 0) - strHTML += _(", has not been successfully broadcast yet"); + strHTML += tr(", has not been successfully broadcast yet"); else if (nRequests == 1) - strHTML += strprintf(_(", broadcast through %d node"), nRequests); + strHTML += tr(", broadcast through %1 node").arg(nRequests); else - strHTML += strprintf(_(", broadcast through %d nodes"), nRequests); + strHTML += tr(", broadcast through %1 nodes").arg(nRequests); } strHTML += "<br>"; - strHTML += _("<b>Date:</b> ") + (nTime ? GUIUtil::DateTimeStr(nTime).toStdString() : "") + "<br>"; - + strHTML += tr("<b>Date:</b> ") + (nTime ? GUIUtil::dateTimeStr(nTime) : QString("")) + "<br>"; // // From // if (wtx.IsCoinBase()) { - strHTML += _("<b>Source:</b> Generated<br>"); + strHTML += tr("<b>Source:</b> Generated<br>"); } else if (!wtx.mapValue["from"].empty()) { // Online transaction if (!wtx.mapValue["from"].empty()) - strHTML += _("<b>From:</b> ") + HtmlEscape(wtx.mapValue["from"]) + "<br>"; + strHTML += tr("<b>From:</b> ") + HtmlEscape(wtx.mapValue["from"]) + "<br>"; } else { @@ -130,13 +103,13 @@ { if (wallet->mapAddressBook.count(address)) { - strHTML += string() + _("<b>From:</b> ") + _("unknown") + "<br>"; - strHTML += _("<b>To:</b> "); + strHTML += tr("<b>From:</b> ") + tr("unknown") + "<br>"; + strHTML += tr("<b>To:</b> "); strHTML += HtmlEscape(address.ToString()); if (!wallet->mapAddressBook[address].empty()) - strHTML += _(" (yours, label: ") + HtmlEscape(wallet->mapAddressBook[address]) + ")"; + strHTML += tr(" (yours, label: ") + HtmlEscape(wallet->mapAddressBook[address]) + ")"; else - strHTML += _(" (yours)"); + strHTML += tr(" (yours)"); strHTML += "<br>"; } } @@ -146,7 +119,6 @@ } } - // // To // @@ -155,13 +127,12 @@ { // Online transaction strAddress = wtx.mapValue["to"]; - strHTML += _("<b>To:</b> "); + strHTML += tr("<b>To:</b> "); if (wallet->mapAddressBook.count(strAddress) && !wallet->mapAddressBook[strAddress].empty()) strHTML += HtmlEscape(wallet->mapAddressBook[strAddress]) + " "; strHTML += HtmlEscape(strAddress) + "<br>"; } - // // Amount // @@ -173,11 +144,13 @@ int64 nUnmatured = 0; BOOST_FOREACH(const CTxOut& txout, wtx.vout) nUnmatured += wallet->GetCredit(txout); - strHTML += _("<b>Credit:</b> "); + strHTML += tr("<b>Credit:</b> "); if (wtx.IsInMainChain()) - strHTML += strprintf(_("(%s matures in %d more blocks)"), FormatMoney(nUnmatured).c_str(), wtx.GetBlocksToMaturity()); + strHTML += tr("(%1 matures in %2 more blocks)") + .arg(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nUnmatured)) + .arg(wtx.GetBlocksToMaturity()); else - strHTML += _("(not accepted)"); + strHTML += tr("(not accepted)"); strHTML += "<br>"; } else if (nNet > 0) @@ -185,7 +158,7 @@ // // Credit // - strHTML += _("<b>Credit:</b> ") + FormatMoney(nNet) + "<br>"; + strHTML += tr("<b>Credit:</b> ") + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nNet) + "<br>"; } else { @@ -213,7 +186,7 @@ CBitcoinAddress address; if (ExtractAddress(txout.scriptPubKey, 0, address)) { - strHTML += _("<b>To:</b> "); + strHTML += tr("<b>To:</b> "); if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty()) strHTML += HtmlEscape(wallet->mapAddressBook[address]) + " "; strHTML += HtmlEscape(address.ToString()); @@ -221,7 +194,7 @@ } } - strHTML += _("<b>Debit:</b> ") + FormatMoney(-txout.nValue) + "<br>"; + strHTML += tr("<b>Debit:</b> ") + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -txout.nValue) + "<br>"; } if (fAllToMe) @@ -229,13 +202,13 @@ // Payment to self int64 nChange = wtx.GetChange(); int64 nValue = nCredit - nChange; - strHTML += _("<b>Debit:</b> ") + FormatMoney(-nValue) + "<br>"; - strHTML += _("<b>Credit:</b> ") + FormatMoney(nValue) + "<br>"; + strHTML += tr("<b>Debit:</b> ") + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -nValue) + "<br>"; + strHTML += tr("<b>Credit:</b> ") + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nValue) + "<br>"; } int64 nTxFee = nDebit - wtx.GetValueOut(); if (nTxFee > 0) - strHTML += _("<b>Transaction fee:</b> ") + FormatMoney(-nTxFee) + "<br>"; + strHTML += tr("<b>Transaction fee:</b> ") + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,-nTxFee) + "<br>"; } else { @@ -244,27 +217,25 @@ // BOOST_FOREACH(const CTxIn& txin, wtx.vin) if (wallet->IsMine(txin)) - strHTML += _("<b>Debit:</b> ") + FormatMoney(-wallet->GetDebit(txin)) + "<br>"; + strHTML += tr("<b>Debit:</b> ") + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,-wallet->GetDebit(txin)) + "<br>"; BOOST_FOREACH(const CTxOut& txout, wtx.vout) if (wallet->IsMine(txout)) - strHTML += _("<b>Credit:</b> ") + FormatMoney(wallet->GetCredit(txout)) + "<br>"; + strHTML += tr("<b>Credit:</b> ") + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,wallet->GetCredit(txout)) + "<br>"; } } - strHTML += _("<b>Net amount:</b> ") + FormatMoney(nNet, true) + "<br>"; - + strHTML += tr("<b>Net amount:</b> ") + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,nNet, true) + "<br>"; // // Message // if (!wtx.mapValue["message"].empty()) - strHTML += string() + "<br><b>" + _("Message:") + "</b><br>" + HtmlEscape(wtx.mapValue["message"], true) + "<br>"; + strHTML += QString("<br><b>") + tr("Message:") + "</b><br>" + HtmlEscape(wtx.mapValue["message"], true) + "<br>"; if (!wtx.mapValue["comment"].empty()) - strHTML += string() + "<br><b>" + _("Comment:") + "</b><br>" + HtmlEscape(wtx.mapValue["comment"], true) + "<br>"; + strHTML += QString("<br><b>") + tr("Comment:") + "</b><br>" + HtmlEscape(wtx.mapValue["comment"], true) + "<br>"; if (wtx.IsCoinBase()) - strHTML += string() + "<br>" + _("Generated coins must wait 120 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, it will change to \"not accepted\" and not be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.") + "<br>"; - + strHTML += QString("<br>") + tr("Generated coins must wait 120 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, it will change to \"not accepted\" and not be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.") + "<br>"; // // Debug view @@ -274,10 +245,10 @@ strHTML += "<hr><br>Debug information<br><br>"; BOOST_FOREACH(const CTxIn& txin, wtx.vin) if(wallet->IsMine(txin)) - strHTML += "<b>Debit:</b> " + FormatMoney(-wallet->GetDebit(txin)) + "<br>"; + strHTML += "<b>Debit:</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,-wallet->GetDebit(txin)) + "<br>"; BOOST_FOREACH(const CTxOut& txout, wtx.vout) if(wallet->IsMine(txout)) - strHTML += "<b>Credit:</b> " + FormatMoney(wallet->GetCredit(txout)) + "<br>"; + strHTML += "<b>Credit:</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,wallet->GetCredit(txout)) + "<br>"; strHTML += "<br><b>Transaction:</b><br>"; strHTML += HtmlEscape(wtx.ToString(), true); @@ -304,9 +275,9 @@ { if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty()) strHTML += HtmlEscape(wallet->mapAddressBook[address]) + " "; - strHTML += address.ToString(); + strHTML += QString::fromStdString(address.ToString()); } - strHTML = strHTML + " Amount=" + FormatMoney(vout.nValue); + strHTML = strHTML + " Amount=" + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,vout.nValue); strHTML = strHTML + " IsMine=" + (wallet->IsMine(vout) ? "true" : "false") + "</li>"; } } @@ -315,8 +286,6 @@ strHTML += "</ul>"; } - - strHTML += "</font></html>"; } return strHTML;
--- a/src/qt/transactiondesc.h +++ b/src/qt/transactiondesc.h @@ -1,16 +1,24 @@ #ifndef TRANSACTIONDESC_H #define TRANSACTIONDESC_H +#include <QString> +#include <QObject> #include <string> class CWallet; class CWalletTx; -class TransactionDesc +class TransactionDesc: public QObject { public: - /* Provide human-readable extended HTML description of a transaction */ - static std::string toHTML(CWallet *wallet, CWalletTx &wtx); + // Provide human-readable extended HTML description of a transaction + static QString toHTML(CWallet *wallet, CWalletTx &wtx); +private: + TransactionDesc() {} + + static QString HtmlEscape(const QString& str, bool fMultiLine=false); + static QString HtmlEscape(const std::string &str, bool fMultiLine=false); + static QString FormatTxStatus(const CWalletTx& wtx); }; #endif // TRANSACTIONDESC_H
--- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -18,7 +18,7 @@ #include <QDateTime> #include <QtAlgorithms> -// Credit and Debit columns are right-aligned as they contain numbers +// Amount column is right-aligned it contains numbers static int column_alignments[] = { Qt::AlignLeft|Qt::AlignVCenter, Qt::AlignLeft|Qt::AlignVCenter, @@ -100,10 +100,10 @@ for(int update_idx = updated_sorted.size()-1; update_idx >= 0; --update_idx) { const uint256 &hash = updated_sorted.at(update_idx); - /* Find transaction in wallet */ + // Find transaction in wallet std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(hash); bool inWallet = mi != wallet->mapWallet.end(); - /* Find bounds of this transaction in model */ + // Find bounds of this transaction in model QList<TransactionRecord>::iterator lower = qLowerBound( cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan()); QList<TransactionRecord>::iterator upper = qUpperBound( @@ -196,7 +196,7 @@ std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash); if(mi != wallet->mapWallet.end()) { - return QString::fromStdString(TransactionDesc::toHTML(wallet, mi->second)); + return TransactionDesc::toHTML(wallet, mi->second); } } return QString(""); @@ -274,7 +274,7 @@ status = tr("Open for %n block(s)","",wtx->status.open_for); break; case TransactionStatus::OpenUntilDate: - status = tr("Open until %1").arg(GUIUtil::DateTimeStr(wtx->status.open_for)); + status = tr("Open until %1").arg(GUIUtil::dateTimeStr(wtx->status.open_for)); break; case TransactionStatus::Offline: status = tr("Offline (%1 confirmations)").arg(wtx->status.depth); @@ -313,7 +313,7 @@ { if(wtx->time) { - return GUIUtil::DateTimeStr(wtx->time); + return GUIUtil::dateTimeStr(wtx->time); } else { @@ -606,11 +606,6 @@ return QVariant(); } -Qt::ItemFlags TransactionTableModel::flags(const QModelIndex &index) const -{ - return QAbstractTableModel::flags(index); -} - QModelIndex TransactionTableModel::index(int row, int column, const QModelIndex &parent) const { Q_UNUSED(parent);
--- a/src/qt/transactiontablemodel.h +++ b/src/qt/transactiontablemodel.h @@ -51,7 +51,6 @@ int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const; - Qt::ItemFlags flags(const QModelIndex &index) const; QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; private: CWallet* wallet;
--- a/src/qt/transactionview.h +++ b/src/qt/transactionview.h @@ -24,6 +24,7 @@ void setModel(WalletModel *model); + // Date ranges for filter enum DateEnum { All,
--- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -83,8 +83,6 @@ // Pre-check input data for validity foreach(const SendCoinsRecipient &rcp, recipients) { - uint160 hash160 = 0; - if(!validateAddress(rcp.address)) { return InvalidAddress;
--- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -15,7 +15,7 @@ qint64 amount; }; -// Interface to a Bitcoin wallet +// Interface to Bitcoin wallet from Qt view code class WalletModel : public QObject { Q_OBJECT @@ -47,9 +47,7 @@ // Check address for validity bool validateAddress(const QString &address); - // Return status record for SendCoins - // fee is used in case status is "AmountWithFeeExceedsBalance" - // hex is filled with the transaction hash if status is "OK" + // Return status record for SendCoins, contains error id + information struct SendCoinsReturn { SendCoinsReturn(StatusCode status, @@ -57,11 +55,11 @@ QString hex=QString()): status(status), fee(fee), hex(hex) {} StatusCode status; - qint64 fee; - QString hex; + qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance" + QString hex; // is filled with the transaction hash if status is "OK" }; - // Send coins to list of recipients + // Send coins to a list of recipients SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients); private: CWallet *wallet;