rVar.onChange();
}
-void CmdNotifyPlaytree::execute()
+void CmdPlaytreeChanged::execute()
{
// Notify the playtree variable
Playtree &rVar = VlcProc::instance( getIntf() )->getPlaytreeVar();
}
+void CmdPlaytreeUpdate::execute()
+{
+ // Notify the playtree variable
+ Playtree &rVar = VlcProc::instance( getIntf() )->getPlaytreeVar();
+ rVar.onUpdate( m_id );
+}
+
+
void CmdSetText::execute()
{
// Change the text variable
/// Command to notify the playlist of a change
DEFINE_COMMAND( NotifyPlaylist, "notify playlist" )
-/// Command to notify the playtree of a change
-DEFINE_COMMAND( NotifyPlaytree, "notify playtree" )
+
+/// Command to notify the playlist of a change
+DEFINE_COMMAND( PlaytreeChanged, "playtree changed" )
+
+/// Command to notify the playtree of an item update
+class CmdPlaytreeUpdate: public CmdGeneric
+{
+ public:
+ CmdPlaytreeUpdate( intf_thread_t *pIntf, int id ):
+ CmdGeneric( pIntf ), m_id( id ) {}
+ virtual ~CmdPlaytreeUpdate() {}
+
+ /// This method does the real job of the command
+ virtual void execute();
+
+ /// Return the type of the command
+ virtual string getType() const { return "playtree update"; }
+
+ private:
+ /// Playlist item ID
+ int m_id;
+};
/// Command to set a text variable
// Create a playlist notify command
CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
// Create a playtree notify command
- CmdNotifyPlaytree *pCmdTree = new CmdNotifyPlaytree( pThis->getIntf() );
+ CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
// Push the command in the asynchronous command queue
AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
pQueue->remove( "notify playlist" );
- pQueue->remove( "notify playtree" );
+ pQueue->remove( "playtree changed" );
pQueue->push( CmdGenericPtr( pCmd ) );
pQueue->push( CmdGenericPtr( pCmdTree ) );
// TODO: selective update
CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
// Create a playtree notify command
- CmdNotifyPlaytree *pCmdTree = new CmdNotifyPlaytree( pThis->getIntf() );
+ CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
+ newVal.i_int );
// Push the command in the asynchronous command queue
AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
pQueue->remove( "notify playlist" );
- pQueue->remove( "notify playtree" );
+ pQueue->remove( "playtree update" );
pQueue->push( CmdGenericPtr( pCmd ) );
pQueue->push( CmdGenericPtr( pCmdTree ) );
// TODO: selective update
CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
// Create a playtree notify command
- CmdNotifyPlaytree *pCmdTree = new CmdNotifyPlaytree( pThis->getIntf() );
+ CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
// Push the command in the asynchronous command queue
pQueue->remove( "notify playlist" );
- pQueue->remove( "notify playtree" );
+ pQueue->remove( "playtree changed" );
pQueue->push( CmdGenericPtr( pCmd ) );
pQueue->push( CmdGenericPtr( pCmdTree ) );
const string VarTree::m_type = "tree";
-VarTree::VarTree( intf_thread_t *pIntf, VarTree *pParent )
- : Variable( pIntf )
+VarTree::VarTree( intf_thread_t *pIntf )
+ : Variable( pIntf ), m_id( 0 ), m_selected( false ), m_playing( false ),
+ m_expanded( true ), m_pData( NULL ), m_pParent( NULL )
{
- m_selected = false;
- m_playing = false;
- m_expanded = true;
- m_pData = NULL;
- m_pParent = pParent;
+ // Create the position variable
+ m_cPosition = VariablePtr( new VarPercent( pIntf ) );
+ getPositionVar().set( 1.0 );
+}
+VarTree::VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
+ const UStringPtr &rcString, bool selected, bool playing,
+ bool expanded, void *pData )
+ : Variable( pIntf ), m_id( id ), m_cString( rcString ),
+ m_selected( selected ), m_playing( playing ), m_expanded( expanded ),
+ m_pData( pData ), m_pParent( pParent )
+{
// Create the position variable
m_cPosition = VariablePtr( new VarPercent( pIntf ) );
getPositionVar().set( 1.0 );
// TODO : check that children are deleted
}
-void VarTree::add( const UStringPtr &rcString,
- bool selected,
- bool playing,
- bool expanded,
- void *pData )
+void VarTree::add( int id, const UStringPtr &rcString, bool selected,
+ bool playing, bool expanded, void *pData )
{
- m_children.push_back( VarTree( getIntf(), this ) );
- back().m_cString = rcString;
- back().m_selected = selected;
- back().m_playing = playing;
- back().m_expanded = expanded;
- back().m_pData = pData;
-
+ m_children.push_back( VarTree( getIntf(), this, id, rcString, selected,
+ playing, expanded, pData ) );
notify();
}
return it;
}
+VarTree::Iterator VarTree::findById( int id )
+{
+ for (Iterator it = begin(); it != end(); ++it )
+ {
+ if( it->m_id == id )
+ {
+ return it;
+ }
+ Iterator result = it->findById( id );
+ if( result != it->end() ) return result;
+ }
+ return end();
+}
+
class VarTree: public Variable, public Subject<VarTree>
{
public:
- VarTree( intf_thread_t *pIntf, VarTree *pParent );
+ VarTree( intf_thread_t *pIntf );
+
+ VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
+ const UStringPtr &rcString, bool selected, bool playing,
+ bool expanded, void *pData );
+
virtual ~VarTree();
/// Get the variable type
virtual const string &getType() const { return m_type; }
/// Add a pointer on string in the children's list
- virtual void add( const UStringPtr &rcString,
- bool selected = true,
- bool playing = true,
- bool expanded = true,
- void *pData = NULL );
+ virtual void add( int id, const UStringPtr &rcString, bool selected,
+ bool playing, bool expanded, void *pData );
/// Remove the selected item from the children's list
virtual void delSelected();
/// Remove all elements from the children's list
virtual void clear();
+ /// FIXME should be private
+ int m_id;
UStringPtr m_cString;
bool m_selected;
bool m_playing;
/// Given an iterator to a visible item, return the next visible item
Iterator getNextVisibleItem( Iterator it );
- private:
-// intf_thread_t *pIntf;
+ /// Find a children node with the given id
+ Iterator findById( int id );
+ private:
/// List of children
list<VarTree> m_children;
#include "charset.h"
-Playtree::Playtree( intf_thread_t *pIntf )
- :VarTree( pIntf, /*m_parent = */NULL )
+Playtree::Playtree( intf_thread_t *pIntf ): VarTree( pIntf )
{
// Get the VLC playlist object
m_pPlaylist = pIntf->p_sys->p_playlist;
notify();
}
-void Playtree::buildNode( playlist_item_t *p_node, VarTree &m_pNode )
+void Playtree::onUpdate( int id )
{
- for( int i = 0; i < p_node->i_children; i++ )
+ Iterator it = findById( id );
+ if( it != end() )
{
- UString *pName = new UString( getIntf(), p_node->pp_children[i]->input.psz_name );
- m_pNode.add( UStringPtr( pName ),
+ // Update the item
+ playlist_item_t* pNode = (playlist_item_t*)(it->m_pData);
+ UString *pName = new UString( getIntf(), pNode->input.psz_name );
+ it->m_cString = UStringPtr( pName );
+ it->m_playing = m_pPlaylist->status.p_item == pNode;
+ }
+ else
+ {
+ msg_Warn(getIntf(), "Cannot find node with id %d", id );
+ }
+ // TODO update only the right node
+ notify();
+}
+
+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 ),
false,
- m_pPlaylist->status.p_item == p_node->pp_children[i],
- true,
- p_node->pp_children[i] );
- if( p_node->pp_children[i]->i_children )
+ m_pPlaylist->status.p_item == pNode->pp_children[i],
+ true, pNode->pp_children[i] );
+ if( pNode->pp_children[i]->i_children )
{
- buildNode( p_node->pp_children[i], m_pNode.back() );
+ buildNode( pNode->pp_children[i], rTree.back() );
}
}
}
vlc_mutex_unlock( &m_pPlaylist->object_lock );
checkParents( NULL );
}
+
/// Function called to notify playlist changes
void onChange();
+ /// Function called to notify playlist item update
+ void onUpdate( int id );
+
private:
/// VLC playlist object
playlist_t *m_pPlaylist;