aboutsummaryrefslogtreecommitdiff
path: root/src/qt
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2011-07-02 13:45:59 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2011-07-02 13:45:59 +0200
commitebff5c40a234f38429965c391da020bbf8312b1b (patch)
treec37239c253c74dc4c2f73838e2d6ae9edad31ed7 /src/qt
parent05da981f05d7b2e1551345a042d3379e9244f09b (diff)
Send: dialog redesign (automatically look up label for entered address)
Diffstat (limited to 'src/qt')
-rw-r--r--src/qt/addresstablemodel.cpp50
-rw-r--r--src/qt/addresstablemodel.h9
-rw-r--r--src/qt/editaddressdialog.cpp9
-rw-r--r--src/qt/forms/addressbookdialog.ui2
-rw-r--r--src/qt/forms/editaddressdialog.ui25
-rw-r--r--src/qt/forms/sendcoinsdialog.ui31
-rw-r--r--src/qt/sendcoinsdialog.cpp12
-rw-r--r--src/qt/sendcoinsdialog.h2
-rw-r--r--src/qt/transactiontablemodel.cpp24
-rw-r--r--src/qt/transactiontablemodel.h5
-rw-r--r--src/qt/walletmodel.cpp16
-rw-r--r--src/qt/walletmodel.h4
12 files changed, 68 insertions, 121 deletions
diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp
index 2550076408..ca605241ed 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 d8465853b2..3ababfc6b5 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 58ecb49486..8ffabf4798 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 d99651d6ab..9bfcb30f46 100644
--- a/src/qt/forms/addressbookdialog.ui
+++ b/src/qt/forms/addressbookdialog.ui
@@ -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>
diff --git a/src/qt/forms/editaddressdialog.ui b/src/qt/forms/editaddressdialog.ui
index 95909fb964..b4a4c1b1e9 100644
--- a/src/qt/forms/editaddressdialog.ui
+++ b/src/qt/forms/editaddressdialog.ui
@@ -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 @@
</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 @@
</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 @@
</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>
diff --git a/src/qt/forms/sendcoinsdialog.ui b/src/qt/forms/sendcoinsdialog.ui
index 3641f61eca..59599f2e5b 100644
--- a/src/qt/forms/sendcoinsdialog.ui
+++ b/src/qt/forms/sendcoinsdialog.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>660</width>
- <height>151</height>
+ <height>193</height>
</rect>
</property>
<property name="windowTitle">
@@ -123,27 +123,33 @@
<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 @@
</customwidgets>
<tabstops>
<tabstop>payTo</tabstop>
- <tabstop>addToAddressBook</tabstop>
<tabstop>addAsLabel</tabstop>
<tabstop>payAmount</tabstop>
<tabstop>addressBookButton</tabstop>
diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp
index 5c889b2347..14d50963f2 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 bbb6a5fc4d..968cbe760f 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 5b11b3311b..0d0d97bbde 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<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
}
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 835b387575..f75f414d4c 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 0fb7d21087..f962b9a7c7 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<std::string, std::string>::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 5b46dfb69d..9c7d16fce6 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: