]> git.sesse.net Git - vlc/commitdiff
* all: don't rebuild the whole playtree when an item is updated
authorCyril Deguet <asmax@videolan.org>
Sun, 23 Oct 2005 17:42:16 +0000 (17:42 +0000)
committerCyril Deguet <asmax@videolan.org>
Sun, 23 Oct 2005 17:42:16 +0000 (17:42 +0000)
 (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
modules/gui/skins2/commands/cmd_vars.hpp
modules/gui/skins2/src/vlcproc.cpp
modules/gui/skins2/utils/var_tree.cpp
modules/gui/skins2/utils/var_tree.hpp
modules/gui/skins2/vars/playtree.cpp
modules/gui/skins2/vars/playtree.hpp

index f859a1a59423893a53f2efc8c67b5f476b39642f..9cd849a71c9bbb7abcf395f8e30005df25d59e67 100644 (file)
@@ -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
index ebb142958df8d2abe4e89c6f6e592456cf5f423e..fbeb07276e635409606f5e815423e2ad58276ffc 100644 (file)
@@ -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
index 225fb2c1b3a872c040de149285f3ccc56487ec56..8d532e5a94ca7320b18d22480527c1c19a194b68 100644 (file)
@@ -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 ) );
 
index 12b7f707a6dbe642fe4c1a144a48cc686a3846b7..2550b659179050e0c77d2b91453c6ebdd6bf8cc9 100644 (file)
 
 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();
+}
+
index 39a1835842983bbf38994f2f6a061ef3a9846808..101d3188aa440ea537332fe3c591c5fdf0e2ca55 100644 (file)
 class VarTree: public Variable, public Subject<VarTree>
 {
     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<VarTree>
         /// 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<VarTree>
         /// 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<VarTree> m_children;
 
index b1af19d001636ab71f822ad272f9378863471698..b5dfd75bd19b54d1cb734ca0c430494a28fb0571 100644 (file)
@@ -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 );
 }
+
index 5c5836c97ff6c867ca43d83f5372075890806ed1..b7a942deca27ba30e1422e44fccad6d472668cee 100644 (file)
@@ -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;