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 *****************************************************************************/
29 #include <vlc_common.h>
31 #include "playtree.hpp"
32 #include <vlc_playlist.h>
33 #include "../utils/ustring.hpp"
35 Playtree::Playtree( intf_thread_t *pIntf ):
36 VarTree( pIntf ), m_currentItem( NULL )
38 // Get the VLC playlist object
39 m_pPlaylist = pIntf->p_sys->p_playlist;
41 i_items_to_append = 0;
50 void Playtree::delSelected()
52 Iterator it = begin();
53 playlist_Lock( getIntf()->p_sys->p_playlist );
54 for( it = begin(); it != end(); it = getNextVisibleItem( it ) )
56 if( (*it).m_selected && !(*it).isReadonly() )
58 (*it).m_deleted = true;
61 /// \todo Do this better (handle item-deleted)
70 VarTree::Iterator it2;
71 playlist_item_t *p_item = (playlist_item_t *)(it->m_pData);
72 if( p_item->i_children == -1 )
74 playlist_DeleteFromInput( getIntf()->p_sys->p_playlist,
75 p_item->p_input, pl_Locked );
79 playlist_NodeDelete( getIntf()->p_sys->p_playlist, p_item,
82 it2 = getNextVisibleItem( it ) ;
83 it->parent()->removeChild( it );
88 it = getNextVisibleItem( it );
91 playlist_Unlock( getIntf()->p_sys->p_playlist );
94 void Playtree::action( VarTree *pItem )
96 playlist_Lock( m_pPlaylist );
99 playlist_item_t *p_item = (playlist_item_t *)pItem->m_pData;
100 playlist_item_t *p_parent = p_item;
103 if( p_parent == m_pPlaylist->p_root_category )
105 p_parent = p_parent->p_parent;
110 playlist_Control( m_pPlaylist, PLAYLIST_VIEWPLAY, pl_Locked, p_parent, p_item );
112 playlist_Unlock( m_pPlaylist );
115 void Playtree::onChange()
123 void Playtree::onUpdateItem( int id )
125 Iterator it = findById( id );
127 descr.b_active_item = false;
131 playlist_item_t* pNode = (playlist_item_t*)(it->m_pData);
132 UString *pName = new UString( getIntf(), pNode->p_input->psz_name );
133 it->m_cString = UStringPtr( pName );
137 msg_Warn(getIntf(), "cannot find node with id %d", id );
144 void Playtree::onUpdateCurrent( bool b_active )
151 Iterator it = findById( m_currentItem->i_id );
152 it->m_playing = false;
153 m_currentItem = NULL;
157 playlist_Lock( m_pPlaylist );
159 playlist_item_t* current = playlist_CurrentPlayingItem( m_pPlaylist );
162 playlist_Unlock( m_pPlaylist );
166 Iterator it = findById( current->i_id );
167 it->m_playing = true;
168 m_currentItem = current;
170 playlist_Unlock( m_pPlaylist );
174 descr.b_active_item = true;
180 /// \todo keep a list of "recently removed" to avoid looking up if we
181 // already removed it
182 void Playtree::onDelete( int i_id )
187 Iterator item = findById( i_id ) ;
191 item->parent()->removeChild( item );
192 descr.b_visible = item->parent() ? item->parent()->m_expanded : true;
197 void Playtree::onAppend( playlist_add_t *p_add )
199 i_items_to_append --;
201 Iterator node = findById( p_add->i_node );
204 Iterator item = findById( p_add->i_item );
207 playlist_Lock( m_pPlaylist );
208 playlist_item_t *p_item = playlist_ItemGetById(
209 m_pPlaylist, p_add->i_item );
212 playlist_Unlock( m_pPlaylist );
215 UString *pName = new UString( getIntf(),
216 p_item->p_input->psz_name );
217 node->add( p_add->i_item, UStringPtr( pName ),
218 false,false, false, p_item->i_flags & PLAYLIST_RO_FLAG,
220 playlist_Unlock( m_pPlaylist );
224 descr.i_id = p_add->i_item;
225 descr.i_parent = p_add->i_node;
226 descr.b_visible = node->m_expanded;
231 void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree )
233 for( int i = 0; i < pNode->i_children; i++ )
235 UString *pName = new UString( getIntf(),
236 pNode->pp_children[i]->p_input->psz_name );
237 rTree.add( pNode->pp_children[i]->i_id, UStringPtr( pName ),
239 playlist_CurrentPlayingItem(m_pPlaylist) == pNode->pp_children[i],
240 false, pNode->pp_children[i]->i_flags & PLAYLIST_RO_FLAG,
241 pNode->pp_children[i] );
242 if( pNode->pp_children[i]->i_children )
244 buildNode( pNode->pp_children[i], rTree.back() );
249 void Playtree::buildTree()
252 playlist_Lock( m_pPlaylist );
254 i_items_to_append = 0;
258 /* TODO: Let user choose view - Stick with category ATM */
260 /* Set the root's name */
261 UString *pName = new UString( getIntf(),
262 m_pPlaylist->p_root_category->p_input->psz_name );
263 m_cString = UStringPtr( pName );
265 buildNode( m_pPlaylist->p_root_category, *this );
267 playlist_Unlock( m_pPlaylist );
269 // checkParents( NULL );