Bitcoin Core  0.19.99
P2P Digital Currency
receiverequestdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2019 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/walletmodel.h>
12 
13 #include <QClipboard>
14 #include <QPixmap>
15 
16 #if defined(HAVE_CONFIG_H)
17 #include <config/bitcoin-config.h> /* for USE_QRCODE */
18 #endif
19 
21  QDialog(parent),
22  ui(new Ui::ReceiveRequestDialog),
23  model(nullptr)
24 {
25  ui->setupUi(this);
26 
27 #ifndef USE_QRCODE
28  ui->btnSaveAs->setVisible(false);
29  ui->lblQRCode->setVisible(false);
30 #endif
31 
32  connect(ui->btnSaveAs, &QPushButton::clicked, ui->lblQRCode, &QRImageWidget::saveImage);
33 }
34 
36 {
37  delete ui;
38 }
39 
41 {
42  this->model = _model;
43 
44  if (_model)
46 
47  // update the display unit if necessary
48  update();
49 }
50 
52 {
53  this->info = _info;
54  update();
55 }
56 
58 {
59  if(!model)
60  return;
61  QString target = info.label;
62  if(target.isEmpty())
63  target = info.address;
64  setWindowTitle(tr("Request payment to %1").arg(target));
65 
66  QString uri = GUIUtil::formatBitcoinURI(info);
67  ui->btnSaveAs->setEnabled(false);
68  QString html;
69  html += "<html><font face='verdana, arial, helvetica, sans-serif'>";
70  html += "<b>"+tr("Payment information")+"</b><br>";
71  html += "<b>"+tr("URI")+"</b>: ";
72  html += "<a href=\""+uri+"\">" + GUIUtil::HtmlEscape(uri) + "</a><br>";
73  html += "<b>"+tr("Address")+"</b>: " + GUIUtil::HtmlEscape(info.address) + "<br>";
74  if(info.amount)
75  html += "<b>"+tr("Amount")+"</b>: " + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), info.amount) + "<br>";
76  if(!info.label.isEmpty())
77  html += "<b>"+tr("Label")+"</b>: " + GUIUtil::HtmlEscape(info.label) + "<br>";
78  if(!info.message.isEmpty())
79  html += "<b>"+tr("Message")+"</b>: " + GUIUtil::HtmlEscape(info.message) + "<br>";
80  if(model->isMultiwallet()) {
81  html += "<b>"+tr("Wallet")+"</b>: " + GUIUtil::HtmlEscape(model->getWalletName()) + "<br>";
82  }
83  ui->outUri->setText(html);
84 
85  if (ui->lblQRCode->setQR(uri, info.address)) {
86  ui->btnSaveAs->setEnabled(true);
87  }
88 }
89 
91 {
93 }
94 
96 {
98 }
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as HTML string (with unit)
Ui::ReceiveRequestDialog * ui
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:218
SendCoinsRecipient info
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:180
ReceiveRequestDialog(QWidget *parent=nullptr)
int getDisplayUnit() const
Definition: optionsmodel.h:81
void setClipboard(const QString &str)
Definition: guiutil.cpp:704
void setInfo(const SendCoinsRecipient &info)
QString getWalletName() const
void displayUnitChanged(int unit)
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:50
bool isMultiwallet()
OptionsModel * getOptionsModel()
void setModel(WalletModel *model)