[gupnp-av/wip/didl-s: 4/4] wip: Add media collection class



commit 7460fa012955900c419de58dac45e5d8087454d0
Author: Jens Georg <mail jensge org>
Date:   Tue Oct 30 21:37:15 2012 +0100

    wip: Add media collection class

 libgupnp-av/Makefile.am              |    2 +
 libgupnp-av/gupnp-media-collection.c |  257 ++++++++++++++++++++++++++++++++++
 libgupnp-av/gupnp-media-collection.h |  102 ++++++++++++++
 3 files changed, 361 insertions(+), 0 deletions(-)
---
diff --git a/libgupnp-av/Makefile.am b/libgupnp-av/Makefile.am
index 0770705..135b561 100644
--- a/libgupnp-av/Makefile.am
+++ b/libgupnp-av/Makefile.am
@@ -27,6 +27,7 @@ libgupnp_av_inc_HEADERS = gupnp-didl-lite-object.h \
 			  gupnp-protocol-info.h \
 		          gupnp-search-criteria-parser.h \
 			  gupnp-last-change-parser.h \
+			  gupnp-media-collection.h \
 			  gupnp-feature.h \
 			  gupnp-feature-list-parser.h \
 			  gupnp-dlna.h \
@@ -64,6 +65,7 @@ libgupnp_av_1_0_la_SOURCES = gupnp-didl-lite-object.c \
 			     gupnp-protocol-info.c \
 			     gupnp-search-criteria-parser.c \
 			     gupnp-last-change-parser.c \
+			     gupnp-media-collection.c \
 			     gupnp-feature.c \
 			     gupnp-feature-list-parser.c \
 			     gupnp-dlna.c \
