2016-01-27 12:05:25 +01:00
|
|
|
// Copyright (c) 2011-2014 The Bitcoin Core developers
|
2022-06-08 01:36:46 +02:00
|
|
|
// Copyright (c) 2014-2021 The Dash Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 16:20:43 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <qt/editaddressdialog.h>
|
|
|
|
#include <qt/forms/ui_editaddressdialog.h>
|
2013-01-23 21:51:02 +01:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <qt/addresstablemodel.h>
|
|
|
|
#include <qt/guiutil.h>
|
2011-05-13 15:58:27 +02:00
|
|
|
|
2011-06-02 17:48:45 +02:00
|
|
|
#include <QDataWidgetMapper>
|
2011-06-03 15:16:11 +02:00
|
|
|
#include <QMessageBox>
|
2011-06-02 17:48:45 +02:00
|
|
|
|
2016-09-23 12:44:09 +02:00
|
|
|
EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
|
2011-05-13 15:58:27 +02:00
|
|
|
QDialog(parent),
|
2013-12-16 22:54:02 +01:00
|
|
|
ui(new Ui::EditAddressDialog),
|
2019-01-14 15:20:45 +01:00
|
|
|
mapper(nullptr),
|
2016-09-23 12:44:09 +02:00
|
|
|
mode(_mode),
|
2019-01-14 15:20:45 +01:00
|
|
|
model(nullptr)
|
2011-05-13 15:58:27 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2011-06-02 15:57:23 +02:00
|
|
|
|
2020-07-09 01:27:53 +02:00
|
|
|
GUIUtil::disableMacFocusRect(this);
|
|
|
|
|
2011-06-02 15:57:23 +02:00
|
|
|
GUIUtil::setupAddressWidget(ui->addressEdit, this);
|
2011-06-02 17:48:45 +02:00
|
|
|
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case NewSendingAddress:
|
|
|
|
setWindowTitle(tr("New sending address"));
|
|
|
|
break;
|
|
|
|
case EditReceivingAddress:
|
|
|
|
setWindowTitle(tr("Edit receiving address"));
|
2013-01-08 08:17:58 +01:00
|
|
|
ui->addressEdit->setEnabled(false);
|
2011-06-02 17:48:45 +02:00
|
|
|
break;
|
|
|
|
case EditSendingAddress:
|
|
|
|
setWindowTitle(tr("Edit sending address"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mapper = new QDataWidgetMapper(this);
|
2011-06-03 15:16:11 +02:00
|
|
|
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
2018-08-02 12:45:15 +02:00
|
|
|
|
|
|
|
GUIUtil::ItemDelegate* delegate = new GUIUtil::ItemDelegate(mapper);
|
|
|
|
connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &EditAddressDialog::reject);
|
|
|
|
mapper->setItemDelegate(delegate);
|
2011-05-13 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EditAddressDialog::~EditAddressDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2011-06-02 17:48:45 +02:00
|
|
|
|
2016-09-23 12:44:09 +02:00
|
|
|
void EditAddressDialog::setModel(AddressTableModel *_model)
|
2011-06-02 17:48:45 +02:00
|
|
|
{
|
2016-09-23 12:44:09 +02:00
|
|
|
this->model = _model;
|
|
|
|
if(!_model)
|
2013-01-08 08:17:58 +01:00
|
|
|
return;
|
|
|
|
|
2016-09-23 12:44:09 +02:00
|
|
|
mapper->setModel(_model);
|
2011-06-02 17:48:45 +02:00
|
|
|
mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
|
|
|
|
mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditAddressDialog::loadRow(int row)
|
|
|
|
{
|
|
|
|
mapper->setCurrentIndex(row);
|
|
|
|
}
|
2011-06-03 15:16:11 +02:00
|
|
|
|
2011-08-04 21:31:47 +02:00
|
|
|
bool EditAddressDialog::saveCurrentRow()
|
2011-06-03 15:16:11 +02:00
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!model)
|
|
|
|
return false;
|
2013-01-08 08:17:58 +01:00
|
|
|
|
2011-06-03 15:16:11 +02:00
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case NewSendingAddress:
|
2011-06-03 21:03:20 +02:00
|
|
|
address = model->addRow(
|
2018-03-20 09:15:08 +01:00
|
|
|
AddressTableModel::Send,
|
2011-06-03 15:16:11 +02:00
|
|
|
ui->labelEdit->text(),
|
2011-07-02 13:45:59 +02:00
|
|
|
ui->addressEdit->text());
|
2011-06-03 15:16:11 +02:00
|
|
|
break;
|
|
|
|
case EditReceivingAddress:
|
|
|
|
case EditSendingAddress:
|
2011-06-03 21:03:20 +02:00
|
|
|
if(mapper->submit())
|
|
|
|
{
|
|
|
|
address = ui->addressEdit->text();
|
|
|
|
}
|
2011-06-03 15:16:11 +02:00
|
|
|
break;
|
|
|
|
}
|
2011-08-04 21:31:47 +02:00
|
|
|
return !address.isEmpty();
|
2011-06-03 15:16:11 +02:00
|
|
|
}
|
2011-07-02 15:09:53 +02:00
|
|
|
|
|
|
|
void EditAddressDialog::accept()
|
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!model)
|
|
|
|
return;
|
2013-01-08 08:17:58 +01:00
|
|
|
|
2011-08-04 21:31:47 +02:00
|
|
|
if(!saveCurrentRow())
|
2011-07-02 15:09:53 +02:00
|
|
|
{
|
2011-07-16 19:01:05 +02:00
|
|
|
switch(model->getEditStatus())
|
2011-07-02 15:09:53 +02:00
|
|
|
{
|
2013-01-08 08:17:58 +01: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 19:01:05 +02:00
|
|
|
break;
|
|
|
|
case AddressTableModel::INVALID_ADDRESS:
|
2011-07-02 15:09:53 +02:00
|
|
|
QMessageBox::warning(this, windowTitle(),
|
2015-03-18 00:06:58 +01:00
|
|
|
tr("The entered address \"%1\" is not a valid Dash address.").arg(ui->addressEdit->text()),
|
2011-07-02 15:09:53 +02:00
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
2013-01-08 08:17:58 +01:00
|
|
|
break;
|
|
|
|
case AddressTableModel::DUPLICATE_ADDRESS:
|
|
|
|
QMessageBox::warning(this, windowTitle(),
|
2021-05-23 00:24:26 +02:00
|
|
|
getDuplicateAddressWarning(),
|
2013-01-08 08:17:58 +01:00
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
break;
|
2011-08-24 22:07:26 +02:00
|
|
|
case AddressTableModel::WALLET_UNLOCK_FAILURE:
|
|
|
|
QMessageBox::critical(this, windowTitle(),
|
|
|
|
tr("Could not unlock wallet."),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
2013-01-08 08:17:58 +01:00
|
|
|
break;
|
2011-09-02 18:02:22 +02:00
|
|
|
case AddressTableModel::KEY_GENERATION_FAILURE:
|
|
|
|
QMessageBox::critical(this, windowTitle(),
|
|
|
|
tr("New key generation failed."),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
2012-04-15 12:42:52 +02:00
|
|
|
break;
|
2011-07-16 19:01:05 +02:00
|
|
|
|
2013-01-08 08:17:58 +01:00
|
|
|
}
|
2011-07-02 15:09:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
2021-05-23 00:24:26 +02: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 21:31:47 +02:00
|
|
|
QString EditAddressDialog::getAddress() const
|
|
|
|
{
|
|
|
|
return address;
|
|
|
|
}
|
2011-11-08 19:54:16 +01:00
|
|
|
|
2016-09-23 12:44:09 +02:00
|
|
|
void EditAddressDialog::setAddress(const QString &_address)
|
2011-11-08 19:54:16 +01:00
|
|
|
{
|
2016-09-23 12:44:09 +02:00
|
|
|
this->address = _address;
|
|
|
|
ui->addressEdit->setText(_address);
|
2011-11-08 19:54:16 +01:00
|
|
|
}
|