// Copyright (c) 2011-2019 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include #include #include #include #if defined(HAVE_CONFIG_H) #include /* for USE_QRCODE */ #endif ReceiveRequestDialog::ReceiveRequestDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ReceiveRequestDialog), model(nullptr) { ui->setupUi(this); GUIUtil::handleCloseWindowShortcut(this); } ReceiveRequestDialog::~ReceiveRequestDialog() { delete ui; } void ReceiveRequestDialog::setModel(WalletModel *_model) { this->model = _model; if (_model) connect(_model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &ReceiveRequestDialog::update); // update the display unit if necessary update(); } void ReceiveRequestDialog::setInfo(const SendCoinsRecipient &_info) { this->info = _info; setWindowTitle(tr("Request payment to %1").arg(info.label.isEmpty() ? info.address : info.label)); QString uri = GUIUtil::formatBitcoinURI(info); #ifdef USE_QRCODE if (ui->qr_code->setQR(uri, info.address)) { connect(ui->btnSaveAs, &QPushButton::clicked, ui->qr_code, &QRImageWidget::saveImage); } else { ui->btnSaveAs->setEnabled(false); } #else ui->btnSaveAs->hide(); ui->qr_code->hide(); #endif ui->uri_content->setText("" + GUIUtil::HtmlEscape(uri) + ""); ui->address_content->setText(info.address); if (!info.amount) { ui->amount_tag->hide(); ui->amount_content->hide(); } // Amount is set in update() slot. update(); if (!info.label.isEmpty()) { ui->label_content->setText(info.label); } else { ui->label_tag->hide(); ui->label_content->hide(); } if (!info.message.isEmpty()) { ui->message_content->setText(info.message); } else { ui->message_tag->hide(); ui->message_content->hide(); } if (!model->getWalletName().isEmpty()) { ui->wallet_content->setText(model->getWalletName()); } else { ui->wallet_tag->hide(); ui->wallet_content->hide(); } } void ReceiveRequestDialog::update() { if (!model) return; ui->amount_content->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), info.amount)); } void ReceiveRequestDialog::on_btnCopyURI_clicked() { GUIUtil::setClipboard(GUIUtil::formatBitcoinURI(info)); } void ReceiveRequestDialog::on_btnCopyAddress_clicked() { GUIUtil::setClipboard(info.address); }