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 = getNextItem( it ) )
56 if( it->m_selected && !it->isReadonly() )
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 );
76 it2 = getNextItem( it ) ;
80 playlist_NodeDelete( getIntf()->p_sys->p_playlist, p_item,
82 it2 = it->getNextSiblingOrUncle();
84 it->parent()->removeChild( it );
89 it = getNextItem( it );
92 playlist_Unlock( getIntf()->p_sys->p_playlist );
95 void Playtree::action( VarTree *pItem )
97 playlist_Lock( m_pPlaylist );
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, pl_Locked, p_parent, p_item );
113 playlist_Unlock( m_pPlaylist );
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 );
138 msg_Warn(getIntf(), "cannot find node with id %d", id );
145 void Playtree::onUpdateCurrent( bool b_active )
152 Iterator it = findById( m_currentItem->i_id );
154 it->m_playing = false;
155 m_currentItem = NULL;
159 playlist_Lock( m_pPlaylist );
161 playlist_item_t* current = playlist_CurrentPlayingItem( m_pPlaylist );
164 playlist_Unlock( m_pPlaylist );
168 Iterator it = findById( current->i_id );
170 it->m_playing = true;
171 m_currentItem = current;
173 playlist_Unlock( m_pPlaylist );
177 descr.b_active_item = true;
183 /// \todo keep a list of "recently removed" to avoid looking up if we
184 // already removed it
185 void Playtree::onDelete( int i_id )
187 Iterator item = findById( i_id ) ;
190 VarTree* parent = item->parent();
192 item->m_deleted = true;
197 descr.b_visible = parent ? parent->m_expanded : true;
201 parent->removeChild( item );
206 void Playtree::onAppend( playlist_add_t *p_add )
208 i_items_to_append --;
210 Iterator node = findById( p_add->i_node );
213 Iterator item = findById( p_add->i_item );
216 playlist_Lock( m_pPlaylist );
217 playlist_item_t *p_item = playlist_ItemGetById(
218 m_pPlaylist, p_add->i_item );
221 playlist_Unlock( m_pPlaylist );
224 UString *pName = new UString( getIntf(),
225 p_item->p_input->psz_name );
226 node->add( p_add->i_item, UStringPtr( pName ),
227 false,false, false, p_item->i_flags & PLAYLIST_RO_FLAG,
229 playlist_Unlock( m_pPlaylist );
233 descr.i_id = p_add->i_item;
234 descr.i_parent = p_add->i_node;
235 descr.b_visible = node->m_expanded;
240 void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree )
242 for( int i = 0; i < pNode->i_children; i++ )
244 UString *pName = new UString( getIntf(),
245 pNode->pp_children[i]->p_input->psz_name );
246 rTree.add( pNode->pp_children[i]->i_id, UStringPtr( pName ),
248 playlist_CurrentPlayingItem(m_pPlaylist) == pNode->pp_children[i],
249 false, pNode->pp_children[i]->i_flags & PLAYLIST_RO_FLAG,
250 pNode->pp_children[i] );
251 if( pNode->pp_children[i]->i_children )
253 buildNode( pNode->pp_children[i], rTree.back() );
258 void Playtree::buildTree()
261 playlist_Lock( m_pPlaylist );
263 i_items_to_append = 0;
267 /* TODO: Let user choose view - Stick with category ATM */
269 /* Set the root's name */
270 UString *pName = new UString( getIntf(),
271 m_pPlaylist->p_root_category->p_input->psz_name );
272 m_cString = UStringPtr( pName );
274 buildNode( m_pPlaylist->p_root_category, *this );
276 playlist_Unlock( m_pPlaylist );