1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

fix backlog removing

This commit is contained in:
Leo Franchi
2011-02-11 23:59:30 -05:00
parent 0cb2a1cf91
commit 60fb37f740
5 changed files with 35 additions and 14 deletions

View File

@@ -25,7 +25,6 @@ DynamicModel::DynamicModel( QObject* parent )
, m_startOnResolved( false )
, m_onDemandRunning( false )
, m_changeOnNext( false )
, m_searchingForNext( false )
, m_currentAttempts( 0 )
, m_lastResolvedRow( 0 )
{
@@ -62,7 +61,6 @@ DynamicModel::startOnDemand()
m_onDemandRunning = true;
m_startOnResolved = true;
m_searchingForNext = false;
m_currentAttempts = 0;
m_lastResolvedRow = 0;
}
@@ -75,7 +73,6 @@ DynamicModel::newTrackGenerated( const Tomahawk::query_ptr& query )
connect( query.data(), SIGNAL( resultsAdded( QList<Tomahawk::result_ptr> ) ), this, SLOT( trackResolved() ) );
append( query );
m_searchingForNext = true;
}
}
@@ -83,7 +80,6 @@ void
DynamicModel::stopOnDemand()
{
m_onDemandRunning = false;
m_searchingForNext = false;
AudioEngine::instance()->stop();
disconnect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), this, SLOT( newTrackLoading() ) );
@@ -104,7 +100,6 @@ DynamicModel::trackResolved()
{
Query* q = qobject_cast<Query*>(sender());
qDebug() << "Got successful resolved track:" << q->track() << q->artist() << m_lastResolvedRow << m_currentAttempts;
m_searchingForNext = false;
if( m_startOnResolved ) { // on first start
m_startOnResolved = false;
AudioEngine::instance()->play();
@@ -115,6 +110,8 @@ DynamicModel::trackResolved()
emit collapseFromTo( m_lastResolvedRow, m_currentAttempts );
}
m_currentAttempts = 0;
emit checkForOverflow();
}
void

View File

@@ -47,6 +47,7 @@ public:
bool searchingForNext() const { return m_searchingForNext; }
signals:
void collapseFromTo( int startRow, int num );
void checkForOverflow();
void trackGenerationFailure( const QString& msg );

View File

@@ -37,6 +37,7 @@ using namespace Tomahawk;
DynamicView::DynamicView( QWidget* parent )
: PlaylistView( parent )
, m_onDemand( false )
, m_checkOnCollapse( false )
{
m_fadeOutAnim.setDuration( FADE_LENGTH );
m_fadeOutAnim.setCurveShape( QTimeLine::LinearCurve );
@@ -51,6 +52,7 @@ DynamicView::DynamicView( QWidget* parent )
connect( &m_fadeOutAnim, SIGNAL( frameChanged( int ) ), viewport(), SLOT( update() ) );
connect( &m_fadeOutAnim, SIGNAL( finished() ), this, SLOT( animFinished() ) );
}
DynamicView::~DynamicView()
@@ -65,6 +67,7 @@ DynamicView::setModel( DynamicModel* model)
PlaylistView::setModel( model );
connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
connect( model, SIGNAL( checkForOverflow() ), this, SLOT( checkForOverflow() ) );
}
void
@@ -122,10 +125,17 @@ DynamicView::onTrackCountChanged( unsigned int tracks )
}
else
overlay()->hide();
}
if( !m_onDemand || m_model->searchingForNext() || proxyModel()->rowCount( QModelIndex() ) == 0 )
void
DynamicView::checkForOverflow()
{
if( !m_onDemand || proxyModel()->rowCount( QModelIndex() ) == 0 )
return;
if( m_fadeOutAnim.state() == QTimeLine::Running )
m_checkOnCollapse = true;
/// We don't want stations to grow forever, because we don't want the view to have to scroll
/// So if there are too many tracks, we remove some that have already been played
/// Our threshold is 4 rows to the end. That's when we collapse.
@@ -145,6 +155,7 @@ DynamicView::onTrackCountChanged( unsigned int tracks )
void
DynamicView::collapseEntries( int startRow, int num, int numToKeep )
{
qDebug() << "BEGINNING TO COLLAPSE FROM" << startRow << num << numToKeep;
if( m_fadeOutAnim.state() == QTimeLine::Running )
qDebug() << "COLLAPSING TWICE!";
@@ -209,6 +220,14 @@ DynamicView::collapseEntries( int startRow, int num, int numToKeep )
proxyModel()->removeIndexes( todel );
}
void
DynamicView::animFinished()
{
if( m_checkOnCollapse )
checkForOverflow();
m_checkOnCollapse = false;
}
void
DynamicView::paintEvent( QPaintEvent* event )
{

View File

@@ -21,6 +21,7 @@
#include <QTimer>
#include <QPropertyAnimation>
#include <QTimeLine>
#include <QMutex>
class PlaylistModel;
class TrackModel;
@@ -56,6 +57,8 @@ public slots:
private slots:
void onTrackCountChanged( unsigned int );
void checkForOverflow();
void animFinished();
private:
DynamicModel* m_model;
@@ -64,6 +67,7 @@ private:
bool m_onDemand;
bool m_readOnly;
bool m_checkOnCollapse;
// for collapsing animation
QPoint m_fadingPointAnchor;

View File

@@ -64,7 +64,7 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
m_view->setContentsMargins( 0, 0, 0, 0 );
m_layout->addWidget( m_view, 1 );
connect( m_model, SIGNAL( collapseFromTo( int, int ) ), m_view, SLOT( collapseEntries( int, int ) ), Qt::QueuedConnection );
connect( m_model, SIGNAL( collapseFromTo( int, int ) ), m_view, SLOT( collapseEntries( int, int ) ) );
connect( m_model, SIGNAL( trackGenerationFailure( QString ) ), m_view, SLOT( showMessage( QString ) ) );