]> git.sesse.net Git - vlc/blob - src/control/hierarchical_media_list_view.c
4dfbd93163fc59251f63c41ac4d512d101bc3b75
[vlc] / src / control / hierarchical_media_list_view.c
1 /*****************************************************************************
2  * hierarchical_media_list_view.c: libvlc hierarchical media list view functs.
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id: flat_media_list.c 21287 2007-08-20 01:28:12Z pdherbemont $
6  *
7  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include "libvlc_internal.h"
25 #include <vlc/libvlc.h>
26 #include <assert.h>
27 #include "vlc_arrays.h"
28
29 //#define DEBUG_HIERARCHICAL_VIEW
30
31 #ifdef DEBUG_HIERARCHICAL_VIEW
32 # define trace( fmt, ... ) printf( "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__ )
33 #else
34 # define trace( ... )
35 #endif
36
37 struct libvlc_media_list_view_private_t
38 {
39     vlc_array_t array;
40 };
41
42 /*
43  * Private functions
44  */
45
46 /**************************************************************************
47  *       flat_media_list_view_count  (private)
48  * (called by media_list_view_count)
49  **************************************************************************/
50 static int
51 hierarch_media_list_view_count( libvlc_media_list_view_t * p_mlv,
52                                 libvlc_exception_t * p_e )
53 {
54     return libvlc_media_list_count( p_mlv->p_mlist, p_e );
55 }
56
57 /**************************************************************************
58  *       flat_media_list_view_item_at_index  (private)
59  * (called by flat_media_list_view_item_at_index)
60  **************************************************************************/
61 static libvlc_media_descriptor_t *
62 hierarch_media_list_view_item_at_index( libvlc_media_list_view_t * p_mlv,
63                                     int index,
64                                     libvlc_exception_t * p_e )
65 {
66     return libvlc_media_list_item_at_index( p_mlv->p_mlist, index, p_e );
67 }
68
69 /**************************************************************************
70  *       flat_media_list_view_item_at_index  (private)
71  * (called by flat_media_list_view_item_at_index)
72  **************************************************************************/
73 static libvlc_media_list_view_t *
74 hierarch_media_list_view_children_at_index( libvlc_media_list_view_t * p_mlv,
75                                         int index,
76                                         libvlc_exception_t * p_e )
77 {
78     libvlc_media_descriptor_t * p_md;
79     libvlc_media_list_t * p_submlist;
80     p_md = libvlc_media_list_item_at_index( p_mlv->p_mlist, index, p_e );
81     if( !p_md ) return NULL;
82     p_submlist = libvlc_media_descriptor_subitems( p_md, p_e );
83     if( !p_submlist ) return NULL;
84     return libvlc_media_list_hierarchical_view( p_submlist, p_e );
85 }
86
87 /**************************************************************************
88  *       flat_media_list_view_release (private)
89  * (called by media_list_view_release)
90  **************************************************************************/
91 static void
92 hierarch_media_list_view_release( libvlc_media_list_view_t * p_mlv )
93 {
94 }
95
96 /*
97  * Public libvlc functions
98  */
99
100 /**************************************************************************
101  *       libvlc_media_list_flat_view (Public)
102  **************************************************************************/
103 libvlc_media_list_view_t *
104 libvlc_media_list_hierarchical_view( libvlc_media_list_t * p_mlist,
105                                      libvlc_exception_t * p_e )
106 {
107     trace("\n");
108     libvlc_media_list_view_t * p_mlv;
109     libvlc_media_list_lock( p_mlist );
110     p_mlv = libvlc_media_list_view_new( p_mlist,
111                                         hierarch_media_list_view_count,
112                                         hierarch_media_list_view_item_at_index,
113                                         hierarch_media_list_view_children_at_index,
114                                         hierarch_media_list_view_release,
115                                         NULL,
116                                         p_e );
117     libvlc_media_list_unlock( p_mlist );
118     return p_mlv;
119 }