X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fskins2%2Fvars%2Fplaytree.cpp;h=ad808d4214bf175cc71ef739a7e289aee5cdf3f7;hb=ee7537e77ae5c190881227db774a1eee6c1c7aa8;hp=d63fa28a0f8830bca7e18d6104d9861506f1f5e6;hpb=4eed32091e344d6a54952b8f3645702106bd78ee;p=vlc diff --git a/modules/gui/skins2/vars/playtree.cpp b/modules/gui/skins2/vars/playtree.cpp index d63fa28a0f..ad808d4214 100644 --- a/modules/gui/skins2/vars/playtree.cpp +++ b/modules/gui/skins2/vars/playtree.cpp @@ -1,10 +1,11 @@ /***************************************************************************** * playtree.cpp ***************************************************************************** - * Copyright (C) 2005 VideoLAN + * Copyright (C) 2005 the VideoLAN team * $Id$ * * Authors: Antoine Cellerier + * Clément Stenac * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,15 +19,20 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include #include "playtree.hpp" +#include #include "../utils/ustring.hpp" -#include "charset.h" +#include "vlc_charset.h" Playtree::Playtree( intf_thread_t *pIntf ): VarTree( pIntf ) @@ -34,98 +40,156 @@ Playtree::Playtree( intf_thread_t *pIntf ): VarTree( pIntf ) // Get the VLC playlist object m_pPlaylist = pIntf->p_sys->p_playlist; - // Try to guess the current charset - char *pCharset; - vlc_current_charset( &pCharset ); - iconvHandle = vlc_iconv_open( "UTF-8", pCharset ); - msg_Dbg( pIntf, "Using character encoding: %s", pCharset ); - free( pCharset ); - - if( iconvHandle == (vlc_iconv_t) - 1 ) - { - msg_Warn( pIntf, "Unable to do requested conversion" ); - } + i_items_to_append = 0; buildTree(); } Playtree::~Playtree() { - if( iconvHandle != (vlc_iconv_t) - 1 ) vlc_iconv_close( iconvHandle ); - // TODO : check that everything is destroyed } void Playtree::delSelected() { - Iterator it; - for (it = begin(); it != end() ; it = getNextVisibleItem( it ) ) + Iterator it = begin(); + vlc_object_lock( getIntf()->p_sys->p_playlist ); + for( it = begin(); it != end(); it = getNextVisibleItem( it ) ) + { + if( (*it).m_selected && !(*it).isReadonly() ) + { + (*it).m_deleted = true; + } + } + /// \todo Do this better (handle item-deleted) + tree_update descr; + descr.i_type = 3; + notify( &descr ); + it = begin(); + while( it != end() ) { - if( (*it).m_selected ) + if( (*it).m_deleted ) { + VarTree::Iterator it2; playlist_item_t *p_item = (playlist_item_t *)(it->m_pData); if( p_item->i_children == -1 ) { - playlist_LockDelete( getIntf()->p_sys->p_playlist, - p_item->input.i_id ); + playlist_DeleteFromInput( getIntf()->p_sys->p_playlist, + p_item->p_input->i_id, true ); + it2 = getNextVisibleItem( it ) ; + it->parent()->removeChild( it ); + it = it2; } else { - vlc_mutex_lock( &getIntf()->p_sys->p_playlist->object_lock ); playlist_NodeDelete( getIntf()->p_sys->p_playlist, p_item, - VLC_TRUE, VLC_FALSE ); - vlc_mutex_unlock( &getIntf()->p_sys->p_playlist->object_lock ); + true, false ); + it2 = getNextSibling( it ); + it->parent()->removeChild( it ); + it = it2; } } + else + { + it = getNextVisibleItem( it ); + } } - buildTree(); - notify(); + vlc_object_unlock( getIntf()->p_sys->p_playlist ); } void Playtree::action( VarTree *pItem ) { - vlc_mutex_lock( &m_pPlaylist->object_lock ); + vlc_object_lock( m_pPlaylist ); VarTree::Iterator it; - if( pItem->size() ) + + playlist_item_t *p_item = (playlist_item_t *)pItem->m_pData; + playlist_item_t *p_parent = p_item; + while( p_parent ) + { + if( p_parent == m_pPlaylist->p_root_category ) + break; + p_parent = p_parent->p_parent; + } + + if( p_parent ) { - it = pItem->begin(); - while( it->size() ) it = it->begin(); + playlist_Control( m_pPlaylist, PLAYLIST_VIEWPLAY, pl_Locked, p_parent, p_item ); } - playlist_Control( m_pPlaylist, - PLAYLIST_VIEWPLAY, - m_pPlaylist->status.i_view, - pItem->size() - ? (playlist_item_t *)pItem->m_pData - : (playlist_item_t *)pItem->parent()->m_pData, - pItem->size() - ? (playlist_item_t *)it->m_pData - : (playlist_item_t *)pItem->m_pData - ); - vlc_mutex_unlock( &m_pPlaylist->object_lock ); + vlc_object_unlock( m_pPlaylist ); } void Playtree::onChange() { buildTree(); - notify(); + tree_update descr; + descr.i_type = 1; + notify( &descr ); } -void Playtree::onUpdate( int id ) +void Playtree::onUpdateItem( int id ) { Iterator it = findById( id ); + tree_update descr; + descr.b_active_item = false; if( it != end() ) { // Update the item playlist_item_t* pNode = (playlist_item_t*)(it->m_pData); - UString *pName = new UString( getIntf(), pNode->input.psz_name ); + UString *pName = new UString( getIntf(), pNode->p_input->psz_name ); it->m_cString = UStringPtr( pName ); it->m_playing = m_pPlaylist->status.p_item == pNode; + if( it->m_playing ) descr.b_active_item = true; } else { - msg_Warn(getIntf(), "Cannot find node with id %d", id ); + msg_Warn(getIntf(), "cannot find node with id %d", id ); } - // TODO update only the right node - notify(); + descr.i_type = 0; + notify( &descr ); +} + +/// \todo keep a list of "recently removed" to avoid looking up if we +// already removed it +void Playtree::onDelete( int i_id ) +{ + tree_update descr; + descr.i_id = i_id; + descr.i_type = 3; + Iterator item = findById( i_id ) ; + if( item != end() ) + { + if( item->parent() ) + item->parent()->removeChild( item ); + descr.b_visible = item->parent() ? true : item->parent()->m_expanded; + notify( &descr ); + } +} + +void Playtree::onAppend( playlist_add_t *p_add ) +{ + i_items_to_append --; + + Iterator node = findById( p_add->i_node ); + if( node != end() ) + { + Iterator item = findById( p_add->i_item ); + if( item == end() ) + { + playlist_item_t *p_item = playlist_ItemGetById( + m_pPlaylist, p_add->i_item, false ); + if( !p_item ) return; + UString *pName = new UString( getIntf(), + p_item->p_input->psz_name ); + node->add( p_add->i_item, UStringPtr( pName ), + false,false, false, p_item->i_flags & PLAYLIST_RO_FLAG, + p_item ); + } + } + tree_update descr; + descr.i_id = p_add->i_item; + descr.i_parent = p_add->i_node; + descr.b_visible = node->m_expanded; + descr.i_type = 2; + notify( &descr ); } void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree ) @@ -133,11 +197,12 @@ void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree ) for( int i = 0; i < pNode->i_children; i++ ) { UString *pName = new UString( getIntf(), - pNode->pp_children[i]->input.psz_name ); - rTree.add( pNode->pp_children[i]->input.i_id, UStringPtr( pName ), + pNode->pp_children[i]->p_input->psz_name ); + rTree.add( pNode->pp_children[i]->p_input->i_id, UStringPtr( pName ), false, m_pPlaylist->status.p_item == pNode->pp_children[i], - true, pNode->pp_children[i] ); + false, pNode->pp_children[i]->i_flags & PLAYLIST_RO_FLAG, + pNode->pp_children[i] ); if( pNode->pp_children[i]->i_children ) { buildNode( pNode->pp_children[i], rTree.back() ); @@ -148,22 +213,23 @@ void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree ) void Playtree::buildTree() { clear(); - vlc_mutex_lock( &m_pPlaylist->object_lock ); + vlc_object_lock( m_pPlaylist ); - playlist_view_t *p_view; - p_view = playlist_ViewFind( m_pPlaylist, VIEW_CATEGORY ); - /* TODO : let the user chose the view type */ + i_items_to_append = 0; clear(); - /* XXX : do we need Playlist::clear() instead of VarTree::clear() ? */ + + /* TODO: Let user choose view - Stick with category ATM */ /* Set the root's name */ - UString *pName = new UString( getIntf(), p_view->p_root->input.psz_name ); + UString *pName = new UString( getIntf(), + m_pPlaylist->p_root_category->p_input->psz_name ); m_cString = UStringPtr( pName ); - buildNode( p_view->p_root, *this ); + buildNode( m_pPlaylist->p_root_category, *this ); - vlc_mutex_unlock( &m_pPlaylist->object_lock ); - checkParents( NULL ); + vlc_object_unlock( m_pPlaylist ); +// What is it ? +// checkParents( NULL ); }