diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-06-21 20:34:43 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-06-21 20:36:03 +0200 |
commit | b9e80983a5c076fed655a7c3c67b53bd9ecc3dda (patch) | |
tree | 8160290efeef086d82cd7b156a0538e922363ad8 /src/qt/addresstablemodel.cpp | |
parent | f5927f5b32c9e28033fb7a00dd43f3162781c1d0 (diff) |
Allow changing default address (fixes issue #6)
Diffstat (limited to 'src/qt/addresstablemodel.cpp')
-rw-r--r-- | src/qt/addresstablemodel.cpp | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index 0558bfa453..1cd82b7626 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -117,6 +117,8 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const return rec->label; case Address: return rec->address; + case IsDefaultAddress: + return rec->isDefaultAddress(); } } else if (role == Qt::FontRole) @@ -187,6 +189,12 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu rec->address = value.toString(); } break; + case IsDefaultAddress: + if(value.toBool()) + { + setDefaultAddress(rec->address); + } + break; } emit dataChanged(index, index); @@ -229,7 +237,7 @@ void AddressTableModel::updateList() endResetModel(); } -QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address) +QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address, bool setAsDefault) { std::string strLabel = label.toStdString(); std::string strAddress = address.toStdString(); @@ -247,8 +255,13 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con } else if(type == Receive) { - // Generate a new address to associate with given label + // Generate a new address to associate with given label, optionally + // set as default receiving address. strAddress = PubKeyToAddress(GetKeyFromKeyPool()); + if(setAsDefault) + { + setDefaultAddress(QString::fromStdString(strAddress)); + } } else { @@ -274,3 +287,32 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex & paren updateList(); return true; } + +QString AddressTableModel::getDefaultAddress() const +{ + std::vector<unsigned char> vchPubKey; + if (CWalletDB("r").ReadDefaultKey(vchPubKey)) + { + return QString::fromStdString(PubKeyToAddress(vchPubKey)); + } + else + { + return QString(); + } +} + +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]); +} + +void AddressTableModel::update() +{ + emit defaultAddressChanged(getDefaultAddress()); +} |