- vlc_bool_t b_found = VLC_FALSE;
- int i;
-
- for( i= 0; i< p_item->i_parents ; i++ )
- {
- if( p_item->pp_parents[i]->i_view == i_view )
-
- {
- b_found = VLC_TRUE;
- break;
- }
- }
- if( b_found == VLC_FALSE )
- {
-
- struct item_parent_t *p_ip = (struct item_parent_t *)
- malloc(sizeof(struct item_parent_t) );
- p_ip->i_view = i_view;
- p_ip->p_parent = p_parent;
-
- INSERT_ELEM( p_item->pp_parents,
- p_item->i_parents, p_item->i_parents,
- p_ip );
- }
- return VLC_SUCCESS;
+
+ playlist_item_t *p_item_in_category;
+ /* What we do
+ * Find the input in CATEGORY.
+ * - If we find it
+ * - change it to node
+ * - we'll return it at the end
+ * - If we are a direct child of onelevel root, change to node, else
+ * delete the input from ONELEVEL
+ * - If we don't find it, just change to node (we are probably in VLM)
+ * and return NULL
+ *
+ * If we were in ONELEVEL, we thus retrieve the node in CATEGORY (will be
+ * useful for later BothAddInput )
+ */
+
+ if( !b_locked ) PL_LOCK;
+
+ /* Fast track the media library, no time to loose */
+ if( p_item == p_playlist->p_ml_category ) {
+ if( !b_locked ) PL_UNLOCK;
+ return p_item;
+ }
+
+ /** \todo First look if we don't already have it */
+ p_item_in_category = playlist_ItemFindFromInputAndRoot(
+ p_playlist, p_item->p_input->i_id,
+ p_playlist->p_root_category,
+ true );
+
+ if( p_item_in_category )
+ {
+ playlist_item_t *p_item_in_one = playlist_ItemFindFromInputAndRoot(
+ p_playlist, p_item->p_input->i_id,
+ p_playlist->p_root_onelevel,
+ true );
+ assert( p_item_in_one );
+
+ /* We already have it, and there is nothing more to do */
+ ChangeToNode( p_playlist, p_item_in_category );
+
+ /* Item in one is a root, change it to node */
+ if( p_item_in_one->p_parent == p_playlist->p_root_onelevel )
+ ChangeToNode( p_playlist, p_item_in_one );
+ else
+ {
+ DeleteFromInput( p_playlist, p_item_in_one->p_input->i_id,
+ p_playlist->p_root_onelevel, false );
+ }
+ p_playlist->b_reset_currently_playing = true;
+ vlc_cond_signal( &p_playlist->object_wait );
+ var_SetInteger( p_playlist, "item-change", p_item_in_category->
+ p_input->i_id );
+ if( !b_locked ) PL_UNLOCK;
+ return p_item_in_category;
+ }
+ else
+ {
+ ChangeToNode( p_playlist, p_item );
+ if( !b_locked ) PL_UNLOCK;
+ return NULL;
+ }