commit ee45af9afbeb2c0965cab365dcc126371399e988
Author: Mathias Hasselmann <mathias@openismus.com>
Date:   Tue Oct 16 20:48:46 2012 +0200

    Add region tags for publication and certification
    
    Both TMDB and IMDB publish region specific information for this metadata.
    
    This fixes https://bugzilla.gnome.org/show_bug.cgi?id=679686

diff --git a/bindings/vala/grilo-0.2-custom.vala b/bindings/vala/grilo-0.2-custom.vala
index 9c93c0e..c48f010 100644
--- a/bindings/vala/grilo-0.2-custom.vala
+++ b/bindings/vala/grilo-0.2-custom.vala
@@ -24,10 +24,14 @@ namespace Grl {
 		public static Grl.KeyID BITRATE;
 		[CCode (cname ="GRL_METADATA_KEY_CERTIFICATE")]
 		public static Grl.KeyID CERTIFICATE;
+		[CCode (cname ="GRL_METADATA_KEY_CERTIFICATE_REGION")]
+		public static Grl.KeyID CERTIFICATE_REGION;
 		[CCode (cname ="GRL_METADATA_KEY_CHILDCOUNT")]
 		public static Grl.KeyID CHILDCOUNT;
 		[CCode (cname ="GRL_METADATA_KEY_PUBLICATION_DATE")]
 		public static Grl.KeyID PUBLICATION_DATE;
+		[CCode (cname ="GRL_METADATA_KEY_PUBLICATION_REGION")]
+		public static Grl.KeyID PUBLICATION_REGION;
 		[CCode (cname ="GRL_METADATA_KEY_DESCRIPTION")]
 		public static Grl.KeyID DESCRIPTION;
 		[CCode (cname ="GRL_METADATA_KEY_DURATION")]
diff --git a/doc/grilo/grilo-sections.txt b/doc/grilo/grilo-sections.txt
index 16313d2..e249f25 100644
--- a/doc/grilo/grilo-sections.txt
+++ b/doc/grilo/grilo-sections.txt
@@ -335,6 +335,8 @@ grl_media_add_url_data
 grl_media_get_author
 grl_media_get_author_nth
 grl_media_get_certificate
+grl_media_get_certificate_data
+grl_media_get_certificate_data_nth
 grl_media_get_creation_date
 grl_media_get_description
 grl_media_get_duration
@@ -350,6 +352,8 @@ grl_media_get_play_count
 grl_media_get_player
 grl_media_get_player_nth
 grl_media_get_publication_date
+grl_media_get_publication_data
+grl_media_get_publication_data_nth
 grl_media_get_rating
 grl_media_get_site
 grl_media_get_source
@@ -367,6 +371,8 @@ grl_media_serialize
 grl_media_serialize_extended
 grl_media_set_author
 grl_media_set_certificate
+grl_media_set_certificate_data
+grl_media_add_certificate_data
 grl_media_set_creation_date
 grl_media_set_description
 grl_media_set_duration
@@ -380,6 +386,8 @@ grl_media_set_mime
 grl_media_set_modification_date
 grl_media_set_play_count
 grl_media_set_publication_date
+grl_media_set_publication_data
+grl_media_add_publication_data
 grl_media_set_rating
 grl_media_set_site
 grl_media_set_source
@@ -586,6 +594,7 @@ GRL_METADATA_KEY_AUTHOR
 GRL_METADATA_KEY_BITRATE
 GRL_METADATA_KEY_CAMERA_MODEL
 GRL_METADATA_KEY_CERTIFICATE
+GRL_METADATA_KEY_CERTIFICATE_REGION
 GRL_METADATA_KEY_CHILDCOUNT
 GRL_METADATA_KEY_CREATION_DATE
 GRL_METADATA_KEY_DESCRIPTION
@@ -610,6 +619,7 @@ GRL_METADATA_KEY_MODIFICATION_DATE
 GRL_METADATA_KEY_ORIENTATION
 GRL_METADATA_KEY_PLAY_COUNT
 GRL_METADATA_KEY_PUBLICATION_DATE
+GRL_METADATA_KEY_PUBLICATION_REGION
 GRL_METADATA_KEY_RATING
 GRL_METADATA_KEY_SEASON
 GRL_METADATA_KEY_SHOW
diff --git a/src/data/grl-media.c b/src/data/grl-media.c
index 8672c6f..c5dbc26 100644
--- a/src/data/grl-media.c
+++ b/src/data/grl-media.c
@@ -691,6 +691,54 @@ grl_media_set_publication_date (GrlMedia *media, const GDateTime *date)
 }
 
 /**
+ * grl_media_set_publication_data:
+ * @media: a #GrlMedia
+ * @date: the date
+ * @region: the region
+ *
+ * Set the publication date of @media for @region
+ *
+ * Since: 0.2.3
+ */
+void
+grl_media_set_publication_data (GrlMedia *media, const GDateTime *date,
+                                const gchar *region)
+{
+  GrlRelatedKeys *relkeys = grl_related_keys_new ();
+  grl_related_keys_set_boxed (relkeys,
+                              GRL_METADATA_KEY_PUBLICATION_DATE,
+                              date);
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_PUBLICATION_REGION,
+                               region);
+  grl_data_set_related_keys (GRL_DATA (media), relkeys, 0);
+}
+
+/**
+ * grl_media_add_publication_data:
+ * @media: a #GrlMedia
+ * @date: the date
+ * @region: the region
+ *
+ * Add a publication date of @media for a @region
+ *
+ * Since: 0.2.3
+ */
+void
+grl_media_add_publication_data (GrlMedia *media, const GDateTime *date,
+                                const gchar *region)
+{
+  GrlRelatedKeys *relkeys = grl_related_keys_new ();
+  grl_related_keys_set_boxed (relkeys,
+                              GRL_METADATA_KEY_PUBLICATION_DATE,
+                              date);
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_PUBLICATION_REGION,
+                               region);
+  grl_data_add_related_keys (GRL_DATA (media), relkeys);
+}
+
+/**
   * grl_media_set_creation_date:
   * @media: the media
   * @creation_date: date when media was created
@@ -851,7 +899,7 @@ grl_media_set_studio (GrlMedia *media, const gchar *studio)
  * @media: the media
  * @certificate: The rating certificate of the media
  *
- * Set the media certificate
+ * Set the media's age certificatication
  *
  * Since: 0.1.6
  */
