commit bae923141b50f8bc6b94fb829b02f81167d0c0b4
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..165eac6 100644
--- a/bindings/vala/grilo-0.2-custom.vala
+++ b/bindings/vala/grilo-0.2-custom.vala
@@ -58,6 +58,8 @@ namespace Grl {
 		public static Grl.KeyID PLAY_COUNT;
 		[CCode (cname ="GRL_METADATA_KEY_RATING")]
 		public static Grl.KeyID RATING;
+		[CCode (cname ="GRL_METADATA_KEY_REGION")]
+		public static Grl.KeyID REGION;
 		[CCode (cname ="GRL_METADATA_KEY_SITE")]
 		public static Grl.KeyID SITE;
 		[CCode (cname ="GRL_METADATA_KEY_SOURCE")]
diff --git a/doc/grilo/grilo-sections.txt b/doc/grilo/grilo-sections.txt
index 16313d2..4108d74 100644
--- a/doc/grilo/grilo-sections.txt
+++ b/doc/grilo/grilo-sections.txt
@@ -350,6 +350,9 @@ grl_media_get_play_count
 grl_media_get_player
 grl_media_get_player_nth
 grl_media_get_publication_date
+grl_media_get_region
+grl_media_get_region_data
+grl_media_get_region_data_nth
 grl_media_get_rating
 grl_media_get_site
 grl_media_get_source
@@ -380,6 +383,9 @@ grl_media_set_mime
 grl_media_set_modification_date
 grl_media_set_play_count
 grl_media_set_publication_date
+grl_media_set_region
+grl_media_set_region_data
+grl_media_add_region_data
 grl_media_set_rating
 grl_media_set_site
 grl_media_set_source
@@ -611,6 +617,7 @@ GRL_METADATA_KEY_ORIENTATION
 GRL_METADATA_KEY_PLAY_COUNT
 GRL_METADATA_KEY_PUBLICATION_DATE
 GRL_METADATA_KEY_RATING
+GRL_METADATA_KEY_REGION
 GRL_METADATA_KEY_SEASON
 GRL_METADATA_KEY_SHOW
 GRL_METADATA_KEY_SITE
diff --git a/src/data/grl-media.c b/src/data/grl-media.c
index 8672c6f..594830f 100644
--- a/src/data/grl-media.c
+++ b/src/data/grl-media.c
@@ -691,6 +691,82 @@ grl_media_set_publication_date (GrlMedia *media, const GDateTime *date)
 }
 
 /**
+ * grl_media_set_region:
+ * @media: a #GrlMedia
+ * @region: the region's ISO-3166-1 code
+ *
+ * Sets the @region where @media got published.
+ *
+ * Since: 0.2.3
+ */
+void
+grl_media_set_region (GrlMedia *media,
+                      const gchar *region)
+{
+  grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_REGION, region);
+}
+
+/**
+ * grl_media_set_region_data:
+ * @media: a #GrlMedia
+ * @region: the region's ISO-3166-1 code
+ * @publication_date: the publication date
+ * @certificate: the age certification
+ *
+ * Sets regional publication and certification information for @region.
+ *
+ * Since: 0.2.3
+ */
+void
+grl_media_set_region_data (GrlMedia *media,
+                           const gchar *region,
+                           const GDateTime *publication_date,
+                           const gchar *certificate)
+{
+  GrlRelatedKeys *relkeys = grl_related_keys_new ();
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_REGION,
+                               region);
+  grl_related_keys_set_boxed (relkeys,
+                              GRL_METADATA_KEY_PUBLICATION_DATE,
+                              publication_date);
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_CERTIFICATE,
+                               certificate);
+  grl_data_set_related_keys (GRL_DATA (media), relkeys, 0);
+}
+
+/**
+ * grl_media_add_region_data:
+ * @media: a #GrlMedia
+ * @region: the region's ISO-3166-1 code
+ * @publication_date: the publication date
+ * @certificate: the age certification
+ *
+ * Adds regional publication and certification information for @region.
+ *
+ * Since: 0.2.3
+ */
+void
+grl_media_add_region_data (GrlMedia *media,
+                           const gchar *region,
+                           const GDateTime *publication_date,
+                           const gchar *certificate)
+{
+  GrlRelatedKeys *relkeys = grl_related_keys_new ();
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_REGION,
+                               region);
+  grl_related_keys_set_boxed (relkeys,
+                              GRL_METADATA_KEY_PUBLICATION_DATE,
+                              publication_date);
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_CERTIFICATE,
+                               certificate);
+  grl_data_add_related_keys (GRL_DATA (media), relkeys);
+}
+
+/**
   * grl_media_set_creation_date:
   * @media: the media
   * @creation_date: date when media was created
@@ -849,9 +925,9 @@ grl_media_set_studio (GrlMedia *media, const gchar *studio)
 /**
  * grl_media_set_certificate:
  * @media: the media
- * @certificate: The rating certificate of the media
+ * @certificate: The age certificate of the media
  *
- * Set the media certificate
+ * Set the media's age certificatication
  *
  * Since: 0.1.6
  */
