Commit 89acb8f5 authored by Cyril Deguet's avatar Cyril Deguet
Browse files

* all: don't rebuild the whole playtree when an item is updated

 (at the moment the tree control is still entirely rebuilt,
 but now it will be easier to fix that)
 + coding style fixes
parent 4e34b354
......@@ -35,7 +35,7 @@ void CmdNotifyPlaylist::execute()
rVar.onChange();
}
void CmdNotifyPlaytree::execute()
void CmdPlaytreeChanged::execute()
{
// Notify the playtree variable
Playtree &rVar = VlcProc::instance( getIntf() )->getPlaytreeVar();
......@@ -43,6 +43,14 @@ void CmdNotifyPlaytree::execute()
}
void CmdPlaytreeUpdate::execute()
{
// Notify the playtree variable
Playtree &rVar = VlcProc::instance( getIntf() )->getPlaytreeVar();
rVar.onUpdate( m_id );
}
void CmdSetText::execute()
{
// Change the text variable
......
......@@ -31,8 +31,28 @@ class VarText;
/// 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
......
......@@ -299,12 +299,12 @@ int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
// 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 ) );
......@@ -348,12 +348,13 @@ int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
// 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 ) );
......@@ -377,11 +378,11 @@ int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
// 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 ) );
......
......@@ -26,15 +26,22 @@
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 );
......@@ -45,19 +52,11 @@ VarTree::~VarTree()
// 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();
}
......@@ -205,3 +204,17 @@ VarTree::Iterator VarTree::getNextVisibleItem( Iterator it )
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();
}
......@@ -35,18 +35,20 @@
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();
......@@ -54,6 +56,8 @@ class VarTree: public Variable, public Subject<VarTree>
/// 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;
......@@ -126,9 +130,10 @@ class VarTree: public Variable, public Subject<VarTree>
/// 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;
......
......@@ -29,8 +29,7 @@
#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;
......@@ -95,19 +94,38 @@ void Playtree::onChange()
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() );
}
}
}
......@@ -133,3 +151,4 @@ void Playtree::buildTree()
vlc_mutex_unlock( &m_pPlaylist->object_lock );
checkParents( NULL );
}
......@@ -42,6 +42,9 @@ class Playtree: public VarTree
/// 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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment