Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

playtree.cpp

00001 /*****************************************************************************
00002  * playtree.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2005 VideoLAN
00005  * $Id: playlist.hpp 8659 2004-09-07 21:16:49Z gbazin $
00006  *
00007  * Authors: Antoine Cellerier <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
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     // Get the VLC playlist object
00035     m_pPlaylist = pIntf->p_sys->p_playlist;
00036 
00037     // Try to guess the current charset
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     // TODO : check that everything is destroyed
00056 }
00057 
00058 void Playtree::delSelected()
00059 {
00060     // TODO
00061     notify();
00062 }
00063 
00064 void Playtree::action( VarTree *pItem )
00065 {
00066     /* do we really want to call preparse here ? */
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         // Update the item
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     // TODO update only the right node
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     /* TODO : let the user chose the view type */
00139 
00140     clear();
00141     /* XXX : do we need Playlist::clear() instead of VarTree::clear() ? */
00142 
00143     /* Set the root's name */
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 

Generated on Tue Dec 20 10:14:43 2005 for vlc-0.8.4a by  doxygen 1.4.2