From 5df328424d668a66f387db25b784d0eee1371e47 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 28 Oct 2011 17:11:58 -0400 Subject: [PATCH] Add shuffle/repeat support to treeview --- src/libtomahawk/playlist/treeproxymodel.cpp | 22 ++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/playlist/treeproxymodel.cpp b/src/libtomahawk/playlist/treeproxymodel.cpp index 5dc0e0cfa..c6c7f99cf 100644 --- a/src/libtomahawk/playlist/treeproxymodel.cpp +++ b/src/libtomahawk/playlist/treeproxymodel.cpp @@ -333,10 +333,30 @@ TreeProxyModel::siblingItem( int itemsAway, bool readOnly ) QModelIndex idx = currentIndex(); + 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 ( !idx.isValid() && m_repeatMode == PlaylistInterface::RepeatAll ) + { + if ( itemsAway > 0 ) + { + // reset to first item + idx = index( 0, 0, currentIndex().parent() ); + } + else + { + // reset to last item + idx = index( rowCount( currentIndex().parent() ) - 1, 0, currentIndex().parent() ); + } + } + // Try to find the next available PlaylistItem (with results) if ( idx.isValid() ) do { - idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() ); if ( !idx.isValid() ) break;