Bitcoin ABC 0.30.7
P2P Digital Currency
editaddressdialog.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-2016 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6#include <qt/forms/ui_editaddressdialog.h>
7
9#include <qt/guiutil.h>
10
11#include <QDataWidgetMapper>
12#include <QMessageBox>
13
15 : QDialog(parent), ui(new Ui::EditAddressDialog), mapper(nullptr),
16 mode(_mode), model(nullptr) {
17 ui->setupUi(this);
18
19 GUIUtil::setupAddressWidget(ui->addressEdit, this);
20
21 switch (mode) {
23 setWindowTitle(tr("New sending address"));
24 break;
26 setWindowTitle(tr("Edit receiving address"));
27 ui->addressEdit->setEnabled(false);
28 break;
30 setWindowTitle(tr("Edit sending address"));
31 break;
32 }
33
34 mapper = new QDataWidgetMapper(this);
35 mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
36
38 connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this,
39 &EditAddressDialog::reject);
40 mapper->setItemDelegate(delegate);
41
43}
44
46 delete ui;
47}
48
50 this->model = _model;
51 if (!_model) {
52 return;
53 }
54
55 mapper->setModel(_model);
56 mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
57 mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
58}
59
61 mapper->setCurrentIndex(row);
62}
63
65 if (!model) {
66 return false;
67 }
68
69 switch (mode) {
72 AddressTableModel::Send, ui->labelEdit->text(),
73 ui->addressEdit->text(), model->GetDefaultAddressType());
74 break;
77 if (mapper->submit()) {
78 address = ui->addressEdit->text();
79 }
80 break;
81 }
82 return !address.isEmpty();
83}
84
86 if (!model) {
87 return;
88 }
89
90 if (!saveCurrentRow()) {
91 switch (model->getEditStatus()) {
93 // Failed with unknown reason. Just reject.
94 break;
96 // No changes were made during edit operation. Just reject.
97 break;
99 QMessageBox::warning(this, windowTitle(),
100 tr("The entered address \"%1\" is not a "
101 "valid Bitcoin address.")
102 .arg(ui->addressEdit->text()),
103 QMessageBox::Ok, QMessageBox::Ok);
104 break;
106 QMessageBox::warning(this, windowTitle(),
108 QMessageBox::Ok, QMessageBox::Ok);
109 break;
111 QMessageBox::critical(this, windowTitle(),
112 tr("Could not unlock wallet."),
113 QMessageBox::Ok, QMessageBox::Ok);
114 break;
116 QMessageBox::critical(this, windowTitle(),
117 tr("New key generation failed."),
118 QMessageBox::Ok, QMessageBox::Ok);
119 break;
120 }
121 return;
122 }
123 QDialog::accept();
124}
125
127 QString dup_address = ui->addressEdit->text();
128 QString existing_label = model->labelForAddress(dup_address);
129 QString existing_purpose = model->purposeForAddress(dup_address);
130
131 if (existing_purpose == "receive" &&
133 return tr("Address \"%1\" already exists as a receiving address with "
134 "label "
135 "\"%2\" and so cannot be added as a sending address.")
136 .arg(dup_address)
137 .arg(existing_label);
138 }
139 return tr("The entered address \"%1\" is already in the address book with "
140 "label \"%2\".")
141 .arg(dup_address)
142 .arg(existing_label);
143}
144
146 return address;
147}
148
149void EditAddressDialog::setAddress(const QString &_address) {
150 this->address = _address;
151 ui->addressEdit->setText(_address);
152}
Qt model of the address book in the core.
OutputType GetDefaultAddressType() const
EditStatus getEditStatus() const
@ WALLET_UNLOCK_FAILURE
Wallet could not be unlocked to create new receiving address.
@ NO_CHANGES
No changes were made during edit operation.
@ INVALID_ADDRESS
Unparseable address.
@ KEY_GENERATION_FAILURE
Generating a new public key for a receiving address failed.
@ OK
Everything ok.
@ DUPLICATE_ADDRESS
Address already in address book.
@ Address
Bitcoin address.
@ Label
User specified label.
static const QString Send
Specifies send address.
QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type)
QString purposeForAddress(const QString &address) const
Look up purpose for address in address book, if not found return empty string.
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
Dialog for editing an address and associated information.
Ui::EditAddressDialog * ui
EditAddressDialog(Mode mode, QWidget *parent=nullptr)
QString getDuplicateAddressWarning() const
Return a descriptive string when adding an already-existing address fails.
void setModel(AddressTableModel *model)
QDataWidgetMapper * mapper
AddressTableModel * model
void accept() override
void setAddress(const QString &address)
QString getAddress() const
void handleCloseWindowShortcut(QWidget *w)
Definition: guiutil.cpp:407
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:130