2015-07-10 21:37:22 +00:00
|
|
|
#include "ClientDataModel.hpp"
|
|
|
|
|
|
2015-07-13 17:56:30 +00:00
|
|
|
#include <graphene/app/api.hpp>
|
|
|
|
|
#include <graphene/chain/protocol/protocol.hpp>
|
|
|
|
|
|
|
|
|
|
#include <fc/rpc/websocket_api.hpp>
|
|
|
|
|
|
2015-07-13 18:14:58 +00:00
|
|
|
using namespace graphene::app;
|
|
|
|
|
|
2015-07-13 17:56:30 +00:00
|
|
|
ChainDataModel::ChainDataModel( fc::thread& t, QObject* parent )
|
|
|
|
|
:QObject(parent),m_thread(&t){}
|
2015-07-10 21:37:22 +00:00
|
|
|
|
2015-07-13 17:19:07 +00:00
|
|
|
Account* ChainDataModel::getAccount(quint64 id) const
|
2015-07-10 21:37:22 +00:00
|
|
|
{
|
|
|
|
|
auto acct = new Account;
|
|
|
|
|
acct->setProperty("id", id);
|
|
|
|
|
acct->setProperty("name", "joe");
|
|
|
|
|
return acct;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 17:19:07 +00:00
|
|
|
Account*ChainDataModel::getAccount(QString name) const
|
2015-07-10 21:37:22 +00:00
|
|
|
{
|
|
|
|
|
auto acct = new Account;
|
|
|
|
|
acct->setProperty("id", 800);
|
|
|
|
|
acct->setProperty("name", name);
|
|
|
|
|
return acct;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QQmlListProperty<Balance> Account::balances()
|
|
|
|
|
{
|
|
|
|
|
return QQmlListProperty<Balance>(this, m_balances);
|
|
|
|
|
}
|
2015-07-13 17:24:30 +00:00
|
|
|
|
2015-07-13 17:56:30 +00:00
|
|
|
GrapheneApplication::GrapheneApplication( QObject* parent )
|
|
|
|
|
:QObject( parent ),m_thread("app")
|
|
|
|
|
{
|
2015-07-13 18:14:58 +00:00
|
|
|
connect( this, &GrapheneApplication::queueExecute,
|
|
|
|
|
this, &GrapheneApplication::execute );
|
|
|
|
|
|
2015-07-13 17:56:30 +00:00
|
|
|
m_model = new ChainDataModel( m_thread, this );
|
|
|
|
|
}
|
2015-07-13 18:14:58 +00:00
|
|
|
|
2015-07-13 17:56:30 +00:00
|
|
|
GrapheneApplication::~GrapheneApplication()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 18:14:58 +00:00
|
|
|
void GrapheneApplication::setIsConnected( bool v )
|
|
|
|
|
{
|
|
|
|
|
if( v != m_isConnected )
|
|
|
|
|
{
|
|
|
|
|
m_isConnected = v;
|
|
|
|
|
Q_EMIT isConnectedChanged( m_isConnected );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 18:35:17 +00:00
|
|
|
void GrapheneApplication::start( QString apiurl, QString user, QString pass )
|
2015-07-13 17:24:30 +00:00
|
|
|
{
|
2015-07-13 17:56:30 +00:00
|
|
|
if( !m_thread.is_current() )
|
|
|
|
|
{
|
2015-07-13 18:35:17 +00:00
|
|
|
m_done = m_thread.async( [=](){ return start( apiurl, user, pass ); } );
|
2015-07-13 18:14:58 +00:00
|
|
|
return;
|
2015-07-13 17:56:30 +00:00
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
auto con = m_client.connect( apiurl.toStdString() );
|
|
|
|
|
auto apic = std::make_shared<fc::rpc::websocket_api_connection>(*con);
|
2015-07-13 18:14:58 +00:00
|
|
|
auto remote_api = apic->get_remote_api< login_api >(1);
|
2015-07-13 17:56:30 +00:00
|
|
|
|
2015-07-13 18:14:58 +00:00
|
|
|
if( !remote_api->login( user.toStdString(), pass.toStdString() ) )
|
|
|
|
|
{
|
|
|
|
|
// TODO: emit error
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-13 17:56:30 +00:00
|
|
|
|
2015-07-13 18:14:58 +00:00
|
|
|
queueExecute( [=](){setIsConnected( true );} );
|
2015-07-13 17:56:30 +00:00
|
|
|
} catch ( const fc::exception& e )
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2015-07-13 18:14:58 +00:00
|
|
|
}
|
|
|
|
|
Q_SLOT void GrapheneApplication::execute( const std::function<void()>& func )const
|
|
|
|
|
{
|
|
|
|
|
func();
|
2015-07-13 17:24:30 +00:00
|
|
|
}
|