bitcoin/src/qt/receiverequestdialog.cpp

109 lines
2.9 KiB
C++
Raw Normal View History

// Copyright (c) 2011-2020 The Bitcoin Core developers
2014-12-13 01:09:33 -03:00
// 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>
2020-05-04 22:56:50 -04:00
#include <qt/qrimagewidget.h>
#include <qt/walletmodel.h>
2020-05-04 22:56:50 -04:00
#include <QDialog>
#include <QString>
#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h> /* for USE_QRCODE */
#endif
2013-10-16 10:14:26 -03:00
ReceiveRequestDialog::ReceiveRequestDialog(QWidget *parent) :
QDialog(parent),
2013-10-16 10:14:26 -03:00
ui(new Ui::ReceiveRequestDialog),
model(nullptr)
{
ui->setupUi(this);
GUIUtil::handleCloseWindowShortcut(this);
}
2013-10-16 10:14:26 -03:00
ReceiveRequestDialog::~ReceiveRequestDialog()
{
delete ui;
}
void ReceiveRequestDialog::setModel(WalletModel *_model)
{
2016-09-09 08:43:29 -03:00
this->model = _model;
2016-09-09 08:43:29 -03:00
if (_model)
connect(_model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &ReceiveRequestDialog::updateDisplayUnit);
// update the display unit if necessary
update();
}
2016-09-09 08:43:29 -03:00
void ReceiveRequestDialog::setInfo(const SendCoinsRecipient &_info)
2012-02-15 09:14:16 -03:00
{
2016-09-09 08:43:29 -03:00
this->info = _info;
2020-05-04 22:56:50 -04:00
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();
2020-05-04 22:56:50 -04:00
if (!info.label.isEmpty()) {
ui->label_content->setText(info.label);
} else {
ui->label_tag->hide();
ui->label_content->hide();
}
2020-05-04 22:56:50 -04:00
if (!info.message.isEmpty()) {
ui->message_content->setText(info.message);
} else {
ui->message_tag->hide();
ui->message_content->hide();
}
2020-05-04 22:56:50 -04:00
if (!model->getWalletName().isEmpty()) {
ui->wallet_content->setText(model->getWalletName());
} else {
ui->wallet_tag->hide();
ui->wallet_content->hide();
}
}
void ReceiveRequestDialog::updateDisplayUnit()
2020-05-04 22:56:50 -04:00
{
if (!model) return;
ui->amount_content->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), info.amount));
}
void ReceiveRequestDialog::on_btnCopyURI_clicked()
2012-02-15 09:14:16 -03:00
{
GUIUtil::setClipboard(GUIUtil::formatBitcoinURI(info));
}
void ReceiveRequestDialog::on_btnCopyAddress_clicked()
{
GUIUtil::setClipboard(info.address);
}