2011-07-16 19:01:05 +02:00
|
|
|
#include "sendcoinsentry.h"
|
|
|
|
#include "ui_sendcoinsentry.h"
|
|
|
|
#include "guiutil.h"
|
2011-07-25 21:35:45 +02:00
|
|
|
#include "bitcoinunits.h"
|
2011-07-16 19:01:05 +02:00
|
|
|
#include "addressbookpage.h"
|
|
|
|
#include "walletmodel.h"
|
2011-07-29 14:36:35 +02:00
|
|
|
#include "optionsmodel.h"
|
2011-07-16 19:01:05 +02:00
|
|
|
#include "addresstablemodel.h"
|
|
|
|
|
|
|
|
#include "qapplication.h"
|
|
|
|
#include "qclipboard.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
SendCoinsEntry::SendCoinsEntry(QWidget *parent) :
|
|
|
|
QFrame(parent),
|
|
|
|
ui(new Ui::SendCoinsEntry),
|
|
|
|
model(0)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
#if QT_VERSION >= 0x040700
|
|
|
|
ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
|
|
|
|
ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
|
|
|
|
#endif
|
|
|
|
setFocusPolicy(Qt::TabFocus);
|
|
|
|
setFocusProxy(ui->payTo);
|
|
|
|
|
|
|
|
GUIUtil::setupAddressWidget(ui->payTo, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
SendCoinsEntry::~SendCoinsEntry()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsEntry::on_pasteButton_clicked()
|
|
|
|
{
|
|
|
|
// Paste text from clipboard into recipient field
|
|
|
|
ui->payTo->setText(QApplication::clipboard()->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsEntry::on_addressBookButton_clicked()
|
|
|
|
{
|
|
|
|
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
|
|
|
|
dlg.setModel(model->getAddressTableModel());
|
|
|
|
if(dlg.exec())
|
|
|
|
{
|
|
|
|
ui->payTo->setText(dlg.getReturnValue());
|
|
|
|
ui->payAmount->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsEntry::on_payTo_textChanged(const QString &address)
|
|
|
|
{
|
|
|
|
ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsEntry::setModel(WalletModel *model)
|
|
|
|
{
|
|
|
|
this->model = model;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsEntry::setRemoveEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
ui->deleteButton->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsEntry::clear()
|
|
|
|
{
|
|
|
|
ui->payTo->clear();
|
|
|
|
ui->addAsLabel->clear();
|
2011-07-22 17:06:37 +02:00
|
|
|
ui->payAmount->clear();
|
2011-07-16 19:01:05 +02:00
|
|
|
ui->payTo->setFocus();
|
2011-07-29 14:36:35 +02:00
|
|
|
if(model)
|
|
|
|
{
|
|
|
|
ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
|
|
|
|
}
|
2011-07-16 19:01:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsEntry::on_deleteButton_clicked()
|
|
|
|
{
|
|
|
|
emit removeEntry(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SendCoinsEntry::validate()
|
|
|
|
{
|
|
|
|
// Check input validity
|
|
|
|
bool retval = true;
|
|
|
|
|
|
|
|
if(!ui->payAmount->validate())
|
|
|
|
{
|
|
|
|
retval = false;
|
|
|
|
}
|
2011-07-26 13:08:34 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if(ui->payAmount->value() <= 0)
|
|
|
|
{
|
|
|
|
// Cannot send 0 coins or less
|
|
|
|
ui->payAmount->setValid(false);
|
|
|
|
retval = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-16 19:01:05 +02:00
|
|
|
if(!ui->payTo->hasAcceptableInput() ||
|
|
|
|
(model && !model->validateAddress(ui->payTo->text())))
|
|
|
|
{
|
|
|
|
ui->payTo->setValid(false);
|
|
|
|
retval = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendCoinsRecipient SendCoinsEntry::getValue()
|
|
|
|
{
|
|
|
|
SendCoinsRecipient rv;
|
|
|
|
|
|
|
|
rv.address = ui->payTo->text();
|
|
|
|
rv.label = ui->addAsLabel->text();
|
2011-07-26 13:08:34 +02:00
|
|
|
rv.amount = ui->payAmount->value();
|
2011-07-16 19:01:05 +02:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
|
|
|
|
{
|
|
|
|
QWidget::setTabOrder(prev, ui->payTo);
|
|
|
|
QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
|
|
|
|
QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
|
|
|
|
QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
|
|
|
|
QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
|
|
|
|
return ui->payAmount->setupTabChain(ui->addAsLabel);
|
|
|
|
}
|
2011-08-07 16:04:48 +02:00
|
|
|
|
|
|
|
void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
|
|
|
|
{
|
|
|
|
ui->payTo->setText(value.address);
|
|
|
|
ui->addAsLabel->setText(value.label);
|
|
|
|
ui->payAmount->setValue(value.amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SendCoinsEntry::isClear()
|
|
|
|
{
|
|
|
|
return ui->payTo->text().isEmpty();
|
|
|
|
}
|
|
|
|
|