e6d2300562
- add qSort() for cachedAddressTable, as qLowerBound() and qUpperBound()
require the list to be in ascending order (see
http://harmattan-dev.nokia.com/docs/library/html/qt4/qtalgorithms.html#qLowerBound)
- add a new check in AddressTableModel::setData() to just return, when no
changes were made to a label or an address (prevents entry duplication
issue)
- remove "rec->label = value.toString();" from
AddressTableModel::setData() as the label gets updated by
AddressTablePriv::updateEntry() anyway (seems @sipa added this line via
1025440184 (L6R225)
)
- add another new check in AddressTableModel::setData() to just return, if
a duplicate address was found (prevents address overwrite)
- add a new check to EditAddressDialog::setModel() to prevent setting an
invalid model
- re-work the switch-case statement in AddressTableModel::accept() to
always break (as return get's called anyway) and order the list to match
the enum definition
- make accept() in editaddressdialog.h a public slot, which it should be
- misc small coding style changes
136 lines
3.6 KiB
C++
136 lines
3.6 KiB
C++
#include "editaddressdialog.h"
|
|
#include "ui_editaddressdialog.h"
|
|
#include "addresstablemodel.h"
|
|
#include "guiutil.h"
|
|
|
|
#include <QDataWidgetMapper>
|
|
#include <QMessageBox>
|
|
|
|
EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::EditAddressDialog), mapper(0), mode(mode), model(0)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
GUIUtil::setupAddressWidget(ui->addressEdit, this);
|
|
|
|
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"));
|
|
ui->addressEdit->setEnabled(false);
|
|
break;
|
|
case EditSendingAddress:
|
|
setWindowTitle(tr("Edit sending address"));
|
|
break;
|
|
}
|
|
|
|
mapper = new QDataWidgetMapper(this);
|
|
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
|
}
|
|
|
|
EditAddressDialog::~EditAddressDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void EditAddressDialog::setModel(AddressTableModel *model)
|
|
{
|
|
this->model = model;
|
|
if(!model)
|
|
return;
|
|
|
|
mapper->setModel(model);
|
|
mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
|
|
mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
|
|
}
|
|
|
|
void EditAddressDialog::loadRow(int row)
|
|
{
|
|
mapper->setCurrentIndex(row);
|
|
}
|
|
|
|
bool EditAddressDialog::saveCurrentRow()
|
|
{
|
|
if(!model)
|
|
return false;
|
|
|
|
switch(mode)
|
|
{
|
|
case NewReceivingAddress:
|
|
case NewSendingAddress:
|
|
address = model->addRow(
|
|
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
|
|
ui->labelEdit->text(),
|
|
ui->addressEdit->text());
|
|
break;
|
|
case EditReceivingAddress:
|
|
case EditSendingAddress:
|
|
if(mapper->submit())
|
|
{
|
|
address = ui->addressEdit->text();
|
|
}
|
|
break;
|
|
}
|
|
return !address.isEmpty();
|
|
}
|
|
|
|
void EditAddressDialog::accept()
|
|
{
|
|
if(!model)
|
|
return;
|
|
|
|
if(!saveCurrentRow())
|
|
{
|
|
switch(model->getEditStatus())
|
|
{
|
|
case AddressTableModel::OK:
|
|
// Failed with unknown reason. Just reject.
|
|
break;
|
|
case AddressTableModel::NO_CHANGES:
|
|
// No changes were made during edit operation. Just reject.
|
|
break;
|
|
case AddressTableModel::INVALID_ADDRESS:
|
|
QMessageBox::warning(this, windowTitle(),
|
|
tr("The entered address \"%1\" is not a valid Bitcoin address.").arg(ui->addressEdit->text()),
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
break;
|
|
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::WALLET_UNLOCK_FAILURE:
|
|
QMessageBox::critical(this, windowTitle(),
|
|
tr("Could not unlock wallet."),
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
break;
|
|
case AddressTableModel::KEY_GENERATION_FAILURE:
|
|
QMessageBox::critical(this, windowTitle(),
|
|
tr("New key generation failed."),
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
break;
|
|
|
|
}
|
|
return;
|
|
}
|
|
QDialog::accept();
|
|
}
|
|
|
|
QString EditAddressDialog::getAddress() const
|
|
{
|
|
return address;
|
|
}
|
|
|
|
void EditAddressDialog::setAddress(const QString &address)
|
|
{
|
|
this->address = address;
|
|
ui->addressEdit->setText(address);
|
|
}
|