Bitcoin Core  21.99.0
P2P Digital Currency
receiverequestdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2020 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  model(nullptr)
25 {
26  ui->setupUi(this);
28 }
29 
31 {
32  delete ui;
33 }
34 
36 {
37  this->model = _model;
38 
39  if (_model)
41 
42  // update the display unit if necessary
43  update();
44 }
45 
47 {
48  this->info = _info;
49  setWindowTitle(tr("Request payment to %1").arg(info.label.isEmpty() ? info.address : info.label));
50  QString uri = GUIUtil::formatBitcoinURI(info);
51 
52 #ifdef USE_QRCODE
53  if (ui->qr_code->setQR(uri, info.address)) {
54  connect(ui->btnSaveAs, &QPushButton::clicked, ui->qr_code, &QRImageWidget::saveImage);
55  } else {
56  ui->btnSaveAs->setEnabled(false);
57  }
58 #else
59  ui->btnSaveAs->hide();
60  ui->qr_code->hide();
61 #endif
62 
63  ui->uri_content->setText("<a href=\"" + uri + "\">" + GUIUtil::HtmlEscape(uri) + "</a>");
64  ui->address_content->setText(info.address);
65 
66  if (!info.amount) {
67  ui->amount_tag->hide();
68  ui->amount_content->hide();
69  } // Amount is set in updateDisplayUnit() slot.
71 
72  if (!info.label.isEmpty()) {
73  ui->label_content->setText(info.label);
74  } else {
75  ui->label_tag->hide();
76  ui->label_content->hide();
77  }
78 
79  if (!info.message.isEmpty()) {
80  ui->message_content->setText(info.message);
81  } else {
82  ui->message_tag->hide();
83  ui->message_content->hide();
84  }
85 
86  if (!model->getWalletName().isEmpty()) {
87  ui->wallet_content->setText(model->getWalletName());
88  } else {
89  ui->wallet_tag->hide();
90  ui->wallet_content->hide();
91  }
92 }
93 
95 {
96  if (!model) return;
98 }
99 
101 {
103 }
104 
106 {
108 }
SendCoinsRecipient::amount
CAmount amount
Definition: sendcoinsrecipient.h:33
qrimagewidget.h
WalletModel::getOptionsModel
OptionsModel * getOptionsModel()
Definition: walletmodel.cpp:284
ReceiveRequestDialog::setModel
void setModel(WalletModel *model)
Definition: receiverequestdialog.cpp:35
ReceiveRequestDialog::ui
Ui::ReceiveRequestDialog * ui
Definition: receiverequestdialog.h:35
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
BitcoinUnits::formatWithUnit
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
Definition: bitcoinunits.cpp:148
ReceiveRequestDialog::info
SendCoinsRecipient info
Definition: receiverequestdialog.h:37
walletmodel.h
SendCoinsRecipient::label
QString label
Definition: sendcoinsrecipient.h:32
GUIUtil
Utility functions used by the Bitcoin Qt UI.
Definition: bitcoingui.h:58
OptionsModel::displayUnitChanged
void displayUnitChanged(int unit)
GUIUtil::formatBitcoinURI
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:187
ReceiveRequestDialog::model
WalletModel * model
Definition: receiverequestdialog.h:36
ReceiveRequestDialog::updateDisplayUnit
void updateDisplayUnit()
Definition: receiverequestdialog.cpp:94
bitcoin-config.h
ReceiveRequestDialog::on_btnCopyAddress_clicked
void on_btnCopyAddress_clicked()
Definition: receiverequestdialog.cpp:105
GUIUtil::dialog_flags
constexpr auto dialog_flags
Definition: guiutil.h:56
GUIUtil::setClipboard
void setClipboard(const QString &str)
Definition: guiutil.cpp:631
ReceiveRequestDialog::setInfo
void setInfo(const SendCoinsRecipient &info)
Definition: receiverequestdialog.cpp:46
SendCoinsRecipient
Definition: sendcoinsrecipient.h:19
ReceiveRequestDialog::ReceiveRequestDialog
ReceiveRequestDialog(QWidget *parent=nullptr)
Definition: receiverequestdialog.cpp:21
guiutil.h
WalletModel::getWalletName
QString getWalletName() const
Definition: walletmodel.cpp:579
ReceiveRequestDialog
Definition: receiverequestdialog.h:18
Ui
Definition: addressbookpage.h:14
GUIUtil::HtmlEscape
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:225
OptionsModel::getDisplayUnit
int getDisplayUnit() const
Definition: optionsmodel.h:86
ReceiveRequestDialog::on_btnCopyURI_clicked
void on_btnCopyURI_clicked()
Definition: receiverequestdialog.cpp:100
SendCoinsRecipient::address
QString address
Definition: sendcoinsrecipient.h:31
bitcoinunits.h
ReceiveRequestDialog::~ReceiveRequestDialog
~ReceiveRequestDialog()
Definition: receiverequestdialog.cpp:30
GUIUtil::handleCloseWindowShortcut
void handleCloseWindowShortcut(QWidget *w)
Definition: guiutil.cpp:395
optionsmodel.h
receiverequestdialog.h
QRImageWidget::saveImage
void saveImage()
Definition: qrimagewidget.cpp:119
SendCoinsRecipient::message
QString message
Definition: sendcoinsrecipient.h:35