[vlc-commits] addons: change i_score type and do boundary check.

Francois Cartegnie git at videolan.org
Wed Feb 19 23:13:10 CET 2014


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Feb 19 23:10:14 2014 +0100| [1edfc31a251c222628f9912442bcace7b45eb4ec] | committer: Francois Cartegnie

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)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1edfc31a251c222628f9912442bcace7b45eb4ec
---

 include/vlc_addons.h                |    3 ++-
 modules/gui/qt4/dialogs/plugins.cpp |    6 +++---
 modules/misc/addons/fsstorage.c     |   10 ++++++++--
 modules/misc/addons/vorepository.c  |    8 +++++++-
 4 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/include/vlc_addons.h b/include/vlc_addons.h
index 7b46dd5..03aa97f 100644
--- a/include/vlc_addons.h
+++ b/include/vlc_addons.h
@@ -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;
diff --git a/modules/gui/qt4/dialogs/plugins.cpp b/modules/gui/qt4/dialogs/plugins.cpp
index 97ca90d..8093c3d 100644
--- a/modules/gui/qt4/dialogs/plugins.cpp
+++ b/modules/gui/qt4/dialogs/plugins.cpp
@@ -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 );
diff --git a/modules/misc/addons/fsstorage.c b/modules/misc/addons/fsstorage.c
index c3634ca..992211c 100644
--- a/modules/misc/addons/fsstorage.c
+++ b/modules/misc/addons/fsstorage.c
@@ -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" ) )
                     {
diff --git a/modules/misc/addons/vorepository.c b/modules/misc/addons/vorepository.c
index b6b9a29..93a7065 100644
--- a/modules/misc/addons/vorepository.c
+++ b/modules/misc/addons/vorepository.c
@@ -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" ) )
                     {



More information about the vlc-commits mailing list