Files
thehub/hub-qt/editaddressdialog.cpp
T

159 lines
4.4 KiB
C++
Raw Permalink Normal View History

2017-11-09 19:34:51 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2011-2013 The Bitcoin Core developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2013-11-04 16:20:43 +01:00
#include "editaddressdialog.h"
#include "ui_editaddressdialog.h"
2013-01-23 21:51:02 +01:00
#include "addresstablemodel.h"
#include "guiutil.h"
#include <QDataWidgetMapper>
2011-06-03 15:16:11 +02:00
#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"));
2013-01-08 08:17:58 +01:00
ui->addressEdit->setEnabled(false);
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);
}
EditAddressDialog::~EditAddressDialog()
{
delete ui;
}
void EditAddressDialog::setModel(AddressTableModel *model)
{
2011-06-03 15:16:11 +02:00
this->model = model;
2013-01-08 08:17:58 +01:00
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);
}
2011-06-03 15:16:11 +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;
2013-01-08 08:17:58 +01:00
2011-06-03 15:16:11 +02:00
switch(mode)
{
case NewReceivingAddress:
case NewSendingAddress:
address = model->addRow(
2011-06-03 15:16:11 +02:00
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
ui->labelEdit->text(),
ui->addressEdit->text());
2011-06-03 15:16:11 +02:00
break;
case EditReceivingAddress:
case EditSendingAddress:
if(mapper->submit())
{
address = ui->addressEdit->text();
}
2011-06-03 15:16:11 +02:00
break;
}
return !address.isEmpty();
2011-06-03 15:16:11 +02:00
}
void EditAddressDialog::accept()
{
2011-11-08 21:18:36 +01:00
if(!model)
return;
2013-01-08 08:17:58 +01:00
if(!saveCurrentRow())
{
2011-07-16 19:01:05 +02:00
switch(model->getEditStatus())
{
2013-01-08 08:17:58 +01:00
case AddressTableModel::OK:
// Failed with unknown reason. Just reject.
break;
case AddressTableModel::NO_CHANGES:
// No changes were made during edit operation. Just reject.
2011-07-16 19:01:05 +02:00
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);
2013-01-08 08:17:58 +01:00
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);
2013-01-08 08:17:58 +01:00
break;
case AddressTableModel::KEY_GENERATION_FAILURE:
QMessageBox::critical(this, windowTitle(),
tr("New key generation failed."),
QMessageBox::Ok, QMessageBox::Ok);
break;
2011-07-16 19:01:05 +02:00
2013-01-08 08:17:58 +01:00
}
return;
}
QDialog::accept();
}
QString EditAddressDialog::getAddress() const
{
return address;
}
void EditAddressDialog::setAddress(const QString &address)
{
this->address = address;
ui->addressEdit->setText(address);
}