1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2005 VideoLAN
5 * $Id: playlist.hpp 8659 2004-09-07 21:16:49Z gbazin $
7 * Authors: Antoine Cellerier <dionoea@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
26 #include "playtree.hpp"
27 #include "../utils/ustring.hpp"
32 Playtree::Playtree( intf_thread_t *pIntf )
33 :VarTree( pIntf, /*m_parent = */NULL )
35 // Get the VLC playlist object
36 m_pPlaylist = pIntf->p_sys->p_playlist;
38 // Try to guess the current charset
40 vlc_current_charset( &pCharset );
41 iconvHandle = vlc_iconv_open( "UTF-8", pCharset );
42 msg_Dbg( pIntf, "Using character encoding: %s", pCharset );
45 if( iconvHandle == (vlc_iconv_t) - 1 )
47 msg_Warn( pIntf, "Unable to do requested conversion" );
55 if( iconvHandle != (vlc_iconv_t) - 1 ) vlc_iconv_close( iconvHandle );
56 // TODO : check that everything is destroyed
59 void Playtree::delSelected()
65 void Playtree::action( VarTree *pItem )
67 /* do we really want to call preparse here ? */
68 playlist_PreparseEnqueueItem( m_pPlaylist,
69 (playlist_item_t *)pItem->m_pData );
70 vlc_mutex_lock( &m_pPlaylist->object_lock );
75 while( it->size() ) it = it->begin();
77 playlist_Control( m_pPlaylist,
79 m_pPlaylist->status.i_view,
81 ? (playlist_item_t *)pItem->m_pData
82 : (playlist_item_t *)pItem->parent()->m_pData,
84 ? (playlist_item_t *)it->m_pData
85 : (playlist_item_t *)pItem->m_pData
87 vlc_mutex_unlock( &m_pPlaylist->object_lock );
90 void Playtree::onChange()
92 /* FIXME : updateTree could be a nice idea so we don't have to
93 * start from scratch each time the playlist changes */
98 void Playtree::buildNode( playlist_item_t *p_node, VarTree &m_pNode )
100 for( int i = 0; i < p_node->i_children; i++ )
102 UString *pName = new UString( getIntf(), p_node->pp_children[i]->input.psz_name );
103 m_pNode.add( UStringPtr( pName ),
105 m_pPlaylist->status.p_item == p_node->pp_children[i],
107 p_node->pp_children[i] );
108 if( p_node->pp_children[i]->i_children )
110 buildNode( p_node->pp_children[i], m_pNode.back() );
115 void Playtree::buildTree()
118 vlc_mutex_lock( &m_pPlaylist->object_lock );
120 playlist_view_t *p_view;
121 p_view = playlist_ViewFind( m_pPlaylist, VIEW_CATEGORY );
122 /* TODO : let the user chose the view type */
125 /* XXX : do we need Playlist::clear() instead of VarTree::clear() ? */
127 /* Set the root's name */
128 UString *pName = new UString( getIntf(), p_view->p_root->input.psz_name );
129 m_cString = UStringPtr( pName );
131 buildNode( p_view->p_root, *this );
133 vlc_mutex_unlock( &m_pPlaylist->object_lock );
134 checkParents( NULL );