bitcoin/src/qt/receiverequestdialog.cpp
MarcoFalke fa0074e2d8
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-
2020-12-31 09:45:41 +01:00

108 lines
2.9 KiB
C++

// Copyright (c) 2011-2020 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 <qt/receiverequestdialog.h>
#include <qt/forms/ui_receiverequestdialog.h>
#include <qt/bitcoinunits.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
#include <qt/qrimagewidget.h>
#include <qt/walletmodel.h>
#include <QDialog>
#include <QString>
#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h> /* 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::updateDisplayUnit);
// 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("<a href=\"" + uri + "\">" + GUIUtil::HtmlEscape(uri) + "</a>");
ui->address_content->setText(info.address);
if (!info.amount) {
ui->amount_tag->hide();
ui->amount_content->hide();
} // Amount is set in updateDisplayUnit() slot.
updateDisplayUnit();
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::updateDisplayUnit()
{
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);
}