core initialisation, client model binding
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
* W.J. van der Laan 2011
|
||||
*/
|
||||
#include "bitcoingui.h"
|
||||
#include "clientmodel.h"
|
||||
#include "util.h"
|
||||
#include "init.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
@@ -10,19 +12,29 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
/* Testing on testnet */
|
||||
fTestNet = true;
|
||||
try {
|
||||
if(AppInit2(argc, argv))
|
||||
{
|
||||
ClientModel model;
|
||||
BitcoinGUI window;
|
||||
window.setModel(&model);
|
||||
|
||||
BitcoinGUI window;
|
||||
window.setBalance(1234.567890);
|
||||
window.setNumConnections(4);
|
||||
window.setNumTransactions(4);
|
||||
window.setNumBlocks(33);
|
||||
window.setAddress("123456789");
|
||||
window.show();
|
||||
|
||||
window.show();
|
||||
/* Depending on settings: QApplication::setQuitOnLastWindowClosed(false); */
|
||||
int retval = app.exec();
|
||||
|
||||
/* Depending on settings: QApplication::setQuitOnLastWindowClosed(false); */
|
||||
Shutdown(NULL);
|
||||
|
||||
return app.exec();
|
||||
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 "optionsdialog.h"
|
||||
#include "aboutdialog.h"
|
||||
#include "clientmodel.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
@@ -139,6 +140,26 @@ void BitcoinGUI::createActions()
|
||||
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()
|
||||
{
|
||||
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());
|
||||
}
|
||||
Reference in New Issue
Block a user