From 6ec8f127c0c5a5c735f6542e196fd7786939c5cc Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 8 Nov 2011 10:41:30 +0100 Subject: [PATCH] * Fixed freezing when filtering out the current item in a tree-view and trying to advance to the next track. --- src/libtomahawk/playlist/trackproxymodel.cpp | 12 +++--------- src/libtomahawk/playlist/treeproxymodel.cpp | 17 +++++++++-------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/libtomahawk/playlist/trackproxymodel.cpp b/src/libtomahawk/playlist/trackproxymodel.cpp index cfbea42a7..3c92699e9 100644 --- a/src/libtomahawk/playlist/trackproxymodel.cpp +++ b/src/libtomahawk/playlist/trackproxymodel.cpp @@ -110,7 +110,7 @@ TrackProxyModel::siblingItem( int itemsAway, bool readOnly ) qDebug() << Q_FUNC_INFO; QModelIndex idx = index( 0, 0 ); - if( rowCount() ) + if ( rowCount() ) { if ( m_shuffled ) { @@ -123,12 +123,7 @@ TrackProxyModel::siblingItem( int itemsAway, bool readOnly ) idx = currentIndex(); // random mode is disabled - if ( m_repeatMode == PlaylistInterface::RepeatOne ) - { - // repeat one track - idx = index( idx.row(), 0 ); - } - else + if ( m_repeatMode != PlaylistInterface::RepeatOne ) { // keep progressing through the playlist normally idx = index( idx.row() + itemsAway, 0 ); @@ -152,7 +147,7 @@ TrackProxyModel::siblingItem( int itemsAway, bool readOnly ) } // Try to find the next available PlaylistItem (with results) - if ( idx.isValid() ) do + while ( idx.isValid() ) { TrackModelItem* item = itemFromIndex( mapToSource( idx ) ); if ( item && item->query()->playable() ) @@ -165,7 +160,6 @@ TrackProxyModel::siblingItem( int itemsAway, bool readOnly ) idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0 ); } - while ( idx.isValid() ); if ( !readOnly ) setCurrentIndex( QModelIndex() ); diff --git a/src/libtomahawk/playlist/treeproxymodel.cpp b/src/libtomahawk/playlist/treeproxymodel.cpp index 206bbd1b7..64f4741eb 100644 --- a/src/libtomahawk/playlist/treeproxymodel.cpp +++ b/src/libtomahawk/playlist/treeproxymodel.cpp @@ -334,11 +334,14 @@ TreeProxyModel::siblingItem( int itemsAway, bool readOnly ) return Tomahawk::result_ptr(); if ( m_shuffled ) + { idx = index( qrand() % rowCount( idx.parent() ), 0, idx.parent() ); - else if ( m_repeatMode == PlaylistInterface::RepeatOne ) - idx = index( idx.row(), 0, idx.parent() ); + } else - idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() ); + { + if ( m_repeatMode != PlaylistInterface::RepeatOne ) + idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() ); + } if ( !idx.isValid() && m_repeatMode == PlaylistInterface::RepeatAll ) { @@ -355,11 +358,8 @@ TreeProxyModel::siblingItem( int itemsAway, bool readOnly ) } // Try to find the next available PlaylistItem (with results) - if ( idx.isValid() ) do + while ( idx.isValid() ) { - if ( !idx.isValid() ) - break; - TreeModelItem* item = itemFromIndex( mapToSource( idx ) ); if ( item && !item->result().isNull() && item->result()->isOnline() ) { @@ -368,8 +368,9 @@ TreeProxyModel::siblingItem( int itemsAway, bool readOnly ) setCurrentIndex( idx ); return item->result(); } + + idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() ); } - while ( idx.isValid() ); if ( !readOnly ) setCurrentIndex( QModelIndex() );