dogecoin/src/qt/sendcoinsdialog.cpp

122 lines
3.2 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 "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>
#include <QMessageBox>
#include <QLocale>
#include <QDebug>
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);
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
}
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
{
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()
{
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
}
void SendCoinsDialog::on_addToAddressBook_toggled(bool checked)
{
ui->addAsLabel->setEnabled(checked);
}