lbrycrd/gui/src/sendcoinsdialog.cpp

116 lines
3.1 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-30 20:20:12 +02:00
#include "clientmodel.h"
2011-05-12 14:44:52 +02:00
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),
2011-05-30 20:20:12 +02:00
ui(new Ui::SendCoinsDialog),
model(0)
2011-05-12 14:44:52 +02:00
{
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
}
2011-05-30 20:20:12 +02:00
void SendCoinsDialog::setModel(ClientModel *model)
{
this->model = model;
}
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-30 20:20:12 +02:00
bool valid;
QString payAmount = ui->payAmount->text();
qint64 payAmountParsed;
2011-05-30 20:20:12 +02:00
valid = ParseMoney(payAmount.toStdString(), payAmountParsed);
if(!valid)
2011-05-14 17:25:05 +02:00
{
2011-05-30 20:20:12 +02:00
QMessageBox::warning(this, tr("Send Coins"),
tr("The amount to pay must be a valid number."),
QMessageBox::Ok, QMessageBox::Ok);
return;
2011-05-14 17:25:05 +02:00
}
2011-05-30 20:20:12 +02:00
switch(model->sendCoins(ui->payTo->text(), payAmountParsed))
2011-05-14 17:25:05 +02:00
{
2011-05-30 20:20:12 +02:00
case ClientModel::InvalidAddress:
QMessageBox::warning(this, tr("Send Coins"),
tr("The recepient address is not valid, please recheck."),
QMessageBox::Ok, QMessageBox::Ok);
ui->payTo->setFocus();
break;
case ClientModel::InvalidAmount:
QMessageBox::warning(this, tr("Send Coins"),
tr("The amount to pay must be larger than 0."),
QMessageBox::Ok, QMessageBox::Ok);
ui->payAmount->setFocus();
2011-05-30 20:20:12 +02:00
break;
case ClientModel::AmountExceedsBalance:
QMessageBox::warning(this, tr("Send Coins"),
tr("Amount exceeds your balance"),
QMessageBox::Ok, QMessageBox::Ok);
ui->payAmount->setFocus();
break;
case ClientModel::AmountWithFeeExceedsBalance:
QMessageBox::warning(this, tr("Send Coins"),
tr("Total exceeds your balance when the %1 transaction fee is included").
arg(QString::fromStdString(FormatMoney(model->getTransactionFee()))),
QMessageBox::Ok, QMessageBox::Ok);
ui->payAmount->setFocus();
break;
case ClientModel::OK:
accept();
break;
2011-05-14 17:25:05 +02:00
}
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
}