bitcoin/gui/src/sendcoinsdialog.cpp

112 lines
2.9 KiB
C++
Raw Normal View History

2011-05-12 05:49:42 -07:00
#include "sendcoinsdialog.h"
2011-05-12 05:44:52 -07:00
#include "ui_sendcoinsdialog.h"
2011-05-30 11:20:12 -07:00
#include "clientmodel.h"
#include "guiutil.h"
2011-05-12 05:44:52 -07:00
2011-05-12 08:55:24 -07:00
#include "addressbookdialog.h"
2011-06-01 00:34:12 -07:00
#include "optionsmodel.h"
2011-05-12 08:55:24 -07:00
2011-05-12 11:16:42 -07:00
#include <QApplication>
#include <QClipboard>
#include <QMessageBox>
#include <QLocale>
#include <QDebug>
2011-05-12 11:16:42 -07:00
#include "util.h"
2011-05-14 08:25:05 -07:00
#include "base58.h"
SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) :
2011-05-12 05:44:52 -07:00
QDialog(parent),
2011-05-30 11:20:12 -07:00
ui(new Ui::SendCoinsDialog),
model(0)
2011-05-12 05:44:52 -07:00
{
ui->setupUi(this);
GUIUtil::setupAddressWidget(ui->payTo, this);
GUIUtil::setupAmountWidget(ui->payAmount, this);
/* Set initial address if provided */
if(!address.isEmpty())
{
ui->payTo->setText(address);
ui->payAmount->setFocus();
}
2011-05-12 05:44:52 -07:00
}
2011-05-30 11:20:12 -07:00
void SendCoinsDialog::setModel(ClientModel *model)
{
this->model = model;
}
2011-05-12 05:44:52 -07:00
SendCoinsDialog::~SendCoinsDialog()
{
delete ui;
}
2011-05-12 08:55:24 -07:00
void SendCoinsDialog::on_sendButton_clicked()
{
2011-05-30 11:20:12 -07:00
bool valid;
QString payAmount = ui->payAmount->text();
qint64 payAmountParsed;
2011-05-30 11:20:12 -07:00
valid = ParseMoney(payAmount.toStdString(), payAmountParsed);
if(!valid)
2011-05-14 08:25:05 -07:00
{
2011-05-30 11:20:12 -07: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 08:25:05 -07:00
}
2011-05-30 11:20:12 -07:00
switch(model->sendCoins(ui->payTo->text(), payAmountParsed))
2011-05-14 08:25:05 -07:00
{
2011-05-30 11:20:12 -07: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 11:20:12 -07: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").
2011-06-01 00:34:12 -07:00
arg(QString::fromStdString(FormatMoney(model->getOptionsModel()->getTransactionFee()))),
2011-05-30 11:20:12 -07:00
QMessageBox::Ok, QMessageBox::Ok);
ui->payAmount->setFocus();
break;
case ClientModel::OK:
accept();
break;
2011-05-14 08:25:05 -07:00
}
2011-05-12 08:55:24 -07:00
}
void SendCoinsDialog::on_pasteButton_clicked()
{
2011-05-12 11:16:42 -07:00
/* Paste text from clipboard into recipient field */
ui->payTo->setText(QApplication::clipboard()->text());
2011-05-12 08:55:24 -07:00
}
void SendCoinsDialog::on_addressBookButton_clicked()
{
AddressBookDialog dlg;
dlg.exec();
2011-05-13 13:00:27 -07:00
ui->payTo->setText(dlg.getReturnValue());
}
void SendCoinsDialog::on_buttonBox_rejected()
{
reject();
2011-05-12 08:55:24 -07:00
}