2011-05-12 14:49:42 +02:00
|
|
|
#include "sendcoinsdialog.h"
|
2011-05-12 14:44:52 +02:00
|
|
|
#include "ui_sendcoinsdialog.h"
|
2011-06-30 18:05:29 +02:00
|
|
|
#include "walletmodel.h"
|
2011-06-02 15:57:23 +02:00
|
|
|
#include "guiutil.h"
|
2011-05-12 14:44:52 +02:00
|
|
|
|
2011-05-12 17:55:24 +02:00
|
|
|
#include "addressbookdialog.h"
|
2011-06-01 09:34:12 +02:00
|
|
|
#include "optionsmodel.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-27 21:43:05 +02:00
|
|
|
#include <QDebug>
|
2011-05-12 20:16:42 +02:00
|
|
|
|
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),
|
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);
|
2011-05-15 19:31:20 +02:00
|
|
|
|
2011-06-02 15:57:23 +02:00
|
|
|
GUIUtil::setupAddressWidget(ui->payTo, this);
|
2011-05-15 19:31:20 +02:00
|
|
|
|
2011-06-18 11:53:25 +02:00
|
|
|
// Set initial send-to address if provided
|
2011-05-15 19:31:20 +02:00
|
|
|
if(!address.isEmpty())
|
|
|
|
{
|
|
|
|
ui->payTo->setText(address);
|
|
|
|
ui->payAmount->setFocus();
|
|
|
|
}
|
2011-05-12 14:44:52 +02:00
|
|
|
}
|
|
|
|
|
2011-06-30 18:05:29 +02:00
|
|
|
void SendCoinsDialog::setModel(WalletModel *model)
|
2011-05-30 20:20:12 +02:00
|
|
|
{
|
|
|
|
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();
|
2011-06-25 19:32:36 +02:00
|
|
|
QString label;
|
2011-05-30 20:20:12 +02:00
|
|
|
qint64 payAmountParsed;
|
2011-05-15 19:31:20 +02:00
|
|
|
|
2011-06-28 21:41:56 +02:00
|
|
|
valid = GUIUtil::parseMoney(payAmount, &payAmountParsed);
|
2011-05-30 20:20:12 +02:00
|
|
|
|
2011-06-30 17:32:19 +02:00
|
|
|
if(!valid || payAmount.isEmpty())
|
2011-05-14 17:25:05 +02:00
|
|
|
{
|
2011-05-30 20:20:12 +02:00
|
|
|
QMessageBox::warning(this, tr("Send Coins"),
|
2011-06-30 17:32:19 +02:00
|
|
|
tr("Must fill in an amount to pay."),
|
2011-05-30 20:20:12 +02:00
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
2011-05-15 19:31:20 +02:00
|
|
|
return;
|
2011-05-14 17:25:05 +02:00
|
|
|
}
|
2011-05-27 21:43:05 +02:00
|
|
|
|
2011-06-25 19:32:36 +02:00
|
|
|
if(ui->addToAddressBook->isChecked())
|
|
|
|
{
|
|
|
|
// Add address to address book under label, if specified
|
|
|
|
label = ui->addAsLabel->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(model->sendCoins(ui->payTo->text(), payAmountParsed, label))
|
2011-05-14 17:25:05 +02:00
|
|
|
{
|
2011-06-30 18:05:29 +02:00
|
|
|
case WalletModel::InvalidAddress:
|
2011-05-30 20:20:12 +02:00
|
|
|
QMessageBox::warning(this, tr("Send Coins"),
|
|
|
|
tr("The recepient address is not valid, please recheck."),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
ui->payTo->setFocus();
|
|
|
|
break;
|
2011-06-30 18:05:29 +02:00
|
|
|
case WalletModel::InvalidAmount:
|
2011-05-30 20:20:12 +02:00
|
|
|
QMessageBox::warning(this, tr("Send Coins"),
|
|
|
|
tr("The amount to pay must be larger than 0."),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
2011-05-15 19:31:20 +02:00
|
|
|
ui->payAmount->setFocus();
|
2011-05-30 20:20:12 +02:00
|
|
|
break;
|
2011-06-30 18:05:29 +02:00
|
|
|
case WalletModel::AmountExceedsBalance:
|
2011-05-30 20:20:12 +02:00
|
|
|
QMessageBox::warning(this, tr("Send Coins"),
|
|
|
|
tr("Amount exceeds your balance"),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
ui->payAmount->setFocus();
|
|
|
|
break;
|
2011-06-30 18:05:29 +02:00
|
|
|
case WalletModel::AmountWithFeeExceedsBalance:
|
2011-05-30 20:20:12 +02:00
|
|
|
QMessageBox::warning(this, tr("Send Coins"),
|
|
|
|
tr("Total exceeds your balance when the %1 transaction fee is included").
|
2011-06-28 21:41:56 +02:00
|
|
|
arg(GUIUtil::formatMoney(model->getOptionsModel()->getTransactionFee())),
|
2011-05-30 20:20:12 +02:00
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
ui->payAmount->setFocus();
|
|
|
|
break;
|
2011-06-30 18:05:29 +02:00
|
|
|
case WalletModel::OK:
|
2011-05-31 22:24:53 +02:00
|
|
|
accept();
|
|
|
|
break;
|
2011-05-14 17:25:05 +02:00
|
|
|
}
|
2011-05-12 17:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsDialog::on_pasteButton_clicked()
|
|
|
|
{
|
2011-06-18 11:53:25 +02:00
|
|
|
// Paste text from clipboard into recipient field
|
2011-05-12 20:16:42 +02:00
|
|
|
ui->payTo->setText(QApplication::clipboard()->text());
|
2011-05-12 17:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsDialog::on_addressBookButton_clicked()
|
|
|
|
{
|
2011-06-13 12:07:32 +02:00
|
|
|
AddressBookDialog dlg(AddressBookDialog::ForSending);
|
2011-06-04 21:54:49 +02:00
|
|
|
dlg.setModel(model->getAddressTableModel());
|
|
|
|
dlg.setTab(AddressBookDialog::SendingTab);
|
2011-05-12 17:55:24 +02:00
|
|
|
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
|
|
|
}
|
2011-06-25 19:32:36 +02:00
|
|
|
|
|
|
|
void SendCoinsDialog::on_addToAddressBook_toggled(bool checked)
|
|
|
|
{
|
|
|
|
ui->addAsLabel->setEnabled(checked);
|
|
|
|
}
|