Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <wallet/wallet.h>7#include <qt/receivecoinsdialog.h>8#include <qt/forms/ui_receivecoinsdialog.h>10#include <qt/addresstablemodel.h>11#include <qt/guiutil.h>12#include <qt/optionsmodel.h>13#include <qt/platformstyle.h>14#include <qt/receiverequestdialog.h>15#include <qt/recentrequeststablemodel.h>16#include <qt/walletmodel.h>18#include <QAction>19#include <QCursor>20#include <QMessageBox>21#include <QScrollBar>22#include <QSettings>23#include <QTextDocument>25ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWidget *parent) :26QDialog(parent, GUIUtil::dialog_flags),27ui(new Ui::ReceiveCoinsDialog),28platformStyle(_platformStyle)29{30ui->setupUi(this);32if (!_platformStyle->getImagesOnButtons()) {33ui->clearButton->setIcon(QIcon());34ui->receiveButton->setIcon(QIcon());35ui->showRequestButton->setIcon(QIcon());36ui->removeRequestButton->setIcon(QIcon());37} else {38ui->clearButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove"));39ui->receiveButton->setIcon(_platformStyle->SingleColorIcon(":/icons/receiving_addresses"));40ui->showRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/eye"));41ui->removeRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove"));42}44// context menu45contextMenu = new QMenu(this);46contextMenu->addAction(tr("Copy &URI"), this, &ReceiveCoinsDialog::copyURI);47contextMenu->addAction(tr("&Copy address"), this, &ReceiveCoinsDialog::copyAddress);48copyLabelAction = contextMenu->addAction(tr("Copy &label"), this, &ReceiveCoinsDialog::copyLabel);49copyMessageAction = contextMenu->addAction(tr("Copy &message"), this, &ReceiveCoinsDialog::copyMessage);50copyAmountAction = contextMenu->addAction(tr("Copy &amount"), this, &ReceiveCoinsDialog::copyAmount);51connect(ui->recentRequestsView, &QWidget::customContextMenuRequested, this, &ReceiveCoinsDialog::showMenu);53connect(ui->clearButton, &QPushButton::clicked, this, &ReceiveCoinsDialog::clear);55QTableView* tableView = ui->recentRequestsView;56tableView->verticalHeader()->hide();57tableView->setAlternatingRowColors(true);58tableView->setSelectionBehavior(QAbstractItemView::SelectRows);59tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);61QSettings settings;62if (!tableView->horizontalHeader()->restoreState(settings.value("RecentRequestsViewHeaderState").toByteArray())) {63tableView->setColumnWidth(RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH);64tableView->setColumnWidth(RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH);65tableView->setColumnWidth(RecentRequestsTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH);66tableView->horizontalHeader()->setMinimumSectionSize(MINIMUM_COLUMN_WIDTH);67tableView->horizontalHeader()->setStretchLastSection(true);68}69}71void ReceiveCoinsDialog::setModel(WalletModel *_model)72{73this->model = _model;75if(_model && _model->getOptionsModel())76{77_model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder);78connect(_model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &ReceiveCoinsDialog::updateDisplayUnit);79updateDisplayUnit();81QTableView* tableView = ui->recentRequestsView;82tableView->setModel(_model->getRecentRequestsTableModel());83tableView->sortByColumn(RecentRequestsTableModel::Date, Qt::DescendingOrder);85connect(tableView->selectionModel(),86&QItemSelectionModel::selectionChanged, this,87&ReceiveCoinsDialog::recentRequestsView_selectionChanged);89// Populate address type dropdown and select default90auto add_address_type = [&](OutputType type, const QString& text, const QString& tooltip) {91const auto index = ui->addressType->count();92ui->addressType->addItem(text, (int) type);93ui->addressType->setItemData(index, tooltip, Qt::ToolTipRole);94if (model->wallet().getDefaultAddressType() == type) ui->addressType->setCurrentIndex(index);95};96add_address_type(OutputType::LEGACY, tr("Base58 (Legacy)"), tr("Not recommended due to higher fees and less protection against typos."));97add_address_type(OutputType::P2SH_SEGWIT, tr("Base58 (P2SH-SegWit)"), tr("Generates an address compatible with older wallets."));98add_address_type(OutputType::BECH32, tr("Bech32 (SegWit)"), tr("Generates a native segwit address (BIP-173). Some old wallets don't support it."));99if (model->wallet().taprootEnabled()) {100add_address_type(OutputType::BECH32M, tr("Bech32m (Taproot)"), tr("Bech32m (BIP-350) is an upgrade to Bech32, wallet support is still limited."));101}103// Set the button to be enabled or disabled based on whether the wallet can give out new addresses.104ui->receiveButton->setEnabled(model->wallet().canGetAddresses());106// Enable/disable the receive button if the wallet is now able/unable to give out new addresses.107connect(model, &WalletModel::canGetAddressesChanged, [this] {108ui->receiveButton->setEnabled(model->wallet().canGetAddresses());109});110}111}113ReceiveCoinsDialog::~ReceiveCoinsDialog()114{115QSettings settings;116settings.setValue("RecentRequestsViewHeaderState", ui->recentRequestsView->horizontalHeader()->saveState());117delete ui;118}120void ReceiveCoinsDialog::clear()121{122ui->reqAmount->clear();123ui->reqLabel->setText("");124ui->reqMessage->setText("");125updateDisplayUnit();126}128void ReceiveCoinsDialog::reject()129{130clear();131}133void ReceiveCoinsDialog::accept()134{135clear();136}138void ReceiveCoinsDialog::updateDisplayUnit()139{140if(model && model->getOptionsModel())141{142ui->reqAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());143}144}146void ReceiveCoinsDialog::on_receiveButton_clicked()147{148if(!model || !model->getOptionsModel() || !model->getAddressTableModel() || !model->getRecentRequestsTableModel())149return;151QString address;152QString label = ui->reqLabel->text();153/* Generate new receiving address */154const OutputType address_type = (OutputType)ui->addressType->currentData().toInt();155address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, "", address_type);157switch(model->getAddressTableModel()->getEditStatus())158{159case AddressTableModel::EditStatus::OK: {160// Success161SendCoinsRecipient info(address, label,162ui->reqAmount->value(), ui->reqMessage->text());163ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);164dialog->setAttribute(Qt::WA_DeleteOnClose);165dialog->setModel(model);166dialog->setInfo(info);167dialog->show();169/* Store request for later reference */170model->getRecentRequestsTableModel()->addNewRequest(info);171break;172}173case AddressTableModel::EditStatus::WALLET_UNLOCK_FAILURE:174QMessageBox::critical(this, windowTitle(),175tr("Could not unlock wallet."),176QMessageBox::Ok, QMessageBox::Ok);177break;178case AddressTableModel::EditStatus::KEY_GENERATION_FAILURE:179QMessageBox::critical(this, windowTitle(),180tr("Could not generate new %1 address").arg(QString::fromStdString(FormatOutputType(address_type))),181QMessageBox::Ok, QMessageBox::Ok);182break;183// These aren't valid return values for our action184case AddressTableModel::EditStatus::INVALID_ADDRESS:185case AddressTableModel::EditStatus::DUPLICATE_ADDRESS:186case AddressTableModel::EditStatus::NO_CHANGES:187assert(false);188}189clear();190}192void ReceiveCoinsDialog::on_recentRequestsView_doubleClicked(const QModelIndex &index)193{194const RecentRequestsTableModel *submodel = model->getRecentRequestsTableModel();195ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);196dialog->setModel(model);197dialog->setInfo(submodel->entry(index.row()).recipient);198dialog->setAttribute(Qt::WA_DeleteOnClose);199dialog->show();200}202void ReceiveCoinsDialog::recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)203{204// Enable Show/Remove buttons only if anything is selected.205bool enable = !ui->recentRequestsView->selectionModel()->selectedRows().isEmpty();206ui->showRequestButton->setEnabled(enable);207ui->removeRequestButton->setEnabled(enable);208}210void ReceiveCoinsDialog::on_showRequestButton_clicked()211{212if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())213return;214QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();216for (const QModelIndex& index : selection) {217on_recentRequestsView_doubleClicked(index);218}219}221void ReceiveCoinsDialog::on_removeRequestButton_clicked()222{223if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())224return;225QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();226if(selection.empty())227return;228// correct for selection mode ContiguousSelection229QModelIndex firstIndex = selection.at(0);230model->getRecentRequestsTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent());231}233QModelIndex ReceiveCoinsDialog::selectedRow()234{235if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())236return QModelIndex();237QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();238if(selection.empty())239return QModelIndex();240// correct for selection mode ContiguousSelection241QModelIndex firstIndex = selection.at(0);242return firstIndex;243}245// copy column of selected row to clipboard246void ReceiveCoinsDialog::copyColumnToClipboard(int column)247{248QModelIndex firstIndex = selectedRow();249if (!firstIndex.isValid()) {250return;
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.