From eba35637c30b4d012c3512d95f087e25532ebba9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20Stenac?= Date: Sat, 3 Dec 2005 11:40:40 +0000 Subject: [PATCH] Add a checkRemove method to CmdGeneric. It is called by asyncqueue if remove flag is true, to let the newly added command check if it wants its predecessors to be removed. Default is to always allow. Only implemented in CmdPlaytreeUpdate: only remove previous commands if they are about the same item. -> Limit excess updates to playtree (There are some debug messages left in this commit, will remove later) --- modules/gui/skins2/commands/async_queue.cpp | 17 +++++++++++------ modules/gui/skins2/commands/async_queue.hpp | 2 +- modules/gui/skins2/commands/cmd_generic.hpp | 4 ++++ modules/gui/skins2/commands/cmd_vars.cpp | 12 ++++++++++++ modules/gui/skins2/commands/cmd_vars.hpp | 3 +++ modules/gui/skins2/controls/ctrl_tree.cpp | 7 +++++++ modules/gui/skins2/src/vlcproc.cpp | 2 +- 7 files changed, 39 insertions(+), 8 deletions(-) diff --git a/modules/gui/skins2/commands/async_queue.cpp b/modules/gui/skins2/commands/async_queue.cpp index 170cec7633..fa2fc44518 100644 --- a/modules/gui/skins2/commands/async_queue.cpp +++ b/modules/gui/skins2/commands/async_queue.cpp @@ -80,13 +80,13 @@ void AsyncQueue::push( const CmdGenericPtr &rcCommand, bool removePrev ) if( removePrev ) { // Remove the commands of the same type - remove( rcCommand.get()->getType() ); + remove( rcCommand.get()->getType(), rcCommand ); } m_cmdList.push_back( rcCommand ); } -void AsyncQueue::remove( const string &rType ) +void AsyncQueue::remove( const string &rType, const CmdGenericPtr &rcCommand ) { vlc_mutex_lock( &m_lock ); @@ -96,10 +96,15 @@ void AsyncQueue::remove( const string &rType ) // Remove the command if it is of the given type if( (*it).get()->getType() == rType ) { - list::iterator itNew = it; - itNew++; - m_cmdList.erase( it ); - it = itNew; + // Maybe the command wants to check if it must really be + // removed + if( rcCommand.get()->checkRemove( (*it).get() ) == true ) + { + list::iterator itNew = it; + itNew++; + m_cmdList.erase( it ); + it = itNew; + } } } diff --git a/modules/gui/skins2/commands/async_queue.hpp b/modules/gui/skins2/commands/async_queue.hpp index e22666b17e..d2d4253353 100644 --- a/modules/gui/skins2/commands/async_queue.hpp +++ b/modules/gui/skins2/commands/async_queue.hpp @@ -49,7 +49,7 @@ class AsyncQueue: public SkinObject void push( const CmdGenericPtr &rcCommand, bool removePrev = true ); /// Remove the commands of the given type - void remove( const string &rType ); + void remove( const string &rType , const CmdGenericPtr &rcCommand ); /// Flush the queue and execute the commands void flush(); diff --git a/modules/gui/skins2/commands/cmd_generic.hpp b/modules/gui/skins2/commands/cmd_generic.hpp index 0235043c1a..c06efc104a 100644 --- a/modules/gui/skins2/commands/cmd_generic.hpp +++ b/modules/gui/skins2/commands/cmd_generic.hpp @@ -73,6 +73,10 @@ class CmdGeneric: public SkinObject /// Return the type of the command virtual string getType() const { return ""; } + /// During queue reductions, check if we really want to remove + /// this command. + virtual bool checkRemove( CmdGeneric * ) const { return true; } + protected: CmdGeneric( intf_thread_t *pIntf ): SkinObject( pIntf ) {} }; diff --git a/modules/gui/skins2/commands/cmd_vars.cpp b/modules/gui/skins2/commands/cmd_vars.cpp index b64ede8be1..a3aa46cf42 100644 --- a/modules/gui/skins2/commands/cmd_vars.cpp +++ b/modules/gui/skins2/commands/cmd_vars.cpp @@ -51,6 +51,18 @@ void CmdPlaytreeUpdate::execute() rVar.onUpdate( m_id ); } +bool CmdPlaytreeUpdate::checkRemove( CmdGeneric *pQueuedCommand ) const +{ + + CmdPlaytreeUpdate *pUpdateCommand = (CmdPlaytreeUpdate *)(pQueuedCommand); + //CmdPlaytreeUpdate *pUpdateCommand = dynamic_cast(pQueuedCommand); + if( m_id == pUpdateCommand->m_id ) + { + return true; + } + return false; +} + void CmdSetText::execute() { diff --git a/modules/gui/skins2/commands/cmd_vars.hpp b/modules/gui/skins2/commands/cmd_vars.hpp index a2445ed0de..9a30fe11b0 100644 --- a/modules/gui/skins2/commands/cmd_vars.hpp +++ b/modules/gui/skins2/commands/cmd_vars.hpp @@ -51,6 +51,9 @@ class CmdPlaytreeUpdate: public CmdGeneric /// Return the type of the command virtual string getType() const { return "playtree update"; } + /// Only accept removal of command if they concern the same item + virtual bool checkRemove( CmdGeneric * ) const; + private: /// Playlist item ID int m_id; diff --git a/modules/gui/skins2/controls/ctrl_tree.cpp b/modules/gui/skins2/controls/ctrl_tree.cpp index c44c888fef..c8906267bb 100644 --- a/modules/gui/skins2/controls/ctrl_tree.cpp +++ b/modules/gui/skins2/controls/ctrl_tree.cpp @@ -472,15 +472,18 @@ void CtrlTree::draw( OSGraphics &rImage, int xDest, int yDest ) void CtrlTree::autoScroll() { + fprintf( stderr, "Autoscroll start\n"); // Find the current playing stream int playIndex = 0; VarTree::Iterator it; for( it = m_rTree.begin(); it != m_rTree.end(); it = m_rTree.getNextVisibleItem( it ) ) { + fprintf (stderr, "Checking playindex is %i\n", playIndex); if( it->m_playing ) break; playIndex++; } + fprintf (stderr, "broke playIndex\n"); if( it == m_rTree.end() ) return; @@ -489,23 +492,27 @@ void CtrlTree::autoScroll() for( it = m_rTree.begin(); it != m_rTree.end(); it = m_rTree.getNextVisibleItem( it ) ) { + fprintf (stderr, "Testing, lastPos is %i\n", lastPosIndex ); if( it == m_lastPos ) break; lastPosIndex++; } if( it == m_rTree.end() ) return; + fprintf( stderr, "I have %i visible\n", maxItems() ); if( it != m_rTree.end() && ( playIndex < lastPosIndex || playIndex > lastPosIndex + maxItems() ) ) { + fprintf( stderr, "Need to scroll\n"); // Scroll to have the playing stream visible VarPercent &rVarPos = m_rTree.getPositionVar(); rVarPos.set( 1.0 - (double)playIndex / (double)m_rTree.visibleItems() ); } else { + fprintf( stderr, "No need to scroll\n"); makeImage(); notifyLayout(); } diff --git a/modules/gui/skins2/src/vlcproc.cpp b/modules/gui/skins2/src/vlcproc.cpp index d86436e01a..73bd8b8158 100644 --- a/modules/gui/skins2/src/vlcproc.cpp +++ b/modules/gui/skins2/src/vlcproc.cpp @@ -406,7 +406,7 @@ int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable, // Push the command in the asynchronous command queue AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); pQueue->push( CmdGenericPtr( pCmd ) ); - pQueue->push( CmdGenericPtr( pCmdTree ), false ); + pQueue->push( CmdGenericPtr( pCmdTree ), true ); return VLC_SUCCESS; } -- 2.39.5