aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/qt/addresstablemodel.cpp46
-rw-r--r--src/qt/addresstablemodel.h14
-rw-r--r--src/qt/bitcoingui.cpp10
-rw-r--r--src/qt/clientmodel.cpp28
-rw-r--r--src/qt/clientmodel.h4
-rw-r--r--src/qt/editaddressdialog.cpp7
-rw-r--r--src/qt/forms/editaddressdialog.ui7
7 files changed, 74 insertions, 42 deletions
diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp
index 0558bfa453..1cd82b7626 100644
--- a/src/qt/addresstablemodel.cpp
+++ b/src/qt/addresstablemodel.cpp
@@ -117,6 +117,8 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
return rec->label;
case Address:
return rec->address;
+ case IsDefaultAddress:
+ return rec->isDefaultAddress();
}
}
else if (role == Qt::FontRole)
@@ -187,6 +189,12 @@ 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);
@@ -229,7 +237,7 @@ void AddressTableModel::updateList()
endResetModel();
}
-QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address)
+QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address, bool setAsDefault)
{
std::string strLabel = label.toStdString();
std::string strAddress = address.toStdString();
@@ -247,8 +255,13 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
}
else if(type == Receive)
{
- // Generate a new address to associate with given label
+ // Generate a new address to associate with given label, optionally
+ // set as default receiving address.
strAddress = PubKeyToAddress(GetKeyFromKeyPool());
+ if(setAsDefault)
+ {
+ setDefaultAddress(QString::fromStdString(strAddress));
+ }
}
else
{
@@ -274,3 +287,32 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex & paren
updateList();
return true;
}
+
+QString AddressTableModel::getDefaultAddress() const
+{
+ std::vector<unsigned char> vchPubKey;
+ if (CWalletDB("r").ReadDefaultKey(vchPubKey))
+ {
+ return QString::fromStdString(PubKeyToAddress(vchPubKey));
+ }
+ else
+ {
+ return QString();
+ }
+}
+
+void AddressTableModel::setDefaultAddress(const QString &defaultAddress)
+{
+ uint160 hash160;
+ std::string strAddress = defaultAddress.toStdString();
+ if (!AddressToHash160(strAddress, hash160))
+ return;
+ if (!mapPubKeys.count(hash160))
+ return;
+ CWalletDB().WriteDefaultKey(mapPubKeys[hash160]);
+}
+
+void AddressTableModel::update()
+{
+ emit defaultAddressChanged(getDefaultAddress());
+}
diff --git a/src/qt/addresstablemodel.h b/src/qt/addresstablemodel.h
index 8799414334..32dd4d9f1d 100644
--- a/src/qt/addresstablemodel.h
+++ b/src/qt/addresstablemodel.h
@@ -15,7 +15,8 @@ public:
enum ColumnIndex {
Label = 0, /* User specified label */
- Address = 1 /* Bitcoin address */
+ Address = 1, /* Bitcoin address */
+ IsDefaultAddress = 2 /* Is default address? */
};
enum {
@@ -37,18 +38,25 @@ 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);
+ 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);
/* Update address list from core. Invalidates any indices.
*/
void updateList();
+
private:
AddressTablePriv *priv;
QStringList columns;
+
signals:
+ void defaultAddressChanged(const QString &address);
public slots:
-
+ void update();
};
#endif // ADDRESSTABLEMODEL_H
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index 2dfcd40df3..bc986dcf9f 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -14,6 +14,7 @@
#include "editaddressdialog.h"
#include "optionsmodel.h"
#include "transactiondescdialog.h"
+#include "addresstablemodel.h"
#include "main.h"
@@ -188,8 +189,8 @@ void BitcoinGUI::setModel(ClientModel *model)
setNumBlocks(model->getNumBlocks());
connect(model, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
- setAddress(model->getAddress());
- connect(model, SIGNAL(addressChanged(QString)), this, SLOT(setAddress(QString)));
+ setAddress(model->getAddressTableModel()->getDefaultAddress());
+ connect(model->getAddressTableModel(), SIGNAL(defaultAddressChanged(QString)), this, SLOT(setAddress(QString)));
// Report errors from network/worker thread
connect(model, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
@@ -329,11 +330,6 @@ void BitcoinGUI::newAddressClicked()
if(dlg.exec())
{
QString newAddress = dlg.saveCurrentRow();
- // Set returned address as new default addres
- if(!newAddress.isEmpty())
- {
- model->setAddress(newAddress);
- }
}
}
diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp
index 86fc8b32d3..4e6a34c79f 100644
--- a/src/qt/clientmodel.cpp
+++ b/src/qt/clientmodel.cpp
@@ -27,19 +27,6 @@ qint64 ClientModel::getBalance() const
return GetBalance();
}
-QString ClientModel::getAddress() const
-{
- std::vector<unsigned char> vchPubKey;
- if (CWalletDB("r").ReadDefaultKey(vchPubKey))
- {
- return QString::fromStdString(PubKeyToAddress(vchPubKey));
- }
- else
- {
- return QString();
- }
-}
-
int ClientModel::getNumConnections() const
{
return vNodes.size();
@@ -63,23 +50,14 @@ int ClientModel::getNumTransactions() const
void ClientModel::update()
{
// Plainly emit all signals for now. To be more efficient this should check
- // whether the values actually changed first.
+ // whether the values actually changed first, although it'd be even better if these
+ // were events coming in from the bitcoin core.
emit balanceChanged(getBalance());
- emit addressChanged(getAddress());
emit numConnectionsChanged(getNumConnections());
emit numBlocksChanged(getNumBlocks());
emit numTransactionsChanged(getNumTransactions());
-}
-void ClientModel::setAddress(const QString &defaultAddress)
-{
- uint160 hash160;
- std::string strAddress = defaultAddress.toStdString();
- if (!AddressToHash160(strAddress, hash160))
- return;
- if (!mapPubKeys.count(hash160))
- return;
- CWalletDB().WriteDefaultKey(mapPubKeys[hash160]);
+ addressTableModel->update();
}
ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payAmount)
diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h
index 7141937441..169ed8c4c9 100644
--- a/src/qt/clientmodel.h
+++ b/src/qt/clientmodel.h
@@ -29,7 +29,6 @@ public:
TransactionTableModel *getTransactionTableModel();
qint64 getBalance() const;
- QString getAddress() const;
int getNumConnections() const;
int getNumBlocks() const;
int getNumTransactions() const;
@@ -39,8 +38,6 @@ public:
/* Return conservative estimate of total number of blocks, or 0 if unknown */
int getTotalBlocksEstimate() const;
- /* Set default address */
- void setAddress(const QString &defaultAddress);
/* Send coins */
StatusCode sendCoins(const QString &payTo, qint64 payAmount);
private:
@@ -50,7 +47,6 @@ private:
signals:
void balanceChanged(qint64 balance);
- void addressChanged(const QString &address);
void numConnectionsChanged(int count);
void numBlocksChanged(int count);
void numTransactionsChanged(int count);
diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp
index dd0541760b..58ecb49486 100644
--- a/src/qt/editaddressdialog.cpp
+++ b/src/qt/editaddressdialog.cpp
@@ -19,9 +19,11 @@ 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"));
@@ -29,6 +31,7 @@ EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) :
break;
case EditSendingAddress:
setWindowTitle(tr("Edit sending address"));
+ ui->setAsDefault->setVisible(false);
break;
}
@@ -47,6 +50,7 @@ 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)
@@ -64,7 +68,8 @@ QString EditAddressDialog::saveCurrentRow()
address = model->addRow(
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
ui->labelEdit->text(),
- ui->addressEdit->text());
+ ui->addressEdit->text(),
+ ui->setAsDefault->isChecked());
if(address.isEmpty())
{
QMessageBox::warning(this, windowTitle(),
diff --git a/src/qt/forms/editaddressdialog.ui b/src/qt/forms/editaddressdialog.ui
index f0ba28a854..ecad196429 100644
--- a/src/qt/forms/editaddressdialog.ui
+++ b/src/qt/forms/editaddressdialog.ui
@@ -53,6 +53,13 @@
</property>
</widget>
</item>
+ <item row="2" column="1">
+ <widget class="QCheckBox" name="setAsDefault">
+ <property name="text">
+ <string>Set as default address</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
<item>