mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-14 05:42:36 -03:00
e476826338
d843db7
Qt: remove "new" button during receive-mode in addressbook (Jonas Schnelli)
Pull request description:
There are currently two ways how to generate new receiving addresses in the GUI (which leads to code duplication or required refactoring, see #12520).
Since the address-book is probably something that should be removed in the long run, suppressing the new-button in receive-mode could be a first step in deprecating the address book.
With this PR, users can still edit existing receiving address book entries and they can still create new sending address book entries.
Tree-SHA512: abe8d1b44bc3e1b53826ccf9d2b3f764264337758d95ca1fe1ef1bac72d47608cf454055fce3720e06634f0a5841a752ce643b4505b47d6e322b6fc71296e961
141 lines
3.7 KiB
C++
141 lines
3.7 KiB
C++
// Copyright (c) 2011-2017 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <qt/editaddressdialog.h>
|
|
#include <qt/forms/ui_editaddressdialog.h>
|
|
|
|
#include <qt/addresstablemodel.h>
|
|
#include <qt/guiutil.h>
|
|
|
|
#include <QDataWidgetMapper>
|
|
#include <QMessageBox>
|
|
|
|
|
|
EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::EditAddressDialog),
|
|
mapper(0),
|
|
mode(_mode),
|
|
model(0)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
GUIUtil::setupAddressWidget(ui->addressEdit, this);
|
|
|
|
switch(mode)
|
|
{
|
|
case NewSendingAddress:
|
|
setWindowTitle(tr("New sending address"));
|
|
break;
|
|
case EditReceivingAddress:
|
|
setWindowTitle(tr("Edit receiving address"));
|
|
ui->addressEdit->setEnabled(false);
|
|
break;
|
|
case EditSendingAddress:
|
|
setWindowTitle(tr("Edit sending address"));
|
|
break;
|
|
}
|
|
|
|
mapper = new QDataWidgetMapper(this);
|
|
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
|
}
|
|
|
|
EditAddressDialog::~EditAddressDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void EditAddressDialog::setModel(AddressTableModel *_model)
|
|
{
|
|
this->model = _model;
|
|
if(!_model)
|
|
return;
|
|
|
|
mapper->setModel(_model);
|
|
mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
|
|
mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
|
|
}
|
|
|
|
void EditAddressDialog::loadRow(int row)
|
|
{
|
|
mapper->setCurrentIndex(row);
|
|
}
|
|
|
|
bool EditAddressDialog::saveCurrentRow()
|
|
{
|
|
if(!model)
|
|
return false;
|
|
|
|
switch(mode)
|
|
{
|
|
case NewSendingAddress:
|
|
address = model->addRow(
|
|
AddressTableModel::Send,
|
|
ui->labelEdit->text(),
|
|
ui->addressEdit->text(),
|
|
model->GetDefaultAddressType());
|
|
break;
|
|
case EditReceivingAddress:
|
|
case EditSendingAddress:
|
|
if(mapper->submit())
|
|
{
|
|
address = ui->addressEdit->text();
|
|
}
|
|
break;
|
|
}
|
|
return !address.isEmpty();
|
|
}
|
|
|
|
void EditAddressDialog::accept()
|
|
{
|
|
if(!model)
|
|
return;
|
|
|
|
if(!saveCurrentRow())
|
|
{
|
|
switch(model->getEditStatus())
|
|
{
|
|
case AddressTableModel::OK:
|
|
// Failed with unknown reason. Just reject.
|
|
break;
|
|
case AddressTableModel::NO_CHANGES:
|
|
// No changes were made during edit operation. Just reject.
|
|
break;
|
|
case AddressTableModel::INVALID_ADDRESS:
|
|
QMessageBox::warning(this, windowTitle(),
|
|
tr("The entered address \"%1\" is not a valid Bitcoin address.").arg(ui->addressEdit->text()),
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
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;
|
|
case AddressTableModel::WALLET_UNLOCK_FAILURE:
|
|
QMessageBox::critical(this, windowTitle(),
|
|
tr("Could not unlock wallet."),
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
break;
|
|
case AddressTableModel::KEY_GENERATION_FAILURE:
|
|
QMessageBox::critical(this, windowTitle(),
|
|
tr("New key generation failed."),
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
break;
|
|
|
|
}
|
|
return;
|
|
}
|
|
QDialog::accept();
|
|
}
|
|
|
|
QString EditAddressDialog::getAddress() const
|
|
{
|
|
return address;
|
|
}
|
|
|
|
void EditAddressDialog::setAddress(const QString &_address)
|
|
{
|
|
this->address = _address;
|
|
ui->addressEdit->setText(_address);
|
|
}
|