[PATCH 1/2] Add storageUsed property



---
 libgupnp-av/gupnp-didl-lite-container.c |  115 ++++++++++++++++++++++++++++++-
 libgupnp-av/gupnp-didl-lite-container.h |    8 ++
 2 files changed, 122 insertions(+), 1 deletions(-)

diff --git a/libgupnp-av/gupnp-didl-lite-container.c b/libgupnp-av/gupnp-didl-lite-container.c
index 00bcd96..68f1280 100644
--- a/libgupnp-av/gupnp-didl-lite-container.c
+++ b/libgupnp-av/gupnp-didl-lite-container.c
@@ -39,7 +39,8 @@ G_DEFINE_TYPE (GUPnPDIDLLiteContainer,
 enum {
         PROP_0,
         PROP_SEARCHABLE,
-        PROP_CHILD_COUNT
+        PROP_CHILD_COUNT,
+        PROP_STORAGE_USED
 };
 
 static void
@@ -69,6 +70,11 @@ gupnp_didl_lite_container_get_property (GObject    *object,
                         (value,
                          gupnp_didl_lite_container_get_child_count (container));
                 break;
+        case PROP_STORAGE_USED:
+                g_value_set_long
+                        (value,
+                         gupnp_didl_lite_container_get_storage_used (container));
+                break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                 break;
@@ -97,6 +103,10 @@ gupnp_didl_lite_container_set_property (GObject      *object,
                                         (container,
                                          g_value_get_int (value));
                 break;
+        case PROP_STORAGE_USED:
+                gupnp_didl_lite_container_set_storage_used
+                                        (container,
+                                         g_value_get_int64 (value));
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                 break;
@@ -148,6 +158,26 @@ gupnp_didl_lite_container_class_init (GUPnPDIDLLiteContainerClass *klass)
                                    G_PARAM_STATIC_NAME |
                                    G_PARAM_STATIC_NICK |
                                    G_PARAM_STATIC_BLURB));
+
+        /**
+         * GUPnPDIDLLiteContainer:storage-used
+         *
+         * The number of bytes used by all child items of this container.
+         **/
+        g_object_class_install_property
+                (object_class,
+                 PROP_STORAGE_USED,
+                 g_param_spec_int64 ("storage-used",
+                                     "Storage Used",
+                                     "The Number of bytes used by all child "
+                                     "items of this container.",
+                                     -1,
+                                     G_MAXINT64,
+                                     -1,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_NAME |
+                                     G_PARAM_STATIC_NICK |
+                                     G_PARAM_STATIC_BLURB));
 }
 
 /**
@@ -234,6 +264,43 @@ gupnp_didl_lite_container_get_create_classes (GUPnPDIDLLiteContainer *container)
 }
 
 /**
+ * gupnp_didl_lite_container_get_storage_used:
+ * @container: #GUPnPDIDLLiteContainer
+ *
+ * Get the number of bytes used by all child items of the @container.
+ * If storage used is unknown, -1 is returned.
+ *
+ * Return value: The number of bytes used by all children of the @container,
+ * or -1 if it is unknown.
+ **/
+gint64
+gupnp_didl_lite_container_get_storage_used (GUPnPDIDLLiteContainer *container)
+{
+        GList *storage = NULL;
+        xmlNode *xml_node;
+        const char *str;
+
+        g_return_val_if_fail (container != NULL, 0);
+        g_return_val_if_fail (GUPNP_IS_DIDL_LITE_CONTAINER (container), 0);
+
+        storage = gupnp_didl_lite_object_get_properties (
+                                        GUPNP_DIDL_LITE_OBJECT (container),
+                                        "storageUsed");
+        if (storage == NULL)
+                return -1;
+
+        /* only return value from first node */
+        xml_node = (xmlNode *) storage->data;
+
+        g_list_free (storage);
+
+        str = (const char *) xml_node->content;
+
+        return g_ascii_strtoll (str, NULL, 10);
+}
+
+
+/**
  * gupnp_didl_lite_container_set_searchable:
  * @container: #GUPnPDIDLLiteContainer
  * @searchable: The searchibility
@@ -354,3 +421,49 @@ gupnp_didl_lite_container_add_create_class_full (
                     (unsigned char *) "includeDerived",
                     (unsigned char *) str);
 }
+
+/**
+ * gupnp_didl_lite_container_get_storage_used:
+ * @container: #GUPnPDIDLLiteContainer
+ * @storage_used: The number of bytes used by all child items of the
+ *                @container or -1 if unknown.
+ *
+ * Set the number of bytes used by all child items of the @container.
+ **/
+void
+gupnp_didl_lite_container_set_storage_used (
+                GUPnPDIDLLiteContainer *container,
+                gint64                  storage_used)
+{
+        GList *storage = NULL;
+        xmlNode *xml_node;
+        xmlNs *namespace;
+        char *str;
+
+        g_return_if_fail (container != NULL);
+        g_return_if_fail (GUPNP_IS_DIDL_LITE_CONTAINER (container));
+
+        xml_node = gupnp_didl_lite_object_get_xml_node
+                                (GUPNP_DIDL_LITE_OBJECT (container));
+
+        namespace = gupnp_didl_lite_object_get_upnp_namespace
+                                (GUPNP_DIDL_LITE_OBJECT (container));
+
+        str = g_strdup_printf ("%"G_GINT64_FORMAT, storage_used);
+
+        storage = gupnp_didl_lite_object_get_properties (
+                                        GUPNP_DIDL_LITE_OBJECT (container),
+                                        "storageUsed");
+        if (storage == NULL)
+                xmlNewChild (xml_node,
+                             namespace,
+                             (unsigned char *) "storageUsed",
+                             (unsigned char *) str);
+        else
+                xmlNodeSetContent ((xmlNode *) storage->data,
+                                   (unsigned char *) str);
+
+        g_free (str);
+
+        g_object_notify (G_OBJECT (container), "storage-used");
+}
diff --git a/libgupnp-av/gupnp-didl-lite-container.h b/libgupnp-av/gupnp-didl-lite-container.h
index e632f9a..f7ee8b6 100644
--- a/libgupnp-av/gupnp-didl-lite-container.h
+++ b/libgupnp-av/gupnp-didl-lite-container.h
@@ -100,6 +100,14 @@ gupnp_didl_lite_container_add_create_class_full
                                          gboolean                include_derived);
 
 
+gint64
+gupnp_didl_lite_container_get_storage_used
+                                       (GUPnPDIDLLiteContainer *container);
+
+void
+gupnp_didl_lite_container_set_storage_used
+                                       (GUPnPDIDLLiteContainer *container,
+                                        gint64                  storage_used);
 G_END_DECLS
 
 #endif /* __GUPNP_DIDL_LITE_CONTAINER_H__ */
-- 
1.7.5.4



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