mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 08:19:42 +01:00
* Implemented new PlaylistInterface for TreeProxyModelPlaylistInterface.
This commit is contained in:
parent
a03c295767
commit
04a4b87558
@ -31,7 +31,8 @@
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
TreeProxyModelPlaylistInterface::TreeProxyModelPlaylistInterface( TreeProxyModel *proxyModel )
|
||||
|
||||
TreeProxyModelPlaylistInterface::TreeProxyModelPlaylistInterface( TreeProxyModel* proxyModel )
|
||||
: PlaylistInterface()
|
||||
, m_proxyModel( proxyModel )
|
||||
, m_repeatMode( PlaylistModes::NoRepeat )
|
||||
@ -66,23 +67,31 @@ TreeProxyModelPlaylistInterface::trackCount() const
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TreeProxyModelPlaylistInterface::hasNextItem()
|
||||
void
|
||||
TreeProxyModelPlaylistInterface::setCurrentIndex( qint64 index )
|
||||
{
|
||||
return !( siblingItem( 1, true ).isNull() );
|
||||
PlayableItem* item = static_cast<PlayableItem*>( (void*)index );
|
||||
if ( index < 0 || !item )
|
||||
{
|
||||
m_proxyModel.data()->setCurrentIndex( QModelIndex() );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_proxyModel.data()->setCurrentIndex( m_proxyModel.data()->mapFromSource( item->index ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Tomahawk::result_ptr
|
||||
TreeProxyModelPlaylistInterface::siblingItem( int itemsAway, bool readOnly )
|
||||
qint64
|
||||
TreeProxyModelPlaylistInterface::siblingIndex( int itemsAway ) const
|
||||
{
|
||||
if ( m_proxyModel.isNull() )
|
||||
return Tomahawk::result_ptr();
|
||||
TreeProxyModel* proxyModel = m_proxyModel.data();
|
||||
return -1;
|
||||
|
||||
TreeProxyModel* proxyModel = m_proxyModel.data();
|
||||
QModelIndex idx = proxyModel->currentIndex();
|
||||
if ( !idx.isValid() )
|
||||
return Tomahawk::result_ptr();
|
||||
return -1;
|
||||
|
||||
if ( m_shuffled )
|
||||
{
|
||||
@ -112,20 +121,15 @@ TreeProxyModelPlaylistInterface::siblingItem( int itemsAway, bool readOnly )
|
||||
while ( idx.isValid() )
|
||||
{
|
||||
PlayableItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( idx ) );
|
||||
if ( item && !item->result().isNull() && item->result()->isOnline() )
|
||||
if ( item )
|
||||
{
|
||||
qDebug() << "Next PlaylistItem found:" << item->result()->url();
|
||||
if ( !readOnly )
|
||||
proxyModel->setCurrentIndex( idx );
|
||||
return item->result();
|
||||
return (qint64)( item->index.internalPointer() );
|
||||
}
|
||||
|
||||
idx = proxyModel->index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() );
|
||||
}
|
||||
|
||||
if ( !readOnly )
|
||||
proxyModel->setCurrentIndex( QModelIndex() );
|
||||
return Tomahawk::result_ptr();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@ -139,5 +143,61 @@ TreeProxyModelPlaylistInterface::currentItem() const
|
||||
PlayableItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( proxyModel->currentIndex() ) );
|
||||
if ( item && !item->result().isNull() && item->result()->isOnline() )
|
||||
return item->result();
|
||||
|
||||
return Tomahawk::result_ptr();
|
||||
}
|
||||
|
||||
|
||||
QList< Tomahawk::query_ptr >
|
||||
TreeProxyModelPlaylistInterface::tracks()
|
||||
{
|
||||
Q_ASSERT( false );
|
||||
QList< Tomahawk::query_ptr > queries;
|
||||
return queries;
|
||||
}
|
||||
|
||||
|
||||
qint64
|
||||
TreeProxyModelPlaylistInterface::indexOfResult( const result_ptr& result ) const
|
||||
{
|
||||
if ( m_proxyModel.isNull() )
|
||||
return -1;
|
||||
|
||||
QModelIndex idx = m_proxyModel.data()->indexFromResult( result );
|
||||
if ( idx.isValid() )
|
||||
{
|
||||
return (qint64)( m_proxyModel.data()->mapToSource( idx ).internalPointer() );
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Tomahawk::query_ptr
|
||||
TreeProxyModelPlaylistInterface::queryAt( qint64 index ) const
|
||||
{
|
||||
if ( m_proxyModel.isNull() )
|
||||
return query_ptr();
|
||||
|
||||
PlayableItem* item = static_cast<PlayableItem*>( (void*)index );
|
||||
if ( item && item->query() )
|
||||
return item->query();
|
||||
if ( item && item->result() )
|
||||
return item->result()->toQuery();
|
||||
|
||||
return query_ptr();
|
||||
}
|
||||
|
||||
|
||||
Tomahawk::result_ptr
|
||||
TreeProxyModelPlaylistInterface::resultAt( qint64 index ) const
|
||||
{
|
||||
if ( m_proxyModel.isNull() )
|
||||
return result_ptr();
|
||||
|
||||
PlayableItem* item = static_cast<PlayableItem*>( (void*)index );
|
||||
if ( item && item->result() )
|
||||
return item->result();
|
||||
|
||||
return result_ptr();
|
||||
}
|
||||
|
@ -36,20 +36,20 @@ class DLLEXPORT TreeProxyModelPlaylistInterface : public Tomahawk::PlaylistInter
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TreeProxyModelPlaylistInterface( TreeProxyModel *proxyModel );
|
||||
explicit TreeProxyModelPlaylistInterface( TreeProxyModel* proxyModel );
|
||||
virtual ~TreeProxyModelPlaylistInterface();
|
||||
|
||||
virtual QList< Tomahawk::query_ptr > tracks() { Q_ASSERT( FALSE ); QList< Tomahawk::query_ptr > queries; return queries; }
|
||||
|
||||
virtual QList< Tomahawk::query_ptr > tracks();
|
||||
virtual int trackCount() const;
|
||||
|
||||
virtual Tomahawk::query_ptr itemAt( unsigned int position ) const { Q_UNUSED( position ); Q_ASSERT( false ); return Tomahawk::query_ptr(); }
|
||||
virtual int indexOfResult( const Tomahawk::result_ptr& result ) const { Q_UNUSED( result ); Q_ASSERT( false ); return -1; }
|
||||
virtual int indexOfQuery( const Tomahawk::query_ptr& query ) const { Q_UNUSED( query ); Q_ASSERT( false ); return -1; }
|
||||
virtual Tomahawk::result_ptr resultAt( qint64 index ) const;
|
||||
virtual Tomahawk::query_ptr queryAt( qint64 index ) const;
|
||||
virtual qint64 indexOfResult( const Tomahawk::result_ptr& result ) const;
|
||||
virtual qint64 indexOfQuery( const Tomahawk::query_ptr& query ) const { Q_UNUSED( query ); Q_ASSERT( false ); return -1; }
|
||||
|
||||
virtual bool hasNextItem();
|
||||
virtual void setCurrentIndex( qint64 index );
|
||||
virtual Tomahawk::result_ptr currentItem() const;
|
||||
virtual Tomahawk::result_ptr siblingItem( int direction, bool readOnly );
|
||||
virtual qint64 siblingIndex( int itemsAway ) const;
|
||||
|
||||
virtual QString filter() const;
|
||||
|
||||
@ -58,18 +58,10 @@ public:
|
||||
virtual PlaylistModes::ViewMode viewMode() const { return PlaylistModes::Tree; }
|
||||
|
||||
signals:
|
||||
void repeatModeChanged( Tomahawk::PlaylistModes::RepeatMode mode );
|
||||
void shuffleModeChanged( bool enabled );
|
||||
|
||||
void trackCountChanged( unsigned int tracks );
|
||||
void sourceTrackCountChanged( unsigned int tracks );
|
||||
|
||||
void filterChanged( const QString& filter );
|
||||
void filteringStarted();
|
||||
void filteringFinished();
|
||||
|
||||
void nextTrackReady();
|
||||
|
||||
public slots:
|
||||
virtual void setRepeatMode( Tomahawk::PlaylistModes::RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); }
|
||||
virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user