1 #include "sendcoinsdialog.h"
2 #include "ui_sendcoinsdialog.h"
3 #include "walletmodel.h"
4 #include "addresstablemodel.h"
7 #include "addressbookpage.h"
8 #include "optionsmodel.h"
10 #include <QApplication>
12 #include <QMessageBox>
15 #include <QMessageBox>
17 SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) :
19 ui(new Ui::SendCoinsDialog),
23 #if QT_VERSION >= 0x040700
24 ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
25 ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
28 GUIUtil::setupAddressWidget(ui->payTo, this);
30 // Set initial send-to address if provided
31 if(!address.isEmpty())
33 ui->payTo->setText(address);
34 ui->payAmount->setFocus();
38 void SendCoinsDialog::setModel(WalletModel *model)
43 SendCoinsDialog::~SendCoinsDialog()
48 void SendCoinsDialog::on_sendButton_clicked()
51 QString payAmount = ui->payAmount->text();
53 qint64 payAmountParsed;
55 valid = GUIUtil::parseMoney(payAmount, &payAmountParsed);
57 if(!valid || payAmount.isEmpty())
59 QMessageBox::warning(this, tr("Send Coins"),
60 tr("Must fill in an amount to pay."),
61 QMessageBox::Ok, QMessageBox::Ok);
65 // Add address to address book under label, if specified
66 label = ui->addAsLabel->text();
68 QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"),
69 tr("Are you sure you want to send %1 BTC to %2 (%3)?").arg(GUIUtil::formatMoney(payAmountParsed), label, ui->payTo->text()),
70 QMessageBox::Yes|QMessageBox::Cancel,
73 if(retval != QMessageBox::Yes)
78 switch(model->sendCoins(ui->payTo->text(), payAmountParsed, label))
80 case WalletModel::InvalidAddress:
81 QMessageBox::warning(this, tr("Send Coins"),
82 tr("The recepient address is not valid, please recheck."),
83 QMessageBox::Ok, QMessageBox::Ok);
84 ui->payTo->setFocus();
86 case WalletModel::InvalidAmount:
87 QMessageBox::warning(this, tr("Send Coins"),
88 tr("The amount to pay must be larger than 0."),
89 QMessageBox::Ok, QMessageBox::Ok);
90 ui->payAmount->setFocus();
92 case WalletModel::AmountExceedsBalance:
93 QMessageBox::warning(this, tr("Send Coins"),
94 tr("Amount exceeds your balance"),
95 QMessageBox::Ok, QMessageBox::Ok);
96 ui->payAmount->setFocus();
98 case WalletModel::AmountWithFeeExceedsBalance:
99 QMessageBox::warning(this, tr("Send Coins"),
100 tr("Total exceeds your balance when the %1 transaction fee is included").
101 arg(GUIUtil::formatMoney(model->getOptionsModel()->getTransactionFee())),
102 QMessageBox::Ok, QMessageBox::Ok);
103 ui->payAmount->setFocus();
105 case WalletModel::OK:
111 void SendCoinsDialog::on_pasteButton_clicked()
113 // Paste text from clipboard into recipient field
114 ui->payTo->setText(QApplication::clipboard()->text());
117 void SendCoinsDialog::on_addressBookButton_clicked()
119 AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
120 dlg.setModel(model->getAddressTableModel());
123 ui->payTo->setText(dlg.getReturnValue());
124 ui->payAmount->setFocus();
128 void SendCoinsDialog::on_buttonBox_rejected()
133 void SendCoinsDialog::on_payTo_textChanged(const QString &address)
135 ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
138 void SendCoinsDialog::clear()
140 ui->payTo->setText(QString());
141 ui->addAsLabel->setText(QString());
142 ui->payAmount->setText(QString());
143 ui->payTo->setFocus();
144 ui->sendButton->setDefault(true);
147 void SendCoinsDialog::reject()
152 void SendCoinsDialog::accept()