Bitcoin ABC  0.24.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 
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 
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) {
70  case NewSendingAddress:
71  address = model->addRow(
72  AddressTableModel::Send, ui->labelEdit->text(),
73  ui->addressEdit->text(), model->GetDefaultAddressType());
74  break;
76  case EditSendingAddress:
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 
149 void EditAddressDialog::setAddress(const QString &_address) {
150  this->address = _address;
151  ui->addressEdit->setText(_address);
152 }
EditAddressDialog::loadRow
void loadRow(int row)
Definition: editaddressdialog.cpp:60
EditAddressDialog::EditReceivingAddress
@ EditReceivingAddress
Definition: editaddressdialog.h:27
AddressTableModel
Qt model of the address book in the core.
Definition: addresstablemodel.h:24
AddressTableModel::labelForAddress
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
Definition: addresstablemodel.cpp:386
AddressTableModel::KEY_GENERATION_FAILURE
@ KEY_GENERATION_FAILURE
Generating a new public key for a receiving address failed.
Definition: addresstablemodel.h:56
GUIUtil::ItemDelegate
Definition: guiutil.h:316
EditAddressDialog::setModel
void setModel(AddressTableModel *model)
Definition: editaddressdialog.cpp:49
GUIUtil::ItemDelegate::keyEscapePressed
void keyEscapePressed()
EditAddressDialog::EditSendingAddress
@ EditSendingAddress
Definition: editaddressdialog.h:27
EditAddressDialog::EditAddressDialog
EditAddressDialog(Mode mode, QWidget *parent=nullptr)
Definition: editaddressdialog.cpp:14
EditAddressDialog
Dialog for editing an address and associated information.
Definition: editaddressdialog.h:23
AddressTableModel::addRow
QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type)
Definition: addresstablemodel.cpp:322
EditAddressDialog::~EditAddressDialog
~EditAddressDialog()
Definition: editaddressdialog.cpp:45
EditAddressDialog::model
AddressTableModel * model
Definition: editaddressdialog.h:53
EditAddressDialog::mapper
QDataWidgetMapper * mapper
Definition: editaddressdialog.h:51
guiutil.h
AddressTableModel::Label
@ Label
User specified label.
Definition: addresstablemodel.h:33
EditAddressDialog::setAddress
void setAddress(const QString &address)
Definition: editaddressdialog.cpp:149
EditAddressDialog::NewSendingAddress
@ NewSendingAddress
Definition: editaddressdialog.h:27
EditAddressDialog::saveCurrentRow
bool saveCurrentRow()
Definition: editaddressdialog.cpp:64
editaddressdialog.h
EditAddressDialog::address
QString address
Definition: editaddressdialog.h:55
AddressTableModel::getEditStatus
EditStatus getEditStatus() const
Definition: addresstablemodel.h:103
EditAddressDialog::mode
Mode mode
Definition: editaddressdialog.h:52
EditAddressDialog::accept
void accept() override
Definition: editaddressdialog.cpp:85
AddressTableModel::WALLET_UNLOCK_FAILURE
@ WALLET_UNLOCK_FAILURE
Wallet could not be unlocked to create new receiving address.
Definition: addresstablemodel.h:54
Ui
Definition: addressbookpage.h:14
EditAddressDialog::ui
Ui::EditAddressDialog * ui
Definition: editaddressdialog.h:50
EditAddressDialog::getDuplicateAddressWarning
QString getDuplicateAddressWarning() const
Return a descriptive string when adding an already-existing address fails.
Definition: editaddressdialog.cpp:126
EditAddressDialog::Mode
Mode
Definition: editaddressdialog.h:27
AddressTableModel::INVALID_ADDRESS
@ INVALID_ADDRESS
Unparseable address.
Definition: addresstablemodel.h:50
AddressTableModel::OK
@ OK
Everything ok.
Definition: addresstablemodel.h:46
EditAddressDialog::getAddress
QString getAddress() const
Definition: editaddressdialog.cpp:145
AddressTableModel::NO_CHANGES
@ NO_CHANGES
No changes were made during edit operation.
Definition: addresstablemodel.h:48
AddressTableModel::Send
static const QString Send
Specifies send address.
Definition: addresstablemodel.h:60
GUIUtil::handleCloseWindowShortcut
void handleCloseWindowShortcut(QWidget *w)
Definition: guiutil.cpp:396
AddressTableModel::GetDefaultAddressType
OutputType GetDefaultAddressType() const
Definition: addresstablemodel.cpp:421
GUIUtil::setupAddressWidget
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:119
AddressTableModel::purposeForAddress
QString purposeForAddress(const QString &address) const
Look up purpose for address in address book, if not found return empty string.
Definition: addresstablemodel.cpp:394
AddressTableModel::DUPLICATE_ADDRESS
@ DUPLICATE_ADDRESS
Address already in address book.
Definition: addresstablemodel.h:52
addresstablemodel.h
AddressTableModel::Address
@ Address
Bitcoin address.
Definition: addresstablemodel.h:35