1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2005 VideoLAN
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 ): VarTree( pIntf )
34 // Get the VLC playlist object
35 m_pPlaylist = pIntf->p_sys->p_playlist;
37 i_items_to_append = 0;
39 // Try to guess the current charset
41 vlc_current_charset( &pCharset );
42 iconvHandle = vlc_iconv_open( "UTF-8", pCharset );
43 msg_Dbg( pIntf, "Using character encoding: %s", pCharset );
46 if( iconvHandle == (vlc_iconv_t) - 1 )
48 msg_Warn( pIntf, "Unable to do requested conversion" );
56 if( iconvHandle != (vlc_iconv_t) - 1 ) vlc_iconv_close( iconvHandle );
57 // TODO : check that everything is destroyed
60 void Playtree::delSelected()
63 for (it = begin(); it != end() ; it = getNextVisibleItem( it ) )
65 if( (*it).m_selected )
67 playlist_item_t *p_item = (playlist_item_t *)(it->m_pData);
68 if( p_item->i_children == -1 )
70 playlist_LockDelete( getIntf()->p_sys->p_playlist,
75 vlc_mutex_lock( &getIntf()->p_sys->p_playlist->object_lock );
76 playlist_NodeDelete( getIntf()->p_sys->p_playlist, p_item,
77 VLC_TRUE, VLC_FALSE );
78 vlc_mutex_unlock( &getIntf()->p_sys->p_playlist->object_lock );
82 // TODO: Do this better
89 void Playtree::action( VarTree *pItem )
91 vlc_mutex_lock( &m_pPlaylist->object_lock );
96 while( it->size() ) it = it->begin();
98 playlist_Control( m_pPlaylist,
100 m_pPlaylist->status.i_view,
102 ? (playlist_item_t *)pItem->m_pData
103 : (playlist_item_t *)pItem->parent()->m_pData,
105 ? (playlist_item_t *)it->m_pData
106 : (playlist_item_t *)pItem->m_pData
108 vlc_mutex_unlock( &m_pPlaylist->object_lock );
111 void Playtree::onChange()
119 void Playtree::onUpdateItem( int id )
121 Iterator it = findById( id );
125 playlist_item_t* pNode = (playlist_item_t*)(it->m_pData);
126 UString *pName = new UString( getIntf(), pNode->input.psz_name );
127 it->m_cString = UStringPtr( pName );
128 it->m_playing = m_pPlaylist->status.p_item == pNode;
132 msg_Warn(getIntf(), "Cannot find node with id %d", id );
139 void Playtree::onAppend( playlist_add_t *p_add )
141 i_items_to_append --;
143 Iterator node = findById( p_add->i_node );
146 Iterator item = findById( p_add->i_item );
149 playlist_item_t *p_item = playlist_ItemGetById(
150 m_pPlaylist, p_add->i_item );
151 if( !p_item ) return;
152 UString *pName = new UString( getIntf(), p_item->input.psz_name );
153 node->add( p_add->i_item, UStringPtr( pName ),
154 false,false, false, p_item );
158 descr.i_id = p_add->i_item;
159 descr.i_parent = p_add->i_node;
160 descr.b_visible = node->m_expanded;
165 void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree )
167 for( int i = 0; i < pNode->i_children; i++ )
169 UString *pName = new UString( getIntf(),
170 pNode->pp_children[i]->input.psz_name );
171 rTree.add( pNode->pp_children[i]->input.i_id, UStringPtr( pName ),
173 m_pPlaylist->status.p_item == pNode->pp_children[i],
174 false, pNode->pp_children[i] );
175 if( pNode->pp_children[i]->i_children )
177 buildNode( pNode->pp_children[i], rTree.back() );
182 void Playtree::buildTree()
185 vlc_mutex_lock( &m_pPlaylist->object_lock );
187 i_items_to_append = 0;
189 playlist_view_t *p_view;
190 p_view = playlist_ViewFind( m_pPlaylist, VIEW_CATEGORY );
191 /* TODO : let the user chose the view type */
194 /* XXX : do we need Playlist::clear() instead of VarTree::clear() ? */
196 /* Set the root's name */
197 UString *pName = new UString( getIntf(), p_view->p_root->input.psz_name );
198 m_cString = UStringPtr( pName );
200 buildNode( p_view->p_root, *this );
202 vlc_mutex_unlock( &m_pPlaylist->object_lock );
204 // checkParents( NULL );