[vlc-commits] Qt: stick to playlist item IDs, do not use input item IDs

Rémi Denis-Courmont git at videolan.org
Tue Nov 15 21:04:44 CET 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Nov 15 20:43:57 2016 +0200| [bfc41c3592e0af8b52f22353269aa2776a54649d] | committer: Rémi Denis-Courmont

Qt: stick to playlist item IDs, do not use input item IDs

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

 modules/gui/qt/components/playlist/playlist.cpp    |  2 +-
 .../gui/qt/components/playlist/playlist_item.cpp   | 13 +---
 .../gui/qt/components/playlist/playlist_item.hpp   | 10 +--
 .../gui/qt/components/playlist/playlist_model.cpp  | 80 +++++++++++-----------
 .../gui/qt/components/playlist/playlist_model.hpp  |  5 +-
 .../gui/qt/components/playlist/standardpanel.cpp   |  6 +-
 modules/gui/qt/components/playlist/vlc_model.cpp   |  4 +-
 modules/gui/qt/components/playlist/vlc_model.hpp   |  6 +-
 8 files changed, 54 insertions(+), 72 deletions(-)

diff --git a/modules/gui/qt/components/playlist/playlist.cpp b/modules/gui/qt/components/playlist/playlist.cpp
index cc89300..f2ff4f2 100644
--- a/modules/gui/qt/components/playlist/playlist.cpp
+++ b/modules/gui/qt/components/playlist/playlist.cpp
@@ -267,7 +267,7 @@ void LocationBar::setIndex( const QModelIndex &index )
         actions.append( action );
         CONNECT( btn, clicked(), action, trigger() );
 
-        mapper->setMapping( action, model->itemId( i, PLAYLIST_ID ) );
+        mapper->setMapping( action, model->itemId( i ) );
         CONNECT( action, triggered(), mapper, map() );
 
         first = false;
diff --git a/modules/gui/qt/components/playlist/playlist_item.cpp b/modules/gui/qt/components/playlist/playlist_item.cpp
index 8ca3316..a38cf93 100644
--- a/modules/gui/qt/components/playlist/playlist_item.cpp
+++ b/modules/gui/qt/components/playlist/playlist_item.cpp
@@ -85,18 +85,9 @@ PLItem::~PLItem()
     children.clear();
 }
 
-int PLItem::id( int type ) const
+int PLItem::id() const
 {
-    switch( type )
-    {
-    case INPUTITEM_ID:
-        return p_input->i_id;
-    case PLAYLIST_ID:
-        return i_playlist_id;
-    default:
-        vlc_assert_unreachable();
-        return -1;
-    }
+    return i_playlist_id;
 }
 
 void PLItem::takeChildAt( int index )
diff --git a/modules/gui/qt/components/playlist/playlist_item.hpp b/modules/gui/qt/components/playlist/playlist_item.hpp
index 71eef78..636bb57 100644
--- a/modules/gui/qt/components/playlist/playlist_item.hpp
+++ b/modules/gui/qt/components/playlist/playlist_item.hpp
@@ -34,12 +34,6 @@
 #include <QString>
 #include <QUrl>
 
