Changeset View
Changeset View
Standalone View
Standalone View
src/qt/addresstablemodel.cpp
Show First 20 Lines • Show All 379 Lines • ▼ Show 20 Lines | if (count != 1 || !rec || rec->type == AddressTableEntry::Receiving) { | ||||
// Also refuse to remove receiving addresses. | // Also refuse to remove receiving addresses. | ||||
return false; | return false; | ||||
} | } | ||||
walletModel->wallet().delAddressBook(DecodeDestination( | walletModel->wallet().delAddressBook(DecodeDestination( | ||||
rec->address.toStdString(), walletModel->getChainParams())); | rec->address.toStdString(), walletModel->getChainParams())); | ||||
return true; | return true; | ||||
} | } | ||||
/* Look up label for address in address book, if not found return empty string. | |||||
*/ | |||||
QString AddressTableModel::labelForAddress(const QString &address) const { | QString AddressTableModel::labelForAddress(const QString &address) const { | ||||
CTxDestination destination = | |||||
DecodeDestination(address.toStdString(), walletModel->getChainParams()); | |||||
std::string name; | std::string name; | ||||
if (walletModel->wallet().getAddress(destination, &name, | if (getAddressData(address, &name, /* purpose= */ nullptr)) { | ||||
/* is_mine= */ nullptr, | |||||
/* purpose= */ nullptr)) { | |||||
return QString::fromStdString(name); | return QString::fromStdString(name); | ||||
} | } | ||||
return QString(); | return QString(); | ||||
} | } | ||||
QString AddressTableModel::purposeForAddress(const QString &address) const { | |||||
std::string purpose; | |||||
if (getAddressData(address, /* name= */ nullptr, &purpose)) { | |||||
return QString::fromStdString(purpose); | |||||
} | |||||
return QString(); | |||||
} | |||||
bool AddressTableModel::getAddressData(const QString &address, | |||||
std::string *name, | |||||
std::string *purpose) const { | |||||
CTxDestination destination = | |||||
DecodeDestination(address.toStdString(), walletModel->getChainParams()); | |||||
return walletModel->wallet().getAddress(destination, name, | |||||
/* is_mine= */ nullptr, purpose); | |||||
} | |||||
int AddressTableModel::lookupAddress(const QString &address) const { | int AddressTableModel::lookupAddress(const QString &address) const { | ||||
QModelIndexList lst = match(index(0, Address, QModelIndex()), Qt::EditRole, | QModelIndexList lst = match(index(0, Address, QModelIndex()), Qt::EditRole, | ||||
address, 1, Qt::MatchExactly); | address, 1, Qt::MatchExactly); | ||||
if (lst.isEmpty()) { | if (lst.isEmpty()) { | ||||
return -1; | return -1; | ||||
} else { | } else { | ||||
return lst.at(0).row(); | return lst.at(0).row(); | ||||
} | } | ||||
} | } | ||||
void AddressTableModel::emitDataChanged(int idx) { | void AddressTableModel::emitDataChanged(int idx) { | ||||
Q_EMIT dataChanged(index(idx, 0, QModelIndex()), | Q_EMIT dataChanged(index(idx, 0, QModelIndex()), | ||||
index(idx, columns.length() - 1, QModelIndex())); | index(idx, columns.length() - 1, QModelIndex())); | ||||
} | } |