Browse Source

QtUI code cleanup / comment improvements

0.8
Wladimir J. van der Laan 14 years ago
parent
commit
b0849613bf
  1. 9
      src/qt/addresstablemodel.cpp
  2. 2
      src/qt/bitcoin.cpp
  3. 3
      src/qt/bitcoinamountfield.cpp
  4. 47
      src/qt/bitcoingui.cpp
  5. 3
      src/qt/bitcoinunits.h
  6. 2
      src/qt/clientmodel.h
  7. 8
      src/qt/guiutil.cpp
  8. 4
      src/qt/guiutil.h
  9. 2
      src/qt/overviewpage.cpp
  10. 133
      src/qt/transactiondesc.cpp
  11. 14
      src/qt/transactiondesc.h
  12. 17
      src/qt/transactiontablemodel.cpp
  13. 1
      src/qt/transactiontablemodel.h
  14. 1
      src/qt/transactionview.h
  15. 2
      src/qt/walletmodel.cpp
  16. 12
      src/qt/walletmodel.h

9
src/qt/addresstablemodel.cpp

@ -161,13 +161,13 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu @@ -161,13 +161,13 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
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 @@ QModelIndex AddressTableModel::index(int row, int column, const QModelIndex & pa @@ -234,7 +234,7 @@ QModelIndex AddressTableModel::index(int row, int column, const QModelIndex & pa
void AddressTableModel::updateList()
{
// Update internal model from Bitcoin core
// Update address book model from Bitcoin core
beginResetModel();
priv->refreshAddressTable();
endResetModel();
@ -247,7 +247,6 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con @@ -247,7 +247,6 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
editStatus = OK;
if(type == Send)
{
if(!walletModel->validateAddress(address))
@ -255,7 +254,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con @@ -255,7 +254,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
editStatus = INVALID_ADDRESS;
return QString();
}
// Check for duplicate
// Check for duplicate addresses
CRITICAL_BLOCK(wallet->cs_mapAddressBook)
{
if(wallet->mapAddressBook.count(strAddress))

2
src/qt/bitcoin.cpp

@ -135,7 +135,7 @@ int main(int argc, char *argv[]) @@ -135,7 +135,7 @@ int main(int argc, char *argv[])
{
{
// 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);

3
src/qt/bitcoinamountfield.cpp

@ -44,7 +44,7 @@ BitcoinAmountField::BitcoinAmountField(QWidget *parent): @@ -44,7 +44,7 @@ BitcoinAmountField::BitcoinAmountField(QWidget *parent):
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 @@ void BitcoinAmountField::clear() @@ -67,7 +67,6 @@ void BitcoinAmountField::clear()
{
amount->clear();
decimals->clear();
// TODO: set default based on configuration
unit->setCurrentIndex(0);
}

47
src/qt/bitcoingui.cpp

@ -52,6 +52,8 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): @@ -52,6 +52,8 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
resize(850, 550);
setWindowTitle(tr("Bitcoin Wallet"));
setWindowIcon(QIcon(":icons/bitcoin"));
// Accept D&D of URIs
setAcceptDrops(true);
createActions();
@ -68,8 +70,8 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): @@ -68,8 +70,8 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
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 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): @@ -77,19 +79,17 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
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();
transactionsPage = new QWidget(this);
QVBoxLayout *vbox = new QVBoxLayout();
transactionView = new TransactionView(this);
connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
vbox->addWidget(transactionView);
transactionsPage = new QWidget(this);
transactionsPage->setLayout(vbox);
addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
@ -109,7 +109,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): @@ -109,7 +109,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
// 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 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): @@ -141,10 +141,11 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
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 @@ void BitcoinGUI::createTrayIcon() @@ -252,7 +253,6 @@ void BitcoinGUI::createTrayIcon()
{
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::createTrayIcon() @@ -268,7 +268,7 @@ void BitcoinGUI::createTrayIcon()
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 @@ void BitcoinGUI::setNumBlocks(int count) @@ -347,31 +347,22 @@ void BitcoinGUI::setNumBlocks(int count)
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::askFee(qint64 nFeeRequired, bool *payFee) @@ -439,12 +430,14 @@ void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
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();

3
src/qt/bitcoinunits.h

@ -4,7 +4,8 @@ @@ -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:

2
src/qt/clientmodel.h

@ -12,7 +12,7 @@ QT_BEGIN_NAMESPACE @@ -12,7 +12,7 @@ QT_BEGIN_NAMESPACE
class QDateTime;
QT_END_NAMESPACE
// Interface to Bitcoin network client
// Model for Bitcoin network client
class ClientModel : public QObject
{
Q_OBJECT

8
src/qt/guiutil.cpp

@ -12,12 +12,12 @@ @@ -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 @@ bool GUIUtil::parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out) @@ -61,8 +61,6 @@ bool GUIUtil::parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out)
}
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;

4
src/qt/guiutil.h

@ -16,8 +16,8 @@ class GUIUtil @@ -16,8 +16,8 @@ class GUIUtil
{
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();

2
src/qt/overviewpage.cpp

@ -74,7 +74,7 @@ public: @@ -74,7 +74,7 @@ public:
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();
}

133
src/qt/transactiondesc.cpp

@ -1,79 +1,55 @@ @@ -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 += "&lt;";
else if (*p == '>') str += "&gt;";
else if (*p == '&') str += "&amp;";
else if (*p == '"') str += "&quot;";
else if (*p == ' ' && p > psz && p[-1] == ' ' && p[1] == ' ') str += "&nbsp;";
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 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -84,36 +60,33 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
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 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -130,13 +103,13 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
{
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 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -146,7 +119,6 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
}
}
//
// To
//
@ -155,13 +127,12 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -155,13 +127,12 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
{
// 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 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -173,11 +144,13 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
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 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -185,7 +158,7 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
//
// Credit
//
strHTML += _("<b>Credit:</b> ") + FormatMoney(nNet) + "<br>";
strHTML += tr("<b>Credit:</b> ") + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nNet) + "<br>";
}
else
{
@ -213,7 +186,7 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -213,7 +186,7 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
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 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -221,7 +194,7 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
}
}
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 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -229,13 +202,13 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
// 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 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -244,27 +217,25 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
//
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 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -274,10 +245,10 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
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 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -304,9 +275,9 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
{
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 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) @@ -315,8 +286,6 @@ string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
strHTML += "</ul>";
}
strHTML += "</font></html>";
}
return strHTML;

14
src/qt/transactiondesc.h

@ -1,16 +1,24 @@ @@ -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

17
src/qt/transactiontablemodel.cpp

@ -18,7 +18,7 @@ @@ -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 @@ struct TransactionTablePriv @@ -100,10 +100,10 @@ struct TransactionTablePriv
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 @@ struct TransactionTablePriv @@ -196,7 +196,7 @@ struct TransactionTablePriv
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 @@ QString TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) cons @@ -274,7 +274,7 @@ QString TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) cons
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 @@ QString TransactionTableModel::formatTxDate(const TransactionRecord *wtx) const @@ -313,7 +313,7 @@ QString TransactionTableModel::formatTxDate(const TransactionRecord *wtx) const
{
if(wtx->time)
{
return GUIUtil::DateTimeStr(wtx->time);
return GUIUtil::dateTimeStr(wtx->time);
}
else
{
@ -606,11 +606,6 @@ QVariant TransactionTableModel::headerData(int section, Qt::Orientation orientat @@ -606,11 +606,6 @@ QVariant TransactionTableModel::headerData(int section, Qt::Orientation orientat
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);

1
src/qt/transactiontablemodel.h

@ -51,7 +51,6 @@ public: @@ -51,7 +51,6 @@ public:
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;

1
src/qt/transactionview.h

@ -24,6 +24,7 @@ public: @@ -24,6 +24,7 @@ public:
void setModel(WalletModel *model);
// Date ranges for filter
enum DateEnum
{
All,

2
src/qt/walletmodel.cpp

@ -83,8 +83,6 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipie @@ -83,8 +83,6 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipie
// Pre-check input data for validity
foreach(const SendCoinsRecipient &rcp, recipients)
{
uint160 hash160 = 0;
if(!validateAddress(rcp.address))
{
return InvalidAddress;

12
src/qt/walletmodel.h

@ -15,7 +15,7 @@ struct SendCoinsRecipient @@ -15,7 +15,7 @@ struct SendCoinsRecipient
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 @@ public: @@ -47,9 +47,7 @@ public:
// 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 @@ public: @@ -57,11 +55,11 @@ public:
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;

Loading…
Cancel
Save