-enum
-{
-    INPUTITEM_ID = 1,
-    PLAYLIST_ID,
-};
-
 class AbstractPLItem
 {
     friend class PLItem; /* super ugly glue stuff */
@@ -52,7 +46,7 @@ public:
     virtual ~AbstractPLItem() {}
 
 protected:
-    virtual int id( int type ) const = 0;
+    virtual int id( ) const = 0;
     int childCount() const { return children.count(); }
     int indexOf( AbstractPLItem *item ) const { return children.indexOf( item ); };
     int lastIndexOf( AbstractPLItem *item ) const { return children.lastIndexOf( item ); };
@@ -82,7 +76,7 @@ public:
 
 private:
     /* AbstractPLItem */
-    int id( int type ) const Q_DECL_OVERRIDE;
+    int id() const Q_DECL_OVERRIDE;
     input_item_t *inputItem() Q_DECL_OVERRIDE { return p_input; }
     AbstractPLItem *child( int id ) const Q_DECL_OVERRIDE { return children.value( id ); };
     virtual QUrl getURI() const Q_DECL_OVERRIDE;
diff --git a/modules/gui/qt/components/playlist/playlist_model.cpp b/modules/gui/qt/components/playlist/playlist_model.cpp
index 6447291..29f439f 100644
--- a/modules/gui/qt/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt/components/playlist/playlist_model.cpp
@@ -220,7 +220,7 @@ void PLModel::dropMove( const PlMimeData * plMimeData, PLItem *target, int row )
             playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
             if( !p_item ) continue;
 
-            PLItem *item = findByInputId( rootItem, p_input->i_id );
+            PLItem *item = findByInput( rootItem, p_input );
             if( !item ) continue;
 
             /* Better not try to move a node into itself.
@@ -282,7 +282,7 @@ void PLModel::activateItem( playlist_item_t *p_item )
     playlist_item_t *p_parent = p_item;
     while( p_parent )
     {
-        if( p_parent->i_id == rootItem->id( PLAYLIST_ID ) ) break;
+        if( p_parent->i_id == rootItem->id() ) break;
         p_parent = p_parent->p_parent;
     }
     if( p_parent )
@@ -414,7 +414,7 @@ bool PLModel::isLeaf( const QModelIndex &index ) const
     vlc_playlist_locker pl_lock ( THEPL );
 
     playlist_item_t *plItem =
-        playlist_ItemGetById( p_playlist, itemId( index, PLAYLIST_ID ) );
+        playlist_ItemGetById( p_playlist, itemId( index ) );
 
     if( plItem )
         b_isLeaf = plItem->i_children == -1;
@@ -446,19 +446,19 @@ QModelIndex PLModel::indexByPLID( const int i_plid, const int c ) const
     return index( findByPLId( rootItem, i_plid ), c );
 }
 
-QModelIndex PLModel::indexByInputItemID( const int i_inputitem_id, const int c ) const
+QModelIndex PLModel::indexByInputItem( const input_item_t *item, const int c ) const
 {
-    return index( findByInputId( rootItem, i_inputitem_id ), c );
+    return index( findByInput( rootItem, item ), c );
 }
 
 QModelIndex PLModel::rootIndex() const
 {
-    return index( findByPLId( rootItem, rootItem->id( PLAYLIST_ID ) ), 0 );
+    return index( findByPLId( rootItem, rootItem->id() ), 0 );
 }
 
 bool PLModel::isTree() const
 {
-    return ( ( rootItem && rootItem->id( PLAYLIST_ID ) != p_playlist->p_playing->i_id )
+    return ( ( rootItem && rootItem->id() != p_playlist->p_playing->i_id )
              || var_InheritBool( p_intf, "playlist-tree" ) );
 }
 
@@ -477,7 +477,7 @@ QModelIndex PLModel::currentIndex() const
 {
     input_thread_t *p_input_thread = THEMIM->getInput();
     if( !p_input_thread ) return QModelIndex();
-    PLItem *item = findByInputId( rootItem, input_GetItem( p_input_thread )->i_id );
+    PLItem *item = findByInput( rootItem, input_GetItem( p_input_thread ) );
     return index( item, 0 );
 }
 
@@ -509,40 +509,23 @@ int PLModel::rowCount( const QModelIndex &parent ) const
 }
 
 /************************* Lookups *****************************/
-PLItem *PLModel::findByPLId( PLItem *root, int i_plitemid ) const
-{
-    return findInner( root, i_plitemid, false );
-}
-
-PLItem *PLModel::findByInputId( PLItem *root, int i_input_itemid ) const
-{
-    PLItem *result = findInner( root, i_input_itemid, true );
-    return result;
-}
-
-PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_isinputid ) const
+PLItem *PLModel::findByPLId( PLItem *root, int i_id ) const
 {
     if( !root ) return NULL;
 
-    if( !b_isinputid && root->id( PLAYLIST_ID ) == i_id )
-        return root;
-
-    else if( b_isinputid && root->id( INPUTITEM_ID ) == i_id )
+    if( root->id() == i_id )
         return root;
 
     QList<AbstractPLItem *>::iterator it = root->children.begin();
     while ( it != root->children.end() )
     {
         PLItem *item = static_cast<PLItem *>(*it);
-        if( !b_isinputid && item->id( PLAYLIST_ID ) == i_id )
-            return item;
-
-        else if( b_isinputid && item->id( INPUTITEM_ID ) == i_id )
+        if( item->id() == i_id )
             return item;
 
         if( item->childCount() )
         {
-            PLItem *childFound = findInner( item, i_id, b_isinputid );
+            PLItem *childFound = findByPLId( item, i_id );
             if( childFound )
                 return childFound;
         }
@@ -551,6 +534,21 @@ PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_isinputid ) const
     return NULL;
 }
 
