Browse Source

Move HtmlEscape (escape for qt rich text controls) to qt gui utilities

0.8
Wladimir J. van der Laan 13 years ago
parent
commit
e073457191
  1. 1
      src/qt/aboutdialog.cpp
  2. 16
      src/qt/guiutil.cpp
  3. 4
      src/qt/guiutil.h
  4. 38
      src/qt/transactiondesc.cpp
  5. 2
      src/qt/transactiondesc.h

1
src/qt/aboutdialog.cpp

@ -7,7 +7,6 @@ AboutDialog::AboutDialog(QWidget *parent) :
ui(new Ui::AboutDialog) ui(new Ui::AboutDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
} }
void AboutDialog::setModel(ClientModel *model) void AboutDialog::setModel(ClientModel *model)

16
src/qt/guiutil.cpp

@ -11,6 +11,7 @@
#include <QFont> #include <QFont>
#include <QLineEdit> #include <QLineEdit>
#include <QUrl> #include <QUrl>
#include <QTextDocument> // For Qt::escape
QString GUIUtil::dateTimeStr(qint64 nTime) QString GUIUtil::dateTimeStr(qint64 nTime)
{ {
@ -72,3 +73,18 @@ bool GUIUtil::parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out)
} }
return true; return true;
} }
QString GUIUtil::HtmlEscape(const QString& str, bool fMultiLine)
{
QString escaped = Qt::escape(str);
if(fMultiLine)
{
escaped = escaped.replace("\n", "<br>\n");
}
return escaped;
}
QString GUIUtil::HtmlEscape(const std::string& str, bool fMultiLine)
{
return HtmlEscape(QString::fromStdString(str), fMultiLine);
}

4
src/qt/guiutil.h

@ -31,6 +31,10 @@ public:
// Parse "bitcoin:" URL into recipient object, return true on succesful parsing // Parse "bitcoin:" URL into recipient object, return true on succesful parsing
// See Bitcoin URL definition discussion here: https://bitcointalk.org/index.php?topic=33490.0 // See Bitcoin URL definition discussion here: https://bitcointalk.org/index.php?topic=33490.0
static bool parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out); static bool parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out);
// HTML escaping for rich text controls
static QString HtmlEscape(const QString& str, bool fMultiLine=false);
static QString HtmlEscape(const std::string& str, bool fMultiLine=false);
}; };
#endif // GUIUTIL_H #endif // GUIUTIL_H

38
src/qt/transactiondesc.cpp

@ -7,25 +7,9 @@
#include "qtui.h" #include "qtui.h"
#include <QString> #include <QString>
#include <QTextDocument> // For Qt::escape
using namespace std; using namespace std;
QString TransactionDesc::HtmlEscape(const QString& str, bool fMultiLine)
{
QString escaped = Qt::escape(str);
if(fMultiLine)
{
escaped = escaped.replace("\n", "<br>\n");
}
return escaped;
}
QString TransactionDesc::HtmlEscape(const std::string& str, bool fMultiLine)
{
return HtmlEscape(QString::fromStdString(str), fMultiLine);
}
QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx) QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx)
{ {
if (!wtx.IsFinal()) if (!wtx.IsFinal())
@ -86,7 +70,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
{ {
// Online transaction // Online transaction
if (!wtx.mapValue["from"].empty()) if (!wtx.mapValue["from"].empty())
strHTML += tr("<b>From:</b> ") + HtmlEscape(wtx.mapValue["from"]) + "<br>"; strHTML += tr("<b>From:</b> ") + GUIUtil::HtmlEscape(wtx.mapValue["from"]) + "<br>";
} }
else else
{ {
@ -105,9 +89,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
{ {
strHTML += tr("<b>From:</b> ") + tr("unknown") + "<br>"; strHTML += tr("<b>From:</b> ") + tr("unknown") + "<br>";
strHTML += tr("<b>To:</b> "); strHTML += tr("<b>To:</b> ");
strHTML += HtmlEscape(address.ToString()); strHTML += GUIUtil::HtmlEscape(address.ToString());
if (!wallet->mapAddressBook[address].empty()) if (!wallet->mapAddressBook[address].empty())
strHTML += tr(" (yours, label: ") + HtmlEscape(wallet->mapAddressBook[address]) + ")"; strHTML += tr(" (yours, label: ") + GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + ")";
else else
strHTML += tr(" (yours)"); strHTML += tr(" (yours)");
strHTML += "<br>"; strHTML += "<br>";
@ -129,8 +113,8 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
strAddress = wtx.mapValue["to"]; strAddress = wtx.mapValue["to"];
strHTML += tr("<b>To:</b> "); strHTML += tr("<b>To:</b> ");
if (wallet->mapAddressBook.count(strAddress) && !wallet->mapAddressBook[strAddress].empty()) if (wallet->mapAddressBook.count(strAddress) && !wallet->mapAddressBook[strAddress].empty())
strHTML += HtmlEscape(wallet->mapAddressBook[strAddress]) + " "; strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[strAddress]) + " ";
strHTML += HtmlEscape(strAddress) + "<br>"; strHTML += GUIUtil::HtmlEscape(strAddress) + "<br>";
} }
// //
@ -188,8 +172,8 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
{ {
strHTML += tr("<b>To:</b> "); strHTML += tr("<b>To:</b> ");
if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty()) if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty())
strHTML += HtmlEscape(wallet->mapAddressBook[address]) + " "; strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + " ";
strHTML += HtmlEscape(address.ToString()); strHTML += GUIUtil::HtmlEscape(address.ToString());
strHTML += "<br>"; strHTML += "<br>";
} }
} }
@ -230,9 +214,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
// Message // Message
// //
if (!wtx.mapValue["message"].empty()) if (!wtx.mapValue["message"].empty())
strHTML += QString("<br><b>") + tr("Message:") + "</b><br>" + HtmlEscape(wtx.mapValue["message"], true) + "<br>"; strHTML += QString("<br><b>") + tr("Message:") + "</b><br>" + GUIUtil::HtmlEscape(wtx.mapValue["message"], true) + "<br>";
if (!wtx.mapValue["comment"].empty()) if (!wtx.mapValue["comment"].empty())
strHTML += QString("<br><b>") + tr("Comment:") + "</b><br>" + HtmlEscape(wtx.mapValue["comment"], true) + "<br>"; strHTML += QString("<br><b>") + tr("Comment:") + "</b><br>" + GUIUtil::HtmlEscape(wtx.mapValue["comment"], true) + "<br>";
if (wtx.IsCoinBase()) if (wtx.IsCoinBase())
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>"; 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>";
@ -251,7 +235,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
strHTML += "<b>Credit:</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,wallet->GetCredit(txout)) + "<br>"; strHTML += "<b>Credit:</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,wallet->GetCredit(txout)) + "<br>";
strHTML += "<br><b>Transaction:</b><br>"; strHTML += "<br><b>Transaction:</b><br>";
strHTML += HtmlEscape(wtx.ToString(), true); strHTML += GUIUtil::HtmlEscape(wtx.ToString(), true);
CTxDB txdb("r"); // To fetch source txouts CTxDB txdb("r"); // To fetch source txouts
@ -274,7 +258,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
if (ExtractAddress(vout.scriptPubKey, address)) if (ExtractAddress(vout.scriptPubKey, address))
{ {
if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty()) if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty())
strHTML += HtmlEscape(wallet->mapAddressBook[address]) + " "; strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + " ";
strHTML += QString::fromStdString(address.ToString()); strHTML += QString::fromStdString(address.ToString());
} }
strHTML = strHTML + " Amount=" + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,vout.nValue); strHTML = strHTML + " Amount=" + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,vout.nValue);

2
src/qt/transactiondesc.h

@ -18,8 +18,6 @@ public:
private: private:
TransactionDesc() {} 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); static QString FormatTxStatus(const CWalletTx& wtx);
}; };

Loading…
Cancel
Save