Browse Source

Send: dialog redesign (automatically look up label for entered address)

0.8
Wladimir J. van der Laan 14 years ago
parent
commit
ebff5c40a2
  1. 50
      src/qt/addresstablemodel.cpp
  2. 9
      src/qt/addresstablemodel.h
  3. 9
      src/qt/editaddressdialog.cpp
  4. 2
      src/qt/forms/addressbookdialog.ui
  5. 25
      src/qt/forms/editaddressdialog.ui
  6. 31
      src/qt/forms/sendcoinsdialog.ui
  7. 12
      src/qt/sendcoinsdialog.cpp
  8. 2
      src/qt/sendcoinsdialog.h
  9. 24
      src/qt/transactiontablemodel.cpp
  10. 5
      src/qt/transactiontablemodel.h
  11. 16
      src/qt/walletmodel.cpp
  12. 4
      src/qt/walletmodel.h

50
src/qt/addresstablemodel.cpp

@ -70,11 +70,6 @@ struct AddressTablePriv @@ -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 @@ -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 @@ -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 @@ -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() @@ -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 @@ -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 @@ -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());
}

9
src/qt/addresstablemodel.h

@ -16,8 +16,7 @@ public: @@ -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: @@ -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.
*/

9
src/qt/editaddressdialog.cpp

@ -19,19 +19,16 @@ EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) : @@ -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) @@ -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() @@ -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(),

2
src/qt/forms/addressbookdialog.ui

@ -59,7 +59,7 @@ @@ -59,7 +59,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>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.</string>
<string>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.</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>

25
src/qt/forms/editaddressdialog.ui

@ -6,8 +6,8 @@ @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>458</width>
<height>114</height>
<width>457</width>
<height>126</height>
</rect>
</property>
<property name="windowTitle">
@ -29,6 +29,13 @@ @@ -29,6 +29,13 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="labelEdit">
<property name="toolTip">
<string>The label associated with this address book entry</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
@ -39,13 +46,6 @@ @@ -39,13 +46,6 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="labelEdit">
<property name="toolTip">
<string>The label associated with this address book entry</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="addressEdit">
<property name="toolTip">
@ -53,13 +53,6 @@ @@ -53,13 +53,6 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="setAsDefault">
<property name="text">
<string>Set as default receiving address</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

31
src/qt/forms/sendcoinsdialog.ui

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>660</width>
<height>151</height>
<height>193</height>
</rect>
</property>
<property name="windowTitle">
@ -122,28 +122,34 @@ @@ -122,28 +122,34 @@
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="addToAddressBook">
<property name="toolTip">
<string>Add specified destination address to address book</string>
</property>
<property name="text">
<string>A&amp;dd to address book as</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="addAsLabel">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="toolTip">
<string>Label to add address as</string>
</property>
<property name="placeholderText">
<string>Enter a label for this address to add it to your address book</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>&amp;Label:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>addAsLabel</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -221,7 +227,6 @@ @@ -221,7 +227,6 @@
</customwidgets>
<tabstops>
<tabstop>payTo</tabstop>
<tabstop>addToAddressBook</tabstop>
<tabstop>addAsLabel</tabstop>
<tabstop>payAmount</tabstop>
<tabstop>addressBookButton</tabstop>

12
src/qt/sendcoinsdialog.cpp

@ -56,11 +56,8 @@ void SendCoinsDialog::on_sendButton_clicked() @@ -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() @@ -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() @@ -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));
}

2
src/qt/sendcoinsdialog.h

@ -23,7 +23,7 @@ private: @@ -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();

24
src/qt/transactiontablemodel.cpp

@ -3,6 +3,7 @@ @@ -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 @@ -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 @@ -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<std::string, std::string>::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 @@ -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)
{

5
src/qt/transactiontablemodel.h

@ -7,12 +7,13 @@ @@ -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: @@ -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;

16
src/qt/walletmodel.cpp

@ -122,3 +122,19 @@ TransactionTableModel *WalletModel::getTransactionTableModel() @@ -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<std::string, std::string>::iterator mi = wallet->mapAddressBook.find(address.toStdString());
if (mi != wallet->mapAddressBook.end())
{
return QString::fromStdString(mi->second);
}
}
return QString();
}

4
src/qt/walletmodel.h

@ -33,6 +33,10 @@ public: @@ -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:

Loading…
Cancel
Save