Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

editaddressdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin Core developers
2 // Copyright (c) 2014-2019 The Dash Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <qt/editaddressdialog.h>
7 #include <qt/forms/ui_editaddressdialog.h>
8 
9 #include <qt/addresstablemodel.h>
10 #include <qt/guiutil.h>
11 
12 #include <QDataWidgetMapper>
13 #include <QMessageBox>
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 
25 
26  GUIUtil::setupAddressWidget(ui->addressEdit, this);
27 
28  switch(mode)
29  {
31  setWindowTitle(tr("New receiving address"));
32  ui->addressEdit->setEnabled(false);
33  break;
34  case NewSendingAddress:
35  setWindowTitle(tr("New sending address"));
36  break;
38  setWindowTitle(tr("Edit receiving address"));
39  ui->addressEdit->setEnabled(false);
40  break;
41  case EditSendingAddress:
42  setWindowTitle(tr("Edit sending address"));
43  break;
44  }
45 
46  mapper = new QDataWidgetMapper(this);
47  mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
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  {
79  case NewSendingAddress:
80  address = model->addRow(
82  ui->labelEdit->text(),
83  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 Dash address.").arg(ui->addressEdit->text()),
114  QMessageBox::Ok, QMessageBox::Ok);
115  break;
117  QMessageBox::warning(this, windowTitle(),
118  tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
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  return address;
141 }
142 
143 void EditAddressDialog::setAddress(const QString &_address)
144 {
145  this->address = _address;
146  ui->addressEdit->setText(_address);
147 }
Generating a new public key for a receiving address failed.
Address already in address book.
EditAddressDialog(Mode mode, QWidget *parent)
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent, bool fAllowURI)
Definition: guiutil.cpp:286
static const QString Send
Specifies send address.
void setModel(AddressTableModel *model)
Wallet could not be unlocked to create new receiving address.
QDataWidgetMapper * mapper
Qt model of the address book in the core.
AddressTableModel * model
void disableMacFocusRect(const QWidget *w)
Disable the OS default focus rect for macOS because we have custom focus rects set in the css files...
Definition: guiutil.cpp:1789
QString addRow(const QString &type, const QString &label, const QString &address)
void setAddress(const QString &address)
static const QString Receive
Specifies receive 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.
Released under the MIT license