Added active exchanges parser

This commit is contained in:
Andre Jochems
2015-11-26 14:30:24 +01:00
parent f7a752473b
commit 849a807d38
14 changed files with 653 additions and 447 deletions

23
QmlImports.qml Normal file
View File

@@ -0,0 +1,23 @@
import QtQuick 2.0
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.1
import QtQuick.Window 2.1
import QtQuick.Controls.Styles 1.2
/*
QmlImports.qml
Declaration of QML Imports required by project.
This is necessary if we want to keep qml files in a folder
separate from .pro file because of the way qmlimportscanner works.
If these imports are not declared, qmake will not recognize them,
and QtQuick will not be packaged with statically built apps and imported
at runtime.
This must be kept in the same directory as your .pro file
*/
QtObject {}

View File

@@ -0,0 +1,14 @@
// This file is autogenerated by qmake. It imports static plugin classes for
// static plugins used by QML imports.
#include <QtPlugin>
Q_IMPORT_PLUGIN(QtQuick2Plugin)
Q_IMPORT_PLUGIN(QtQuickControlsPlugin)
Q_IMPORT_PLUGIN(QtQuick2DialogsPlugin)
Q_IMPORT_PLUGIN(QtQuickLayoutsPlugin)
Q_IMPORT_PLUGIN(QtQuick2WindowPlugin)
Q_IMPORT_PLUGIN(QmlFolderListModelPlugin)
Q_IMPORT_PLUGIN(QmlSettingsPlugin)
Q_IMPORT_PLUGIN(QtQuick2DialogsPrivatePlugin)
Q_IMPORT_PLUGIN(QtQuickExtrasPlugin)
Q_IMPORT_PLUGIN(QtQmlModelsPlugin)
Q_IMPORT_PLUGIN(QtQuick2PrivateWidgetsPlugin)

View File

@@ -88,8 +88,8 @@ void CasinoCoinWebAPIParser::ParseCasinos( const QJsonObject& a_rJsonCasinos )
void CasinoCoinWebAPIParser::ParseExchanges( const QJsonObject& a_rJsonExchanges ) void CasinoCoinWebAPIParser::ParseExchanges( const QJsonObject& a_rJsonExchanges )
{ {
qDebug() << "Coming soon - ParseExchanges"; qDebug() << "ParseExchanges";
qDebug() << a_rJsonExchanges; emit signalActiveExchangesParsed( new JsonActiveExchangesParser( a_rJsonExchanges ) );
} }
void CasinoCoinWebAPIParser::ParseNewsItems( const QJsonObject& a_rJsonNewsItems ) void CasinoCoinWebAPIParser::ParseNewsItems( const QJsonObject& a_rJsonNewsItems )

View File

@@ -6,6 +6,8 @@
#include "jsonactivepromotionsparser.h" #include "jsonactivepromotionsparser.h"
#include "jsonsingleactivepromotion.h" #include "jsonsingleactivepromotion.h"
#include "jsoncoininfoparser.h" #include "jsoncoininfoparser.h"
#include "jsonactiveexchangesparser.h"
#include "jsonsingleactiveexchange.h"
#include <QNetworkReply> #include <QNetworkReply>
@@ -20,7 +22,7 @@ signals:
void signalActivePromotionsParsed( JsonActivePromotionsParser* a_pActivePromotions ); void signalActivePromotionsParsed( JsonActivePromotionsParser* a_pActivePromotions );
void signalCoinInfoParsed( JsonCoinInfoParser* a_pCoinInfo ); void signalCoinInfoParsed( JsonCoinInfoParser* a_pCoinInfo );
// void signalActiveCasinosParsed( JsonActiveCasinosParser* a_pActivePromotions ); // void signalActiveCasinosParsed( JsonActiveCasinosParser* a_pActivePromotions );
// void signalActiveExchangesParsed( JsonActiveExchangesParser* a_pActivePromotions ); void signalActiveExchangesParsed( JsonActiveExchangesParser* a_pActiveExchanges );
// void signalActiveNewsItemsParsed( JsonActiveNewsItemsParser* a_pActivePromotions ); // void signalActiveNewsItemsParsed( JsonActiveNewsItemsParser* a_pActivePromotions );
public slots: public slots:

View File

