Commit eba35637 authored by Clément Stenac's avatar Clément Stenac

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)
parent 43c3dc3f
......@@ -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<CmdGenericPtr>::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<CmdGenericPtr>::iterator itNew = it;
itNew++;
m_cmdList.erase( it );
it = itNew;
}
}
}
......
......@@ -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();
......
......@@ -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 ) {}
};
......
......@@ -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<CmdPlaytreeUpdate *>(pQueuedCommand);
if( m_id == pUpdateCommand->m_id )
{
return true;
}
return false;
}
void CmdSetText::execute()
{
......
......@@ -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;
......
......@@ -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();
}
......
......@@ -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;
}
......
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