Commit 1edfc31a authored by François Cartegnie's avatar François Cartegnie 🤞
Browse files

addons: change i_score type and do boundary check.

Use hundredths for that 0..5 value.
(avoids dealing with locale separators in xml readers
and writers)
parent 881548c3
......@@ -54,6 +54,7 @@ typedef enum addon_flags_t
ADDON_UPDATABLE = 1 << 2,
} addon_flags_t;
#define ADDON_MAX_SCORE (5 * 100)
#define ADDON_UUID_SIZE 16
#define ADDON_UUID_PSZ_SIZE (ADDON_UUID_SIZE * 2 + 4)
typedef uint8_t addon_uuid_t[ADDON_UUID_SIZE];
......@@ -86,7 +87,7 @@ struct addon_entry_t
/* stats */
long int i_downloads;
long int i_score;
int i_score; /* score 0..5 in hundredth */
/* Lister */
char *psz_source_module;
......
......@@ -748,7 +748,7 @@ QVariant AddonsListModel::Addon::data( int role ) const
returnval = QVariant( (double) p_entry->i_downloads );
break;
case ScoreRole:
returnval = QVariant( (double) p_entry->i_score );
returnval = QVariant( (int) p_entry->i_score );
break;
case VersionRole:
returnval = QVariant( p_entry->psz_version );
......@@ -1031,13 +1031,13 @@ void AddonItemDelegate::paint( QPainter *painter,
textrect.translate( 0, newopt.fontMetrics.height() );
/* Score */
double i_score = index.data( AddonsListModel::ScoreRole ).toDouble();
int i_score = index.data( AddonsListModel::ScoreRole ).toInt();
QPixmap scoreicon;
if ( i_score )
{
scoreicon = QPixmap( ":/addons/score" ).scaledToHeight(
newopt.fontMetrics.height(), Qt::SmoothTransformation );
int i_width = ( i_score / 5.0 ) * scoreicon.width();
int i_width = ( (float) i_score / ADDON_MAX_SCORE ) * scoreicon.width();
/* Erase the end (value) of our pixmap with a shadow */
QPainter erasepainter( &scoreicon );
erasepainter.setCompositionMode( QPainter::CompositionMode_SourceIn );
......
......@@ -593,7 +593,7 @@ static int WriteCatalog( addons_storage_t *p_storage,
char *psz_uuid = addons_uuid_to_psz( ( const addon_uuid_t * ) & p_entry->uuid );
fprintf( p_catalog, "\t\t<addon source=\"%s\" type=\"%s\" id=\"%s\" "
"downloads=\"%ld\" score=\"%ld\"",
"downloads=\"%ld\" score=\"%d\"",
( psz_tempstring ) ? psz_tempstring : "",
getTypePsz( p_entry->e_type ),
psz_uuid,
......@@ -746,10 +746,16 @@ static int LoadCatalog( addons_finder_t *p_finder )
else if ( !strcmp( attr, "downloads" ) )
{
p_entry->i_downloads = atoi( value );
if ( p_entry->i_downloads < 0 )
p_entry->i_downloads = 0;
}
else if ( !strcmp( attr, "score" ) )
{
p_entry->i_score = atol( value );
p_entry->i_score = atoi( value );
if ( p_entry->i_score < 0 )
p_entry->i_score = 0;
else if ( p_entry->i_score > ADDON_MAX_SCORE )
p_entry->i_score = ADDON_MAX_SCORE;
}
else if ( !strcmp( attr, "source" ) )
{
......
......@@ -249,10 +249,16 @@ static int ParseCategoriesInfo( addons_finder_t *p_finder, stream_t *p_stream )
else if ( !strcmp( attr, "downloads" ) )
{
p_entry->i_downloads = atoi( value );
if ( p_entry->i_downloads < 0 )
p_entry->i_downloads = 0;
}
else if ( !strcmp( attr, "score" ) )
{
p_entry->i_score = atol( value );
p_entry->i_score = atoi( value );
if ( p_entry->i_score < 0 )
p_entry->i_score = 0;
else if ( p_entry->i_score > ADDON_MAX_SCORE )
p_entry->i_score = ADDON_MAX_SCORE;
}
else if ( !strcmp( attr, "version" ) )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment