/** * 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; /* Delete the children */ for( int i = p_root->i_children - 1 ; i >= 0; i-- ) if( b_delete_items || p_root->pp_children[i]->i_children >= 0 ) playlist_NodeDelete( p_playlist, p_root->pp_children[i], b_delete_items, b_force ); /* Delete the node */ if( p_root->i_flags & PLAYLIST_RO_FLAG && !b_force ) return VLC_SUCCESS; pl_priv(p_playlist)->b_reset_currently_playing = true; 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 ); if( p_root->i_children == -1 ) { ARRAY_BSEARCH( p_playlist->items,->i_id, int, p_root->i_id, i ); if( i != -1 ) ARRAY_REMOVE( p_playlist->items, i ); }
void Playtree::delSelected() { for( Iterator it = m_children.begin(); it != m_children.end(); ) { if( it->isSelected() && !it->isReadonly() ) { playlist_Lock( m_pPlaylist ); playlist_item_t *pItem = playlist_ItemGetById( m_pPlaylist, it->getId() ); if( pItem ) { if( pItem->i_children == -1 ) { playlist_DeleteFromInput( m_pPlaylist, pItem->p_input, pl_Locked ); } else { playlist_NodeDelete( m_pPlaylist, pItem, true, false ); } } playlist_Unlock( m_pPlaylist ); it = it->getNextSiblingOrUncle(); } else { it = getNextItem( it ); } } }
/** * Remove all the children of a node * * This function must be entered with the playlist lock * * \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_NodeEmpty( playlist_t *p_playlist, playlist_item_t *p_root, bool b_delete_items ) { 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 , false ); } else if( b_delete_items ) { /* Delete the item here */ playlist_DeleteFromItemId( p_playlist, p_root->pp_children[i]->i_id ); } } return VLC_SUCCESS; }
/* A new item has been removed from a certain sd */ static void playlist_sd_item_removed( const vlc_event_t * p_event, void * user_data ) { input_item_t * p_input = p_event->u.services_discovery_item_removed.p_item; playlist_item_t * p_parent = user_data; playlist_item_t * p_pl_item; /* First make sure that if item is a node it will be deleted. * XXX: Why don't we have a function to ensure that in the playlist code ? */ vlc_object_lock( p_parent->p_playlist ); p_pl_item = playlist_ItemFindFromInputAndRoot( p_parent->p_playlist, p_input->i_id, p_parent, false ); if( p_pl_item && p_pl_item->i_children > -1 ) { playlist_NodeDelete( p_parent->p_playlist, p_pl_item, true, false ); vlc_object_unlock( p_parent->p_playlist ); return; } /* Delete the non-node item normally */ playlist_DeleteFromInputInParent( p_parent->p_playlist, p_input->i_id, p_parent, pl_Locked ); vlc_object_unlock( p_parent->p_playlist ); }
/** * 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; }
/* Do the actual removal */ int playlist_DeleteItem( playlist_t * p_playlist, playlist_item_t *p_item, bool b_stop ) { assert( b_stop ); return playlist_NodeDelete( p_playlist, p_item, true, false ); }
/** * 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; }
int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist, const char *psz_module ) { struct playlist_services_discovery_support_t * p_sds = NULL; int i; PL_LOCK; for( i = 0 ; i< p_playlist->i_sds ; i ++ ) { if( !strcmp( psz_module, p_playlist->pp_sds[i]->p_sd->psz_module ) ) { p_sds = p_playlist->pp_sds[i]; REMOVE_ELEM( p_playlist->pp_sds, p_playlist->i_sds, i ); break; } } PL_UNLOCK; if( !p_sds || !p_sds->p_sd ) { msg_Warn( p_playlist, "module %s is not loaded", psz_module ); return VLC_EGENERIC; } services_discovery_Stop( p_sds->p_sd ); vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ), vlc_ServicesDiscoveryItemAdded, playlist_sd_item_added, p_sds->p_one ); vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ), vlc_ServicesDiscoveryItemAdded, playlist_sd_item_added, p_sds->p_cat ); vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ), vlc_ServicesDiscoveryItemRemoved, playlist_sd_item_removed, p_sds->p_one ); vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ), vlc_ServicesDiscoveryItemRemoved, playlist_sd_item_removed, p_sds->p_cat ); /* Remove the sd playlist node if it exists */ PL_LOCK; if( p_sds->p_cat != p_playlist->p_root_category && p_sds->p_one != p_playlist->p_root_onelevel ) { playlist_NodeDelete( p_playlist, p_sds->p_cat, true, false ); playlist_NodeDelete( p_playlist, p_sds->p_one, true, false ); } PL_UNLOCK; services_discovery_Destroy( p_sds->p_sd ); free( p_sds ); return VLC_SUCCESS; }