2011-05-13 15:58:27 +02:00
|
|
|
#include "editaddressdialog.h"
|
|
|
|
#include "ui_editaddressdialog.h"
|
2011-06-02 17:48:45 +02:00
|
|
|
#include "addresstablemodel.h"
|
2011-06-02 15:57:23 +02:00
|
|
|
#include "guiutil.h"
|
2011-05-13 15:58:27 +02:00
|
|
|
|
2011-06-02 17:48:45 +02:00
|
|
|
#include <QDataWidgetMapper>
|
2011-06-03 15:16:11 +02:00
|
|
|
#include <QMessageBox>
|
2011-06-02 17:48:45 +02:00
|
|
|
|
2011-06-02 15:57:23 +02:00
|
|
|
EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) :
|
2011-05-13 15:58:27 +02:00
|
|
|
QDialog(parent),
|
2011-06-03 15:16:11 +02:00
|
|
|
ui(new Ui::EditAddressDialog), mapper(0), mode(mode), model(0)
|
2011-05-13 15:58:27 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2011-06-02 15:57:23 +02:00
|
|
|
|
|
|
|
GUIUtil::setupAddressWidget(ui->addressEdit, this);
|
2011-06-02 17:48:45 +02:00
|
|
|
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case NewReceivingAddress:
|
|
|
|
setWindowTitle(tr("New receiving address"));
|
|
|
|
ui->addressEdit->setEnabled(false);
|
|
|
|
break;
|
|
|
|
case NewSendingAddress:
|
|
|
|
setWindowTitle(tr("New sending address"));
|
|
|
|
break;
|
|
|
|
case EditReceivingAddress:
|
|
|
|
setWindowTitle(tr("Edit receiving address"));
|
2011-07-02 13:45:59 +02:00
|
|
|
ui->addressEdit->setDisabled(true);
|
2011-06-02 17:48:45 +02:00
|
|
|
break;
|
|
|
|
case EditSendingAddress:
|
|
|
|
setWindowTitle(tr("Edit sending address"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mapper = new QDataWidgetMapper(this);
|
2011-06-03 15:16:11 +02:00
|
|
|
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
2011-05-13 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EditAddressDialog::~EditAddressDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2011-06-02 17:48:45 +02:00
|
|
|
|
|
|
|
void EditAddressDialog::setModel(AddressTableModel *model)
|
|
|
|
{
|
2011-06-03 15:16:11 +02:00
|
|
|
this->model = model;
|
2011-06-02 17:48:45 +02:00
|
|
|
mapper->setModel(model);
|
|
|
|
mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
|
|
|
|
mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditAddressDialog::loadRow(int row)
|
|
|
|
{
|
|
|
|
mapper->setCurrentIndex(row);
|
|
|
|
}
|
2011-06-03 15:16:11 +02:00
|
|
|
|
2011-08-04 21:31:47 +02:00
|
|
|
bool EditAddressDialog::saveCurrentRow()
|
2011-06-03 15:16:11 +02:00
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!model)
|
|
|
|
return false;
|
2011-06-03 15:16:11 +02:00
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case NewReceivingAddress:
|
|
|
|
case NewSendingAddress:
|
2011-06-03 21:03:20 +02:00
|
|
|
address = model->addRow(
|
2011-06-03 15:16:11 +02:00
|
|
|
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
|
|
|
|
ui->labelEdit->text(),
|
2011-07-02 13:45:59 +02:00
|
|
|
ui->addressEdit->text());
|
2011-06-03 15:16:11 +02:00
|
|
|
break;
|
|
|
|
case EditReceivingAddress:
|
|
|
|
case EditSendingAddress:
|
2011-06-03 21:03:20 +02:00
|
|
|
if(mapper->submit())
|
|
|
|
{
|
|
|
|
address = ui->addressEdit->text();
|
|
|
|
}
|
2011-06-03 15:16:11 +02:00
|
|
|
break;
|
|
|
|
}
|
2011-08-04 21:31:47 +02:00
|
|
|
return !address.isEmpty();
|
2011-06-03 15:16:11 +02:00
|
|
|
}
|
2011-07-02 15:09:53 +02:00
|
|
|
|
|
|
|
void EditAddressDialog::accept()
|
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!model)
|
|
|
|
return;
|
2011-08-04 21:31:47 +02:00
|
|
|
if(!saveCurrentRow())
|
2011-07-02 15:09:53 +02:00
|
|
|
{
|
2011-07-16 19:01:05 +02:00
|
|
|
switch(model->getEditStatus())
|
2011-07-02 15:09:53 +02:00
|
|
|
{
|
2011-07-16 19:01:05 +02:00
|
|
|
case AddressTableModel::DUPLICATE_ADDRESS:
|
|
|
|
QMessageBox::warning(this, windowTitle(),
|
|
|
|
tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
break;
|
|
|
|
case AddressTableModel::INVALID_ADDRESS:
|
2011-07-02 15:09:53 +02:00
|
|
|
QMessageBox::warning(this, windowTitle(),
|
2012-05-13 16:09:14 +02:00
|
|
|
tr("The entered address \"%1\" is not a valid Bitcoin address.").arg(ui->addressEdit->text()),
|
2011-07-02 15:09:53 +02:00
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
return;
|
2011-08-24 22:07:26 +02:00
|
|
|
case AddressTableModel::WALLET_UNLOCK_FAILURE:
|
|
|
|
QMessageBox::critical(this, windowTitle(),
|
|
|
|
tr("Could not unlock wallet."),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
return;
|
2011-09-02 18:02:22 +02:00
|
|
|
case AddressTableModel::KEY_GENERATION_FAILURE:
|
|
|
|
QMessageBox::critical(this, windowTitle(),
|
|
|
|
tr("New key generation failed."),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
return;
|
2012-04-15 12:42:52 +02:00
|
|
|
case AddressTableModel::OK:
|
|
|
|
// Failed with unknown reason. Just reject.
|
|
|
|
break;
|
2011-07-02 15:09:53 +02:00
|
|
|
}
|
2011-07-16 19:01:05 +02:00
|
|
|
|
2011-07-02 15:09:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
2011-08-04 21:31:47 +02:00
|
|
|
QString EditAddressDialog::getAddress() const
|
|
|
|
{
|
|
|
|
return address;
|
|
|
|
}
|
2011-11-08 19:54:16 +01:00
|
|
|
|
|
|
|
void EditAddressDialog::setAddress(const QString &address)
|
|
|
|
{
|
|
|
|
this->address = address;
|
|
|
|
ui->addressEdit->setText(address);
|
|
|
|
}
|