2 * Copyright (C) 2012 Intel Corporation.
4 * Authors: Krzesimir Nowak <krnowak@openismus.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 * SECTION:gupnp-dlna-information
24 * @short_description: Base class for storing various types of
25 * metadata informations.
27 * Subclasses of #GUPnPDLNAInformation should override all virtual
28 * functions provided by this class. The overrides should return a
29 * subclasses of specific information base classes.
31 * When instantiating a subclass of #GUPnPDLNAInformation make sure
32 * that "uri" with a URI to media file is passed to g_object_new().
35 #include "gupnp-dlna-information.h"
37 G_DEFINE_ABSTRACT_TYPE (GUPnPDLNAInformation,
38 gupnp_dlna_information,
41 struct _GUPnPDLNAInformationPrivate {
43 gboolean got_audio_info;
44 gboolean got_container_info;
45 gboolean got_image_info;
46 gboolean got_video_info;
47 GUPnPDLNAAudioInformation *audio_info;
48 GUPnPDLNAContainerInformation *container_info;
49 GUPnPDLNAImageInformation *image_info;
50 GUPnPDLNAVideoInformation *video_info;
64 gupnp_dlna_information_get_profile_name_default (GUPnPDLNAInformation *info G_GNUC_UNUSED)
70 gupnp_dlna_information_dispose (GObject *object)
72 GUPnPDLNAInformation *info = GUPNP_DLNA_INFORMATION (object);
73 GUPnPDLNAInformationPrivate *priv = info->priv;
75 g_clear_object (&priv->audio_info);
76 g_clear_object (&priv->container_info);
77 g_clear_object (&priv->image_info);
78 g_clear_object (&priv->video_info);
79 G_OBJECT_CLASS (gupnp_dlna_information_parent_class)->dispose (object);
83 gupnp_dlna_information_finalize (GObject *object)
85 GUPnPDLNAInformation *info = GUPNP_DLNA_INFORMATION (object);
87 g_free (info->priv->uri);
88 G_OBJECT_CLASS (gupnp_dlna_information_parent_class)->finalize (object);
92 gupnp_dlna_information_set_property (GObject *object,
97 GUPnPDLNAInformation *info = GUPNP_DLNA_INFORMATION (object);
98 GUPnPDLNAInformationPrivate *priv = info->priv;
100 switch (property_id) {
103 priv->uri = g_value_dup_string (value);
107 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
113 gupnp_dlna_information_get_property (GObject *object,
118 GUPnPDLNAInformation *info = GUPNP_DLNA_INFORMATION (object);
119 GUPnPDLNAInformationPrivate *priv = info->priv;
121 switch (property_id) {
123 g_value_set_string (value, priv->uri);
126 case PROP_AUDIO_INFO:
129 gupnp_dlna_information_get_audio_information (info));
132 case PROP_CONTAINER_INFO:
135 gupnp_dlna_information_get_container_information (info));
138 case PROP_IMAGE_INFO:
141 gupnp_dlna_information_get_image_information (info));
144 case PROP_VIDEO_INFO:
147 gupnp_dlna_information_get_video_information (info));
151 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
158 gupnp_dlna_information_class_init (GUPnPDLNAInformationClass *info_class)
160 GObjectClass *object_class = G_OBJECT_CLASS (info_class);
163 object_class->dispose = gupnp_dlna_information_dispose;
164 object_class->finalize = gupnp_dlna_information_finalize;
165 object_class->set_property = gupnp_dlna_information_set_property;
166 object_class->get_property = gupnp_dlna_information_get_property;
167 info_class->get_container_information = NULL;
168 info_class->get_image_information = NULL;
169 info_class->get_video_information = NULL;
170 info_class->get_audio_information = NULL;
171 info_class->get_profile_name = gupnp_dlna_information_get_profile_name_default;
174 * GUPnPDLNAInformation:uri:
176 * URI of file which metadata this object stores.
178 pspec = g_param_spec_string ("uri",
180 "URI of file which metadata this object "
184 G_PARAM_CONSTRUCT_ONLY);
185 g_object_class_install_property (object_class, PROP_URI, pspec);
188 * GUPnPDLNAInformation:audio-information:
190 * Audio information of a file.
192 pspec = g_param_spec_object ("audio-information",
194 "Audio information of a file",
195 GUPNP_TYPE_DLNA_AUDIO_INFORMATION,
197 g_object_class_install_property (object_class, PROP_AUDIO_INFO, pspec);
200 * GUPnPDLNAInformation:container-information:
202 * Container information of a file.
204 pspec = g_param_spec_object ("container-information",
205 "Container information",
206 "Container information of a file",
207 GUPNP_TYPE_DLNA_CONTAINER_INFORMATION,
209 g_object_class_install_property (object_class,
214 * GUPnPDLNAInformation:image-information:
216 * Image information of a file.
218 pspec = g_param_spec_object ("image-information",
220 "Image information of a file",
221 GUPNP_TYPE_DLNA_IMAGE_INFORMATION,
223 g_object_class_install_property (object_class, PROP_IMAGE_INFO, pspec);
226 * GUPnPDLNAInformation:video-information:
228 * Video information of a file.
230 pspec = g_param_spec_object ("video-information",
232 "Video information of a file",
233 GUPNP_TYPE_DLNA_VIDEO_INFORMATION,
235 g_object_class_install_property (object_class, PROP_VIDEO_INFO, pspec);
237 g_type_class_add_private (info_class,
238 sizeof (GUPnPDLNAInformationPrivate));
242 gupnp_dlna_information_init (GUPnPDLNAInformation *info)
244 GUPnPDLNAInformationPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE
246 GUPNP_TYPE_DLNA_INFORMATION,
247 GUPnPDLNAInformationPrivate);
250 priv->got_audio_info = FALSE;
251 priv->got_container_info = FALSE;
252 priv->got_image_info = FALSE;
253 priv->got_video_info = FALSE;
254 priv->audio_info = NULL;
255 priv->container_info = NULL;
256 priv->image_info = NULL;
257 priv->video_info = NULL;
262 * gupnp_dlna_information_get_audio_information:
263 * @info: A #GUPnPDLNAInformation object.
265 * Get an audio information of media file if applicable (e.g. for
266 * video and audio files).
268 * Returns: (transfer none): A #GUPnPDLNAAudioInformation object or %NULL.
270 GUPnPDLNAAudioInformation *
271 gupnp_dlna_information_get_audio_information (GUPnPDLNAInformation *info)
273 GUPnPDLNAInformationPrivate *priv;
275 g_return_val_if_fail (GUPNP_IS_DLNA_INFORMATION (info), NULL);
278 if (!priv->got_audio_info) {
279 GUPnPDLNAInformationClass *info_class;
281 info_class = GUPNP_DLNA_INFORMATION_GET_CLASS (info);
284 (GUPNP_IS_DLNA_INFORMATION_CLASS (info_class),
286 g_return_val_if_fail (info_class->get_audio_information != NULL,
289 priv->audio_info = info_class->get_audio_information (info);
290 priv->got_audio_info = TRUE;
293 return priv->audio_info;
297 * gupnp_dlna_information_get_container_information:
298 * @info: A #GUPnPDLNAInformation object.
300 * Get an container information of media file if applicable (e.g. for
301 * video and audio files).
303 * Returns: (transfer none): A #GUPnPDLNAContainerInformation object or %NULL.
305 GUPnPDLNAContainerInformation *
306 gupnp_dlna_information_get_container_information (GUPnPDLNAInformation *info)
308 GUPnPDLNAInformationPrivate *priv;
310 g_return_val_if_fail (GUPNP_IS_DLNA_INFORMATION (info), NULL);
313 if (!priv->got_container_info) {
314 GUPnPDLNAInformationClass *info_class;
316 info_class = GUPNP_DLNA_INFORMATION_GET_CLASS (info);
319 (GUPNP_IS_DLNA_INFORMATION_CLASS (info_class),
322 (info_class->get_container_information != NULL,
325 priv->container_info =
326 info_class->get_container_information (info);
327 priv->got_container_info = TRUE;
330 return priv->container_info;
334 * gupnp_dlna_information_get_image_information:
335 * @info: A #GUPnPDLNAInformation object.
337 * Get an container information of media file if applicable (e.g. for
340 * Returns: (transfer none): A #GUPnPDLNAImageInformation object or %NULL.
342 GUPnPDLNAImageInformation *
343 gupnp_dlna_information_get_image_information (GUPnPDLNAInformation *info)
345 GUPnPDLNAInformationPrivate *priv;
347 g_return_val_if_fail (GUPNP_IS_DLNA_INFORMATION (info), NULL);
350 if (!priv->got_image_info) {
351 GUPnPDLNAInformationClass *info_class;
353 info_class = GUPNP_DLNA_INFORMATION_GET_CLASS (info);
356 (GUPNP_IS_DLNA_INFORMATION_CLASS (info_class),
358 g_return_val_if_fail (info_class->get_image_information != NULL,
361 priv->image_info = info_class->get_image_information (info);
362 priv->got_image_info = TRUE;
365 return priv->image_info;
369 * gupnp_dlna_information_get_video_information:
370 * @info: A #GUPnPDLNAInformation object.
372 * Get an container information of media file if applicable (e.g. for
375 * Returns: (transfer none): A #GUPnPDLNAVideoInformation object or %NULL.
377 GUPnPDLNAVideoInformation *
378 gupnp_dlna_information_get_video_information (GUPnPDLNAInformation *info)
380 GUPnPDLNAInformationPrivate *priv;
382 g_return_val_if_fail (GUPNP_IS_DLNA_INFORMATION (info), NULL);
385 if (!priv->got_video_info) {
386 GUPnPDLNAInformationClass *info_class;
388 info_class = GUPNP_DLNA_INFORMATION_GET_CLASS (info);
391 (GUPNP_IS_DLNA_INFORMATION_CLASS (info_class),
393 g_return_val_if_fail (info_class->get_video_information != NULL,
396 priv->video_info = info_class->get_video_information (info);
397 priv->got_video_info = TRUE;
400 return priv->video_info;
404 * gupnp_dlna_information_get_profile_name:
405 * @info: A #GUPnPDLNAInformation object.
407 * Returns: (transfer none): The name of a DLNA profile or %NULL.
410 gupnp_dlna_information_get_profile_name (GUPnPDLNAInformation *info)
412 g_return_val_if_fail (GUPNP_IS_DLNA_INFORMATION (info), NULL);
414 return GUPNP_DLNA_INFORMATION_GET_CLASS (info)->get_profile_name (info);
419 * gupnp_dlna_information_get_uri:
420 * @info: A #GUPnPDLNAInformation object.
422 * Returns: (transfer none): An URI of a file.
425 gupnp_dlna_information_get_uri (GUPnPDLNAInformation *info)
427 g_return_val_if_fail (GUPNP_IS_DLNA_INFORMATION (info), NULL);
429 return info->priv->uri;