2018-01-02 18:12:05 +01:00
|
|
|
// Copyright (c) 2011-2017 The Bitcoin 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.
|
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/editaddressdialog.h>
|
2017-08-15 17:31:26 +02:00
|
|
|
#include <qt/forms/ui_editaddressdialog.h>
|
2013-01-23 21:51:02 +01:00
|
|
|
|
2017-11-10 01:57:53 +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
|
|
|
|
2018-01-16 21:11:40 +01:00
|
|
|
extern OutputType g_address_type;
|
|
|
|
|
2016-09-09 13:43:29 +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),
|
|
|
|
mapper(0),
|
2016-09-09 13:43:29 +02:00
|
|
|
mode(_mode),
|
2013-12-16 22:54:02 +01:00
|
|
|
model(0)
|
2011-05-13 15:58:27 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(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 NewReceivingAddress:
|
|
|
|
setWindowTitle(tr("New receiving address"));
|
|
|
|
ui->addressEdit->setEnabled(false);
|
|
|
|
break;
|
|
|
|
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);
|
2011-05-13 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EditAddressDialog::~EditAddressDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2011-06-02 17:48:45 +02:00
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
void EditAddressDialog::setModel(AddressTableModel *_model)
|
2011-06-02 17:48:45 +02:00
|
|
|
{
|
2016-09-09 13:43:29 +02:00
|
|
|
this->model = _model;
|
|
|
|
if(!_model)
|
2013-01-08 08:17:58 +01:00
|
|
|
return;
|
|
|
|
|
2016-09-09 13:43:29 +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 NewReceivingAddress:
|
|
|
|
case NewSendingAddress:
|
2011-06-03 21:03:20 +02:00
|
|
|
address = model->addRow(
|
2011-06-03 15:16:11 +02:00
|
|
|
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
|
|
|
|
ui->labelEdit->text(),
|
2018-01-16 21:11:40 +01:00
|
|
|
ui->addressEdit->text(),
|
|
|
|
g_address_type);
|
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(),
|
2012-05-13 16:09:14 +02:00
|
|
|
tr("The entered address \"%1\" is not a valid Bitcoin 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(),
|
|
|
|
tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2011-08-04 21:31:47 +02:00
|
|
|
QString EditAddressDialog::getAddress() const
|
|
|
|
{
|
|
|
|
return address;
|
|
|
|
}
|
2011-11-08 19:54:16 +01:00
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
void EditAddressDialog::setAddress(const QString &_address)
|
2011-11-08 19:54:16 +01:00
|
|
|
{
|
2016-09-09 13:43:29 +02:00
|
|
|
this->address = _address;
|
|
|
|
ui->addressEdit->setText(_address);
|
2011-11-08 19:54:16 +01:00
|
|
|
}
|