@@ -0,0 +1,54 @@
#include "jsonactiveexchangesparser.h"
#include "../qtquick_controls/cpp/qmlimageprovider.h"
#include <QDebug>
JsonActiveExchangesParser::JsonActiveExchangesParser()
{
}
JsonActiveExchangesParser::JsonActiveExchangesParser( const QJsonObject& a_rOther )
: QJsonObject( a_rOther )
{
ResolveExchangesArray();
}
void JsonActiveExchangesParser::ResolveExchangesArray()
{
if ( find( "Result" ).value().isObject() )
{
if ( find( "Result" ).value().toObject().find( "ActiveExchanges" ).value().isArray() )
{
QJsonArray arrayOfExchangeDescriptors( find( "Result" ).value().toObject().find( "ActiveExchanges" ).value().toArray() );
foreach( QJsonValue singleExchangeDescriptor, arrayOfExchangeDescriptors )
{
if ( singleExchangeDescriptor.isObject() )
{
m_aActiveExchanges.append( JsonSingleActiveExchange( singleExchangeDescriptor.toObject() ) );
}
}
}
}
}
const QList<JsonSingleActiveExchange>& JsonActiveExchangesParser::GetExchanges() const
{
return m_aActiveExchanges;
}
QList<JsonSingleActiveExchange>& JsonActiveExchangesParser::GetExchanges()
{
return m_aActiveExchanges;
}
void JsonActiveExchangesParser::AddImagesToPool( QmlImageProvider* a_pImageProvider )
{
if ( a_pImageProvider )
{
foreach( JsonSingleActiveExchange oExchange, m_aActiveExchanges )
{
a_pImageProvider->AddToImagePool( oExchange.getImageName(), oExchange.getExchangeImage() );
}
}
}

View File

@@ -0,0 +1,31 @@
#ifndef JSONACTIVEEXCHANGESPARSER_H
#define JSONACTIVEEXCHANGESPARSER_H
#include <QJsonObject>
#include <QJsonValue>
#include <QJsonArray>
#include <QList>
#include "jsonsingleactiveexchange.h"
class QmlImageProvider;
class JsonActiveExchangesParser : public QJsonObject
{
public:
JsonActiveExchangesParser();
JsonActiveExchangesParser( const QJsonObject& a_rOther );
virtual ~JsonActiveExchangesParser(){}
const QList<JsonSingleActiveExchange>& GetExchanges() const;
QList<JsonSingleActiveExchange>& GetExchanges();
void AddImagesToPool( QmlImageProvider* a_pImageProvider );
private:
void ResolveExchangesArray();
QList<JsonSingleActiveExchange> m_aActiveExchanges;
};
#endif // JSONACTIVEEXCHANGESPARSER_H

View File

@@ -0,0 +1,42 @@
#include "jsonsingleactiveexchange.h"
#include <QFile>
#include <QImage>
#include <QDir>
#include <QDebug>
JsonSingleActiveExchange::JsonSingleActiveExchange()
{
}
JsonSingleActiveExchange::JsonSingleActiveExchange( const QJsonObject& a_rOther )
: QJsonObject( a_rOther )
{
m_strImageName = find( "exchange_name" ).value().toString().remove( getRestrictedCharacters() );
storeImage();
m_strExchangeName = find( "exchange_name" ).value().toString().remove( getRestrictedCharacters() );
m_strAccessUrl = find( "access_url" ).value().toString();
m_strDescription = find( "description" ).value().toString();
m_dblLastBidPriceBTC = find( "last_bid_price_btc" ).value().toDouble();
m_dblLastAskPriceBTC = find( "last_ask_price_btc" ).value().toDouble();
m_dblLastPriceBTC = find( "last_price_btc" ).value().toDouble();
m_dblVolume24H = find( "volume24h" ).value().toDouble();
m_strLastUpdateTime = find( "last_update_time" ).value().toString();
}
QRegExp JsonSingleActiveExchange::getRestrictedCharacters()
{
return QRegExp( "[<,>|\\:()&;#?*% ]" );
}
void JsonSingleActiveExchange::storeImage()
{
if ( find( "image_mime_type" ).value().toString().split( "/" ).first().contains( "image" ) )
{
QByteArray binaryData = QByteArray::fromBase64( find( "exchange_image" ).value().toString().toLocal8Bit() );
m_oExchangeImage = QImage::fromData( binaryData );
}
}

View File

@@ -0,0 +1,46 @@
#ifndef JSONSINGLEACTIVEEXCHANGE_H
#define JSONSINGLEACTIVEEXCHANGE_H
#include <QJsonObject>
#include <QJsonValue>
#include <QJsonArray>
#include <QImage>
class JsonSingleActiveExchange : public QJsonObject
{
public:
JsonSingleActiveExchange();
JsonSingleActiveExchange( const QJsonObject& a_rOther );
virtual ~JsonSingleActiveExchange(){}
QString getImageName() const{ return m_strImageName; }
QImage getExchangeImage() const { return m_oExchangeImage; }
QString getExchangeName() const{ return m_strExchangeName; }
QString getAccessUrl() const{ return m_strAccessUrl; }
QString getDescription() const{ return m_strDescription; }
double getLastBidPriceBTC() const{ return m_dblLastBidPriceBTC; }
double getLastAskPriceBTC() const{ return m_dblLastAskPriceBTC; }
double getLastPriceBTC() const{ return m_dblLastBidPriceBTC; }
double getVolume24H() const{ return m_dblVolume24H; }
QString getLastUpdateTime() const{ return m_strLastUpdateTime; }
private:
void storeImage();
static QRegExp getRestrictedCharacters();
QString m_strImageName;
QImage m_oExchangeImage;
QString m_strExchangeName;
QString m_strAccessUrl;
QString m_strDescription;
double m_dblLastBidPriceBTC;
double m_dblLastAskPriceBTC;
double m_dblLastPriceBTC;
double m_dblVolume24H;
QString m_strLastUpdateTime;
};
#endif // JSONSINGLEACTIVEEXCHANGE_H

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>800</width>
<height>500</height> <height>600</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -159,31 +159,6 @@
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>343</width>
<height>217</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QFormLayout" name="formCoinDetails"> <layout class="QFormLayout" name="formCoinDetails">
@@ -607,8 +582,6 @@
</layout> </layout>
</item> </item>
</layout> </layout>
</widget>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@@ -83,6 +83,14 @@
</item> </item>
<item row="4" column="1"> <item row="4" column="1">
<widget class="QPushButton" name="butRedeem"> <widget class="QPushButton" name="butRedeem">
<property name="styleSheet">
<string notr="true">background-color: rgb(166, 27, 31);
color: rgb(255, 255, 255);
pressed
{
background-color: rgb(166, 27, 31);
}</string>
</property>
<property name="text"> <property name="text">
<string>Redeem</string> <string>Redeem</string>
</property> </property>
@@ -91,7 +99,10 @@
<normaloff>:/icons/res/icons/prypto.png</normaloff>:/icons/res/icons/prypto.png</iconset> <normaloff>:/icons/res/icons/prypto.png</normaloff>:/icons/res/icons/prypto.png</iconset>
</property> </property>
<property name="autoDefault"> <property name="autoDefault">
<bool>false</bool> <bool>true</bool>
</property>
<property name="default">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>

