lbrycrd/gui/src/sendcoinsdialog.cpp

93 lines
2.4 KiB
C++
Raw Normal View History

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>
#include <QMessageBox>
#include <QLocale>
#include <QDebug>
2011-05-12 20:16:42 +02:00
#include "util.h"
2011-05-14 17:25:05 +02:00
#include "base58.h"
SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) :
2011-05-12 14:44:52 +02:00
QDialog(parent),
ui(new Ui::SendCoinsDialog)
{
ui->setupUi(this);
/* 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));
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;
int64 payAmount = 0.0;
bool valid = false;
if(!AddressToHash160(payTo.constData(), payToHash))
2011-05-14 17:25:05 +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
}
valid = ParseMoney(ui->payAmount->text().toStdString(), payAmount);
if(!valid || payAmount <= 0)
2011-05-14 17:25:05 +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
}
qDebug() << "Pay " << payAmount;
/* 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
}