1 /*****************************************************************************
2 * item.c : Playlist item creation/deletion/add/removal functions
3 *****************************************************************************
4 * Copyright (C) 1999-2007 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Clément Stenac <zorglub@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
30 #include <vlc_playlist.h>
31 #include "playlist_internal.h"
33 static void AddItem( playlist_t
*p_playlist
, playlist_item_t
*p_item
,
34 playlist_item_t
*p_node
, int i_mode
, int i_pos
);
35 static void GoAndPreparse( playlist_t
*p_playlist
, int i_mode
,
36 playlist_item_t
*, playlist_item_t
* );
37 static void ChangeToNode( playlist_t
*p_playlist
, playlist_item_t
*p_item
);
38 static int DeleteInner( playlist_t
* p_playlist
, playlist_item_t
*p_item
,
41 /*****************************************************************************
42 * An input item has gained a subitem (Event Callback)
43 *****************************************************************************/
44 static void input_item_subitem_added( const vlc_event_t
* p_event
,
47 playlist_item_t
*p_parent_playlist_item
= user_data
;
48 playlist_t
* p_playlist
= p_parent_playlist_item
->p_playlist
;
49 input_item_t
* p_parent
, * p_child
;
50 playlist_item_t
* p_child_in_category
;
51 playlist_item_t
* p_item_in_category
;
54 p_parent
= p_event
->p_obj
;
55 p_child
= p_event
->u
.input_item_subitem_added
.p_new_child
;
58 b_play
= var_CreateGetBool( p_playlist
, "playlist-autostart" );
60 /* This part is really hakish, but this playlist system isn't simple */
61 /* First check if we haven't already added the item as we are
62 * listening using the onelevel and the category representent
63 * (Because of the playlist design) */
64 p_child_in_category
= playlist_ItemFindFromInputAndRoot(
65 p_playlist
, p_child
->i_id
,
66 p_playlist
->p_root_category
,
67 VLC_FALSE
/* Only non-node */ );
69 if( !p_child_in_category
)
71 /* Then, transform to a node if needed */
72 p_item_in_category
= playlist_ItemFindFromInputAndRoot(
73 p_playlist
, p_parent
->i_id
,
74 p_playlist
->p_root_category
,
75 VLC_FALSE
/* Only non-node */ );
76 if( !p_item_in_category
)
78 /* Item may have been removed */
83 b_play
= b_play
&& p_item_in_category
== p_playlist
->status
.p_item
;
85 /* If this item is already a node don't transform it */
86 if( p_item_in_category
->i_children
== -1 )
88 p_item_in_category
= playlist_ItemToNode( p_playlist
,
89 p_item_in_category
, VLC_TRUE
);
90 p_item_in_category
->p_input
->i_type
= ITEM_TYPE_PLAYLIST
;
93 playlist_BothAddInput( p_playlist
, p_child
, p_item_in_category
,
94 PLAYLIST_APPEND
| PLAYLIST_SPREPARSE
, PLAYLIST_END
,
95 NULL
, NULL
, VLC_TRUE
);
99 playlist_Control( p_playlist
, PLAYLIST_VIEWPLAY
,
100 VLC_TRUE
, p_item_in_category
, NULL
);
108 /*****************************************************************************
109 * Listen to vlc_InputItemAddSubItem event
110 *****************************************************************************/
111 static void install_input_item_observer( playlist_item_t
* p_item
)
113 vlc_event_attach( &p_item
->p_input
->event_manager
,
114 vlc_InputItemSubItemAdded
,
115 input_item_subitem_added
,
119 static void uninstall_input_item_observer( playlist_item_t
* p_item
)
121 vlc_event_detach( &p_item
->p_input
->event_manager
,
122 vlc_InputItemSubItemAdded
,
123 input_item_subitem_added
,
128 /*****************************************************************************
129 * Playlist item creation
130 *****************************************************************************/
131 playlist_item_t
* playlist_ItemNewWithType( vlc_object_t
*p_obj
,
133 const char *psz_name
,
135 const char *const *ppsz_options
,
136 int i_duration
, int i_type
)
138 input_item_t
*p_input
;
139 if( psz_uri
== NULL
) return NULL
;
140 p_input
= input_ItemNewWithType( p_obj
, psz_uri
,
141 psz_name
, i_options
, ppsz_options
,
142 i_duration
, i_type
);
143 return playlist_ItemNewFromInput( p_obj
, p_input
);
146 playlist_item_t
*__playlist_ItemNewFromInput( vlc_object_t
*p_obj
,
147 input_item_t
*p_input
)
149 DECMALLOC_NULL( p_item
, playlist_item_t
);
150 playlist_t
*p_playlist
= pl_Yield( p_obj
);
152 p_item
->p_input
= p_input
;
153 vlc_gc_incref( p_item
->p_input
);
155 p_item
->i_id
= ++p_playlist
->i_last_playlist_id
;
157 p_item
->p_parent
= NULL
;
158 p_item
->i_children
= -1;
159 p_item
->pp_children
= NULL
;
161 p_item
->p_playlist
= p_playlist
;
163 install_input_item_observer( p_item
);
165 pl_Release( p_item
->p_playlist
);
170 /***************************************************************************
171 * Playlist item destruction
172 ***************************************************************************/
174 /** Delete a playlist item and detach its input item */
175 int playlist_ItemDelete( playlist_item_t
*p_item
)
177 uninstall_input_item_observer( p_item
);
179 vlc_gc_decref( p_item
->p_input
);
184 /** Remove an input item when it appears from a root playlist item */
185 static int DeleteFromInput( playlist_t
*p_playlist
, int i_input_id
,
186 playlist_item_t
*p_root
, vlc_bool_t b_do_stop
)
189 for( i
= 0 ; i
< p_root
->i_children
; i
++ )
191 if( p_root
->pp_children
[i
]->i_children
== -1 &&
192 p_root
->pp_children
[i
]->p_input
->i_id
== i_input_id
)
194 DeleteInner( p_playlist
, p_root
->pp_children
[i
], b_do_stop
);
197 else if( p_root
->pp_children
[i
]->i_children
>= 0 )
199 int i_ret
= DeleteFromInput( p_playlist
, i_input_id
,
200 p_root
->pp_children
[i
], b_do_stop
);
201 if( i_ret
== VLC_SUCCESS
) return VLC_SUCCESS
;
207 /** Remove an input item when it appears from a root playlist item */
208 int playlist_DeleteInputInParent( playlist_t
*p_playlist
, int i_input_id
,
209 playlist_item_t
*p_root
, vlc_bool_t b_locked
)
212 if( !b_locked
) PL_LOCK
;
213 i_ret
= DeleteFromInput( p_playlist
, i_input_id
,
215 if( !b_locked
) PL_UNLOCK
;
219 /** Remove an input item from ONELEVEL and CATEGORY */
220 int playlist_DeleteFromInput( playlist_t
*p_playlist
, int i_input_id
,
221 vlc_bool_t b_locked
)
224 if( !b_locked
) PL_LOCK
;
225 i_ret1
= DeleteFromInput( p_playlist
, i_input_id
,
226 p_playlist
->p_root_category
, VLC_TRUE
);
227 i_ret2
= DeleteFromInput( p_playlist
, i_input_id
,
228 p_playlist
->p_root_onelevel
, VLC_TRUE
);
229 if( !b_locked
) PL_UNLOCK
;
230 return ( i_ret1
== VLC_SUCCESS
|| i_ret2
== VLC_SUCCESS
) ?
231 VLC_SUCCESS
: VLC_ENOITEM
;
234 void playlist_Clear( playlist_t
* p_playlist
, vlc_bool_t b_locked
)
236 if( !b_locked
) PL_LOCK
;
237 playlist_NodeEmpty( p_playlist
, p_playlist
->p_local_category
, VLC_TRUE
);
238 playlist_NodeEmpty( p_playlist
, p_playlist
->p_local_onelevel
, VLC_TRUE
);
239 if( !b_locked
) PL_UNLOCK
;
242 /** Remove a playlist item from the playlist, given its id
243 * This function is to be used only by the playlist */
244 int playlist_DeleteFromItemId( playlist_t
*p_playlist
, int i_id
)
246 playlist_item_t
*p_item
= playlist_ItemGetById( p_playlist
, i_id
,
248 if( !p_item
) return VLC_EGENERIC
;
249 return DeleteInner( p_playlist
, p_item
, VLC_TRUE
);
252 /***************************************************************************
253 * Playlist item addition
254 ***************************************************************************/
255 /** Add an item to the playlist or the media library
256 * \param p_playlist the playlist to add into
257 * \param psz_uri the mrl to add to the playlist
258 * \param psz_name a text giving a name or description of this item
259 * \param i_mode the mode used when adding
260 * \param i_pos the position in the playlist where to add. If this is
261 * PLAYLIST_END the item will be added at the end of the playlist
262 * regardless of its size
263 * \param b_playlist TRUE for playlist, FALSE for media library
264 * \return The id of the playlist item
266 int playlist_Add( playlist_t
*p_playlist
, const char *psz_uri
,
267 const char *psz_name
, int i_mode
, int i_pos
,
268 vlc_bool_t b_playlist
, vlc_bool_t b_locked
)
270 return playlist_AddExt( p_playlist
, psz_uri
, psz_name
,
271 i_mode
, i_pos
, -1, NULL
, 0, b_playlist
, b_locked
);
275 * Add a MRL into the playlist or the media library, duration and options given
277 * \param p_playlist the playlist to add into
278 * \param psz_uri the mrl to add to the playlist
279 * \param psz_name a text giving a name or description of this item
280 * \param i_mode the mode used when adding
281 * \param i_pos the position in the playlist where to add. If this is
282 * PLAYLIST_END the item will be added at the end of the playlist
283 * regardless of its size
284 * \param i_duration length of the item in milliseconds.
285 * \param ppsz_options an array of options
286 * \param i_options the number of options
287 * \param b_playlist TRUE for playlist, FALSE for media library
288 * \return The id of the playlist item
290 int playlist_AddExt( playlist_t
*p_playlist
, const char * psz_uri
,
291 const char *psz_name
, int i_mode
, int i_pos
,
292 mtime_t i_duration
, const char *const *ppsz_options
,
293 int i_options
, vlc_bool_t b_playlist
, vlc_bool_t b_locked
)
296 input_item_t
*p_input
= input_ItemNewExt( p_playlist
, psz_uri
, psz_name
,
297 i_options
, ppsz_options
,
300 i_ret
= playlist_AddInput( p_playlist
, p_input
, i_mode
, i_pos
, b_playlist
,
302 int i_id
= i_ret
== VLC_SUCCESS
? p_input
->i_id
: -1;
304 vlc_gc_decref( p_input
);
309 /** Add an input item to the playlist node */
310 int playlist_AddInput( playlist_t
* p_playlist
, input_item_t
*p_input
,
311 int i_mode
, int i_pos
, vlc_bool_t b_playlist
,
312 vlc_bool_t b_locked
)
314 playlist_item_t
*p_item_cat
, *p_item_one
;
316 if( !p_playlist
->b_doing_ml
)
317 PL_DEBUG( "adding item `%s' ( %s )", p_input
->psz_name
,
320 if( !b_locked
) PL_LOCK
;
322 /* Add to ONELEVEL */
323 p_item_one
= playlist_ItemNewFromInput( p_playlist
, p_input
);
324 if( p_item_one
== NULL
) return VLC_ENOMEM
;
325 AddItem( p_playlist
, p_item_one
,
326 b_playlist
? p_playlist
->p_local_onelevel
:
327 p_playlist
->p_ml_onelevel
, i_mode
, i_pos
);
329 /* Add to CATEGORY */
330 p_item_cat
= playlist_ItemNewFromInput( p_playlist
, p_input
);
331 if( p_item_cat
== NULL
) return VLC_ENOMEM
;
332 AddItem( p_playlist
, p_item_cat
,
333 b_playlist
? p_playlist
->p_local_category
:
334 p_playlist
->p_ml_category
, i_mode
, i_pos
);
336 GoAndPreparse( p_playlist
, i_mode
, p_item_cat
, p_item_one
);
338 if( !b_locked
) PL_UNLOCK
;
342 /** Add an input item to p_direct_parent in the category tree, and to the
343 * matching top category in onelevel **/
344 int playlist_BothAddInput( playlist_t
*p_playlist
,
345 input_item_t
*p_input
,
346 playlist_item_t
*p_direct_parent
,
347 int i_mode
, int i_pos
,
348 int *i_cat
, int *i_one
, vlc_bool_t b_locked
)
350 playlist_item_t
*p_item_cat
, *p_item_one
, *p_up
;
353 if( !b_locked
) PL_LOCK
;
355 /* Add to category */
356 p_item_cat
= playlist_ItemNewFromInput( p_playlist
, p_input
);
357 if( p_item_cat
== NULL
) return VLC_ENOMEM
;
358 AddItem( p_playlist
, p_item_cat
, p_direct_parent
, i_mode
, i_pos
);
360 /* Add to onelevel */
361 /**Â \todo make a faster case for ml import */
362 p_item_one
= playlist_ItemNewFromInput( p_playlist
, p_input
);
363 if( p_item_one
== NULL
) return VLC_ENOMEM
;
365 p_up
= p_direct_parent
;
366 while( p_up
->p_parent
!= p_playlist
->p_root_category
)
368 p_up
= p_up
->p_parent
;
370 for( i_top
= 0 ; i_top
< p_playlist
->p_root_onelevel
->i_children
; i_top
++ )
372 if( p_playlist
->p_root_onelevel
->pp_children
[i_top
]->p_input
->i_id
==
373 p_up
->p_input
->i_id
)
375 AddItem( p_playlist
, p_item_one
,
376 p_playlist
->p_root_onelevel
->pp_children
[i_top
],
381 GoAndPreparse( p_playlist
, i_mode
, p_item_cat
, p_item_one
);
383 if( i_cat
) *i_cat
= p_item_cat
->i_id
;
384 if( i_one
) *i_one
= p_item_one
->i_id
;
386 if( !b_locked
) PL_UNLOCK
;
390 /** Add an input item to a given node */
391 playlist_item_t
* playlist_NodeAddInput( playlist_t
*p_playlist
,
392 input_item_t
*p_input
,
393 playlist_item_t
*p_parent
,
394 int i_mode
, int i_pos
,
395 vlc_bool_t b_locked
)
397 playlist_item_t
*p_item
;
399 assert( p_parent
&& p_parent
->i_children
!= -1 );
401 if( !b_locked
) PL_LOCK
;
403 p_item
= playlist_ItemNewFromInput( p_playlist
, p_input
);
404 if( p_item
== NULL
) return NULL
;
405 AddItem( p_playlist
, p_item
, p_parent
, i_mode
, i_pos
);
407 if( !b_locked
) PL_UNLOCK
;
412 /*****************************************************************************
413 * Playlist item misc operations
414 *****************************************************************************/
417 * Transform an item to a node. Return the node in the category tree, or NULL
419 * This function must be entered without the playlist lock
421 playlist_item_t
*playlist_ItemToNode( playlist_t
*p_playlist
,
422 playlist_item_t
*p_item
,
423 vlc_bool_t b_locked
)
426 playlist_item_t
*p_item_in_category
;
428 * Find the input in CATEGORY.
430 * - change it to node
431 * - we'll return it at the end
432 * - If we are a direct child of onelevel root, change to node, else
433 * delete the input from ONELEVEL
434 * - If we don't find it, just change to node (we are probably in VLM)
437 * If we were in ONELEVEL, we thus retrieve the node in CATEGORY (will be
438 * useful for later BothAddInput )
441 if( !b_locked
) PL_LOCK
;
443 /* Fast track the media library, no time to loose */
444 if( p_item
== p_playlist
->p_ml_category
) {
445 if( !b_locked
) PL_UNLOCK
;
449 /** \todo First look if we don't already have it */
450 p_item_in_category
= playlist_ItemFindFromInputAndRoot(
451 p_playlist
, p_item
->p_input
->i_id
,
452 p_playlist
->p_root_category
,
455 if( p_item_in_category
)
457 playlist_item_t
*p_item_in_one
= playlist_ItemFindFromInputAndRoot(
458 p_playlist
, p_item
->p_input
->i_id
,
459 p_playlist
->p_root_onelevel
,
461 assert( p_item_in_one
);
463 /* We already have it, and there is nothing more to do */
464 ChangeToNode( p_playlist
, p_item_in_category
);
466 /* Item in one is a root, change it to node */
467 if( p_item_in_one
->p_parent
== p_playlist
->p_root_onelevel
)
468 ChangeToNode( p_playlist
, p_item_in_one
);
471 DeleteFromInput( p_playlist
, p_item_in_one
->p_input
->i_id
,
472 p_playlist
->p_root_onelevel
, VLC_FALSE
);
474 p_playlist
->b_reset_currently_playing
= VLC_TRUE
;
475 vlc_cond_signal( &p_playlist
->object_wait
);
476 var_SetInteger( p_playlist
, "item-change", p_item_in_category
->
478 if( !b_locked
) PL_UNLOCK
;
479 return p_item_in_category
;
483 ChangeToNode( p_playlist
, p_item
);
484 if( !b_locked
) PL_UNLOCK
;
489 /** Find an item within a root, given its input id.
490 * \return the first found item, or NULL if not found
492 playlist_item_t
*playlist_ItemFindFromInputAndRoot( playlist_t
*p_playlist
,
494 playlist_item_t
*p_root
,
495 vlc_bool_t b_items_only
)
498 for( i
= 0 ; i
< p_root
->i_children
; i
++ )
500 if( ( b_items_only
? p_root
->pp_children
[i
]->i_children
== -1 : 1 ) &&
501 p_root
->pp_children
[i
]->p_input
->i_id
== i_input_id
)
503 return p_root
->pp_children
[i
];
505 else if( p_root
->pp_children
[i
]->i_children
>= 0 )
507 playlist_item_t
*p_search
=
508 playlist_ItemFindFromInputAndRoot( p_playlist
, i_input_id
,
509 p_root
->pp_children
[i
],
511 if( p_search
) return p_search
;
518 static int TreeMove( playlist_t
*p_playlist
, playlist_item_t
*p_item
,
519 playlist_item_t
*p_node
, int i_newpos
)
522 playlist_item_t
*p_detach
= p_item
->p_parent
;
525 if( p_node
->i_children
== -1 ) return VLC_EGENERIC
;
527 for( j
= 0; j
< p_detach
->i_children
; j
++ )
529 if( p_detach
->pp_children
[j
] == p_item
) break;
531 REMOVE_ELEM( p_detach
->pp_children
, p_detach
->i_children
, j
);
533 /* Attach to new parent */
534 INSERT_ELEM( p_node
->pp_children
, p_node
->i_children
, i_newpos
, p_item
);
535 p_item
->p_parent
= p_node
;
543 * This function must be entered with the playlist lock
545 * \param p_playlist the playlist
546 * \param p_item the item to move
547 * \param p_node the new parent of the item
548 * \param i_newpos the new position under this new parent
549 * \return VLC_SUCCESS or an error
551 int playlist_TreeMove( playlist_t
* p_playlist
, playlist_item_t
*p_item
,
552 playlist_item_t
*p_node
, int i_newpos
)
555 /* Drop on a top level node. Move in the two trees */
556 if( p_node
->p_parent
== p_playlist
->p_root_category
||
557 p_node
->p_parent
== p_playlist
->p_root_onelevel
)
559 /* Fixme: avoid useless lookups but we need some clean helpers */
561 /* Fixme: if we try to move a node on a top-level node, it will
562 * fail because the node doesn't exist in onelevel and we will
563 * do some shit in onelevel. We should recursively move all items
565 playlist_item_t
*p_node_onelevel
;
566 playlist_item_t
*p_item_onelevel
;
567 p_node_onelevel
= playlist_ItemFindFromInputAndRoot( p_playlist
,
568 p_node
->p_input
->i_id
,
569 p_playlist
->p_root_onelevel
,
571 p_item_onelevel
= playlist_ItemFindFromInputAndRoot( p_playlist
,
572 p_item
->p_input
->i_id
,
573 p_playlist
->p_root_onelevel
,
575 if( p_node_onelevel
&& p_item_onelevel
)
576 TreeMove( p_playlist
, p_item_onelevel
, p_node_onelevel
, 0 );
579 playlist_item_t
*p_node_category
;
580 playlist_item_t
*p_item_category
;
581 p_node_category
= playlist_ItemFindFromInputAndRoot( p_playlist
,
582 p_node
->p_input
->i_id
,
583 p_playlist
->p_root_category
,
585 p_item_category
= playlist_ItemFindFromInputAndRoot( p_playlist
,
586 p_item
->p_input
->i_id
,
587 p_playlist
->p_root_category
,
589 if( p_node_category
&& p_item_category
)
590 TreeMove( p_playlist
, p_item_category
, p_node_category
, 0 );
595 i_ret
= TreeMove( p_playlist
, p_item
, p_node
, i_newpos
);
596 p_playlist
->b_reset_currently_playing
= VLC_TRUE
;
597 vlc_cond_signal( &p_playlist
->object_wait
);
601 /** Send a notification that an item has been added to a node */
602 void playlist_SendAddNotify( playlist_t
*p_playlist
, int i_item_id
,
603 int i_node_id
, vlc_bool_t b_signal
)
606 playlist_add_t
*p_add
= (playlist_add_t
*)malloc(sizeof( playlist_add_t
));
607 p_add
->i_item
= i_item_id
;
608 p_add
->i_node
= i_node_id
;
609 val
.p_address
= p_add
;
610 p_playlist
->b_reset_currently_playing
= VLC_TRUE
;
612 vlc_cond_signal( &p_playlist
->object_wait
);
613 var_Set( p_playlist
, "item-append", val
);
617 /*****************************************************************************
618 * Playlist item accessors
619 *****************************************************************************/
621 /** Set the name of a playlist item */
622 int playlist_ItemSetName( playlist_item_t
*p_item
, const char *psz_name
)
624 if( psz_name
&& p_item
)
626 input_item_SetName( p_item
->p_input
, psz_name
);
632 /***************************************************************************
633 * The following functions are local
634 ***************************************************************************/
636 /* Enqueue an item for preparsing, and play it, if needed */
637 static void GoAndPreparse( playlist_t
*p_playlist
, int i_mode
,
638 playlist_item_t
*p_item_cat
,
639 playlist_item_t
*p_item_one
)
641 if( (i_mode
& PLAYLIST_GO
) )
643 playlist_item_t
*p_parent
= p_item_one
;
644 playlist_item_t
*p_toplay
= NULL
;
647 if( p_parent
== p_playlist
->p_root_category
)
649 p_toplay
= p_item_cat
; break;
651 else if( p_parent
== p_playlist
->p_root_onelevel
)
653 p_toplay
= p_item_one
; break;
655 p_parent
= p_parent
->p_parent
;
658 p_playlist
->request
.b_request
= VLC_TRUE
;
659 p_playlist
->request
.i_skip
= 0;
660 p_playlist
->request
.p_item
= p_toplay
;
661 if( p_playlist
->p_input
)
662 input_StopThread( p_playlist
->p_input
);
663 p_playlist
->request
.i_status
= PLAYLIST_RUNNING
;
664 vlc_cond_signal( &p_playlist
->object_wait
);
666 /* Preparse if PREPARSE or SPREPARSE & not enough meta */
667 char *psz_artist
= input_item_GetArtist( p_item_cat
->p_input
);
668 char *psz_album
= input_item_GetAlbum( p_item_cat
->p_input
);
669 if( p_playlist
->b_auto_preparse
&&
670 (i_mode
& PLAYLIST_PREPARSE
||
671 ( i_mode
& PLAYLIST_SPREPARSE
&&
672 ( EMPTY_STR( psz_artist
) || ( EMPTY_STR( psz_album
) ) )
674 playlist_PreparseEnqueue( p_playlist
, p_item_cat
->p_input
);
675 /* If we already have it, signal it */
676 else if( !EMPTY_STR( psz_artist
) && !EMPTY_STR( psz_album
) )
677 input_item_SetPreparsed( p_item_cat
->p_input
, VLC_TRUE
);
682 /* Add the playlist item to the requested node and fire a notification */
683 static void AddItem( playlist_t
*p_playlist
, playlist_item_t
*p_item
,
684 playlist_item_t
*p_node
, int i_mode
, int i_pos
)
686 ARRAY_APPEND(p_playlist
->items
, p_item
);
687 ARRAY_APPEND(p_playlist
->all_items
, p_item
);
688 p_playlist
->i_enabled
++;
690 if( i_pos
== PLAYLIST_END
)
691 playlist_NodeAppend( p_playlist
, p_item
, p_node
);
693 playlist_NodeInsert( p_playlist
, p_item
, p_node
, i_pos
);
695 if( !p_playlist
->b_doing_ml
)
696 playlist_SendAddNotify( p_playlist
, p_item
->i_id
, p_node
->i_id
,
697 !( i_mode
& PLAYLIST_NO_REBUILD
) );
700 /* Actually convert an item to a node */
701 static void ChangeToNode( playlist_t
*p_playlist
, playlist_item_t
*p_item
)
704 if( p_item
->i_children
== -1 )
705 p_item
->i_children
= 0;
707 /* Remove it from the array of available items */
708 ARRAY_BSEARCH( p_playlist
->items
,->i_id
, int, p_item
->i_id
, i
);
710 ARRAY_REMOVE( p_playlist
->items
, i
);
713 /* Do the actual removal */
714 static int DeleteInner( playlist_t
* p_playlist
, playlist_item_t
*p_item
,
718 int i_id
= p_item
->i_id
;
719 vlc_bool_t b_delay_deletion
= VLC_FALSE
;
721 if( p_item
->i_children
> -1 )
723 return playlist_NodeDelete( p_playlist
, p_item
, VLC_TRUE
, VLC_FALSE
);
725 p_playlist
->b_reset_currently_playing
= VLC_TRUE
;
726 var_SetInteger( p_playlist
, "item-deleted", i_id
);
728 /* Remove the item from the bank */
729 ARRAY_BSEARCH( p_playlist
->all_items
,->i_id
, int, i_id
, i
);
731 ARRAY_REMOVE( p_playlist
->all_items
, i
);
733 /* Check if it is the current item */
734 if( p_playlist
->status
.p_item
== p_item
)
736 /* Hack we don't call playlist_Control for lock reasons */
739 p_playlist
->request
.i_status
= PLAYLIST_STOPPED
;
740 p_playlist
->request
.b_request
= VLC_TRUE
;
741 p_playlist
->request
.p_item
= NULL
;
742 msg_Info( p_playlist
, "stopping playback" );
743 vlc_cond_signal( &p_playlist
->object_wait
);
745 b_delay_deletion
= VLC_TRUE
;
748 PL_DEBUG( "deleting item `%s'", p_item
->p_input
->psz_name
);
750 /* Remove the item from its parent */
751 playlist_NodeRemoveItem( p_playlist
, p_item
, p_item
->p_parent
);
753 if( !b_delay_deletion
)
754 playlist_ItemDelete( p_item
);
757 PL_DEBUG( "marking %s for further deletion", PLI_NAME( p_item
) );
758 p_item
->i_flags
|= PLAYLIST_REMOVE_FLAG
;