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 );
153 it->m_playing = false;
154 m_currentItem = NULL;
158 playlist_Lock( m_pPlaylist );
160 playlist_item_t* current = playlist_CurrentPlayingItem( m_pPlaylist );
163 playlist_Unlock( m_pPlaylist );
167 Iterator it = findById( current->i_id );
169 it->m_playing = true;
170 m_currentItem = current;
172 playlist_Unlock( m_pPlaylist );
176 descr.b_active_item = true;
182 /// \todo keep a list of "recently removed" to avoid looking up if we
183 // already removed it
184 void Playtree::onDelete( int i_id )
189 Iterator item = findById( i_id ) ;
192 VarTree* parent = item->parent();
194 parent->removeChild( item );
196 descr.b_visible = parent ? parent->m_expanded : true;
201 void Playtree::onAppend( playlist_add_t *p_add )
203 i_items_to_append --;
205 Iterator node = findById( p_add->i_node );
208 Iterator item = findById( p_add->i_item );
211 playlist_Lock( m_pPlaylist );
212 playlist_item_t *p_item = playlist_ItemGetById(
213 m_pPlaylist, p_add->i_item );
216 playlist_Unlock( m_pPlaylist );
219 UString *pName = new UString( getIntf(),
220 p_item->p_input->psz_name );
221 node->add( p_add->i_item, UStringPtr( pName ),
222 false,false, false, p_item->i_flags & PLAYLIST_RO_FLAG,
224 playlist_Unlock( m_pPlaylist );
228 descr.i_id = p_add->i_item;
229 descr.i_parent = p_add->i_node;
230 descr.b_visible = node->m_expanded;
235 void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree )
237 for( int i = 0; i < pNode->i_children; i++ )
239 UString *pName = new UString( getIntf(),
240 pNode->pp_children[i]->p_input->psz_name );
241 rTree.add( pNode->pp_children[i]->i_id, UStringPtr( pName ),
243 playlist_CurrentPlayingItem(m_pPlaylist) == pNode->pp_children[i],
244 false, pNode->pp_children[i]->i_flags & PLAYLIST_RO_FLAG,
245 pNode->pp_children[i] );
246 if( pNode->pp_children[i]->i_children )
248 buildNode( pNode->pp_children[i], rTree.back() );
253 void Playtree::buildTree()
256 playlist_Lock( m_pPlaylist );
258 i_items_to_append = 0;
262 /* TODO: Let user choose view - Stick with category ATM */
264 /* Set the root's name */
265 UString *pName = new UString( getIntf(),
266 m_pPlaylist->p_root_category->p_input->psz_name );
267 m_cString = UStringPtr( pName );
269 buildNode( m_pPlaylist->p_root_category, *this );
271 playlist_Unlock( m_pPlaylist );
273 // checkParents( NULL );