]> git.sesse.net Git - vlc/blobdiff - src/playlist/item.c
Revert "sd: Export internals with a getters."
[vlc] / src / playlist / item.c
index 6d971f246ece4919291da55381d7f27ef4c1668c..9b8a469037fa7833b475124e6dc4096d3d596e40 100644 (file)
@@ -36,8 +36,6 @@ static void GoAndPreparse( playlist_t *p_playlist, int i_mode,
                            playlist_item_t * );
 static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item );
 
-static playlist_item_t *ItemToNode( playlist_t *, playlist_item_t *, bool );
-
 static int RecursiveAddIntoParent (
                 playlist_t *p_playlist, playlist_item_t *p_parent,
                 input_item_node_t *p_node, int i_pos, bool b_flat,
@@ -63,9 +61,9 @@ static void input_item_add_subitem_tree ( const vlc_event_t * p_event,
     playlist_item_t *p_parent = p_item->p_parent;
     assert( p_parent != NULL );
 
-    bool b_play = var_CreateGetBool( p_playlist, "playlist-autostart" ) &&
-                  get_current_status_item( p_playlist ) == p_item;
-    bool b_stop = b_play && p_item->i_flags & PLAYLIST_SUBITEM_STOP_FLAG;
+    bool b_current = get_current_status_item( p_playlist ) == p_item;
+    bool b_autostart = var_CreateGetBool( p_playlist, "playlist-autostart" );
+    bool b_stop = p_item->i_flags & PLAYLIST_SUBITEM_STOP_FLAG;
     p_item->i_flags &= ~PLAYLIST_SUBITEM_STOP_FLAG;
 
     int pos = 0;
@@ -82,8 +80,7 @@ static void input_item_add_subitem_tree ( const vlc_event_t * p_event,
     playlist_item_t *p_up = p_item;
     while( p_up->p_parent )
     {
-        if( p_up->p_parent == p_playlist->p_playing ||
-            p_up->p_parent == p_playlist->p_media_library )
+        if( p_up->p_parent == p_playlist->p_playing )
         {
             if( !pl_priv(p_playlist)->b_tree ) b_flat = true;
             break;
@@ -98,20 +95,23 @@ static void input_item_add_subitem_tree ( const vlc_event_t * p_event,
     }
     else
         p_item = playlist_InsertInputItemTree( p_playlist, p_item,
-                                               p_new_root, 0, false );
+                                               p_new_root, PLAYLIST_END, false );
 
     if( !b_flat ) var_SetAddress( p_playlist, "leaf-to-parent", p_input );
 
-    if( b_stop && !b_flat )
-    {
-        PL_UNLOCK;
-        playlist_Stop( p_playlist );
-        return;
-    }
-    else if( b_play )
+    if( b_current )
     {
-        playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
-                          pl_Locked, get_current_status_node( p_playlist ), p_item );
+        if( ( b_stop && !b_flat ) || !b_autostart )
+        {
+            PL_UNLOCK;
+            playlist_Stop( p_playlist );
+            return;
+        }
+        else
+        {
+            playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
+                pl_Locked, get_current_status_node( p_playlist ), p_item );
+        }
     }
 
     PL_UNLOCK;
@@ -478,80 +478,6 @@ playlist_item_t *playlist_InsertInputItemTree (
  * Playlist item misc operations
  *****************************************************************************/
 
-/**
- * Item to node
- *
- * Transform an item to a node. Return the node in the category tree, or NULL
- * if not found there
- * This function must be entered without the playlist lock
- * \param p_playlist the playlist object
- * \param p_item the item to transform
- * \param b_locked TRUE if the playlist is locked
- * \return the item transform in a node
- */
-static playlist_item_t *ItemToNode( playlist_t *p_playlist,
-                                    playlist_item_t *p_item,
-                                    bool b_locked )
-{
-    PL_LOCK_IF( !b_locked );
-
-    assert( p_item->p_parent );
-
-    bool b_flat = false;
-    playlist_item_t *p_up = p_item;
-    while( p_up->p_parent )
-    {
-        if( p_up->p_parent == p_playlist->p_playing ||
-            p_up->p_parent == p_playlist->p_media_library )
-        {
-            if( !pl_priv(p_playlist)->b_tree ) b_flat = true;
-            break;
-        }
-        p_up = p_up->p_parent;
-    }
-
-    if( !b_flat )
-    {
-        ChangeToNode( p_playlist, p_item );
-        if( p_up == p_playlist->p_root )
-            var_SetAddress( p_playlist, "item-change", p_item->p_input );
-        PL_UNLOCK_IF( !b_locked );
-        return p_item;
-    }
-    else
-    {
-        playlist_item_t *p_status_item = get_current_status_item( p_playlist );
-        playlist_item_t *p_status_node = get_current_status_node( p_playlist );
-        if( p_item == p_status_item )
-        {
-            /* We're deleting the current playlist item. Update
-              * the playlist object to point at the previous item
-              * so the playlist won't be restarted */
-            playlist_item_t *p_prev_status_item = NULL;
-            int i = 0;
-            while( i < p_status_node->i_children &&
-                    p_status_node->pp_children[i] != p_status_item )
-            {
-                p_prev_status_item = p_status_node->pp_children[i];
-                i++;
-            }
-            if( i == p_status_node->i_children )
-                p_prev_status_item = NULL;
-            if( p_prev_status_item )
-                set_current_status_item( p_playlist, p_prev_status_item );
-        }
-
-        DeleteFromInput( p_playlist, p_item->p_input,
-                          p_playlist->p_root, false );
-
-        pl_priv(p_playlist)->b_reset_currently_playing = true;
-        vlc_cond_signal( &pl_priv(p_playlist)->signal );
-
-        PL_UNLOCK_IF( !b_locked );
-        return p_item->p_parent;
-    }
-}
-
 /**
  * Find an item within a root, given its input id.
  *
@@ -753,8 +679,16 @@ static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
 static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item )
 {
     int i;
-    if( p_item->i_children == -1 )
-        p_item->i_children = 0;
+    if( p_item->i_children != -1 ) return;
+
+    p_item->i_children = 0;
+
+    input_item_t *p_input = p_item->p_input;
+    vlc_mutex_lock( &p_input->lock );
+    p_input->i_type = ITEM_TYPE_NODE;
+    vlc_mutex_unlock( &p_input->lock );
+
+    var_SetAddress( p_playlist, "item-change", p_item->p_input );
 
     /* Remove it from the array of available items */
     ARRAY_BSEARCH( p_playlist->items,->i_id, int, p_item->i_id, i );