Commit 1756ffef authored by Jakob Leben's avatar Jakob Leben

input_item: post individual subitems later when posting the whole tree

This makes the interface more comprehensible and allows for
input_item_node_Append[x] functions to be used for general node manipulation
without side effects, if needed in future.
parent d49c4280
......@@ -124,10 +124,12 @@ VLC_EXPORT( void, input_item_SetName, ( input_item_t *p_item, const char *psz_na
* This won't hold the item, but can tell to interested third parties
* Like the playlist, that there is a new sub item. With this design
* It is not the input item's responsability to keep all the ref of
* the input item children. */
* the input item children.
*
* Sends a vlc_InputItemSubItemTreeAdded and a vlc_InputItemSubItemAdded event
*/
VLC_EXPORT( void, input_item_PostSubItem, ( input_item_t *p_parent, input_item_t *p_child ) );
/**
* Start adding multiple subitems.
*
......@@ -136,19 +138,14 @@ VLC_EXPORT( void, input_item_PostSubItem, ( input_item_t *p_parent, input_item_t
VLC_EXPORT( input_item_node_t *, input_item_node_Create, ( input_item_t *p_input ) );
/**
* Add a subitem to this input_item and to this input_item_node.
*
* A vlc_InputItemSubItemAdded event will be sent right away.
* Add a new child node to this parent node that will point to this subitem.
*/
VLC_EXPORT( input_item_node_t *, input_item_node_AppendItem, ( input_item_node_t *p_node, input_item_t *p_item ) );
/**
* Add a subitem to this input_item and to this input_item_node.
*
* A vlc_InputItemSubItemAdded event will be sent right away for the subitem
* pointed by input_item_node_t.
* Add an already created node to children of this parent node.
*/
VLC_EXPORT( void, input_item_node_AppendNode, ( input_item_node_t *p_node, input_item_node_t *p_item ) );
VLC_EXPORT( void, input_item_node_AppendNode, ( input_item_node_t *p_parent, input_item_node_t *p_child ) );
/**
* Delete a node created with input_item_node_Create() and all its children.
......@@ -158,11 +155,13 @@ VLC_EXPORT( void, input_item_node_Delete, ( input_item_node_t *p_node ) );
/**
* End adding multiple subitems.
*
* Send a notification that the item pointed to by the given root node
* has created new subitems that are pointed to by all the children of the node.
* Then delete the node and all its children.
* Sends a vlc_InputItemSubItemTreeAdded event to notify that the item pointed to
* by the given root node has created new subitems that are pointed to by all the
* children of the node.
*
* Also sends vlc_InputItemSubItemAdded event for every child under the given root node;
*
* A vlc_InputItemSubItemTreeAdded event will be sent.
* In the end deletes the node and all its children nodes.
*/
VLC_EXPORT( void, input_item_node_PostAndDelete, ( input_item_node_t *p_node ) );
......
......@@ -234,13 +234,17 @@ void input_item_CopyOptions( input_item_t *p_parent,
vlc_mutex_unlock( &p_parent->lock );
}
static void notify_subitem_added(input_item_t *p_parent, input_item_t *p_child)
static void post_subitems( input_item_node_t *p_node )
{
/* Notify interested third parties */
vlc_event_t event;
event.type = vlc_InputItemSubItemAdded;
event.u.input_item_subitem_added.p_new_child = p_child;
vlc_event_send( &p_parent->event_manager, &event );
for( int i = 0; i < p_node->i_children; i++ )
{
vlc_event_t event;
event.type = vlc_InputItemSubItemAdded;
event.u.input_item_subitem_added.p_new_child = p_node->pp_children[i]->p_item;
vlc_event_send( &p_node->p_item->event_manager, &event );
post_subitems( p_node->pp_children[i] );
}
}
/* This won't hold the item, but can tell to interested third parties
......@@ -997,8 +1001,6 @@ input_item_node_t *input_item_node_AppendItem( input_item_node_t *p_node, input_
void input_item_node_AppendNode( input_item_node_t *p_parent, input_item_node_t *p_child )
{
notify_subitem_added(p_parent->p_item, p_child->p_item);
assert( p_parent && p_child && p_child->p_parent == NULL );
INSERT_ELEM( p_parent->pp_children,
p_parent->i_children,
......@@ -1009,6 +1011,8 @@ void input_item_node_AppendNode( input_item_node_t *p_parent, input_item_node_t
void input_item_node_PostAndDelete( input_item_node_t *p_root )
{
post_subitems( p_root );
vlc_event_t event;
event.type = vlc_InputItemSubItemTreeAdded;
event.u.input_item_subitem_tree_added.p_root = p_root;
......
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