return 0;
}
}
-
- bool isDefaultAddress(const AddressTableEntry *rec)
- {
- return rec->address == QString::fromStdString(wallet->GetDefaultAddress());
- }
};
AddressTableModel::AddressTableModel(CWallet *wallet, QObject *parent) :
}
case Address:
return rec->address;
- case IsDefaultAddress:
- return priv->isDefaultAddress(rec);
}
}
else if (role == Qt::FontRole)
{
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)
rec->address = value.toString();
}
break;
- case IsDefaultAddress:
- if(value.toBool())
- {
- setDefaultAddress(rec->address);
- }
- break;
}
emit dataChanged(index, index);
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();
// 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
{
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());
+
}
enum ColumnIndex {
Label = 0, /* User specified label */
- Address = 1, /* Bitcoin address */
- IsDefaultAddress = 2 /* Is default address? */
+ Address = 1 /* Bitcoin address */
};
enum {
/* 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.
*/
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;
}
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)
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(),
<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>
<rect>
<x>0</x>
<y>0</y>
- <width>458</width>
- <height>114</height>
+ <width>457</width>
+ <height>126</height>
</rect>
</property>
<property name="windowTitle">
</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">
</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">
</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>
<x>0</x>
<y>0</y>
<width>660</width>
- <height>151</height>
+ <height>193</height>
</rect>
</property>
<property name="windowTitle">
<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&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>&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>
</customwidgets>
<tabstops>
<tabstop>payTo</tabstop>
- <tabstop>addToAddressBook</tabstop>
<tabstop>addAsLabel</tabstop>
<tabstop>payAmount</tabstop>
<tabstop>addressBookButton</tabstop>
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))
{
dlg.setTab(AddressBookDialog::SendingTab);
dlg.exec();
ui->payTo->setText(dlg.getReturnValue());
+ ui->payAmount->setFocus();
}
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));
}
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();
#include "transactionrecord.h"
#include "guiconstants.h"
#include "transactiondesc.h"
+#include "walletmodel.h"
#include "headers.h"
};
-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");
}
}
-/* 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())
{
}
else if (role == LabelRole)
{
- return labelForAddress(rec->address);
+ return walletModel->labelForAddress(QString::fromStdString(rec->address));
}
else if (role == AbsoluteAmountRole)
{
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 {
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;
{
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();
+}
+
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: