1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

TWK-712: Don't emit track number changed when they really haven't, thus masking other errors

This commit is contained in:
Leo Franchi
2012-03-01 22:11:02 -05:00
parent 4889ed6a33
commit f7f2c51d4e
4 changed files with 70 additions and 45 deletions

View File

@@ -54,19 +54,22 @@ DynamicModel::loadPlaylist( const Tomahawk::dynplaylist_ptr& playlist, bool load
{ {
Q_UNUSED( loadEntries ); Q_UNUSED( loadEntries );
if( !m_playlist.isNull() ) { if ( !m_playlist.isNull() )
{
disconnect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( newTrackGenerated( Tomahawk::query_ptr ) ) ); disconnect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( newTrackGenerated( Tomahawk::query_ptr ) ) );
} }
const int oldCount = rowCount( QModelIndex() );
m_playlist = playlist; m_playlist = playlist;
m_deduper.clear(); m_deduper.clear();
if( m_playlist->mode() == OnDemand ) if ( m_playlist->mode() == OnDemand )
setFilterUnresolvable( true ); setFilterUnresolvable( true );
connect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( newTrackGenerated( Tomahawk::query_ptr ) ) ); connect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( newTrackGenerated( Tomahawk::query_ptr ) ) );
PlaylistModel::loadPlaylist( m_playlist, m_playlist->mode() == Static ); PlaylistModel::loadPlaylist( m_playlist, m_playlist->mode() == Static );
if( m_playlist->mode() == OnDemand ) if ( m_playlist->mode() == OnDemand && oldCount != rowCount( QModelIndex() ) )
emit trackCountChanged( rowCount( QModelIndex() ) ); emit trackCountChanged( rowCount( QModelIndex() ) );
} }
@@ -74,7 +77,7 @@ DynamicModel::loadPlaylist( const Tomahawk::dynplaylist_ptr& playlist, bool load
QString QString
DynamicModel::description() const DynamicModel::description() const
{ {
if( !m_playlist.isNull() && !m_playlist->generator().isNull() ) if ( !m_playlist.isNull() && !m_playlist->generator().isNull() )
return m_playlist->generator()->sentenceSummary(); return m_playlist->generator()->sentenceSummary();
else else
return QString(); return QString();
@@ -95,7 +98,8 @@ DynamicModel::startOnDemand()
void void
DynamicModel::newTrackGenerated( const Tomahawk::query_ptr& query ) DynamicModel::newTrackGenerated( const Tomahawk::query_ptr& query )
{ {
if( m_onDemandRunning ) { if ( m_onDemandRunning )
{
bool isDuplicate = false; bool isDuplicate = false;
for ( int i = 0; i < m_deduper.size(); i++ ) for ( int i = 0; i < m_deduper.size(); i++ )
{ {
@@ -125,7 +129,7 @@ void
DynamicModel::stopOnDemand( bool stopPlaying ) DynamicModel::stopOnDemand( bool stopPlaying )
{ {
m_onDemandRunning = false; m_onDemandRunning = false;
if( stopPlaying ) if ( stopPlaying )
AudioEngine::instance()->stop(); AudioEngine::instance()->stop();
disconnect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), this, SLOT( newTrackLoading() ) ); disconnect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), this, SLOT( newTrackLoading() ) );
@@ -135,7 +139,7 @@ DynamicModel::stopOnDemand( bool stopPlaying )
void void
DynamicModel::changeStation() DynamicModel::changeStation()
{ {
if( m_onDemandRunning ) if ( m_onDemandRunning )
m_changeOnNext = true; m_changeOnNext = true;
else // if we're not running, just start else // if we're not running, just start
m_playlist->generator()->startOnDemand(); m_playlist->generator()->startOnDemand();
@@ -171,7 +175,7 @@ DynamicModel::trackResolveFinished( bool success )
{ {
qDebug() << "Got successful resolved track:" << q->track() << q->artist() << m_lastResolvedRow << m_currentAttempts; qDebug() << "Got successful resolved track:" << q->track() << q->artist() << m_lastResolvedRow << m_currentAttempts;
if( m_currentAttempts > 0 ) { if ( m_currentAttempts > 0 ) {
qDebug() << "EMITTING AN ASK FOR COLLAPSE:" << m_lastResolvedRow << m_currentAttempts; qDebug() << "EMITTING AN ASK FOR COLLAPSE:" << m_lastResolvedRow << m_currentAttempts;
emit collapseFromTo( m_lastResolvedRow, m_currentAttempts ); emit collapseFromTo( m_lastResolvedRow, m_currentAttempts );
} }
@@ -188,11 +192,14 @@ void
DynamicModel::newTrackLoading() DynamicModel::newTrackLoading()
{ {
qDebug() << "Got NEW TRACK LOADING signal"; qDebug() << "Got NEW TRACK LOADING signal";
if( m_changeOnNext ) { // reset instead of getting the next one if ( m_changeOnNext )
{ // reset instead of getting the next one
m_lastResolvedRow = rowCount( QModelIndex() ); m_lastResolvedRow = rowCount( QModelIndex() );
m_searchingForNext = true; m_searchingForNext = true;
m_playlist->generator()->startOnDemand(); m_playlist->generator()->startOnDemand();
} else if( m_onDemandRunning && m_currentAttempts == 0 && !m_searchingForNext ) { // if we're in dynamic mode and we're also currently idle }
else if ( m_onDemandRunning && m_currentAttempts == 0 && !m_searchingForNext )
{ // if we're in dynamic mode and we're also currently idle
m_lastResolvedRow = rowCount( QModelIndex() ); m_lastResolvedRow = rowCount( QModelIndex() );
m_searchingForNext = true; m_searchingForNext = true;
qDebug() << "IDLE fetching new track!"; qDebug() << "IDLE fetching new track!";
@@ -204,13 +211,17 @@ DynamicModel::newTrackLoading()
void void
DynamicModel::tracksGenerated( const QList< query_ptr > entries, int limitResolvedTo ) DynamicModel::tracksGenerated( const QList< query_ptr > entries, int limitResolvedTo )
{ {
if( m_filterUnresolvable && m_playlist->mode() == OnDemand ) { // wait till we get them resolved (for previewing stations) if ( m_filterUnresolvable && m_playlist->mode() == OnDemand )
{ // wait till we get them resolved (for previewing stations)
m_limitResolvedTo = limitResolvedTo; m_limitResolvedTo = limitResolvedTo;
filterUnresolved( entries ); filterUnresolved( entries );
} else { }
else
{
addToPlaylist( entries, m_playlist->mode() == OnDemand ); // if ondemand, we're previewing, so clear old addToPlaylist( entries, m_playlist->mode() == OnDemand ); // if ondemand, we're previewing, so clear old
if( m_playlist->mode() == OnDemand ) { if ( m_playlist->mode() == OnDemand )
{
m_lastResolvedRow = rowCount( QModelIndex() ); m_lastResolvedRow = rowCount( QModelIndex() );
} }
} }
@@ -224,9 +235,9 @@ DynamicModel::filterUnresolved( const QList< query_ptr >& entries )
{ {
m_toResolveList = entries; m_toResolveList = entries;
foreach( const query_ptr& q, entries ) { foreach ( const query_ptr& q, entries )
connect( q.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( filteringTrackResolved( bool ) ) ); connect( q.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( filteringTrackResolved( bool ) ) );
}
Pipeline::instance()->resolve( entries, true ); Pipeline::instance()->resolve( entries, true );
} }
@@ -240,7 +251,8 @@ DynamicModel::filteringTrackResolved( bool successful )
// if meantime the user began the station, abort // if meantime the user began the station, abort
qDebug() << "Got filtering resolved finished for track, was it successful?:" << q->track() << q->artist() << successful << q->playable(); qDebug() << "Got filtering resolved finished for track, was it successful?:" << q->track() << q->artist() << successful << q->playable();
if( m_onDemandRunning ) { if ( m_onDemandRunning )
{
m_toResolveList.clear(); m_toResolveList.clear();
m_resolvedList.clear(); m_resolvedList.clear();
@@ -248,8 +260,10 @@ DynamicModel::filteringTrackResolved( bool successful )
} }
query_ptr realptr; query_ptr realptr;
foreach( const query_ptr& qptr, m_toResolveList ) { foreach ( const query_ptr& qptr, m_toResolveList )
if( qptr.data() == q ) { {
if ( qptr.data() == q )
{
realptr = qptr; realptr = qptr;
break; break;
} }
@@ -259,25 +273,30 @@ DynamicModel::filteringTrackResolved( bool successful )
m_toResolveList.removeAll( realptr ); m_toResolveList.removeAll( realptr );
if( realptr->playable() ) { if ( realptr->playable() )
{
m_resolvedList << realptr; m_resolvedList << realptr;
// append and update internal lastResolvedRow // append and update internal lastResolvedRow
addToPlaylist( QList< query_ptr >() << realptr, false ); addToPlaylist( QList< query_ptr >() << realptr, false );
if( m_playlist->mode() == OnDemand ) { if ( m_playlist->mode() == OnDemand )
{
m_lastResolvedRow = rowCount( QModelIndex() ); m_lastResolvedRow = rowCount( QModelIndex() );
} }
if( m_toResolveList.isEmpty() || m_resolvedList.size() == m_limitResolvedTo ) { // done if ( m_toResolveList.isEmpty() || m_resolvedList.size() == m_limitResolvedTo )
{ // done
m_toResolveList.clear(); m_toResolveList.clear();
m_resolvedList.clear(); m_resolvedList.clear();
} }
} else { }
else
{
qDebug() << "Got unsuccessful resolve request for this track" << realptr->track() << realptr->artist(); qDebug() << "Got unsuccessful resolve request for this track" << realptr->track() << realptr->artist();
} }
if( m_toResolveList.isEmpty() && rowCount( QModelIndex() ) == 0 ) // we failed if ( m_toResolveList.isEmpty() && rowCount( QModelIndex() ) == 0 ) // we failed
emit trackGenerationFailure( tr( "Could not find a playable track.\n\nPlease change the filters or try again." ) ); emit trackGenerationFailure( tr( "Could not find a playable track.\n\nPlease change the filters or try again." ) );
} }
@@ -285,16 +304,20 @@ DynamicModel::filteringTrackResolved( bool successful )
void void
DynamicModel::addToPlaylist( const QList< query_ptr >& entries, bool clearFirst ) DynamicModel::addToPlaylist( const QList< query_ptr >& entries, bool clearFirst )
{ {
if( clearFirst ) if ( clearFirst )
clear(); clear();
foreach ( const query_ptr& q, entries ) foreach ( const query_ptr& q, entries )
m_deduper.append( QPair< QString, QString >( q->track(), q->artist() ) ); m_deduper.append( QPair< QString, QString >( q->track(), q->artist() ) );
if( m_playlist->author()->isLocal() && m_playlist->mode() == Static ) { if ( m_playlist->author()->isLocal() && m_playlist->mode() == Static )
{
m_playlist->addEntries( entries, m_playlist->currentrevision() ); m_playlist->addEntries( entries, m_playlist->currentrevision() );
} else { // read-only, so add tracks only in the GUI, not to the playlist itself }
foreach( const query_ptr& query, entries ) { else
{ // read-only, so add tracks only in the GUI, not to the playlist itself
foreach ( const query_ptr& query, entries )
{
append( query ); append( query );
} }
} }
@@ -310,12 +333,15 @@ DynamicModel::remove(const QModelIndex& idx, bool moreToCome)
return; return;
qDebug() << Q_FUNC_INFO << "DYNAMIC MODEL REMOVIN!" << moreToCome << ( idx == index( rowCount( QModelIndex() ) - 1, 0, QModelIndex() ) ); qDebug() << Q_FUNC_INFO << "DYNAMIC MODEL REMOVIN!" << moreToCome << ( idx == index( rowCount( QModelIndex() ) - 1, 0, QModelIndex() ) );
if( m_playlist->mode() == OnDemand ) { if ( m_playlist->mode() == OnDemand )
if( !moreToCome && idx == index( rowCount( QModelIndex() ) - 1, 0, QModelIndex() ) ) { // if the user is manually removing the last one, re-add as we're a station {
if ( !moreToCome && idx == index( rowCount( QModelIndex() ) - 1, 0, QModelIndex() ) )
{ // if the user is manually removing the last one, re-add as we're a station
newTrackLoading(); newTrackLoading();
} }
TrackModel::remove( idx ); TrackModel::remove( idx );
} else }
else
PlaylistModel::remove( idx, moreToCome ); PlaylistModel::remove( idx, moreToCome );
// don't call onPlaylistChanged. // don't call onPlaylistChanged.

View File

@@ -1,6 +1,6 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -32,33 +32,33 @@ namespace Tomahawk
class DynamicModel; class DynamicModel;
class DynamicView : public PlaylistView class DynamicView : public PlaylistView
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DynamicView( QWidget* parent = 0 ); explicit DynamicView( QWidget* parent = 0 );
virtual ~DynamicView(); virtual ~DynamicView();
virtual void setDynamicModel( DynamicModel* model ); virtual void setDynamicModel( DynamicModel* model );
void setOnDemand( bool onDemand ); void setOnDemand( bool onDemand );
void setReadOnly( bool readOnly ); void setReadOnly( bool readOnly );
void setDynamicWorking( bool working ); void setDynamicWorking( bool working );
virtual void paintEvent( QPaintEvent* event ); virtual void paintEvent( QPaintEvent* event );
public slots: public slots:
void showMessageTimeout( const QString& title, const QString& body ); void showMessageTimeout( const QString& title, const QString& body );
void showMessage( const QString& message ); void showMessage( const QString& message );
// collapse and animate the transition // collapse and animate the transition
// there MUST be a row *after* startRow + num. that is, you can't collapse // there MUST be a row *after* startRow + num. that is, you can't collapse
// entries unless there is at least one entry after the last collapsed row // entries unless there is at least one entry after the last collapsed row
// optionally you can specify how many rows are past the block of collapsed rows // optionally you can specify how many rows are past the block of collapsed rows
void collapseEntries( int startRow, int num, int numToKeep = 1 ); void collapseEntries( int startRow, int num, int numToKeep = 1 );
private slots: private slots:
void onTrackCountChanged( unsigned int ); void onTrackCountChanged( unsigned int );
void checkForOverflow(); void checkForOverflow();
@@ -70,7 +70,7 @@ private:
DynamicModel* m_model; DynamicModel* m_model;
QString m_title; QString m_title;
QString m_body; QString m_body;
bool m_onDemand; bool m_onDemand;
bool m_readOnly; bool m_readOnly;
bool m_checkOnCollapse; bool m_checkOnCollapse;
@@ -88,7 +88,7 @@ private:
QTimeLine m_fadeOutAnim; QTimeLine m_fadeOutAnim;
QTimeLine m_slideAnim; QTimeLine m_slideAnim;
}; };
}; };

View File

@@ -443,8 +443,7 @@ DynamicWidget::steeringChanged()
void void
DynamicWidget::showPreview() DynamicWidget::showPreview()
{ {
if ( m_playlist->mode() == OnDemand && if ( m_playlist->mode() == OnDemand && !m_runningOnDemand )
!m_runningOnDemand )
{ {
// if this is a not running station, preview matching tracks // if this is a not running station, preview matching tracks
m_model->clear(); m_model->clear();