00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <vlc/vlc.h>
00025
00026 #include "playtree.hpp"
00027 #include "../utils/ustring.hpp"
00028
00029 #include "charset.h"
00030
00031
00032 Playtree::Playtree( intf_thread_t *pIntf ): VarTree( pIntf )
00033 {
00034
00035 m_pPlaylist = pIntf->p_sys->p_playlist;
00036
00037
00038 char *pCharset;
00039 vlc_current_charset( &pCharset );
00040 iconvHandle = vlc_iconv_open( "UTF-8", pCharset );
00041 msg_Dbg( pIntf, "Using character encoding: %s", pCharset );
00042 free( pCharset );
00043
00044 if( iconvHandle == (vlc_iconv_t) - 1 )
00045 {
00046 msg_Warn( pIntf, "Unable to do requested conversion" );
00047 }
00048
00049 buildTree();
00050 }
00051
00052 Playtree::~Playtree()
00053 {
00054 if( iconvHandle != (vlc_iconv_t) - 1 ) vlc_iconv_close( iconvHandle );
00055
00056 }
00057
00058 void Playtree::delSelected()
00059 {
00060
00061 notify();
00062 }
00063
00064 void Playtree::action( VarTree *pItem )
00065 {
00066
00067 playlist_PreparseEnqueueItem( m_pPlaylist,
00068 (playlist_item_t *)pItem->m_pData );
00069 vlc_mutex_lock( &m_pPlaylist->object_lock );
00070 VarTree::Iterator it;
00071 if( pItem->size() )
00072 {
00073 it = pItem->begin();
00074 while( it->size() ) it = it->begin();
00075 }
00076 playlist_Control( m_pPlaylist,
00077 PLAYLIST_VIEWPLAY,
00078 m_pPlaylist->status.i_view,
00079 pItem->size()
00080 ? (playlist_item_t *)pItem->m_pData
00081 : (playlist_item_t *)pItem->parent()->m_pData,
00082 pItem->size()
00083 ? (playlist_item_t *)it->m_pData
00084 : (playlist_item_t *)pItem->m_pData
00085 );
00086 vlc_mutex_unlock( &m_pPlaylist->object_lock );
00087 }
00088
00089 void Playtree::onChange()
00090 {
00091 buildTree();
00092 notify();
00093 }
00094
00095 void Playtree::onUpdate( int id )
00096 {
00097 Iterator it = findById( id );
00098 if( it != end() )
00099 {
00100
00101 playlist_item_t* pNode = (playlist_item_t*)(it->m_pData);
00102 UString *pName = new UString( getIntf(), pNode->input.psz_name );
00103 it->m_cString = UStringPtr( pName );
00104 it->m_playing = m_pPlaylist->status.p_item == pNode;
00105 }
00106 else
00107 {
00108 msg_Warn(getIntf(), "Cannot find node with id %d", id );
00109 }
00110
00111 notify();
00112 }
00113
00114 void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree )
00115 {
00116 for( int i = 0; i < pNode->i_children; i++ )
00117 {
00118 UString *pName = new UString( getIntf(),
00119 pNode->pp_children[i]->input.psz_name );
00120 rTree.add( pNode->pp_children[i]->input.i_id, UStringPtr( pName ),
00121 false,
00122 m_pPlaylist->status.p_item == pNode->pp_children[i],
00123 true, pNode->pp_children[i] );
00124 if( pNode->pp_children[i]->i_children )
00125 {
00126 buildNode( pNode->pp_children[i], rTree.back() );
00127 }
00128 }
00129 }
00130
00131 void Playtree::buildTree()
00132 {
00133 clear();
00134 vlc_mutex_lock( &m_pPlaylist->object_lock );
00135
00136 playlist_view_t *p_view;
00137 p_view = playlist_ViewFind( m_pPlaylist, VIEW_CATEGORY );
00138
00139
00140 clear();
00141
00142
00143
00144 UString *pName = new UString( getIntf(), p_view->p_root->input.psz_name );
00145 m_cString = UStringPtr( pName );
00146
00147 buildNode( p_view->p_root, *this );
00148
00149 vlc_mutex_unlock( &m_pPlaylist->object_lock );
00150 checkParents( NULL );
00151 }
00152