mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 15:59:42 +01:00
* Moved prev/next check into PlaylistInterface.
This commit is contained in:
parent
5e4940cb8d
commit
e4c66de0fd
@ -30,6 +30,9 @@ PlaylistInterface::PlaylistInterface ()
|
||||
: QObject()
|
||||
, m_latchMode( PlaylistModes::StayOnSong )
|
||||
, m_finished( false )
|
||||
, m_prevAvail( false )
|
||||
, m_nextAvail( false )
|
||||
, m_currentIndex( -1 )
|
||||
{
|
||||
m_id = uuid();
|
||||
}
|
||||
@ -55,9 +58,9 @@ PlaylistInterface::nextResult() const
|
||||
|
||||
|
||||
Tomahawk::result_ptr
|
||||
PlaylistInterface::siblingResult( int itemsAway ) const
|
||||
PlaylistInterface::siblingResult( int itemsAway, qint64 rootIndex ) const
|
||||
{
|
||||
qint64 idx = siblingIndex( itemsAway );
|
||||
qint64 idx = siblingIndex( itemsAway, rootIndex );
|
||||
qint64 safetyCheck = -1;
|
||||
|
||||
// If safetyCheck equals idx, this means the interface keeps returning the same item and we won't discover anything new - abort
|
||||
@ -168,3 +171,55 @@ PlaylistInterface::hasPreviousResult() const
|
||||
{
|
||||
return ( siblingResult( -1 ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistInterface::onItemsChanged()
|
||||
{
|
||||
if ( QThread::currentThread() != thread() )
|
||||
{
|
||||
QMetaObject::invokeMethod( this, "onItemsChanged", Qt::QueuedConnection );
|
||||
return;
|
||||
}
|
||||
|
||||
Tomahawk::result_ptr prevResult = siblingResult( -1, m_currentIndex );
|
||||
Tomahawk::result_ptr nextResult = siblingResult( 1, m_currentIndex );
|
||||
|
||||
if ( prevResult )
|
||||
{
|
||||
bool avail = prevResult->toQuery()->playable();
|
||||
if ( avail != m_prevAvail )
|
||||
{
|
||||
m_prevAvail = avail;
|
||||
emit previousTrackAvailable();
|
||||
}
|
||||
}
|
||||
else if ( m_prevAvail )
|
||||
{
|
||||
m_prevAvail = false;
|
||||
emit previousTrackAvailable();
|
||||
}
|
||||
|
||||
if ( nextResult )
|
||||
{
|
||||
bool avail = nextResult->toQuery()->playable();
|
||||
if ( avail != m_nextAvail )
|
||||
{
|
||||
m_nextAvail = avail;
|
||||
emit nextTrackAvailable();
|
||||
}
|
||||
}
|
||||
else if ( m_nextAvail )
|
||||
{
|
||||
m_nextAvail = false;
|
||||
emit nextTrackAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistInterface::setCurrentIndex( qint64 index )
|
||||
{
|
||||
m_currentIndex = index;
|
||||
onItemsChanged();
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
virtual int trackCount() const = 0;
|
||||
|
||||
virtual Tomahawk::result_ptr currentItem() const = 0;
|
||||
virtual void setCurrentIndex( qint64 index ) = 0;
|
||||
virtual void setCurrentIndex( qint64 index );
|
||||
|
||||
virtual bool hasNextResult() const;
|
||||
virtual bool hasPreviousResult() const;
|
||||
@ -54,7 +54,7 @@ public:
|
||||
virtual Tomahawk::result_ptr previousResult() const;
|
||||
|
||||
virtual qint64 siblingIndex( int itemsAway, qint64 rootIndex = -1 ) const = 0;
|
||||
virtual Tomahawk::result_ptr siblingResult( int itemsAway ) const;
|
||||
virtual Tomahawk::result_ptr siblingResult( int itemsAway, qint64 rootIndex = -1 ) const;
|
||||
|
||||
virtual Tomahawk::result_ptr resultAt( qint64 index ) const = 0;
|
||||
virtual Tomahawk::query_ptr queryAt( qint64 index ) const = 0;
|
||||
@ -100,11 +100,17 @@ signals:
|
||||
void previousTrackAvailable();
|
||||
void nextTrackAvailable();
|
||||
|
||||
protected slots:
|
||||
virtual void onItemsChanged();
|
||||
|
||||
protected:
|
||||
virtual QList<Tomahawk::query_ptr> filterTracks( const QList<Tomahawk::query_ptr>& queries );
|
||||
|
||||
PlaylistModes::LatchMode m_latchMode;
|
||||
bool m_finished;
|
||||
mutable bool m_prevAvail;
|
||||
mutable bool m_nextAvail;
|
||||
mutable qint64 m_currentIndex;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY( PlaylistInterface )
|
||||
|
Loading…
x
Reference in New Issue
Block a user