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)
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 );
// 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;
+ }
}
}
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();
/// 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 ) {}
};
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()
{
/// 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;
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;
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();
}
// 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;
}