| 38 | | static void add_media_list( libvlc_media_list_t * p_mlist, libvlc_media_list_t * p_submlist ); |
|---|
| 39 | | static void remove_media_list( libvlc_media_list_t * p_fmlist, libvlc_media_list_t * p_mlist ); |
|---|
| | 40 | static void install_flat_mlist_observer( libvlc_media_list_t * p_mlist ); |
|---|
| | 41 | static void uninstall_flat_mlist_observer( libvlc_media_list_t * p_mlist ); |
|---|
| | 42 | |
|---|
| | 43 | /************************************************************************** |
|---|
| | 44 | * uninstall_media_list_observer (Private) |
|---|
| | 45 | **************************************************************************/ |
|---|
| | 46 | static void |
|---|
| | 47 | uninstall_media_list_observer( libvlc_media_list_t * p_mlist, |
|---|
| | 48 | libvlc_media_list_t * p_submlist ) |
|---|
| | 49 | { |
|---|
| | 50 | libvlc_event_detach( p_submlist->p_event_manager, |
|---|
| | 51 | libvlc_MediaListItemAdded, |
|---|
| | 52 | sublist_item_added, p_mlist, NULL ); |
|---|
| | 53 | libvlc_event_detach( p_submlist->p_event_manager, |
|---|
| | 54 | libvlc_MediaListItemDeleted, |
|---|
| | 55 | sublist_item_removed, p_mlist, NULL ); |
|---|
| | 56 | |
|---|
| | 57 | } |
|---|
| | 58 | |
|---|
| | 59 | /************************************************************************** |
|---|
| | 60 | * install_media_list_observer (Private) |
|---|
| | 61 | **************************************************************************/ |
|---|
| | 62 | static void |
|---|
| | 63 | install_media_list_observer( libvlc_media_list_t * p_mlist, |
|---|
| | 64 | libvlc_media_list_t * p_submlist ) |
|---|
| | 65 | { |
|---|
| | 66 | libvlc_event_attach( p_submlist->p_event_manager, |
|---|
| | 67 | libvlc_MediaListItemAdded, |
|---|
| | 68 | sublist_item_added, p_mlist, NULL ); |
|---|
| | 69 | libvlc_event_attach( p_submlist->p_event_manager, |
|---|
| | 70 | libvlc_MediaListItemDeleted, |
|---|
| | 71 | sublist_item_removed, p_mlist, NULL ); |
|---|
| | 72 | } |
|---|
| | 73 | |
|---|
| | 74 | /************************************************************************** |
|---|
| | 75 | * add_media_list (Private) |
|---|
| | 76 | **************************************************************************/ |
|---|
| | 77 | static void |
|---|
| | 78 | add_media_list( libvlc_media_list_t * p_mlist, |
|---|
| | 79 | libvlc_media_list_t * p_submlist ) |
|---|
| | 80 | { |
|---|
| | 81 | int count = libvlc_media_list_count( p_submlist, NULL ); |
|---|
| | 82 | int i; |
|---|
| | 83 | |
|---|
| | 84 | for( i = 0; i < count; i++ ) |
|---|
| | 85 | { |
|---|
| | 86 | libvlc_media_descriptor_t * p_md; |
|---|
| | 87 | p_md = libvlc_media_list_item_at_index( p_submlist, i, NULL ); |
|---|
| | 88 | add_item( p_mlist->p_flat_mlist, p_md ); |
|---|
| | 89 | } |
|---|
| | 90 | install_media_list_observer( p_mlist, p_submlist ); |
|---|
| | 91 | } |
|---|
| | 92 | |
|---|
| | 93 | /************************************************************************** |
|---|
| | 94 | * remove_media_list (Private) |
|---|
| | 95 | **************************************************************************/ |
|---|
| | 96 | static void |
|---|
| | 97 | remove_media_list( libvlc_media_list_t * p_mlist, |
|---|
| | 98 | libvlc_media_list_t * p_submlist ) |
|---|
| | 99 | { |
|---|
| | 100 | int count = libvlc_media_list_count( p_submlist, NULL ); |
|---|
| | 101 | int i; |
|---|
| | 102 | uninstall_media_list_observer( p_mlist, p_submlist ); |
|---|
| | 103 | |
|---|
| | 104 | for( i = 0; i < count; i++ ) |
|---|
| | 105 | { |
|---|
| | 106 | libvlc_media_descriptor_t * p_md; |
|---|
| | 107 | p_md = libvlc_media_list_item_at_index( p_submlist, i, NULL ); |
|---|
| | 108 | remove_item( p_mlist, p_md ); |
|---|
| | 109 | } |
|---|
| | 110 | } |
|---|
| | 111 | |
|---|
| 120 | | * add_media_list (Private) |
|---|
| 121 | | **************************************************************************/ |
|---|
| 122 | | void |
|---|
| 123 | | add_media_list( libvlc_media_list_t * p_mlist, |
|---|
| 124 | | libvlc_media_list_t * p_submlist ) |
|---|
| 125 | | { |
|---|
| 126 | | int count = libvlc_media_list_count( p_submlist, NULL ); |
|---|
| 127 | | int i; |
|---|
| 128 | | |
|---|
| 129 | | libvlc_event_attach( p_submlist->p_event_manager, |
|---|
| 130 | | libvlc_MediaListItemAdded, |
|---|
| 131 | | sublist_item_added, p_mlist, NULL ); |
|---|
| 132 | | libvlc_event_attach( p_submlist->p_event_manager, |
|---|
| 133 | | libvlc_MediaListItemDeleted, |
|---|
| 134 | | sublist_item_removed, p_mlist, NULL ); |
|---|
| 135 | | for( i = 0; i < count; i++ ) |
|---|
| 136 | | { |
|---|
| 137 | | libvlc_media_descriptor_t * p_md; |
|---|
| 138 | | p_md = libvlc_media_list_item_at_index( p_submlist, i, NULL ); |
|---|
| 139 | | add_item( p_mlist->p_flat_mlist, p_md ); |
|---|
| 140 | | } |
|---|
| 141 | | } |
|---|
| 142 | | |
|---|
| 143 | | /************************************************************************** |
|---|
| 144 | | * remove_media_list (Private) |
|---|
| 145 | | **************************************************************************/ |
|---|
| 146 | | void |
|---|
| 147 | | remove_media_list( libvlc_media_list_t * p_mlist, |
|---|
| 148 | | libvlc_media_list_t * p_submlist ) |
|---|
| 149 | | { |
|---|
| | 196 | * remove_item_in_submlist_rec (private) |
|---|
| | 197 | **************************************************************************/ |
|---|
| | 198 | static void |
|---|
| | 199 | remove_item_in_submlist_rec( libvlc_media_list_t * p_mlist, |
|---|
| | 200 | libvlc_media_list_t * p_submlist, |
|---|
| | 201 | libvlc_media_descriptor_t * p_md ) |
|---|
| | 202 | { |
|---|
| | 203 | libvlc_media_descriptor_t * p_md_insub; |
|---|
| 154 | | libvlc_media_descriptor_t * p_md; |
|---|
| 155 | | p_md = libvlc_media_list_item_at_index( p_submlist, i, NULL ); |
|---|
| 156 | | remove_item( p_mlist, p_md ); |
|---|
| 157 | | } |
|---|
| 158 | | |
|---|
| 159 | | libvlc_event_detach( p_mlist->p_event_manager, |
|---|
| | 208 | p_md_insub = libvlc_media_list_item_at_index( p_submlist, |
|---|
| | 209 | i, NULL ); |
|---|
| | 210 | if( p_md_insub->p_subitems ) |
|---|
| | 211 | remove_item_in_submlist_rec( p_mlist, p_submlist, p_md ); |
|---|
| | 212 | if( p_md == p_md_insub ) |
|---|
| | 213 | { |
|---|
| | 214 | uninstall_media_list_observer( p_mlist, p_submlist ); |
|---|
| | 215 | libvlc_media_list_remove_index( p_submlist, i, NULL ); |
|---|
| | 216 | install_media_list_observer( p_mlist, p_submlist ); |
|---|
| | 217 | } |
|---|
| | 218 | } |
|---|
| | 219 | } |
|---|
| | 220 | |
|---|
| | 221 | /************************************************************************** |
|---|
| | 222 | * flat_mlist_item_removed (private) (Event Callback) |
|---|
| | 223 | **************************************************************************/ |
|---|
| | 224 | static void |
|---|
| | 225 | flat_mlist_item_removed( const libvlc_event_t * p_event, void * p_user_data ) |
|---|
| | 226 | { |
|---|
| | 227 | /* Remove all occurences of that one in sublist */ |
|---|
| | 228 | libvlc_media_list_t * p_mlist = p_user_data; |
|---|
| | 229 | libvlc_media_descriptor_t * p_md = p_event->u.media_list_item_deleted.item; |
|---|
| | 230 | remove_item( p_mlist, p_md ); /* Just to detach the event */ |
|---|
| | 231 | remove_item_in_submlist_rec( p_mlist, p_mlist, p_md ); |
|---|
| | 232 | } |
|---|
| | 233 | |
|---|
| | 234 | /************************************************************************** |
|---|
| | 235 | * flat_mlist_item_added (private) (Event Callback) |
|---|
| | 236 | **************************************************************************/ |
|---|
| | 237 | static void |
|---|
| | 238 | flat_mlist_item_added( const libvlc_event_t * p_event, void * p_user_data ) |
|---|
| | 239 | { |
|---|
| | 240 | libvlc_media_list_t * p_mlist = p_user_data; |
|---|
| | 241 | libvlc_media_descriptor_t * p_md = p_event->u.media_list_item_added.item; |
|---|
| | 242 | |
|---|
| | 243 | /* Add in our root */ |
|---|
| | 244 | uninstall_media_list_observer( p_mlist, p_mlist ); |
|---|
| | 245 | libvlc_media_list_add_media_descriptor( p_mlist, p_md, NULL ); |
|---|
| | 246 | install_media_list_observer( p_mlist, p_mlist ); |
|---|
| | 247 | } |
|---|
| | 248 | |
|---|
| | 249 | /************************************************************************** |
|---|
| | 250 | * install_flat_mlist_observer (Private) |
|---|
| | 251 | **************************************************************************/ |
|---|
| | 252 | static void |
|---|
| | 253 | install_flat_mlist_observer( libvlc_media_list_t * p_mlist ) |
|---|
| | 254 | { |
|---|
| | 255 | libvlc_event_attach( p_mlist->p_flat_mlist->p_event_manager, |
|---|
| 164 | | sublist_item_removed, p_mlist, NULL ); |
|---|
| 165 | | } |
|---|
| 166 | | |
|---|
| | 260 | flat_mlist_item_removed, p_mlist, NULL ); |
|---|
| | 261 | |
|---|
| | 262 | } |
|---|
| | 263 | |
|---|
| | 264 | /************************************************************************** |
|---|
| | 265 | * uninstall_flat_mlist_observer (Private) |
|---|
| | 266 | **************************************************************************/ |
|---|
| | 267 | static void |
|---|
| | 268 | uninstall_flat_mlist_observer( libvlc_media_list_t * p_mlist ) |
|---|
| | 269 | { |
|---|
| | 270 | libvlc_event_detach( p_mlist->p_flat_mlist->p_event_manager, |
|---|
| | 271 | libvlc_MediaListItemAdded, |
|---|
| | 272 | flat_mlist_item_added, p_mlist, NULL ); |
|---|
| | 273 | libvlc_event_attach( p_mlist->p_flat_mlist->p_event_manager, |
|---|
| | 274 | libvlc_MediaListItemDeleted, |
|---|
| | 275 | flat_mlist_item_removed, p_mlist, NULL ); |
|---|
| | 276 | |
|---|
| | 277 | } |
|---|
| | 278 | |
|---|
| | 279 | /* |
|---|
| | 280 | * libvlc Internal functions |
|---|
| | 281 | */ |
|---|
| | 282 | /************************************************************************** |
|---|
| | 283 | * flat_media_list_release (Internal) |
|---|
| | 284 | **************************************************************************/ |
|---|
| | 285 | void |
|---|
| | 286 | libvlc_media_list_flat_media_list_release( libvlc_media_list_t * p_mlist ) |
|---|
| | 287 | { |
|---|
| | 288 | if( !p_mlist->p_flat_mlist ) |
|---|
| | 289 | return; |
|---|
| | 290 | uninstall_flat_mlist_observer( p_mlist ); |
|---|
| | 291 | libvlc_media_list_release( p_mlist->p_flat_mlist ); |
|---|
| | 292 | } |
|---|