dogecoin/src/qt/sendcoinsdialog.cpp

151 lines
4.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"
#include "walletmodel.h"
#include "addresstablemodel.h"
#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>
#include <QMessageBox>
#include <QLocale>
#include <QDebug>
2011-07-07 17:33:15 +02:00
#include <QMessageBox>
2011-05-12 20:16:42 +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);
#if QT_VERSION >= 0x040700
2011-07-08 19:00:08 +02:00
ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
#endif
2011-07-08 19:25:35 +02:00
GUIUtil::setupAddressWidget(ui->payTo, this);
// Set initial send-to address if provided
if(!address.isEmpty())
{
ui->payTo->setText(address);
ui->payAmount->setFocus();
}
2011-05-12 14:44:52 +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();
QString label;
2011-05-30 20:20:12 +02:00
qint64 payAmountParsed;
valid = GUIUtil::parseMoney(payAmount, &payAmountParsed);
2011-05-30 20:20:12 +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"),
tr("Must fill in an amount to pay."),
2011-05-30 20:20:12 +02:00
QMessageBox::Ok, QMessageBox::Ok);
return;
2011-05-14 17:25:05 +02:00
}
// Add address to address book under label, if specified
label = ui->addAsLabel->text();
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;
}
switch(model->sendCoins(ui->payTo->text(), payAmountParsed, label))
2011-05-14 17:25:05 +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;
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);
ui->payAmount->setFocus();
2011-05-30 20:20:12 +02:00
break;
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;
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").
arg(GUIUtil::formatMoney(model->getOptionsModel()->getTransactionFee())),
2011-05-30 20:20:12 +02:00
QMessageBox::Ok, QMessageBox::Ok);
ui->payAmount->setFocus();
break;
case WalletModel::OK:
accept();
break;
2011-05-14 17:25:05 +02:00
}
2011-05-12 17:55:24 +02:00
}
void SendCoinsDialog::on_pasteButton_clicked()
{
// 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_payTo_textChanged(const QString &address)
{
ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
}
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();
ui->sendButton->setDefault(true);
2011-07-07 17:33:15 +02:00
}
void SendCoinsDialog::reject()
{
clear();
}
void SendCoinsDialog::accept()
{
clear();
}