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"
|
|
|
|
|
2011-08-07 16:09:49 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
2011-07-16 19:01:05 +02:00
|
|
|
|
|
|
|
SendCoinsEntry::SendCoinsEntry(QWidget *parent) :
|
|
|
|
QFrame(parent),
|
|
|
|
ui(new Ui::SendCoinsEntry),
|
|
|
|
model(0)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2011-10-07 13:21:45 +02:00
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
ui->payToLayout->setSpacing(4);
|
|
|
|
#endif
|
|
|
|
|
2011-07-16 19:01:05 +02:00
|
|
|
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()
|
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!model)
|
|
|
|
return;
|
2011-07-16 19:01:05 +02:00
|
|
|
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)
|
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!model)
|
|
|
|
return;
|
2012-04-13 21:08:46 +02:00
|
|
|
// 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);
|
|
|
|
}
|
2011-07-16 19:01:05 +02:00
|
|
|
|
|
|
|
void SendCoinsEntry::setModel(WalletModel *model)
|
|
|
|
{
|
|
|
|
this->model = model;
|
2012-03-16 13:23:59 +01:00
|
|
|
clear();
|
2011-07-16 19:01:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-11-08 21:18:36 +01:00
|
|
|
if(model && model->getOptionsModel())
|
2011-07-29 14:36:35 +02:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2011-12-07 06:00:04 +01:00
|
|
|
void SendCoinsEntry::setFocus()
|
|
|
|
{
|
|
|
|
ui->payTo->setFocus();
|
|
|
|
}
|
|
|
|
|