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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 );
59 void Playtree::delSelected()
61 Iterator it = begin();
62 vlc_mutex_lock( &getIntf()->p_sys->p_playlist->object_lock );
63 for( it = begin(); it != end(); it = getNextVisibleItem( it ) )
65 if( (*it).m_selected && !(*it).isReadonly() )
67 (*it).m_deleted = true;
70 /// \todo Do this better (handle item-deleted)
79 VarTree::Iterator it2;
80 playlist_item_t *p_item = (playlist_item_t *)(it->m_pData);
81 if( p_item->i_children == -1 )
83 playlist_Delete( getIntf()->p_sys->p_playlist,
85 it2 = getNextVisibleItem( it ) ;
86 it->parent()->removeChild( it );
91 playlist_NodeDelete( getIntf()->p_sys->p_playlist, p_item,
92 VLC_TRUE, VLC_FALSE );
93 it2 = getNextSibling( it );
94 it->parent()->removeChild( it );
100 it = getNextVisibleItem( it );
103 vlc_mutex_unlock( &getIntf()->p_sys->p_playlist->object_lock );
106 void Playtree::action( VarTree *pItem )
108 vlc_mutex_lock( &m_pPlaylist->object_lock );
109 VarTree::Iterator it;
113 while( it->size() ) it = it->begin();
115 playlist_Control( m_pPlaylist,
117 m_pPlaylist->status.i_view,
119 ? (playlist_item_t *)pItem->m_pData
120 : (playlist_item_t *)pItem->parent()->m_pData,
122 ? (playlist_item_t *)it->m_pData
123 : (playlist_item_t *)pItem->m_pData
125 vlc_mutex_unlock( &m_pPlaylist->object_lock );
128 void Playtree::onChange()
136 void Playtree::onUpdateItem( int id )
138 Iterator it = findById( id );
140 descr.b_active_item = false;
144 playlist_item_t* pNode = (playlist_item_t*)(it->m_pData);
145 UString *pName = new UString( getIntf(), pNode->input.psz_name );
146 it->m_cString = UStringPtr( pName );
147 it->m_playing = m_pPlaylist->status.p_item == pNode;
148 if( it->m_playing ) descr.b_active_item = true;
152 msg_Warn(getIntf(), "Cannot find node with id %d", id );
158 /// \todo keep a list of "recently removed" to avoid looking up if we
159 // already removed it
160 void Playtree::onDelete( int i_id )
165 Iterator item = findById( i_id ) ;
169 item->parent()->removeChild( item );
170 descr.b_visible = item->parent() ? true : item->parent()->m_expanded;
175 void Playtree::onAppend( playlist_add_t *p_add )
177 i_items_to_append --;
179 Iterator node = findById( p_add->i_node );
182 Iterator item = findById( p_add->i_item );
185 playlist_item_t *p_item = playlist_ItemGetById(
186 m_pPlaylist, p_add->i_item );
187 if( !p_item ) return;
188 UString *pName = new UString( getIntf(), p_item->input.psz_name );
189 node->add( p_add->i_item, UStringPtr( pName ),
190 false,false, false, p_item->i_flags & PLAYLIST_RO_FLAG,
195 descr.i_id = p_add->i_item;
196 descr.i_parent = p_add->i_node;
197 descr.b_visible = node->m_expanded;
202 void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree )
204 for( int i = 0; i < pNode->i_children; i++ )
206 UString *pName = new UString( getIntf(),
207 pNode->pp_children[i]->input.psz_name );
208 rTree.add( pNode->pp_children[i]->input.i_id, UStringPtr( pName ),
210 m_pPlaylist->status.p_item == pNode->pp_children[i],
211 false, pNode->pp_children[i]->i_flags & PLAYLIST_RO_FLAG,
212 pNode->pp_children[i] );
213 if( pNode->pp_children[i]->i_children )
215 buildNode( pNode->pp_children[i], rTree.back() );
220 void Playtree::buildTree()
223 vlc_mutex_lock( &m_pPlaylist->object_lock );
225 i_items_to_append = 0;
227 playlist_view_t *p_view;
228 p_view = playlist_ViewFind( m_pPlaylist, VIEW_CATEGORY );
229 /// \todo let the user chose the view
233 /* Set the root's name */
234 UString *pName = new UString( getIntf(), p_view->p_root->input.psz_name );
235 m_cString = UStringPtr( pName );
237 buildNode( p_view->p_root, *this );
239 vlc_mutex_unlock( &m_pPlaylist->object_lock );
241 // checkParents( NULL );