@@ -864,6 +912,54 @@ grl_media_set_certificate (GrlMedia *media, const gchar *certificate)
 }
 
 /**
+ * grl_media_set_certificate_data:
+ * @media: a #GrlMedia
+ * @certificate: The rating certificate of the media
+ * @region: the region
+ *
+ * Set the media's age certificatication for @region
+ *
+ * Since: 0.2.3
+ */
+void
+grl_media_set_certificate_data (GrlMedia *media, const gchar *certificate,
+                                const gchar *region)
+{
+  GrlRelatedKeys *relkeys = grl_related_keys_new ();
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_CERTIFICATE,
+                               certificate);
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_CERTIFICATE_REGION,
+                               region);
+  grl_data_set_related_keys (GRL_DATA (media), relkeys, 0);
+}
+
+/**
+ * grl_media_add_certificate_data:
+ * @media: a #GrlMedia
+ * @certificate: The rating certificate of the media
+ * @region: the region
+ *
+ * Adds an age certificatication for @region
+ *
+ * Since: 0.2.3
+ */
+void
+grl_media_add_certificate_data (GrlMedia *media, const gchar *certificate,
+                                const gchar *region)
+{
+  GrlRelatedKeys *relkeys = grl_related_keys_new ();
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_CERTIFICATE,
+                               certificate);
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_CERTIFICATE_REGION,
+                               region);
+  grl_data_add_related_keys (GRL_DATA (media), relkeys);
+}
+
+/**
  * grl_media_set_license:
  * @media: the media
  * @license: The license of the media
@@ -1158,6 +1254,54 @@ grl_media_get_publication_date (GrlMedia *media)
 }
 
 /**
+ * grl_media_get_publication_data:
+ * @media: the media object
+ * @region: (out) (transfer none): the region, or %NULL to ignore.
+ *
+ * Returns: (transfer none): the publication date of @media (owned by @media).
+ *
+ * Since: 0.2.3
+ */
+GDateTime *
+grl_media_get_publication_data (GrlMedia *media, const gchar **region)
+{
+  return grl_media_get_publication_data_nth (media, 0, region);
+}
+
+/**
+ * grl_media_get_publication_data_nth():
+ * @media: the media object
+ * @index: element to retrieve
+ * @region: (out) (transfer none): the region, or %NULL to ignore.
+ *
+ * Returns: (transfer none): the n-th publication date of @media
+ * (owned by @media).
+ *
+ * Since: 0.2.3
+ */
+GDateTime *
+grl_media_get_publication_data_nth (GrlMedia *media, guint index,
+                                    const gchar **region)
+{
+    GrlRelatedKeys *relkeys =
+      grl_data_get_related_keys (GRL_DATA (media),
+                                 GRL_METADATA_KEY_PUBLICATION_DATE,
+                                 index);
+
+    if (!relkeys) {
+      return NULL;
+    }
+
+    if (region) {
+      *region = grl_related_keys_get_string
+                (relkeys, GRL_METADATA_KEY_PUBLICATION_REGION);
+    }
+
+    return grl_related_keys_get_boxed (relkeys,
+                                       GRL_METADATA_KEY_PUBLICATION_DATE);
+}
+
+/**
  * grl_media_get_creation_date:
  * @media: the media
  *
@@ -1355,7 +1499,7 @@ grl_media_get_studio(GrlMedia *media)
  * grl_media_get_certificate:
  * @media: the media object
  *
- * Returns: the media's certificate
+ * Returns: the media's age certificatification
  *
  * Since: 0.1.6
  */
