| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
#include "libvlc_internal.h" |
|---|
| 25 |
#include <vlc/libvlc.h> |
|---|
| 26 |
#include <assert.h> |
|---|
| 27 |
#include "vlc_arrays.h" |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 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 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 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 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
static libvlc_media_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 |
|
|---|
| 71 |
|
|---|
| 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_t * p_md; |
|---|
| 79 |
libvlc_media_list_t * p_submlist; |
|---|
| 80 |
libvlc_media_list_view_t * p_ret; |
|---|
| 81 |
p_md = libvlc_media_list_item_at_index( p_mlv->p_mlist, index, p_e ); |
|---|
| 82 |
if( !p_md ) return NULL; |
|---|
| 83 |
p_submlist = libvlc_media_subitems( p_md, p_e ); |
|---|
| 84 |
libvlc_media_release( p_md ); |
|---|
| 85 |
if( !p_submlist ) return NULL; |
|---|
| 86 |
p_ret = libvlc_media_list_hierarchical_view( p_submlist, p_e ); |
|---|
| 87 |
libvlc_media_list_release( p_submlist ); |
|---|
| 88 |
|
|---|
| 89 |
return p_ret; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
static void |
|---|
| 96 |
media_list_item_added( const libvlc_event_t * p_event, void * user_data ) |
|---|
| 97 |
{ |
|---|
| 98 |
libvlc_media_t * p_md; |
|---|
| 99 |
libvlc_media_list_view_t * p_mlv = user_data; |
|---|
| 100 |
int index = p_event->u.media_list_item_added.index; |
|---|
| 101 |
p_md = p_event->u.media_list_item_added.item; |
|---|
| 102 |
libvlc_media_list_view_item_added( p_mlv, p_md, index ); |
|---|
| 103 |
} |
|---|
| 104 |
static void |
|---|
| 105 |
media_list_will_add_item( const libvlc_event_t * p_event, void * user_data ) |
|---|
| 106 |
{ |
|---|
| 107 |
libvlc_media_t * p_md; |
|---|
| 108 |
libvlc_media_list_view_t * p_mlv = user_data; |
|---|
| 109 |
int index = p_event->u.media_list_will_add_item.index; |
|---|
| 110 |
p_md = p_event->u.media_list_will_add_item.item; |
|---|
| 111 |
libvlc_media_list_view_will_add_item( p_mlv, p_md, index ); |
|---|
| 112 |
} |
|---|
| 113 |
static void |
|---|
| 114 |
media_list_item_deleted( const libvlc_event_t * p_event, void * user_data ) |
|---|
| 115 |
{ |
|---|
| 116 |
libvlc_media_t * p_md; |
|---|
| 117 |
libvlc_media_list_view_t * p_mlv = user_data; |
|---|
| 118 |
int index = p_event->u.media_list_item_deleted.index; |
|---|
| 119 |
p_md = p_event->u.media_list_item_deleted.item; |
|---|
| 120 |
libvlc_media_list_view_item_deleted( p_mlv, p_md, index ); |
|---|
| 121 |
} |
|---|
| 122 |
static void |
|---|
| 123 |
media_list_will_delete_item( const libvlc_event_t * p_event, void * user_data ) |
|---|
| 124 |
{ |
|---|
| 125 |
libvlc_media_t * p_md; |
|---|
| 126 |
libvlc_media_list_view_t * p_mlv = user_data; |
|---|
| 127 |
int index = p_event->u.media_list_will_delete_item.index; |
|---|
| 128 |
p_md = p_event->u.media_list_will_delete_item.item; |
|---|
| 129 |
libvlc_media_list_view_will_delete_item( p_mlv, p_md, index ); |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
static void |
|---|
| 142 |
hierarch_media_list_view_release( libvlc_media_list_view_t * p_mlv ) |
|---|
| 143 |
{ |
|---|
| 144 |
libvlc_event_detach( p_mlv->p_mlist->p_event_manager, |
|---|
| 145 |
libvlc_MediaListItemAdded, |
|---|
| 146 |
media_list_item_added, p_mlv, NULL ); |
|---|
| 147 |
libvlc_event_detach( p_mlv->p_mlist->p_event_manager, |
|---|
| 148 |
libvlc_MediaListWillAddItem, |
|---|
| 149 |
media_list_will_add_item, p_mlv, NULL ); |
|---|
| 150 |
libvlc_event_detach( p_mlv->p_mlist->p_event_manager, |
|---|
| 151 |
libvlc_MediaListItemDeleted, |
|---|
| 152 |
media_list_item_deleted, p_mlv, NULL ); |
|---|
| 153 |
libvlc_event_detach( p_mlv->p_mlist->p_event_manager, |
|---|
| 154 |
libvlc_MediaListWillDeleteItem, |
|---|
| 155 |
media_list_will_delete_item, p_mlv, NULL ); |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
libvlc_media_list_view_t * |
|---|
| 162 |
libvlc_media_list_hierarchical_view( libvlc_media_list_t * p_mlist, |
|---|
| 163 |
libvlc_exception_t * p_e ) |
|---|
| 164 |
{ |
|---|
| 165 |
trace("\n"); |
|---|
| 166 |
libvlc_media_list_view_t * p_mlv; |
|---|
| 167 |
p_mlv = libvlc_media_list_view_new( p_mlist, |
|---|
| 168 |
hierarch_media_list_view_count, |
|---|
| 169 |
hierarch_media_list_view_item_at_index, |
|---|
| 170 |
hierarch_media_list_view_children_at_index, |
|---|
| 171 |
libvlc_media_list_hierarchical_view, |
|---|
| 172 |
hierarch_media_list_view_release, |
|---|
| 173 |
NULL, |
|---|
| 174 |
p_e ); |
|---|
| 175 |
libvlc_media_list_lock( p_mlist ); |
|---|
| 176 |
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, |
|---|
| 177 |
libvlc_MediaListItemAdded, |
|---|
| 178 |
media_list_item_added, p_mlv, NULL ); |
|---|
| 179 |
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, |
|---|
| 180 |
libvlc_MediaListWillAddItem, |
|---|
| 181 |
media_list_will_add_item, p_mlv, NULL ); |
|---|
| 182 |
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, |
|---|
| 183 |
libvlc_MediaListItemDeleted, |
|---|
| 184 |
media_list_item_deleted, p_mlv, NULL ); |
|---|
| 185 |
libvlc_event_attach( p_mlv->p_mlist->p_event_manager, |
|---|
| 186 |
libvlc_MediaListWillDeleteItem, |
|---|
| 187 |
media_list_will_delete_item, p_mlv, NULL ); |
|---|
| 188 |
libvlc_media_list_unlock( p_mlist ); |
|---|
| 189 |
return p_mlv; |
|---|
| 190 |
} |
|---|