You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.0 KiB
78 lines
2.0 KiB
#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->setReadOnly(true); |
|
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; |
|
mapper->setModel(model); |
|
mapper->addMapping(ui->labelEdit, AddressTableModel::Label); |
|
mapper->addMapping(ui->addressEdit, AddressTableModel::Address); |
|
} |
|
|
|
void EditAddressDialog::loadRow(int row) |
|
{ |
|
mapper->setCurrentIndex(row); |
|
} |
|
|
|
void EditAddressDialog::saveCurrentRow() |
|
{ |
|
switch(mode) |
|
{ |
|
case NewReceivingAddress: |
|
case NewSendingAddress: |
|
if(!model->addRow( |
|
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive, |
|
ui->labelEdit->text(), |
|
ui->addressEdit->text())) |
|
{ |
|
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: |
|
mapper->submit(); |
|
break; |
|
} |
|
}
|
|
|