mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 08:04:25 +02:00
* When shuffle is enabled and we want to play the previous track, actually go back in shuffle history.
This commit is contained in:
@@ -63,10 +63,10 @@ QList< Tomahawk::query_ptr >
|
|||||||
PlayableProxyModelPlaylistInterface::tracks()
|
PlayableProxyModelPlaylistInterface::tracks()
|
||||||
{
|
{
|
||||||
if ( m_proxyModel.isNull() )
|
if ( m_proxyModel.isNull() )
|
||||||
return QList< Tomahawk::query_ptr >();
|
return QList< query_ptr >();
|
||||||
|
|
||||||
PlayableProxyModel* proxyModel = m_proxyModel.data();
|
PlayableProxyModel* proxyModel = m_proxyModel.data();
|
||||||
QList<Tomahawk::query_ptr> queries;
|
QList< query_ptr > queries;
|
||||||
|
|
||||||
for ( int i = 0; i < proxyModel->rowCount( QModelIndex() ); i++ )
|
for ( int i = 0; i < proxyModel->rowCount( QModelIndex() ); i++ )
|
||||||
{
|
{
|
||||||
@@ -99,7 +99,7 @@ PlayableProxyModelPlaylistInterface::siblingItem( int itemsAway, bool readOnly )
|
|||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_shuffled << itemsAway << readOnly;
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_shuffled << itemsAway << readOnly;
|
||||||
|
|
||||||
if ( m_proxyModel.isNull() )
|
if ( m_proxyModel.isNull() )
|
||||||
return Tomahawk::result_ptr();
|
return result_ptr();
|
||||||
|
|
||||||
PlayableProxyModel* proxyModel = m_proxyModel.data();
|
PlayableProxyModel* proxyModel = m_proxyModel.data();
|
||||||
|
|
||||||
@@ -113,36 +113,50 @@ PlayableProxyModelPlaylistInterface::siblingItem( int itemsAway, bool readOnly )
|
|||||||
{
|
{
|
||||||
if ( m_shuffled )
|
if ( m_shuffled )
|
||||||
{
|
{
|
||||||
// random mode is enabled
|
if ( itemsAway < 0 )
|
||||||
if ( m_shuffleCache.isValid() )
|
|
||||||
{
|
{
|
||||||
idx = m_shuffleCache;
|
if ( m_shuffleHistory.count() > 1 )
|
||||||
|
{
|
||||||
|
m_shuffleHistory.removeLast();
|
||||||
|
if ( proxyModel->itemFromQuery( m_shuffleHistory.last() ) )
|
||||||
|
idx = proxyModel->mapFromSource( proxyModel->itemFromQuery( m_shuffleHistory.takeLast() )->index );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return result_ptr();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int safetyCounter = 0;
|
// random mode is enabled
|
||||||
PlayableItem* item = 0;
|
if ( m_shuffleCache.isValid() )
|
||||||
do
|
|
||||||
{
|
{
|
||||||
safetyCounter++;
|
idx = m_shuffleCache;
|
||||||
idx = proxyModel->index( qrand() % proxyModel->rowCount(), 0 );
|
|
||||||
item = proxyModel->itemFromIndex( proxyModel->mapToSource( idx ) );
|
|
||||||
}
|
|
||||||
while ( safetyCounter < proxyModel->rowCount() &&
|
|
||||||
( !item || !item->query()->playable() || m_shuffleHistory.contains( item->query() ) ) );
|
|
||||||
|
|
||||||
if ( item && item->query()->playable() )
|
|
||||||
{
|
|
||||||
if ( readOnly )
|
|
||||||
{
|
|
||||||
m_shuffleCache = idx;
|
|
||||||
tDebug( LOGVERBOSE ) << "Next shuffled PlaylistItem cached:" << item->query()->toString() << item->query()->results().at( 0 )->url()
|
|
||||||
<< "- after" << safetyCounter << "tries to find a track";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO << "Error finding next shuffled playable track";
|
int safetyCounter = 0;
|
||||||
|
PlayableItem* item = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
safetyCounter++;
|
||||||
|
idx = proxyModel->index( qrand() % proxyModel->rowCount(), 0 );
|
||||||
|
item = proxyModel->itemFromIndex( proxyModel->mapToSource( idx ) );
|
||||||
|
}
|
||||||
|
while ( safetyCounter < proxyModel->rowCount() &&
|
||||||
|
( !item || !item->query()->playable() || m_shuffleHistory.contains( item->query() ) ) );
|
||||||
|
|
||||||
|
if ( item && item->query()->playable() )
|
||||||
|
{
|
||||||
|
if ( readOnly )
|
||||||
|
{
|
||||||
|
m_shuffleCache = idx;
|
||||||
|
tDebug( LOGVERBOSE ) << "Next shuffled PlaylistItem cached:" << item->query()->toString() << item->query()->results().at( 0 )->url()
|
||||||
|
<< "- after" << safetyCounter << "tries to find a track";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO << "Error finding next shuffled playable track";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,7 +210,8 @@ PlayableProxyModelPlaylistInterface::siblingItem( int itemsAway, bool readOnly )
|
|||||||
|
|
||||||
if ( !readOnly )
|
if ( !readOnly )
|
||||||
proxyModel->setCurrentIndex( QModelIndex() );
|
proxyModel->setCurrentIndex( QModelIndex() );
|
||||||
return Tomahawk::result_ptr();
|
|
||||||
|
return result_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -204,7 +219,7 @@ Tomahawk::result_ptr
|
|||||||
PlayableProxyModelPlaylistInterface::currentItem() const
|
PlayableProxyModelPlaylistInterface::currentItem() const
|
||||||
{
|
{
|
||||||
if ( m_proxyModel.isNull() )
|
if ( m_proxyModel.isNull() )
|
||||||
return Tomahawk::result_ptr();
|
return result_ptr();
|
||||||
|
|
||||||
PlayableProxyModel* proxyModel = m_proxyModel.data();
|
PlayableProxyModel* proxyModel = m_proxyModel.data();
|
||||||
|
|
||||||
@@ -212,6 +227,6 @@ PlayableProxyModelPlaylistInterface::currentItem() const
|
|||||||
if ( item && !item->query().isNull() && item->query()->playable() )
|
if ( item && !item->query().isNull() && item->query()->playable() )
|
||||||
return item->query()->results().at( 0 );
|
return item->query()->results().at( 0 );
|
||||||
|
|
||||||
return Tomahawk::result_ptr();
|
return result_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user