From: Wladimir J. van der Laan Date: Fri, 23 Dec 2011 11:53:31 +0000 (-0800) Subject: Merge pull request #723 from TheBlueMatt/gitianfix X-Git-Tag: v0.4.0-unstable~129^2~298 X-Git-Url: https://git.novaco.in/?a=commitdiff_plain;h=5ad2ca011eaee4f07c71458bb475224608132b25;hp=7415b805c492981992f5c0eb7969fa26ca62b629;p=novacoin.git Merge pull request #723 from TheBlueMatt/gitianfix Fix #722. --- diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index 0bd2113..b690fae 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -19,6 +19,14 @@ OBJECTS_DIR = build MOC_DIR = build UI_DIR = build +# use: qmake "USE_QRCODE=1" +# libqrencode (http://fukuchi.org/works/qrencode/index.en.html) must be installed for support +contains(USE_QRCODE, 1) { + message(Building with QRCode support) + DEFINES += USE_QRCODE + LIBS += -lqrencode +} + # use: qmake "RELEASE=1" contains(RELEASE, 1) { # Mac: compile for maximum compatibility (10.5, 32-bit) @@ -199,6 +207,12 @@ FORMS += \ src/qt/forms/sendcoinsentry.ui \ src/qt/forms/askpassphrasedialog.ui +contains(USE_QRCODE, 1) { +HEADERS += src/qt/qrcodedialog.h +SOURCES += src/qt/qrcodedialog.cpp +FORMS += src/qt/forms/qrcodedialog.ui +} + CODECFORTR = UTF-8 # for lrelease/lupdate diff --git a/contrib/gitian-descriptors/gitian.yml b/contrib/gitian-descriptors/gitian.yml index d0f8dec..903a9dc 100644 --- a/contrib/gitian-descriptors/gitian.yml +++ b/contrib/gitian-descriptors/gitian.yml @@ -16,6 +16,7 @@ packages: - "libssl-dev" - "git-core" - "unzip" +- "qrencode" reference_datetime: "2011-01-30 00:00:00" remotes: - "url": "https://github.com/bitcoin/bitcoin.git" diff --git a/doc/build-osx.txt b/doc/build-osx.txt index 8002441..d47febe 100644 --- a/doc/build-osx.txt +++ b/doc/build-osx.txt @@ -43,6 +43,9 @@ pushd bitcoin/contrib/minipupnpc; sudo port install; popd (this will be unnecessary soon, you will just port install miniupnpc along with the rest of the dependencies). +Optionally install qrencode (and set USE_QRCODE=1): +sudo port install qrencode + 4. Now you should be able to build bitcoind: cd bitcoin/src diff --git a/doc/build-unix.txt b/doc/build-unix.txt index f4178ca..5389339 100644 --- a/doc/build-unix.txt +++ b/doc/build-unix.txt @@ -23,12 +23,13 @@ the graphical bitcoin. Dependencies ------------ - Library Purpose Description - ------- ------- ----------- - libssl SSL Support Secure communications - libdb4.8 Berkeley DB Blockchain & wallet storage - libboost Boost C++ Library - miniupnpc UPnP Support Optional firewall-jumping support + Library Purpose Description + ------- ------- ----------- + libssl SSL Support Secure communications + libdb4.8 Berkeley DB Blockchain & wallet storage + libboost Boost C++ Library + miniupnpc UPnP Support Optional firewall-jumping support + libqrencode QRCode generation Optional QRCode generation miniupnpc may be used for UPnP port mapping. It can be downloaded from http://miniupnp.tuxfamily.org/files/. UPnP support is compiled in and @@ -37,6 +38,12 @@ turned off by default. Set USE_UPNP to a different value to control this: USE_UPNP=0 (the default) UPnP support turned off by default at runtime USE_UPNP=1 UPnP support turned on by default at runtime +libqrencode may be used for QRCode image generation. It can be downloaded +from http://fukuchi.org/works/qrencode/index.html.en, or installed via +your package manager. Set USE_QRCODE to control this: + USE_QRCODE=0 (the default) No QRCode support - libarcode not required + USE_QRCODE=1 QRCode support enabled + Licenses of statically linked libraries: Berkeley DB New BSD license with additional requirement that linked software must be free open source @@ -50,7 +57,6 @@ Versions used in this release: Boost 1.37 miniupnpc 1.6 - Dependency Build Instructions: Ubuntu & Debian ---------------------------------------------- sudo apt-get install build-essential diff --git a/src/makefile.osx b/src/makefile.osx index bd72e6b..cf5ec38 100644 --- a/src/makefile.osx +++ b/src/makefile.osx @@ -96,6 +96,10 @@ else endif endif +ifdef USE_QRCODE + DEFS += -DUSE_QRCODE=$(USE_QRCODE) + LIBS += -lqrencode +endif all: bitcoind diff --git a/src/qt/aboutdialog.cpp b/src/qt/aboutdialog.cpp index a3aa6de..08d7774 100644 --- a/src/qt/aboutdialog.cpp +++ b/src/qt/aboutdialog.cpp @@ -7,7 +7,6 @@ AboutDialog::AboutDialog(QWidget *parent) : ui(new Ui::AboutDialog) { ui->setupUi(this); - } void AboutDialog::setModel(ClientModel *model) diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index 0a147c9..91412fc 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -4,11 +4,17 @@ #include "addresstablemodel.h" #include "editaddressdialog.h" #include "csvmodelwriter.h" +#include "guiutil.h" #include #include #include #include +#include + +#ifdef USE_QRCODE +#include "qrcodedialog.h" +#endif AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : QDialog(parent), @@ -25,6 +31,10 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : ui->deleteButton->setIcon(QIcon()); #endif +#ifndef USE_QRCODE + ui->showQRCode->setVisible(false); +#endif + switch(mode) { case ForSending: @@ -45,7 +55,28 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : break; } ui->tableView->setTabKeyNavigation(false); + ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); + + // Context menu actions + QAction *copyAddressAction = new QAction(tr("Copy address"), this); + QAction *copyLabelAction = new QAction(tr("Copy label"), this); + QAction *editAction = new QAction(tr("Edit"), this); + deleteAction = new QAction(tr("Delete"), this); + contextMenu = new QMenu(); + contextMenu->addAction(copyAddressAction); + contextMenu->addAction(copyLabelAction); + contextMenu->addAction(editAction); + contextMenu->addAction(deleteAction); + + connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(on_copyToClipboard_clicked())); + connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(onCopyLabelAction())); + connect(editAction, SIGNAL(triggered()), this, SLOT(onEditAction())); + connect(deleteAction, SIGNAL(triggered()), this, SLOT(on_deleteButton_clicked())); + + connect(ui->tableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint))); + + // Pass through accept action from button box connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); } @@ -100,18 +131,29 @@ void AddressBookPage::setModel(AddressTableModel *model) void AddressBookPage::on_copyToClipboard_clicked() { - // Copy currently selected address to clipboard - // (or nothing, if nothing selected) - QTableView *table = ui->tableView; - if(!table->selectionModel()) + GUIUtil::copyEntryData(ui->tableView, AddressTableModel::Address); +} +void AddressBookPage::onCopyLabelAction() +{ + GUIUtil::copyEntryData(ui->tableView, AddressTableModel::Label); +} + +void AddressBookPage::onEditAction() +{ + if(!ui->tableView->selectionModel()) + return; + QModelIndexList indexes = ui->tableView->selectionModel()->selectedRows(); + if(indexes.isEmpty()) return; - QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address); - foreach (QModelIndex index, indexes) - { - QVariant address = index.data(); - QApplication::clipboard()->setText(address.toString()); - } + EditAddressDialog dlg( + tab == SendingTab ? + EditAddressDialog::EditSendingAddress : + EditAddressDialog::EditReceivingAddress); + dlg.setModel(model); + QModelIndex origIndex = proxyModel->mapToSource(indexes.at(0)); + dlg.loadRow(origIndex.row()); + dlg.exec(); } void AddressBookPage::on_newAddressButton_clicked() @@ -162,17 +204,23 @@ void AddressBookPage::selectionChanged() switch(tab) { case SendingTab: + // In sending tab, allow deletion of selection ui->deleteButton->setEnabled(true); + deleteAction->setEnabled(true); break; case ReceivingTab: + // Deleting receiving addresses, however, is not allowed ui->deleteButton->setEnabled(false); + deleteAction->setEnabled(false); break; } ui->copyToClipboard->setEnabled(true); + ui->showQRCode->setEnabled(true); } else { ui->deleteButton->setEnabled(false); + ui->showQRCode->setEnabled(false); ui->copyToClipboard->setEnabled(false); } } @@ -197,6 +245,7 @@ void AddressBookPage::done(int retval) if(returnValue.isEmpty()) { + // If no address entry selected, return rejected retval = Rejected; } @@ -227,3 +276,32 @@ void AddressBookPage::exportClicked() QMessageBox::Abort, QMessageBox::Abort); } } + +void AddressBookPage::on_showQRCode_clicked() +{ +#ifdef USE_QRCODE + QTableView *table = ui->tableView; + QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address); + + + QRCodeDialog *d; + foreach (QModelIndex index, indexes) + { + QString address = index.data().toString(), + label = index.sibling(index.row(), 0).data().toString(), + title = QString("%1 << %2 >>").arg(label).arg(address); + + QRCodeDialog *d = new QRCodeDialog(title, address, label, tab == ReceivingTab, this); + d->show(); + } +#endif +} + +void AddressBookPage::contextualMenu(const QPoint &point) +{ + QModelIndex index = ui->tableView->indexAt(point); + if(index.isValid()) + { + contextMenu->exec(QCursor::pos()); + } +} diff --git a/src/qt/addressbookpage.h b/src/qt/addressbookpage.h index 1a97f3d..6b08f84 100644 --- a/src/qt/addressbookpage.h +++ b/src/qt/addressbookpage.h @@ -12,6 +12,7 @@ QT_BEGIN_NAMESPACE class QTableView; class QItemSelection; class QSortFilterProxyModel; +class QMenu; QT_END_NAMESPACE /** Widget that shows a list of sending or receiving addresses. @@ -48,12 +49,23 @@ private: Tabs tab; QString returnValue; QSortFilterProxyModel *proxyModel; + QMenu *contextMenu; + QAction *deleteAction; private slots: void on_deleteButton_clicked(); void on_newAddressButton_clicked(); + /** Copy address of currently selected address entry to clipboard */ void on_copyToClipboard_clicked(); void selectionChanged(); + void on_showQRCode_clicked(); + /** Spawn contextual menu (right mouse menu) for address book entry */ + void contextualMenu(const QPoint &point); + + /** Copy label of currently selected address entry to clipboard */ + void onCopyLabelAction(); + /** Edit currently selected address entry */ + void onEditAction(); }; #endif // ADDRESSBOOKDIALOG_H diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index cba4e85..894bbb9 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -114,6 +114,7 @@ std::string _(const char* psz) int main(int argc, char *argv[]) { + // Internal string conversion is all UTF-8 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForTr()); diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc index aea61d6..5693ae1 100644 --- a/src/qt/bitcoin.qrc +++ b/src/qt/bitcoin.qrc @@ -41,6 +41,7 @@ res/images/about.png res/images/splash2.jpg + res/images/qrcode.png res/movies/update_spinner.mng diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 1c49683..d4ce8a7 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -112,7 +112,6 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): // Status bar notification icons QFrame *frameBlocks = new QFrame(); - //frameBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken); frameBlocks->setContentsMargins(0,0,0,0); frameBlocks->setMinimumWidth(56); frameBlocks->setMaximumWidth(56); diff --git a/src/qt/forms/addressbookpage.ui b/src/qt/forms/addressbookpage.ui index fb098c8..9b301cb 100644 --- a/src/qt/forms/addressbookpage.ui +++ b/src/qt/forms/addressbookpage.ui @@ -80,6 +80,17 @@ + + + Show &QR Code + + + + :/images/qrcode:/images/qrcode + + + + Delete the currently selected address from the list. Only sending addresses can be deleted. diff --git a/src/qt/forms/qrcodedialog.ui b/src/qt/forms/qrcodedialog.ui new file mode 100644 index 0000000..fa21f60 --- /dev/null +++ b/src/qt/forms/qrcodedialog.ui @@ -0,0 +1,213 @@ + + + QRCodeDialog + + + + 0 + 0 + 320 + 404 + + + + Dialog + + + + + + + 0 + 0 + + + + + 300 + 300 + + + + QR Code + + + Qt::AlignCenter + + + + + + + + + + + + + + true + + + Request Payment + + + + + + + + + + 0 + 0 + + + + Amount: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + lnReqAmount + + + + + + + false + + + + 60 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + BTC + + + lnReqAmount + + + + + + + + + + + + + Label: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + lnLabel + + + + + + + + 100 + 0 + + + + + + + + Message: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + lnMessage + + + + + + + + 100 + 0 + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &Save As... + + + + + + + + + + + + + + chkReq + clicked(bool) + lnReqAmount + setEnabled(bool) + + + 92 + 285 + + + 98 + 311 + + + + + diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 158b84a..22d9cc7 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -11,6 +11,10 @@ #include #include #include +#include // For Qt::escape +#include +#include +#include QString GUIUtil::dateTimeStr(qint64 nTime) { @@ -72,3 +76,31 @@ bool GUIUtil::parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out) } return true; } + +QString GUIUtil::HtmlEscape(const QString& str, bool fMultiLine) +{ + QString escaped = Qt::escape(str); + if(fMultiLine) + { + escaped = escaped.replace("\n", "
\n"); + } + return escaped; +} + +QString GUIUtil::HtmlEscape(const std::string& str, bool fMultiLine) +{ + return HtmlEscape(QString::fromStdString(str), fMultiLine); +} + +void GUIUtil::copyEntryData(QAbstractItemView *view, int column, int role) +{ + if(!view || !view->selectionModel()) + return; + QModelIndexList selection = view->selectionModel()->selectedRows(column); + + if(!selection.isEmpty()) + { + // Copy first item + QApplication::clipboard()->setText(selection.at(0).data(role).toString()); + } +} diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 94e3314..3a81bd2 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -9,6 +9,7 @@ class QLineEdit; class QWidget; class QDateTime; class QUrl; +class QAbstractItemView; QT_END_NAMESPACE class SendCoinsRecipient; @@ -31,6 +32,19 @@ public: // 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 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); + + /** Copy a field of the currently selected entry of a view to the clipboard. Does nothing if nothing + is selected. + @param[in] column Data column to extract from the model + @param[in] role Data role to extract from the model + @see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress + */ + static void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole); + }; #endif // GUIUTIL_H diff --git a/src/qt/qrcodedialog.cpp b/src/qt/qrcodedialog.cpp new file mode 100644 index 0000000..ed4c758 --- /dev/null +++ b/src/qt/qrcodedialog.cpp @@ -0,0 +1,106 @@ +#include "qrcodedialog.h" +#include "ui_qrcodedialog.h" +#include +#include +#include +#include +#include + +#include + +#define EXPORT_IMAGE_SIZE 256 + +QRCodeDialog::QRCodeDialog(const QString &title, const QString &addr, const QString &label, bool enableReq, QWidget *parent) : + QDialog(parent), + ui(new Ui::QRCodeDialog), + address(addr) +{ + ui->setupUi(this); + setWindowTitle(title); + setAttribute(Qt::WA_DeleteOnClose); + + ui->chkReq->setVisible(enableReq); + ui->lnReqAmount->setVisible(enableReq); + ui->lblAm1->setVisible(enableReq); + ui->lblAm2->setVisible(enableReq); + + ui->lnLabel->setText(label); + + genCode(); +} + +QRCodeDialog::~QRCodeDialog() +{ + delete ui; +} + +void QRCodeDialog::genCode() { + + QString uri = getURI(); + //qDebug() << "Encoding:" << uri.toUtf8().constData(); + QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1); + myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32); + myImage.fill(0xffffff); + unsigned char *p = code->data; + for(int y = 0; y < code->width; y++) { + for(int x = 0; x < code->width; x++) { + myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff)); + p++; + } + } + QRcode_free(code); + ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300)); +} + +QString QRCodeDialog::getURI() { + QString ret = QString("bitcoin:%1").arg(address); + + int paramCount = 0; + if(ui->chkReq->isChecked() && ui->lnReqAmount->text().isEmpty() == false) { + bool ok= false; + double amount = ui->lnReqAmount->text().toDouble(&ok); + if(ok) { + ret += QString("?amount=%1X8").arg(ui->lnReqAmount->text()); + paramCount++; + } + } + + if(ui->lnLabel->text().isEmpty() == false) { + QString lbl(QUrl::toPercentEncoding(ui->lnLabel->text())); + ret += QString("%1label=%2").arg(paramCount == 0 ? "?" : "&").arg(lbl); + paramCount++; + } + + if(ui->lnMessage->text().isEmpty() == false) { + QString msg(QUrl::toPercentEncoding(ui->lnMessage->text())); + ret += QString("%1message=%2").arg(paramCount == 0 ? "?" : "&").arg(msg); + paramCount++; + } + + return ret; +} + +void QRCodeDialog::on_lnReqAmount_textChanged(const QString &) { + genCode(); +} + +void QRCodeDialog::on_lnLabel_textChanged(const QString &) { + genCode(); +} + +void QRCodeDialog::on_lnMessage_textChanged(const QString &) { + genCode(); +} + +void QRCodeDialog::on_btnSaveAs_clicked() +{ + QString fn = QFileDialog::getSaveFileName(this, "Save Image...", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation), "Images (*.png)"); + if(!fn.isEmpty()) { + myImage.scaled(EXPORT_IMAGE_SIZE, EXPORT_IMAGE_SIZE).save(fn); + } +} + +void QRCodeDialog::on_chkReq_toggled(bool) +{ + genCode(); +} diff --git a/src/qt/qrcodedialog.h b/src/qt/qrcodedialog.h new file mode 100644 index 0000000..7463a88 --- /dev/null +++ b/src/qt/qrcodedialog.h @@ -0,0 +1,37 @@ +#ifndef QRCODEDIALOG_H +#define QRCODEDIALOG_H + +#include +#include + +namespace Ui { + class QRCodeDialog; +} + +class QRCodeDialog : public QDialog +{ + Q_OBJECT + +public: + explicit QRCodeDialog(const QString &title, const QString &address, const QString &label, bool allowReq, QWidget *parent = 0); + ~QRCodeDialog(); + +private slots: + void on_lnReqAmount_textChanged(const QString &arg1); + void on_lnLabel_textChanged(const QString &arg1); + void on_lnMessage_textChanged(const QString &arg1); + void on_btnSaveAs_clicked(); + + void on_chkReq_toggled(bool checked); + +private: + Ui::QRCodeDialog *ui; + QImage myImage; + + QString getURI(); + QString address; + + void genCode(); +}; + +#endif // QRCODEDIALOG_H diff --git a/src/qt/res/images/qrcode.png b/src/qt/res/images/qrcode.png new file mode 100644 index 0000000..c89a49b Binary files /dev/null and b/src/qt/res/images/qrcode.png differ diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 821ef98..8de63c1 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -7,25 +7,9 @@ #include "qtui.h" #include -#include // For Qt::escape using namespace std; -QString TransactionDesc::HtmlEscape(const QString& str, bool fMultiLine) -{ - QString escaped = Qt::escape(str); - if(fMultiLine) - { - escaped = escaped.replace("\n", "
\n"); - } - return escaped; -} - -QString TransactionDesc::HtmlEscape(const std::string& str, bool fMultiLine) -{ - return HtmlEscape(QString::fromStdString(str), fMultiLine); -} - QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx) { if (!wtx.IsFinal()) @@ -86,7 +70,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) { // Online transaction if (!wtx.mapValue["from"].empty()) - strHTML += tr("From: ") + HtmlEscape(wtx.mapValue["from"]) + "
"; + strHTML += tr("From: ") + GUIUtil::HtmlEscape(wtx.mapValue["from"]) + "
"; } else { @@ -105,9 +89,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) { strHTML += tr("From: ") + tr("unknown") + "
"; strHTML += tr("To: "); - strHTML += HtmlEscape(address.ToString()); + strHTML += GUIUtil::HtmlEscape(address.ToString()); if (!wallet->mapAddressBook[address].empty()) - strHTML += tr(" (yours, label: ") + HtmlEscape(wallet->mapAddressBook[address]) + ")"; + strHTML += tr(" (yours, label: ") + GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + ")"; else strHTML += tr(" (yours)"); strHTML += "
"; @@ -129,8 +113,8 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) strAddress = wtx.mapValue["to"]; strHTML += tr("To: "); if (wallet->mapAddressBook.count(strAddress) && !wallet->mapAddressBook[strAddress].empty()) - strHTML += HtmlEscape(wallet->mapAddressBook[strAddress]) + " "; - strHTML += HtmlEscape(strAddress) + "
"; + strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[strAddress]) + " "; + strHTML += GUIUtil::HtmlEscape(strAddress) + "
"; } // @@ -188,8 +172,8 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) { strHTML += tr("To: "); if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty()) - strHTML += HtmlEscape(wallet->mapAddressBook[address]) + " "; - strHTML += HtmlEscape(address.ToString()); + strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + " "; + strHTML += GUIUtil::HtmlEscape(address.ToString()); strHTML += "
"; } } @@ -230,9 +214,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) // Message // if (!wtx.mapValue["message"].empty()) - strHTML += QString("
") + tr("Message:") + "
" + HtmlEscape(wtx.mapValue["message"], true) + "
"; + strHTML += QString("
") + tr("Message:") + "
" + GUIUtil::HtmlEscape(wtx.mapValue["message"], true) + "
"; if (!wtx.mapValue["comment"].empty()) - strHTML += QString("
") + tr("Comment:") + "
" + HtmlEscape(wtx.mapValue["comment"], true) + "
"; + strHTML += QString("
") + tr("Comment:") + "
" + GUIUtil::HtmlEscape(wtx.mapValue["comment"], true) + "
"; if (wtx.IsCoinBase()) strHTML += QString("
") + 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.") + "
"; @@ -251,7 +235,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) strHTML += "Credit: " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,wallet->GetCredit(txout)) + "
"; strHTML += "
Transaction:
"; - strHTML += HtmlEscape(wtx.ToString(), true); + strHTML += GUIUtil::HtmlEscape(wtx.ToString(), true); CTxDB txdb("r"); // To fetch source txouts @@ -274,7 +258,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) if (ExtractAddress(vout.scriptPubKey, address)) { 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 = strHTML + " Amount=" + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC,vout.nValue); diff --git a/src/qt/transactiondesc.h b/src/qt/transactiondesc.h index 55b9eaf..2523f9a 100644 --- a/src/qt/transactiondesc.h +++ b/src/qt/transactiondesc.h @@ -18,8 +18,6 @@ public: 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); }; diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 2dcbf1e..cba0629 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -10,6 +10,7 @@ #include "transactiondescdialog.h" #include "editaddressdialog.h" #include "optionsmodel.h" +#include "guiutil.h" #include #include @@ -100,7 +101,6 @@ TransactionView::TransactionView(QWidget *parent) : QVBoxLayout *vlayout = new QVBoxLayout(this); vlayout->setContentsMargins(0,0,0,0); vlayout->setSpacing(0); - //vlayout->addLayout(hlayout2); QTableView *view = new QTableView(this); vlayout->addLayout(hlayout); @@ -124,12 +124,14 @@ TransactionView::TransactionView(QWidget *parent) : // Actions QAction *copyAddressAction = new QAction(tr("Copy address"), this); QAction *copyLabelAction = new QAction(tr("Copy label"), this); + QAction *copyAmountAction = new QAction(tr("Copy amount"), this); QAction *editLabelAction = new QAction(tr("Edit label"), this); QAction *showDetailsAction = new QAction(tr("Show details..."), this); contextMenu = new QMenu(); contextMenu->addAction(copyAddressAction); contextMenu->addAction(copyLabelAction); + contextMenu->addAction(copyAmountAction); contextMenu->addAction(editLabelAction); contextMenu->addAction(showDetailsAction); @@ -140,14 +142,11 @@ TransactionView::TransactionView(QWidget *parent) : connect(amountWidget, SIGNAL(textChanged(QString)), this, SLOT(changedAmount(QString))); connect(view, SIGNAL(doubleClicked(QModelIndex)), this, SIGNAL(doubleClicked(QModelIndex))); - - connect(view, - SIGNAL(customContextMenuRequested(QPoint)), - this, - SLOT(contextualMenu(QPoint))); + connect(view, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint))); connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(copyAddress())); connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel())); + connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount())); connect(editLabelAction, SIGNAL(triggered()), this, SLOT(editLabel())); connect(showDetailsAction, SIGNAL(triggered()), this, SLOT(showDetails())); } @@ -303,24 +302,17 @@ void TransactionView::contextualMenu(const QPoint &point) void TransactionView::copyAddress() { - if(!transactionView->selectionModel()) - return; - QModelIndexList selection = transactionView->selectionModel()->selectedRows(); - if(!selection.isEmpty()) - { - QApplication::clipboard()->setText(selection.at(0).data(TransactionTableModel::AddressRole).toString()); - } + GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::AddressRole); } void TransactionView::copyLabel() { - if(!transactionView->selectionModel()) - return; - QModelIndexList selection = transactionView->selectionModel()->selectedRows(); - if(!selection.isEmpty()) - { - QApplication::clipboard()->setText(selection.at(0).data(TransactionTableModel::LabelRole).toString()); - } + GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::LabelRole); +} + +void TransactionView::copyAmount() +{ + GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::FormattedAmountRole); } void TransactionView::editLabel() diff --git a/src/qt/transactionview.h b/src/qt/transactionview.h index 67d0b46..bc6e1e4 100644 --- a/src/qt/transactionview.h +++ b/src/qt/transactionview.h @@ -60,6 +60,11 @@ private: private slots: void contextualMenu(const QPoint &); void dateRangeChanged(); + void showDetails(); + void copyAddress(); + void editLabel(); + void copyLabel(); + void copyAmount(); signals: void doubleClicked(const QModelIndex&); @@ -70,10 +75,6 @@ public slots: void changedPrefix(const QString &prefix); void changedAmount(const QString &amount); void exportClicked(); - void showDetails(); - void copyAddress(); - void editLabel(); - void copyLabel(); };