diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-06-03 21:03:20 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-06-03 21:18:05 +0200 |
commit | 2547f1f7e5dd6cb6397152047b67c4b2d4981c6b (patch) | |
tree | ba58edb6c2e7fae7a807086c35e30764953e498a | |
parent | 9d9a4e874db82e63a2b876c9f490be7247856282 (diff) |
create new address from main gui, move address book model to client model
-rw-r--r-- | gui/include/addresstablemodel.h | 4 | ||||
-rw-r--r-- | gui/include/clientmodel.h | 6 | ||||
-rw-r--r-- | gui/include/editaddressdialog.h | 2 | ||||
-rw-r--r-- | gui/src/addressbookdialog.cpp | 6 | ||||
-rw-r--r-- | gui/src/addresstablemodel.cpp | 8 | ||||
-rw-r--r-- | gui/src/bitcoingui.cpp | 16 | ||||
-rw-r--r-- | gui/src/clientmodel.cpp | 13 | ||||
-rw-r--r-- | gui/src/editaddressdialog.cpp | 14 |
8 files changed, 49 insertions, 20 deletions
diff --git a/gui/include/addresstablemodel.h b/gui/include/addresstablemodel.h index 1890260971..8799414334 100644 --- a/gui/include/addresstablemodel.h +++ b/gui/include/addresstablemodel.h @@ -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. */ diff --git a/gui/include/clientmodel.h b/gui/include/clientmodel.h index 01c0d70fc7..d68b34fe96 100644 --- a/gui/include/clientmodel.h +++ b/gui/include/clientmodel.h @@ -2,7 +2,9 @@ #define CLIENTMODEL_H #include <QObject> + class OptionsModel; +class AddressTableModel; class ClientModel : public QObject { @@ -22,6 +24,7 @@ public: }; OptionsModel *getOptionsModel(); + AddressTableModel *getAddressTableModel(); qint64 getBalance(); QString getAddress(); @@ -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); diff --git a/gui/include/editaddressdialog.h b/gui/include/editaddressdialog.h index dd7766951b..6f396d0457 100644 --- a/gui/include/editaddressdialog.h +++ b/gui/include/editaddressdialog.h @@ -29,7 +29,7 @@ public: void setModel(AddressTableModel *model); void loadRow(int row); - void saveCurrentRow(); + QString saveCurrentRow(); private: Ui::EditAddressDialog *ui; diff --git a/gui/src/addressbookdialog.cpp b/gui/src/addressbookdialog.cpp index 9b9e9bbc8e..35078d3aea 100644 --- a/gui/src/addressbookdialog.cpp +++ b/gui/src/addressbookdialog.cpp @@ -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() void AddressBookDialog::setModel(AddressTableModel *model) { + /* Refresh list from core */ + model->updateList(); + /* Receive filter */ QSortFilterProxyModel *receive_model = new QSortFilterProxyModel(this); receive_model->setSourceModel(model); diff --git a/gui/src/addresstablemodel.cpp b/gui/src/addresstablemodel.cpp index fbb2eb528b..1cbc1b5d1d 100644 --- a/gui/src/addresstablemodel.cpp +++ b/gui/src/addresstablemodel.cpp @@ -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 { 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 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) diff --git a/gui/src/bitcoingui.cpp b/gui/src/bitcoingui.cpp index ba5b1d99a8..5996496036 100644 --- a/gui/src/bitcoingui.cpp +++ b/gui/src/bitcoingui.cpp @@ -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() void BitcoinGUI::addressbookClicked() { AddressBookDialog dlg; + dlg.setModel(model->getAddressTableModel()); dlg.setTab(AddressBookDialog::SendingTab); dlg.exec(); } @@ -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() 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() diff --git a/gui/src/clientmodel.cpp b/gui/src/clientmodel.cpp index 7dcbc576a4..497f8dc3d2 100644 --- a/gui/src/clientmodel.cpp +++ b/gui/src/clientmodel.cpp @@ -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) : 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 OptionsModel *ClientModel::getOptionsModel() { - return options_model; + return optionsModel; +} + +AddressTableModel *ClientModel::getAddressTableModel() +{ + return addressTableModel; } diff --git a/gui/src/editaddressdialog.cpp b/gui/src/editaddressdialog.cpp index ddc7292cc6..dd0541760b 100644 --- a/gui/src/editaddressdialog.cpp +++ b/gui/src/editaddressdialog.cpp @@ -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() break; case EditReceivingAddress: case EditSendingAddress: - mapper->submit(); + if(mapper->submit()) + { + address = ui->addressEdit->text(); + } break; } + return address; } |