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 *****************************************************************************/
28 #include <vlc_common.h>
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 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 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, true );
90 p_item_in_category->p_input->i_type = ITEM_TYPE_PLAYLIST;
93 int i_ret = playlist_BothAddInput( p_playlist, p_child,
95 PLAYLIST_APPEND | PLAYLIST_SPREPARSE , PLAYLIST_END,
98 if( i_ret == VLC_SUCCESS && b_play )
100 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
101 true, p_item_in_category, NULL );
109 /*****************************************************************************
110 * An input item's meta has changed (Event Callback)
111 *****************************************************************************/
112 static void input_item_meta_changed( const vlc_event_t * p_event,
115 playlist_item_t * p_item = user_data;
116 var_SetInteger( p_item->p_playlist,
117 "item-change", p_item->i_id );
120 /*****************************************************************************
121 * Listen to vlc_InputItemAddSubItem event
122 *****************************************************************************/
123 static void install_input_item_observer( playlist_item_t * p_item )
125 vlc_event_attach( &p_item->p_input->event_manager,
126 vlc_InputItemSubItemAdded,
127 input_item_subitem_added,
129 vlc_event_attach( &p_item->p_input->event_manager,
130 vlc_InputItemMetaChanged,
131 input_item_meta_changed,
135 static void uninstall_input_item_observer( playlist_item_t * p_item )
137 vlc_event_detach( &p_item->p_input->event_manager,
138 vlc_InputItemMetaChanged,
139 input_item_meta_changed,
141 vlc_event_detach( &p_item->p_input->event_manager,
142 vlc_InputItemSubItemAdded,
143 input_item_subitem_added,
147 /*****************************************************************************
148 * Playlist item creation
149 *****************************************************************************/
150 playlist_item_t * playlist_ItemNewWithType( vlc_object_t *p_obj,
152 const char *psz_name,
154 const char *const *ppsz_options,
155 int i_duration, int i_type )
157 input_item_t *p_input;
158 if( psz_uri == NULL ) return NULL;
159 p_input = input_ItemNewWithType( p_obj, psz_uri,
160 psz_name, i_options, ppsz_options,
161 i_duration, i_type );
162 return playlist_ItemNewFromInput( p_obj, p_input );
165 playlist_item_t *__playlist_ItemNewFromInput( vlc_object_t *p_obj,
166 input_item_t *p_input )
168 DECMALLOC_NULL( p_item, playlist_item_t );
169 playlist_t *p_playlist = pl_Yield( p_obj );
171 p_item->p_input = p_input;
172 vlc_gc_incref( p_item->p_input );
174 p_item->i_id = ++p_playlist->i_last_playlist_id;
176 p_item->p_parent = NULL;
177 p_item->i_children = -1;
178 p_item->pp_children = NULL;
180 p_item->p_playlist = p_playlist;
182 install_input_item_observer( p_item );
184 pl_Release( p_item->p_playlist );
189 /***************************************************************************
190 * Playlist item destruction
191 ***************************************************************************/
196 * Delete a playlist item and detach its input item
197 * \param p_item item to delete
198 * \return VLC_SUCCESS
200 int playlist_ItemDelete( playlist_item_t *p_item )
202 uninstall_input_item_observer( p_item );
204 vlc_gc_decref( p_item->p_input );
212 * Remove an input item when it appears from a root playlist item
213 * \param p_playlist playlist object
214 * \param i_input_id id of the input to delete
215 * \param p_root root playlist item
216 * \param b_do_stop must stop or not the playlist
217 * \return VLC_SUCCESS or VLC_EGENERIC
219 static int DeleteFromInput( playlist_t *p_playlist, int i_input_id,
220 playlist_item_t *p_root, bool b_do_stop )
223 for( i = 0 ; i< p_root->i_children ; i++ )
225 if( p_root->pp_children[i]->i_children == -1 &&
226 p_root->pp_children[i]->p_input->i_id == i_input_id )
228 DeleteInner( p_playlist, p_root->pp_children[i], b_do_stop );
231 else if( p_root->pp_children[i]->i_children >= 0 )
233 int i_ret = DeleteFromInput( p_playlist, i_input_id,
234 p_root->pp_children[i], b_do_stop );
235 if( i_ret == VLC_SUCCESS ) return VLC_SUCCESS;
244 * Remove an input item when it appears from a root playlist item
245 * \param p_playlist playlist object
246 * \param i_input_id id of the input to delete
247 * \param p_root root playlist item
248 * \param b_locked TRUE if the playlist is locked
249 * \return VLC_SUCCESS or VLC_EGENERIC
251 int playlist_DeleteInputInParent( playlist_t *p_playlist, int i_input_id,
252 playlist_item_t *p_root, bool b_locked )
255 if( !b_locked ) PL_LOCK;
256 i_ret = DeleteFromInput( p_playlist, i_input_id,
258 if( !b_locked ) PL_UNLOCK;
265 * Remove an input item from ONELEVEL and CATEGORY
266 * \param p_playlist playlist object
267 * \param i_input_id id of the input to delete
268 * \param b_locked TRUE if the playlist is locked
269 * \return VLC_SUCCESS or VLC_ENOITEM
271 int playlist_DeleteFromInput( playlist_t *p_playlist, int i_input_id,
275 if( !b_locked ) PL_LOCK;
276 i_ret1 = DeleteFromInput( p_playlist, i_input_id,
277 p_playlist->p_root_category, true );
278 i_ret2 = DeleteFromInput( p_playlist, i_input_id,
279 p_playlist->p_root_onelevel, true );
280 if( !b_locked ) PL_UNLOCK;
281 return ( i_ret1 == VLC_SUCCESS || i_ret2 == VLC_SUCCESS ) ?
282 VLC_SUCCESS : VLC_ENOITEM;
288 * \param p_playlist playlist object
289 * \param b_locked TRUE if the playlist is locked
292 void playlist_Clear( playlist_t * p_playlist, bool b_locked )
294 if( !b_locked ) PL_LOCK;
295 playlist_NodeEmpty( p_playlist, p_playlist->p_local_category, true );
296 playlist_NodeEmpty( p_playlist, p_playlist->p_local_onelevel, true );
297 if( !b_locked ) PL_UNLOCK;
301 * Delete playlist item
303 * Remove a playlist item from the playlist, given its id
304 * This function is to be used only by the playlist
305 * \param p_playlist playlist object
306 * \param i_id id of the item do delete
307 * \return VLC_SUCCESS or an error
309 int playlist_DeleteFromItemId( playlist_t *p_playlist, int i_id )
311 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id,
313 if( !p_item ) return VLC_EGENERIC;
314 return DeleteInner( p_playlist, p_item, true );
317 /***************************************************************************
318 * Playlist item addition
319 ***************************************************************************/
323 * Add an item to the playlist or the media library
324 * \param p_playlist the playlist to add into
325 * \param psz_uri the mrl to add to the playlist
326 * \param psz_name a text giving a name or description of this item
327 * \param i_mode the mode used when adding
328 * \param i_pos the position in the playlist where to add. If this is
329 * PLAYLIST_END the item will be added at the end of the playlist
330 * regardless of its size
331 * \param b_playlist TRUE for playlist, FALSE for media library
332 * \param b_locked TRUE if the playlist is locked
333 * \return The id of the playlist item
335 int playlist_Add( playlist_t *p_playlist, const char *psz_uri,
336 const char *psz_name, int i_mode, int i_pos,
337 bool b_playlist, bool b_locked )
339 return playlist_AddExt( p_playlist, psz_uri, psz_name,
340 i_mode, i_pos, -1, NULL, 0, b_playlist, b_locked );
344 * Add a MRL into the playlist or the media library, duration and options given
346 * \param p_playlist the playlist to add into
347 * \param psz_uri the mrl to add to the playlist
348 * \param psz_name a text giving a name or description of this item
349 * \param i_mode the mode used when adding
350 * \param i_pos the position in the playlist where to add. If this is
351 * PLAYLIST_END the item will be added at the end of the playlist
352 * regardless of its size
353 * \param i_duration length of the item in milliseconds.
354 * \param ppsz_options an array of options
355 * \param i_options the number of options
356 * \param b_playlist TRUE for playlist, FALSE for media library
357 * \param b_locked TRUE if the playlist is locked
358 * \return The id of the playlist item
360 int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
361 const char *psz_name, int i_mode, int i_pos,
362 mtime_t i_duration, const char *const *ppsz_options,
363 int i_options, bool b_playlist, bool b_locked )
366 input_item_t *p_input = input_ItemNewExt( p_playlist, psz_uri, psz_name,
367 i_options, ppsz_options,
370 i_ret = playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist,
372 int i_id = i_ret == VLC_SUCCESS ? p_input->i_id : -1;
374 vlc_gc_decref( p_input );
380 * Add an input item to the playlist node
382 * \param p_playlist the playlist to add into
383 * \param p_input the input item to add
384 * \param i_mode the mode used when adding
385 * \param i_pos the position in the playlist where to add. If this is
386 * PLAYLIST_END the item will be added at the end of the playlist
387 * regardless of its size
388 * \param b_playlist TRUE for playlist, FALSE for media library
389 * \param b_locked TRUE if the playlist is locked
390 * \return VLC_SUCCESS or VLC_ENOMEM or VLC_EGENERIC
392 int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
393 int i_mode, int i_pos, bool b_playlist,
396 playlist_item_t *p_item_cat, *p_item_one;
397 if( p_playlist->b_die ) return VLC_EGENERIC;
398 if( !p_playlist->b_doing_ml )
399 PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name,
402 if( !b_locked ) PL_LOCK;
404 /* Add to ONELEVEL */
405 p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
406 if( p_item_one == NULL ) return VLC_ENOMEM;
407 AddItem( p_playlist, p_item_one,
408 b_playlist ? p_playlist->p_local_onelevel :
409 p_playlist->p_ml_onelevel , i_mode, i_pos );
411 /* Add to CATEGORY */
412 p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
413 if( p_item_cat == NULL ) return VLC_ENOMEM;
414 AddItem( p_playlist, p_item_cat,
415 b_playlist ? p_playlist->p_local_category :
416 p_playlist->p_ml_category , i_mode, i_pos );
418 GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
420 if( !b_locked ) PL_UNLOCK;
427 * Add an input item to p_direct_parent in the category tree, and to the
428 * matching top category in onelevel
429 * \param p_playlist the playlist to add into
430 * \param p_input the input item to add
431 * \param p_direct_parent the parent item to add into
432 * \param i_mode the mode used when adding
433 * \param i_pos the position in the playlist where to add. If this is
434 * PLAYLIST_END the item will be added at the end of the playlist
435 * regardless of its size
436 * \param i_cat id of the items category
437 * \param i_one id of the item onelevel category
438 * \param b_locked TRUE if the playlist is locked
439 * \return VLC_SUCCESS if success, VLC_EGENERIC if fail, VLC_ENOMEM if OOM
441 int playlist_BothAddInput( playlist_t *p_playlist,
442 input_item_t *p_input,
443 playlist_item_t *p_direct_parent,
444 int i_mode, int i_pos,
445 int *i_cat, int *i_one, bool b_locked )
447 playlist_item_t *p_item_cat, *p_item_one, *p_up;
450 if( p_playlist->b_die ) return VLC_EGENERIC;
451 if( !b_locked ) PL_LOCK;
453 /* Add to category */
454 p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
455 if( p_item_cat == NULL ) return VLC_ENOMEM;
456 AddItem( p_playlist, p_item_cat, p_direct_parent, i_mode, i_pos );
458 /* Add to onelevel */
459 /**Â \todo make a faster case for ml import */
460 p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
461 if( p_item_one == NULL ) return VLC_ENOMEM;
463 p_up = p_direct_parent;
464 while( p_up->p_parent != p_playlist->p_root_category )
466 p_up = p_up->p_parent;
468 for( i_top = 0 ; i_top < p_playlist->p_root_onelevel->i_children; i_top++ )
470 if( p_playlist->p_root_onelevel->pp_children[i_top]->p_input->i_id ==
471 p_up->p_input->i_id )
473 AddItem( p_playlist, p_item_one,
474 p_playlist->p_root_onelevel->pp_children[i_top],
479 GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
481 if( i_cat ) *i_cat = p_item_cat->i_id;
482 if( i_one ) *i_one = p_item_one->i_id;
484 if( !b_locked ) PL_UNLOCK;
489 * Add an input item to a given node
491 * \param p_playlist the playlist to add into
492 * \param p_input the input item to add
493 * \param p_parent the parent item to add into
494 * \param i_mode the mode used when addin
495 * \param i_pos the position in the playlist where to add. If this is
496 * PLAYLIST_END the item will be added at the end of the playlist
497 * regardless of its size
498 * \param b_locked TRUE if the playlist is locked
499 * \return the new playlist item
501 playlist_item_t * playlist_NodeAddInput( playlist_t *p_playlist,
502 input_item_t *p_input,
503 playlist_item_t *p_parent,
504 int i_mode, int i_pos,
507 playlist_item_t *p_item;
509 assert( p_parent && p_parent->i_children != -1 );
511 if( p_playlist->b_die )
513 if( !b_locked ) PL_LOCK;
515 p_item = playlist_ItemNewFromInput( p_playlist, p_input );
516 if( p_item == NULL ) return NULL;
517 AddItem( p_playlist, p_item, p_parent, i_mode, i_pos );
519 if( !b_locked ) PL_UNLOCK;
524 /*****************************************************************************
525 * Playlist item misc operations
526 *****************************************************************************/
531 * Transform an item to a node. Return the node in the category tree, or NULL
533 * This function must be entered without the playlist lock
534 * \param p_playlist the playlist object
535 * \param p_item the item to transform
536 * \param b_locked TRUE if the playlist is locked
537 * \return the item transform in a node
539 playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
540 playlist_item_t *p_item,
544 playlist_item_t *p_item_in_category;
546 * Find the input in CATEGORY.
548 * - change it to node
549 * - we'll return it at the end
550 * - If we are a direct child of onelevel root, change to node, else
551 * delete the input from ONELEVEL
552 * - If we don't find it, just change to node (we are probably in VLM)
555 * If we were in ONELEVEL, we thus retrieve the node in CATEGORY (will be
556 * useful for later BothAddInput )
559 if( !b_locked ) PL_LOCK;
561 /* Fast track the media library, no time to loose */
562 if( p_item == p_playlist->p_ml_category ) {
563 if( !b_locked ) PL_UNLOCK;
567 /** \todo First look if we don't already have it */
568 p_item_in_category = playlist_ItemFindFromInputAndRoot(
569 p_playlist, p_item->p_input->i_id,
570 p_playlist->p_root_category,
573 if( p_item_in_category )
575 playlist_item_t *p_item_in_one = playlist_ItemFindFromInputAndRoot(
576 p_playlist, p_item->p_input->i_id,
577 p_playlist->p_root_onelevel,
579 assert( p_item_in_one );
581 /* We already have it, and there is nothing more to do */
582 ChangeToNode( p_playlist, p_item_in_category );
584 /* Item in one is a root, change it to node */
585 if( p_item_in_one->p_parent == p_playlist->p_root_onelevel )
586 ChangeToNode( p_playlist, p_item_in_one );
589 DeleteFromInput( p_playlist, p_item_in_one->p_input->i_id,
590 p_playlist->p_root_onelevel, false );
592 p_playlist->b_reset_currently_playing = true;
593 vlc_cond_signal( &p_playlist->object_wait );
594 var_SetInteger( p_playlist, "item-change", p_item_in_category->
596 if( !b_locked ) PL_UNLOCK;
597 return p_item_in_category;
601 ChangeToNode( p_playlist, p_item );
602 if( !b_locked ) PL_UNLOCK;
608 * Find an item within a root, given its input id.
610 * \param p_playlist the playlist object
611 * \param i_input_id id of the input
612 * \param p_root root playlist item
613 * \param b_items_only TRUE if we want the item himself
614 * \return the first found item, or NULL if not found
616 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
618 playlist_item_t *p_root,
622 for( i = 0 ; i< p_root->i_children ; i++ )
624 if( ( b_items_only ? p_root->pp_children[i]->i_children == -1 : 1 ) &&
625 p_root->pp_children[i]->p_input->i_id == i_input_id )
627 return p_root->pp_children[i];
629 else if( p_root->pp_children[i]->i_children >= 0 )
631 playlist_item_t *p_search =
632 playlist_ItemFindFromInputAndRoot( p_playlist, i_input_id,
633 p_root->pp_children[i],
635 if( p_search ) return p_search;
642 static int TreeMove( playlist_t *p_playlist, playlist_item_t *p_item,
643 playlist_item_t *p_node, int i_newpos )
646 playlist_item_t *p_detach = p_item->p_parent;
649 if( p_node->i_children == -1 ) return VLC_EGENERIC;
651 for( j = 0; j < p_detach->i_children; j++ )
653 if( p_detach->pp_children[j] == p_item ) break;
655 REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, j );
657 /* Attach to new parent */
658 INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
659 p_item->p_parent = p_node;
667 * This function must be entered with the playlist lock
669 * \param p_playlist the playlist
670 * \param p_item the item to move
671 * \param p_node the new parent of the item
672 * \param i_newpos the new position under this new parent
673 * \return VLC_SUCCESS or an error
675 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
676 playlist_item_t *p_node, int i_newpos )
679 /* Drop on a top level node. Move in the two trees */
680 if( p_node->p_parent == p_playlist->p_root_category ||
681 p_node->p_parent == p_playlist->p_root_onelevel )
683 /* Fixme: avoid useless lookups but we need some clean helpers */
685 /* Fixme: if we try to move a node on a top-level node, it will
686 * fail because the node doesn't exist in onelevel and we will
687 * do some shit in onelevel. We should recursively move all items
689 playlist_item_t *p_node_onelevel;
690 playlist_item_t *p_item_onelevel;
691 p_node_onelevel = playlist_ItemFindFromInputAndRoot( p_playlist,
692 p_node->p_input->i_id,
693 p_playlist->p_root_onelevel,
695 p_item_onelevel = playlist_ItemFindFromInputAndRoot( p_playlist,
696 p_item->p_input->i_id,
697 p_playlist->p_root_onelevel,
699 if( p_node_onelevel && p_item_onelevel )
700 TreeMove( p_playlist, p_item_onelevel, p_node_onelevel, 0 );
703 playlist_item_t *p_node_category;
704 playlist_item_t *p_item_category;
705 p_node_category = playlist_ItemFindFromInputAndRoot( p_playlist,
706 p_node->p_input->i_id,
707 p_playlist->p_root_category,
709 p_item_category = playlist_ItemFindFromInputAndRoot( p_playlist,
710 p_item->p_input->i_id,
711 p_playlist->p_root_category,
713 if( p_node_category && p_item_category )
714 TreeMove( p_playlist, p_item_category, p_node_category, 0 );
719 i_ret = TreeMove( p_playlist, p_item, p_node, i_newpos );
720 p_playlist->b_reset_currently_playing = true;
721 vlc_cond_signal( &p_playlist->object_wait );
726 * Send a notification that an item has been added to a node
728 * \param p_playlist the playlist object
729 * \param i_item_id id of the item added
730 * \param i_node_id id of the node in wich the item was added
731 * \param b_signal TRUE if the function must send a signal
734 void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
735 int i_node_id, bool b_signal )
738 playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t) );
742 p_add->i_item = i_item_id;
743 p_add->i_node = i_node_id;
744 val.p_address = p_add;
745 p_playlist->b_reset_currently_playing = true;
747 vlc_cond_signal( &p_playlist->object_wait );
748 var_Set( p_playlist, "item-append", val );
752 /*****************************************************************************
753 * Playlist item accessors
754 *****************************************************************************/
757 * Set the name of a playlist item
759 * \param p_item the item
760 * \param psz_name the name
761 * \return VLC_SUCCESS or VLC_EGENERIC
763 int playlist_ItemSetName( playlist_item_t *p_item, const char *psz_name )
765 if( psz_name && p_item )
767 input_item_SetName( p_item->p_input, psz_name );
773 /***************************************************************************
774 * The following functions are local
775 ***************************************************************************/
777 /* Enqueue an item for preparsing, and play it, if needed */
778 static void GoAndPreparse( playlist_t *p_playlist, int i_mode,
779 playlist_item_t *p_item_cat,
780 playlist_item_t *p_item_one )
782 if( (i_mode & PLAYLIST_GO ) )
784 playlist_item_t *p_parent = p_item_one;
785 playlist_item_t *p_toplay = NULL;
788 if( p_parent == p_playlist->p_root_category )
790 p_toplay = p_item_cat; break;
792 else if( p_parent == p_playlist->p_root_onelevel )
794 p_toplay = p_item_one; break;
796 p_parent = p_parent->p_parent;
799 p_playlist->request.b_request = true;
800 p_playlist->request.i_skip = 0;
801 p_playlist->request.p_item = p_toplay;
802 if( p_playlist->p_input )
803 input_StopThread( p_playlist->p_input );
804 p_playlist->request.i_status = PLAYLIST_RUNNING;
805 vlc_cond_signal( &p_playlist->object_wait );
807 /* Preparse if PREPARSE or SPREPARSE & not enough meta */
808 char *psz_artist = input_item_GetArtist( p_item_cat->p_input );
809 char *psz_album = input_item_GetAlbum( p_item_cat->p_input );
810 if( p_playlist->b_auto_preparse &&
811 (i_mode & PLAYLIST_PREPARSE ||
812 ( i_mode & PLAYLIST_SPREPARSE &&
813 ( EMPTY_STR( psz_artist ) || ( EMPTY_STR( psz_album ) ) )
815 playlist_PreparseEnqueue( p_playlist, p_item_cat->p_input );
816 /* If we already have it, signal it */
817 else if( !EMPTY_STR( psz_artist ) && !EMPTY_STR( psz_album ) )
818 input_item_SetPreparsed( p_item_cat->p_input, true );
823 /* Add the playlist item to the requested node and fire a notification */
824 static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
825 playlist_item_t *p_node, int i_mode, int i_pos )
827 ARRAY_APPEND(p_playlist->items, p_item);
828 ARRAY_APPEND(p_playlist->all_items, p_item);
830 if( i_pos == PLAYLIST_END )
831 playlist_NodeAppend( p_playlist, p_item, p_node );
833 playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
835 if( !p_playlist->b_doing_ml )
836 playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id,
837 !( i_mode & PLAYLIST_NO_REBUILD ) );
840 /* Actually convert an item to a node */
841 static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item )
844 if( p_item->i_children == -1 )
845 p_item->i_children = 0;
847 /* Remove it from the array of available items */
848 ARRAY_BSEARCH( p_playlist->items,->i_id, int, p_item->i_id, i );
850 ARRAY_REMOVE( p_playlist->items, i );
853 /* Do the actual removal */
854 static int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
858 int i_id = p_item->i_id;
859 bool b_delay_deletion = false;
861 if( p_item->i_children > -1 )
863 return playlist_NodeDelete( p_playlist, p_item, true, false );
865 p_playlist->b_reset_currently_playing = true;
866 var_SetInteger( p_playlist, "item-deleted", i_id );
868 /* Remove the item from the bank */
869 ARRAY_BSEARCH( p_playlist->all_items,->i_id, int, i_id, i );
871 ARRAY_REMOVE( p_playlist->all_items, i );
873 ARRAY_BSEARCH( p_playlist->items,->i_id, int, i_id, i );
875 ARRAY_REMOVE( p_playlist->items, i );
877 /* Check if it is the current item */
878 if( p_playlist->status.p_item == p_item )
880 /* Hack we don't call playlist_Control for lock reasons */
883 p_playlist->request.i_status = PLAYLIST_STOPPED;
884 p_playlist->request.b_request = true;
885 p_playlist->request.p_item = NULL;
886 msg_Info( p_playlist, "stopping playback" );
887 vlc_cond_signal( &p_playlist->object_wait );
889 b_delay_deletion = true;
892 PL_DEBUG( "deleting item `%s'", p_item->p_input->psz_name );
894 /* Remove the item from its parent */
895 playlist_NodeRemoveItem( p_playlist, p_item, p_item->p_parent );
897 if( !b_delay_deletion )
898 playlist_ItemDelete( p_item );
901 PL_DEBUG( "marking %s for further deletion", PLI_NAME( p_item ) );
902 p_item->i_flags |= PLAYLIST_REMOVE_FLAG;