Bitcoin Core  24.99.0
P2P Digital Currency
receiverequestdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2021 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 
6 #include <qt/forms/ui_receiverequestdialog.h>
7 
8 #include <qt/bitcoinunits.h>
9 #include <qt/guiutil.h>
10 #include <qt/optionsmodel.h>
11 #include <qt/qrimagewidget.h>
12 #include <qt/walletmodel.h>
13 
14 #include <QDialog>
15 #include <QString>
16 
17 #if defined(HAVE_CONFIG_H)
18 #include <config/bitcoin-config.h> /* for USE_QRCODE */
19 #endif
20 
22  : QDialog(parent, GUIUtil::dialog_flags),
23  ui(new Ui::ReceiveRequestDialog)
24 {
25  ui->setupUi(this);
27 }
28 
30 {
31  delete ui;
32 }
33 
35 {
36  this->model = _model;
37 
38  if (_model)
40 
41  // update the display unit if necessary
42  update();
43 }
44 
46 {
47  this->info = _info;
48  setWindowTitle(tr("Request payment to %1").arg(info.label.isEmpty() ? info.address : info.label));
49  QString uri = GUIUtil::formatBitcoinURI(info);
50 
51 #ifdef USE_QRCODE
52  if (ui->qr_code->setQR(uri, info.address)) {
53  connect(ui->btnSaveAs, &QPushButton::clicked, ui->qr_code, &QRImageWidget::saveImage);
54  } else {
55  ui->btnSaveAs->setEnabled(false);
56  }
57 #else
58  ui->btnSaveAs->hide();
59  ui->qr_code->hide();
60 #endif
61 
62  ui->uri_content->setText("<a href=\"" + uri + "\">" + GUIUtil::HtmlEscape(uri) + "</a>");
63  ui->address_content->setText(info.address);
64 
65  if (!info.amount) {
66  ui->amount_tag->hide();
67  ui->amount_content->hide();
68  } // Amount is set in updateDisplayUnit() slot.
70 
71  if (!info.label.isEmpty()) {
72  ui->label_content->setText(info.label);
73  } else {
74  ui->label_tag->hide();
75  ui->label_content->hide();
76  }
77 
78  if (!info.message.isEmpty()) {
79  ui->message_content->setText(info.message);
80  } else {
81  ui->message_tag->hide();
82  ui->message_content->hide();
83  }
84 
85  if (!model->getWalletName().isEmpty()) {
86  ui->wallet_content->setText(model->getWalletName());
87  } else {
88  ui->wallet_tag->hide();
89  ui->wallet_content->hide();
90  }
91 
92  ui->btnVerify->setVisible(model->wallet().hasExternalSigner());
93 
94  connect(ui->btnVerify, &QPushButton::clicked, [this] {
95  model->displayAddress(info.address.toStdString());
96  });
97 }
98 
100 {
101  if (!model) return;
103 }
104 
106 {
108 }
109 
111 {
113 }
static QString formatWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
void displayUnitChanged(BitcoinUnit unit)
BitcoinUnit getDisplayUnit() const
Definition: optionsmodel.h:93
ReceiveRequestDialog(QWidget *parent=nullptr)
void setModel(WalletModel *model)
Ui::ReceiveRequestDialog * ui
void setInfo(const SendCoinsRecipient &info)
SendCoinsRecipient info
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:53
interfaces::Wallet & wallet() const
Definition: walletmodel.h:145
OptionsModel * getOptionsModel() const
QString getWalletName() const
virtual bool hasExternalSigner()=0
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:60
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:240
void handleCloseWindowShortcut(QWidget *w)
Definition: guiutil.cpp:415
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:202
constexpr auto dialog_flags
Definition: guiutil.h:60
void setClipboard(const QString &str)
Definition: guiutil.cpp:652