mirror of
https://github.com/AskDavis/Casinotest.git
synced 2026-01-03 12:29:46 -08:00
Adverts widget supports population from web and from local files.
This commit is contained in:
@@ -14,40 +14,21 @@ JsonSingleActivePromotion::JsonSingleActivePromotion()
|
||||
JsonSingleActivePromotion::JsonSingleActivePromotion( const QJsonObject& a_rOther )
|
||||
: QJsonObject( a_rOther )
|
||||
{
|
||||
m_strImageName = find( "promotion_title" ).value().toString().remove( GetRestrictedCharacters() );
|
||||
StoreImage();
|
||||
}
|
||||
|
||||
QString JsonSingleActivePromotion::GetImagePath() const
|
||||
QRegExp JsonSingleActivePromotion::GetRestrictedCharacters()
|
||||
{
|
||||
return QString( "file://" + QDir::currentPath() + "/" + GetImageRelativePath() );
|
||||
return QRegExp( "[<,>|\\:()&;#?*% ]" );
|
||||
}
|
||||
|
||||
QString JsonSingleActivePromotion::GetImageRelativePath() const
|
||||
void JsonSingleActivePromotion::StoreImage()
|
||||
{
|
||||
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;
|
||||
}
|
||||
m_oAdvertImage = QImage::fromData( binaryData );
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user