@@ -1366,6 +1510,52 @@ grl_media_get_certificate (GrlMedia *media)
 }
 
 /**
+ * grl_media_get_certificate_data:
+ * @media: the media object
+ * @region: (out) (transfer none): the region, or %NULL to ignore.
+ *
+ * Returns: the media's age certificatification
+ *
+ * Since: 0.2.3
+ */
+const gchar *
+grl_media_get_certificate_data (GrlMedia *media, const gchar **region)
+{
+  return grl_media_get_certificate_data_nth (media, 0, region);
+}
+
+/**
+ * grl_media_get_certificate_data_nth():
+ * @media: the media object
+ * @index: element to retrieve
+ * @region: (out) (transfer none): the region, or %NULL to ignore.
+ *
+ * Returns: the media's n-th age certificatification
+ *
+ * Since: 0.2.3
+ */
+const gchar *
+grl_media_get_certificate_data_nth (GrlMedia *media, guint index,
+                                    const gchar **region)
+{
+    GrlRelatedKeys *relkeys =
+      grl_data_get_related_keys (GRL_DATA (media),
+                                 GRL_METADATA_KEY_CERTIFICATE,
+                                 index);
+
+    if (!relkeys) {
+      return NULL;
+    }
+
+    if (region) {
+      *region = grl_related_keys_get_string
+                (relkeys, GRL_METADATA_KEY_CERTIFICATE_REGION);
+    }
+
+    return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_CERTIFICATE);
+}
+
+/**
  * grl_media_get_license:
  * @media: the media object
  *
diff --git a/src/data/grl-media.h b/src/data/grl-media.h
index 96fc20c..7d5099a 100644
--- a/src/data/grl-media.h
+++ b/src/data/grl-media.h
@@ -121,6 +121,10 @@ void grl_media_set_duration (GrlMedia *media, gint duration);
 
 void grl_media_set_publication_date (GrlMedia *media, const GDateTime *date);
 
+void grl_media_set_publication_data (GrlMedia *media, const GDateTime *date, const gchar *region);
+
+void grl_media_add_publication_data (GrlMedia *media, const GDateTime *date, const gchar *region);
+
 void grl_media_set_creation_date (GrlMedia *media,
                                   const GDateTime *creation_date);
 
@@ -143,6 +147,10 @@ void grl_media_set_studio (GrlMedia *media, const gchar *studio);
 
 void grl_media_set_certificate (GrlMedia *media, const gchar *certificate);
 
+void grl_media_set_certificate_data (GrlMedia *media, const gchar *certificate, const gchar *region);
+
+void grl_media_add_certificate_data (GrlMedia *media, const gchar *certificate, const gchar *region);
+
 void grl_media_set_license (GrlMedia *media, const gchar *license);
 
 void grl_media_set_rating (GrlMedia *media, gfloat rating, gfloat max);
@@ -193,6 +201,10 @@ gint grl_media_get_duration (GrlMedia *media);
 
 GDateTime *grl_media_get_publication_date (GrlMedia *media);
 
+GDateTime *grl_media_get_publication_data (GrlMedia *media, const gchar **region);
+
+GDateTime *grl_media_get_publication_data_nth (GrlMedia *media, guint index, const gchar **region);
+
 GDateTime *grl_media_get_creation_date (GrlMedia *media);
 
 GDateTime *grl_media_get_modification_date (GrlMedia *media);
@@ -219,6 +231,10 @@ const gchar *grl_media_get_studio (GrlMedia *media);
 
 const gchar *grl_media_get_certificate (GrlMedia *media);
 
+const gchar *grl_media_get_certificate_data (GrlMedia *media, const gchar **region);
+
+const gchar *grl_media_get_certificate_data_nth (GrlMedia *media, guint index, const gchar **region);
+
 const gchar *grl_media_get_license (GrlMedia *media);
 
 gfloat grl_media_get_start_time (GrlMedia *media);
diff --git a/src/grl-metadata-key.c b/src/grl-metadata-key.c
index a8d5075..1db3bd0 100644
--- a/src/grl-metadata-key.c
+++ b/src/grl-metadata-key.c
@@ -448,6 +448,26 @@ grl_metadata_key_setup_system_keys (GrlRegistry *registry)
                                            GRL_METADATA_KEY_START_TIME,
                                            NULL);
 
+  grl_registry_register_metadata_key_full (registry,
+                                           g_param_spec_string ("publication-region",
+                                                                "Publication Region",
+                                                                "Region in which the media was published",
+                                                                NULL,
+                                                                G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE),
+                                           GRL_METADATA_KEY_PUBLICATION_REGION,
+                                           NULL);
+
+
+  grl_registry_register_metadata_key_full (registry,
+                                           g_param_spec_string ("certificate-region",
+                                                                "Certificate Region",
+                                                                "Region for which an age certificate applies",
+                                                                NULL,
+                                                                G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE),
+                                           GRL_METADATA_KEY_CERTIFICATE_REGION,
+                                           NULL);
+
+
   /* Create the relations */
   grl_registry_register_metadata_key_relation (registry,
                                                GRL_METADATA_KEY_URL,
@@ -467,7 +487,12 @@ grl_metadata_key_setup_system_keys (GrlRegistry *registry)
   grl_registry_register_metadata_key_relation (registry,
                                                GRL_METADATA_KEY_URL,
                                                GRL_METADATA_KEY_START_TIME);
-
+  grl_registry_register_metadata_key_relation (registry,
+                                               GRL_METADATA_KEY_PUBLICATION_DATE,
+                                               GRL_METADATA_KEY_PUBLICATION_REGION);
+  grl_registry_register_metadata_key_relation (registry,
+                                               GRL_METADATA_KEY_CERTIFICATE,
+                                               GRL_METADATA_KEY_CERTIFICATE_REGION);
 }
 
 /**
diff --git a/src/grl-metadata-key.h b/src/grl-metadata-key.h
index cf09add..32781e0 100644
--- a/src/grl-metadata-key.h
+++ b/src/grl-metadata-key.h
@@ -89,6 +89,8 @@ typedef guint32 GrlKeyID;
 #define GRL_METADATA_KEY_TRACK_NUMBER         40
 #define GRL_METADATA_KEY_MODIFICATION_DATE    41
 #define GRL_METADATA_KEY_START_TIME           42
+#define GRL_METADATA_KEY_PUBLICATION_REGION   43
+#define GRL_METADATA_KEY_CERTIFICATE_REGION   44
 
 G_BEGIN_DECLS
 
