Raven Core  3.0.0
P2P Digital Currency
editaddressdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven 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 "editaddressdialog.h"
7 #include "ui_editaddressdialog.h"
8 
9 #include "addresstablemodel.h"
10 #include "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 
24  GUIUtil::setupAddressWidget(ui->addressEdit, this);
25 
26  switch(mode)
27  {
29  setWindowTitle(tr("New receiving address"));
30  ui->addressEdit->setEnabled(false);
31  break;
32  case NewSendingAddress:
33  setWindowTitle(tr("New sending address"));
34  break;
36  setWindowTitle(tr("Edit receiving address"));
37  ui->addressEdit->setEnabled(false);
38  break;
39  case EditSendingAddress:
40  setWindowTitle(tr("Edit sending address"));
41  break;
42  }
43 
44  mapper = new QDataWidgetMapper(this);
45  mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
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  {
77  case NewSendingAddress:
78  address = model->addRow(
80  ui->labelEdit->text(),
81  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 Raven address.").arg(ui->addressEdit->text()),
112  QMessageBox::Ok, QMessageBox::Ok);
113  break;
115  QMessageBox::warning(this, windowTitle(),
116  tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
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  return address;
139 }
140 
141 void EditAddressDialog::setAddress(const QString &_address)
142 {
143  this->address = _address;
144  ui->addressEdit->setText(_address);
145 }
Generating a new public key for a receiving address failed.
Address already in address book.
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:201
Wallet could not be unlocked to create new receiving address.
QDataWidgetMapper * mapper
Qt model of the address book in the core.
AddressTableModel * model
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.