peerplays_migrated/programs/light_client/ClientDataModel.hpp

110 lines
2.4 KiB
C++
Raw Normal View History

2015-07-10 21:37:22 +00:00
#pragma once
2015-07-13 17:56:30 +00:00
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#include <fc/network/http/websocket.hpp>
#include <fc/thread/thread.hpp>
2015-07-10 21:37:22 +00:00
#include <QObject>
#include <QQmlListProperty>
2015-07-13 17:56:30 +00:00
2015-07-13 18:14:58 +00:00
Q_DECLARE_METATYPE(std::function<void()>)
2015-07-13 17:56:30 +00:00
2015-07-10 21:37:22 +00:00
class Asset : public QObject {
Q_OBJECT
Q_PROPERTY(QString symbol MEMBER symbol)
Q_PROPERTY(quint64 id MEMBER id)
Q_PROPERTY(quint8 precision MEMBER precision)
QString symbol;
quint64 id;
quint8 precision;
};
class Balance : public QObject {
Q_OBJECT
Q_PROPERTY(Asset* type MEMBER type)
Q_PROPERTY(qint64 amount MEMBER amount)
Q_PROPERTY(quint64 id MEMBER id)
Asset* type;
qint64 amount;
quint64 id;
};
class Account : public QObject {
Q_OBJECT
Q_PROPERTY(QString name MEMBER name)
Q_PROPERTY(quint64 id MEMBER id)
Q_PROPERTY(QQmlListProperty<Balance> balances READ balances)
QString name;
quint64 id;
QList<Balance*> m_balances;
public:
Account(QObject* parent = nullptr)
: QObject(parent){}
QQmlListProperty<Balance> balances();
};
2015-07-13 17:19:07 +00:00
class ChainDataModel : public QObject {
2015-07-10 21:37:22 +00:00
Q_OBJECT
public:
Q_INVOKABLE Account* getAccount(quint64 id)const;
Q_INVOKABLE Account* getAccount(QString name)const;
2015-07-13 17:56:30 +00:00
ChainDataModel(){}
ChainDataModel( fc::thread& t, QObject* parent = nullptr );
private:
fc::thread* m_thread = nullptr;
std::string m_api_url;
2015-07-10 21:37:22 +00:00
};
2015-07-13 17:19:07 +00:00
class GrapheneApplication : public QObject {
Q_OBJECT
Q_PROPERTY(ChainDataModel* model READ model CONSTANT)
Q_PROPERTY(bool isConnected READ isConnected NOTIFY isConnectedChanged)
2015-07-13 17:56:30 +00:00
fc::thread m_thread;
ChainDataModel* m_model = nullptr;
bool m_isConnected = false;
fc::http::websocket_client m_client;
2015-07-13 18:14:58 +00:00
fc::future<void> m_done;
void setIsConnected( bool v );
Q_SLOT void execute( const std::function<void()>& )const;
2015-07-13 17:19:07 +00:00
public:
2015-07-13 17:56:30 +00:00
GrapheneApplication( QObject* parent = nullptr );
~GrapheneApplication();
2015-07-13 17:19:07 +00:00
ChainDataModel* model() const
{
return m_model;
}
2015-07-13 18:14:58 +00:00
Q_INVOKABLE void start( QString dataDirectory,
QString apiUrl,
QString user,
QString pass );
2015-07-13 17:19:07 +00:00
bool isConnected() const
{
return m_isConnected;
}
signals:
void isConnectedChanged(bool isConnected);
2015-07-13 18:14:58 +00:00
void queueExecute( const std::function<void()>& );
2015-07-13 17:19:07 +00:00
};