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 vlc_object_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, true );
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 vlc_object_unlock( getIntf()->p_sys->p_playlist );
99 void Playtree::action( VarTree *pItem )
101 vlc_object_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 vlc_object_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 = m_pPlaylist->status.p_item == 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_item_t *p_item = playlist_ItemGetById(
178 m_pPlaylist, p_add->i_item, false );
179 if( !p_item ) return;
180 UString *pName = new UString( getIntf(),
181 p_item->p_input->psz_name );
182 node->add( p_add->i_item, UStringPtr( pName ),
183 false,false, false, p_item->i_flags & PLAYLIST_RO_FLAG,
188 descr.i_id = p_add->i_item;
189 descr.i_parent = p_add->i_node;
190 descr.b_visible = node->m_expanded;
195 void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree )
197 for( int i = 0; i < pNode->i_children; i++ )
199 UString *pName = new UString( getIntf(),
200 pNode->pp_children[i]->p_input->psz_name );
201 rTree.add( pNode->pp_children[i]->p_input->i_id, UStringPtr( pName ),
203 m_pPlaylist->status.p_item == pNode->pp_children[i],
204 false, pNode->pp_children[i]->i_flags & PLAYLIST_RO_FLAG,
205 pNode->pp_children[i] );
206 if( pNode->pp_children[i]->i_children )
208 buildNode( pNode->pp_children[i], rTree.back() );
213 void Playtree::buildTree()
216 vlc_object_lock( m_pPlaylist );
218 i_items_to_append = 0;
222 /* TODO: Let user choose view - Stick with category ATM */
224 /* Set the root's name */
225 UString *pName = new UString( getIntf(),
226 m_pPlaylist->p_root_category->p_input->psz_name );
227 m_cString = UStringPtr( pName );
229 buildNode( m_pPlaylist->p_root_category, *this );
231 vlc_object_unlock( m_pPlaylist );
233 // checkParents( NULL );