Bitcoin Core  0.20.99
P2P Digital Currency
editaddressdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2018 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 
14 
15 EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
16  QDialog(parent),
17  ui(new Ui::EditAddressDialog),
18  mapper(nullptr),
19  mode(_mode),
20  model(nullptr)
21 {
22  ui->setupUi(this);
23 
24  GUIUtil::setupAddressWidget(ui->addressEdit, this);
25 
26  switch(mode)
27  {
28  case NewSendingAddress:
29  setWindowTitle(tr("New sending address"));
30  break;
32  setWindowTitle(tr("Edit receiving address"));
33  ui->addressEdit->setEnabled(false);
34  break;
35  case EditSendingAddress:
36  setWindowTitle(tr("Edit sending address"));
37  break;
38  }
39 
40  mapper = new QDataWidgetMapper(this);
41  mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
42 
44  connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &EditAddressDialog::reject);
45  mapper->setItemDelegate(delegate);
46 
48 }
49 
51 {
52  delete ui;
53 }
54 
56 {
57  this->model = _model;
58  if(!_model)
59  return;
60 
61  mapper->setModel(_model);
62  mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
63  mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
64 }
65 
67 {
68  mapper->setCurrentIndex(row);
69 }
70 
72 {
73  if(!model)
74  return false;
75 
76  switch(mode)
77  {
78  case NewSendingAddress:
79  address = model->addRow(
81  ui->labelEdit->text(),
82  ui->addressEdit->text(),
84  break;
86  case EditSendingAddress:
87  if(mapper->submit())
88  {
89  address = ui->addressEdit->text();
90  }
91  break;
92  }
93  return !address.isEmpty();
94 }
95 
97 {
98  if(!model)
99  return;
100 
101  if(!saveCurrentRow())
102  {
103  switch(model->getEditStatus())
104  {
106  // Failed with unknown reason. Just reject.
107  break;
109  // No changes were made during edit operation. Just reject.
110  break;
112  QMessageBox::warning(this, windowTitle(),
113  tr("The entered address \"%1\" is not a valid Bitcoin address.").arg(ui->addressEdit->text()),
114  QMessageBox::Ok, QMessageBox::Ok);
115  break;
117  QMessageBox::warning(this, windowTitle(),
119  QMessageBox::Ok, QMessageBox::Ok);
120  break;
122  QMessageBox::critical(this, windowTitle(),
123  tr("Could not unlock wallet."),
124  QMessageBox::Ok, QMessageBox::Ok);
125  break;
127  QMessageBox::critical(this, windowTitle(),
128  tr("New key generation failed."),
129  QMessageBox::Ok, QMessageBox::Ok);
130  break;
131 
132  }
133  return;
134  }
135  QDialog::accept();
136 }
137 
139 {
140  QString dup_address = ui->addressEdit->text();
141  QString existing_label = model->labelForAddress(dup_address);
142  QString existing_purpose = model->purposeForAddress(dup_address);
143 
144  if (existing_purpose == "receive" &&
146  return tr(
147  "Address \"%1\" already exists as a receiving address with label "
148  "\"%2\" and so cannot be added as a sending address."
149  ).arg(dup_address).arg(existing_label);
150  }
151  return tr(
152  "The entered address \"%1\" is already in the address book with "
153  "label \"%2\"."
154  ).arg(dup_address).arg(existing_label);
155 }
156 
158 {
159  return address;
160 }
161 
162 void EditAddressDialog::setAddress(const QString &_address)
163 {
164  this->address = _address;
165  ui->addressEdit->setText(_address);
166 }
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:106
Wallet could not be unlocked to create new receiving address.
EditAddressDialog(Mode mode, QWidget *parent=nullptr)
void handleCloseWindowShortcut(QWidget *w)
Definition: guiutil.cpp:390
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.