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 #include "vlc_charset.h"
38 Playtree::Playtree( intf_thread_t *pIntf ): VarTree( pIntf )
40 // Get the VLC playlist object
41 m_pPlaylist = pIntf->p_sys->p_playlist;
43 i_items_to_append = 0;
52 void Playtree::delSelected()
54 Iterator it = begin();
55 playlist_Lock( getIntf()->p_sys->p_playlist );
56 for( it = begin(); it != end(); it = getNextVisibleItem( it ) )
58 if( (*it).m_selected && !(*it).isReadonly() )
60 (*it).m_deleted = true;
63 /// \todo Do this better (handle item-deleted)
72 VarTree::Iterator it2;
73 playlist_item_t *p_item = (playlist_item_t *)(it->m_pData);
74 if( p_item->i_children == -1 )
76 playlist_DeleteFromInput( getIntf()->p_sys->p_playlist,
77 p_item->p_input->i_id, pl_Locked );
78 it2 = getNextVisibleItem( it ) ;
79 it->parent()->removeChild( it );
84 playlist_NodeDelete( getIntf()->p_sys->p_playlist, p_item,
86 it2 = getNextSibling( it );
87 it->parent()->removeChild( it );
93 it = getNextVisibleItem( it );
96 playlist_Unlock( getIntf()->p_sys->p_playlist );
99 void Playtree::action( VarTree *pItem )
101 playlist_Lock( m_pPlaylist );
102 VarTree::Iterator it;
104 playlist_item_t *p_item = (playlist_item_t *)pItem->m_pData;
105 playlist_item_t *p_parent = p_item;
108 if( p_parent == m_pPlaylist->p_root_category )
110 p_parent = p_parent->p_parent;
115 playlist_Control( m_pPlaylist, PLAYLIST_VIEWPLAY, pl_Locked, p_parent, p_item );
117 playlist_Unlock( m_pPlaylist );
120 void Playtree::onChange()
128 void Playtree::onUpdateItem( int id )
130 Iterator it = findById( id );
132 descr.b_active_item = false;
136 playlist_item_t* pNode = (playlist_item_t*)(it->m_pData);
137 UString *pName = new UString( getIntf(), pNode->p_input->psz_name );
138 it->m_cString = UStringPtr( pName );
139 it->m_playing = playlist_CurrentPlayingItem( m_pPlaylist ) == pNode;
140 if( it->m_playing ) descr.b_active_item = true;
144 msg_Warn(getIntf(), "cannot find node with id %d", id );
150 /// \todo keep a list of "recently removed" to avoid looking up if we
151 // already removed it
152 void Playtree::onDelete( int i_id )
157 Iterator item = findById( i_id ) ;
161 item->parent()->removeChild( item );
162 descr.b_visible = item->parent() ? true : item->parent()->m_expanded;
167 void Playtree::onAppend( playlist_add_t *p_add )
169 i_items_to_append --;
171 Iterator node = findById( p_add->i_node );
174 Iterator item = findById( p_add->i_item );
177 playlist_Lock( m_pPlaylist );
178 playlist_item_t *p_item = playlist_ItemGetById(
179 m_pPlaylist, p_add->i_item );
182 playlist_Unlock( m_pPlaylist );
185 UString *pName = new UString( getIntf(),
186 p_item->p_input->psz_name );
187 node->add( p_add->i_item, UStringPtr( pName ),
188 false,false, false, p_item->i_flags & PLAYLIST_RO_FLAG,
190 playlist_Unlock( m_pPlaylist );
194 descr.i_id = p_add->i_item;
195 descr.i_parent = p_add->i_node;
196 descr.b_visible = node->m_expanded;
201 void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree )
203 for( int i = 0; i < pNode->i_children; i++ )
205 UString *pName = new UString( getIntf(),
206 pNode->pp_children[i]->p_input->psz_name );
207 rTree.add( pNode->pp_children[i]->i_id, UStringPtr( pName ),
209 playlist_CurrentPlayingItem(m_pPlaylist) == pNode->pp_children[i],
210 false, pNode->pp_children[i]->i_flags & PLAYLIST_RO_FLAG,
211 pNode->pp_children[i] );
212 if( pNode->pp_children[i]->i_children )
214 buildNode( pNode->pp_children[i], rTree.back() );
219 void Playtree::buildTree()
222 playlist_Lock( m_pPlaylist );
224 i_items_to_append = 0;
228 /* TODO: Let user choose view - Stick with category ATM */
230 /* Set the root's name */
231 UString *pName = new UString( getIntf(),
232 m_pPlaylist->p_root_category->p_input->psz_name );
233 m_cString = UStringPtr( pName );
235 buildNode( m_pPlaylist->p_root_category, *this );
237 playlist_Unlock( m_pPlaylist );
239 // checkParents( NULL );