Browse Source

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

pull/1/head
Wladimir J. van der Laan 12 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: @@ -35,9 +35,9 @@ public:
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
/* 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.
*/

6
gui/include/clientmodel.h

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

2
gui/include/editaddressdialog.h

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

6
gui/src/addressbookdialog.cpp

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

8
gui/src/addresstablemodel.cpp

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

16
gui/src/bitcoingui.cpp

@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
#include "aboutdialog.h"
#include "clientmodel.h"
#include "guiutil.h"
#include "editaddressdialog.h"
#include "main.h"
@ -239,6 +240,7 @@ void BitcoinGUI::sendcoinsClicked() @@ -239,6 +240,7 @@ void BitcoinGUI::sendcoinsClicked()
void BitcoinGUI::addressbookClicked()
{
AddressBookDialog dlg;
dlg.setModel(model->getAddressTableModel());
dlg.setTab(AddressBookDialog::SendingTab);
dlg.exec();
}
@ -246,6 +248,7 @@ void BitcoinGUI::addressbookClicked() @@ -246,6 +248,7 @@ void BitcoinGUI::addressbookClicked()
void BitcoinGUI::receivingAddressesClicked()
{
AddressBookDialog dlg;
dlg.setModel(model->getAddressTableModel());
dlg.setTab(AddressBookDialog::ReceivingTab);
dlg.exec();
}
@ -265,8 +268,17 @@ void BitcoinGUI::aboutClicked() @@ -265,8 +268,17 @@ void BitcoinGUI::aboutClicked()
void BitcoinGUI::newAddressClicked()
{
qDebug() << "New address clicked";
/* TODO: generate new address */
EditAddressDialog dlg(EditAddressDialog::NewReceivingAddress);
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()

13
gui/src/clientmodel.cpp

@ -2,11 +2,12 @@ @@ -2,11 +2,12 @@
#include "main.h"
#include "guiconstants.h"
#include "optionsmodel.h"
#include "addresstablemodel.h"
#include <QTimer>
ClientModel::ClientModel(QObject *parent) :
QObject(parent), options_model(0)
QObject(parent), optionsModel(0), addressTableModel(0)
{
/* Until we build signal notifications into the bitcoin core,
simply update everything using a timer.
@ -15,7 +16,8 @@ ClientModel::ClientModel(QObject *parent) : @@ -15,7 +16,8 @@ ClientModel::ClientModel(QObject *parent) :
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(MODEL_UPDATE_DELAY);
options_model = new OptionsModel(this);
optionsModel = new OptionsModel(this);
addressTableModel = new AddressTableModel(this);
}
qint64 ClientModel::getBalance()
@ -128,5 +130,10 @@ ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payA @@ -128,5 +130,10 @@ ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payA
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) @@ -54,16 +54,18 @@ void EditAddressDialog::loadRow(int row)
mapper->setCurrentIndex(row);
}
void EditAddressDialog::saveCurrentRow()
QString EditAddressDialog::saveCurrentRow()
{
QString address;
switch(mode)
{
case NewReceivingAddress:
case NewSendingAddress:
if(!model->addRow(
address = model->addRow(
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
ui->labelEdit->text(),
ui->addressEdit->text()))
ui->addressEdit->text());
if(address.isEmpty())
{
QMessageBox::warning(this, windowTitle(),
tr("The address %1 is already in the address book.").arg(ui->addressEdit->text()),
@ -72,7 +74,11 @@ void EditAddressDialog::saveCurrentRow() @@ -72,7 +74,11 @@ void EditAddressDialog::saveCurrentRow()
break;
case EditReceivingAddress:
case EditSendingAddress:
mapper->submit();
if(mapper->submit())
{
address = ui->addressEdit->text();
}
break;
}
return address;
}

Loading…
Cancel
Save