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

* Implemented new PlaylistInterface for TreeProxyModelPlaylistInterface.

This commit is contained in:
Christian Muehlhaeuser
2012-11-28 04:47:42 +01:00
parent a03c295767
commit 04a4b87558
2 changed files with 85 additions and 33 deletions

View File

@@ -31,7 +31,8 @@
using namespace Tomahawk; using namespace Tomahawk;
TreeProxyModelPlaylistInterface::TreeProxyModelPlaylistInterface( TreeProxyModel *proxyModel )
TreeProxyModelPlaylistInterface::TreeProxyModelPlaylistInterface( TreeProxyModel* proxyModel )
: PlaylistInterface() : PlaylistInterface()
, m_proxyModel( proxyModel ) , m_proxyModel( proxyModel )
, m_repeatMode( PlaylistModes::NoRepeat ) , m_repeatMode( PlaylistModes::NoRepeat )
@@ -66,23 +67,31 @@ TreeProxyModelPlaylistInterface::trackCount() const
} }
bool void
TreeProxyModelPlaylistInterface::hasNextItem() 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 qint64
TreeProxyModelPlaylistInterface::siblingItem( int itemsAway, bool readOnly ) TreeProxyModelPlaylistInterface::siblingIndex( int itemsAway ) const
{ {
if ( m_proxyModel.isNull() ) if ( m_proxyModel.isNull() )
return Tomahawk::result_ptr(); return -1;
TreeProxyModel* proxyModel = m_proxyModel.data();
TreeProxyModel* proxyModel = m_proxyModel.data();
QModelIndex idx = proxyModel->currentIndex(); QModelIndex idx = proxyModel->currentIndex();
if ( !idx.isValid() ) if ( !idx.isValid() )
return Tomahawk::result_ptr(); return -1;
if ( m_shuffled ) if ( m_shuffled )
{ {
@@ -112,20 +121,15 @@ TreeProxyModelPlaylistInterface::siblingItem( int itemsAway, bool readOnly )
while ( idx.isValid() ) while ( idx.isValid() )
{ {
PlayableItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( idx ) ); PlayableItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( idx ) );
if ( item && !item->result().isNull() && item->result()->isOnline() ) if ( item )
{ {
qDebug() << "Next PlaylistItem found:" << item->result()->url(); return (qint64)( item->index.internalPointer() );
if ( !readOnly )
proxyModel->setCurrentIndex( idx );
return item->result();
} }
idx = proxyModel->index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() ); idx = proxyModel->index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() );
} }
if ( !readOnly ) return -1;
proxyModel->setCurrentIndex( QModelIndex() );
return Tomahawk::result_ptr();
} }
@@ -139,5 +143,61 @@ TreeProxyModelPlaylistInterface::currentItem() const
PlayableItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( proxyModel->currentIndex() ) ); PlayableItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( proxyModel->currentIndex() ) );
if ( item && !item->result().isNull() && item->result()->isOnline() ) if ( item && !item->result().isNull() && item->result()->isOnline() )
return item->result(); return item->result();
return Tomahawk::result_ptr(); 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();
}

View File

@@ -36,20 +36,20 @@ class DLLEXPORT TreeProxyModelPlaylistInterface : public Tomahawk::PlaylistInter
Q_OBJECT Q_OBJECT
public: public:
explicit TreeProxyModelPlaylistInterface( TreeProxyModel *proxyModel ); explicit TreeProxyModelPlaylistInterface( TreeProxyModel* proxyModel );
virtual ~TreeProxyModelPlaylistInterface(); 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 int trackCount() const;
virtual Tomahawk::query_ptr itemAt( unsigned int position ) const { Q_UNUSED( position ); Q_ASSERT( false ); return Tomahawk::query_ptr(); } virtual Tomahawk::result_ptr resultAt( qint64 index ) const;
virtual int indexOfResult( const Tomahawk::result_ptr& result ) const { Q_UNUSED( result ); Q_ASSERT( false ); return -1; } virtual Tomahawk::query_ptr queryAt( qint64 index ) const;
virtual int indexOfQuery( const Tomahawk::query_ptr& query ) const { Q_UNUSED( query ); Q_ASSERT( false ); return -1; } 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 currentItem() const;
virtual Tomahawk::result_ptr siblingItem( int direction, bool readOnly ); virtual qint64 siblingIndex( int itemsAway ) const;
virtual QString filter() const; virtual QString filter() const;
@@ -58,18 +58,10 @@ public:
virtual PlaylistModes::ViewMode viewMode() const { return PlaylistModes::Tree; } virtual PlaylistModes::ViewMode viewMode() const { return PlaylistModes::Tree; }
signals: 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 filterChanged( const QString& filter );
void filteringStarted(); void filteringStarted();
void filteringFinished(); void filteringFinished();
void nextTrackReady();
public slots: public slots:
virtual void setRepeatMode( Tomahawk::PlaylistModes::RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); } virtual void setRepeatMode( Tomahawk::PlaylistModes::RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); }
virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); } virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); }