@@ -1158,6 +1234,80 @@ grl_media_get_publication_date (GrlMedia *media)
 }
 
 /**
+ * grl_media_get_region:
+ * @media: the media object
+ *
+ * Returns: (transfer none): the ISO-3166-1 of the region where the media got
+ * published (owned by @media).
+ *
+ * Since: 0.2.3
+ */
+const gchar *
+grl_media_get_region (GrlMedia *media)
+{
+  return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_REGION);
+}
+
+/**
+ * grl_media_get_region_data:
+ * @media: the media object
+ * @publication_date: (out) (transfer none): the publication date, or %NULL to ignore.
+ * @certificate: (out) (transfer none): the age certification, or %NULL to ignore.
+ *
+ * Returns: (transfer none): the ISO-3166-1 of the region where the media got
+ * published (owned by @media).
+ *
+ * Since: 0.2.3
+ */
+const gchar *
+grl_media_get_region_data (GrlMedia *media,
+                           const GDateTime **publication_date,
+                           const gchar **certificate)
+{
+  return grl_media_get_region_data_nth (media, 0, publication_date,  certificate);
+}
+
+/**
+ * grl_media_get_region_data_nth:
+ * @media: the media object
+ * @index: element to retrieve
+ * @publication_date: (out) (transfer none): the publication date, or %NULL to ignore.
+ * @certificate: (out) (transfer none): the age certification, or %NULL to ignore.
+ *
+ * Returns: (transfer none): the ISO-3166-1 of the region where the media got
+ * published (owned by @media).
+ *
+ * Since: 0.2.3
+ */
+const gchar *
+grl_media_get_region_data_nth (GrlMedia *media,
+                               guint index,
+                               const GDateTime **publication_date,
+                               const gchar **certificate)
+{
+    GrlRelatedKeys *relkeys =
+      grl_data_get_related_keys (GRL_DATA (media),
+                                 GRL_METADATA_KEY_PUBLICATION_DATE,
+                                 index);
+
+    if (!relkeys) {
+      return NULL;
+    }
+
+    if (publication_date) {
+      *publication_date = grl_related_keys_get_boxed
+                (relkeys, GRL_METADATA_KEY_PUBLICATION_DATE);
+    }
+
+    if (certificate) {
+      *certificate = grl_related_keys_get_string
+                (relkeys, GRL_METADATA_KEY_CERTIFICATE);
+    }
+
+    return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_REGION);
+}
+
+/**
  * grl_media_get_creation_date:
  * @media: the media
  *
@@ -1355,7 +1505,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
  */
diff --git a/src/data/grl-media.h b/src/data/grl-media.h
index 96fc20c..321b446 100644
--- a/src/data/grl-media.h
+++ b/src/data/grl-media.h
@@ -121,6 +121,19 @@ void grl_media_set_duration (GrlMedia *media, gint duration);
 
 void grl_media_set_publication_date (GrlMedia *media, const GDateTime *date);
 
+void grl_media_set_region (GrlMedia *media,
+                           const gchar *region);
+
+void grl_media_set_region_data (GrlMedia *media,
+                                const gchar *region,
+                                const GDateTime *publication_date,
+                                const gchar *certificate);
+
+void grl_media_add_region_data (GrlMedia *media,
+                                const gchar *region,
+                                const GDateTime *publication_date,
+                                const gchar *certificate);
+
 void grl_media_set_creation_date (GrlMedia *media,
                                   const GDateTime *creation_date);
 
@@ -193,6 +206,17 @@ gint grl_media_get_duration (GrlMedia *media);
 
 GDateTime *grl_media_get_publication_date (GrlMedia *media);
 
+const gchar *grl_media_get_region (GrlMedia *media);
+
+const gchar *grl_media_get_region_data(GrlMedia *media,
+                                       const GDateTime **publication_date,
+                                       const gchar **certificate);
+
+const gchar *grl_media_get_region_data_nth(GrlMedia *media,
+                                           guint index,
+                                           const GDateTime **publication_date,
+                                           const gchar **certificate);
+
 GDateTime *grl_media_get_creation_date (GrlMedia *media);
 
 GDateTime *grl_media_get_modification_date (GrlMedia *media);
diff --git a/src/grl-metadata-key.c b/src/grl-metadata-key.c
index a8d5075..a719c8c 100644
--- a/src/grl-metadata-key.c
+++ b/src/grl-metadata-key.c
@@ -448,6 +448,15 @@ 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 ("region",
+                                                                "Region",
+                                                                "Region in which the media was published",
+                                                                NULL,
+                                                                G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE),
+                                           GRL_METADATA_KEY_REGION,
+                                           NULL);
+
   /* Create the relations */
   grl_registry_register_metadata_key_relation (registry,
                                                GRL_METADATA_KEY_URL,
@@ -467,7 +476,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_REGION,
+                                               GRL_METADATA_KEY_PUBLICATION_DATE);
+  grl_registry_register_metadata_key_relation (registry,
+                                               GRL_METADATA_KEY_REGION,
+                                               GRL_METADATA_KEY_CERTIFICATE);
 }
 
 /**
diff --git a/src/grl-metadata-key.h b/src/grl-metadata-key.h
index cf09add..9d5e093 100644
--- a/src/grl-metadata-key.h
+++ b/src/grl-metadata-key.h
@@ -89,6 +89,7 @@ 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_REGION               43
 
 G_BEGIN_DECLS
 
