[grilo] [core] Use float type for rating key
- From: Iago Toral Quiroga <itoral src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo] [core] Use float type for rating key
- Date: Thu, 15 Apr 2010 09:15:23 +0000 (UTC)
commit e12ab8c7d9f3abe76adb0e84f333062650b4b502
Author: Iago Toral Quiroga <itoral igalia com>
Date: Tue Apr 13 15:45:35 2010 +0200
[core] Use float type for rating key
src/data/grl-media.c | 37 ++++++++-----------------------------
src/data/grl-media.h | 8 +++-----
2 files changed, 11 insertions(+), 34 deletions(-)
---
diff --git a/src/data/grl-media.c b/src/data/grl-media.c
index e7cdaa9..50310d1 100644
--- a/src/data/grl-media.c
+++ b/src/data/grl-media.c
@@ -90,37 +90,16 @@ grl_media_new (void)
/**
* grl_media_set_rating:
* @media: a media
- * @rating: a string with the rating number
- * @max: a string with the max rate value
+ * @rating: a rating value
+ * @max: maximum rating value
*
- * This method receives a rating and a max string, they
- * are transformed into integers and the rating value is
- * normalized.
+ * This method receives a rating and its scale and normalizes it
*/
void
-grl_media_set_rating (GrlMedia *media,
- const gchar *rating,
- const gchar *max)
+grl_media_set_rating (GrlMedia *media, gfloat rating, gfloat max)
{
- g_return_if_fail (rating != NULL);
- g_return_if_fail (max != NULL);
-
- gchar *tmp;
- gdouble rating_value = g_ascii_strtod (rating, &tmp);
- if (*tmp != '\0' || rating_value < 0) {
- g_critical ("Invalid rating value: %s", rating);
- return;
- }
- gdouble max_value = g_ascii_strtod (max, &tmp);
- if (*tmp != '\0' || max_value <= 0) {
- g_critical ("Invalid MAX value for rating: '%s'", max);
- return;
- }
-
- char value[G_ASCII_DTOSTR_BUF_SIZE];
- gdouble normalized_value = (rating_value * RATING_MAX) / max_value;
- g_ascii_formatd (value, sizeof (value), "%.2f", normalized_value);
- grl_data_set_string (GRL_DATA (media),
- GRL_METADATA_KEY_RATING,
- value);
+ gfloat normalized_value = (rating * RATING_MAX) / max;
+ grl_data_set_float (GRL_DATA (media),
+ GRL_METADATA_KEY_RATING,
+ normalized_value);
}
diff --git a/src/data/grl-media.h b/src/data/grl-media.h
index 9f1d126..627ec35 100644
--- a/src/data/grl-media.h
+++ b/src/data/grl-media.h
@@ -246,9 +246,7 @@ struct _GrlMedia
GRL_METADATA_KEY_LAST_POSITION, \
(last_position))
-void grl_media_set_rating (GrlMedia *media,
- const gchar *rating,
- const gchar *max);
+void grl_media_set_rating (GrlMedia *media, gfloat rating, gfloat max);
/**
* grl_media_get_id:
@@ -353,10 +351,10 @@ void grl_media_set_rating (GrlMedia *media,
* grl_media_get_rating:
* @data: the media object
*
- * Returns: (type utf8) (transfer none): the media's rating
+ * Returns: the media's rating
*/
#define grl_media_get_rating(data) \
- grl_data_get_string(GRL_DATA((data)), GRL_METADATA_KEY_RATING)
+ grl_data_get_float(GRL_DATA((data)), GRL_METADATA_KEY_RATING)
/**
* grl_media_get_play_count:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]