Bitcoin ABC  0.22.12
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 
5 #include <qt/editaddressdialog.h>
6 #include <qt/forms/ui_editaddressdialog.h>
7 
8 #include <qt/addresstablemodel.h>
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) {
22  case NewSendingAddress:
23  setWindowTitle(tr("New sending address"));
24  break;
26  setWindowTitle(tr("Edit receiving address"));
27  ui->addressEdit->setEnabled(false);
28  break;
29  case EditSendingAddress:
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 }
42 
44  delete ui;
45 }
46 
48  this->model = _model;
49  if (!_model) {
50  return;
51  }
52 
53  mapper->setModel(_model);
54  mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
55  mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
56 }
57 
59  mapper->setCurrentIndex(row);
60 }
61 
63  if (!model) {
64  return false;
65  }
66 
67  switch (mode) {
68  case NewSendingAddress:
69  address = model->addRow(
70  AddressTableModel::Send, ui->labelEdit->text(),
71  ui->addressEdit->text(), model->GetDefaultAddressType());
72  break;
74  case EditSendingAddress:
75  if (mapper->submit()) {
76  address = ui->addressEdit->text();
77  }
78  break;
79  }
80  return !address.isEmpty();
81 }
82 
84  if (!model) {
85  return;
86  }
87 
88  if (!saveCurrentRow()) {
89  switch (model->getEditStatus()) {
91  // Failed with unknown reason. Just reject.
92  break;
94  // No changes were made during edit operation. Just reject.
95  break;
97  QMessageBox::warning(this, windowTitle(),
98  tr("The entered address \"%1\" is not a "
99  "valid Bitcoin address.")
100  .arg(ui->addressEdit->text()),
101  QMessageBox::Ok, QMessageBox::Ok);
102  break;
104  QMessageBox::warning(this, windowTitle(),
106  QMessageBox::Ok, QMessageBox::Ok);
107  break;
109  QMessageBox::critical(this, windowTitle(),
110  tr("Could not unlock wallet."),
111  QMessageBox::Ok, QMessageBox::Ok);
112  break;
114  QMessageBox::critical(this, windowTitle(),
115  tr("New key generation failed."),
116  QMessageBox::Ok, QMessageBox::Ok);
117  break;
118  }
119  return;
120  }
121  QDialog::accept();
122 }
123 
125  QString dup_address = ui->addressEdit->text();
126  QString existing_label = model->labelForAddress(dup_address);
127  QString existing_purpose = model->purposeForAddress(dup_address);
128 
129  if (existing_purpose == "receive" &&
131  return tr("Address \"%1\" already exists as a receiving address with "
132  "label "
133  "\"%2\" and so cannot be added as a sending address.")
134  .arg(dup_address)
135  .arg(existing_label);
136  }
137  return tr("The entered address \"%1\" is already in the address book with "
138  "label \"%2\".")
139  .arg(dup_address)
140  .arg(existing_label);
141 }
142 
144  return address;
145 }
146 
147 void EditAddressDialog::setAddress(const QString &_address) {
148  this->address = _address;
149  ui->addressEdit->setText(_address);
150 }
Generating a new public key for a receiving address failed.
Address already in address book.
QString purposeForAddress(const QString &address) const
Look up purpose for address in address book, if not found return empty string.
QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type)
static const QString Send
Specifies send address.
void setModel(AddressTableModel *model)
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:117
Wallet could not be unlocked to create new receiving address.
EditAddressDialog(Mode mode, QWidget *parent=nullptr)
QDataWidgetMapper * mapper
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
Qt model of the address book in the core.
AddressTableModel * model
OutputType GetDefaultAddressType() const
void accept() override
void setAddress(const QString &address)
Dialog for editing an address and associated information.
QString getAddress() const
No changes were made during edit operation.
Ui::EditAddressDialog * ui
EditStatus getEditStatus() const
User specified label.
QString getDuplicateAddressWarning() const
Return a descriptive string when adding an already-existing address fails.