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

This commit is contained in:
Wladimir J. van der Laan 2011-07-02 13:45:59 +02:00
parent 05da981f05
commit ebff5c40a2
12 changed files with 68 additions and 121 deletions

View file

@ -70,11 +70,6 @@ struct AddressTablePriv
return 0; return 0;
} }
} }
bool isDefaultAddress(const AddressTableEntry *rec)
{
return rec->address == QString::fromStdString(wallet->GetDefaultAddress());
}
}; };
AddressTableModel::AddressTableModel(CWallet *wallet, QObject *parent) : AddressTableModel::AddressTableModel(CWallet *wallet, QObject *parent) :
@ -124,8 +119,6 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
} }
case Address: case Address:
return rec->address; return rec->address;
case IsDefaultAddress:
return priv->isDefaultAddress(rec);
} }
} }
else if (role == Qt::FontRole) else if (role == Qt::FontRole)
@ -135,27 +128,8 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
{ {
font = GUIUtil::bitcoinAddressFont(); font = GUIUtil::bitcoinAddressFont();
} }
if(priv->isDefaultAddress(rec))
{
font.setBold(true);
}
return font; 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) else if (role == TypeRole)
{ {
switch(rec->type) switch(rec->type)
@ -196,12 +170,6 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
rec->address = value.toString(); rec->address = value.toString();
} }
break; break;
case IsDefaultAddress:
if(value.toBool())
{
setDefaultAddress(rec->address);
}
break;
} }
emit dataChanged(index, index); emit dataChanged(index, index);
@ -244,7 +212,7 @@ void AddressTableModel::updateList()
endResetModel(); 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 strLabel = label.toStdString();
std::string strAddress = address.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 // Generate a new address to associate with given label, optionally
// set as default receiving address. // set as default receiving address.
strAddress = PubKeyToAddress(wallet->GetKeyFromKeyPool()); strAddress = PubKeyToAddress(wallet->GetKeyFromKeyPool());
if(setAsDefault)
{
setDefaultAddress(QString::fromStdString(strAddress));
}
} }
else else
{ {
@ -295,17 +259,7 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex & paren
return true; return true;
} }
QString AddressTableModel::getDefaultAddress() const
{
return QString::fromStdString(wallet->GetDefaultAddress());
}
void AddressTableModel::setDefaultAddress(const QString &defaultAddress)
{
wallet->SetDefaultAddress(defaultAddress.toStdString());
}
void AddressTableModel::update() void AddressTableModel::update()
{ {
emit defaultAddressChanged(getDefaultAddress());
} }

View file

