13 #include <boost/foreach.hpp>
59 if (strPurpose ==
"send")
61 else if (strPurpose ==
"receive")
63 else if (strPurpose ==
"unknown" || strPurpose ==
"")
89 QString::fromStdString(item.second.
purpose), fMine);
90 const std::string& strName = item.second.
name;
92 QString::fromStdString(strName),
93 QString::fromStdString(address.
ToString())));
102 void updateEntry(
const QString &address,
const QString &label,
bool isMine,
const QString &purpose,
int status)
105 QList<AddressTableEntry>::iterator lower = qLowerBound(
107 QList<AddressTableEntry>::iterator upper = qUpperBound(
111 bool inModel = (lower != upper);
119 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got CT_NEW, but entry is already in model";
122 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
129 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got CT_UPDATED, but entry is not in model";
132 lower->type = newEntryType;
133 lower->label = label;
139 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got CT_DELETED, but entry is not in model";
142 parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
168 QAbstractTableModel(parent),walletModel(parent),wallet(_wallet),priv(0)
170 columns << tr(
"Label") << tr(
"Address");
199 if(role == Qt::DisplayRole || role == Qt::EditRole)
201 switch(
index.column())
204 if(rec->
label.isEmpty() && role == Qt::DisplayRole)
206 return tr(
"(no label)");
216 else if (role == Qt::FontRole)
247 if(role == Qt::EditRole)
254 if(rec->
label == value.toString())
263 if(boost::get<CNoDestination>(&newAddress))
269 else if(newAddress == curAddress)
297 if(orientation == Qt::Horizontal)
299 if(role == Qt::DisplayRole && section <
columns.size())
313 Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
319 retval |= Qt::ItemIsEditable;
330 return createIndex(row, column,
priv->
index(row));
334 return QModelIndex();
339 const QString &label,
bool isMine,
const QString &purpose,
int status)
347 std::string strLabel = label.toStdString();
348 std::string strAddress = address.toStdString();
399 (type ==
Send ?
"send" :
"receive"));
401 return QString::fromStdString(strAddress);
431 return QString::fromStdString(mi->second.name);
439 QModelIndexList lst = match(
index(0,
Address, QModelIndex()),
440 Qt::EditRole, address, 1, Qt::MatchExactly);
447 return lst.at(0).row();
453 Q_EMIT dataChanged(
index(idx, 0, QModelIndex()),
index(idx,
columns.length()-1, QModelIndex()));
Qt model of the address book in the core.
@ TypeRole
Type of address (Send or Receive)
int lookupAddress(const QString &address) const
int columnCount(const QModelIndex &parent) const
AddressTableModel(CWallet *wallet, WalletModel *parent=0)
QVariant headerData(int section, Qt::Orientation orientation, int role) const
WalletModel * walletModel
@ WALLET_UNLOCK_FAILURE
Wallet could not be unlocked to create new receiving address.
@ NO_CHANGES
No changes were made during edit operation.
@ INVALID_ADDRESS
Unparseable address.
@ KEY_GENERATION_FAILURE
Generating a new public key for a receiving address failed.
@ DUPLICATE_ADDRESS
Address already in address book.
void emitDataChanged(int index)
Notify listeners that data changed.
@ Address
Bitcoin address.
@ Label
User specified label.
Qt::ItemFlags flags(const QModelIndex &index) const
bool setData(const QModelIndex &index, const QVariant &value, int role)
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
QModelIndex index(int row, int column, const QModelIndex &parent) const
QVariant data(const QModelIndex &index, int role) const
static const QString Send
Specifies send address.
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
friend class AddressTablePriv
QString addRow(const QString &type, const QString &label, const QString &address)
static const QString Receive
Specifies receive address.
int rowCount(const QModelIndex &parent) const
QString labelForAddress(const QString &address) const
QList< AddressTableEntry > cachedAddressTable
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
AddressTableModel * parent
AddressTablePriv(CWallet *_wallet, AddressTableModel *_parent)
void refreshAddressTable()
AddressTableEntry * index(int idx)
std::string ToString() const
base58-encoded Bitcoin addresses.
CTxDestination Get() const
An encapsulated public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
std::map< CTxDestination, CAddressBookData > mapAddressBook
CCriticalSection cs_wallet
Interface to Bitcoin wallet from Qt view code.
bool validateAddress(const QString &address)
UnlockContext requestUnlock()
bool GetKeyFromPool(CPubKey &key)
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
bool DelAddressBook(const CTxDestination &address)
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey, SigVersion sigversion)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
AddressTableEntry(Type _type, const QString &_label, const QString &_address)
bool operator()(const AddressTableEntry &a, const AddressTableEntry &b) const
bool operator()(const QString &a, const AddressTableEntry &b) const
bool operator()(const AddressTableEntry &a, const QString &b) const
#define PAIRTYPE(t1, t2)
This is needed because the foreach macro can't get over the comma in pair<t1, t2>