+PLItem *PLModel::findByInput( PLItem *root, const input_item_t *input ) const
+{
+    int i_id;
+    {
+        playlist_item_t *item;
+
+        vlc_playlist_locker pl_lock ( THEPL );
+        item = playlist_ItemGetByInput( THEPL, input );
+        if( item == NULL )
+            return NULL;
+        i_id = item->i_id;
+    }
+    return findByPLId( root, i_id );
+}
+
 PLModel::pl_nodetype PLModel::getPLRootType() const
 {
     vlc_playlist_locker pl_lock ( THEPL );
@@ -559,11 +557,11 @@ PLModel::pl_nodetype PLModel::getPLRootType() const
     AbstractPLItem *plitem = rootItem;
     while( plitem->parent() )plitem = plitem->parent();
 
-    if( plitem->id( PLAYLIST_ID ) == p_playlist->p_playing->i_id )
+    if( plitem->id() == p_playlist->p_playing->i_id )
         return ROOTTYPE_CURRENT_PLAYING;
 
     if( p_playlist->p_media_library &&
-        plitem->id( PLAYLIST_ID ) == p_playlist->p_media_library->i_id )
+        plitem->id() == p_playlist->p_media_library->i_id )
         return ROOTTYPE_MEDIA_LIBRARY;
 
     return ROOTTYPE_OTHER;
@@ -582,7 +580,7 @@ void PLModel::processInputItemUpdate( )
     input_thread_t *p_input = THEMIM->getInput();
     if( !p_input ) return;
 
-    PLItem *item = findByInputId( rootItem, input_GetItem( p_input )->i_id );
+    PLItem *item = findByInput( rootItem, input_GetItem( p_input ) );
     if( item ) emit currentIndexChanged( index( item, 0 ) );
 
     processInputItemUpdate( input_GetItem( p_input ) );
@@ -591,7 +589,7 @@ void PLModel::processInputItemUpdate( )
 void PLModel::processInputItemUpdate( input_item_t *p_item )
 {
     if( !p_item ) return;
-    PLItem *item = findByInputId( rootItem, p_item->i_id );
+    PLItem *item = findByInput( rootItem, p_item );
     if( item )
         updateTreeItem( item );
 }
@@ -614,7 +612,7 @@ void PLModel::processItemAppend( int i_pl_itemid, int i_pl_itemidparent )
 
     /* Search for an already matching children */
     foreach( AbstractPLItem *existing, nodeParentItem->children )
-        if( existing->id( PLAYLIST_ID ) == i_pl_itemid ) return;
+        if( existing->id() == i_pl_itemid ) return;
 
     /* Find the child */
     {
@@ -713,7 +711,7 @@ void PLModel::removeItem( PLItem *item )
 /* This function must be entered WITH the playlist lock */
 void PLModel::updateChildren( PLItem *root )
 {
-    playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->id( PLAYLIST_ID ) );
+    playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->id() );
     updateChildren( p_node, root );
 }
 
