BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
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(0),
19  mode(_mode),
20  model(0)
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 }
47 
49 {
50  delete ui;
51 }
52 
54 {
55  this->model = _model;
56  if(!_model)
57  return;
58 
59  mapper->setModel(_model);
60  mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
61  mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
62 }
63 
65 {
66  mapper->setCurrentIndex(row);
67 }
68 
70 {
71  if(!model)
72  return false;
73 
74  switch(mode)
75  {
76  case NewSendingAddress:
77  address = model->addRow(
79  ui->labelEdit->text(),
80  ui->addressEdit->text(),
82  break;
84  case EditSendingAddress:
85  if(mapper->submit())
86  {
87  address = ui->addressEdit->text();
88  }
89  break;
90  }
91  return !address.isEmpty();
92 }
93 
95 {
96  if(!model)
97  return;
98 
99  if(!saveCurrentRow())
100  {
101  switch(model->getEditStatus())
102  {
104  // Failed with unknown reason. Just reject.
105  break;
107  // No changes were made during edit operation. Just reject.
108  break;
110  QMessageBox::warning(this, windowTitle(),
111  tr("The entered address \"%1\" is not a valid BSHA3 address.").arg(ui->addressEdit->text()),
112  QMessageBox::Ok, QMessageBox::Ok);
113  break;
115  QMessageBox::warning(this, windowTitle(),
117  QMessageBox::Ok, QMessageBox::Ok);
118  break;
120  QMessageBox::critical(this, windowTitle(),
121  tr("Could not unlock wallet."),
122  QMessageBox::Ok, QMessageBox::Ok);
123  break;
125  QMessageBox::critical(this, windowTitle(),
126  tr("New key generation failed."),
127  QMessageBox::Ok, QMessageBox::Ok);
128  break;
129 
130  }
131  return;
132  }
133  QDialog::accept();
134 }
135 
137 {
138  QString dup_address = ui->addressEdit->text();
139  QString existing_label = model->labelForAddress(dup_address);
140  QString existing_purpose = model->purposeForAddress(dup_address);
141 
142  if (existing_purpose == "receive" &&
144  return tr(
145  "Address \"%1\" already exists as a receiving address with label "
146  "\"%2\" and so cannot be added as a sending address."
147  ).arg(dup_address).arg(existing_label);
148  }
149  return tr(
150  "The entered address \"%1\" is already in the address book with "
151  "label \"%2\"."
152  ).arg(dup_address).arg(existing_label);
153 }
154 
156 {
157  return address;
158 }
159 
160 void EditAddressDialog::setAddress(const QString &_address)
161 {
162  this->address = _address;
163  ui->addressEdit->setText(_address);
164 }
Generating a new public key for a receiving address failed.
EditAddressDialog(Mode mode, QWidget *parent=0)
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:104
Wallet could not be unlocked to create new receiving address.
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 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.