Browse Source

create new address from main gui, move address book model to client model

miguelfreitas
Wladimir J. van der Laan 14 years ago
parent
commit
2547f1f7e5
  1. 4
      gui/include/addresstablemodel.h
  2. 6
      gui/include/clientmodel.h
  3. 2
      gui/include/editaddressdialog.h
  4. 6
      gui/src/addressbookdialog.cpp
  5. 8
      gui/src/addresstablemodel.cpp
  6. 16
      gui/src/bitcoingui.cpp
  7. 13
      gui/src/clientmodel.cpp
  8. 14
      gui/src/editaddressdialog.cpp

4
gui/include/addresstablemodel.h

@ -35,9 +35,9 @@ public:
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
/* Add an address to the model. /* Add an address to the model.
Returns true on success, false otherwise. Returns the added address on success, and an empty string otherwise.
*/ */
bool addRow(const QString &type, const QString &label, const QString &address); QString addRow(const QString &type, const QString &label, const QString &address);
/* Update address list from core. Invalidates any indices. /* Update address list from core. Invalidates any indices.
*/ */

6
gui/include/clientmodel.h

@ -2,7 +2,9 @@
#define CLIENTMODEL_H #define CLIENTMODEL_H
#include <QObject> #include <QObject>
class OptionsModel; class OptionsModel;
class AddressTableModel;
class ClientModel : public QObject class ClientModel : public QObject
{ {
@ -22,6 +24,7 @@ public:
}; };
OptionsModel *getOptionsModel(); OptionsModel *getOptionsModel();
AddressTableModel *getAddressTableModel();
qint64 getBalance(); qint64 getBalance();
QString getAddress(); QString getAddress();
@ -34,7 +37,8 @@ public:
/* Send coins */ /* Send coins */
StatusCode sendCoins(const QString &payTo, qint64 payAmount); StatusCode sendCoins(const QString &payTo, qint64 payAmount);
private: private:
OptionsModel *options_model; OptionsModel *optionsModel;
AddressTableModel *addressTableModel;
signals: signals:
void balanceChanged(qint64 balance); void balanceChanged(qint64 balance);

2
gui/include/editaddressdialog.h

@ -29,7 +29,7 @@ public:
void setModel(AddressTableModel *model); void setModel(AddressTableModel *model);
void loadRow(int row); void loadRow(int row);
void saveCurrentRow(); QString saveCurrentRow();
private: private:
Ui::EditAddressDialog *ui; Ui::EditAddressDialog *ui;

6
gui/src/addressbookdialog.cpp

@ -14,9 +14,6 @@ AddressBookDialog::AddressBookDialog(QWidget *parent) :
model(0) model(0)
{ {
ui->setupUi(this); ui->setupUi(this);
model = new AddressTableModel(this);
setModel(model);
} }
AddressBookDialog::~AddressBookDialog() AddressBookDialog::~AddressBookDialog()
@ -26,6 +23,9 @@ AddressBookDialog::~AddressBookDialog()
void AddressBookDialog::setModel(AddressTableModel *model) void AddressBookDialog::setModel(AddressTableModel *model)
{ {
/* Refresh list from core */
model->updateList();
/* Receive filter */ /* Receive filter */
QSortFilterProxyModel *receive_model = new QSortFilterProxyModel(this); QSortFilterProxyModel *receive_model = new QSortFilterProxyModel(this);
receive_model->setSourceModel(model); receive_model->setSourceModel(model);

8
gui/src/addresstablemodel.cpp

@ -191,7 +191,7 @@ void AddressTableModel::updateList()
endResetModel(); endResetModel();
} }
bool AddressTableModel::addRow(const QString &type, const QString &label, const QString &address) 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();
@ -203,7 +203,7 @@ bool AddressTableModel::addRow(const QString &type, const QString &label, const
{ {
if(mapAddressBook.count(strAddress)) if(mapAddressBook.count(strAddress))
{ {
return false; return QString();
} }
} }
} else if(type == Receive) } else if(type == Receive)
@ -212,12 +212,12 @@ bool AddressTableModel::addRow(const QString &type, const QString &label, const
strAddress = PubKeyToAddress(GetKeyFromKeyPool()); strAddress = PubKeyToAddress(GetKeyFromKeyPool());
} else } else
{ {
return false; return QString();
} }
/* Add entry and update list */ /* Add entry and update list */
SetAddressBookName(strAddress, strLabel); SetAddressBookName(strAddress, strLabel);
updateList(); updateList();
return true; return QString::fromStdString(strAddress);
} }
bool AddressTableModel::removeRows(int row, int count, const QModelIndex & parent) bool AddressTableModel::removeRows(int row, int count, const QModelIndex & parent)

