diff options
Diffstat (limited to 'src/qt/sendcoinsentry.cpp')
-rw-r--r-- | src/qt/sendcoinsentry.cpp | 108 |
1 files changed, 76 insertions, 32 deletions
diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index ee84f7bc11..2d240f1fe5 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -1,12 +1,15 @@ +// Copyright (c) 2011-2013 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + #include "sendcoinsentry.h" #include "ui_sendcoinsentry.h" -#include "guiutil.h" -#include "bitcoinunits.h" #include "addressbookpage.h" -#include "walletmodel.h" -#include "optionsmodel.h" #include "addresstablemodel.h" +#include "guiutil.h" +#include "optionsmodel.h" +#include "walletmodel.h" #include <QApplication> #include <QClipboard> @@ -18,7 +21,7 @@ SendCoinsEntry::SendCoinsEntry(QWidget *parent) : { ui->setupUi(this); - setCurrentWidget(ui->SendCoinsInsecure); + setCurrentWidget(ui->SendCoins); #ifdef Q_OS_MAC ui->payToLayout->setSpacing(4); @@ -28,10 +31,12 @@ SendCoinsEntry::SendCoinsEntry(QWidget *parent) : ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book")); ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)")); #endif - setFocusPolicy(Qt::TabFocus); setFocusProxy(ui->payTo); + // normal bitcoin address field GUIUtil::setupAddressWidget(ui->payTo, this); + // just a label for displaying bitcoin address(es) + ui->payTo_is->setFont(GUIUtil::bitcoinAddressFont()); } SendCoinsEntry::~SendCoinsEntry() @@ -49,7 +54,7 @@ void SendCoinsEntry::on_addressBookButton_clicked() { if(!model) return; - AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this); + AddressBookPage dlg(AddressBookPage::ForSelection, AddressBookPage::SendingTab, this); dlg.setModel(model->getAddressTableModel()); if(dlg.exec()) { @@ -60,19 +65,14 @@ void SendCoinsEntry::on_addressBookButton_clicked() void SendCoinsEntry::on_payTo_textChanged(const QString &address) { - if(!model) - return; - // Fill in label from address book, if address has an associated label - QString associatedLabel = model->getAddressTableModel()->labelForAddress(address); - if(!associatedLabel.isEmpty()) - ui->addAsLabel->setText(associatedLabel); + updateLabel(address); } void SendCoinsEntry::setModel(WalletModel *model) { this->model = model; - if(model && model->getOptionsModel()) + if (model && model->getOptionsModel()) connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); clear(); @@ -85,10 +85,21 @@ void SendCoinsEntry::setRemoveEnabled(bool enabled) void SendCoinsEntry::clear() { + // clear UI elements for normal payment ui->payTo->clear(); ui->addAsLabel->clear(); ui->payAmount->clear(); + // clear UI elements for insecure payment request + ui->payTo_is->clear(); + ui->memoTextLabel_is->clear(); + ui->payAmount_is->clear(); + // clear UI elements for secure payment request + ui->payTo_s->clear(); + ui->memoTextLabel_s->clear(); + ui->payAmount_s->clear(); + ui->payTo->setFocus(); + // update the display unit, to not use the default ("BTC") updateDisplayUnit(); } @@ -100,20 +111,23 @@ void SendCoinsEntry::on_deleteButton_clicked() bool SendCoinsEntry::validate() { + if (!model) + return false; + // Check input validity bool retval = true; - if (!recipient.authenticatedMerchant.isEmpty()) + // Skip checks for payment request + if (recipient.paymentRequest.IsInitialized()) return retval; - if (!ui->payTo->hasAcceptableInput() || - (model && !model->validateAddress(ui->payTo->text()))) + if (!ui->payTo->hasAcceptableInput() || !model->validateAddress(ui->payTo->text())) { ui->payTo->setValid(false); retval = false; } - if(!ui->payAmount->validate()) + if (!ui->payAmount->validate()) { retval = false; } @@ -129,10 +143,11 @@ bool SendCoinsEntry::validate() SendCoinsRecipient SendCoinsEntry::getValue() { - if (!recipient.authenticatedMerchant.isEmpty()) + // Payment request + if (recipient.paymentRequest.IsInitialized()) return recipient; - // User-entered or non-authenticated: + // Normal payment recipient.address = ui->payTo->text(); recipient.label = ui->addAsLabel->text(); recipient.amount = ui->payAmount->value(); @@ -154,18 +169,30 @@ void SendCoinsEntry::setValue(const SendCoinsRecipient &value) { recipient = value; - ui->payTo->setText(value.address); - ui->addAsLabel->setText(value.label); - ui->payAmount->setValue(value.amount); - - if (!recipient.authenticatedMerchant.isEmpty()) + if (recipient.paymentRequest.IsInitialized()) // payment request { - const payments::PaymentDetails& details = value.paymentRequest.getDetails(); - - ui->payTo_s->setText(value.authenticatedMerchant); - ui->memoTextLabel_s->setText(QString::fromStdString(details.memo())); - ui->payAmount_s->setValue(value.amount); - setCurrentWidget(ui->SendCoinsSecure); + if (recipient.authenticatedMerchant.isEmpty()) // insecure + { + ui->payTo_is->setText(recipient.address); + ui->memoTextLabel_is->setText(recipient.message); + ui->payAmount_is->setValue(recipient.amount); + ui->payAmount_is->setReadOnly(true); + setCurrentWidget(ui->SendCoins_InsecurePaymentRequest); + } + else // secure + { + ui->payTo_s->setText(recipient.authenticatedMerchant); + ui->memoTextLabel_s->setText(recipient.message); + ui->payAmount_s->setValue(recipient.amount); + ui->payAmount_s->setReadOnly(true); + setCurrentWidget(ui->SendCoins_SecurePaymentRequest); + } + } + else // normal payment + { + ui->payTo->setText(recipient.address); + ui->addAsLabel->setText(recipient.label); + ui->payAmount->setValue(recipient.amount); } } @@ -177,7 +204,7 @@ void SendCoinsEntry::setAddress(const QString &address) bool SendCoinsEntry::isClear() { - return ui->payTo->text().isEmpty() && ui->payTo_s->text().isEmpty(); + return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty(); } void SendCoinsEntry::setFocus() @@ -191,6 +218,23 @@ void SendCoinsEntry::updateDisplayUnit() { // Update payAmount with the current unit ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); + ui->payAmount_is->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); ui->payAmount_s->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); } } + +bool SendCoinsEntry::updateLabel(const QString &address) +{ + if(!model) + return false; + + // Fill in label from address book, if address has an associated label + QString associatedLabel = model->getAddressTableModel()->labelForAddress(address); + if(!associatedLabel.isEmpty()) + { + ui->addAsLabel->setText(associatedLabel); + return true; + } + + return false; +} |