1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

* Properly implemented SingleTrackPlaylistInterface.

This commit is contained in:
Christian Muehlhaeuser 2012-12-22 14:37:47 +01:00
parent 63fc41d23d
commit c51ca312db
3 changed files with 103 additions and 12 deletions

View File

@ -81,7 +81,7 @@ set( libGuiSources
playlist/PlaylistLargeItemDelegate.cpp
playlist/PlaylistChartItemDelegate.cpp
playlist/PlayableItem.cpp
playlist/SingleTrackPlaylistInterface.h
playlist/SingleTrackPlaylistInterface.cpp
playlist/dynamic/DynamicPlaylist.cpp
playlist/dynamic/DynamicView.cpp

View File

@ -0,0 +1,95 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012 Leo Franchi <lfranchi@kde.org>
* Copyright 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SingleTrackPlaylistInterface.h"
namespace Tomahawk
{
SingleTrackPlaylistInterface::SingleTrackPlaylistInterface( const Tomahawk::query_ptr& query )
: PlaylistInterface()
, m_track( query )
{
}
Tomahawk::result_ptr
SingleTrackPlaylistInterface::currentItem() const
{
if ( m_track && m_track->numResults() )
return m_track->results().first();
return result_ptr();
}
Tomahawk::result_ptr
SingleTrackPlaylistInterface::resultAt( qint64 index ) const
{
if ( index == 0 && m_track && m_track->numResults() )
return m_track->results().first();
return result_ptr();
}
Tomahawk::query_ptr
SingleTrackPlaylistInterface::queryAt( qint64 index ) const
{
if ( index == 0 )
return m_track;
return query_ptr();
}
qint64
SingleTrackPlaylistInterface::indexOfResult( const Tomahawk::result_ptr& result ) const
{
if ( m_track && m_track->results().contains( result ) )
return 0;
return -1;
}
qint64
SingleTrackPlaylistInterface::indexOfQuery( const Tomahawk::query_ptr& query ) const
{
if ( m_track == query )
return 0;
return -1;
}
QList< Tomahawk::query_ptr >
SingleTrackPlaylistInterface::tracks() const
{
QList< query_ptr > ql;
if ( m_track )
ql << m_track;
return ql;
}
}

View File

@ -32,22 +32,18 @@ class DLLEXPORT SingleTrackPlaylistInterface : public PlaylistInterface
{
Q_OBJECT
public:
explicit SingleTrackPlaylistInterface( const query_ptr& query )
: PlaylistInterface()
, m_track( query )
{
}
explicit SingleTrackPlaylistInterface( const query_ptr& query );
query_ptr track() const { return m_track; }
void setQuery( const query_ptr& track ) { m_track = track; }
virtual void setCurrentIndex( qint64 index ) { Q_UNUSED( index ); }
virtual result_ptr currentItem() const { return result_ptr(); }
virtual result_ptr currentItem() const;
virtual Tomahawk::result_ptr resultAt( qint64 index ) const { Q_UNUSED( index ); Q_ASSERT( false ); return Tomahawk::result_ptr(); }
virtual Tomahawk::query_ptr queryAt( qint64 index ) const { Q_UNUSED( index ); Q_ASSERT( false ); return Tomahawk::query_ptr(); }
virtual qint64 indexOfResult( const Tomahawk::result_ptr& result ) const { Q_UNUSED( result ); Q_ASSERT( false ); return -1; }
virtual qint64 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;
virtual PlaylistModes::RepeatMode repeatMode() const { return PlaylistModes::NoRepeat; }
virtual void setRepeatMode( PlaylistModes::RepeatMode ) {}
@ -57,7 +53,7 @@ public:
virtual qint64 siblingIndex( int, qint64 rootIndex = -1 ) const { Q_UNUSED( rootIndex ); return -1; }
virtual int trackCount() const { return 1; }
virtual QList< query_ptr > tracks() const { return QList< query_ptr >(); }
virtual QList< query_ptr > tracks() const;
private:
query_ptr m_track;