aboutsummaryrefslogtreecommitdiff
path: root/src/qt/editaddressdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt/editaddressdialog.cpp')
-rw-r--r--src/qt/editaddressdialog.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp
new file mode 100644
index 0000000000..2b3d9bf0f0
--- /dev/null
+++ b/src/qt/editaddressdialog.cpp
@@ -0,0 +1,105 @@
+#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->setDisabled(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);
+}
+
+bool EditAddressDialog::saveCurrentRow()
+{
+ 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(!saveCurrentRow())
+ {
+ switch(model->getEditStatus())
+ {
+ 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:
+ QMessageBox::warning(this, windowTitle(),
+ tr("The entered address \"%1\" is not a valid bitcoin address.").arg(ui->addressEdit->text()),
+ QMessageBox::Ok, QMessageBox::Ok);
+ return;
+ }
+
+ return;
+ }
+ QDialog::accept();
+}
+
+QString EditAddressDialog::getAddress() const
+{
+ return address;
+}