[PATCH 2/7] core: changed type of date keys to GDateTime



Strings could be dangerous because errors in their formatting is likely to be
detected too late.

See also https://mail.gnome.org/archives/grilo-list/2011-June/msg00002.html.
---
 src/data/grl-media.c   |   26 +++++++++++++-------------
 src/data/grl-media.h   |    8 ++++----
 src/grl-metadata-key.c |   14 +++++++-------
 3 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/src/data/grl-media.c b/src/data/grl-media.c
index 0757a06..eea3602 100644
--- a/src/data/grl-media.c
+++ b/src/data/grl-media.c
@@ -679,11 +679,11 @@ grl_media_set_duration (GrlMedia *media, gint duration)
  * Set the media's date (TBD)
  */
 void
-grl_media_set_date (GrlMedia *media, const gchar *date)
+grl_media_set_date (GrlMedia *media, const GDateTime *date)
 {
-  grl_data_set_string (GRL_DATA (media),
-                       GRL_METADATA_KEY_DATE,
-                       date);
+  grl_data_set_boxed (GRL_DATA (media),
+                      GRL_METADATA_KEY_DATE,
+                      date);
 }
 
 /**
@@ -697,11 +697,11 @@ grl_media_set_date (GrlMedia *media, const gchar *date)
   */
 void
 grl_media_set_creation_date (GrlMedia *media,
-                             const gchar * creation_date)
+                             const GDateTime *creation_date)
 {
-  grl_data_set_string (GRL_DATA (media),
-                       GRL_METADATA_KEY_CREATION_DATE,
-                       creation_date);
+  grl_data_set_boxed (GRL_DATA (media),
+                      GRL_METADATA_KEY_CREATION_DATE,
+                      creation_date);
 }
 
 /**
@@ -1127,10 +1127,10 @@ grl_media_get_duration (GrlMedia *media)
  *
  * Since: 0.1.4
  */
-const gchar *
+const GDateTime *
 grl_media_get_date (GrlMedia *media)
 {
-  return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_DATE);
+  return grl_data_get_boxed (GRL_DATA (media), GRL_METADATA_KEY_DATE);
 }
 
 /**
@@ -1141,11 +1141,11 @@ grl_media_get_date (GrlMedia *media)
  *
  * Since: 0.1.12
  */
-const gchar *
+const GDateTime *
 grl_media_get_creation_date (GrlMedia *media)
 {
-  return grl_data_get_string (GRL_DATA (media),
-                              GRL_METADATA_KEY_CREATION_DATE);
+  return grl_data_get_boxed (GRL_DATA (media),
+                             GRL_METADATA_KEY_CREATION_DATE);
 }
 
 /**
diff --git a/src/data/grl-media.h b/src/data/grl-media.h
index 242f16a..b23422e 100644
--- a/src/data/grl-media.h
+++ b/src/data/grl-media.h
@@ -119,9 +119,9 @@ void grl_media_set_site (GrlMedia *media, const gchar *site);
 
 void grl_media_set_duration (GrlMedia *media, gint duration);
 
-void grl_media_set_date (GrlMedia *media, const gchar *date);
+void grl_media_set_date (GrlMedia *media, const GDateTime *date);
 
-void grl_media_set_creation_date (GrlMedia *media, const gchar *creation_date);
+void grl_media_set_creation_date (GrlMedia *media, const GDateTime *creation_date);
 
 void grl_media_set_mime (GrlMedia *media, const gchar *mime);
 
@@ -187,9 +187,9 @@ const gchar *grl_media_get_site (GrlMedia *media);
 
 gint grl_media_get_duration (GrlMedia *media);
 
-const gchar *grl_media_get_date (GrlMedia *media);
+const GDateTime *grl_media_get_date (GrlMedia *media);
 
-const gchar *grl_media_get_creation_date (GrlMedia *media);
+const GDateTime *grl_media_get_creation_date (GrlMedia *media);
 
 const gchar *grl_media_get_mime (GrlMedia *media);
 
diff --git a/src/grl-metadata-key.c b/src/grl-metadata-key.c
index 977b77f..5b19ba6 100644
--- a/src/grl-metadata-key.c
+++ b/src/grl-metadata-key.c
@@ -67,10 +67,10 @@ grl_metadata_key_setup_system_keys (GrlPluginRegistry *registry)
                                                   NULL);
 
   grl_plugin_registry_register_metadata_key_full (registry,
-                                                  g_param_spec_string ("date",
+                                                  g_param_spec_boxed ("date",
                                                                        "Date",
                                                                        "Publishing or recording date",
-                                                                       NULL,
+                                                                       G_TYPE_DATE_TIME,
                                                                        G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE),
                                                   GRL_METADATA_KEY_DATE,
                                                   NULL);
@@ -360,11 +360,11 @@ grl_metadata_key_setup_system_keys (GrlPluginRegistry *registry)
 
 
   grl_plugin_registry_register_metadata_key_full (registry,
-                                                  g_param_spec_string ("creation-date",
-                                                                       "Creation date",
-                                                                       "Creation date",
-                                                                       NULL,
-                                                                       G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE),
+                                                  g_param_spec_boxed ("creation-date",
+                                                                      "Creation date",
+                                                                      "Creation date",
+                                                                      G_TYPE_DATE_TIME,
+                                                                      G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE),
                                                   GRL_METADATA_KEY_CREATION_DATE,
                                                   NULL);
 
-- 
1.7.4.1



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