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-07-07 17:33:15 +02:00
|
|
|
#include "addressbookpage.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-07-07 17:33:15 +02:00
|
|
|
#include <QMessageBox>
|
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-07-03 08:24:07 +02:00
|
|
|
#if QT_VERSION >= 0x040700
|
2011-07-08 19:00:08 +02:00
|
|
|
ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
|
2011-07-03 08:24:07 +02:00
|
|
|
ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
|
|
|
|
#endif
|
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-07-02 13:45:59 +02:00
|
|
|
// Add address to address book under label, if specified
|
|
|
|
label = ui->addAsLabel->text();
|
2011-06-25 19:32:36 +02:00
|
|
|
|
2011-07-07 17:33:15 +02:00
|
|
|
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"),
|
|
|
|
tr("Are you sure you want to send %1 BTC to %2 (%3)?").arg(GUIUtil::formatMoney(payAmountParsed), label, ui->payTo->text()),
|
|
|
|
QMessageBox::Yes|QMessageBox::Cancel,
|
|
|
|
QMessageBox::Cancel);
|
|
|
|
|
|
|
|
if(retval != QMessageBox::Yes)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-25 19:32:36 +02:00
|
|
|
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-07-07 18:25:27 +02:00
|
|
|
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
|
2011-06-04 21:54:49 +02:00
|
|
|
dlg.setModel(model->getAddressTableModel());
|
2011-07-07 18:25:27 +02:00
|
|
|
if(dlg.exec())
|
|
|
|
{
|
|
|
|
ui->payTo->setText(dlg.getReturnValue());
|
|
|
|
ui->payAmount->setFocus();
|
|
|
|
}
|
2011-05-13 22:00:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsDialog::on_buttonBox_rejected()
|
|
|
|
{
|
|
|
|
reject();
|
2011-05-12 17:55:24 +02:00
|
|
|
}
|
2011-06-25 19:32:36 +02:00
|
|
|
|
2011-07-02 13:45:59 +02:00
|
|
|
void SendCoinsDialog::on_payTo_textChanged(const QString &address)
|
2011-06-25 19:32:36 +02:00
|
|
|
{
|
2011-07-02 13:45:59 +02:00
|
|
|
ui->addAsLabel->setText(model->labelForAddress(address));
|
2011-06-25 19:32:36 +02:00
|
|
|
}
|
2011-07-07 17:33:15 +02:00
|
|
|
|
|
|
|
void SendCoinsDialog::clear()
|
|
|
|
{
|
|
|
|
ui->payTo->setText(QString());
|
|
|
|
ui->addAsLabel->setText(QString());
|
|
|
|
ui->payAmount->setText(QString());
|
|
|
|
ui->payTo->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsDialog::reject()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsDialog::accept()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|