2020-10-07 10:36:04 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2023-01-02 19:30:11 +00:00
|
|
|
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2021-06-28 17:48:23 +00:00
|
|
|
#include "ReceiveWidget.h"
|
|
|
|
#include "ui_ReceiveWidget.h"
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
#include <QMenu>
|
2021-05-02 18:22:38 +00:00
|
|
|
#include <QMessageBox>
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2021-10-01 17:10:46 +00:00
|
|
|
#include "dialog/PaymentRequestDialog.h"
|
2021-06-28 17:48:23 +00:00
|
|
|
#include "dialog/QrCodeDialog.h"
|
|
|
|
#include "utils/Icons.h"
|
2023-03-28 20:42:12 +00:00
|
|
|
#include "utils/Utils.h"
|
2021-06-28 17:48:23 +00:00
|
|
|
|
2023-03-01 02:05:56 +00:00
|
|
|
ReceiveWidget::ReceiveWidget(Wallet *wallet, QWidget *parent)
|
2021-06-28 17:48:23 +00:00
|
|
|
: QWidget(parent)
|
|
|
|
, ui(new Ui::ReceiveWidget)
|
2023-03-01 02:05:56 +00:00
|
|
|
, m_wallet(wallet)
|
2020-10-07 10:36:04 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2023-03-01 02:05:56 +00:00
|
|
|
m_model = m_wallet->subaddressModel();
|
|
|
|
m_proxyModel = new SubaddressProxyModel(this, m_wallet->subaddress());
|
2021-05-18 15:59:18 +00:00
|
|
|
m_proxyModel->setSourceModel(m_model);
|
|
|
|
m_proxyModel->setHiddenAddresses(this->getHiddenAddresses());
|
|
|
|
|
|
|
|
ui->addresses->setModel(m_proxyModel);
|
|
|
|
ui->addresses->setColumnHidden(SubaddressModel::isUsed, true);
|
2023-03-07 20:36:15 +00:00
|
|
|
ui->addresses->header()->setSectionResizeMode(SubaddressModel::Index, QHeaderView::ResizeToContents);
|
|
|
|
ui->addresses->header()->setSectionResizeMode(SubaddressModel::Address, QHeaderView::ResizeToContents);
|
|
|
|
ui->addresses->header()->setSectionResizeMode(SubaddressModel::Label, QHeaderView::Stretch);
|
2021-05-18 15:59:18 +00:00
|
|
|
|
|
|
|
connect(ui->addresses->selectionModel(), &QItemSelectionModel::currentChanged, [=](QModelIndex current, QModelIndex prev){
|
|
|
|
this->updateQrCode();
|
|
|
|
});
|
|
|
|
connect(m_model, &SubaddressModel::modelReset, [this](){
|
|
|
|
this->updateQrCode();
|
|
|
|
});
|
|
|
|
|
2021-05-23 22:02:36 +00:00
|
|
|
ui->qrCode->setCursor(Qt::PointingHandCursor);
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
// header context menu
|
|
|
|
ui->addresses->header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
m_headerMenu = new QMenu(this);
|
|
|
|
m_showFullAddressesAction = m_headerMenu->addAction("Show full addresses", this, &ReceiveWidget::setShowFullAddresses);
|
|
|
|
m_showFullAddressesAction->setCheckable(true);
|
2023-06-27 13:21:46 +00:00
|
|
|
m_showChangeAddressesAction = m_headerMenu->addAction("Show change addresses", this, &ReceiveWidget::setShowChangeAddresses);
|
|
|
|
m_showChangeAddressesAction->setCheckable(true);
|
2020-10-07 10:36:04 +00:00
|
|
|
connect(ui->addresses->header(), &QHeaderView::customContextMenuRequested, this, &ReceiveWidget::showHeaderMenu);
|
|
|
|
|
|
|
|
// context menu
|
|
|
|
ui->addresses->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
m_showTransactionsAction = new QAction("Show transactions");
|
|
|
|
connect(m_showTransactionsAction, &QAction::triggered, this, &ReceiveWidget::onShowTransactions);
|
|
|
|
connect(ui->addresses, &QTreeView::customContextMenuRequested, this, &ReceiveWidget::showContextMenu);
|
|
|
|
|
2021-05-02 18:22:38 +00:00
|
|
|
connect(ui->btn_generateSubaddress, &QPushButton::clicked, this, &ReceiveWidget::generateSubaddress);
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
connect(ui->qrCode, &ClickableLabel::clicked, this, &ReceiveWidget::showQrCodeDialog);
|
2021-05-23 14:58:18 +00:00
|
|
|
connect(ui->search, &QLineEdit::textChanged, this, &ReceiveWidget::setSearchFilter);
|
2021-03-14 21:12:02 +00:00
|
|
|
|
|
|
|
connect(ui->check_showUsed, &QCheckBox::clicked, this, &ReceiveWidget::setShowUsedAddresses);
|
|
|
|
connect(ui->check_showHidden, &QCheckBox::clicked, this, &ReceiveWidget::setShowHiddenAddresses);
|
2021-10-01 17:10:46 +00:00
|
|
|
|
|
|
|
connect(ui->btn_createPaymentRequest, &QPushButton::clicked, this, &ReceiveWidget::createPaymentRequest);
|
2020-10-07 10:36:04 +00:00
|
|
|
}
|
|
|
|
|
2021-05-23 14:58:18 +00:00
|
|
|
void ReceiveWidget::setSearchbarVisible(bool visible) {
|
|
|
|
ui->search->setVisible(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReceiveWidget::focusSearchbar() {
|
|
|
|
ui->search->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
ui->search->setFocus();
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
void ReceiveWidget::copyAddress() {
|
|
|
|
QModelIndex index = ui->addresses->currentIndex();
|
2023-03-28 20:42:12 +00:00
|
|
|
Utils::copyColumn(&index, SubaddressModel::Address);
|
2020-10-07 10:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReceiveWidget::copyLabel() {
|
|
|
|
QModelIndex index = ui->addresses->currentIndex();
|
2023-03-28 20:42:12 +00:00
|
|
|
Utils::copyColumn(&index, SubaddressModel::Label);
|
2020-10-07 10:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReceiveWidget::editLabel() {
|
|
|
|
QModelIndex index = ui->addresses->currentIndex().siblingAtColumn(m_model->ModelColumn::Label);
|
|
|
|
ui->addresses->setCurrentIndex(index);
|
|
|
|
ui->addresses->edit(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReceiveWidget::showContextMenu(const QPoint &point) {
|
2021-03-14 21:12:02 +00:00
|
|
|
Monero::SubaddressRow* row = this->currentEntry();
|
|
|
|
if (!row) return;
|
|
|
|
|
|
|
|
QString address = QString::fromStdString(row->getAddress());
|
|
|
|
bool isUsed = row->isUsed();
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
auto *menu = new QMenu(ui->addresses);
|
|
|
|
|
2021-10-23 13:25:29 +00:00
|
|
|
menu->addAction("Copy address", this, &ReceiveWidget::copyAddress);
|
|
|
|
menu->addAction("Copy label", this, &ReceiveWidget::copyLabel);
|
|
|
|
menu->addAction("Edit label", this, &ReceiveWidget::editLabel);
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
if (isUsed) {
|
|
|
|
menu->addAction(m_showTransactionsAction);
|
|
|
|
}
|
|
|
|
|
2021-03-14 21:12:02 +00:00
|
|
|
QStringList hiddenAddresses = this->getHiddenAddresses();
|
|
|
|
if (hiddenAddresses.contains(address)) {
|
2021-10-23 13:25:29 +00:00
|
|
|
menu->addAction("Unhide address", this, &ReceiveWidget::showAddress);
|
2021-03-14 21:12:02 +00:00
|
|
|
} else {
|
|
|
|
menu->addAction("Hide address", this, &ReceiveWidget::hideAddress);
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:05:56 +00:00
|
|
|
if (m_wallet->isHwBacked()) {
|
2021-05-02 18:22:38 +00:00
|
|
|
menu->addAction("Show on device", this, &ReceiveWidget::showOnDevice);
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
menu->popup(ui->addresses->viewport()->mapToGlobal(point));
|
|
|
|
}
|
|
|
|
|
2021-10-01 17:10:46 +00:00
|
|
|
void ReceiveWidget::createPaymentRequest() {
|
|
|
|
QModelIndex index = ui->addresses->currentIndex();
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString address = index.model()->data(index.siblingAtColumn(SubaddressModel::Address), Qt::UserRole).toString();
|
|
|
|
|
2023-03-01 02:05:56 +00:00
|
|
|
PaymentRequestDialog dialog{this, m_wallet, address};
|
2021-10-01 17:10:46 +00:00
|
|
|
dialog.exec();
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
void ReceiveWidget::onShowTransactions() {
|
|
|
|
QModelIndex index = ui->addresses->currentIndex();
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString address = index.model()->data(index.siblingAtColumn(SubaddressModel::Address), Qt::UserRole).toString();
|
|
|
|
emit showTransactions(address);
|
|
|
|
}
|
|
|
|
|
2023-06-27 13:21:46 +00:00
|
|
|
void ReceiveWidget::setShowChangeAddresses(bool show) {
|
|
|
|
if (!m_proxyModel) return;
|
|
|
|
m_proxyModel->setShowChangeAddresses(show);
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
void ReceiveWidget::setShowFullAddresses(bool show) {
|
|
|
|
if (!m_model) return;
|
|
|
|
m_model->setShowFullAddresses(show);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReceiveWidget::setShowUsedAddresses(bool show) {
|
|
|
|
if (!m_proxyModel) return;
|
|
|
|
m_proxyModel->setShowUsed(show);
|
|
|
|
}
|
|
|
|
|
2021-03-14 21:12:02 +00:00
|
|
|
void ReceiveWidget::setShowHiddenAddresses(bool show) {
|
|
|
|
if (!m_proxyModel) return;
|
|
|
|
m_proxyModel->setShowHidden(show);
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
void ReceiveWidget::setSearchFilter(const QString &filter) {
|
|
|
|
if (!m_proxyModel) return;
|
|
|
|
m_proxyModel->setSearchFilter(filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReceiveWidget::showHeaderMenu(const QPoint& position)
|
|
|
|
{
|
2021-05-10 13:20:33 +00:00
|
|
|
Q_UNUSED(position);
|
2020-10-07 10:36:04 +00:00
|
|
|
m_showFullAddressesAction->setChecked(m_model->isShowFullAddresses());
|
|
|
|
m_headerMenu->exec(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
2021-03-14 21:12:02 +00:00
|
|
|
void ReceiveWidget::hideAddress()
|
|
|
|
{
|
|
|
|
Monero::SubaddressRow* row = this->currentEntry();
|
|
|
|
if (!row) return;
|
|
|
|
QString address = QString::fromStdString(row->getAddress());
|
|
|
|
this->addHiddenAddress(address);
|
|
|
|
m_proxyModel->setHiddenAddresses(this->getHiddenAddresses());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReceiveWidget::showAddress()
|
|
|
|
{
|
|
|
|
Monero::SubaddressRow* row = this->currentEntry();
|
|
|
|
if (!row) return;
|
|
|
|
QString address = QString::fromStdString(row->getAddress());
|
|
|
|
this->removeHiddenAddress(address);
|
|
|
|
m_proxyModel->setHiddenAddresses(this->getHiddenAddresses());
|
|
|
|
}
|
|
|
|
|
2021-05-02 18:22:38 +00:00
|
|
|
void ReceiveWidget::showOnDevice() {
|
|
|
|
Monero::SubaddressRow* row = this->currentEntry();
|
|
|
|
if (!row) return;
|
2023-03-01 02:05:56 +00:00
|
|
|
m_wallet->deviceShowAddressAsync(m_wallet->currentSubaddressAccount(), row->getRowId(), "");
|
2021-05-02 18:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReceiveWidget::generateSubaddress() {
|
2023-03-01 02:05:56 +00:00
|
|
|
bool r = m_wallet->subaddress()->addRow(m_wallet->currentSubaddressAccount(), "");
|
2021-05-02 18:22:38 +00:00
|
|
|
if (!r) {
|
2023-09-12 14:15:40 +00:00
|
|
|
Utils::showError(this, "Failed to generate subaddress", m_wallet->subaddress()->errorString());
|
2021-05-02 18:22:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 11:11:54 +00:00
|
|
|
void ReceiveWidget::updateQrCode(){
|
|
|
|
QModelIndex index = ui->addresses->currentIndex();
|
|
|
|
if (!index.isValid()) {
|
|
|
|
ui->qrCode->clear();
|
2021-10-01 17:10:46 +00:00
|
|
|
ui->btn_createPaymentRequest->hide();
|
2020-11-14 11:11:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString address = index.model()->data(index.siblingAtColumn(SubaddressModel::Address), Qt::UserRole).toString();
|
2020-10-07 10:36:04 +00:00
|
|
|
const QrCode qrc(address, QrCode::Version::AUTO, QrCode::ErrorCorrectionLevel::MEDIUM);
|
|
|
|
|
|
|
|
int width = ui->qrCode->width() - 4;
|
|
|
|
if (qrc.isValid()) {
|
|
|
|
ui->qrCode->setPixmap(qrc.toPixmap(1).scaled(width, width, Qt::KeepAspectRatio));
|
2021-10-01 17:10:46 +00:00
|
|
|
ui->btn_createPaymentRequest->show();
|
2020-10-07 10:36:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReceiveWidget::showQrCodeDialog() {
|
|
|
|
QModelIndex index = ui->addresses->currentIndex();
|
2020-11-14 11:11:54 +00:00
|
|
|
if (!index.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-10-07 10:36:04 +00:00
|
|
|
QString address = index.model()->data(index.siblingAtColumn(SubaddressModel::Address), Qt::UserRole).toString();
|
2020-10-16 03:05:05 +00:00
|
|
|
QrCode qr(address, QrCode::Version::AUTO, QrCode::ErrorCorrectionLevel::HIGH);
|
2021-07-03 22:06:24 +00:00
|
|
|
QrCodeDialog dialog{this, &qr, "Address"};
|
|
|
|
dialog.exec();
|
2020-10-07 10:36:04 +00:00
|
|
|
}
|
|
|
|
|
2021-03-14 21:12:02 +00:00
|
|
|
QStringList ReceiveWidget::getHiddenAddresses() {
|
2023-03-01 02:05:56 +00:00
|
|
|
QString data = m_wallet->getCacheAttribute("feather.hiddenaddresses");
|
2021-03-14 21:12:02 +00:00
|
|
|
return data.split(",");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReceiveWidget::addHiddenAddress(const QString& address) {
|
|
|
|
QStringList hiddenAddresses = this->getHiddenAddresses();
|
|
|
|
if (!hiddenAddresses.contains(address)) {
|
|
|
|
hiddenAddresses.append(address);
|
|
|
|
}
|
|
|
|
QString data = hiddenAddresses.join(",");
|
2023-03-01 02:05:56 +00:00
|
|
|
m_wallet->setCacheAttribute("feather.hiddenaddresses", data);
|
2021-03-14 21:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReceiveWidget::removeHiddenAddress(const QString &address) {
|
|
|
|
QStringList hiddenAddresses = this->getHiddenAddresses();
|
|
|
|
hiddenAddresses.removeAll(address);
|
|
|
|
QString data = hiddenAddresses.join(",");
|
2023-03-01 02:05:56 +00:00
|
|
|
m_wallet->setCacheAttribute("feather.hiddenaddresses", data);
|
2021-03-14 21:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Monero::SubaddressRow* ReceiveWidget::currentEntry() {
|
|
|
|
QModelIndexList list = ui->addresses->selectionModel()->selectedRows();
|
|
|
|
if (list.size() == 1) {
|
|
|
|
return m_model->entryFromIndex(m_proxyModel->mapToSource(list.first()));
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-27 12:13:05 +00:00
|
|
|
ReceiveWidget::~ReceiveWidget() = default;
|