1 /*****************************************************************************
2 * hierarchical_media_list_view.c: libvlc hierarchical media list view functs.
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
7 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
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.
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.
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 *****************************************************************************/
28 #include <vlc/libvlc.h>
29 #include <vlc/libvlc_media.h>
30 #include <vlc/libvlc_media_list.h>
31 #include <vlc/libvlc_media_list_view.h>
33 #include "media_list_internal.h"
34 #include "media_list_view_internal.h"
36 //#define DEBUG_HIERARCHICAL_VIEW
38 #ifdef DEBUG_HIERARCHICAL_VIEW
39 # define trace( fmt, ... ) printf( "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__ )
48 /**************************************************************************
49 * flat_media_list_view_count (private)
50 * (called by media_list_view_count)
51 **************************************************************************/
53 hierarch_media_list_view_count( libvlc_media_list_view_t * p_mlv,
54 libvlc_exception_t * p_e )
56 return libvlc_media_list_count( p_mlv->p_mlist, p_e );
59 /**************************************************************************
60 * flat_media_list_view_item_at_index (private)
61 * (called by flat_media_list_view_item_at_index)
62 **************************************************************************/
63 static libvlc_media_t *
64 hierarch_media_list_view_item_at_index( libvlc_media_list_view_t * p_mlv,
66 libvlc_exception_t * p_e )
68 return libvlc_media_list_item_at_index( p_mlv->p_mlist, index, p_e );
71 /**************************************************************************
72 * flat_media_list_view_item_at_index (private)
73 * (called by flat_media_list_view_item_at_index)
74 **************************************************************************/
75 static libvlc_media_list_view_t *
76 hierarch_media_list_view_children_at_index( libvlc_media_list_view_t * p_mlv,
78 libvlc_exception_t * p_e )
80 libvlc_media_t * p_md;
81 libvlc_media_list_t * p_submlist;
82 libvlc_media_list_view_t * p_ret;
83 p_md = libvlc_media_list_item_at_index( p_mlv->p_mlist, index, p_e );
84 if( !p_md ) return NULL;
85 p_submlist = libvlc_media_subitems( p_md, p_e );
86 libvlc_media_release( p_md );
87 if( !p_submlist ) return NULL;
88 p_ret = libvlc_media_list_hierarchical_view( p_submlist, p_e );
89 libvlc_media_list_release( p_submlist );
94 /**************************************************************************
95 * media_list_(item|will)_* (private) (Event callback)
96 **************************************************************************/
98 media_list_item_added( const libvlc_event_t * p_event, void * user_data )
100 libvlc_media_t * p_md;
101 libvlc_media_list_view_t * p_mlv = user_data;
102 int index = p_event->u.media_list_item_added.index;
103 p_md = p_event->u.media_list_item_added.item;
104 libvlc_media_list_view_item_added( p_mlv, p_md, index );
107 media_list_will_add_item( const libvlc_event_t * p_event, void * user_data )
109 libvlc_media_t * p_md;
110 libvlc_media_list_view_t * p_mlv = user_data;
111 int index = p_event->u.media_list_will_add_item.index;
112 p_md = p_event->u.media_list_will_add_item.item;
113 libvlc_media_list_view_will_add_item( p_mlv, p_md, index );
116 media_list_item_deleted( const libvlc_event_t * p_event, void * user_data )
118 libvlc_media_t * p_md;
119 libvlc_media_list_view_t * p_mlv = user_data;
120 int index = p_event->u.media_list_item_deleted.index;
121 p_md = p_event->u.media_list_item_deleted.item;
122 libvlc_media_list_view_item_deleted( p_mlv, p_md, index );
125 media_list_will_delete_item( const libvlc_event_t * p_event, void * user_data )
127 libvlc_media_t * p_md;
128 libvlc_media_list_view_t * p_mlv = user_data;
129 int index = p_event->u.media_list_will_delete_item.index;
130 p_md = p_event->u.media_list_will_delete_item.item;
131 libvlc_media_list_view_will_delete_item( p_mlv, p_md, index );
135 * Public libvlc functions
139 /**************************************************************************
140 * flat_media_list_view_release (private)
141 * (called by media_list_view_release)
142 **************************************************************************/
144 hierarch_media_list_view_release( libvlc_media_list_view_t * p_mlv )
146 libvlc_event_detach( p_mlv->p_mlist->p_event_manager,
147 libvlc_MediaListItemAdded,
148 media_list_item_added, p_mlv, NULL );
149 libvlc_event_detach( p_mlv->p_mlist->p_event_manager,
150 libvlc_MediaListWillAddItem,
151 media_list_will_add_item, p_mlv, NULL );
152 libvlc_event_detach( p_mlv->p_mlist->p_event_manager,
153 libvlc_MediaListItemDeleted,
154 media_list_item_deleted, p_mlv, NULL );
155 libvlc_event_detach( p_mlv->p_mlist->p_event_manager,
156 libvlc_MediaListWillDeleteItem,
157 media_list_will_delete_item, p_mlv, NULL );
160 /**************************************************************************
161 * libvlc_media_list_flat_view (Public)
162 **************************************************************************/
163 libvlc_media_list_view_t *
164 libvlc_media_list_hierarchical_view( libvlc_media_list_t * p_mlist,
165 libvlc_exception_t * p_e )
168 libvlc_media_list_view_t * p_mlv;
169 p_mlv = libvlc_media_list_view_new( p_mlist,
170 hierarch_media_list_view_count,
171 hierarch_media_list_view_item_at_index,
172 hierarch_media_list_view_children_at_index,
173 libvlc_media_list_hierarchical_view,
174 hierarch_media_list_view_release,
177 libvlc_media_list_lock( p_mlist );
178 libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
179 libvlc_MediaListItemAdded,
180 media_list_item_added, p_mlv, NULL );
181 libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
182 libvlc_MediaListWillAddItem,
183 media_list_will_add_item, p_mlv, NULL );
184 libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
185 libvlc_MediaListItemDeleted,
186 media_list_item_deleted, p_mlv, NULL );
187 libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
188 libvlc_MediaListWillDeleteItem,
189 media_list_will_delete_item, p_mlv, NULL );
190 libvlc_media_list_unlock( p_mlist );