diff --git a/libgupnp-av/gupnp-media-collection.c b/libgupnp-av/gupnp-media-collection.c
new file mode 100644
index 0000000..e9958f2
--- /dev/null
+++ b/libgupnp-av/gupnp-media-collection.c
@@ -0,0 +1,257 @@
+/*
+ * 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.
+ */
+
+/**
+ * SECTION:gupnp-media-collection
+ * @short_description: Media collection writer
+ *
+ * #GUPnPMediaCollection is a helper class for writing media collection files.
+ **/
+
+#include "gupnp-media-collection.h"
+#include "gupnp-didl-lite-writer.h"
+
+G_DEFINE_TYPE (GUPnPMediaCollection,
+               gupnp_media_collection,
+               G_TYPE_OBJECT);
+
+struct _GUPnPMediaCollectionPrivate {
+        GUPnPDIDLLiteWriter *writer;
+        GUPnPDIDLLiteContainer *container;
+};
+
+enum {
+        PROP_0,
+        PROP_AUTHOR,
+        PROP_TITLE,
+};
+
+static void
+gupnp_media_collection_init (GUPnPMediaCollection *collection)
+{
+        collection->priv = G_TYPE_INSTANCE_GET_PRIVATE
+                                        (collection,
+                                         GUPNP_TYPE_MEDIA_COLLECTION,
+                                         GUPnPMediaCollectionPrivate);
+}
+
+static void
+gupnp_media_collection_set_property (GObject      *object,
+                                     guint         property_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec)
+{
+        GUPnPMediaCollection *collection;
+
+        collection = GUPNP_MEDIA_COLLECTION (object);
+
+        switch (property_id) {
+        case PROP_AUTHOR:
+                gupnp_media_collection_set_author (collection,
+                                                   g_value_get_string (value));
+                break;
+        case PROP_TITLE:
+                gupnp_media_collection_set_title (collection,
+                                                  g_value_get_string (value));
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                break;
+        }
+}
+
+static void
+gupnp_media_collection_get_property (GObject    *object,
+                                     guint       property_id,
+                                     GValue     *value,
+                                     GParamSpec *pspec)
+{
+        GUPnPMediaCollection *collection;
+
+        collection = GUPNP_MEDIA_COLLECTION (object);
+
+        switch (property_id) {
+        case PROP_AUTHOR:
+                g_value_set_string
+                        (value, gupnp_media_collection_get_author (collection));
+                break;
+        case PROP_TITLE:
+                g_value_set_string
+                        (value, gupnp_media_collection_get_title (collection));
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                break;
+        }
+}
+
+static void
+gupnp_media_collection_constructed (GObject *object)
+{
+        GUPnPMediaCollection *collection;
+        GObjectClass         *object_class;
+
+        collection = GUPNP_MEDIA_COLLECTION (object);
+        if (collection->priv->writer != NULL)
+                collection->priv->writer = gupnp_didl_lite_writer_new (NULL);
+
+        object_class = G_OBJECT_CLASS (gupnp_media_collection_parent_class);
+        if (object_class->constructed != NULL)
+                object_class->constructed (object);
+}
+
+static void
+gupnp_media_collection_dispose (GObject *object)
+{
+        GUPnPMediaCollection *collection;
+        GObjectClass         *object_class;
+
+        collection = GUPNP_MEDIA_COLLECTION (object);
+
+        if (collection->priv->writer) {
+                g_object_unref (collection->priv->writer);
+                collection->priv->writer = NULL;
+        }
+
+        if (collection->priv->container) {
+                g_object_unref (collection->priv->container);
+                collection->priv->container = NULL;
+        }
+
+        object_class = G_OBJECT_CLASS (gupnp_media_collection_parent_class);
+        object_class->dispose (object);
+}
+
+static void
+gupnp_media_collection_class_init (GUPnPMediaCollectionClass *klass)
+{
+        GObjectClass *object_class;
+
+        object_class = G_OBJECT_CLASS (klass);
+
+        object_class->set_property = gupnp_media_collection_set_property;
+        object_class->get_property = gupnp_media_collection_get_property;
+        object_class->constructed = gupnp_media_collection_constructed;
+        object_class->dispose = gupnp_media_collection_dispose;
+
+        g_type_class_add_private (klass, sizeof (GUPnPMediaCollectionPrivate));
+
+        /**
+         * GUPnPMediaCollection:author:
+         *
+         * The author of this media collection.
+         **/
+        g_object_class_install_property
+                (object_class,
+                 PROP_AUTHOR,
+                 g_param_spec_string ("author",
+                                      "Author",
+                                      "The author of this collection",
+                                      NULL,
+                                      G_PARAM_READWRITE |
+                                      G_PARAM_CONSTRUCT |
+                                      G_PARAM_STATIC_STRINGS));
+        
+        /**
+         * GUPnPMediaCollection:title:
+         *
+         * The title of this media collection.
+         **/
+        g_object_class_install_property
+                (object_class,
+                 PROP_AUTHOR,
+                 g_param_spec_string ("title",
+                                      "Title",
+                                      "The title of this collection",
+                                      NULL,
+                                      G_PARAM_READWRITE |
+                                      G_PARAM_CONSTRUCT |
+                                      G_PARAM_STATIC_STRINGS));
+}
+
+void
+gupnp_media_collection_set_title  (GUPnPMediaCollection *collection,
+                                   const char           *title)
+{
+}
+
+/**
+ * gupnp_media_collection_get_title:
+ * @collection: #GUPnPMediaCollection
+ *
+ * Return: The title of this media collection or %NULL if not set.
+ **/
+const char *
+gupnp_media_collection_get_title  (GUPnPMediaCollection *collection)
+{
+        g_return_val_if_fail (GUPNP_IS_MEDIA_COLLECTION (collection), NULL);
+
+        if (collection->priv->container == NULL)
+                return NULL;
+
+        return gupnp_didl_lite_object_get_title
+                                        (GUPNP_DIDL_LITE_OBJECT (collection));
+}
+
+void
+gupnp_media_collection_set_author (GUPnPMediaCollection *collection,
+                                   const char           *author)
+{
+}
+
+/**
+ * gupnp_media_collection_get_author:
+ * @collection: #GUPnPMediaCollection
+ *
+ * Return: The author of this media collection or %NULL if not set.
+ **/
+const char *
+gupnp_media_collection_get_author (GUPnPMediaCollection *collection)
+{
+        g_return_val_if_fail (GUPNP_IS_MEDIA_COLLECTION (collection), NULL);
+
+        if (collection->priv->container == NULL)
+                return NULL;
+
+        return gupnp_didl_lite_object_get_creator
+                                        (GUPNP_DIDL_LITE_OBJECT (collection));
+}
+
+/**
+ * gupnp_media_collection_add_item:
+ * @collection: #GUPnPMediaCollection
+ *
+ * Return value: (transfer full): A new #GUPnPDIDLLiteItem object. Unref after
+ * usage.
+ **/
+GUPnPDIDLLiteItem *
+gupnp_media_collection_add_item   (GUPnPMediaCollection *collection)
+{
+        g_return_val_if_fail (collection != NULL, NULL);
+        g_return_val_if_fail (GUPNP_IS_MEDIA_COLLECTION (collection), NULL);
+
+        if (collection->priv->container != NULL)
+                return gupnp_didl_lite_writer_add_container_child_item
+                                        (collection->priv->writer,
+                                         collection->priv->container);
+
+        return gupnp_didl_lite_writer_add_item (collection->priv->writer);
+}
diff --git a/libgupnp-av/gupnp-media-collection.h b/libgupnp-av/gupnp-media-collection.h
new file mode 100644
index 0000000..8c18876
--- /dev/null
+++ b/libgupnp-av/gupnp-media-collection.h
@@ -0,0 +1,102 @@
+/*
+ * 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 __GUPNP_DIDL_LITE_MEDIA_COLLECTION_H__
+#define __GUPNP_DIDL_LITE_MEDIA_COLLECTION_H__
+
+#include <glib-object.h>
+
+#include "gupnp-didl-lite-item.h"
+
+G_BEGIN_DECLS
+
+GType
+gupnp_media_collection_get_type (void) G_GNUC_CONST;
+
+#define GUPNP_TYPE_MEDIA_COLLECTION \
+                (gupnp_media_collection_get_type ())
+#define GUPNP_MEDIA_COLLECTION(obj) \
+                (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                 GUPNP_TYPE_MEDIA_COLLECTION, \
+                 GUPnPMediaCollection))
+#define GUPNP_MEDIA_COLLECTION_CLASS(obj) \
+                (G_TYPE_CHECK_CLASS_CAST ((obj), \
+                 GUPNP_TYPE_MEDIA_COLLECTION, \
+                 GUPnPMediaCollectionClass))
+#define GUPNP_IS_MEDIA_COLLECTION(obj) \
+                (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+                 GUPNP_TYPE_MEDIA_COLLECTION))
+#define GUPNP_IS_MEDIA_COLLECTION_CLASS(obj) \
+                (G_TYPE_CHECK_CLASS_TYPE ((obj), \
+                 GUPNP_TYPE_MEDIA_COLLECTION))
+#define GUPNP_MEDIA_COLLECTION_GET_CLASS(obj) \
+                (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                 GUPNP_TYPE_MEDIA_COLLECTION, \
+                 GUPnPMediaCollectionClass))
+
+typedef struct _GUPnPMediaCollectionPrivate GUPnPMediaCollectionPrivate;
+typedef struct _GUPnPMediaCollection GUPnPMediaCollection;
+typedef struct _GUPnPMediaCollectionClass GUPnPMediaCollectionClass;
+
+enum _GUPnPMediaCollectionType {
+        DIDL_S
+};
+typedef enum _GUPnPMediaCollectionType GUPnPMediaCollectionType;
+
+struct _GUPnPMediaCollection {
+        GObject parent;
+
+        GUPnPMediaCollectionPrivate *priv;
+};
+
+struct _GUPnPMediaCollectionClass {
+        GObjectClass parent_class;
+
+        /* padding */
+        void (* _gupnp_reserved1) (void);
+        void (* _gupnp_reserved2) (void);
+        void (* _gupnp_reserved3) (void);
+        void (* _gupnp_reserved4) (void);
+};
+
+GUPnPMediaCollection *
+gupnp_media_collection_new (GUPnPMediaCollectionType type);
+
+void
+gupnp_media_collection_set_title  (GUPnPMediaCollection *collection,
+                                   const char           *title);
+
+const char *
+gupnp_media_collection_get_title  (GUPnPMediaCollection *collection);
+
+void
+gupnp_media_collection_set_author (GUPnPMediaCollection *collection,
+                                   const char           *author);
+
+const char *
+gupnp_media_collection_get_author (GUPnPMediaCollection *collection);
+
+GUPnPDIDLLiteItem *
+gupnp_media_collection_add_item   (GUPnPMediaCollection *collection);
+
+G_END_DECLS
+
+#endif /* __GUPNP_DIDL_LITE_MEDIA_COLLECTION_H__ */



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