Wladimir J. van der Laan
14 years ago
7 changed files with 144 additions and 13 deletions
@ -0,0 +1,31 @@
@@ -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
|
@ -0,0 +1,58 @@
@@ -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 new issue