1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea@videolan.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 *****************************************************************************/
27 #include "playtree.hpp"
28 #include <vlc_playlist.h>
29 #include "../utils/ustring.hpp"
31 #include "vlc_charset.h"
34 Playtree::Playtree( intf_thread_t *pIntf ): VarTree( pIntf )
36 // Get the VLC playlist object
37 m_pPlaylist = pIntf->p_sys->p_playlist;
39 i_items_to_append = 0;
48 void Playtree::delSelected()
50 Iterator it = begin();
51 vlc_mutex_lock( &getIntf()->p_sys->p_playlist->object_lock );
52 for( it = begin(); it != end(); it = getNextVisibleItem( it ) )
54 if( (*it).m_selected && !(*it).isReadonly() )
56 (*it).m_deleted = true;
59 /// \todo Do this better (handle item-deleted)
68 VarTree::Iterator it2;
69 playlist_item_t *p_item = (playlist_item_t *)(it->m_pData);
70 if( p_item->i_children == -1 )
72 playlist_DeleteFromInput( getIntf()->p_sys->p_playlist,
73 p_item->p_input->i_id, VLC_TRUE );
74 it2 = getNextVisibleItem( it ) ;
75 it->parent()->removeChild( it );
80 playlist_NodeDelete( getIntf()->p_sys->p_playlist, p_item,
81 VLC_TRUE, VLC_FALSE );
82 it2 = getNextSibling( it );
83 it->parent()->removeChild( it );
89 it = getNextVisibleItem( it );
92 vlc_mutex_unlock( &getIntf()->p_sys->p_playlist->object_lock );
95 void Playtree::action( VarTree *pItem )
97 vlc_mutex_lock( &m_pPlaylist->object_lock );
100 playlist_item_t *p_item = (playlist_item_t *)pItem->m_pData;
101 playlist_item_t *p_parent = p_item;
104 if( p_parent == m_pPlaylist->p_root_category )
106 p_parent = p_parent->p_parent;
111 playlist_Control( m_pPlaylist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_parent, p_item );
113 vlc_mutex_unlock( &m_pPlaylist->object_lock );
116 void Playtree::onChange()
124 void Playtree::onUpdateItem( int id )
126 Iterator it = findById( id );
128 descr.b_active_item = false;
132 playlist_item_t* pNode = (playlist_item_t*)(it->m_pData);
133 UString *pName = new UString( getIntf(), pNode->p_input->psz_name );
134 it->m_cString = UStringPtr( pName );
135 it->m_playing = m_pPlaylist->status.p_item == pNode;
136 if( it->m_playing ) descr.b_active_item = true;
140 msg_Warn(getIntf(), "cannot find node with id %d", id );
146 /// \todo keep a list of "recently removed" to avoid looking up if we
147 // already removed it
148 void Playtree::onDelete( int i_id )
153 Iterator item = findById( i_id ) ;
157 item->parent()->removeChild( item );
158 descr.b_visible = item->parent() ? true : item->parent()->m_expanded;
163 void Playtree::onAppend( playlist_add_t *p_add )
165 i_items_to_append --;
167 Iterator node = findById( p_add->i_node );
170 Iterator item = findById( p_add->i_item );
173 playlist_item_t *p_item = playlist_ItemGetById(
174 m_pPlaylist, p_add->i_item, VLC_TRUE );
175 if( !p_item ) return;
176 UString *pName = new UString( getIntf(),
177 p_item->p_input->psz_name );
178 node->add( p_add->i_item, UStringPtr( pName ),
179 false,false, false, p_item->i_flags & PLAYLIST_RO_FLAG,
184 descr.i_id = p_add->i_item;
185 descr.i_parent = p_add->i_node;
186 descr.b_visible = node->m_expanded;
191 void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree )
193 for( int i = 0; i < pNode->i_children; i++ )
195 UString *pName = new UString( getIntf(),
196 pNode->pp_children[i]->p_input->psz_name );
197 rTree.add( pNode->pp_children[i]->p_input->i_id, UStringPtr( pName ),
199 m_pPlaylist->status.p_item == pNode->pp_children[i],
200 false, pNode->pp_children[i]->i_flags & PLAYLIST_RO_FLAG,
201 pNode->pp_children[i] );
202 if( pNode->pp_children[i]->i_children )
204 buildNode( pNode->pp_children[i], rTree.back() );
209 void Playtree::buildTree()
212 vlc_mutex_lock( &m_pPlaylist->object_lock );
214 i_items_to_append = 0;
218 /* TODO: Let user choose view - Stick with category ATM */
220 /* Set the root's name */
221 UString *pName = new UString( getIntf(),
222 m_pPlaylist->p_root_category->p_input->psz_name );
223 m_cString = UStringPtr( pName );
225 buildNode( m_pPlaylist->p_root_category, *this );
227 vlc_mutex_unlock( &m_pPlaylist->object_lock );
229 // checkParents( NULL );