[gupnp-av/wip/didl-s: 3/10] Add dlna:lifetime property to items
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp-av/wip/didl-s: 3/10] Add dlna:lifetime property to items
- Date: Wed, 14 Nov 2012 22:29:08 +0000 (UTC)
commit cbcdfb9bbb7ecea4e280bb1c38706a3afd3886b6
Author: Jens Georg <mail jensge org>
Date: Tue Oct 30 20:26:22 2012 +0100
Add dlna:lifetime property to items
doc/gupnp-av-sections.txt | 2 +
libgupnp-av/Makefile.am | 2 +
libgupnp-av/gupnp-didl-lite-item.c | 90 +++++++++++++++++++++++++++++++-
libgupnp-av/gupnp-didl-lite-item.h | 9 +++
libgupnp-av/gupnp-didl-lite-resource.c | 34 +-----------
libgupnp-av/time-utils.c | 68 ++++++++++++++++++++++++
libgupnp-av/time-utils.h | 35 ++++++++++++
7 files changed, 207 insertions(+), 33 deletions(-)
---
diff --git a/doc/gupnp-av-sections.txt b/doc/gupnp-av-sections.txt
index c0d46b8..c5d2136 100644
--- a/doc/gupnp-av-sections.txt
+++ b/doc/gupnp-av-sections.txt
@@ -99,6 +99,8 @@ gupnp_didl_lite_container_get_type
GUPnPDIDLLiteItem
gupnp_didl_lite_item_get_ref_id
gupnp_didl_lite_item_set_ref_id
+gupnp_didl_lite_item_get_lifetime
+gupnp_didl_lite_item_set_lifetime
<SUBSECTION Standard>
GUPnPDIDLLiteItemClass
GUPNP_TYPE_DIDL_LITE_ITEM
diff --git a/libgupnp-av/Makefile.am b/libgupnp-av/Makefile.am
index 8c5ea5c..0770705 100644
--- a/libgupnp-av/Makefile.am
+++ b/libgupnp-av/Makefile.am
@@ -74,6 +74,8 @@ libgupnp_av_1_0_la_SOURCES = gupnp-didl-lite-object.c \
gvalue-util.h \
fragment-util.c \
fragment-util.h \
+ time-utils.c \
+ time-utils.h \
xsd-data.c \
xsd-data.h \
$(BUILT_SOURCES)
diff --git a/libgupnp-av/gupnp-didl-lite-item.c b/libgupnp-av/gupnp-didl-lite-item.c
index 9e5d34c..80cc8b0 100644
--- a/libgupnp-av/gupnp-didl-lite-item.c
+++ b/libgupnp-av/gupnp-didl-lite-item.c
@@ -31,6 +31,7 @@
#include "gupnp-didl-lite-item.h"
#include "xml-util.h"
+#include "time-utils.h"
G_DEFINE_TYPE (GUPnPDIDLLiteItem,
gupnp_didl_lite_item,
@@ -38,7 +39,8 @@ G_DEFINE_TYPE (GUPnPDIDLLiteItem,
enum {
PROP_0,
- PROP_REF_ID
+ PROP_REF_ID,
+ PROP_LIFETIME
};
static void
@@ -63,6 +65,11 @@ gupnp_didl_lite_item_get_property (GObject *object,
(value,
gupnp_didl_lite_item_get_ref_id (item));
break;
+ case PROP_LIFETIME:
+ g_value_set_long
+ (value,
+ gupnp_didl_lite_item_get_lifetime (item));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -85,6 +92,10 @@ gupnp_didl_lite_item_set_property (GObject *object,
gupnp_didl_lite_item_set_ref_id (item,
g_value_get_string (value));
break;
+ case PROP_LIFETIME:
+ gupnp_didl_lite_item_set_lifetime (item,
+ g_value_get_long (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -117,6 +128,24 @@ gupnp_didl_lite_item_class_init (GUPnPDIDLLiteItemClass *klass)
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
+
+ /**
+ * GUPnPDIDLLiteItem:lifetime:
+ *
+ * The lifetime in seconds of this DIDLLite item in a media collection.
+ **/
+ g_object_class_install_property
+ (object_class,
+ PROP_LIFETIME,
+ g_param_spec_long ("lifetime",
+ "Lifetime",
+ "The lifetime (in seconds) of this"
+ " item.",
+ -1,
+ G_MAXLONG,
+ -1,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
}
/**
@@ -166,3 +195,62 @@ gupnp_didl_lite_item_set_ref_id (GUPnPDIDLLiteItem *item,
g_object_notify (G_OBJECT (item), "ref-id");
}
+
+/**
+ * gupnp_didl_lite_item_set_lifetime:
+ * @item: #GUPnPDIDLLiteItem
+ * @lifetime: The lifetime (in seconds) of this item in a media collection.
+ **/
+void
+gupnp_didl_lite_item_set_lifetime (GUPnPDIDLLiteItem *item,
+ long lifetime)
+{
+ xmlNode *node = NULL;
+ xmlNs *ns = NULL;
+ GUPnPXMLDoc *doc = NULL;
+ GUPnPDIDLLiteObject *object = NULL;
+
+ g_return_if_fail (GUPNP_IS_DIDL_LITE_ITEM (item));
+
+ object = GUPNP_DIDL_LITE_OBJECT (item);
+ node = gupnp_didl_lite_object_get_xml_node (object);
+ ns = gupnp_didl_lite_object_get_dlna_namespace (object);
+ g_object_get (G_OBJECT (object), "xml-doc", &doc, NULL);
+
+ if (lifetime < 0)
+ xml_util_unset_child (node, "lifetime");
+ else {
+ char *str;
+
+ str = seconds_to_time (lifetime);
+ xml_util_set_child (node, ns, doc->doc, "lifetime", str);
+ g_free (str);
+ }
+
+ g_object_notify (G_OBJECT (object), "lifetime");
+}
+
+/**
+ * gupnp_didl_lite_item_get_lifetime:
+ * @item: #GUPnPDIDLLiteItem
+ *
+ * Returns: -1 if unset or the lifetime (in seconds) of the current item.
+ **/
+long
+gupnp_didl_lite_item_get_lifetime (GUPnPDIDLLiteItem *item)
+{
+ xmlNode *node = NULL;
+ const char *lifetime_str;
+ long lifetime;
+ GUPnPDIDLLiteObject *object = NULL;
+
+ g_return_val_if_fail (GUPNP_IS_DIDL_LITE_ITEM (item), -1);
+
+ object = GUPNP_DIDL_LITE_OBJECT (item);
+ node = gupnp_didl_lite_object_get_xml_node (object);
+
+ lifetime_str = xml_util_get_child_element_content (node, "lifetime");
+ lifetime = seconds_from_time (lifetime_str);
+
+ return lifetime;
+}
diff --git a/libgupnp-av/gupnp-didl-lite-item.h b/libgupnp-av/gupnp-didl-lite-item.h
index 1719729..c839493 100644
--- a/libgupnp-av/gupnp-didl-lite-item.h
+++ b/libgupnp-av/gupnp-didl-lite-item.h
@@ -1,8 +1,10 @@
/*
* Copyright (C) 2009 Nokia Corporation.
+ * Copyright (C) 2012 Intel Corporation.
*
* Authors: Zeeshan Ali (Khattak) <zeeshan ali nokia com>
* <zeeshanak gnome org>
+ * Jens Georg <jensg openismus com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -73,6 +75,13 @@ void
gupnp_didl_lite_item_set_ref_id (GUPnPDIDLLiteItem *item,
const char *ref_id);
+void
+gupnp_didl_lite_item_set_lifetime (GUPnPDIDLLiteItem *item,
+ long lifetime);
+
+long
+gupnp_didl_lite_item_get_lifetime (GUPnPDIDLLiteItem *item);
+
G_END_DECLS
#endif /* __GUPNP_DIDL_LITE_ITEM_H__ */
diff --git a/libgupnp-av/gupnp-didl-lite-resource.c b/libgupnp-av/gupnp-didl-lite-resource.c
index 8b4e064..4d79a0d 100644
--- a/libgupnp-av/gupnp-didl-lite-resource.c
+++ b/libgupnp-av/gupnp-didl-lite-resource.c
@@ -35,9 +35,7 @@
#include "gupnp-didl-lite-resource.h"
#include "xml-util.h"
-
-#define SEC_PER_MIN 60
-#define SEC_PER_HOUR 3600
+#include "time-utils.h"
G_DEFINE_TYPE (GUPnPDIDLLiteResource,
gupnp_didl_lite_resource,
@@ -106,31 +104,6 @@ return_point:
g_strfreev (tokens);
}
-static long
-seconds_from_time (const char *time_str)
-{
- char **tokens;
- gdouble seconds = -1;
-
- if (time_str == NULL)
- return -1;
-
- tokens = g_strsplit (time_str, ":", -1);
- if (tokens[0] == NULL ||
- tokens[1] == NULL ||
- tokens[2] == NULL)
- goto return_point;
-
- seconds = g_strtod (tokens[2], NULL);
- seconds += g_strtod (tokens[1], NULL) * SEC_PER_MIN;
- seconds += g_strtod (tokens[0], NULL) * SEC_PER_HOUR;
-
-return_point:
- g_strfreev (tokens);
-
- return (long) seconds;
-}
-
static void
on_protocol_info_changed (GUPnPProtocolInfo *info,
GParamSpec *pspec,
@@ -1220,10 +1193,7 @@ gupnp_didl_lite_resource_set_duration (GUPnPDIDLLiteResource *resource,
else {
char *str;
- str = g_strdup_printf ("%ld:%.2ld:%.2ld.000",
- duration / (60 * 60),
- (duration / 60) % 60,
- duration % 60);
+ str = seconds_to_time (duration);
xmlSetProp (resource->priv->xml_node,
(unsigned char *) "duration",
(unsigned char *) str);
diff --git a/libgupnp-av/time-utils.c b/libgupnp-av/time-utils.c
new file mode 100644
index 0000000..0964f9e
--- /dev/null
+++ b/libgupnp-av/time-utils.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Authors: Jens Georg <jensg openismus com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <glib.h>
+
+#include "time-utils.h"
+
+#define SEC_PER_MIN 60
+#define SEC_PER_HOUR 3600
+
+long
+seconds_from_time (const char *time_str)
+{
+ char **tokens;
+ gdouble seconds = -1;
+
+ if (time_str == NULL)
+ return -1;
+
+ tokens = g_strsplit (time_str, ":", -1);
+ if (tokens[0] == NULL ||
+ tokens[1] == NULL ||
+ tokens[2] == NULL)
+ goto return_point;
+
+ seconds = g_strtod (tokens[2], NULL);
+ seconds += g_strtod (tokens[1], NULL) * SEC_PER_MIN;
+ seconds += g_strtod (tokens[0], NULL) * SEC_PER_HOUR;
+
+return_point:
+ g_strfreev (tokens);
+
+ return (long) seconds;
+}
+
+char *
+seconds_to_time (long seconds)
+{
+ char *str;
+
+ if (seconds < 0)
+ return NULL;
+
+ str = g_strdup_printf ("%ld:%.2ld:%.2ld.000",
+ seconds / (60 * 60),
+ (seconds / 60) % 60,
+ seconds % 60);
+
+ return str;
+}
diff --git a/libgupnp-av/time-utils.h b/libgupnp-av/time-utils.h
new file mode 100644
index 0000000..d15c598
--- /dev/null
+++ b/libgupnp-av/time-utils.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Authors: Jens Georg <jensg openismus com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __TIME_UTILS_H__
+#define __TIME_UTILS_H__
+
+G_BEGIN_DECLS
+
+G_GNUC_INTERNAL long
+seconds_from_time (const char *time_string);
+
+G_GNUC_INTERNAL char *
+seconds_to_time (long seconds);
+
+G_END_DECLS
+
+#endif /* __TIME_UTILS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]