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.
5 #include <qt/editaddressdialog.h>
6 #include <qt/forms/ui_editaddressdialog.h>
8 #include <qt/addresstablemodel.h>
9 #include <qt/guiutil.h>
11 #include <QDataWidgetMapper>
12 #include <QMessageBox>
14 EditAddressDialog::EditAddressDialog(Mode _mode
, QWidget
*parent
) :
16 ui(new Ui::EditAddressDialog
),
23 GUIUtil::setupAddressWidget(ui
->addressEdit
, this);
27 case NewReceivingAddress
:
28 setWindowTitle(tr("New receiving address"));
29 ui
->addressEdit
->setEnabled(false);
31 case NewSendingAddress
:
32 setWindowTitle(tr("New sending address"));
34 case EditReceivingAddress
:
35 setWindowTitle(tr("Edit receiving address"));
36 ui
->addressEdit
->setEnabled(false);
38 case EditSendingAddress
:
39 setWindowTitle(tr("Edit sending address"));
43 mapper
= new QDataWidgetMapper(this);
44 mapper
->setSubmitPolicy(QDataWidgetMapper::ManualSubmit
);
47 EditAddressDialog::~EditAddressDialog()
52 void EditAddressDialog::setModel(AddressTableModel
*_model
)
58 mapper
->setModel(_model
);
59 mapper
->addMapping(ui
->labelEdit
, AddressTableModel::Label
);
60 mapper
->addMapping(ui
->addressEdit
, AddressTableModel::Address
);
63 void EditAddressDialog::loadRow(int row
)
65 mapper
->setCurrentIndex(row
);
68 bool EditAddressDialog::saveCurrentRow()
75 case NewReceivingAddress
:
76 case NewSendingAddress
:
77 address
= model
->addRow(
78 mode
== NewSendingAddress
? AddressTableModel::Send
: AddressTableModel::Receive
,
79 ui
->labelEdit
->text(),
80 ui
->addressEdit
->text());
82 case EditReceivingAddress
:
83 case EditSendingAddress
:
86 address
= ui
->addressEdit
->text();
90 return !address
.isEmpty();
93 void EditAddressDialog::accept()
100 switch(model
->getEditStatus())
102 case AddressTableModel::OK
:
103 // Failed with unknown reason. Just reject.
105 case AddressTableModel::NO_CHANGES
:
106 // No changes were made during edit operation. Just reject.
108 case AddressTableModel::INVALID_ADDRESS
:
109 QMessageBox::warning(this, windowTitle(),
110 tr("The entered address \"%1\" is not a valid Bitcoin address.").arg(ui
->addressEdit
->text()),
111 QMessageBox::Ok
, QMessageBox::Ok
);
113 case AddressTableModel::DUPLICATE_ADDRESS
:
114 QMessageBox::warning(this, windowTitle(),
115 tr("The entered address \"%1\" is already in the address book.").arg(ui
->addressEdit
->text()),
116 QMessageBox::Ok
, QMessageBox::Ok
);
118 case AddressTableModel::WALLET_UNLOCK_FAILURE
:
119 QMessageBox::critical(this, windowTitle(),
120 tr("Could not unlock wallet."),
121 QMessageBox::Ok
, QMessageBox::Ok
);
123 case AddressTableModel::KEY_GENERATION_FAILURE
:
124 QMessageBox::critical(this, windowTitle(),
125 tr("New key generation failed."),
126 QMessageBox::Ok
, QMessageBox::Ok
);
135 QString
EditAddressDialog::getAddress() const
140 void EditAddressDialog::setAddress(const QString
&_address
)
142 this->address
= _address
;
143 ui
->addressEdit
->setText(_address
);