Adverts widget supports population from web and from local files.

This commit is contained in:
felixrojauro
2015-11-01 19:19:03 +01:00
parent 5a3b2dbce6
commit 85a611ed19
16 changed files with 167 additions and 116 deletions

View File

@@ -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;
}