@@ -781,7 +779,7 @@ void PLModel::recurseDelete( QList<AbstractPLItem*> children, QModelIndexList *f
 /******* Volume III: Sorting and searching ********/
 void PLModel::sort( const int column, Qt::SortOrder order )
 {
-    sort( QModelIndex(), indexByPLID( rootItem->id( PLAYLIST_ID ), 0 ) , column, order );
+    sort( QModelIndex(), indexByPLID( rootItem->id(), 0 ) , column, order );
 }
 
 void PLModel::sort( QModelIndex caller, QModelIndex rootIndex, const int column, Qt::SortOrder order )
@@ -799,7 +797,7 @@ void PLModel::sort( QModelIndex caller, QModelIndex rootIndex, const int column,
         ? static_cast<AbstractPLItem*>( caller.internalPointer() )->inputItem()
         : NULL;
 
-    int i_root_id = item->id( PLAYLIST_ID );
+    int i_root_id = item->id();
 
     QModelIndex qIndex = index( item, 0 );
     int count = item->childCount();
@@ -834,7 +832,7 @@ void PLModel::sort( QModelIndex caller, QModelIndex rootIndex, const int column,
     /* if we have popup item, try to make sure that you keep that item visible */
     if( p_caller_item )
     {
-        QModelIndex idx = indexByInputItemID( p_caller_item->i_id, 0 );
+        QModelIndex idx = indexByInputItem( p_caller_item, 0 );
 
         emit currentIndexChanged( idx );
     }
@@ -851,7 +849,7 @@ void PLModel::filter( const QString& search_text, const QModelIndex & idx, bool
         vlc_playlist_locker pl_lock ( THEPL );
 
         playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
-                                            itemId( idx, PLAYLIST_ID ) );
+                                                        itemId( idx ) );
         assert( p_root );
         playlist_LiveSearchUpdate( p_playlist, p_root, qtu( search_text ),
                                    b_recursive );
@@ -896,7 +894,7 @@ void PLModel::createNode( QModelIndex index, QString name )
 
     index = index.parent();
     if ( !index.isValid() ) index = rootIndex();
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, itemId( index, PLAYLIST_ID ) );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, itemId( index ) );
     if( p_item )
         playlist_NodeCreate( p_playlist, qtu( name ), p_item, PLAYLIST_END, 0, NULL );
 }
