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

* 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() ...@@ -35,7 +35,7 @@ void CmdNotifyPlaylist::execute()
rVar.onChange(); rVar.onChange();
} }
void CmdNotifyPlaytree::execute() void CmdPlaytreeChanged::execute()
{ {
// Notify the playtree variable // Notify the playtree variable
Playtree &rVar = VlcProc::instance( getIntf() )->getPlaytreeVar(); Playtree &rVar = VlcProc::instance( getIntf() )->getPlaytreeVar();
...@@ -43,6 +43,14 @@ void CmdNotifyPlaytree::execute() ...@@ -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() void CmdSetText::execute()
{ {
// Change the text variable // Change the text variable
......
...@@ -31,8 +31,28 @@ class VarText; ...@@ -31,8 +31,28 @@ class VarText;
/// Command to notify the playlist of a change /// Command to notify the playlist of a change
DEFINE_COMMAND( NotifyPlaylist, "notify playlist" ) 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 /// Command to set a text variable
......
...@@ -299,12 +299,12 @@ int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable, ...@@ -299,12 +299,12 @@ int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
// Create a playlist notify command // Create a playlist notify command
CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() ); CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
// Create a playtree notify command // 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 // Push the command in the asynchronous command queue
AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
pQueue->remove( "notify playlist" ); pQueue->remove( "notify playlist" );
pQueue->remove( "notify playtree" ); pQueue->remove( "playtree changed" );
pQueue->push( CmdGenericPtr( pCmd ) ); pQueue->push( CmdGenericPtr( pCmd ) );
pQueue->push( CmdGenericPtr( pCmdTree ) ); pQueue->push( CmdGenericPtr( pCmdTree ) );
...@@ -348,12 +348,13 @@ int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable, ...@@ -348,12 +348,13 @@ int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
// TODO: selective update // TODO: selective update
CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() ); CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
// Create a playtree notify command // 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 // Push the command in the asynchronous command queue
AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
pQueue->remove( "notify playlist" ); pQueue->remove( "notify playlist" );
pQueue->remove( "notify playtree" ); pQueue->remove( "playtree update" );
pQueue->push( CmdGenericPtr( pCmd ) ); pQueue->push( CmdGenericPtr( pCmd ) );
pQueue->push( CmdGenericPtr( pCmdTree ) ); pQueue->push( CmdGenericPtr( pCmdTree ) );
...@@ -377,11 +378,11 @@ int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable, ...@@ -377,11 +378,11 @@ int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
// TODO: selective update // TODO: selective update
CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() ); CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
// Create a playtree notify command // 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 // Push the command in the asynchronous command queue
pQueue->remove( "notify playlist" ); pQueue->remove( "notify playlist" );
pQueue->remove( "notify playtree" ); pQueue->remove( "playtree changed" );
pQueue->push( CmdGenericPtr( pCmd ) ); pQueue->push( CmdGenericPtr( pCmd ) );
pQueue->push( CmdGenericPtr( pCmdTree ) ); pQueue->push( CmdGenericPtr( pCmdTree ) );
......
...@@ -26,15 +26,22 @@ ...@@ -26,15 +26,22 @@
const string VarTree::m_type = "tree"; const string VarTree::m_type = "tree";
VarTree::VarTree( intf_thread_t *pIntf, VarTree *pParent ) VarTree::VarTree( intf_thread_t *pIntf )
: Variable( pIntf ) : Variable( pIntf ), m_id( 0 ), m_selected( false ), m_playing( false ),
m_expanded( true ), m_pData( NULL ), m_pParent( NULL )
{ {
m_selected = false; // Create the position variable
m_playing = false; m_cPosition = VariablePtr( new VarPercent( pIntf ) );
m_expanded = true; getPositionVar().set( 1.0 );
m_pData = NULL; }
m_pParent = pParent;
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 // Create the position variable
m_cPosition = VariablePtr( new VarPercent( pIntf ) ); m_cPosition = VariablePtr( new VarPercent( pIntf ) );
getPositionVar().set( 1.0 ); getPositionVar().set( 1.0 );
...@@ -45,19 +52,11 @@ VarTree::~VarTree() ...@@ -45,19 +52,11 @@ VarTree::~VarTree()
// TODO : check that children are deleted // TODO : check that children are deleted
} }
void VarTree::add( const UStringPtr &rcString, void VarTree::add( int id, const UStringPtr &rcString, bool selected,
bool selected, bool playing, bool expanded, void *pData )
bool playing,
bool expanded,
void *pData )
{ {
m_children.push_back( VarTree( getIntf(), this ) ); m_children.push_back( VarTree( getIntf(), this, id, rcString, selected,
back().m_cString = rcString; playing, expanded, pData ) );
back().m_selected = selected;
back().m_playing = playing;
back().m_expanded = expanded;
back().m_pData = pData;
notify(); notify();
} }
...@@ -205,3 +204,17 @@ VarTree::Iterator VarTree::getNextVisibleItem( Iterator it ) ...@@ -205,3 +204,17 @@ VarTree::Iterator VarTree::getNextVisibleItem( Iterator it )
return 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 @@ ...@@ -35,18 +35,20 @@
class VarTree: public Variable, public Subject<VarTree> class VarTree: public Variable, public Subject<VarTree>
{ {
public: 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(); virtual ~VarTree();
/// Get the variable type /// Get the variable type
virtual const string &getType() const { return m_type; } virtual const string &getType() const { return m_type; }
/// Add a pointer on string in the children's list /// Add a pointer on string in the children's list
virtual void add( const UStringPtr &rcString, virtual void add( int id, const UStringPtr &rcString, bool selected,
bool selected = true, bool playing, bool expanded, void *pData );
bool playing = true,
bool expanded = true,
void *pData = NULL );
/// Remove the selected item from the children's list /// Remove the selected item from the children's list
virtual void delSelected(); virtual void delSelected();
...@@ -54,6 +56,8 @@ class VarTree: public Variable, public Subject<VarTree> ...@@ -54,6 +56,8 @@ class VarTree: public Variable, public Subject<VarTree>
/// Remove all elements from the children's list /// Remove all elements from the children's list
virtual void clear(); virtual void clear();
/// FIXME should be private
int m_id;
UStringPtr m_cString; UStringPtr m_cString;
bool m_selected; bool m_selected;
bool m_playing; bool m_playing;
...@@ -126,9 +130,10 @@ class VarTree: public Variable, public Subject<VarTree> ...@@ -126,9 +130,10 @@ class VarTree: public Variable, public Subject<VarTree>
/// Given an iterator to a visible item, return the next visible item /// Given an iterator to a visible item, return the next visible item
Iterator getNextVisibleItem( Iterator it ); Iterator getNextVisibleItem( Iterator it );
private: /// Find a children node with the given id
// intf_thread_t *pIntf; Iterator findById( int id );
private:
/// List of children /// List of children
list<VarTree> m_children; list<VarTree> m_children;
......
...@@ -29,8 +29,7 @@ ...@@ -29,8 +29,7 @@
#include "charset.h" #include "charset.h"
Playtree::Playtree( intf_thread_t *pIntf ) Playtree::Playtree( intf_thread_t *pIntf ): VarTree( pIntf )
:VarTree( pIntf, /*m_parent = */NULL )
{ {
// Get the VLC playlist object // Get the VLC playlist object
m_pPlaylist = pIntf->p_sys->p_playlist; m_pPlaylist = pIntf->p_sys->p_playlist;
...@@ -95,19 +94,38 @@ void Playtree::onChange() ...@@ -95,19 +94,38 @@ void Playtree::onChange()
notify(); 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 ); // Update the item
m_pNode.add( UStringPtr( pName ), 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, false,
m_pPlaylist->status.p_item == p_node->pp_children[i], m_pPlaylist->status.p_item == pNode->pp_children[i],
true, true, pNode->pp_children[i] );
p_node->pp_children[i] ); if( pNode->pp_children[i]->i_children )
if( p_node->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() ...@@ -133,3 +151,4 @@ void Playtree::buildTree()
vlc_mutex_unlock( &m_pPlaylist->object_lock ); vlc_mutex_unlock( &m_pPlaylist->object_lock );
checkParents( NULL ); checkParents( NULL );
} }
...@@ -42,6 +42,9 @@ class Playtree: public VarTree ...@@ -42,6 +42,9 @@ class Playtree: public VarTree
/// Function called to notify playlist changes /// Function called to notify playlist changes
void onChange(); void onChange();
/// Function called to notify playlist item update
void onUpdate( int id );
private: private:
/// VLC playlist object /// VLC playlist object
playlist_t *m_pPlaylist; 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