/** * Remove all the children of a node and removes the node * * \param p_playlist the playlist * \param p_root the node * \param b_delete_items do we have to delete the children items ? * \return VLC_SUCCESS or an error */ int playlist_NodeDelete( playlist_t *p_playlist, playlist_item_t *p_root, bool b_delete_items, bool b_force ) { PL_ASSERT_LOCKED; int i; if( p_root->i_children == -1 ) { return VLC_EGENERIC; } /* Delete the children */ for( i = p_root->i_children - 1 ; i >= 0; i-- ) { if( p_root->pp_children[i]->i_children > -1 ) { playlist_NodeDelete( p_playlist, p_root->pp_children[i], b_delete_items , b_force ); } else if( b_delete_items ) { playlist_DeleteFromItemId( p_playlist, p_root->pp_children[i]->i_id ); } } /* Delete the node */ if( p_root->i_flags & PLAYLIST_RO_FLAG && !b_force ) { } else { int i; var_SetInteger( p_playlist, "playlist-item-deleted", p_root->i_id ); ARRAY_BSEARCH( p_playlist->all_items, ->i_id, int, p_root->i_id, i ); if( i != -1 ) ARRAY_REMOVE( p_playlist->all_items, i ); /* Remove the item from its parent */ if( p_root->p_parent ) playlist_NodeRemoveItem( p_playlist, p_root, p_root->p_parent ); playlist_ItemRelease( p_root ); } return VLC_SUCCESS; }
/** * Deletes an item from a playlist. * * This function must be entered without the playlist lock * * \param p_playlist the playlist to remove from. * \param i_id the identifier of the item to delete * \return returns VLC_SUCCESS or an error */ int playlist_Delete( playlist_t * p_playlist, int i_id ) { int i, i_top, i_bottom; int i_pos; vlc_bool_t b_flag = VLC_FALSE; playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id ); if( p_item == NULL ) { return VLC_EGENERIC; } if( p_item->i_children > -1 ) { return playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE ); } var_SetInteger( p_playlist, "item-deleted", i_id ); i_bottom = 0; i_top = p_playlist->i_all_size - 1; i = i_top / 2; while( p_playlist->pp_all_items[i]->input.i_id != i_id && i_top > i_bottom ) { if( p_playlist->pp_all_items[i]->input.i_id < i_id ) { i_bottom = i + 1; } else { i_top = i - 1; } i = i_bottom + ( i_top - i_bottom ) / 2; } if( p_playlist->pp_all_items[i]->input.i_id == i_id ) { REMOVE_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size, i ); } /* Check if it is the current item */ if( p_playlist->status.p_item == p_item ) { /* Hack we don't call playlist_Control for lock reasons */ p_playlist->status.i_status = PLAYLIST_STOPPED; p_playlist->request.b_request = VLC_TRUE; p_playlist->request.p_item = NULL; msg_Info( p_playlist, "stopping playback" ); b_flag = VLC_TRUE; } /* Get position and update index if needed */ i_pos = playlist_GetPositionById( p_playlist, i_id ); if( i_pos >= 0 && i_pos <= p_playlist->i_index ) { p_playlist->i_index--; } msg_Dbg( p_playlist, "deleting playlist item `%s'", p_item->input.psz_name ); /* Remove the item from all its parent nodes */ for ( i= 0 ; i < p_item->i_parents ; i++ ) { playlist_NodeRemoveItem( p_playlist, p_item, p_item->pp_parents[i]->p_parent ); if( p_item->pp_parents[i]->i_view == VIEW_ALL ) { p_playlist->i_size--; } } /* TODO : Update views */ if( b_flag == VLC_FALSE ) playlist_ItemDelete( p_item ); else p_item->i_flags |= PLAYLIST_REMOVE_FLAG; return VLC_SUCCESS; }