@ -16,8 +16,7 @@ public:
enum ColumnIndex { enum ColumnIndex {
Label = 0, /* User specified label */ Label = 0, /* User specified label */
Address = 1, /* Bitcoin address */ Address = 1 /* Bitcoin address */
IsDefaultAddress = 2 /* Is default address? */
}; };
enum { enum {
@ -39,11 +38,7 @@ public:
/* Add an address to the model. /* Add an address to the model.
Returns the added address on success, and an empty string otherwise. Returns the added address on success, and an empty string otherwise.
*/ */
QString addRow(const QString &type, const QString &label, const QString &address, bool setAsDefault); QString addRow(const QString &type, const QString &label, const QString &address);
/* Set and get default address */
QString getDefaultAddress() const;
void setDefaultAddress(const QString &defaultAddress);
/* Update address list from core. Invalidates any indices. /* Update address list from core. Invalidates any indices.
*/ */

View file

@ -19,19 +19,16 @@ EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) :
case NewReceivingAddress: case NewReceivingAddress:
setWindowTitle(tr("New receiving address")); setWindowTitle(tr("New receiving address"));
ui->addressEdit->setEnabled(false); ui->addressEdit->setEnabled(false);
ui->setAsDefault->setChecked(true);
break; break;
case NewSendingAddress: case NewSendingAddress:
setWindowTitle(tr("New sending address")); setWindowTitle(tr("New sending address"));
ui->setAsDefault->setVisible(false);
break; break;
case EditReceivingAddress: case EditReceivingAddress:
setWindowTitle(tr("Edit receiving address")); setWindowTitle(tr("Edit receiving address"));
ui->addressEdit->setReadOnly(true); ui->addressEdit->setDisabled(true);
break; break;
case EditSendingAddress: case EditSendingAddress:
setWindowTitle(tr("Edit sending address")); setWindowTitle(tr("Edit sending address"));
ui->setAsDefault->setVisible(false);
break; break;
} }
@ -50,7 +47,6 @@ void EditAddressDialog::setModel(AddressTableModel *model)
mapper->setModel(model); mapper->setModel(model);
mapper->addMapping(ui->labelEdit, AddressTableModel::Label); mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
mapper->addMapping(ui->addressEdit, AddressTableModel::Address); mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
mapper->addMapping(ui->setAsDefault, AddressTableModel::IsDefaultAddress);
} }
void EditAddressDialog::loadRow(int row) void EditAddressDialog::loadRow(int row)
@ -68,8 +64,7 @@ QString EditAddressDialog::saveCurrentRow()
address = model->addRow( address = model->addRow(
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive, mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
ui->labelEdit->text(), ui->labelEdit->text(),
ui->addressEdit->text(), ui->addressEdit->text());
ui->setAsDefault->isChecked());
if(address.isEmpty()) if(address.isEmpty())
{ {
QMessageBox::warning(this, windowTitle(), QMessageBox::warning(this, windowTitle(),

View file

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

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>458</width> <width>457</width>
<height>114</height> <height>126</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -29,6 +29,13 @@
</property> </property>
</widget> </widget>
</item> </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"> <item row="1" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
@ -39,13 +46,6 @@
</property> </property>
</widget> </widget>
</item> </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"> <item row="1" column="1">
<widget class="QLineEdit" name="addressEdit"> <widget class="QLineEdit" name="addressEdit">
<property name="toolTip"> <property name="toolTip">
@ -53,13 +53,6 @@
</property> </property>
</widget> </widget>
</item> </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> </layout>
</item> </item>
<item> <item>

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>660</width> <width>660</width>
<height>151</height> <height>193</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -122,28 +122,34 @@
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </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> <item>
<widget class="QLineEdit" name="addAsLabel"> <widget class="QLineEdit" name="addAsLabel">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Label to add address as</string> <string>Label to add address as</string>
</property> </property>
<property name="placeholderText">
<string>Enter a label for this address to add it to your address book</string>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </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> </layout>
</item> </item>
<item> <item>
@ -221,7 +227,6 @@
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>payTo</tabstop> <tabstop>payTo</tabstop>
<tabstop>addToAddressBook</tabstop>
<tabstop>addAsLabel</tabstop> <tabstop>addAsLabel</tabstop>
<tabstop>payAmount</tabstop> <tabstop>payAmount</tabstop>
<tabstop>addressBookButton</tabstop> <tabstop>addressBookButton</tabstop>

View file

@ -56,11 +56,8 @@ void SendCoinsDialog::on_sendButton_clicked()
return; return;
} }
if(ui->addToAddressBook->isChecked())
{
// Add address to address book under label, if specified // Add address to address book under label, if specified
label = ui->addAsLabel->text(); label = ui->addAsLabel->text();
}
switch(model->sendCoins(ui->payTo->text(), payAmountParsed, label)) switch(model->sendCoins(ui->payTo->text(), payAmountParsed, label))
{ {
@ -108,6 +105,7 @@ void SendCoinsDialog::on_addressBookButton_clicked()
dlg.setTab(AddressBookDialog::SendingTab); dlg.setTab(AddressBookDialog::SendingTab);
dlg.exec(); dlg.exec();
ui->payTo->setText(dlg.getReturnValue()); ui->payTo->setText(dlg.getReturnValue());
ui->payAmount->setFocus();
} }
void SendCoinsDialog::on_buttonBox_rejected() void SendCoinsDialog::on_buttonBox_rejected()
@ -115,7 +113,7 @@ void SendCoinsDialog::on_buttonBox_rejected()
reject(); 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));
} }

