Browse Source

Merge pull request #2157 from Diapolo/Qt_addrlist

Bitcoin-Qt: fix known addressbook bugs
0.8
Wladimir J. van der Laan 12 years ago
parent
commit
bd85cf3df7
  1. 28
      src/qt/addresstablemodel.cpp
  2. 3
      src/qt/addresstablemodel.h
  3. 30
      src/qt/editaddressdialog.cpp
  4. 6
      src/qt/editaddressdialog.h

28
src/qt/addresstablemodel.cpp

@ -69,6 +69,8 @@ public: @@ -69,6 +69,8 @@ public:
QString::fromStdString(address.ToString())));
}
}
// qLowerBound() and qUpperBound() require our cachedAddressTable list to be sorted in asc order
qSort(cachedAddressTable.begin(), cachedAddressTable.end(), AddressTableEntryLessThan());
}
void updateEntry(const QString &address, const QString &label, bool isMine, int status)
@ -221,18 +223,36 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu @@ -221,18 +223,36 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
switch(index.column())
{
case Label:
// Do nothing, if old label == new label
if(rec->label == value.toString())
{
editStatus = NO_CHANGES;
return false;
}
wallet->SetAddressBookName(CBitcoinAddress(rec->address.toStdString()).Get(), value.toString().toStdString());
rec->label = value.toString();
break;
case Address:
// Do nothing, if old address == new address
if(CBitcoinAddress(rec->address.toStdString()) == CBitcoinAddress(value.toString().toStdString()))
{
editStatus = NO_CHANGES;
return false;
}
// Refuse to set invalid address, set error status and return false
if(!walletModel->validateAddress(value.toString()))
else if(!walletModel->validateAddress(value.toString()))
{
editStatus = INVALID_ADDRESS;
return false;
}
// Check for duplicate addresses to prevent accidental deletion of addresses, if you try
// to paste an existing address over another address (with a different label)
else if(wallet->mapAddressBook.count(CBitcoinAddress(value.toString().toStdString()).Get()))
{
editStatus = DUPLICATE_ADDRESS;
return false;
}
// Double-check that we're not overwriting a receiving address
if(rec->type == AddressTableEntry::Sending)
else if(rec->type == AddressTableEntry::Sending)
{
{
LOCK(wallet->cs_wallet);
@ -244,7 +264,6 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu @@ -244,7 +264,6 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
}
break;
}
return true;
}
return false;
@ -345,6 +364,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con @@ -345,6 +364,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
{
return QString();
}
// Add entry
{
LOCK(wallet->cs_wallet);

3
src/qt/addresstablemodel.h

@ -29,7 +29,8 @@ public: @@ -29,7 +29,8 @@ public:
/** Return status of edit/insert operation */
enum EditStatus {
OK,
OK, /**< Everything ok */
NO_CHANGES, /**< No changes were made during edit operation */
INVALID_ADDRESS, /**< Unparseable address */
DUPLICATE_ADDRESS, /**< Address already in address book */
WALLET_UNLOCK_FAILURE, /**< Wallet could not be unlocked to create new receiving address */

30
src/qt/editaddressdialog.cpp

@ -25,7 +25,7 @@ EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) : @@ -25,7 +25,7 @@ EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) :
break;
case EditReceivingAddress:
setWindowTitle(tr("Edit receiving address"));
ui->addressEdit->setDisabled(true);
ui->addressEdit->setEnabled(false);
break;
case EditSendingAddress:
setWindowTitle(tr("Edit sending address"));
@ -44,6 +44,9 @@ EditAddressDialog::~EditAddressDialog() @@ -44,6 +44,9 @@ EditAddressDialog::~EditAddressDialog()
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);
@ -58,6 +61,7 @@ bool EditAddressDialog::saveCurrentRow() @@ -58,6 +61,7 @@ bool EditAddressDialog::saveCurrentRow()
{
if(!model)
return false;
switch(mode)
{
case NewReceivingAddress:
@ -82,35 +86,39 @@ void EditAddressDialog::accept() @@ -82,35 +86,39 @@ void EditAddressDialog::accept()
{
if(!model)
return;
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);
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);
return;
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);
return;
break;
case AddressTableModel::KEY_GENERATION_FAILURE:
QMessageBox::critical(this, windowTitle(),
tr("New key generation failed."),
QMessageBox::Ok, QMessageBox::Ok);
return;
case AddressTableModel::OK:
// Failed with unknown reason. Just reject.
break;
}
}
return;
}
QDialog::accept();

6
src/qt/editaddressdialog.h

@ -32,10 +32,12 @@ public: @@ -32,10 +32,12 @@ public:
void setModel(AddressTableModel *model);
void loadRow(int row);
void accept();
QString getAddress() const;
void setAddress(const QString &address);
public slots:
void accept();
private:
bool saveCurrentRow();

Loading…
Cancel
Save