core initialisation, client model binding
This commit is contained in:
parent
ad88e7626b
commit
18cab09a95
7 changed files with 144 additions and 13 deletions
|
@ -4,6 +4,7 @@ DEPENDPATH += .
|
||||||
INCLUDEPATH += gui/include core/include cryptopp/include json/include
|
INCLUDEPATH += gui/include core/include cryptopp/include json/include
|
||||||
unix:LIBS += -lssl -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -ldb_cxx
|
unix:LIBS += -lssl -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -ldb_cxx
|
||||||
macx:DEFINES += __WXMAC_OSX__ MSG_NOSIGNAL=0
|
macx:DEFINES += __WXMAC_OSX__ MSG_NOSIGNAL=0
|
||||||
|
# WINDOWS defines, -DSSL, look at build system
|
||||||
|
|
||||||
# Input
|
# Input
|
||||||
HEADERS += gui/include/bitcoingui.h \
|
HEADERS += gui/include/bitcoingui.h \
|
||||||
|
@ -51,7 +52,9 @@ HEADERS += gui/include/bitcoingui.h \
|
||||||
json/include/json/json_spirit_reader.h \
|
json/include/json/json_spirit_reader.h \
|
||||||
json/include/json/json_spirit_error_position.h \
|
json/include/json/json_spirit_error_position.h \
|
||||||
json/include/json/json_spirit.h \
|
json/include/json/json_spirit.h \
|
||||||
core/include/rpc.h
|
core/include/rpc.h \
|
||||||
|
gui/src/clientmodel.h \
|
||||||
|
gui/include/clientmodel.h
|
||||||
SOURCES += gui/src/bitcoin.cpp gui/src/bitcoingui.cpp \
|
SOURCES += gui/src/bitcoin.cpp gui/src/bitcoingui.cpp \
|
||||||
gui/src/transactiontablemodel.cpp \
|
gui/src/transactiontablemodel.cpp \
|
||||||
gui/src/addresstablemodel.cpp \
|
gui/src/addresstablemodel.cpp \
|
||||||
|
@ -74,7 +77,8 @@ SOURCES += gui/src/bitcoin.cpp gui/src/bitcoingui.cpp \
|
||||||
core/src/db.cpp \
|
core/src/db.cpp \
|
||||||
json/src/json_spirit_writer.cpp \
|
json/src/json_spirit_writer.cpp \
|
||||||
json/src/json_spirit_value.cpp \
|
json/src/json_spirit_value.cpp \
|
||||||
json/src/json_spirit_reader.cpp
|
json/src/json_spirit_reader.cpp \
|
||||||
|
gui/src/clientmodel.cpp
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
gui/bitcoin.qrc
|
gui/bitcoin.qrc
|
||||||
|
|
|
@ -513,9 +513,11 @@ bool AppInit2(int argc, char* argv[])
|
||||||
SetStartOnSystemStartup(true);
|
SetStartOnSystemStartup(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
#ifndef GUI
|
#ifndef GUI
|
||||||
while (1)
|
while (1)
|
||||||
Sleep(5000);
|
Sleep(5000);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
class TransactionTableModel;
|
class TransactionTableModel;
|
||||||
|
class ClientModel;
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QLabel;
|
class QLabel;
|
||||||
|
@ -17,6 +18,7 @@ class BitcoinGUI : public QMainWindow
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit BitcoinGUI(QWidget *parent = 0);
|
explicit BitcoinGUI(QWidget *parent = 0);
|
||||||
|
void setModel(ClientModel *model);
|
||||||
|
|
||||||
/* Transaction table tab indices */
|
/* Transaction table tab indices */
|
||||||
enum {
|
enum {
|
||||||
|
@ -27,6 +29,7 @@ public:
|
||||||
} TabIndex;
|
} TabIndex;
|
||||||
private:
|
private:
|
||||||
TransactionTableModel *transaction_model;
|
TransactionTableModel *transaction_model;
|
||||||
|
ClientModel *model;
|
||||||
|
|
||||||
QLineEdit *address;
|
QLineEdit *address;
|
||||||
QLabel *labelBalance;
|
QLabel *labelBalance;
|
||||||
|
|
31
gui/include/clientmodel.h
Normal file
31
gui/include/clientmodel.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef CLIENTMODEL_H
|
||||||
|
#define CLIENTMODEL_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class ClientModel : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ClientModel(QObject *parent = 0);
|
||||||
|
|
||||||
|
double getBalance();
|
||||||
|
QString getAddress();
|
||||||
|
int getNumConnections();
|
||||||
|
int getNumBlocks();
|
||||||
|
int getNumTransactions();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void balanceChanged(double balance);
|
||||||
|
void addressChanged(const QString &address);
|
||||||
|
void numConnectionsChanged(int count);
|
||||||
|
void numBlocksChanged(int count);
|
||||||
|
void numTransactionsChanged(int count);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void update();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CLIENTMODEL_H
|
|
@ -2,7 +2,9 @@
|
||||||
* W.J. van der Laan 2011
|
* W.J. van der Laan 2011
|
||||||
*/
|
*/
|
||||||
#include "bitcoingui.h"
|
#include "bitcoingui.h"
|
||||||
|
#include "clientmodel.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "init.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
|
@ -10,19 +12,29 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
/* Testing on testnet */
|
try {
|
||||||
fTestNet = true;
|
if(AppInit2(argc, argv))
|
||||||
|
{
|
||||||
|
ClientModel model;
|
||||||
BitcoinGUI window;
|
BitcoinGUI window;
|
||||||
window.setBalance(1234.567890);
|
window.setModel(&model);
|
||||||
window.setNumConnections(4);
|
|
||||||
window.setNumTransactions(4);
|
|
||||||
window.setNumBlocks(33);
|
|
||||||
window.setAddress("123456789");
|
|
||||||
|
|
||||||
window.show();
|
window.show();
|
||||||
|
|
||||||
/* Depending on settings: QApplication::setQuitOnLastWindowClosed(false); */
|
/* Depending on settings: QApplication::setQuitOnLastWindowClosed(false); */
|
||||||
|
int retval = app.exec();
|
||||||
|
|
||||||
return app.exec();
|
Shutdown(NULL);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
PrintException(&e, "Runaway exception");
|
||||||
|
} catch (...) {
|
||||||
|
PrintException(NULL, "Runaway exception");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "sendcoinsdialog.h"
|
#include "sendcoinsdialog.h"
|
||||||
#include "optionsdialog.h"
|
#include "optionsdialog.h"
|
||||||
#include "aboutdialog.h"
|
#include "aboutdialog.h"
|
||||||
|
#include "clientmodel.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
@ -139,6 +140,26 @@ void BitcoinGUI::createActions()
|
||||||
connect(about, SIGNAL(triggered()), this, SLOT(aboutClicked()));
|
connect(about, SIGNAL(triggered()), this, SLOT(aboutClicked()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BitcoinGUI::setModel(ClientModel *model)
|
||||||
|
{
|
||||||
|
this->model = model;
|
||||||
|
|
||||||
|
setBalance(model->getBalance());
|
||||||
|
connect(model, SIGNAL(balanceChanged(double)), this, SLOT(setBalance(double)));
|
||||||
|
|
||||||
|
setNumConnections(model->getNumConnections());
|
||||||
|
connect(model, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
|
||||||
|
|
||||||
|
setNumTransactions(model->getNumTransactions());
|
||||||
|
connect(model, SIGNAL(numTransactionsChanged(int)), this, SLOT(setNumTransactions(int)));
|
||||||
|
|
||||||
|
setNumBlocks(model->getNumBlocks());
|
||||||
|
connect(model, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
|
||||||
|
|
||||||
|
setAddress(model->getAddress());
|
||||||
|
connect(model, SIGNAL(addressChanged(QString)), this, SLOT(setAddress(QString)));
|
||||||
|
}
|
||||||
|
|
||||||
void BitcoinGUI::createTrayIcon()
|
void BitcoinGUI::createTrayIcon()
|
||||||
{
|
{
|
||||||
QMenu *trayIconMenu = new QMenu(this);
|
QMenu *trayIconMenu = new QMenu(this);
|
||||||
|
|
58
gui/src/clientmodel.cpp
Normal file
58
gui/src/clientmodel.cpp
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#include "clientmodel.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
/* milliseconds between model updates */
|
||||||
|
const int MODEL_UPDATE_DELAY = 250;
|
||||||
|
|
||||||
|
ClientModel::ClientModel(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
/* Until we build signal notifications into the bitcoin core,
|
||||||
|
simply update everything using a timer.
|
||||||
|
*/
|
||||||
|
QTimer *timer = new QTimer(this);
|
||||||
|
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
|
||||||
|
timer->start(MODEL_UPDATE_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
double ClientModel::getBalance()
|
||||||
|
{
|
||||||
|
return GetBalance();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ClientModel::getAddress()
|
||||||
|
{
|
||||||
|
std::vector<unsigned char> vchPubKey;
|
||||||
|
if (CWalletDB("r").ReadDefaultKey(vchPubKey))
|
||||||
|
{
|
||||||
|
return QString::fromStdString(PubKeyToAddress(vchPubKey));
|
||||||
|
} else {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ClientModel::getNumConnections()
|
||||||
|
{
|
||||||
|
return vNodes.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ClientModel::getNumBlocks()
|
||||||
|
{
|
||||||
|
return nBestHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ClientModel::getNumTransactions()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClientModel::update()
|
||||||
|
{
|
||||||
|
emit balanceChanged(getBalance());
|
||||||
|
emit addressChanged(getAddress());
|
||||||
|
emit numConnectionsChanged(getNumConnections());
|
||||||
|
emit numBlocksChanged(getNumBlocks());
|
||||||
|
emit numTransactionsChanged(getNumTransactions());
|
||||||
|
}
|
Loading…
Reference in a new issue