|
Packit |
712bc5 |
/*
|
|
Packit |
712bc5 |
* Copyright (C) 2012 Intel Corporation.
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Authors: Jens Georg <jensg@openismus.com>
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
712bc5 |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
712bc5 |
* License as published by the Free Software Foundation; either
|
|
Packit |
712bc5 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
712bc5 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
712bc5 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
712bc5 |
* Library General Public License for more details.
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
712bc5 |
* License along with this library; if not, write to the
|
|
Packit |
712bc5 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
Packit |
712bc5 |
* Boston, MA 02110-1301, USA.
|
|
Packit |
712bc5 |
*/
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* SECTION:gupnp-media-collection
|
|
Packit |
712bc5 |
* @short_description: Media collection writer
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* #GUPnPMediaCollection is a helper class for writing media collection files.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
#include "gupnp-media-collection.h"
|
|
Packit |
712bc5 |
#include "gupnp-didl-lite-writer.h"
|
|
Packit |
712bc5 |
#include "gupnp-didl-lite-writer-private.h"
|
|
Packit |
712bc5 |
#include "gupnp-didl-lite-parser.h"
|
|
Packit |
712bc5 |
#include "gupnp-didl-lite-parser-private.h"
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
// DIDL_S allowed tags as per DLNA Guidelines 11.1
|
|
Packit |
712bc5 |
#define DIDL_S_FILTER "dc:title,dc:creator,upnp:class,upnp:album,res,item," \
|
|
Packit |
712bc5 |
"container,dlna:lifetime"
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
G_DEFINE_TYPE (GUPnPMediaCollection,
|
|
Packit |
712bc5 |
gupnp_media_collection,
|
|
Packit |
712bc5 |
G_TYPE_OBJECT);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
struct _GUPnPMediaCollectionPrivate {
|
|
Packit |
712bc5 |
GUPnPDIDLLiteWriter *writer;
|
|
Packit |
712bc5 |
GUPnPDIDLLiteObject *container;
|
|
Packit |
712bc5 |
GList *items;
|
|
Packit |
712bc5 |
gboolean mutable;
|
|
Packit |
712bc5 |
char *data;
|
|
Packit |
712bc5 |
};
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
enum {
|
|
Packit |
712bc5 |
PROP_0,
|
|
Packit |
712bc5 |
PROP_AUTHOR,
|
|
Packit |
712bc5 |
PROP_TITLE,
|
|
Packit |
712bc5 |
PROP_MUTABLE,
|
|
Packit |
712bc5 |
PROP_DATA,
|
|
Packit |
712bc5 |
};
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
reparent_children (GUPnPMediaCollection *collection)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GList *it;
|
|
Packit |
712bc5 |
xmlNode *container_node;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
container_node = gupnp_didl_lite_object_get_xml_node
|
|
Packit |
712bc5 |
(collection->priv->container);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Reverse iterate the list to get the correct order in XML */
|
|
Packit |
712bc5 |
it = g_list_last (collection->priv->items);
|
|
Packit |
712bc5 |
while (it) {
|
|
Packit |
712bc5 |
xmlNode *node;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
node = gupnp_didl_lite_object_get_xml_node
|
|
Packit |
712bc5 |
(GUPNP_DIDL_LITE_OBJECT (it->data));
|
|
Packit |
712bc5 |
xmlUnlinkNode (node);
|
|
Packit |
712bc5 |
xmlAddChild (container_node, node);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
it = it->prev;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
on_container_available (GUPnPMediaCollection *self,
|
|
Packit |
712bc5 |
GUPnPDIDLLiteContainer *container,
|
|
Packit |
712bc5 |
G_GNUC_UNUSED gpointer user_data)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
/* According to media format spec, there's only one container allowed;
|
|
Packit |
712bc5 |
* We allow any number of containers, but only the last one wins. */
|
|
Packit |
712bc5 |
if (self->priv->container != NULL)
|
|
Packit |
712bc5 |
g_object_unref (self->priv->container);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
self->priv->container = g_object_ref (container);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
on_item_available (GUPnPMediaCollection *self,
|
|
Packit |
712bc5 |
GUPnPDIDLLiteItem *item,
|
|
Packit |
712bc5 |
G_GNUC_UNUSED gpointer user_data)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
self->priv->items = g_list_prepend (self->priv->items,
|
|
Packit |
712bc5 |
g_object_ref (item));
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
parse_data (GUPnPMediaCollection *collection, const char *data)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPDIDLLiteParser *parser;
|
|
Packit |
712bc5 |
GError *error = NULL;
|
|
Packit |
712bc5 |
gboolean result;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
parser = gupnp_didl_lite_parser_new ();
|
|
Packit |
712bc5 |
g_signal_connect_swapped (G_OBJECT (parser),
|
|
Packit |
712bc5 |
"container-available",
|
|
Packit |
712bc5 |
G_CALLBACK (on_container_available),
|
|
Packit |
712bc5 |
collection);
|
|
Packit |
712bc5 |
g_signal_connect_swapped (G_OBJECT (parser),
|
|
Packit |
712bc5 |
"item-available",
|
|
Packit |
712bc5 |
G_CALLBACK (on_item_available),
|
|
Packit |
712bc5 |
collection);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
result = gupnp_didl_lite_parser_parse_didl_recursive (parser,
|
|
Packit |
712bc5 |
data,
|
|
Packit |
712bc5 |
TRUE,
|
|
Packit |
712bc5 |
&error);
|
|
Packit |
712bc5 |
if (!result) {
|
|
Packit |
712bc5 |
GUPnPMediaCollectionPrivate *priv = collection->priv;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_warning ("Failed to parse DIDL-Lite: %s", error->message);
|
|
Packit |
712bc5 |
g_error_free (error);
|
|
Packit |
712bc5 |
if (priv->container) {
|
|
Packit |
712bc5 |
g_object_unref (priv->container);
|
|
Packit |
712bc5 |
priv->container = NULL;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
if (priv->items) {
|
|
Packit |
712bc5 |
g_list_free_full (priv->items, g_object_unref);
|
|
Packit |
712bc5 |
priv->items = NULL;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
gupnp_media_collection_init (GUPnPMediaCollection *collection)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
collection->priv = G_TYPE_INSTANCE_GET_PRIVATE
|
|
Packit |
712bc5 |
(collection,
|
|
Packit |
712bc5 |
GUPNP_TYPE_MEDIA_COLLECTION,
|
|
Packit |
712bc5 |
GUPnPMediaCollectionPrivate);
|
|
Packit |
712bc5 |
/* Initialize as mutable and decide later on in constructed() if we
|
|
Packit |
712bc5 |
* really are. */
|
|
Packit |
712bc5 |
collection->priv->mutable = TRUE;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
gupnp_media_collection_set_property (GObject *object,
|
|
Packit |
712bc5 |
guint property_id,
|
|
Packit |
712bc5 |
const GValue *value,
|
|
Packit |
712bc5 |
GParamSpec *pspec)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPMediaCollection *collection;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
collection = GUPNP_MEDIA_COLLECTION (object);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
switch (property_id) {
|
|
Packit |
712bc5 |
case PROP_AUTHOR:
|
|
Packit |
712bc5 |
gupnp_media_collection_set_author (collection,
|
|
Packit |
712bc5 |
g_value_get_string (value));
|
|
Packit |
712bc5 |
break;
|
|
Packit |
712bc5 |
case PROP_TITLE:
|
|
Packit |
712bc5 |
gupnp_media_collection_set_title (collection,
|
|
Packit |
712bc5 |
g_value_get_string (value));
|
|
Packit |
712bc5 |
break;
|
|
Packit |
712bc5 |
case PROP_DATA:
|
|
Packit |
712bc5 |
collection->priv->data = g_value_dup_string (value);
|
|
Packit |
712bc5 |
break;
|
|
Packit |
712bc5 |
default:
|
|
Packit |
712bc5 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
Packit |
712bc5 |
break;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
gupnp_media_collection_get_property (GObject *object,
|
|
Packit |
712bc5 |
guint property_id,
|
|
Packit |
712bc5 |
GValue *value,
|
|
Packit |
712bc5 |
GParamSpec *pspec)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPMediaCollection *collection;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
collection = GUPNP_MEDIA_COLLECTION (object);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
switch (property_id) {
|
|
Packit |
712bc5 |
case PROP_AUTHOR:
|
|
Packit |
712bc5 |
g_value_set_string
|
|
Packit |
712bc5 |
(value, gupnp_media_collection_get_author (collection));
|
|
Packit |
712bc5 |
break;
|
|
Packit |
712bc5 |
case PROP_TITLE:
|
|
Packit |
712bc5 |
g_value_set_string
|
|
Packit |
712bc5 |
(value, gupnp_media_collection_get_title (collection));
|
|
Packit |
712bc5 |
break;
|
|
Packit |
712bc5 |
case PROP_MUTABLE:
|
|
Packit |
712bc5 |
g_value_set_boolean
|
|
Packit |
712bc5 |
(value, gupnp_media_collection_get_mutable (collection));
|
|
Packit |
712bc5 |
break;
|
|
Packit |
712bc5 |
default:
|
|
Packit |
712bc5 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
Packit |
712bc5 |
break;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
gupnp_media_collection_constructed (GObject *object)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPMediaCollection *collection;
|
|
Packit |
712bc5 |
GObjectClass *object_class;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
collection = GUPNP_MEDIA_COLLECTION (object);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Check if we have some data. If there's data, we assume that the
|
|
Packit |
712bc5 |
* user meant to parse a playlist. We ignore title and author then. */
|
|
Packit |
712bc5 |
if (collection->priv->data != NULL) {
|
|
Packit |
712bc5 |
if (collection->priv->container != NULL) {
|
|
Packit |
712bc5 |
g_object_unref (collection->priv->container);
|
|
Packit |
712bc5 |
collection->priv->container = NULL;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (collection->priv->writer != NULL) {
|
|
Packit |
712bc5 |
g_object_unref (collection->priv->writer);
|
|
Packit |
712bc5 |
collection->priv->writer = NULL;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
parse_data (collection, collection->priv->data);
|
|
Packit |
712bc5 |
collection->priv->mutable = FALSE;
|
|
Packit |
712bc5 |
} else if (collection->priv->writer == NULL) {
|
|
Packit |
712bc5 |
collection->priv->writer =
|
|
Packit |
712bc5 |
gupnp_didl_lite_writer_new (NULL);
|
|
Packit |
712bc5 |
collection->priv->mutable = TRUE;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Chain up */
|
|
Packit |
712bc5 |
object_class = G_OBJECT_CLASS (gupnp_media_collection_parent_class);
|
|
Packit |
712bc5 |
if (object_class->constructed != NULL)
|
|
Packit |
712bc5 |
object_class->constructed (object);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
gupnp_media_collection_dispose (GObject *object)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPMediaCollection *collection;
|
|
Packit |
712bc5 |
GObjectClass *object_class;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
collection = GUPNP_MEDIA_COLLECTION (object);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (collection->priv->writer) {
|
|
Packit |
712bc5 |
g_object_unref (collection->priv->writer);
|
|
Packit |
712bc5 |
collection->priv->writer = NULL;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (collection->priv->items) {
|
|
Packit |
712bc5 |
g_list_free_full (collection->priv->items, g_object_unref);
|
|
Packit |
712bc5 |
collection->priv->items = NULL;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (collection->priv->container) {
|
|
Packit |
712bc5 |
g_object_unref (collection->priv->container);
|
|
Packit |
712bc5 |
collection->priv->container = NULL;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_free (collection->priv->data);
|
|
Packit |
712bc5 |
collection->priv->data = NULL;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
object_class = G_OBJECT_CLASS (gupnp_media_collection_parent_class);
|
|
Packit |
712bc5 |
object_class->dispose (object);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
gupnp_media_collection_class_init (GUPnPMediaCollectionClass *klass)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GObjectClass *object_class;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
object_class = G_OBJECT_CLASS (klass);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
object_class->set_property = gupnp_media_collection_set_property;
|
|
Packit |
712bc5 |
object_class->get_property = gupnp_media_collection_get_property;
|
|
Packit |
712bc5 |
object_class->constructed = gupnp_media_collection_constructed;
|
|
Packit |
712bc5 |
object_class->dispose = gupnp_media_collection_dispose;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_type_class_add_private (klass, sizeof (GUPnPMediaCollectionPrivate));
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* GUPnPMediaCollection:author:
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* The author of this media collection.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
g_object_class_install_property
|
|
Packit |
712bc5 |
(object_class,
|
|
Packit |
712bc5 |
PROP_AUTHOR,
|
|
Packit |
712bc5 |
g_param_spec_string ("author",
|
|
Packit |
712bc5 |
"Author",
|
|
Packit |
712bc5 |
"The author of this collection",
|
|
Packit |
712bc5 |
NULL,
|
|
Packit |
712bc5 |
G_PARAM_READWRITE |
|
|
Packit |
712bc5 |
G_PARAM_CONSTRUCT |
|
|
Packit |
712bc5 |
G_PARAM_STATIC_STRINGS));
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* GUPnPMediaCollection:title:
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* The title of this media collection.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
g_object_class_install_property
|
|
Packit |
712bc5 |
(object_class,
|
|
Packit |
712bc5 |
PROP_AUTHOR,
|
|
Packit |
712bc5 |
g_param_spec_string ("title",
|
|
Packit |
712bc5 |
"Title",
|
|
Packit |
712bc5 |
"The title of this collection",
|
|
Packit |
712bc5 |
NULL,
|
|
Packit |
712bc5 |
G_PARAM_READWRITE |
|
|
Packit |
712bc5 |
G_PARAM_CONSTRUCT |
|
|
Packit |
712bc5 |
G_PARAM_STATIC_STRINGS));
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* GUPnPMediaCollection:mutable:
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Whether this media collation is modifyable or not.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
g_object_class_install_property
|
|
Packit |
712bc5 |
(object_class,
|
|
Packit |
712bc5 |
PROP_MUTABLE,
|
|
Packit |
712bc5 |
g_param_spec_boolean ("mutable",
|
|
Packit |
712bc5 |
"Mutable",
|
|
Packit |
712bc5 |
"The mutability of this collection",
|
|
Packit |
712bc5 |
FALSE,
|
|
Packit |
712bc5 |
G_PARAM_READABLE |
|
|
Packit |
712bc5 |
G_PARAM_STATIC_STRINGS));
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* GUPnPMediaCollection:data:
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Block of data to parse a collection from. If data is set upon
|
|
Packit |
712bc5 |
* construction it will override the other properties and create a
|
|
Packit |
712bc5 |
* unmutable collection parsed from data.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
g_object_class_install_property
|
|
Packit |
712bc5 |
(object_class,
|
|
Packit |
712bc5 |
PROP_DATA,
|
|
Packit |
712bc5 |
g_param_spec_string ("data",
|
|
Packit |
712bc5 |
"Data",
|
|
Packit |
712bc5 |
"Data to construct the playlist from",
|
|
Packit |
712bc5 |
NULL,
|
|
Packit |
712bc5 |
G_PARAM_WRITABLE |
|
|
Packit |
712bc5 |
G_PARAM_CONSTRUCT_ONLY |
|
|
Packit |
712bc5 |
G_PARAM_STATIC_STRINGS));
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* gupnp_media_collection_new:
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Create a new writable media collection.
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Returns: (transfer full): A new #GUPnPMediaCollection.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
GUPnPMediaCollection *
|
|
Packit |
712bc5 |
gupnp_media_collection_new (void)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
return g_object_new (GUPNP_TYPE_MEDIA_COLLECTION, NULL);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* gupnp_media_collection_new_from_string:
|
|
Packit |
712bc5 |
* @data: XML string.
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Parse a new #GUPnPMediaCollection from a block of XML data.
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Returns: (transfer full): A new #GUPnPMediaCollection.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
GUPnPMediaCollection *
|
|
Packit |
712bc5 |
gupnp_media_collection_new_from_string (const char *data)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
return g_object_new (GUPNP_TYPE_MEDIA_COLLECTION,
|
|
Packit |
712bc5 |
"data", data,
|
|
Packit |
712bc5 |
NULL);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* gupnp_media_collection_set_title:
|
|
Packit |
712bc5 |
* @collection: #GUPnPMediaCollection
|
|
Packit |
712bc5 |
* @title: New Title of this collection;
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Set the title of a #GUPnPMediaCollection.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
void
|
|
Packit |
712bc5 |
gupnp_media_collection_set_title (GUPnPMediaCollection *collection,
|
|
Packit |
712bc5 |
const char *title)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPDIDLLiteContainer *container;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_return_if_fail (GUPNP_IS_MEDIA_COLLECTION (collection));
|
|
Packit |
712bc5 |
g_return_if_fail (collection->priv->mutable);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (title == NULL)
|
|
Packit |
712bc5 |
return;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (collection->priv->container != NULL) {
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_title (collection->priv->container,
|
|
Packit |
712bc5 |
title);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
return;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (collection->priv->writer == NULL)
|
|
Packit |
712bc5 |
collection->priv->writer = gupnp_didl_lite_writer_new (NULL);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
container = gupnp_didl_lite_writer_add_container
|
|
Packit |
712bc5 |
(collection->priv->writer);
|
|
Packit |
712bc5 |
collection->priv->container = GUPNP_DIDL_LITE_OBJECT (container);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
reparent_children (collection);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_title (collection->priv->container,
|
|
Packit |
712bc5 |
title);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* gupnp_media_collection_get_title:
|
|
Packit |
712bc5 |
* @collection: #GUPnPMediaCollection
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Returns: The title of this media collection or %NULL if not set.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
const char *
|
|
Packit |
712bc5 |
gupnp_media_collection_get_title (GUPnPMediaCollection *collection)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
g_return_val_if_fail (GUPNP_IS_MEDIA_COLLECTION (collection), NULL);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (collection->priv->container == NULL)
|
|
Packit |
712bc5 |
return NULL;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
return gupnp_didl_lite_object_get_title (collection->priv->container);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* gupnp_media_collection_set_author:
|
|
Packit |
712bc5 |
* @collection: #GUPnPMediaCollection
|
|
Packit |
712bc5 |
* @author: New author of this media collection.
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Set the author of the media collection
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
void
|
|
Packit |
712bc5 |
gupnp_media_collection_set_author (GUPnPMediaCollection *collection,
|
|
Packit |
712bc5 |
const char *author)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPDIDLLiteContainer *container;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_return_if_fail (GUPNP_IS_MEDIA_COLLECTION (collection));
|
|
Packit |
712bc5 |
g_return_if_fail (collection->priv->mutable);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (author == NULL)
|
|
Packit |
712bc5 |
return;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (collection->priv->container != NULL) {
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_creator (collection->priv->container,
|
|
Packit |
712bc5 |
author);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
return;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (collection->priv->writer == NULL)
|
|
Packit |
712bc5 |
collection->priv->writer = gupnp_didl_lite_writer_new (NULL);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
container = gupnp_didl_lite_writer_add_container
|
|
Packit |
712bc5 |
(collection->priv->writer);
|
|
Packit |
712bc5 |
collection->priv->container = GUPNP_DIDL_LITE_OBJECT (container);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
reparent_children (collection);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_creator (collection->priv->container,
|
|
Packit |
712bc5 |
author);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* gupnp_media_collection_get_author:
|
|
Packit |
712bc5 |
* @collection: #GUPnPMediaCollection
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Returns: The author of this media collection or %NULL if not set.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
const char *
|
|
Packit |
712bc5 |
gupnp_media_collection_get_author (GUPnPMediaCollection *collection)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
g_return_val_if_fail (GUPNP_IS_MEDIA_COLLECTION (collection), NULL);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (collection->priv->container == NULL)
|
|
Packit |
712bc5 |
return NULL;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
return gupnp_didl_lite_object_get_creator (collection->priv->container);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* gupnp_media_collection_add_item:
|
|
Packit |
712bc5 |
* @collection: #GUPnPMediaCollection
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Return value: (transfer full): A new #GUPnPDIDLLiteItem object. Unref after
|
|
Packit |
712bc5 |
* use.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
GUPnPDIDLLiteItem *
|
|
Packit |
712bc5 |
gupnp_media_collection_add_item (GUPnPMediaCollection *collection)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPDIDLLiteItem *item = NULL;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_return_val_if_fail (collection != NULL, NULL);
|
|
Packit |
712bc5 |
g_return_val_if_fail (GUPNP_IS_MEDIA_COLLECTION (collection), NULL);
|
|
Packit |
712bc5 |
g_return_val_if_fail (collection->priv->mutable, NULL);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (collection->priv->container != NULL)
|
|
Packit |
712bc5 |
item = gupnp_didl_lite_writer_add_container_child_item
|
|
Packit |
712bc5 |
(collection->priv->writer,
|
|
Packit |
712bc5 |
GUPNP_DIDL_LITE_CONTAINER
|
|
Packit |
712bc5 |
(collection->priv->container));
|
|
Packit |
712bc5 |
else
|
|
Packit |
712bc5 |
item = gupnp_didl_lite_writer_add_item
|
|
Packit |
712bc5 |
(collection->priv->writer);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Keep a reference of the object in case we need to do reparenting */
|
|
Packit |
712bc5 |
collection->priv->items = g_list_prepend (collection->priv->items,
|
|
Packit |
712bc5 |
g_object_ref (item));
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Mandatory in DLNA for object. Not specified if mandatory for
|
|
Packit |
712bc5 |
* DIDL_S, but to avoid problems with clients reusing their normal
|
|
Packit |
712bc5 |
* DIDL-Lite parser, we set it here if the application doesn't.
|
|
Packit |
712bc5 |
*/
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_restricted (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
TRUE);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
return item;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* gupnp_media_collection_get_string:
|
|
Packit |
712bc5 |
* @collection: #GUPnPMediaCollection
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Return value: (transfer full): XML string representing this media
|
|
Packit |
712bc5 |
* collection. g_free() after use. If the colleciton is not mutable, returns a
|
|
Packit |
712bc5 |
* copy of the original string.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
char *
|
|
Packit |
712bc5 |
gupnp_media_collection_get_string (GUPnPMediaCollection *collection)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
g_return_val_if_fail (collection != NULL, NULL);
|
|
Packit |
712bc5 |
g_return_val_if_fail (GUPNP_IS_MEDIA_COLLECTION (collection), NULL);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
if (collection->priv->data)
|
|
Packit |
712bc5 |
return g_strdup (collection->priv->data);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
gupnp_didl_lite_writer_filter_tags (collection->priv->writer,
|
|
Packit |
712bc5 |
DIDL_S_FILTER);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
return gupnp_didl_lite_writer_get_string (collection->priv->writer);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* gupnp_media_collection_get_items:
|
|
Packit |
712bc5 |
* @collection: #GUPnPMediaCollection
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Return value: (transfer full)(element-type GUPnPDIDLLiteItem): A #GList
|
|
Packit |
712bc5 |
* containing the elemens of this collection, in proper order. Unref all items
|
|
Packit |
712bc5 |
* and free the list after use.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
GList *
|
|
Packit |
712bc5 |
gupnp_media_collection_get_items (GUPnPMediaCollection *collection)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GList *tmp = NULL, *iter;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_return_val_if_fail (collection != NULL, NULL);
|
|
Packit |
712bc5 |
g_return_val_if_fail (GUPNP_IS_MEDIA_COLLECTION (collection), NULL);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
for (iter = collection->priv->items; iter != NULL; iter = iter->next) {
|
|
Packit |
712bc5 |
tmp = g_list_prepend (tmp, g_object_ref (iter->data));
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
return tmp;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/**
|
|
Packit |
712bc5 |
* gupnp_media_collection_get_mutable:
|
|
Packit |
712bc5 |
* @collection: #GUPnPMediaCollection
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Return value: #TRUE if the collections is modifiable, #FALSE otherwise.
|
|
Packit |
712bc5 |
**/
|
|
Packit |
712bc5 |
gboolean
|
|
Packit |
712bc5 |
gupnp_media_collection_get_mutable (GUPnPMediaCollection *collection)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
g_return_val_if_fail (collection != NULL, FALSE);
|
|
Packit |
712bc5 |
g_return_val_if_fail (GUPNP_IS_MEDIA_COLLECTION (collection), FALSE);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
return collection->priv->mutable;
|
|
Packit |
712bc5 |
}
|