@@ -947,7 +945,7 @@ bool PLModel::action( QAction *action, const QModelIndexList &indexes )
 
         foreach( const QModelIndex &currentIndex, indexes )
         {
-            playlist_item_t *p_item = playlist_ItemGetById( THEPL, itemId( currentIndex, PLAYLIST_ID ) );
+            playlist_item_t *p_item = playlist_ItemGetById( THEPL, itemId( currentIndex ) );
             if( !p_item ) continue;
 
             playlist_NodeAddCopy( THEPL, p_item,
diff --git a/modules/gui/qt/components/playlist/playlist_model.hpp b/modules/gui/qt/components/playlist/playlist_model.hpp
index 58b4005..57441ff 100644
--- a/modules/gui/qt/components/playlist/playlist_model.hpp
+++ b/modules/gui/qt/components/playlist/playlist_model.hpp
@@ -101,7 +101,7 @@ public:
     virtual void filter( const QString& search_text, const QModelIndex & root, bool b_recursive ) Q_DECL_OVERRIDE;
     virtual QModelIndex currentIndex() const Q_DECL_OVERRIDE;
     virtual QModelIndex indexByPLID( const int i_plid, const int c ) const Q_DECL_OVERRIDE;
-    virtual QModelIndex indexByInputItemID( const int i_inputitem_id, const int c ) const Q_DECL_OVERRIDE;
+    virtual QModelIndex indexByInputItem( const input_item_t *, const int c ) const Q_DECL_OVERRIDE;
     virtual bool isTree() const Q_DECL_OVERRIDE;
     virtual bool canEdit() const Q_DECL_OVERRIDE;
     virtual bool action( QAction *action, const QModelIndexList &indexes ) Q_DECL_OVERRIDE;
@@ -142,8 +142,7 @@ private:
 
     /* Lookups */
     PLItem *findByPLId( PLItem *, int i_plitemid ) const;
-    PLItem *findByInputId( PLItem *, int i_input_itemid ) const;
-    PLItem *findInner(PLItem *, int i_id, bool b_isinputid ) const;
+    PLItem *findByInput( PLItem *, const input_item_t * ) const;
     enum pl_nodetype
     {
         ROOTTYPE_CURRENT_PLAYING,
diff --git a/modules/gui/qt/components/playlist/standardpanel.cpp b/modules/gui/qt/components/playlist/standardpanel.cpp
index 4f04823..3a586c3 100644
--- a/modules/gui/qt/components/playlist/standardpanel.cpp
+++ b/modules/gui/qt/components/playlist/standardpanel.cpp
@@ -144,7 +144,7 @@ void StandardPLPanel::gotoPlayingItem()
 void StandardPLPanel::handleExpansion( const QModelIndex& index )
 {
     assert( currentView );
-    if( currentRootIndexPLId != -1 && currentRootIndexPLId != model->itemId( index.parent(), PLAYLIST_ID ) )
+    if( currentRootIndexPLId != -1 && currentRootIndexPLId != model->itemId( index.parent() ) )
         browseInto( index.parent() );
     currentView->scrollTo( index );
 }
@@ -509,7 +509,7 @@ void StandardPLPanel::browseInto( const QModelIndex &index )
             currentView->scrollTo( newIndex );
 
         /* Store new rootindexid*/
-        currentRootIndexPLId = model->itemId( index, PLAYLIST_ID );
+        currentRootIndexPLId = model->itemId( index );
 
         model->ensureArtRequested( index );
     }
@@ -802,7 +802,7 @@ void StandardPLPanel::activate( const QModelIndex &index )
         else
         {
             playlist_Lock( THEPL );
-            playlist_item_t *p_item = playlist_ItemGetById( THEPL, model->itemId( index, PLAYLIST_ID ) );
+            playlist_item_t *p_item = playlist_ItemGetById( THEPL, model->itemId( index ) );
             if ( p_item )
             {
                 p_item->i_flags |= PLAYLIST_SUBITEM_STOP_FLAG;
diff --git a/modules/gui/qt/components/playlist/vlc_model.cpp b/modules/gui/qt/components/playlist/vlc_model.cpp
index 66886bf..7d48f73 100644
--- a/modules/gui/qt/components/playlist/vlc_model.cpp
+++ b/modules/gui/qt/components/playlist/vlc_model.cpp
@@ -145,11 +145,11 @@ int VLCModel::metaToColumn( int _meta )
     return column;
 }
 
-int VLCModel::itemId( const QModelIndex &index, int type ) const
+int VLCModel::itemId( const QModelIndex &index ) const
 {
     AbstractPLItem *item = getItem( index );
     if ( !item ) return -1;
-    return item->id( type );
+    return item->id();
 }
 
 AbstractPLItem *VLCModel::getItem( const QModelIndex &index ) const
diff --git a/modules/gui/qt/components/playlist/vlc_model.hpp b/modules/gui/qt/components/playlist/vlc_model.hpp
index b6f3f85..d0d3a28 100644
--- a/modules/gui/qt/components/playlist/vlc_model.hpp
+++ b/modules/gui/qt/components/playlist/vlc_model.hpp
@@ -71,8 +71,8 @@ public:
     virtual void filter( const QString& search_text, const QModelIndex & root, bool b_recursive ) = 0;
     virtual QModelIndex currentIndex() const = 0;
     virtual QModelIndex indexByPLID( const int i_plid, const int c ) const = 0;
-    virtual QModelIndex indexByInputItemID( const int i_inputitem_id, const int c ) const = 0;
-    virtual int itemId( const QModelIndex &, int type ) const = 0;
+    virtual QModelIndex indexByInputItem( const input_item_t *, const int c ) const = 0;
+    virtual int itemId( const QModelIndex & ) const = 0;
     virtual bool isTree() const = 0;
     virtual bool canEdit() const = 0;
     virtual QString getURI( const QModelIndex &index ) const = 0;
@@ -129,7 +129,7 @@ public:
     QVariant headerData( int, Qt::Orientation, int ) const Q_DECL_OVERRIDE;
 
     /*** VLCModelSubInterface subclassing ***/
-    int itemId( const QModelIndex &, int type ) const Q_DECL_OVERRIDE;
+    int itemId( const QModelIndex & ) const Q_DECL_OVERRIDE;
     QString getURI( const QModelIndex &index ) const Q_DECL_OVERRIDE;
     input_item_t *getInputItem( const QModelIndex & ) const Q_DECL_OVERRIDE;
     QString getTitle( const QModelIndex &index ) const Q_DECL_OVERRIDE;



More information about the vlc-commits mailing list