2021-12-30 14:36:57 -03:00
|
|
|
// Copyright (c) 2011-2021 The Bitcoin Core developers
|
2014-12-13 01:09:33 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 12:20:43 -03:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <qt/editaddressdialog.h>
|
2017-08-15 12:31:26 -03:00
|
|
|
#include <qt/forms/ui_editaddressdialog.h>
|
2013-01-23 17:51:02 -03:00
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <qt/addresstablemodel.h>
|
|
|
|
#include <qt/guiutil.h>
|
2011-05-13 09:58:27 -04:00
|
|
|
|
2011-06-02 11:48:45 -04:00
|
|
|
#include <QDataWidgetMapper>
|
2011-06-03 09:16:11 -04:00
|
|
|
#include <QMessageBox>
|
2011-06-02 11:48:45 -04:00
|
|
|
|
2018-01-16 17:11:40 -03:00
|
|
|
|
2016-09-09 08:43:29 -03:00
|
|
|
EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
|
2020-09-07 13:09:33 -03:00
|
|
|
QDialog(parent, GUIUtil::dialog_flags),
|
2013-12-16 18:54:02 -03:00
|
|
|
ui(new Ui::EditAddressDialog),
|
2018-07-30 06:37:09 -04:00
|
|
|
mapper(nullptr),
|
2016-09-09 08:43:29 -03:00
|
|
|
mode(_mode),
|
2018-07-30 06:37:09 -04:00
|
|
|
model(nullptr)
|
2011-05-13 09:58:27 -04:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2011-06-02 09:57:23 -04:00
|
|
|
|
|
|
|
GUIUtil::setupAddressWidget(ui->addressEdit, this);
|
2011-06-02 11:48:45 -04:00
|
|
|
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case NewSendingAddress:
|
|
|
|
setWindowTitle(tr("New sending address"));
|
|
|
|
break;
|
|
|
|
case EditReceivingAddress:
|
|
|
|
setWindowTitle(tr("Edit receiving address"));
|
2013-01-08 04:17:58 -03:00
|
|
|
ui->addressEdit->setEnabled(false);
|
2011-06-02 11:48:45 -04:00
|
|
|
break;
|
|
|
|
case EditSendingAddress:
|
|
|
|
setWindowTitle(tr("Edit sending address"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mapper = new QDataWidgetMapper(this);
|
2011-06-03 09:16:11 -04:00
|
|
|
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
2018-07-28 18:45:05 -04:00
|
|
|
|
|
|
|
GUIUtil::ItemDelegate* delegate = new GUIUtil::ItemDelegate(mapper);
|
|
|
|
connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &EditAddressDialog::reject);
|
|
|
|
mapper->setItemDelegate(delegate);
|
2019-04-07 15:33:35 -04:00
|
|
|
|
|
|
|
GUIUtil::handleCloseWindowShortcut(this);
|
2011-05-13 09:58:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
EditAddressDialog::~EditAddressDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2011-06-02 11:48:45 -04:00
|
|
|
|
2016-09-09 08:43:29 -03:00
|
|
|
void EditAddressDialog::setModel(AddressTableModel *_model)
|
2011-06-02 11:48:45 -04:00
|
|
|
{
|
2016-09-09 08:43:29 -03:00
|
|
|
this->model = _model;
|
|
|
|
if(!_model)
|
2013-01-08 04:17:58 -03:00
|
|
|
return;
|
|
|
|
|
2016-09-09 08:43:29 -03:00
|
|
|
mapper->setModel(_model);
|
2011-06-02 11:48:45 -04:00
|
|
|
mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
|
|
|
|
mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditAddressDialog::loadRow(int row)
|
|
|
|
{
|
|
|
|
mapper->setCurrentIndex(row);
|
|
|
|
}
|
2011-06-03 09:16:11 -04:00
|
|
|
|
2011-08-04 15:31:47 -04:00
|
|
|
bool EditAddressDialog::saveCurrentRow()
|
2011-06-03 09:16:11 -04:00
|
|
|
{
|
2011-11-08 17:18:36 -03:00
|
|
|
if(!model)
|
|
|
|
return false;
|
2013-01-08 04:17:58 -03:00
|
|
|
|
2011-06-03 09:16:11 -04:00
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case NewSendingAddress:
|
2011-06-03 15:03:20 -04:00
|
|
|
address = model->addRow(
|
2018-03-19 02:13:08 -03:00
|
|
|
AddressTableModel::Send,
|
2011-06-03 09:16:11 -04:00
|
|
|
ui->labelEdit->text(),
|
2018-01-16 17:11:40 -03:00
|
|
|
ui->addressEdit->text(),
|
2018-02-10 23:06:35 -03:00
|
|
|
model->GetDefaultAddressType());
|
2011-06-03 09:16:11 -04:00
|
|
|
break;
|
|
|
|
case EditReceivingAddress:
|
|
|
|
case EditSendingAddress:
|
2011-06-03 15:03:20 -04:00
|
|
|
if(mapper->submit())
|
|
|
|
{
|
|
|
|
address = ui->addressEdit->text();
|
|
|
|
}
|
2011-06-03 09:16:11 -04:00
|
|
|
break;
|
|
|
|
}
|
2011-08-04 15:31:47 -04:00
|
|
|
return !address.isEmpty();
|
2011-06-03 09:16:11 -04:00
|
|
|
}
|
2011-07-02 09:09:53 -04:00
|
|
|
|
|
|
|
void EditAddressDialog::accept()
|
|
|
|
{
|
2011-11-08 17:18:36 -03:00
|
|
|
if(!model)
|
|
|
|
return;
|
2013-01-08 04:17:58 -03:00
|
|
|
|
2011-08-04 15:31:47 -04:00
|
|
|
if(!saveCurrentRow())
|
2011-07-02 09:09:53 -04:00
|
|
|
{
|
2011-07-16 13:01:05 -04:00
|
|
|
switch(model->getEditStatus())
|
2011-07-02 09:09:53 -04:00
|
|
|
{
|
2013-01-08 04:17:58 -03:00
|
|
|
case AddressTableModel::OK:
|
|
|
|
// Failed with unknown reason. Just reject.
|
|
|
|
break;
|
|
|
|
case AddressTableModel::NO_CHANGES:
|
|
|
|
// No changes were made during edit operation. Just reject.
|
2011-07-16 13:01:05 -04:00
|
|
|
break;
|
|
|
|
case AddressTableModel::INVALID_ADDRESS:
|
2011-07-02 09:09:53 -04:00
|
|
|
QMessageBox::warning(this, windowTitle(),
|
2012-05-13 10:09:14 -04:00
|
|
|
tr("The entered address \"%1\" is not a valid Bitcoin address.").arg(ui->addressEdit->text()),
|
2011-07-02 09:09:53 -04:00
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
2013-01-08 04:17:58 -03:00
|
|
|
break;
|
|
|
|
case AddressTableModel::DUPLICATE_ADDRESS:
|
|
|
|
QMessageBox::warning(this, windowTitle(),
|
2018-04-10 17:27:40 -03:00
|
|
|
getDuplicateAddressWarning(),
|
2013-01-08 04:17:58 -03:00
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
break;
|
2011-08-24 17:07:26 -03:00
|
|
|
case AddressTableModel::WALLET_UNLOCK_FAILURE:
|
|
|
|
QMessageBox::critical(this, windowTitle(),
|
|
|
|
tr("Could not unlock wallet."),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
2013-01-08 04:17:58 -03:00
|
|
|
break;
|
2011-09-02 13:02:22 -03:00
|
|
|
case AddressTableModel::KEY_GENERATION_FAILURE:
|
|
|
|
QMessageBox::critical(this, windowTitle(),
|
|
|
|
tr("New key generation failed."),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
2012-04-15 07:42:52 -03:00
|
|
|
break;
|
2011-07-16 13:01:05 -04:00
|
|
|
|
2013-01-08 04:17:58 -03:00
|
|
|
}
|
2011-07-02 09:09:53 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
2018-04-10 17:27:40 -03:00
|
|
|
QString EditAddressDialog::getDuplicateAddressWarning() const
|
|
|
|
{
|
|
|
|
QString dup_address = ui->addressEdit->text();
|
|
|
|
QString existing_label = model->labelForAddress(dup_address);
|
|
|
|
QString existing_purpose = model->purposeForAddress(dup_address);
|
|
|
|
|
|
|
|
if (existing_purpose == "receive" &&
|
|
|
|
(mode == NewSendingAddress || mode == EditSendingAddress)) {
|
|
|
|
return tr(
|
|
|
|
"Address \"%1\" already exists as a receiving address with label "
|
|
|
|
"\"%2\" and so cannot be added as a sending address."
|
|
|
|
).arg(dup_address).arg(existing_label);
|
|
|
|
}
|
|
|
|
return tr(
|
|
|
|
"The entered address \"%1\" is already in the address book with "
|
|
|
|
"label \"%2\"."
|
|
|
|
).arg(dup_address).arg(existing_label);
|
|
|
|
}
|
|
|
|
|
2011-08-04 15:31:47 -04:00
|
|
|
QString EditAddressDialog::getAddress() const
|
|
|
|
{
|
|
|
|
return address;
|
|
|
|
}
|
2011-11-08 15:54:16 -03:00
|
|
|
|
2016-09-09 08:43:29 -03:00
|
|
|
void EditAddressDialog::setAddress(const QString &_address)
|
2011-11-08 15:54:16 -03:00
|
|
|
{
|
2016-09-09 08:43:29 -03:00
|
|
|
this->address = _address;
|
|
|
|
ui->addressEdit->setText(_address);
|
2011-11-08 15:54:16 -03:00
|
|
|
}
|