From 89acb8f512feb0a4be4587ce085be08aa922b2de Mon Sep 17 00:00:00 2001 From: Cyril Deguet Date: Sun, 23 Oct 2005 17:42:16 +0000 Subject: [PATCH] * 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 --- modules/gui/skins2/commands/cmd_vars.cpp | 10 ++++- modules/gui/skins2/commands/cmd_vars.hpp | 24 ++++++++++- modules/gui/skins2/src/vlcproc.cpp | 13 +++--- modules/gui/skins2/utils/var_tree.cpp | 51 +++++++++++++++--------- modules/gui/skins2/utils/var_tree.hpp | 21 ++++++---- modules/gui/skins2/vars/playtree.cpp | 41 ++++++++++++++----- modules/gui/skins2/vars/playtree.hpp | 3 ++ 7 files changed, 116 insertions(+), 47 deletions(-) diff --git a/modules/gui/skins2/commands/cmd_vars.cpp b/modules/gui/skins2/commands/cmd_vars.cpp index f859a1a594..9cd849a71c 100644 --- a/modules/gui/skins2/commands/cmd_vars.cpp +++ b/modules/gui/skins2/commands/cmd_vars.cpp @@ -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 diff --git a/modules/gui/skins2/commands/cmd_vars.hpp b/modules/gui/skins2/commands/cmd_vars.hpp index ebb142958d..fbeb07276e 100644 --- a/modules/gui/skins2/commands/cmd_vars.hpp +++ b/modules/gui/skins2/commands/cmd_vars.hpp @@ -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 diff --git a/modules/gui/skins2/src/vlcproc.cpp b/modules/gui/skins2/src/vlcproc.cpp index 225fb2c1b3..8d532e5a94 100644 --- a/modules/gui/skins2/src/vlcproc.cpp +++ b/modules/gui/skins2/src/vlcproc.cpp @@ -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 ) ); diff --git a/modules/gui/skins2/utils/var_tree.cpp b/modules/gui/skins2/utils/var_tree.cpp index 12b7f707a6..2550b65917 100644 --- a/modules/gui/skins2/utils/var_tree.cpp +++ b/modules/gui/skins2/utils/var_tree.cpp @@ -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(); +} + diff --git a/modules/gui/skins2/utils/var_tree.hpp b/modules/gui/skins2/utils/var_tree.hpp index 39a1835842..101d3188aa 100644 --- a/modules/gui/skins2/utils/var_tree.hpp +++ b/modules/gui/skins2/utils/var_tree.hpp @@ -35,18 +35,20 @@ class VarTree: public Variable, public Subject { 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 /// 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 /// 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 m_children; diff --git a/modules/gui/skins2/vars/playtree.cpp b/modules/gui/skins2/vars/playtree.cpp index b1af19d001..b5dfd75bd1 100644 --- a/modules/gui/skins2/vars/playtree.cpp +++ b/modules/gui/skins2/vars/playtree.cpp @@ -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 ); } + diff --git a/modules/gui/skins2/vars/playtree.hpp b/modules/gui/skins2/vars/playtree.hpp index 5c5836c97f..b7a942deca 100644 --- a/modules/gui/skins2/vars/playtree.hpp +++ b/modules/gui/skins2/vars/playtree.hpp @@ -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; -- 2.39.2