mirror of
https://github.com/AskDavis/Casinotest.git
synced 2026-01-10 06:39:46 -08:00
Adverts widget v0.2 added:
*Querying webAPI for adverts content; *Starting browsers new tab with url specified in json file *Basic QML items and models *Overview tab layout changes *Storing images on harddrive (temporary solution) *Sending queries to webAPI straight from widget (temporary solution) coming next: -store whole json file as url/desription need to be stored for further use -display images of adverts from QImage, not from file stored on harddrive -hide/show adverts button tweaking -proper webAPI base class for querying various servers for data (prypto for instance) *
This commit is contained in:
52
src/qt/CSCPublicAPI/casinocoinwebapi.cpp
Normal file
52
src/qt/CSCPublicAPI/casinocoinwebapi.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "casinocoinwebapi.h"
|
||||
|
||||
#include <QSsl>
|
||||
|
||||
const QString CasinoCoinWebAPI::s_strServerAddress = "http://119.81.188.59/";
|
||||
const QString CasinoCoinWebAPI::s_strServerEndpoint = "CSCPublicAPI";
|
||||
|
||||
CasinoCoinWebAPI::CasinoCoinWebAPI( QObject*a_pParent )
|
||||
: QObject(a_pParent )
|
||||
{
|
||||
connect( &m_oNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotParseNetworkResponse(QNetworkReply*)));
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPI::GetActivePromotions()
|
||||
{
|
||||
Get( s_strServerAddress + "/" + s_strServerEndpoint + "/ActivePromotions" );
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPI::GetActiveCasinos()
|
||||
{
|
||||
Get( s_strServerAddress + "/" + s_strServerEndpoint + "/ActiveCasinos" );
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPI::GetActiveNewsItems()
|
||||
{
|
||||
Get( s_strServerAddress + "/" + s_strServerEndpoint + "/ActiveNewsItems" );
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPI::GetActiveExchanges()
|
||||
{
|
||||
Get( s_strServerAddress + "/" + s_strServerEndpoint + "/ActiveExchanges" );
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPI::Get( const QString& a_rUrl )
|
||||
{
|
||||
QUrl oUrl ( a_rUrl );
|
||||
QNetworkRequest oNetworkRequest ( oUrl );
|
||||
m_oNetworkAccessManager.get( oNetworkRequest );
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPI::slotParseNetworkResponse( QNetworkReply *finished )
|
||||
{
|
||||
if ( finished->error() != QNetworkReply::NoError )
|
||||
{
|
||||
// A communication error has occurred
|
||||
emit signalNetworkError( finished->error() );
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray data = finished->readAll();
|
||||
emit signalResponseReady( data );
|
||||
}
|
||||
37
src/qt/CSCPublicAPI/casinocoinwebapi.h
Normal file
37
src/qt/CSCPublicAPI/casinocoinwebapi.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef CASINOCOINWEBAPI_H
|
||||
#define CASINOCOINWEBAPI_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
|
||||
class CasinoCoinWebAPI : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CasinoCoinWebAPI( QObject* a_pParent = 0 );
|
||||
virtual ~CasinoCoinWebAPI(){}
|
||||
|
||||
void GetActivePromotions();
|
||||
void GetActiveCasinos();
|
||||
void GetActiveNewsItems();
|
||||
void GetActiveExchanges();
|
||||
|
||||
static const QString s_strServerAddress;
|
||||
static const QString s_strServerEndpoint;
|
||||
|
||||
signals:
|
||||
void signalResponseReady( const QByteArray& a_rJsonFile );
|
||||
void signalNetworkError( QNetworkReply::NetworkError a_eError );
|
||||
|
||||
public slots:
|
||||
void slotParseNetworkResponse( QNetworkReply *finished );
|
||||
|
||||
private:
|
||||
void Get( const QString& a_rUrl );
|
||||
|
||||
QNetworkAccessManager m_oNetworkAccessManager;
|
||||
};
|
||||
|
||||
#endif // CASINOCOINWEBAPI_H
|
||||
66
src/qt/CSCPublicAPI/casinocoinwebapiparser.cpp
Normal file
66
src/qt/CSCPublicAPI/casinocoinwebapiparser.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "casinocoinwebapiparser.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
CasinoCoinWebAPIParser::CasinoCoinWebAPIParser( QObject* a_pParent )
|
||||
: QObject(a_pParent)
|
||||
{
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPIParser::slotParseAnswer( const QByteArray& a_rJsonFile )
|
||||
{
|
||||
QJsonParseError oError;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson( a_rJsonFile, &oError );
|
||||
if ( oError.error == QJsonParseError::NoError )
|
||||
{
|
||||
QJsonObject docAsObject = jsonDoc.object();
|
||||
if ( docAsObject.find( "Result" ).value().isObject() )
|
||||
{
|
||||
QJsonObject jsonObjectResult = docAsObject.find( "Result" ).value().toObject();
|
||||
if ( jsonObjectResult.find( "ActivePromotions" ).value().isArray() )
|
||||
{
|
||||
ParsePromotions( docAsObject );
|
||||
}
|
||||
else if ( jsonObjectResult.find( "ActiveNewsItems" ).value().isArray() )
|
||||
{
|
||||
ParseNewsItems( docAsObject );
|
||||
}
|
||||
else if ( jsonObjectResult.find( "ActiveCasinos" ).value().isArray() )
|
||||
{
|
||||
ParseCasinos( docAsObject );
|
||||
}
|
||||
else if ( jsonObjectResult.find( "ActiveExchanges" ).value().isArray() )
|
||||
{
|
||||
ParseExchanges( docAsObject );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPIParser::ParsePromotions( const QJsonObject& a_rJsonPromotions )
|
||||
{
|
||||
qDebug() << "ParsePromotions";
|
||||
emit signalActivePromotionsParsed( new JsonActivePromotionsParser( a_rJsonPromotions ) );
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPIParser::ParseCasinos( const QJsonObject& a_rJsonCasinos )
|
||||
{
|
||||
qDebug() << "Coming soon - ParseCasinos";
|
||||
qDebug() << a_rJsonCasinos;
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPIParser::ParseExchanges( const QJsonObject& a_rJsonExchanges )
|
||||
{
|
||||
qDebug() << "Coming soon - ParseExchanges";
|
||||
qDebug() << a_rJsonExchanges;
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPIParser::ParseNewsItems( const QJsonObject& a_rJsonNewsItems )
|
||||
{
|
||||
qDebug() << "Coming soon - ParseNewsItems";
|
||||
qDebug() << a_rJsonNewsItems;
|
||||
}
|
||||
32
src/qt/CSCPublicAPI/casinocoinwebapiparser.h
Normal file
32
src/qt/CSCPublicAPI/casinocoinwebapiparser.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef CASINOCOINWEBAPIPARSER_H
|
||||
#define CASINOCOINWEBAPIPARSER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "jsonactivepromotionsparser.h"
|
||||
#include "jsonsingleactivepromotion.h"
|
||||
|
||||
class CasinoCoinWebAPIParser : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CasinoCoinWebAPIParser( QObject* a_pParent = 0 );
|
||||
|
||||
|
||||
signals:
|
||||
void signalActivePromotionsParsed( JsonActivePromotionsParser* a_pActivePromotions );
|
||||
// void signalActiveCasinosParsed( JsonActiveCasinosParser* a_pActivePromotions );
|
||||
// void signalActiveExchangesParsed( JsonActiveExchangesParser* a_pActivePromotions );
|
||||
// void signalActiveNewsItemsParsed( JsonActiveNewsItemsParser* a_pActivePromotions );
|
||||
|
||||
public slots:
|
||||
void slotParseAnswer( const QByteArray& a_rJsonFile );
|
||||
|
||||
private:
|
||||
void ParsePromotions( const QJsonObject& a_rJsonPromotions );
|
||||
void ParseCasinos ( const QJsonObject& a_rJsonCasinos );
|
||||
void ParseExchanges ( const QJsonObject& a_rJsonExchanges );
|
||||
void ParseNewsItems ( const QJsonObject& a_rJsonNewsItems );
|
||||
};
|
||||
|
||||
#endif // CASINOCOINWEBAPIPARSER_H
|
||||
42
src/qt/CSCPublicAPI/jsonactivepromotionsparser.cpp
Normal file
42
src/qt/CSCPublicAPI/jsonactivepromotionsparser.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "jsonactivepromotionsparser.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
JsonActivePromotionsParser::JsonActivePromotionsParser()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
JsonActivePromotionsParser::JsonActivePromotionsParser( const QJsonObject& a_rOther )
|
||||
: QJsonObject( a_rOther )
|
||||
{
|
||||
ResolvePromotionsArray();
|
||||
}
|
||||
|
||||
void JsonActivePromotionsParser::ResolvePromotionsArray()
|
||||
{
|
||||
if ( find( "Result" ).value().isObject() )
|
||||
{
|
||||
if ( find( "Result" ).value().toObject().find( "ActivePromotions" ).value().isArray() )
|
||||
{
|
||||
QJsonArray arrayOfCasinoDescriptors( find( "Result" ).value().toObject().find( "ActivePromotions" ).value().toArray() );
|
||||
foreach( QJsonValue singleCasinoDescriptor, arrayOfCasinoDescriptors )
|
||||
{
|
||||
if ( singleCasinoDescriptor.isObject() )
|
||||
{
|
||||
m_aActiveCasinos.append( JsonSingleActivePromotion( singleCasinoDescriptor.toObject() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const QList<JsonSingleActivePromotion>& JsonActivePromotionsParser::GetPromotions() const
|
||||
{
|
||||
return m_aActiveCasinos;
|
||||
}
|
||||
|
||||
QList<JsonSingleActivePromotion>& JsonActivePromotionsParser::GetPromotions()
|
||||
{
|
||||
return m_aActiveCasinos;
|
||||
}
|
||||
27
src/qt/CSCPublicAPI/jsonactivepromotionsparser.h
Normal file
27
src/qt/CSCPublicAPI/jsonactivepromotionsparser.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef JSONACTIVEPROMOTIONSPARSER_H
|
||||
#define JSONACTIVEPROMOTIONSPARSER_H
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QJsonArray>
|
||||
#include <QList>
|
||||
|
||||
#include "jsonsingleactivepromotion.h"
|
||||
|
||||
class JsonActivePromotionsParser : public QJsonObject
|
||||
{
|
||||
public:
|
||||
JsonActivePromotionsParser();
|
||||
JsonActivePromotionsParser( const QJsonObject& a_rOther );
|
||||
virtual ~JsonActivePromotionsParser(){}
|
||||
|
||||
const QList<JsonSingleActivePromotion>& GetPromotions() const;
|
||||
QList<JsonSingleActivePromotion>& GetPromotions();
|
||||
private:
|
||||
|
||||
void ResolvePromotionsArray();
|
||||
|
||||
QList<JsonSingleActivePromotion> m_aActiveCasinos;
|
||||
};
|
||||
|
||||
#endif // JSONACTIVEPROMOTIONSPARSER_H
|
||||
53
src/qt/CSCPublicAPI/jsonsingleactivepromotion.cpp
Normal file
53
src/qt/CSCPublicAPI/jsonsingleactivepromotion.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "jsonsingleactivepromotion.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QImage>
|
||||
#include <QDir>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
JsonSingleActivePromotion::JsonSingleActivePromotion()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
JsonSingleActivePromotion::JsonSingleActivePromotion( const QJsonObject& a_rOther )
|
||||
: QJsonObject( a_rOther )
|
||||
{
|
||||
StoreImage();
|
||||
}
|
||||
|
||||
QString JsonSingleActivePromotion::GetImagePath() const
|
||||
{
|
||||
return QString( "file://" + QDir::currentPath() + "/" + GetImageRelativePath() );
|
||||
}
|
||||
|
||||
QString JsonSingleActivePromotion::GetImageRelativePath() const
|
||||
{
|
||||
return QString( "adverts/" + find( "promotion_title" ).value().toString().remove( " " ) + "." + find( "image_mime_type" ).value().toString().split( "/" ).last() );
|
||||
}
|
||||
|
||||
QString JsonSingleActivePromotion::StoreImage()
|
||||
{
|
||||
QString strReturn = QString();
|
||||
if ( find( "image_mime_type" ).value().toString().split( "/" ).first().contains( "image" ) )
|
||||
{
|
||||
QString strFileName = GetImageRelativePath();
|
||||
QByteArray binaryData = QByteArray::fromBase64( find( "promotion_image" ).value().toString().toLocal8Bit() );
|
||||
|
||||
if ( !QDir( "adverts" ).exists() )
|
||||
{
|
||||
QDir().mkdir( "adverts" );
|
||||
}
|
||||
QFile imageOutputFile( strFileName );
|
||||
QImage outputImage = QImage::fromData( binaryData, "JPEG" );
|
||||
if ( imageOutputFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
|
||||
{
|
||||
outputImage.save( &imageOutputFile, 0 );
|
||||
imageOutputFile.close();
|
||||
strReturn = strFileName;
|
||||
}
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
22
src/qt/CSCPublicAPI/jsonsingleactivepromotion.h
Normal file
22
src/qt/CSCPublicAPI/jsonsingleactivepromotion.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef JSONSINGLEACTIVEPROMOTION_H
|
||||
#define JSONSINGLEACTIVEPROMOTION_H
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QJsonArray>
|
||||
|
||||
class JsonSingleActivePromotion : public QJsonObject
|
||||
{
|
||||
public:
|
||||
JsonSingleActivePromotion();
|
||||
JsonSingleActivePromotion( const QJsonObject& a_rOther );
|
||||
virtual ~JsonSingleActivePromotion(){}
|
||||
|
||||
QString GetImagePath() const;
|
||||
|
||||
private:
|
||||
QString GetImageRelativePath() const;
|
||||
QString StoreImage();
|
||||
};
|
||||
|
||||
#endif // JSONSINGLEACTIVEPROMOTION_H
|
||||
Reference in New Issue
Block a user