Bitcoin ABC 0.30.7
P2P Digital Currency
sendcoinsentry.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-2016 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#if defined(HAVE_CONFIG_H)
6#include <config/bitcoin-config.h>
7#endif
8
9#include <qt/forms/ui_sendcoinsentry.h>
10#include <qt/sendcoinsentry.h>
11
12#include <config.h>
13#include <qt/addressbookpage.h>
15#include <qt/guiutil.h>
16#include <qt/optionsmodel.h>
17#include <qt/platformstyle.h>
18#include <qt/walletmodel.h>
19
20#include <QApplication>
21#include <QClipboard>
22
24 WalletModel *_model, QWidget *parent)
25 : QStackedWidget(parent), ui(new Ui::SendCoinsEntry), model(_model),
26 platformStyle(_platformStyle) {
27 ui->setupUi(this);
28
29 ui->addressBookButton->setIcon(
30 platformStyle->SingleColorIcon(":/icons/address-book"));
31 ui->pasteButton->setIcon(
32 platformStyle->SingleColorIcon(":/icons/editpaste"));
33 ui->deleteButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
34 ui->deleteButton_is->setIcon(
35 platformStyle->SingleColorIcon(":/icons/remove"));
36 ui->deleteButton_s->setIcon(
37 platformStyle->SingleColorIcon(":/icons/remove"));
38
39 setCurrentWidget(ui->SendCoins);
40
42 ui->payToLayout->setSpacing(4);
43 }
44
45 // normal bitcoin address field
46 GUIUtil::setupAddressWidget(ui->payTo, this);
47 // just a label for displaying bitcoin address(es)
48 ui->payTo_is->setFont(GUIUtil::fixedPitchFont());
49
50 // Connect signals
51 connect(ui->payAmount, &BitcoinAmountField::valueChanged, this,
53 connect(ui->checkboxSubtractFeeFromAmount, &QCheckBox::toggled, this,
55 connect(ui->deleteButton, &QPushButton::clicked, this,
57 connect(ui->deleteButton_is, &QPushButton::clicked, this,
59 connect(ui->deleteButton_s, &QPushButton::clicked, this,
61 connect(ui->useAvailableBalanceButton, &QPushButton::clicked, this,
63
64 // Set the model properly.
66}
67
69 delete ui;
70}
71
73 // Paste text from clipboard into recipient field
74 ui->payTo->setText(QApplication::clipboard()->text());
75}
76
78 if (!model) {
79 return;
80 }
84 if (dlg.exec()) {
85 ui->payTo->setText(dlg.getReturnValue());
86 ui->payAmount->setFocus();
87 }
88}
89
90void SendCoinsEntry::on_payTo_textChanged(const QString &address) {
91 updateLabel(address);
92}
93
95 this->model = _model;
96
97 if (_model) {
98 ui->messageTextLabel->setToolTip(
99 tr("A message that was attached to the %1 URI which will be stored "
100 "with the transaction for your reference. Note: This message "
101 "will not be sent over the Bitcoin network.")
102 .arg(QString::fromStdString(
103 _model->getChainParams().CashAddrPrefix())));
104 }
105
106 if (_model && _model->getOptionsModel()) {
109 }
110
111 clear();
112}
113
115 // clear UI elements for normal payment
116 ui->payTo->clear();
117 ui->addAsLabel->clear();
118 ui->payAmount->clear();
119 ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked);
120 ui->messageTextLabel->clear();
121 ui->messageTextLabel->hide();
122 ui->messageLabel->hide();
123 // clear UI elements for unauthenticated payment request
124 ui->payTo_is->clear();
125 ui->memoTextLabel_is->clear();
126 ui->payAmount_is->clear();
127 // clear UI elements for authenticated payment request
128 ui->payTo_s->clear();
129 ui->memoTextLabel_s->clear();
130 ui->payAmount_s->clear();
131
132 // update the display unit, to not use the default ("XEC")
134}
135
137 ui->checkboxSubtractFeeFromAmount->setChecked(true);
138}
139
141 Q_EMIT removeEntry(this);
142}
143
145 Q_EMIT useAvailableBalance(this);
146}
147
149 if (!model) {
150 return false;
151 }
152
153 // Check input validity
154 bool retval = true;
155
156#ifdef ENABLE_BIP70
157 // Skip checks for payment request
158 if (recipient.paymentRequest.IsInitialized()) {
159 return retval;
160 }
161#endif
162
163 if (!model->validateAddress(ui->payTo->text())) {
164 ui->payTo->setValid(false);
165 retval = false;
166 }
167
168 if (!ui->payAmount->validate()) {
169 retval = false;
170 }
171
172 // Sending a zero amount is invalid
173 if (ui->payAmount->value(nullptr) <= Amount::zero()) {
174 ui->payAmount->setValid(false);
175 retval = false;
176 }
177
178 // Reject dust outputs:
179 if (retval &&
180 GUIUtil::isDust(node, ui->payTo->text(), ui->payAmount->value(),
181 model->getChainParams())) {
182 ui->payAmount->setValid(false);
183 retval = false;
184 }
185
186 return retval;
187}
188
190#ifdef ENABLE_BIP70
191 // Payment request
192 if (recipient.paymentRequest.IsInitialized()) {
193 return recipient;
194 }
195#endif
196
197 // Normal payment
198 recipient.address = ui->payTo->text();
199 recipient.label = ui->addAsLabel->text();
200 recipient.amount = ui->payAmount->value();
201 recipient.message = ui->messageTextLabel->text();
203 (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked);
204
205 return recipient;
206}
207
208QWidget *SendCoinsEntry::setupTabChain(QWidget *prev) {
209 QWidget::setTabOrder(prev, ui->payTo);
210 QWidget::setTabOrder(ui->payTo, ui->addAsLabel);
211 QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel);
212 QWidget::setTabOrder(w, ui->checkboxSubtractFeeFromAmount);
213 QWidget::setTabOrder(ui->checkboxSubtractFeeFromAmount,
214 ui->addressBookButton);
215 QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
216 QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
217 return ui->deleteButton;
218}
219
221 recipient = value;
222
223#ifdef ENABLE_BIP70
224 // payment request
225 if (recipient.paymentRequest.IsInitialized()) {
226 // unauthenticated
227 if (recipient.authenticatedMerchant.isEmpty()) {
228 ui->payTo_is->setText(recipient.address);
229 ui->memoTextLabel_is->setText(recipient.message);
230 ui->payAmount_is->setValue(recipient.amount);
231 ui->payAmount_is->setReadOnly(true);
232 setCurrentWidget(ui->SendCoins_UnauthenticatedPaymentRequest);
233 }
234
235 // authenticated
236 else {
237 ui->payTo_s->setText(recipient.authenticatedMerchant);
238 ui->memoTextLabel_s->setText(recipient.message);
239 ui->payAmount_s->setValue(recipient.amount);
240 ui->payAmount_s->setReadOnly(true);
241 setCurrentWidget(ui->SendCoins_AuthenticatedPaymentRequest);
242 }
243 }
244
245 // normal payment
246 else
247#endif
248 {
249 // message
250 ui->messageTextLabel->setText(recipient.message);
251 ui->messageTextLabel->setVisible(!recipient.message.isEmpty());
252 ui->messageLabel->setVisible(!recipient.message.isEmpty());
253
254 ui->addAsLabel->clear();
255 // this may set a label from addressbook
256 ui->payTo->setText(recipient.address);
257 // if a label had been set from the addressbook, don't overwrite with an
258 // empty label
259 if (!recipient.label.isEmpty()) {
260 ui->addAsLabel->setText(recipient.label);
261 }
262 ui->payAmount->setValue(recipient.amount);
263 }
264}
265
266void SendCoinsEntry::setAddress(const QString &address) {
267 ui->payTo->setText(address);
268 ui->payAmount->setFocus();
269}
270
272 ui->payAmount->setValue(amount);
273}
274
276 return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() &&
277 ui->payTo_s->text().isEmpty();
278}
279
281 ui->payTo->setFocus();
282}
283
285 if (model && model->getOptionsModel()) {
286 // Update payAmount with the current unit
287 ui->payAmount->setDisplayUnit(
289 ui->payAmount_is->setDisplayUnit(
291 ui->payAmount_s->setDisplayUnit(
293 }
294}
295
296bool SendCoinsEntry::updateLabel(const QString &address) {
297 if (!model) {
298 return false;
299 }
300
301 // Fill in label from address book, if address has an associated label
302 QString associatedLabel =
304 if (!associatedLabel.isEmpty()) {
305 ui->addAsLabel->setText(associatedLabel);
306 return true;
307 }
308
309 return false;
310}
Widget that shows a list of sending or receiving addresses.
@ ForSelection
Open address book to pick address.
void setModel(AddressTableModel *model)
const QString & getReturnValue() const
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
const std::string & CashAddrPrefix() const
Definition: chainparams.h:132
int getDisplayUnit() const
Definition: optionsmodel.h:97
void displayUnitChanged(int unit)
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
bool getUseExtraSpacing() const
Definition: platformstyle.h:21
A single entry in the dialog for sending bitcoins.
WalletModel * model
void setFocus()
bool updateLabel(const QString &address)
void setAmount(const Amount amount)
void setAddress(const QString &address)
bool isClear()
Return whether the entry is still empty and unedited.
void subtractFeeFromAmountChanged()
void useAvailableBalance(SendCoinsEntry *entry)
~SendCoinsEntry()
SendCoinsRecipient recipient
void setValue(const SendCoinsRecipient &value)
void updateDisplayUnit()
void on_payTo_textChanged(const QString &address)
void on_pasteButton_clicked()
void setModel(WalletModel *model)
void useAvailableBalanceClicked()
void removeEntry(SendCoinsEntry *entry)
SendCoinsEntry(const PlatformStyle *platformStyle, WalletModel *model, QWidget *parent=nullptr)
void payAmountChanged()
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
const PlatformStyle * platformStyle
void deleteClicked()
void clear()
void on_addressBookButton_clicked()
bool validate(interfaces::Node &node)
Ui::SendCoinsEntry * ui
void checkSubtractFeeFromAmount()
SendCoinsRecipient getValue()
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:47
bool validateAddress(const QString &address)
const CChainParams & getChainParams() const
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:59
bool isDust(interfaces::Node &node, const QString &address, const Amount amount, const CChainParams &chainParams)
Definition: guiutil.cpp:243
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:130
QFont fixedPitchFont()
Definition: guiutil.cpp:87
Definition: init.h:28
Definition: amount.h:19
static constexpr Amount zero() noexcept
Definition: amount.h:32