Commit 7b565326 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

media_list_view.c: Properly forward all items added events.

parent 0dbfd625
...@@ -56,17 +56,35 @@ install_md_listener( libvlc_media_list_view_t * p_mlv, ...@@ -56,17 +56,35 @@ install_md_listener( libvlc_media_list_view_t * p_mlv,
int i, count = libvlc_media_list_count( p_mlist, NULL ); int i, count = libvlc_media_list_count( p_mlist, NULL );
for( i = 0; i < count; i++) for( i = 0; i < count; i++)
{ {
libvlc_event_t added_event;
libvlc_media_descriptor_t * p_submd; libvlc_media_descriptor_t * p_submd;
p_submd = libvlc_media_list_item_at_index( p_mlist, i, NULL ); p_submd = libvlc_media_list_item_at_index( p_mlist, i, NULL );
/* Install our listeners */
install_md_listener( p_mlv, p_submd ); install_md_listener( p_mlv, p_submd );
/* For each item, send a notification to the mlv subclasses */
added_event.u.media_list_item_added.item = p_submd;
added_event.u.media_list_item_added.index = 0;
if( p_mlv->pf_ml_item_added ) p_mlv->pf_ml_item_added( &added_event, p_mlv );
libvlc_media_descriptor_release( p_submd ); libvlc_media_descriptor_release( p_submd );
} }
libvlc_event_attach( p_mlist->p_event_manager,
libvlc_MediaListItemAdded,
media_list_item_added, p_mlv, NULL );
libvlc_event_attach( p_mlist->p_event_manager,
libvlc_MediaListItemDeleted,
media_list_item_removed, p_mlv, NULL );
libvlc_media_list_unlock( p_mlist ); libvlc_media_list_unlock( p_mlist );
libvlc_media_list_release( p_mlist ); libvlc_media_list_release( p_mlist );
} }
else
{
/* No mlist, wait for a subitem added event */
libvlc_event_attach( p_md->p_event_manager, libvlc_event_attach( p_md->p_event_manager,
libvlc_MediaDescriptorSubItemAdded, libvlc_MediaDescriptorSubItemAdded,
media_list_subitem_added, p_mlv, NULL ); media_list_subitem_added, p_mlv, NULL );
}
} }
static void static void
...@@ -84,6 +102,13 @@ uninstall_md_listener( libvlc_media_list_view_t * p_mlv, ...@@ -84,6 +102,13 @@ uninstall_md_listener( libvlc_media_list_view_t * p_mlv,
if((p_mlist = libvlc_media_descriptor_subitems( p_md, NULL ))) if((p_mlist = libvlc_media_descriptor_subitems( p_md, NULL )))
{ {
libvlc_media_list_lock( p_mlist ); libvlc_media_list_lock( p_mlist );
libvlc_event_detach( p_mlist->p_event_manager,
libvlc_MediaListItemAdded,
media_list_item_added, p_mlv, NULL );
libvlc_event_detach( p_mlist->p_event_manager,
libvlc_MediaListItemDeleted,
media_list_item_removed, p_mlv, NULL );
int i, count = libvlc_media_list_count( p_mlist, NULL ); int i, count = libvlc_media_list_count( p_mlist, NULL );
for( i = 0; i < count; i++) for( i = 0; i < count; i++)
{ {
...@@ -103,6 +128,7 @@ media_list_item_added( const libvlc_event_t * p_event, void * p_user_data ) ...@@ -103,6 +128,7 @@ media_list_item_added( const libvlc_event_t * p_event, void * p_user_data )
libvlc_media_list_view_t * p_mlv = p_user_data; libvlc_media_list_view_t * p_mlv = p_user_data;
libvlc_media_descriptor_t * p_md = p_event->u.media_list_item_added.item; libvlc_media_descriptor_t * p_md = p_event->u.media_list_item_added.item;
install_md_listener( p_mlv, p_md ); install_md_listener( p_mlv, p_md );
printf("media_list_item_added\n");
if( p_mlv->pf_ml_item_added ) p_mlv->pf_ml_item_added( p_event, p_mlv ); if( p_mlv->pf_ml_item_added ) p_mlv->pf_ml_item_added( p_event, p_mlv );
} }
...@@ -118,12 +144,34 @@ media_list_item_removed( const libvlc_event_t * p_event, void * p_user_data ) ...@@ -118,12 +144,34 @@ media_list_item_removed( const libvlc_event_t * p_event, void * p_user_data )
static void static void
media_list_subitem_added( const libvlc_event_t * p_event, void * p_user_data ) media_list_subitem_added( const libvlc_event_t * p_event, void * p_user_data )
{ {
libvlc_media_list_t * p_mlist;
libvlc_event_t added_event; libvlc_event_t added_event;
libvlc_media_list_view_t * p_mlv = p_user_data; libvlc_media_list_view_t * p_mlv = p_user_data;
libvlc_media_descriptor_t * p_md = p_event->u.media_descriptor_subitem_added.new_child; libvlc_media_descriptor_t * p_submd = p_event->u.media_descriptor_subitem_added.new_child;
install_md_listener( p_mlv, p_md ); libvlc_media_descriptor_t * p_md = p_event->p_obj;
if((p_mlist = libvlc_media_descriptor_subitems( p_md, NULL )))
{
/* We have a mlist to which we're going to listen to events
* thus, no need to wait for SubItemAdded events */
libvlc_event_detach( p_md->p_event_manager,
libvlc_MediaDescriptorSubItemAdded,
media_list_subitem_added, p_mlv, NULL );
libvlc_media_list_lock( p_mlist );
libvlc_event_attach( p_mlist->p_event_manager,
libvlc_MediaListItemAdded,
media_list_item_added, p_mlv, NULL );
libvlc_event_attach( p_mlist->p_event_manager,
libvlc_MediaListItemDeleted,
media_list_item_removed, p_mlv, NULL );
libvlc_media_list_unlock( p_mlist );
libvlc_media_list_release( p_mlist );
}
install_md_listener( p_mlv, p_submd );
added_event.u.media_list_item_added.item = p_md; added_event.u.media_list_item_added.item = p_submd;
added_event.u.media_list_item_added.index = 0; added_event.u.media_list_item_added.index = 0;
if( p_mlv->pf_ml_item_added ) p_mlv->pf_ml_item_added( &added_event, p_mlv ); if( p_mlv->pf_ml_item_added ) p_mlv->pf_ml_item_added( &added_event, p_mlv );
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment