Fabcoin Core  0.16.2
P2P Digital Currency
editaddressdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2017 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 <editaddressdialog.h>
6 #include <ui_editaddressdialog.h>
7 
8 #include <addresstablemodel.h>
9 #include <guiutil.h>
10 #include <styleSheet.h>
11 
12 #include <QDataWidgetMapper>
13 #include <QMessageBox>
14 #include <QPushButton>
15 
16 EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
17  QDialog(parent),
18  ui(new Ui::EditAddressDialog),
19  mapper(0),
20  mode(_mode),
21  model(0)
22 {
23  ui->setupUi(this);
24 
25  SetObjectStyleSheet(ui->buttonBox->button(QDialogButtonBox::Cancel), StyleSheetNames::ButtonWhite);
26  SetObjectStyleSheet(ui->buttonBox->button(QDialogButtonBox::Ok), StyleSheetNames::ButtonBlue);
27 
29 
30  switch(mode)
31  {
33  setWindowTitle(tr("New receiving address"));
34  ui->addressEdit->setEnabled(false);
35  break;
36  case NewSendingAddress:
37  setWindowTitle(tr("New sending address"));
38  break;
40  setWindowTitle(tr("Edit receiving address"));
41  ui->addressEdit->setEnabled(false);
42  break;
43  case EditSendingAddress:
44  setWindowTitle(tr("Edit sending address"));
45  break;
46  }
47 
48  mapper = new QDataWidgetMapper(this);
49  mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
50 }
51 
53 {
54  delete ui;
55 }
56 
58 {
59  this->model = _model;
60  if(!_model)
61  return;
62 
63  mapper->setModel(_model);
66 }
67 
69 {
70  mapper->setCurrentIndex(row);
71 }
72 
74 {
75  if(!model)
76  return false;
77 
78  switch(mode)
79  {
81  case NewSendingAddress:
82  address = model->addRow(
84  ui->labelEdit->text(),
85  ui->addressEdit->text());
86  break;
88  case EditSendingAddress:
89  if(mapper->submit())
90  {
91  address = ui->addressEdit->text();
92  }
93  break;
94  }
95  return !address.isEmpty();
96 }
97 
99 {
100  if(!model)
101  return;
102 
103  if(!saveCurrentRow())
104  {
105  switch(model->getEditStatus())
106  {
108  // Failed with unknown reason. Just reject.
109  break;
111  // No changes were made during edit operation. Just reject.
112  break;
114  QMessageBox::warning(this, windowTitle(),
115  tr("The entered address \"%1\" is not a valid Fabcoin address.").arg(ui->addressEdit->text()),
116  QMessageBox::Ok, QMessageBox::Ok);
117  break;
119  QMessageBox::warning(this, windowTitle(),
120  tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
121  QMessageBox::Ok, QMessageBox::Ok);
122  break;
124  QMessageBox::critical(this, windowTitle(),
125  tr("Could not unlock wallet."),
126  QMessageBox::Ok, QMessageBox::Ok);
127  break;
129  QMessageBox::critical(this, windowTitle(),
130  tr("New key generation failed."),
131  QMessageBox::Ok, QMessageBox::Ok);
132  break;
133 
134  }
135  return;
136  }
137  QDialog::accept();
138 }
139 
141 {
142  return address;
143 }
144 
145 void EditAddressDialog::setAddress(const QString &_address)
146 {
147  this->address = _address;
148  ui->addressEdit->setText(_address);
149 }
Generating a new public key for a receiving address failed.
QString getAddress() const
#define SetObjectStyleSheet(object, name)
Definition: styleSheet.h:10
QDialogButtonBox * buttonBox
Address already in address book.
evm_mode mode
Definition: SmartVM.cpp:47
EditAddressDialog(Mode mode, QWidget *parent)
static const QString Send
Specifies send address.
void setModel(AddressTableModel *model)
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:122
Wallet could not be unlocked to create new receiving address.
QDataWidgetMapper * mapper
QValidatedLineEdit * addressEdit
Qt model of the address book in the core.
AddressTableModel * model
EditStatus getEditStatus() const
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.
void setEnabled(bool enabled)
void setupUi(QDialog *EditAddressDialog)
No changes were made during edit operation.
Ui::EditAddressDialog * ui
User specified label.