14 #include <boost/foreach.hpp> 60 if (strPurpose ==
"send")
62 else if (strPurpose ==
"receive")
64 else if (strPurpose ==
"unknown" || strPurpose ==
"")
90 QString::fromStdString(item.second.
purpose), fMine);
91 const std::string& strName = item.second.
name;
93 QString::fromStdString(strName),
94 QString::fromStdString(address.
ToString())));
103 void updateEntry(
const QString &address,
const QString &label,
bool isMine,
const QString &purpose,
int status)
106 QList<AddressTableEntry>::iterator lower = qLowerBound(
108 QList<AddressTableEntry>::iterator upper = qUpperBound(
112 bool inModel = (lower != upper);
120 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got CT_NEW, but entry is already in model";
123 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
130 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got CT_UPDATED, but entry is not in model";
133 lower->type = newEntryType;
134 lower->label = label;
140 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got CT_DELETED, but entry is not in model";
143 parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
169 QAbstractTableModel(parent),walletModel(parent),
wallet(
wallet),priv(0)
171 columns << tr(
"Label") << tr(
"Address");
200 if(role == Qt::DisplayRole || role == Qt::EditRole)
202 switch(
index.column())
205 if(rec->
label.isEmpty() && role == Qt::DisplayRole)
207 return tr(
"(no label)");
217 else if (role == Qt::FontRole)
248 if(role == Qt::EditRole)
255 if(rec->
label == value.toString())
260 wallet->SetAddressBook(curAddress, value.toString().toStdString(), strPurpose);
264 if(boost::get<CNoDestination>(&newAddress))
270 else if(newAddress == curAddress)
277 else if(
wallet->mapAddressBook.count(newAddress))
286 wallet->DelAddressBook(curAddress);
288 wallet->SetAddressBook(newAddress, rec->
label.toStdString(), strPurpose);
298 if(orientation == Qt::Horizontal)
300 if(role == Qt::DisplayRole && section <
columns.size())
314 Qt::ItemFlags
retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
320 retval |= Qt::ItemIsEditable;
331 return createIndex(row, column,
priv->
index(row));
335 return QModelIndex();
340 const QString &label,
bool isMine,
const QString &purpose,
int status)
348 std::string strLabel = label.toStdString();
349 std::string strAddress = address.toStdString();
374 if(!
wallet->GetKeyFromPool(newKey,
false))
383 if(!
wallet->GetKeyFromPool(newKey,
false))
400 (type ==
Send ?
"send" :
"receive"));
402 return QString::fromStdString(strAddress);
429 std::map<CTxDestination, CAddressBookData>::iterator mi =
wallet->mapAddressBook.find(address_parsed.Get());
430 if (mi !=
wallet->mapAddressBook.end())
432 return QString::fromStdString(mi->second.name);
440 QModelIndexList lst = match(
index(0,
Address, QModelIndex()),
441 Qt::EditRole, address, 1, Qt::MatchExactly);
448 return lst.at(0).row();
454 Q_EMIT dataChanged(
index(idx, 0, QModelIndex()),
index(idx,
columns.length()-1, QModelIndex()));
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
AddressTablePriv(CWallet *wallet, AddressTableModel *parent)
static const QString Send
QString addRow(const QString &type, const QString &label, const QString &address)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
friend class AddressTablePriv
static const QString Receive
Qt::ItemFlags flags(const QModelIndex &index) const
int lookupAddress(const QString &address) const
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
bool operator()(const QString &a, const AddressTableEntry &b) const
void refreshAddressTable()
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
WalletModel * walletModel
int columnCount(const QModelIndex &parent) const
std::string ToString() const
bool operator()(const AddressTableEntry &a, const QString &b) const
QModelIndex index(int row, int column, const QModelIndex &parent) const
AddressTableModel(CWallet *wallet, WalletModel *parent=0)
QString labelForAddress(const QString &address) const
static secp256k1_context * ctx
bool operator()(const AddressTableEntry &a, const AddressTableEntry &b) const
AddressTableEntry * index(int idx)
AddressTableModel * parent
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
bool validateAddress(const QString &address)
void emitDataChanged(int index)
CTxDestination Get() const
bool setData(const QModelIndex &index, const QVariant &value, int role)
QList< AddressTableEntry > cachedAddressTable
QVariant data(const QModelIndex &index, int role) const
static AddressTableEntry::Type translateTransactionType(const QString &strPurpose, bool isMine)
int rowCount(const QModelIndex &parent) const
AddressTableEntry(Type type, const QString &label, const QString &address)
UnlockContext requestUnlock(bool fForMixingOnly=false)
QVariant headerData(int section, Qt::Orientation orientation, int role) const