2011-05-12 14:49:42 +02:00
|
|
|
#include "sendcoinsdialog.h"
|
2011-05-12 14:44:52 +02:00
|
|
|
#include "ui_sendcoinsdialog.h"
|
|
|
|
|
2011-05-12 17:55:24 +02:00
|
|
|
#include "addressbookdialog.h"
|
2011-05-13 22:00:27 +02:00
|
|
|
#include "bitcoinaddressvalidator.h"
|
2011-05-12 17:55:24 +02:00
|
|
|
|
2011-05-12 20:16:42 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
2011-05-15 19:31:20 +02:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QLocale>
|
2011-05-12 20:16:42 +02:00
|
|
|
|
2011-05-14 17:25:05 +02:00
|
|
|
#include "base58.h"
|
|
|
|
|
2011-05-15 19:31:20 +02:00
|
|
|
SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) :
|
2011-05-12 14:44:52 +02:00
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::SendCoinsDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2011-05-15 19:31:20 +02:00
|
|
|
|
|
|
|
/* Set up validators */
|
2011-05-14 11:18:39 +02:00
|
|
|
ui->payTo->setMaxLength(BitcoinAddressValidator::MaxAddressLength);
|
2011-05-13 22:00:27 +02:00
|
|
|
ui->payTo->setValidator(new BitcoinAddressValidator(this));
|
2011-05-15 19:31:20 +02:00
|
|
|
QDoubleValidator *amountValidator = new QDoubleValidator(this);
|
|
|
|
amountValidator->setDecimals(8);
|
|
|
|
amountValidator->setBottom(0.0);
|
|
|
|
ui->payAmount->setValidator(amountValidator);
|
|
|
|
|
|
|
|
/* Set initial address if provided */
|
|
|
|
if(!address.isEmpty())
|
|
|
|
{
|
|
|
|
ui->payTo->setText(address);
|
|
|
|
ui->payAmount->setFocus();
|
|
|
|
}
|
2011-05-12 14:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SendCoinsDialog::~SendCoinsDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2011-05-12 17:55:24 +02:00
|
|
|
|
|
|
|
void SendCoinsDialog::on_sendButton_clicked()
|
|
|
|
{
|
2011-05-14 17:25:05 +02:00
|
|
|
QByteArray payTo = ui->payTo->text().toUtf8();
|
|
|
|
uint160 payToHash = 0;
|
2011-05-15 19:31:20 +02:00
|
|
|
double payAmount = 0.0;
|
|
|
|
bool valid = false;
|
|
|
|
|
|
|
|
if(!AddressToHash160(payTo.constData(), payToHash))
|
2011-05-14 17:25:05 +02:00
|
|
|
{
|
2011-05-15 19:31:20 +02:00
|
|
|
QMessageBox::warning(this, tr("Warning"),
|
|
|
|
tr("The recepient address is not valid, please recheck."),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
QMessageBox::Ok);
|
|
|
|
ui->payTo->setFocus();
|
|
|
|
return;
|
2011-05-14 17:25:05 +02:00
|
|
|
}
|
2011-05-15 19:31:20 +02:00
|
|
|
payAmount = QLocale::system().toDouble(ui->payAmount->text(), &valid);
|
|
|
|
if(!valid || payAmount <= 0.0)
|
2011-05-14 17:25:05 +02:00
|
|
|
{
|
2011-05-15 19:31:20 +02:00
|
|
|
QMessageBox::warning(this, tr("Warning"),
|
|
|
|
tr("The amount to pay must be a valid number larger than 0."),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
QMessageBox::Ok);
|
|
|
|
ui->payAmount->setFocus();
|
|
|
|
return;
|
2011-05-14 17:25:05 +02:00
|
|
|
}
|
2011-05-15 19:31:20 +02:00
|
|
|
|
|
|
|
/* TODO: send command to core, once this succeeds do accept() */
|
|
|
|
accept();
|
2011-05-12 17:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsDialog::on_pasteButton_clicked()
|
|
|
|
{
|
2011-05-12 20:16:42 +02:00
|
|
|
/* Paste text from clipboard into recipient field */
|
|
|
|
ui->payTo->setText(QApplication::clipboard()->text());
|
2011-05-12 17:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsDialog::on_addressBookButton_clicked()
|
|
|
|
{
|
|
|
|
AddressBookDialog dlg;
|
|
|
|
dlg.exec();
|
2011-05-13 22:00:27 +02:00
|
|
|
ui->payTo->setText(dlg.getReturnValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsDialog::on_buttonBox_rejected()
|
|
|
|
{
|
|
|
|
reject();
|
2011-05-12 17:55:24 +02:00
|
|
|
}
|