[PATCH 5/6] core: reorganised date-related keys.
- From: Guillaume Emont <guijemont igalia com>
- To: grilo-list gnome org
- Cc: Guillaume Emont <guijemont igalia com>
- Subject: [PATCH 5/6] core: reorganised date-related keys.
- Date: Wed, 22 Jun 2011 19:07:55 +0200
GRL_METADATA_KEY_DATE was removed because its definition is not precise enough.
GRL_METADATA_KEY_PUBLICATION_DATE and GRL_METADATA_KEY_MODIFCATION_DATE were added.
All date keys now have ISO-8601 wrappers for their setters. This is useful
because GObject Introspection bindings do not seem to support GDateTime well
for now.
---
src/data/grl-media.c | 148 ++++++++++++++++++++++++++++++++++++++------
src/data/grl-media.h | 21 +++++-
src/grl-metadata-key.c | 17 ++++-
src/grl-metadata-key.h | 3 +-
tests/python/test_media.py | 23 +++++--
5 files changed, 176 insertions(+), 36 deletions(-)
diff --git a/src/data/grl-media.c b/src/data/grl-media.c
index 9d7a50b..4b4ee6f 100644
--- a/src/data/grl-media.c
+++ b/src/data/grl-media.c
@@ -77,6 +77,30 @@ grl_media_finalize (GObject *object)
G_OBJECT_CLASS (grl_media_parent_class)->finalize (object);
}
+static GDateTime *
+date_time_from_iso8601 (const gchar *date)
+{
+ GTimeVal t = { 0, };
+ gboolean ret;
+
+ ret = g_time_val_from_iso8601 (date, &t);
+
+ /* second condition works around
+ * https://bugzilla.gnome.org/show_bug.cgi?id=650968 */
+ if (!ret || (t.tv_sec == 0 && t.tv_usec == 0)) {
+ /* We might be in the case where there is a date alone. In that case, we
+ * take the convention of setting it to noon GMT */
+ gchar *date_time = g_strdup_printf ("%sT12:00:00Z", date);
+ ret = g_time_val_from_iso8601 (date_time, &t);
+ g_free (date_time);
+ }
+
+ if (ret)
+ return g_date_time_new_from_timeval_utc (&t);
+
+ return NULL;
+}
+
/**
* grl_media_new:
*
@@ -672,40 +696,41 @@ grl_media_set_duration (GrlMedia *media, gint duration)
}
/**
- * grl_media_set_date:
+ * grl_media_set_publication_date:
* @media: the media
* @date: the date
*
- * Set the media's date (TBD)
+ * Set the publication date of @media.
*/
void
-grl_media_set_date (GrlMedia *media, const GDateTime *date)
+grl_media_set_publication_date (GrlMedia *media, const GDateTime *date)
{
grl_data_set_boxed (GRL_DATA (media),
- GRL_METADATA_KEY_DATE,
+ GRL_METADATA_KEY_PUBLICATION_DATE,
date);
}
+/**
+ * grl_media_set_publication_date_from_iso8601:
+ * @media: the media
+ * @date: an ISO-8601 formatted string specifying a date and time
+ *
+ * Set the publication date of @media.
+ *
+ * Return: %TRUE if @date could be parsed and set correctly, %FALSE otherwise.
+ */
gboolean
-grl_media_set_date_from_iso8601 (GrlMedia *media, const gchar *date)
+grl_media_set_publication_date_from_iso8601 (GrlMedia *media, const gchar *date)
{
- GTimeVal t = { 0, };
-
- if (g_time_val_from_iso8601 (date, &t)) {
- GDateTime *date_time;
+ GDateTime *date_time;
- /* work around https://bugzilla.gnome.org/show_bug.cgi?id=650968 */
- if (t.tv_sec == 0 && t.tv_usec == 0)
- return FALSE;
-
- date_time = g_date_time_new_from_timeval_utc (&t);
-
- grl_media_set_date (media, date_time);
+ date_time = date_time_from_iso8601 (date);
+ if (date_time) {
+ grl_media_set_publication_date (media, date_time);
g_date_time_unref (date_time);
return TRUE;
}
-
return FALSE;
}
@@ -728,6 +753,75 @@ grl_media_set_creation_date (GrlMedia *media,
}
/**
+ * grl_media_set_creation_date_from_iso8601:
+ * @media: the media
+ * @date: an ISO-8601 formatted string specifying a date and time
+ *
+ * Set the creation date of @media.
+ *
+ * Return: %TRUE if @date could be parsed and set correctly, %FALSE otherwise.
+ */
+gboolean
+grl_media_set_creation_date_from_iso8601 (GrlMedia *media,
+ const gchar *date)
+{
+ GDateTime *date_time;
+
+ date_time = date_time_from_iso8601 (date);
+ if (date_time) {
+ grl_media_set_creation_date (media, date_time);
+ g_date_time_unref (date_time);
+
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+ * grl_media_set_modification_date:
+ * @media: the media
+ * @modification_date: date when the media was last modified
+ *
+ * Set the modification date of the media
+ *
+ */
+void
+grl_media_set_modification_date (GrlMedia *media,
+ const GDateTime *modification_date)
+
+{
+ grl_data_set_boxed (GRL_DATA (media),
+ GRL_METADATA_KEY_MODIFICATION_DATE,
+ modification_date);
+}
+
+/**
+ * grl_media_set_modification_date_from_iso8601:
+ * @media: the media
+ * @date: an ISO-8601 formatted string specifying a date and time
+ *
+ * Set the modification date of @media.
+ *
+ * Return: %TRUE if @date could be parsed and set correctly, %FALSE otherwise.
+ */
+gboolean
+grl_media_set_modification_date_from_iso8601 (GrlMedia *media,
+ const gchar* date)
+
+{
+ GDateTime *date_time;
+
+ date_time = date_time_from_iso8601 (date);
+ if (date_time) {
+ grl_media_set_modification_date (media, date_time);
+ g_date_time_unref (date_time);
+
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
* grl_media_set_mime:
* @media: the media
* @mime: the mime type
@@ -1143,7 +1237,7 @@ grl_media_get_duration (GrlMedia *media)
}
/**
- * grl_media_get_date:
+ * grl_media_get_publication_date:
* @media: the media object
*
* Returns: the media's date (TBD)
@@ -1151,9 +1245,9 @@ grl_media_get_duration (GrlMedia *media)
* Since: 0.1.4
*/
const GDateTime *
-grl_media_get_date (GrlMedia *media)
+grl_media_get_publication_date (GrlMedia *media)
{
- return grl_data_get_boxed (GRL_DATA (media), GRL_METADATA_KEY_DATE);
+ return grl_data_get_boxed (GRL_DATA (media), GRL_METADATA_KEY_PUBLICATION_DATE);
}
/**
@@ -1172,6 +1266,20 @@ grl_media_get_creation_date (GrlMedia *media)
}
/**
+ * grl_media_get_modification_date:
+ * @media: the media
+ *
+ * Returns: date when the media was last modified
+ */
+const GDateTime *
+grl_media_get_modification_date (GrlMedia *media)
+
+{
+ return grl_data_get_boxed (GRL_DATA (media),
+ GRL_METADATA_KEY_MODIFICATION_DATE);
+}
+
+/**
* grl_media_get_mime:
* @media: the media object
*
diff --git a/src/data/grl-media.h b/src/data/grl-media.h
index 626d765..2441a1b 100644
--- a/src/data/grl-media.h
+++ b/src/data/grl-media.h
@@ -119,11 +119,22 @@ 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 GDateTime *date);
+void grl_media_set_publication_date (GrlMedia *media, const GDateTime *date);
-gboolean grl_media_set_date_from_iso8601 (GrlMedia *media, const gchar *date);
+gboolean grl_media_set_publication_date_from_iso8601 (GrlMedia *media,
+ const gchar *date);
-void grl_media_set_creation_date (GrlMedia *media, const GDateTime *creation_date);
+void grl_media_set_creation_date (GrlMedia *media,
+ const GDateTime *creation_date);
+
+gboolean grl_media_set_creation_date_from_iso8601 (GrlMedia *media,
+ const gchar *date);
+
+void grl_media_set_modification_date (GrlMedia *media,
+ const GDateTime *modification_date);
+
+gboolean grl_media_set_modification_date_from_iso8601 (GrlMedia *media,
+ const gchar* date);
void grl_media_set_mime (GrlMedia *media, const gchar *mime);
@@ -189,10 +200,12 @@ const gchar *grl_media_get_site (GrlMedia *media);
gint grl_media_get_duration (GrlMedia *media);
-const GDateTime *grl_media_get_date (GrlMedia *media);
+const GDateTime *grl_media_get_publication_date (GrlMedia *media);
const GDateTime *grl_media_get_creation_date (GrlMedia *media);
+const GDateTime *grl_media_get_modification_date (GrlMedia *media);
+
const gchar *grl_media_get_mime (GrlMedia *media);
gfloat grl_media_get_rating (GrlMedia *media);
diff --git a/src/grl-metadata-key.c b/src/grl-metadata-key.c
index 5b19ba6..435b81b 100644
--- a/src/grl-metadata-key.c
+++ b/src/grl-metadata-key.c
@@ -67,12 +67,12 @@ grl_metadata_key_setup_system_keys (GrlPluginRegistry *registry)
NULL);
grl_plugin_registry_register_metadata_key_full (registry,
- g_param_spec_boxed ("date",
- "Date",
- "Publishing or recording date",
+ g_param_spec_boxed ("publishing-date",
+ "Publishing date",
+ "When the media was originally published",
G_TYPE_DATE_TIME,
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE),
- GRL_METADATA_KEY_DATE,
+ GRL_METADATA_KEY_PUBLICATION_DATE,
NULL);
grl_plugin_registry_register_metadata_key_full (registry,
@@ -421,6 +421,15 @@ grl_metadata_key_setup_system_keys (GrlPluginRegistry *registry)
GRL_METADATA_KEY_ISO_SPEED,
NULL);
+ grl_plugin_registry_register_metadata_key_full (registry,
+ g_param_spec_boxed ("modification-date",
+ "Modification date",
+ "When the media was last modified",
+ G_TYPE_DATE_TIME,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE),
+ GRL_METADATA_KEY_MODIFICATION_DATE,
+ NULL);
+
/* Create the relations */
grl_plugin_registry_register_metadata_key_relation (registry,
GRL_METADATA_KEY_URL,
diff --git a/src/grl-metadata-key.h b/src/grl-metadata-key.h
index b11cf92..7c876c4 100644
--- a/src/grl-metadata-key.h
+++ b/src/grl-metadata-key.h
@@ -49,7 +49,7 @@ typedef guint32 GrlKeyID;
#define GRL_METADATA_KEY_BITRATE 4
#define GRL_METADATA_KEY_CERTIFICATE 5
#define GRL_METADATA_KEY_CHILDCOUNT 6
-#define GRL_METADATA_KEY_DATE 7
+#define GRL_METADATA_KEY_PUBLICATION_DATE 7
#define GRL_METADATA_KEY_DESCRIPTION 8
#define GRL_METADATA_KEY_DURATION 9
#define GRL_METADATA_KEY_EXTERNAL_PLAYER 10
@@ -82,6 +82,7 @@ typedef guint32 GrlKeyID;
#define GRL_METADATA_KEY_FLASH_USED 37
#define GRL_METADATA_KEY_EXPOSURE_TIME 38
#define GRL_METADATA_KEY_ISO_SPEED 39
+#define GRL_METADATA_KEY_MODIFICATION_DATE 40
const gchar *grl_metadata_key_get_name (GrlKeyID key);
diff --git a/tests/python/test_media.py b/tests/python/test_media.py
index e3fc5a2..d689709 100644
--- a/tests/python/test_media.py
+++ b/tests/python/test_media.py
@@ -11,15 +11,13 @@ class TestMedia(unittest.TestCase):
media = Grl.Media.new()
self.assertFalse(media is None)
- def test_date(self):
+ def test_publication_date(self):
media = Grl.Media.new()
- self.assertTrue(media.get_date() is None)
- self.assertTrue(media.set_date_from_iso8601("2001-02-03T04:05:06Z"))
- self.assertFalse(media.set_date_from_iso8601("abcd"))
- # incomplete
- self.assertFalse(media.set_date_from_iso8601("2001-02-03"))
- d = media.get_date()
+ self.assertTrue(media.get_publication_date() is None)
+ self.assertTrue(media.set_publication_date_from_iso8601("2001-02-03T04:05:06Z"))
+ self.assertFalse(media.set_publication_date_from_iso8601("abcd"))
+ d = media.get_publication_date()
self.assertTrue(d is not None)
self.assertEqual(d.get_year(), 2001)
self.assertEqual(d.get_month(), 2)
@@ -28,6 +26,17 @@ class TestMedia(unittest.TestCase):
self.assertEqual(d.get_minute(), 5)
self.assertEqual(d.get_second(), 6)
+ # date only
+ self.assertTrue(media.set_publication_date_from_iso8601("2001-02-03"))
+ d = media.get_publication_date()
+ self.assertTrue(d is not None)
+ self.assertEqual(d.get_year(), 2001)
+ self.assertEqual(d.get_month(), 2)
+ self.assertEqual(d.get_day_of_month(), 3)
+ self.assertEqual(d.get_hour(), 12)
+ self.assertEqual(d.get_minute(), 0)
+ self.assertEqual(d.get_second(), 0)
+
# who said "this is ugly" ?
Grl.init([])
registry = Grl.PluginRegistry.get_default()
--
1.7.4.1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]