[libgdata] youtube: Simplify video ratings handling code



commit 3ca4fbcc88dbf26a1edda79fbad9e819a11ae82d
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Wed Jul 8 15:31:53 2015 +0100

    youtube: Simplify video ratings handling code
    
    This simplifies the code and fixes a problem where if both
    region_restriction_allowed and region_restriction_blocked were not
    spcified, the GDataYouTubeVideo would behave as if restricted for all
    regions, which is most likely not the intention.

 gdata/services/youtube/gdata-youtube-video.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/gdata/services/youtube/gdata-youtube-video.c b/gdata/services/youtube/gdata-youtube-video.c
index dbcef6e..06d346f 100644
--- a/gdata/services/youtube/gdata-youtube-video.c
+++ b/gdata/services/youtube/gdata-youtube-video.c
@@ -1748,16 +1748,28 @@ gboolean
 gdata_youtube_video_is_restricted_in_country (GDataYouTubeVideo *self, const gchar *country)
 {
        GDataYouTubeVideoPrivate *priv;
+       gboolean allowed_present, allowed_empty;
+       gboolean blocked_present, blocked_empty;
+       gboolean in_allowed, in_blocked;
 
        g_return_val_if_fail (GDATA_IS_YOUTUBE_VIDEO (self), FALSE);
        g_return_val_if_fail (country != NULL && *country != '\0', FALSE);
 
        priv = self->priv;
 
-       return (!strv_contains ((const gchar * const *) priv->region_restriction_allowed, country) &&
-               (strv_contains ((const gchar * const *) priv->region_restriction_blocked, country) ||
-                priv->region_restriction_allowed == NULL ||
-                priv->region_restriction_allowed[0] == NULL));
+       allowed_present = (priv->region_restriction_allowed != NULL);
+       allowed_empty = (allowed_present &&
+                        priv->region_restriction_allowed[0] == NULL);
+       blocked_present = (priv->region_restriction_blocked != NULL);
+       blocked_empty = (blocked_present &&
+                        priv->region_restriction_blocked[0] == NULL);
+
+       in_allowed = strv_contains ((const gchar * const *) priv->region_restriction_allowed, country);
+       in_blocked = strv_contains ((const gchar * const *) priv->region_restriction_blocked, country);
+
+       return ((allowed_present && !in_allowed) ||
+               allowed_empty ||
+               (in_blocked && !in_allowed));
 }
 
 /* References:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]