16
gui/src/bitcoingui.cpp

@ -11,6 +11,7 @@
#include "aboutdialog.h" #include "aboutdialog.h"
#include "clientmodel.h" #include "clientmodel.h"
#include "guiutil.h" #include "guiutil.h"
#include "editaddressdialog.h"
#include "main.h" #include "main.h"
@ -239,6 +240,7 @@ void BitcoinGUI::sendcoinsClicked()
void BitcoinGUI::addressbookClicked() void BitcoinGUI::addressbookClicked()
{ {
AddressBookDialog dlg; AddressBookDialog dlg;
dlg.setModel(model->getAddressTableModel());
dlg.setTab(AddressBookDialog::SendingTab); dlg.setTab(AddressBookDialog::SendingTab);
dlg.exec(); dlg.exec();
} }
@ -246,6 +248,7 @@ void BitcoinGUI::addressbookClicked()
void BitcoinGUI::receivingAddressesClicked() void BitcoinGUI::receivingAddressesClicked()
{ {
AddressBookDialog dlg; AddressBookDialog dlg;
dlg.setModel(model->getAddressTableModel());
dlg.setTab(AddressBookDialog::ReceivingTab); dlg.setTab(AddressBookDialog::ReceivingTab);
dlg.exec(); dlg.exec();
} }
@ -265,8 +268,17 @@ void BitcoinGUI::aboutClicked()
void BitcoinGUI::newAddressClicked() void BitcoinGUI::newAddressClicked()
{ {
qDebug() << "New address clicked"; EditAddressDialog dlg(EditAddressDialog::NewReceivingAddress);
/* TODO: generate new address */ dlg.setModel(model->getAddressTableModel());
if(dlg.exec())
{
QString newAddress = dlg.saveCurrentRow();
/* Set returned address as new default address */
if(!newAddress.isEmpty())
{
model->setAddress(newAddress);
}
}
} }
void BitcoinGUI::copyClipboardClicked() void BitcoinGUI::copyClipboardClicked()

13
gui/src/clientmodel.cpp

@ -2,11 +2,12 @@
#include "main.h" #include "main.h"
#include "guiconstants.h" #include "guiconstants.h"
#include "optionsmodel.h" #include "optionsmodel.h"
#include "addresstablemodel.h"
#include <QTimer> #include <QTimer>
ClientModel::ClientModel(QObject *parent) : ClientModel::ClientModel(QObject *parent) :
QObject(parent), options_model(0) QObject(parent), optionsModel(0), addressTableModel(0)
{ {
/* Until we build signal notifications into the bitcoin core, /* Until we build signal notifications into the bitcoin core,
simply update everything using a timer. simply update everything using a timer.
@ -15,7 +16,8 @@ ClientModel::ClientModel(QObject *parent) :
connect(timer, SIGNAL(timeout()), this, SLOT(update())); connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(MODEL_UPDATE_DELAY); timer->start(MODEL_UPDATE_DELAY);
options_model = new OptionsModel(this); optionsModel = new OptionsModel(this);
addressTableModel = new AddressTableModel(this);
} }
qint64 ClientModel::getBalance() qint64 ClientModel::getBalance()
@ -128,5 +130,10 @@ ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payA
OptionsModel *ClientModel::getOptionsModel() OptionsModel *ClientModel::getOptionsModel()
{ {
return options_model; return optionsModel;
}
AddressTableModel *ClientModel::getAddressTableModel()
{
return addressTableModel;
} }

14
gui/src/editaddressdialog.cpp

@ -54,16 +54,18 @@ void EditAddressDialog::loadRow(int row)
mapper->setCurrentIndex(row); mapper->setCurrentIndex(row);
} }
void EditAddressDialog::saveCurrentRow() QString EditAddressDialog::saveCurrentRow()
{ {
QString address;
switch(mode) switch(mode)
{ {
case NewReceivingAddress: case NewReceivingAddress:
case NewSendingAddress: case NewSendingAddress:
if(!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());
if(address.isEmpty())
{ {
QMessageBox::warning(this, windowTitle(), QMessageBox::warning(this, windowTitle(),
tr("The address %1 is already in the address book.").arg(ui->addressEdit->text()), tr("The address %1 is already in the address book.").arg(ui->addressEdit->text()),
@ -72,7 +74,11 @@ void EditAddressDialog::saveCurrentRow()
break; break;
case EditReceivingAddress: case EditReceivingAddress:
case EditSendingAddress: case EditSendingAddress:
mapper->submit(); if(mapper->submit())
{
address = ui->addressEdit->text();
}
break; break;
} }
return address;
} }

Loading…
Cancel
Save