diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index 25500764..ca605241 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -70,11 +70,6 @@ struct AddressTablePriv return 0; } } - - bool isDefaultAddress(const AddressTableEntry *rec) - { - return rec->address == QString::fromStdString(wallet->GetDefaultAddress()); - } }; AddressTableModel::AddressTableModel(CWallet *wallet, QObject *parent) : @@ -124,8 +119,6 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const } case Address: return rec->address; - case IsDefaultAddress: - return priv->isDefaultAddress(rec); } } else if (role == Qt::FontRole) @@ -135,27 +128,8 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const { font = GUIUtil::bitcoinAddressFont(); } - if(priv->isDefaultAddress(rec)) - { - font.setBold(true); - } return font; } - else if (role == Qt::BackgroundRole) - { - // Show default address in alternative color - if(priv->isDefaultAddress(rec)) - { - return QColor(255,255,128); - } - } - else if (role == Qt::ToolTipRole) - { - if(priv->isDefaultAddress(rec)) - { - return tr("Default receiving address"); - } - } else if (role == TypeRole) { switch(rec->type) @@ -196,12 +170,6 @@ 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); @@ -244,7 +212,7 @@ void AddressTableModel::updateList() endResetModel(); } -QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address, bool setAsDefault) +QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address) { std::string strLabel = label.toStdString(); std::string strAddress = address.toStdString(); @@ -265,10 +233,6 @@ 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(wallet->GetKeyFromKeyPool()); - if(setAsDefault) - { - setDefaultAddress(QString::fromStdString(strAddress)); - } } else { @@ -295,17 +259,7 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex & paren return true; } -QString AddressTableModel::getDefaultAddress() const -{ - return QString::fromStdString(wallet->GetDefaultAddress()); -} - -void AddressTableModel::setDefaultAddress(const QString &defaultAddress) -{ - wallet->SetDefaultAddress(defaultAddress.toStdString()); -} - void AddressTableModel::update() { - emit defaultAddressChanged(getDefaultAddress()); + } diff --git a/src/qt/addresstablemodel.h b/src/qt/addresstablemodel.h index d8465853..3ababfc6 100644 --- a/src/qt/addresstablemodel.h +++ b/src/qt/addresstablemodel.h @@ -16,8 +16,7 @@ public: enum ColumnIndex { Label = 0, /* User specified label */ - Address = 1, /* Bitcoin address */ - IsDefaultAddress = 2 /* Is default address? */ + Address = 1 /* Bitcoin address */ }; enum { @@ -39,11 +38,7 @@ public: /* Add an address to the model. Returns the added address on success, and an empty string otherwise. */ - QString addRow(const QString &type, const QString &label, const QString &address, bool setAsDefault); - - /* Set and get default address */ - QString getDefaultAddress() const; - void setDefaultAddress(const QString &defaultAddress); + QString addRow(const QString &type, const QString &label, const QString &address); /* Update address list from core. Invalidates any indices. */ diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp index 58ecb494..8ffabf47 100644 --- a/src/qt/editaddressdialog.cpp +++ b/src/qt/editaddressdialog.cpp @@ -19,19 +19,16 @@ EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) : case NewReceivingAddress: setWindowTitle(tr("New receiving address")); ui->addressEdit->setEnabled(false); - ui->setAsDefault->setChecked(true); break; case NewSendingAddress: setWindowTitle(tr("New sending address")); - ui->setAsDefault->setVisible(false); break; case EditReceivingAddress: setWindowTitle(tr("Edit receiving address")); - ui->addressEdit->setReadOnly(true); + ui->addressEdit->setDisabled(true); break; case EditSendingAddress: setWindowTitle(tr("Edit sending address")); - ui->setAsDefault->setVisible(false); break; } @@ -50,7 +47,6 @@ void EditAddressDialog::setModel(AddressTableModel *model) mapper->setModel(model); mapper->addMapping(ui->labelEdit, AddressTableModel::Label); mapper->addMapping(ui->addressEdit, AddressTableModel::Address); - mapper->addMapping(ui->setAsDefault, AddressTableModel::IsDefaultAddress); } void EditAddressDialog::loadRow(int row) @@ -68,8 +64,7 @@ QString EditAddressDialog::saveCurrentRow() address = model->addRow( mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive, ui->labelEdit->text(), - ui->addressEdit->text(), - ui->setAsDefault->isChecked()); + ui->addressEdit->text()); if(address.isEmpty()) { QMessageBox::warning(this, windowTitle(), diff --git a/src/qt/forms/addressbookdialog.ui b/src/qt/forms/addressbookdialog.ui index d99651d6..9bfcb30f 100644 --- a/src/qt/forms/addressbookdialog.ui +++ b/src/qt/forms/addressbookdialog.ui @@ -59,7 +59,7 @@ - These are your Bitcoin addresses for receiving payments. You may want to give a different one to each sender so you can keep track of who is paying you. The highlighted address is your default receiving address. + These are your Bitcoin addresses for receiving payments. You may want to give a different one to each sender so you can keep track of who is paying you. Qt::AutoText diff --git a/src/qt/forms/editaddressdialog.ui b/src/qt/forms/editaddressdialog.ui index 95909fb9..b4a4c1b1 100644 --- a/src/qt/forms/editaddressdialog.ui +++ b/src/qt/forms/editaddressdialog.ui @@ -6,8 +6,8 @@ 0 0 - 458 - 114 + 457 + 126 @@ -29,6 +29,13 @@ + + + + The label associated with this address book entry + + + @@ -39,13 +46,6 @@ - - - - The label associated with this address book entry - - - @@ -53,13 +53,6 @@ - - - - Set as default receiving address - - - diff --git a/src/qt/forms/sendcoinsdialog.ui b/src/qt/forms/sendcoinsdialog.ui index 3641f61e..59599f2e 100644 --- a/src/qt/forms/sendcoinsdialog.ui +++ b/src/qt/forms/sendcoinsdialog.ui @@ -7,7 +7,7 @@ 0 0 660 - 151 + 193 @@ -122,28 +122,34 @@ 0 - - - - Add specified destination address to address book - - - A&dd to address book as - - - - false + true Label to add address as + + Enter a label for this address to add it to your address book + + + + + &Label: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + addAsLabel + + + @@ -221,7 +227,6 @@ payTo - addToAddressBook addAsLabel payAmount addressBookButton diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 5c889b23..14d50963 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -56,11 +56,8 @@ void SendCoinsDialog::on_sendButton_clicked() return; } - if(ui->addToAddressBook->isChecked()) - { - // Add address to address book under label, if specified - label = ui->addAsLabel->text(); - } + // Add address to address book under label, if specified + label = ui->addAsLabel->text(); switch(model->sendCoins(ui->payTo->text(), payAmountParsed, label)) { @@ -108,6 +105,7 @@ void SendCoinsDialog::on_addressBookButton_clicked() dlg.setTab(AddressBookDialog::SendingTab); dlg.exec(); ui->payTo->setText(dlg.getReturnValue()); + ui->payAmount->setFocus(); } void SendCoinsDialog::on_buttonBox_rejected() @@ -115,7 +113,7 @@ void SendCoinsDialog::on_buttonBox_rejected() reject(); } -void SendCoinsDialog::on_addToAddressBook_toggled(bool checked) +void SendCoinsDialog::on_payTo_textChanged(const QString &address) { - ui->addAsLabel->setEnabled(checked); + ui->addAsLabel->setText(model->labelForAddress(address)); } diff --git a/src/qt/sendcoinsdialog.h b/src/qt/sendcoinsdialog.h index bbb6a5fc..968cbe76 100644 --- a/src/qt/sendcoinsdialog.h +++ b/src/qt/sendcoinsdialog.h @@ -23,7 +23,7 @@ private: WalletModel *model; private slots: - void on_addToAddressBook_toggled(bool checked); + void on_payTo_textChanged(const QString &address); void on_buttonBox_rejected(); void on_addressBookButton_clicked(); void on_pasteButton_clicked(); diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 5b11b331..0d0d97bb 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -3,6 +3,7 @@ #include "transactionrecord.h" #include "guiconstants.h" #include "transactiondesc.h" +#include "walletmodel.h" #include "headers.h" @@ -201,9 +202,10 @@ struct TransactionTablePriv }; -TransactionTableModel::TransactionTableModel(CWallet* wallet, QObject *parent): +TransactionTableModel::TransactionTableModel(CWallet* wallet, WalletModel *parent): QAbstractTableModel(parent), wallet(wallet), + walletModel(parent), priv(new TransactionTablePriv(wallet, this)) { columns << tr("Status") << tr("Date") << tr("Type") << tr("Address") << tr("Amount"); @@ -298,29 +300,13 @@ QVariant TransactionTableModel::formatTxDate(const TransactionRecord *wtx) const } } -/* Look up label for address in address book, if not found return empty string. - This should really move to the wallet class. - */ -QString TransactionTableModel::labelForAddress(const std::string &address) const -{ - CRITICAL_BLOCK(wallet->cs_mapAddressBook) - { - std::map::iterator mi = wallet->mapAddressBook.find(address); - if (mi != wallet->mapAddressBook.end()) - { - return QString::fromStdString(mi->second); - } - } - return QString(); -} - /* Look up address in address book, if found return address[0:12]... (label) otherwise just return address */ QString TransactionTableModel::lookupAddress(const std::string &address) const { - QString label = labelForAddress(address); + QString label = walletModel->labelForAddress(QString::fromStdString(address)); QString description; if(label.isEmpty()) { @@ -526,7 +512,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const } else if (role == LabelRole) { - return labelForAddress(rec->address); + return walletModel->labelForAddress(QString::fromStdString(rec->address)); } else if (role == AbsoluteAmountRole) { diff --git a/src/qt/transactiontablemodel.h b/src/qt/transactiontablemodel.h index 835b3875..f75f414d 100644 --- a/src/qt/transactiontablemodel.h +++ b/src/qt/transactiontablemodel.h @@ -7,12 +7,13 @@ class CWallet; class TransactionTablePriv; class TransactionRecord; +class WalletModel; class TransactionTableModel : public QAbstractTableModel { Q_OBJECT public: - explicit TransactionTableModel(CWallet* wallet, QObject *parent = 0); + explicit TransactionTableModel(CWallet* wallet, WalletModel *parent = 0); ~TransactionTableModel(); enum { @@ -47,10 +48,10 @@ public: QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; private: CWallet* wallet; + WalletModel *walletModel; QStringList columns; TransactionTablePriv *priv; - QString labelForAddress(const std::string &address) const; QString lookupAddress(const std::string &address) const; QVariant formatTxStatus(const TransactionRecord *wtx) const; QVariant formatTxDate(const TransactionRecord *wtx) const; diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 0fb7d210..f962b9a7 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -122,3 +122,19 @@ TransactionTableModel *WalletModel::getTransactionTableModel() { return transactionTableModel; } + +/* Look up label for address in address book, if not found return empty string. + */ +QString WalletModel::labelForAddress(const QString &address) const +{ + CRITICAL_BLOCK(wallet->cs_mapAddressBook) + { + std::map::iterator mi = wallet->mapAddressBook.find(address.toStdString()); + if (mi != wallet->mapAddressBook.end()) + { + return QString::fromStdString(mi->second); + } + } + return QString(); +} + diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 5b46dfb6..9c7d16fc 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -33,6 +33,10 @@ public: qint64 getBalance() const; int getNumTransactions() const; + /* Look up label for address in address book, if not found return empty string. + */ + QString labelForAddress(const QString &address) const; + /* Send coins */ StatusCode sendCoins(const QString &payTo, qint64 payAmount, const QString &addToAddressBookAs=QString()); private: