/*****************************************************************************
* 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 <sam@zoy.org>
*
* 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 <stdlib.h> /* free(), strtol() */
#include <stdio.h> /* sprintf() */
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;
{
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 );
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 )
{
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;
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 )
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 )
{
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;
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 );
}
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 );
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;
}
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 )
{
return p_playlist->pp_all_items[i];
}
-
return NULL;
}
*/
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 );
{
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 */
/* 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;
}