View File

@@ -730,11 +730,11 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color: rgb(170, 28, 33); <string notr="true">background-color: rgb(166, 27, 31);
color: rgb(255, 255, 255); color: rgb(255, 255, 255);
pressed pressed
{ {
background-color: rgb(170, 28, 33); background-color: rgb(166, 27, 31);
}</string> }</string>
</property> </property>
<property name="text"> <property name="text">

View File

@@ -5,6 +5,7 @@
#include <QSsl> #include <QSsl>
#include <QMessageBox> #include <QMessageBox>
#include <QDebug> #include <QDebug>
#include <QListIterator>
const QString PryptoPage::strAPIEndpoint = "https://prypto.com/merchants/api/"; const QString PryptoPage::strAPIEndpoint = "https://prypto.com/merchants/api/";
const QString PryptoPage::strMerchantToken = "35616ab118fa557b77fdac78ef09d5632d302609"; const QString PryptoPage::strMerchantToken = "35616ab118fa557b77fdac78ef09d5632d302609";
@@ -18,6 +19,7 @@ PryptoPage::PryptoPage(QWidget *parent) :
connect( &networkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(parseAPINetworkResponse(QNetworkReply*)) ); connect( &networkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(parseAPINetworkResponse(QNetworkReply*)) );
connect( this, SIGNAL(apiResponseReady(QByteArray)), this, SLOT(showAPIResult(QByteArray)) ); connect( this, SIGNAL(apiResponseReady(QByteArray)), this, SLOT(showAPIResult(QByteArray)) );
connect( this, SIGNAL(apiNetworkError(QNetworkReply::NetworkError)), this, SLOT(showAPINetworkError(QNetworkReply::NetworkError)) ); connect( this, SIGNAL(apiNetworkError(QNetworkReply::NetworkError)), this, SLOT(showAPINetworkError(QNetworkReply::NetworkError)) );
connect( &networkAccessManager, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError> & )), this, SLOT(sslErrorHandler(QNetworkReply*, const QList<QSslError> & )));
} }
void PryptoPage::setWalletModel(WalletModel *model) void PryptoPage::setWalletModel(WalletModel *model)
@@ -82,6 +84,12 @@ void PryptoPage::parseAPINetworkResponse( QNetworkReply *finished )
emit apiResponseReady( data ); emit apiResponseReady( data );
} }
void PryptoPage::sslErrorHandler(QNetworkReply* qnr, const QList<QSslError> & errlist)
{
qDebug() << "---PryptoPage::sslErrorHandler: ";
qnr->ignoreSslErrors();
}
void PryptoPage::showAPINetworkError(QNetworkReply::NetworkError error) void PryptoPage::showAPINetworkError(QNetworkReply::NetworkError error)
{ {
qDebug() << "PryptoPage::showAPINetworkError: " << error; qDebug() << "PryptoPage::showAPINetworkError: " << error;

View File

@@ -6,6 +6,7 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
#include <QProgressDialog> #include <QProgressDialog>
#include <QList>
class WalletModel; class WalletModel;
@@ -31,6 +32,7 @@ private slots:
void parseAPINetworkResponse( QNetworkReply *finished ); void parseAPINetworkResponse( QNetworkReply *finished );
void showAPIResult(QByteArray data); void showAPIResult(QByteArray data);
void showAPINetworkError(QNetworkReply::NetworkError error); void showAPINetworkError(QNetworkReply::NetworkError error);
void sslErrorHandler(QNetworkReply* qnr, const QList<QSslError> & errlist);
private: private:
static const QString strAPIEndpoint; static const QString strAPIEndpoint;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 26 KiB