Initial submission of GUPnP-AV to Tizen IVI
[profile/ivi/GUPnP-AV.git] / libgupnp-av / gupnp-didl-lite-item.c
1 /*
2  * Copyright (C) 2009 Nokia Corporation.
3  *
4  * Authors: Zeeshan Ali (Khattak) <zeeshan.ali@nokia.com>
5  *                                <zeeshanak@gnome.org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 /**
24  * SECTION:gupnp-didl-lite-item
25  * @short_description: DIDL-Lite Item
26  *
27  * #GUPnPDIDLLiteItem respresents a DIDL-Lite item element.
28  */
29
30 #include <string.h>
31
32 #include "gupnp-didl-lite-item.h"
33 #include "xml-util.h"
34
35 G_DEFINE_TYPE (GUPnPDIDLLiteItem,
36                gupnp_didl_lite_item,
37                GUPNP_TYPE_DIDL_LITE_OBJECT);
38
39 enum {
40         PROP_0,
41         PROP_REF_ID
42 };
43
44 static void
45 gupnp_didl_lite_item_init (GUPnPDIDLLiteItem *item)
46 {
47         /* Nothing to initialize, yay! */
48 }
49
50 static void
51 gupnp_didl_lite_item_get_property (GObject    *object,
52                                    guint       property_id,
53                                    GValue     *value,
54                                    GParamSpec *pspec)
55 {
56         GUPnPDIDLLiteItem *item;
57
58         item = GUPNP_DIDL_LITE_ITEM (object);
59
60         switch (property_id) {
61         case PROP_REF_ID:
62                 g_value_set_string
63                         (value,
64                          gupnp_didl_lite_item_get_ref_id (item));
65                 break;
66         default:
67                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
68                 break;
69         }
70 }
71
72 static void
73 gupnp_didl_lite_item_set_property (GObject      *object,
74                                    guint         property_id,
75                                    const GValue *value,
76                                    GParamSpec   *pspec)
77
78 {
79         GUPnPDIDLLiteItem *item;
80
81         item = GUPNP_DIDL_LITE_ITEM (object);
82
83         switch (property_id) {
84         case PROP_REF_ID:
85                 gupnp_didl_lite_item_set_ref_id (item,
86                                                  g_value_get_string (value));
87                 break;
88         default:
89                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
90                 break;
91         }
92 }
93
94 static void
95 gupnp_didl_lite_item_class_init (GUPnPDIDLLiteItemClass *klass)
96 {
97         GObjectClass *object_class;
98
99         object_class = G_OBJECT_CLASS (klass);
100
101         object_class->get_property = gupnp_didl_lite_item_get_property;
102         object_class->set_property = gupnp_didl_lite_item_set_property;
103
104         /**
105          * GUPnPDIDLLiteItem:ref-id:
106          *
107          * The ref ID of this item.
108          **/
109         g_object_class_install_property
110                 (object_class,
111                  PROP_REF_ID,
112                  g_param_spec_string ("ref-id",
113                                       "RefID",
114                                       "The ref ID of this item.",
115                                       NULL,
116                                       G_PARAM_READWRITE |
117                                       G_PARAM_STATIC_NAME |
118                                       G_PARAM_STATIC_NICK |
119                                       G_PARAM_STATIC_BLURB));
120 }
121
122 /**
123  * gupnp_didl_lite_item_get_ref_id:
124  * @item: #GUPnPDIDLLiteItem
125  *
126  * Get the ref ID of the @item.
127  *
128  * Return value: The ref ID of the @item, or %NULL.
129  **/
130 const char *
131 gupnp_didl_lite_item_get_ref_id (GUPnPDIDLLiteItem *item)
132 {
133         xmlNode *xml_node;
134
135         g_return_val_if_fail (item != NULL, 0);
136         g_return_val_if_fail (GUPNP_IS_DIDL_LITE_ITEM (item), NULL);
137
138         xml_node = gupnp_didl_lite_object_get_xml_node
139                                         (GUPNP_DIDL_LITE_OBJECT (item));
140
141         return xml_util_get_attribute_content (xml_node, "refID");
142 }
143
144 /**
145  * gupnp_didl_lite_item_set_ref_id:
146  * @item: #GUPnPDIDLLiteItem
147  * @ref_id: The ref ID
148  *
149  * Set the ref ID of the @item.
150  **/
151 void
152 gupnp_didl_lite_item_set_ref_id (GUPnPDIDLLiteItem *item,
153                                  const char        *ref_id)
154 {
155         xmlNode *xml_node;
156
157         g_return_if_fail (item != NULL);
158         g_return_if_fail (GUPNP_IS_DIDL_LITE_ITEM (item));
159
160         xml_node = gupnp_didl_lite_object_get_xml_node
161                                 (GUPNP_DIDL_LITE_OBJECT (item));
162
163         xmlSetProp (xml_node,
164                     (unsigned char *) "refID",
165                     (unsigned char *) ref_id);
166
167         g_object_notify (G_OBJECT (item), "ref-id");
168 }