You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.0 KiB
114 lines
3.0 KiB
14 years ago
|
#include "sendcoinsdialog.h"
|
||
14 years ago
|
#include "ui_sendcoinsdialog.h"
|
||
14 years ago
|
#include "clientmodel.h"
|
||
14 years ago
|
#include "guiutil.h"
|
||
14 years ago
|
|
||
14 years ago
|
#include "addressbookdialog.h"
|
||
14 years ago
|
#include "optionsmodel.h"
|
||
14 years ago
|
|
||
14 years ago
|
#include <QApplication>
|
||
|
#include <QClipboard>
|
||
14 years ago
|
#include <QMessageBox>
|
||
|
#include <QLocale>
|
||
14 years ago
|
#include <QDebug>
|
||
14 years ago
|
|
||
14 years ago
|
#include "util.h"
|
||
14 years ago
|
#include "base58.h"
|
||
|
|
||
14 years ago
|
SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) :
|
||
14 years ago
|
QDialog(parent),
|
||
14 years ago
|
ui(new Ui::SendCoinsDialog),
|
||
|
model(0)
|
||
14 years ago
|
{
|
||
|
ui->setupUi(this);
|
||
14 years ago
|
|
||
14 years ago
|
GUIUtil::setupAddressWidget(ui->payTo, this);
|
||
|
GUIUtil::setupAmountWidget(ui->payAmount, this);
|
||
14 years ago
|
|
||
|
/* Set initial address if provided */
|
||
|
if(!address.isEmpty())
|
||
|
{
|
||
|
ui->payTo->setText(address);
|
||
|
ui->payAmount->setFocus();
|
||
|
}
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
void SendCoinsDialog::setModel(ClientModel *model)
|
||
|
{
|
||
|
this->model = model;
|
||
|
}
|
||
|
|
||
14 years ago
|
SendCoinsDialog::~SendCoinsDialog()
|
||
|
{
|
||
|
delete ui;
|
||
|
}
|
||
14 years ago
|
|
||
|
void SendCoinsDialog::on_sendButton_clicked()
|
||
|
{
|
||
14 years ago
|
bool valid;
|
||
|
QString payAmount = ui->payAmount->text();
|
||
|
qint64 payAmountParsed;
|
||
14 years ago
|
|
||
14 years ago
|
valid = ParseMoney(payAmount.toStdString(), payAmountParsed);
|
||
|
|
||
|
if(!valid)
|
||
14 years ago
|
{
|
||
14 years ago
|
QMessageBox::warning(this, tr("Send Coins"),
|
||
|
tr("The amount to pay must be a valid number."),
|
||
|
QMessageBox::Ok, QMessageBox::Ok);
|
||
14 years ago
|
return;
|
||
14 years ago
|
}
|
||
14 years ago
|
|
||
14 years ago
|
switch(model->sendCoins(ui->payTo->text(), payAmountParsed))
|
||
14 years ago
|
{
|
||
14 years ago
|
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);
|
||
14 years ago
|
ui->payAmount->setFocus();
|
||
14 years ago
|
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").
|
||
14 years ago
|
arg(QString::fromStdString(FormatMoney(model->getOptionsModel()->getTransactionFee()))),
|
||
14 years ago
|
QMessageBox::Ok, QMessageBox::Ok);
|
||
|
ui->payAmount->setFocus();
|
||
|
break;
|
||
14 years ago
|
case ClientModel::OK:
|
||
|
accept();
|
||
|
break;
|
||
14 years ago
|
}
|
||
14 years ago
|
}
|
||
|
|
||
|
void SendCoinsDialog::on_pasteButton_clicked()
|
||
|
{
|
||
14 years ago
|
/* Paste text from clipboard into recipient field */
|
||
|
ui->payTo->setText(QApplication::clipboard()->text());
|
||
14 years ago
|
}
|
||
|
|
||
|
void SendCoinsDialog::on_addressBookButton_clicked()
|
||
|
{
|
||
|
AddressBookDialog dlg;
|
||
14 years ago
|
dlg.setModel(model->getAddressTableModel());
|
||
|
dlg.setTab(AddressBookDialog::SendingTab);
|
||
14 years ago
|
dlg.exec();
|
||
14 years ago
|
ui->payTo->setText(dlg.getReturnValue());
|
||
|
}
|
||
|
|
||
|
void SendCoinsDialog::on_buttonBox_rejected()
|
||
|
{
|
||
|
reject();
|
||
14 years ago
|
}
|