X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fplaylist%2Fitem-ext.c;h=b52ed4348266fbebd2e21a304962c049ff2fcd9d;hb=3083fe224f71ff21ecb86fb98983e908ef3d0dad;hp=1072c7776a50dcf46fff666e1bb9179d064dc4e6;hpb=efaf656afeed5194a8601bf2db7bd636075703bf;p=vlc diff --git a/src/playlist/item-ext.c b/src/playlist/item-ext.c index 1072c7776a..b52ed43482 100644 --- a/src/playlist/item-ext.c +++ b/src/playlist/item-ext.c @@ -1,7 +1,7 @@ /***************************************************************************** * item-ext.c : Playlist item management functions (act on the playlist) ***************************************************************************** - * Copyright (C) 1999-2004 VideoLAN + * Copyright (C) 1999-2004 the VideoLAN team * $Id$ * * Authors: Samuel Hocevar @@ -19,7 +19,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ #include /* free(), strtol() */ #include /* sprintf() */ @@ -151,7 +151,7 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item, i_mode |= PLAYLIST_APPEND; } - msg_Info( p_playlist, "adding playlist item `%s' ( %s )", + msg_Dbg( p_playlist, "adding playlist item `%s' ( %s )", p_item->input.psz_name, p_item->input.psz_uri ); p_item->input.i_id = ++p_playlist->i_last_id; @@ -200,8 +200,8 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item, { playlist_NodeAppend( p_playlist, VIEW_CATEGORY, p_item, p_playlist->p_general ); - p_add->p_item = p_item; - p_add->p_node = p_playlist->p_general; + p_add->i_item = p_item->input.i_id; + p_add->i_node = p_playlist->p_general->input.i_id; p_add->i_view = VIEW_CATEGORY; val.p_address = p_add; var_Set( p_playlist, "item-append", val ); @@ -216,26 +216,6 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item, p_view = playlist_ViewFind( p_playlist, VIEW_ALL ); playlist_ItemAddParent( p_item, VIEW_ALL, p_view->p_root ); - /* Also add the item to the "simple" view */ - p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE ); - - if( b_end == VLC_TRUE ) - { - playlist_NodeAppend( p_playlist, VIEW_SIMPLE,p_item, - p_view->p_root ); - p_add->p_item = p_item; - p_add->p_node = p_view->p_root; - p_add->i_view = VIEW_SIMPLE; - val.p_address = p_add; - var_Set( p_playlist, "item-append", val ); - } - else - { - playlist_NodeInsert( p_playlist, VIEW_SIMPLE,p_item, - p_view->p_root, i_pos ); - } - - /* FIXME : Update sorted views */ if( p_playlist->i_index >= i_pos ) @@ -252,7 +232,7 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item, { p_playlist->request.b_request = VLC_TRUE; /* FIXME ... */ - p_playlist->request.i_view = VIEW_SIMPLE; + p_playlist->request.i_view = VIEW_CATEGORY; p_playlist->request.p_node = p_view->p_root; p_playlist->request.p_item = p_item; @@ -263,6 +243,11 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item, p_playlist->status.i_status = PLAYLIST_RUNNING; } + if( i_mode & PLAYLIST_PREPARSE ) + { + playlist_PreparseEnqueue( p_playlist, &p_item->input ); + } + vlc_mutex_unlock( &p_playlist->object_lock ); if( b_end == VLC_FALSE ) @@ -301,6 +286,8 @@ int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item, vlc_mutex_lock( &p_playlist->object_lock ); + if ( i_pos == PLAYLIST_END ) i_pos = -1; + /* Sanity checks */ if( !p_parent || p_parent->i_children == -1 ) { @@ -333,7 +320,7 @@ int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item, i_mode |= PLAYLIST_APPEND; } - msg_Info( p_playlist, "adding playlist item `%s' ( %s )", + msg_Dbg( p_playlist, "adding playlist item `%s' ( %s )", p_item->input.psz_name, p_item->input.psz_uri ); p_item->input.i_id = ++p_playlist->i_last_id; @@ -354,10 +341,10 @@ int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item, p_playlist->i_enabled ++; /* TODO: Handle modes */ - playlist_NodeAppend( p_playlist, i_view, p_item, p_parent ); + playlist_NodeInsert( p_playlist, i_view, p_item, p_parent, i_pos ); - p_add->p_item = p_item; - p_add->p_node = p_parent; + p_add->i_item = p_item->input.i_id; + p_add->i_node = p_parent->input.i_id; p_add->i_view = i_view; val.p_address = p_add; var_Set( p_playlist, "item-append", val ); @@ -381,6 +368,10 @@ int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item, } p_playlist->status.i_status = PLAYLIST_RUNNING; } + if( i_mode & PLAYLIST_PREPARSE ) + { + playlist_PreparseEnqueue( p_playlist, &p_item->input ); + } vlc_mutex_unlock( &p_playlist->object_lock ); @@ -407,9 +398,9 @@ int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item, int playlist_GetPositionById( playlist_t * p_playlist , int i_id ) { int i; - for( i = 0 ; i < p_playlist->i_all_size ; i++ ) + for( i = 0 ; i < p_playlist->i_size ; i++ ) { - if( p_playlist->pp_all_items[i]->input.i_id == i_id ) + if( p_playlist->pp_items[i]->input.i_id == i_id ) { return i; } @@ -461,7 +452,7 @@ playlist_item_t *playlist_LockItemGetByPos( playlist_t *p_playlist, int i_pos ) playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id ) { int i, i_top, i_bottom; - i_bottom = 0; i_top = p_playlist->i_all_size; + 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 ) @@ -480,7 +471,6 @@ playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id ) { return p_playlist->pp_all_items[i]; } - return NULL; } @@ -642,7 +632,9 @@ int playlist_Replace( playlist_t *p_playlist, playlist_item_t *p_olditem, */ int playlist_Delete( playlist_t * p_playlist, int i_id ) { - int i; + 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 ); @@ -650,18 +642,53 @@ int playlist_Delete( playlist_t * p_playlist, int i_id ) { 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->status.p_item = NULL; + p_playlist->request.p_item = NULL; + msg_Info( p_playlist, "stopping playback" ); + b_flag = VLC_TRUE; } - msg_Info( p_playlist, "deleting playlist item `%s'", + /* 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 */ @@ -677,7 +704,10 @@ int playlist_Delete( playlist_t * p_playlist, int i_id ) /* TODO : Update views */ - playlist_ItemDelete( p_item ); + if( b_flag == VLC_FALSE ) + playlist_ItemDelete( p_item ); + else + p_item->i_flags |= PLAYLIST_REMOVE_FLAG; return VLC_SUCCESS; }