X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Faddresstablemodel.cpp;h=eece092f0da545b23c6aa8f0892632e5015cb6b9;hb=e8ef3da7133dd9fc411fa8b3cc8b8fc2f9c58a98;hp=1cd82b76265da07eeea7a497acfa99846c9179b5;hpb=d99f5a470c8c4e80223f7a78679db58db78ee979;p=novacoin.git diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index 1cd82b7..eece092 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -1,6 +1,7 @@ #include "addresstablemodel.h" #include "guiutil.h" -#include "main.h" + +#include "headers.h" #include #include @@ -22,31 +23,25 @@ struct AddressTableEntry AddressTableEntry() {} AddressTableEntry(Type type, const QString &label, const QString &address): type(type), label(label), address(address) {} - - bool isDefaultAddress() const - { - std::vector vchPubKey; - if (CWalletDB("r").ReadDefaultKey(vchPubKey)) - { - return address == QString::fromStdString(PubKeyToAddress(vchPubKey)); - } - return false; - } }; // Private implementation struct AddressTablePriv { + CWallet *wallet; QList cachedAddressTable; + AddressTablePriv(CWallet *wallet): + wallet(wallet) {} + void refreshAddressTable() { cachedAddressTable.clear(); - CRITICAL_BLOCK(cs_mapKeys) - CRITICAL_BLOCK(cs_mapAddressBook) + CRITICAL_BLOCK(wallet->cs_mapKeys) + CRITICAL_BLOCK(wallet->cs_mapAddressBook) { - BOOST_FOREACH(const PAIRTYPE(std::string, std::string)& item, mapAddressBook) + BOOST_FOREACH(const PAIRTYPE(std::string, std::string)& item, wallet->mapAddressBook) { std::string strAddress = item.first; std::string strName = item.second; @@ -75,13 +70,18 @@ struct AddressTablePriv return 0; } } + + bool isDefaultAddress(const AddressTableEntry *rec) + { + return rec->address == QString::fromStdString(wallet->GetDefaultAddress()); + } }; -AddressTableModel::AddressTableModel(QObject *parent) : - QAbstractTableModel(parent),priv(0) +AddressTableModel::AddressTableModel(CWallet *wallet, QObject *parent) : + QAbstractTableModel(parent),wallet(wallet),priv(0) { columns << tr("Label") << tr("Address"); - priv = new AddressTablePriv(); + priv = new AddressTablePriv(wallet); priv->refreshAddressTable(); } @@ -118,7 +118,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const case Address: return rec->address; case IsDefaultAddress: - return rec->isDefaultAddress(); + return priv->isDefaultAddress(rec); } } else if (role == Qt::FontRole) @@ -128,7 +128,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const { font = GUIUtil::bitcoinAddressFont(); } - if(rec->isDefaultAddress()) + if(priv->isDefaultAddress(rec)) { font.setBold(true); } @@ -137,14 +137,14 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const else if (role == Qt::ForegroundRole) { // Show default address in alternative color - if(rec->isDefaultAddress()) + if(priv->isDefaultAddress(rec)) { return QColor(0,0,255); } } else if (role == Qt::ToolTipRole) { - if(rec->isDefaultAddress()) + if(priv->isDefaultAddress(rec)) { return tr("Default receiving address"); } @@ -174,7 +174,7 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu switch(index.column()) { case Label: - SetAddressBookName(rec->address.toStdString(), value.toString().toStdString()); + wallet->SetAddressBookName(rec->address.toStdString(), value.toString().toStdString()); rec->label = value.toString(); break; case Address: @@ -182,9 +182,9 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu if(rec->type == AddressTableEntry::Sending) { // Remove old entry - CWalletDB().EraseName(rec->address.toStdString()); + wallet->EraseAddressBookName(rec->address.toStdString()); // Add new entry with new address - SetAddressBookName(value.toString().toStdString(), rec->label.toStdString()); + wallet->SetAddressBookName(value.toString().toStdString(), rec->label.toStdString()); rec->address = value.toString(); } @@ -245,9 +245,9 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con if(type == Send) { // Check for duplicate - CRITICAL_BLOCK(cs_mapAddressBook) + CRITICAL_BLOCK(wallet->cs_mapAddressBook) { - if(mapAddressBook.count(strAddress)) + if(wallet->mapAddressBook.count(strAddress)) { return QString(); } @@ -257,7 +257,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con { // Generate a new address to associate with given label, optionally // set as default receiving address. - strAddress = PubKeyToAddress(GetKeyFromKeyPool()); + strAddress = PubKeyToAddress(wallet->GetKeyFromKeyPool()); if(setAsDefault) { setDefaultAddress(QString::fromStdString(strAddress)); @@ -268,7 +268,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con return QString(); } // Add entry and update list - SetAddressBookName(strAddress, strLabel); + wallet->SetAddressBookName(strAddress, strLabel); updateList(); return QString::fromStdString(strAddress); } @@ -283,33 +283,19 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex & paren // Also refuse to remove receiving addresses. return false; } - CWalletDB().EraseName(rec->address.toStdString()); + wallet->EraseAddressBookName(rec->address.toStdString()); updateList(); return true; } QString AddressTableModel::getDefaultAddress() const { - std::vector vchPubKey; - if (CWalletDB("r").ReadDefaultKey(vchPubKey)) - { - return QString::fromStdString(PubKeyToAddress(vchPubKey)); - } - else - { - return QString(); - } + return QString::fromStdString(wallet->GetDefaultAddress()); } void AddressTableModel::setDefaultAddress(const QString &defaultAddress) { - uint160 hash160; - std::string strAddress = defaultAddress.toStdString(); - if (!AddressToHash160(strAddress, hash160)) - return; - if (!mapPubKeys.count(hash160)) - return; - CWalletDB().WriteDefaultKey(mapPubKeys[hash160]); + wallet->SetDefaultAddress(defaultAddress.toStdString()); } void AddressTableModel::update()