[vlc-devel] commit: Qt4: remove b_current and store current PLItem in playlist_model ( Ilkka Ollakka )

git version control git at videolan.org
Sun Aug 16 13:50:55 CEST 2009


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Sat Aug 15 08:53:51 2009 +0300| [3863e4e452d18e52875685a4b2576ae11868a9ff] | committer: Ilkka Ollakka 

Qt4: remove b_current and store current PLItem in playlist_model

Maybe this would actually works better if we store index, but maybe I'll
look it sometime later why it didn't work as I expected.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3863e4e452d18e52875685a4b2576ae11868a9ff
---

 .../gui/qt4/components/playlist/playlist_item.cpp  |    4 +--
 .../gui/qt4/components/playlist/playlist_item.hpp  |    3 +-
 .../gui/qt4/components/playlist/playlist_model.cpp |   27 +++++++++++++++----
 .../gui/qt4/components/playlist/playlist_model.hpp |    3 +-
 4 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/playlist_item.cpp b/modules/gui/qt4/components/playlist/playlist_item.cpp
index 694fcaf..f160328 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.cpp
@@ -54,7 +54,6 @@ void PLItem::init( playlist_item_t *_playlist_item, PLItem *parent, PLModel *m,
     i_id       = _playlist_item->i_id;           /* Playlist item specific id */
     model      = m;               /* PLModel (QAbsmodel) */
     i_type     = -1;              /* Item type - Avoid segfault */
-    b_current  = false;           /* Is the item the current Item or not */
     b_is_node  = _playlist_item->i_children > -1;
     p_input    = _playlist_item->p_input;
     vlc_gc_incref( p_input );
@@ -139,13 +138,12 @@ int PLItem::row() const
 }
 
 /* update the PL Item, get the good names and so on */
-void PLItem::update( playlist_item_t *p_item, bool iscurrent )
+void PLItem::update( playlist_item_t *p_item )
 {
     assert( p_item->p_input == p_input);
 
     /* Useful for the model */
     i_type = p_item->p_input->i_type;
-    b_current = iscurrent;
     b_is_node = p_item->i_children > -1;
 
     i_showflags = parentItem ? parentItem->i_showflags : i_showflags;
diff --git a/modules/gui/qt4/components/playlist/playlist_item.hpp b/modules/gui/qt4/components/playlist/playlist_item.hpp
index 48fd164..c8cb2c6 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.hpp
@@ -59,11 +59,10 @@ public:
 
     PLItem *parent() { return parentItem; };
 
-    void update( playlist_item_t *, bool );
+    void update( playlist_item_t * );
 
 protected:
     QList<PLItem*> children;
-    bool b_current;
     int i_type;
     int i_id;
     int i_showflags;
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index b2afe6b..527d6dd 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -77,6 +77,7 @@ PLModel::PLModel( playlist_t *_p_playlist,  /* THEPL */
     i_cached_id       = -1;
     i_cached_input_id = -1;
     i_popup_item      = i_popup_parent = -1;
+    currentItem       = NULL;
 
     rootItem          = NULL; /* PLItem rootItem, will be set in rebuild( ) */
 
@@ -98,6 +99,18 @@ PLModel::PLModel( playlist_t *_p_playlist,  /* THEPL */
             this, ProcessInputItemUpdate( input_item_t *) );
     CONNECT( THEMIM, inputChanged( input_thread_t * ),
             this, ProcessInputItemUpdate( input_thread_t* ) );
+    PL_LOCK;
+    playlist_item_t *p_item;
+    /* Check if there's allready some item playing when playlist
+     * model is created, if so, tell model that it's currentone
+     */
+    if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
+    {
+        currentItem = FindByInput( rootItem,
+                                           p_item->p_input->i_id );
+        emit currentChanged( index( currentItem, 0 ) );
+    }
+    PL_UNLOCK;
 }
 
 PLModel::~PLModel()
@@ -370,7 +383,7 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
     }
     else if( role == Qt::FontRole )
     {
-        if( item->b_current == true )
+        if( isCurrent( index ) )
         {
             QFont f; f.setBold( true ); return QVariant( f );
         }
@@ -378,10 +391,11 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
     return QVariant();
 }
 
-bool PLModel::isCurrent( const QModelIndex &index )
+bool PLModel::isCurrent( const QModelIndex &index ) const
 {
     assert( index.isValid() );
-    return static_cast<PLItem*>(index.internalPointer())->b_current;
+    if( !currentItem ) return false;
+    return static_cast<PLItem*>(index.internalPointer())->p_input == currentItem->p_input;
 }
 
 int PLModel::itemId( const QModelIndex &index ) const
@@ -646,6 +660,7 @@ void PLModel::ProcessInputItemUpdate( input_thread_t *p_input )
     if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
     {
         PLItem *item = FindByInput( rootItem, input_GetItem( p_input )->i_id );
+        currentItem = item;
         emit currentChanged( index( item, 0 ) );
     }
 }
@@ -730,7 +745,7 @@ void PLModel::rebuild( playlist_item_t *p_root )
     UpdateNodeChildren( rootItem );
     if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
     {
-        PLItem *currentItem = FindByInput( rootItem,
+        currentItem = FindByInput( rootItem,
                                            p_item->p_input->i_id );
         if( currentItem )
         {
@@ -782,9 +797,9 @@ void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
     if( !force && i_depth == DEPTH_SEL && p_item->p_parent &&
                                  p_item->p_parent->i_id != rootItem->i_id )
         return;
-    item->update( p_item, p_item == playlist_CurrentPlayingItem( p_playlist ) );
+    item->update( p_item );
     if( signal )
-        emit dataChanged( index( item, 0 ) , index( item, 1 ) );
+        emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
 }
 
 /************************* Actions ******************************/
diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp
index 124e198..41fb688 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.hpp
@@ -98,7 +98,7 @@ public:
     QModelIndex index( int r, int c, const QModelIndex &parent ) const;
     QModelIndex index( PLItem *, int c ) const;
     int itemId( const QModelIndex &index ) const;
-    bool isCurrent( const QModelIndex &index );
+    bool isCurrent( const QModelIndex &index ) const;
     QModelIndex parent( const QModelIndex &index ) const;
     int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
     int rowCount( const QModelIndex &parent = QModelIndex() ) const;
@@ -132,6 +132,7 @@ private:
     void customEvent( QEvent * );
 
     PLItem *rootItem;
+    PLItem *currentItem;
 
     playlist_t *p_playlist;
     intf_thread_t *p_intf;




More information about the vlc-devel mailing list