View file

@ -23,7 +23,7 @@ private:
WalletModel *model; WalletModel *model;
private slots: private slots:
void on_addToAddressBook_toggled(bool checked); void on_payTo_textChanged(const QString &address);
void on_buttonBox_rejected(); void on_buttonBox_rejected();
void on_addressBookButton_clicked(); void on_addressBookButton_clicked();
void on_pasteButton_clicked(); void on_pasteButton_clicked();

View file

@ -3,6 +3,7 @@
#include "transactionrecord.h" #include "transactionrecord.h"
#include "guiconstants.h" #include "guiconstants.h"
#include "transactiondesc.h" #include "transactiondesc.h"
#include "walletmodel.h"
#include "headers.h" #include "headers.h"
@ -201,9 +202,10 @@ struct TransactionTablePriv
}; };
TransactionTableModel::TransactionTableModel(CWallet* wallet, QObject *parent): TransactionTableModel::TransactionTableModel(CWallet* wallet, WalletModel *parent):
QAbstractTableModel(parent), QAbstractTableModel(parent),
wallet(wallet), wallet(wallet),
walletModel(parent),
priv(new TransactionTablePriv(wallet, this)) priv(new TransactionTablePriv(wallet, this))
{ {
columns << tr("Status") << tr("Date") << tr("Type") << tr("Address") << tr("Amount"); 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<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 /* Look up address in address book, if found return
address[0:12]... (label) address[0:12]... (label)
otherwise just return address otherwise just return address
*/ */
QString TransactionTableModel::lookupAddress(const std::string &address) const QString TransactionTableModel::lookupAddress(const std::string &address) const
{ {
QString label = labelForAddress(address); QString label = walletModel->labelForAddress(QString::fromStdString(address));
QString description; QString description;
if(label.isEmpty()) if(label.isEmpty())
{ {
@ -526,7 +512,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
} }
else if (role == LabelRole) else if (role == LabelRole)
{ {
return labelForAddress(rec->address); return walletModel->labelForAddress(QString::fromStdString(rec->address));
} }
else if (role == AbsoluteAmountRole) else if (role == AbsoluteAmountRole)
{ {

View file

@ -7,12 +7,13 @@
class CWallet; class CWallet;
class TransactionTablePriv; class TransactionTablePriv;
class TransactionRecord; class TransactionRecord;
class WalletModel;
class TransactionTableModel : public QAbstractTableModel class TransactionTableModel : public QAbstractTableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit TransactionTableModel(CWallet* wallet, QObject *parent = 0); explicit TransactionTableModel(CWallet* wallet, WalletModel *parent = 0);
~TransactionTableModel(); ~TransactionTableModel();
enum { enum {
@ -47,10 +48,10 @@ public:
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
private: private:
CWallet* wallet; CWallet* wallet;
WalletModel *walletModel;
QStringList columns; QStringList columns;
TransactionTablePriv *priv; TransactionTablePriv *priv;
QString labelForAddress(const std::string &address) const;
QString lookupAddress(const std::string &address) const; QString lookupAddress(const std::string &address) const;
QVariant formatTxStatus(const TransactionRecord *wtx) const; QVariant formatTxStatus(const TransactionRecord *wtx) const;
QVariant formatTxDate(const TransactionRecord *wtx) const; QVariant formatTxDate(const TransactionRecord *wtx) const;

View file

@ -122,3 +122,19 @@ TransactionTableModel *WalletModel::getTransactionTableModel()
{ {
return transactionTableModel; 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();
}

View file

@ -33,6 +33,10 @@ public:
qint64 getBalance() const; qint64 getBalance() const;
int getNumTransactions() 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 */ /* Send coins */
StatusCode sendCoins(const QString &payTo, qint64 payAmount, const QString &addToAddressBookAs=QString()); StatusCode sendCoins(const QString &payTo, qint64 payAmount, const QString &addToAddressBookAs=QString());
private: private: