2011-05-12 14:49:42 +02:00
|
|
|
#include "addresstablemodel.h"
|
2013-01-23 21:51:02 +01:00
|
|
|
|
2011-06-01 20:08:21 +02:00
|
|
|
#include "guiutil.h"
|
2011-07-16 19:01:05 +02:00
|
|
|
#include "walletmodel.h"
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2012-04-15 22:10:54 +02:00
|
|
|
#include "wallet.h"
|
2012-05-14 23:44:52 +02:00
|
|
|
#include "base58.h"
|
2011-05-09 20:44:46 +02:00
|
|
|
|
2011-06-02 15:57:23 +02:00
|
|
|
#include <QFont>
|
|
|
|
|
2011-05-13 15:58:27 +02:00
|
|
|
const QString AddressTableModel::Send = "S";
|
|
|
|
const QString AddressTableModel::Receive = "R";
|
|
|
|
|
2011-06-01 15:50:09 +02:00
|
|
|
struct AddressTableEntry
|
|
|
|
{
|
|
|
|
enum Type {
|
|
|
|
Sending,
|
|
|
|
Receiving
|
|
|
|
};
|
2011-06-03 15:16:11 +02:00
|
|
|
|
2011-06-01 15:50:09 +02:00
|
|
|
Type type;
|
|
|
|
QString label;
|
|
|
|
QString address;
|
|
|
|
|
|
|
|
AddressTableEntry() {}
|
|
|
|
AddressTableEntry(Type type, const QString &label, const QString &address):
|
|
|
|
type(type), label(label), address(address) {}
|
|
|
|
};
|
|
|
|
|
2012-05-06 22:41:35 +02:00
|
|
|
struct AddressTableEntryLessThan
|
|
|
|
{
|
|
|
|
bool operator()(const AddressTableEntry &a, const AddressTableEntry &b) const
|
|
|
|
{
|
|
|
|
return a.address < b.address;
|
|
|
|
}
|
|
|
|
bool operator()(const AddressTableEntry &a, const QString &b) const
|
|
|
|
{
|
|
|
|
return a.address < b;
|
|
|
|
}
|
|
|
|
bool operator()(const QString &a, const AddressTableEntry &b) const
|
|
|
|
{
|
|
|
|
return a < b.address;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-06-18 11:53:25 +02:00
|
|
|
// Private implementation
|
2012-04-15 12:31:56 +02:00
|
|
|
class AddressTablePriv
|
2011-06-01 15:50:09 +02:00
|
|
|
{
|
2012-04-15 12:31:56 +02:00
|
|
|
public:
|
2011-06-26 19:23:24 +02:00
|
|
|
CWallet *wallet;
|
2011-06-01 15:50:09 +02:00
|
|
|
QList<AddressTableEntry> cachedAddressTable;
|
2012-05-06 22:41:35 +02:00
|
|
|
AddressTableModel *parent;
|
2011-06-01 15:50:09 +02:00
|
|
|
|
2012-05-06 22:41:35 +02:00
|
|
|
AddressTablePriv(CWallet *wallet, AddressTableModel *parent):
|
|
|
|
wallet(wallet), parent(parent) {}
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2011-06-01 15:50:09 +02:00
|
|
|
void refreshAddressTable()
|
|
|
|
{
|
|
|
|
cachedAddressTable.clear();
|
|
|
|
{
|
2012-04-06 18:39:12 +02:00
|
|
|
LOCK(wallet->cs_wallet);
|
2013-07-15 07:20:50 +02:00
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& item, wallet->mapAddressBook)
|
2011-06-01 15:50:09 +02:00
|
|
|
{
|
2011-07-26 15:38:31 +02:00
|
|
|
const CBitcoinAddress& address = item.first;
|
2013-07-22 08:50:39 +02:00
|
|
|
|
|
|
|
AddressTableEntry::Type addressType;
|
|
|
|
const std::string& strPurpose = item.second.purpose;
|
|
|
|
if (strPurpose == "send") addressType = AddressTableEntry::Sending;
|
|
|
|
else if (strPurpose == "receive") addressType = AddressTableEntry::Receiving;
|
|
|
|
else if (strPurpose == "unknown") {
|
|
|
|
bool fMine = IsMine(*wallet, address.Get());
|
|
|
|
addressType = (fMine ? AddressTableEntry::Receiving : AddressTableEntry::Sending);
|
|
|
|
}
|
|
|
|
else continue; // "refund" addresses aren't shown, and change addresses aren't in mapAddressBook at all.
|
|
|
|
|
2013-07-15 07:20:50 +02:00
|
|
|
const std::string& strName = item.second.name;
|
2013-07-22 08:50:39 +02:00
|
|
|
cachedAddressTable.append(AddressTableEntry(addressType,
|
2011-06-01 15:50:09 +02:00
|
|
|
QString::fromStdString(strName),
|
2011-07-26 15:38:31 +02:00
|
|
|
QString::fromStdString(address.ToString())));
|
2011-06-01 15:50:09 +02:00
|
|
|
}
|
|
|
|
}
|
2013-01-08 08:17:58 +01:00
|
|
|
// qLowerBound() and qUpperBound() require our cachedAddressTable list to be sorted in asc order
|
|
|
|
qSort(cachedAddressTable.begin(), cachedAddressTable.end(), AddressTableEntryLessThan());
|
2011-06-01 15:50:09 +02:00
|
|
|
}
|
|
|
|
|
2012-05-06 22:41:35 +02:00
|
|
|
void updateEntry(const QString &address, const QString &label, bool isMine, int status)
|
|
|
|
{
|
|
|
|
// Find address / label in model
|
|
|
|
QList<AddressTableEntry>::iterator lower = qLowerBound(
|
|
|
|
cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
|
|
|
|
QList<AddressTableEntry>::iterator upper = qUpperBound(
|
|
|
|
cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
|
|
|
|
int lowerIndex = (lower - cachedAddressTable.begin());
|
|
|
|
int upperIndex = (upper - cachedAddressTable.begin());
|
|
|
|
bool inModel = (lower != upper);
|
|
|
|
AddressTableEntry::Type newEntryType = isMine ? AddressTableEntry::Receiving : AddressTableEntry::Sending;
|
|
|
|
|
|
|
|
switch(status)
|
|
|
|
{
|
|
|
|
case CT_NEW:
|
|
|
|
if(inModel)
|
|
|
|
{
|
|
|
|
OutputDebugStringF("Warning: AddressTablePriv::updateEntry: Got CT_NOW, but entry is already in model\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
|
|
|
|
cachedAddressTable.insert(lowerIndex, AddressTableEntry(newEntryType, label, address));
|
|
|
|
parent->endInsertRows();
|
|
|
|
break;
|
|
|
|
case CT_UPDATED:
|
|
|
|
if(!inModel)
|
|
|
|
{
|
|
|
|
OutputDebugStringF("Warning: AddressTablePriv::updateEntry: Got CT_UPDATED, but entry is not in model\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lower->type = newEntryType;
|
|
|
|
lower->label = label;
|
|
|
|
parent->emitDataChanged(lowerIndex);
|
|
|
|
break;
|
|
|
|
case CT_DELETED:
|
|
|
|
if(!inModel)
|
|
|
|
{
|
|
|
|
OutputDebugStringF("Warning: AddressTablePriv::updateEntry: Got CT_DELETED, but entry is not in model\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
|
|
|
|
cachedAddressTable.erase(lower, upper);
|
|
|
|
parent->endRemoveRows();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-01 15:50:09 +02:00
|
|
|
int size()
|
|
|
|
{
|
|
|
|
return cachedAddressTable.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
AddressTableEntry *index(int idx)
|
|
|
|
{
|
|
|
|
if(idx >= 0 && idx < cachedAddressTable.size())
|
|
|
|
{
|
|
|
|
return &cachedAddressTable[idx];
|
2011-06-07 18:59:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-01 15:50:09 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-16 19:01:05 +02:00
|
|
|
AddressTableModel::AddressTableModel(CWallet *wallet, WalletModel *parent) :
|
|
|
|
QAbstractTableModel(parent),walletModel(parent),wallet(wallet),priv(0)
|
2011-05-09 20:44:46 +02:00
|
|
|
{
|
2011-06-01 15:50:09 +02:00
|
|
|
columns << tr("Label") << tr("Address");
|
2012-05-06 22:41:35 +02:00
|
|
|
priv = new AddressTablePriv(wallet, this);
|
2011-06-01 15:50:09 +02:00
|
|
|
priv->refreshAddressTable();
|
|
|
|
}
|
2011-05-13 15:58:27 +02:00
|
|
|
|
2011-06-01 15:50:09 +02:00
|
|
|
AddressTableModel::~AddressTableModel()
|
|
|
|
{
|
|
|
|
delete priv;
|
2011-05-13 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int AddressTableModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
2011-05-27 08:20:23 +02:00
|
|
|
Q_UNUSED(parent);
|
2011-06-01 15:50:09 +02:00
|
|
|
return priv->size();
|
2011-05-13 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int AddressTableModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
2011-06-01 15:50:09 +02:00
|
|
|
Q_UNUSED(parent);
|
|
|
|
return columns.length();
|
2011-05-13 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant AddressTableModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if(!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
2011-06-01 15:50:09 +02:00
|
|
|
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
|
|
|
|
|
2011-06-02 17:48:45 +02:00
|
|
|
if(role == Qt::DisplayRole || role == Qt::EditRole)
|
2011-05-13 15:58:27 +02:00
|
|
|
{
|
2011-06-01 15:50:09 +02:00
|
|
|
switch(index.column())
|
|
|
|
{
|
|
|
|
case Label:
|
2011-07-02 17:31:27 +02:00
|
|
|
if(rec->label.isEmpty() && role == Qt::DisplayRole)
|
2011-06-30 21:29:20 +02:00
|
|
|
{
|
|
|
|
return tr("(no label)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return rec->label;
|
|
|
|
}
|
2011-06-01 15:50:09 +02:00
|
|
|
case Address:
|
|
|
|
return rec->address;
|
|
|
|
}
|
2011-06-07 18:59:01 +02:00
|
|
|
}
|
|
|
|
else if (role == Qt::FontRole)
|
2011-06-01 20:08:21 +02:00
|
|
|
{
|
2011-06-21 19:54:09 +02:00
|
|
|
QFont font;
|
2011-06-01 20:08:21 +02:00
|
|
|
if(index.column() == Address)
|
|
|
|
{
|
2011-06-21 19:54:09 +02:00
|
|
|
font = GUIUtil::bitcoinAddressFont();
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
2011-06-07 18:59:01 +02:00
|
|
|
else if (role == TypeRole)
|
2011-05-13 15:58:27 +02:00
|
|
|
{
|
2011-06-01 15:50:09 +02:00
|
|
|
switch(rec->type)
|
2011-05-13 15:58:27 +02:00
|
|
|
{
|
2011-06-01 15:50:09 +02:00
|
|
|
case AddressTableEntry::Sending:
|
|
|
|
return Send;
|
|
|
|
case AddressTableEntry::Receiving:
|
|
|
|
return Receive;
|
|
|
|
default: break;
|
2011-05-13 15:58:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2013-01-08 08:17:58 +01:00
|
|
|
bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2011-06-02 17:48:45 +02:00
|
|
|
{
|
|
|
|
if(!index.isValid())
|
|
|
|
return false;
|
2011-06-03 15:16:11 +02:00
|
|
|
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
|
2013-07-22 08:50:39 +02:00
|
|
|
std::string strPurpose = (rec->type == AddressTableEntry::Sending ? "send" : "receive");
|
2011-07-16 19:01:05 +02:00
|
|
|
editStatus = OK;
|
|
|
|
|
2011-06-02 17:48:45 +02:00
|
|
|
if(role == Qt::EditRole)
|
|
|
|
{
|
|
|
|
switch(index.column())
|
|
|
|
{
|
|
|
|
case Label:
|
2013-01-08 08:17:58 +01:00
|
|
|
// Do nothing, if old label == new label
|
|
|
|
if(rec->label == value.toString())
|
|
|
|
{
|
|
|
|
editStatus = NO_CHANGES;
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-22 08:50:39 +02:00
|
|
|
wallet->SetAddressBook(CBitcoinAddress(rec->address.toStdString()).Get(), value.toString().toStdString(), strPurpose);
|
2011-06-02 17:48:45 +02:00
|
|
|
break;
|
|
|
|
case Address:
|
2013-01-08 08:17:58 +01:00
|
|
|
// Do nothing, if old address == new address
|
|
|
|
if(CBitcoinAddress(rec->address.toStdString()) == CBitcoinAddress(value.toString().toStdString()))
|
|
|
|
{
|
|
|
|
editStatus = NO_CHANGES;
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-08 17:38:17 +02:00
|
|
|
// Refuse to set invalid address, set error status and return false
|
2013-01-08 08:17:58 +01:00
|
|
|
else if(!walletModel->validateAddress(value.toString()))
|
2011-07-16 19:01:05 +02:00
|
|
|
{
|
|
|
|
editStatus = INVALID_ADDRESS;
|
2011-07-02 17:31:27 +02:00
|
|
|
return false;
|
2011-07-16 19:01:05 +02:00
|
|
|
}
|
2013-01-08 08:17:58 +01:00
|
|
|
// 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;
|
|
|
|
}
|
2011-08-08 17:38:17 +02:00
|
|
|
// Double-check that we're not overwriting a receiving address
|
2013-01-08 08:17:58 +01:00
|
|
|
else if(rec->type == AddressTableEntry::Sending)
|
2011-06-03 15:16:11 +02:00
|
|
|
{
|
2011-07-07 15:22:54 +02:00
|
|
|
{
|
2012-04-06 18:39:12 +02:00
|
|
|
LOCK(wallet->cs_wallet);
|
2011-07-07 15:22:54 +02:00
|
|
|
// Remove old entry
|
2013-07-22 08:50:39 +02:00
|
|
|
wallet->DelAddressBook(CBitcoinAddress(rec->address.toStdString()).Get());
|
2011-07-07 15:22:54 +02:00
|
|
|
// Add new entry with new address
|
2013-07-22 08:50:39 +02:00
|
|
|
wallet->SetAddressBook(CBitcoinAddress(value.toString().toStdString()).Get(), rec->label.toStdString(), strPurpose);
|
2011-07-07 15:22:54 +02:00
|
|
|
}
|
2011-06-03 15:16:11 +02:00
|
|
|
}
|
2011-06-02 17:48:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-13 15:58:27 +02:00
|
|
|
QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
2011-06-01 15:50:09 +02:00
|
|
|
if(orientation == Qt::Horizontal)
|
|
|
|
{
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
return columns[section];
|
|
|
|
}
|
|
|
|
}
|
2011-05-13 15:58:27 +02:00
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2013-01-08 08:17:58 +01:00
|
|
|
Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
|
2011-07-02 17:31:27 +02:00
|
|
|
{
|
|
|
|
if(!index.isValid())
|
|
|
|
return 0;
|
|
|
|
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
|
|
|
|
|
|
|
|
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
|
|
// Can edit address and label for sending addresses,
|
|
|
|
// and only label for receiving addresses.
|
|
|
|
if(rec->type == AddressTableEntry::Sending ||
|
|
|
|
(rec->type == AddressTableEntry::Receiving && index.column()==Label))
|
|
|
|
{
|
|
|
|
retval |= Qt::ItemIsEditable;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-01-08 08:17:58 +01:00
|
|
|
QModelIndex AddressTableModel::index(int row, int column, const QModelIndex &parent) const
|
2011-05-13 15:58:27 +02:00
|
|
|
{
|
2011-06-01 15:50:09 +02:00
|
|
|
Q_UNUSED(parent);
|
|
|
|
AddressTableEntry *data = priv->index(row);
|
|
|
|
if(data)
|
|
|
|
{
|
|
|
|
return createIndex(row, column, priv->index(row));
|
2011-06-07 18:59:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-01 15:50:09 +02:00
|
|
|
return QModelIndex();
|
|
|
|
}
|
2011-05-09 20:44:46 +02:00
|
|
|
}
|
2011-06-01 15:50:09 +02:00
|
|
|
|
2012-05-06 22:41:35 +02:00
|
|
|
void AddressTableModel::updateEntry(const QString &address, const QString &label, bool isMine, int status)
|
2011-06-01 20:08:21 +02:00
|
|
|
{
|
2011-08-08 17:38:17 +02:00
|
|
|
// Update address book model from Bitcoin core
|
2012-05-06 22:41:35 +02:00
|
|
|
priv->updateEntry(address, label, isMine, status);
|
2011-06-01 20:08:21 +02:00
|
|
|
}
|
2011-06-03 15:16:11 +02:00
|
|
|
|
2011-07-02 13:45:59 +02:00
|
|
|
QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address)
|
2011-06-03 15:16:11 +02:00
|
|
|
{
|
|
|
|
std::string strLabel = label.toStdString();
|
|
|
|
std::string strAddress = address.toStdString();
|
|
|
|
|
2011-07-16 19:01:05 +02:00
|
|
|
editStatus = OK;
|
|
|
|
|
2011-06-03 15:16:11 +02:00
|
|
|
if(type == Send)
|
|
|
|
{
|
2011-07-16 19:01:05 +02:00
|
|
|
if(!walletModel->validateAddress(address))
|
|
|
|
{
|
|
|
|
editStatus = INVALID_ADDRESS;
|
|
|
|
return QString();
|
|
|
|
}
|
2011-08-08 17:38:17 +02:00
|
|
|
// Check for duplicate addresses
|
2011-06-03 15:16:11 +02:00
|
|
|
{
|
2012-04-06 18:39:12 +02:00
|
|
|
LOCK(wallet->cs_wallet);
|
2012-05-14 23:44:52 +02:00
|
|
|
if(wallet->mapAddressBook.count(CBitcoinAddress(strAddress).Get()))
|
2011-06-03 15:16:11 +02:00
|
|
|
{
|
2011-07-16 19:01:05 +02:00
|
|
|
editStatus = DUPLICATE_ADDRESS;
|
2011-06-03 21:03:20 +02:00
|
|
|
return QString();
|
2011-06-03 15:16:11 +02:00
|
|
|
}
|
|
|
|
}
|
2011-06-07 18:59:01 +02:00
|
|
|
}
|
|
|
|
else if(type == Receive)
|
2011-06-03 15:16:11 +02:00
|
|
|
{
|
2011-07-26 15:38:31 +02:00
|
|
|
// Generate a new address to associate with given label
|
2012-05-14 19:07:52 +02:00
|
|
|
CPubKey newKey;
|
2013-08-23 21:54:50 +02:00
|
|
|
if(!wallet->GetKeyFromPool(newKey))
|
2011-09-02 18:02:22 +02:00
|
|
|
{
|
2013-08-16 06:53:21 +02:00
|
|
|
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
|
|
|
|
if(!ctx.isValid())
|
|
|
|
{
|
|
|
|
// Unlock wallet failed or was cancelled
|
|
|
|
editStatus = WALLET_UNLOCK_FAILURE;
|
|
|
|
return QString();
|
|
|
|
}
|
2013-08-23 21:54:50 +02:00
|
|
|
if(!wallet->GetKeyFromPool(newKey))
|
2013-08-16 06:53:21 +02:00
|
|
|
{
|
|
|
|
editStatus = KEY_GENERATION_FAILURE;
|
|
|
|
return QString();
|
|
|
|
}
|
2011-09-02 18:02:22 +02:00
|
|
|
}
|
2012-05-14 23:44:52 +02:00
|
|
|
strAddress = CBitcoinAddress(newKey.GetID()).ToString();
|
2011-06-07 18:59:01 +02:00
|
|
|
}
|
|
|
|
else
|
2011-06-03 15:16:11 +02:00
|
|
|
{
|
2011-06-03 21:03:20 +02:00
|
|
|
return QString();
|
2011-06-03 15:16:11 +02:00
|
|
|
}
|
2013-01-08 08:17:58 +01:00
|
|
|
|
2012-03-24 18:48:18 +01:00
|
|
|
// Add entry
|
2012-04-06 18:39:12 +02:00
|
|
|
{
|
|
|
|
LOCK(wallet->cs_wallet);
|
2013-07-22 08:50:39 +02:00
|
|
|
wallet->SetAddressBook(CBitcoinAddress(strAddress).Get(), strLabel,
|
|
|
|
(type == Send ? "send" : "receive"));
|
2012-04-06 18:39:12 +02:00
|
|
|
}
|
2011-06-03 21:03:20 +02:00
|
|
|
return QString::fromStdString(strAddress);
|
2011-06-03 15:16:11 +02:00
|
|
|
}
|
|
|
|
|
2013-01-08 08:17:58 +01:00
|
|
|
bool AddressTableModel::removeRows(int row, int count, const QModelIndex &parent)
|
2011-06-03 15:16:11 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
AddressTableEntry *rec = priv->index(row);
|
|
|
|
if(count != 1 || !rec || rec->type == AddressTableEntry::Receiving)
|
|
|
|
{
|
2011-06-18 11:53:25 +02:00
|
|
|
// Can only remove one row at a time, and cannot remove rows not in model.
|
|
|
|
// Also refuse to remove receiving addresses.
|
2011-06-03 15:16:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-07-07 15:22:54 +02:00
|
|
|
{
|
2012-04-06 18:39:12 +02:00
|
|
|
LOCK(wallet->cs_wallet);
|
2013-07-22 08:50:39 +02:00
|
|
|
wallet->DelAddressBook(CBitcoinAddress(rec->address.toStdString()).Get());
|
2011-07-07 15:22:54 +02:00
|
|
|
}
|
2011-06-03 15:16:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
2011-06-21 20:34:43 +02:00
|
|
|
|
2011-07-08 22:27:36 +02:00
|
|
|
/* Look up label for address in address book, if not found return empty string.
|
|
|
|
*/
|
|
|
|
QString AddressTableModel::labelForAddress(const QString &address) const
|
|
|
|
{
|
|
|
|
{
|
2012-04-06 18:39:12 +02:00
|
|
|
LOCK(wallet->cs_wallet);
|
2011-07-26 15:38:31 +02:00
|
|
|
CBitcoinAddress address_parsed(address.toStdString());
|
2013-07-15 07:20:50 +02:00
|
|
|
std::map<CTxDestination, CAddressBookData>::iterator mi = wallet->mapAddressBook.find(address_parsed.Get());
|
2011-07-08 22:27:36 +02:00
|
|
|
if (mi != wallet->mapAddressBook.end())
|
|
|
|
{
|
2013-07-15 07:20:50 +02:00
|
|
|
return QString::fromStdString(mi->second.name);
|
2011-07-08 22:27:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
int AddressTableModel::lookupAddress(const QString &address) const
|
|
|
|
{
|
|
|
|
QModelIndexList lst = match(index(0, Address, QModelIndex()),
|
|
|
|
Qt::EditRole, address, 1, Qt::MatchExactly);
|
|
|
|
if(lst.isEmpty())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return lst.at(0).row();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-06 22:41:35 +02:00
|
|
|
void AddressTableModel::emitDataChanged(int idx)
|
|
|
|
{
|
|
|
|
emit dataChanged(index(idx, 0, QModelIndex()), index(idx, columns.length()-1, QModelIndex()));
|
|
|
|
}
|