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"));
|
|
|
|
ui->addressEdit->setReadOnly(true);
|
|
|
|
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-06-03 21:03:20 +02:00
|
|
|
QString EditAddressDialog::saveCurrentRow()
|
2011-06-03 15:16:11 +02:00
|
|
|
{
|
2011-06-03 21:03:20 +02:00
|
|
|
QString address;
|
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-06-03 21:03:20 +02:00
|
|
|
ui->addressEdit->text());
|
|
|
|
if(address.isEmpty())
|
2011-06-03 15:16:11 +02:00
|
|
|
{
|
|
|
|
QMessageBox::warning(this, windowTitle(),
|
|
|
|
tr("The address %1 is already in the address book.").arg(ui->addressEdit->text()),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
}
|
|
|
|
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-06-03 21:03:20 +02:00
|
|
|
return address;
|
2011-06-03 15:16:11 +02:00
|
|
|
}
|