]> git.sesse.net Git - vlc/commitdiff
Add a checkRemove method to CmdGeneric.
authorClément Stenac <zorglub@videolan.org>
Sat, 3 Dec 2005 11:40:40 +0000 (11:40 +0000)
committerClément Stenac <zorglub@videolan.org>
Sat, 3 Dec 2005 11:40:40 +0000 (11:40 +0000)
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
modules/gui/skins2/commands/async_queue.hpp
modules/gui/skins2/commands/cmd_generic.hpp
modules/gui/skins2/commands/cmd_vars.cpp
modules/gui/skins2/commands/cmd_vars.hpp
modules/gui/skins2/controls/ctrl_tree.cpp
modules/gui/skins2/src/vlcproc.cpp

index 170cec763386391efb262333fb754b97417dbc02..fa2fc4451845057c4e3ad476623902958786b7d6 100644 (file)
@@ -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;
+            }
         }
     }
 
index e22666b17ea8574b4e703bad451f7530f0a85a5b..d2d4253353bdce78f51d2701854187715ca3490c 100644 (file)
@@ -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();
index 0235043c1a9017caf423bff84bc4e3e285152802..c06efc104a2b869335f872238e1a1fd0e5f86a29 100644 (file)
@@ -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 ) {}
 };
index b64ede8be17b5648114278306b81a97a5ebf1eb4..a3aa46cf42ab34356627c1bca4727cdb2e328e74 100644 (file)
@@ -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()
 {
index a2445ed0deaa969128a34f7ffef0b90ebe7c67d0..9a30fe11b04d06667b9373327e0d1ad7cc53ff81 100644 (file)
@@ -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;
index c44c888fef4edbf0391643e759a6094fad5af121..c8906267bb282ee675baf5877b41e0425a362430 100644 (file)
@@ -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();
     }
index d86436e01a5a0654d7511f8318cc97bb69e69fad..73bd8b81586fd5f05d86125f2d63c1c51a6df5dc 100644 (file)
@@ -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;
 }