[vlc-devel] commit: Qt: PLModel: simplify and fix current item update (Jakob Leben )
git version control
git at videolan.org
Tue Feb 9 04:58:25 CET 2010
vlc | branch: master | Jakob Leben <jleben at videolan.org> | Tue Feb 9 04:56:14 2010 +0100| [9f9dfeb81f5fade4d1e9b3f5585710766ccdb4e7] | committer: Jakob Leben
Qt: PLModel: simplify and fix current item update
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9f9dfeb81f5fade4d1e9b3f5585710766ccdb4e7
---
.../gui/qt4/components/playlist/playlist_model.cpp | 42 ++++++--------------
.../gui/qt4/components/playlist/playlist_model.hpp | 3 +-
2 files changed, 13 insertions(+), 32 deletions(-)
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index f561910..d2fba6f 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -65,7 +65,6 @@ 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( ) */
@@ -349,8 +348,9 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
bool PLModel::isCurrent( const QModelIndex &index ) const
{
- if( !currentItem ) return false;
- return getItem( index )->p_input == currentItem->p_input;
+ input_thread_t *p_input_thread = THEMIM->getInput();
+ if( !p_input_thread ) return false;
+ return getItem( index )->p_input == input_GetItem( p_input_thread );
}
int PLModel::itemId( const QModelIndex &index ) const
@@ -399,6 +399,14 @@ QModelIndex PLModel::index( PLItem *item, int column ) const
return QModelIndex();
}
+QModelIndex PLModel::currentIndex()
+{
+ input_thread_t *p_input_thread = THEMIM->getInput();
+ if( !p_input_thread ) return QModelIndex();
+ PLItem *item = findByInput( rootItem, input_GetItem( p_input_thread )->i_id );
+ return index( item, 0 );
+}
+
QModelIndex PLModel::parent( const QModelIndex &index ) const
{
if( !index.isValid() ) return QModelIndex();
@@ -577,12 +585,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 ) );
- }
- else
- {
- currentItem = NULL;
+ if( item ) emit currentChanged( index( item, 0 ) );
}
processInputItemUpdate( input_GetItem( p_input ) );
}
@@ -624,18 +627,10 @@ void PLModel::processItemAppend( int i_item, int i_parent )
newItem = new PLItem( p_item, nodeItem );
PL_UNLOCK;
- currentInputThread = THEMIM->getInput();
- if( currentInputThread &&
- newItem->p_input == input_GetItem( currentInputThread ) )
- currentItem = newItem;
-
beginInsertRows( index( nodeItem, 0 ), pos, pos );
nodeItem->insertChild( newItem, pos );
endInsertRows();
- if( currentItem == newItem )
- emit currentChanged( index( newItem, 0 ) );
-
return;
end:
PL_UNLOCK;
@@ -705,12 +700,6 @@ void PLModel::removeItem( PLItem *item )
if( item->i_id == i_cached_id ) i_cached_id = -1;
i_cached_input_id = -1;
- if( currentItem == item || rootItem == item)
- {
- currentItem = NULL;
- emit currentChanged( QModelIndex() );
- }
-
if(item == rootItem)
rootItem = NULL;
@@ -729,24 +718,17 @@ void PLModel::removeItem( PLItem *item )
void PLModel::updateChildren( PLItem *root )
{
playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
- currentItem = NULL;
updateChildren( p_node, root );
- emit currentChanged( index( currentItem, 0 ) );
}
/* This function must be entered WITH the playlist lock */
void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
{
- playlist_item_t *p_item = playlist_CurrentPlayingItem(p_playlist);
for( int i = 0; i < p_node->i_children ; i++ )
{
if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
PLItem *newItem = new PLItem( p_node->pp_children[i], root );
root->appendChild( newItem );
- if( p_item && newItem->p_input == p_item->p_input )
- {
- currentItem = newItem;
- }
if( p_node->pp_children[i]->i_children != -1 )
updateChildren( p_node->pp_children[i], newItem );
}
diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp
index e1d87b4..9e36847 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.hpp
@@ -87,7 +87,7 @@ public:
QStringList selectedURIs();
QModelIndex index( PLItem *, int c ) const;
QModelIndex index( int i_id, int c );
- QModelIndex currentIndex( ) { return index( currentItem, 0 ); };
+ QModelIndex currentIndex();
bool isCurrent( const QModelIndex &index ) const;
int itemId( const QModelIndex &index ) const;
@@ -111,7 +111,6 @@ private:
/* General */
PLItem *rootItem;
- PLItem *currentItem;
playlist_t *p_playlist;
intf_thread_t *p_intf;
More information about the vlc-devel
mailing list