mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 23:57:34 +02:00
* Artist class is now a proper PlaylistInterface. Also, added appendArtist to PlaylistModel.
This commit is contained in:
@@ -31,8 +31,9 @@ public:
|
||||
Tomahawk::collection_ptr collection() const { return m_collection; }
|
||||
QList<Tomahawk::query_ptr> tracks();
|
||||
|
||||
virtual int unfilteredTrackCount() const { return m_queries.count(); }
|
||||
virtual int trackCount() const { return m_queries.count(); }
|
||||
virtual int unfilteredTrackCount() const { return m_queries.count(); }
|
||||
|
||||
virtual Tomahawk::result_ptr siblingItem( int itemsAway );
|
||||
|
||||
virtual PlaylistInterface::RepeatMode repeatMode() const { return PlaylistInterface::NoRepeat; }
|
||||
|
@@ -27,8 +27,56 @@ Artist::get( unsigned int id, const QString& name, const Tomahawk::collection_pt
|
||||
|
||||
|
||||
Artist::Artist( unsigned int id, const QString& name, const Tomahawk::collection_ptr& collection )
|
||||
: m_id( id )
|
||||
: PlaylistInterface( this )
|
||||
, m_id( id )
|
||||
, m_name( name )
|
||||
, m_collection( collection )
|
||||
, m_currentTrack( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Artist::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
m_queries << tracks;
|
||||
emit tracksAdded( tracks, collection );
|
||||
}
|
||||
|
||||
|
||||
Tomahawk::result_ptr
|
||||
Artist::siblingItem( int itemsAway )
|
||||
{
|
||||
int p = m_currentTrack;
|
||||
p += itemsAway;
|
||||
|
||||
if ( p < 0 )
|
||||
return Tomahawk::result_ptr();
|
||||
|
||||
if ( p >= m_queries.count() )
|
||||
return Tomahawk::result_ptr();
|
||||
|
||||
m_currentTrack = p;
|
||||
return m_queries.at( p )->results().first();
|
||||
}
|
||||
|
||||
|
||||
QList<Tomahawk::query_ptr>
|
||||
Artist::tracks()
|
||||
{
|
||||
if ( m_queries.isEmpty() )
|
||||
{
|
||||
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_collection );
|
||||
cmd->setArtist( this );
|
||||
cmd->setSortOrder( DatabaseCommand_AllTracks::Album );
|
||||
|
||||
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ),
|
||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
|
||||
return m_queries;
|
||||
}
|
||||
|
@@ -7,12 +7,14 @@
|
||||
#include "typedefs.h"
|
||||
#include "collection.h"
|
||||
|
||||
#include "playlistinterface.h"
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
class DLLEXPORT Artist : public QObject
|
||||
class DLLEXPORT Artist : public QObject, public PlaylistInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -26,13 +28,38 @@ public:
|
||||
|
||||
Tomahawk::collection_ptr collection() const { return m_collection; }
|
||||
|
||||
// QList<Tomahawk::query_ptr> tracks();
|
||||
// virtual int trackCount() const { return 0; }
|
||||
QList<Tomahawk::query_ptr> tracks();
|
||||
|
||||
virtual int trackCount() const { return 0; }
|
||||
virtual int unfilteredTrackCount() const { return m_queries.count(); }
|
||||
|
||||
virtual Tomahawk::result_ptr siblingItem( int itemsAway );
|
||||
|
||||
virtual PlaylistInterface::RepeatMode repeatMode() const { return PlaylistInterface::NoRepeat; }
|
||||
virtual bool shuffled() const { return false; }
|
||||
|
||||
virtual void setRepeatMode( PlaylistInterface::RepeatMode ) {}
|
||||
virtual void setShuffled( bool ) {}
|
||||
|
||||
virtual void setFilter( const QString& pattern ) {}
|
||||
|
||||
signals:
|
||||
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
|
||||
void shuffleModeChanged( bool enabled );
|
||||
|
||||
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& );
|
||||
void trackCountChanged( unsigned int tracks );
|
||||
void sourceTrackCountChanged( unsigned int tracks );
|
||||
|
||||
private slots:
|
||||
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection );
|
||||
|
||||
private:
|
||||
unsigned int m_id;
|
||||
QString m_name;
|
||||
|
||||
QList<Tomahawk::query_ptr> m_queries;
|
||||
unsigned int m_currentTrack;
|
||||
Tomahawk::collection_ptr m_collection;
|
||||
};
|
||||
|
||||
|
@@ -18,6 +18,10 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi )
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case Album:
|
||||
m_orderToken = "album.name, file_join.albumpos";
|
||||
break;
|
||||
|
||||
case ModificationTime:
|
||||
m_orderToken = "file.mtime";
|
||||
break;
|
||||
@@ -37,9 +41,10 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi )
|
||||
"AND file_join.artist = artist.id "
|
||||
"AND file_join.track = track.id "
|
||||
"AND file.source %1 "
|
||||
"%2 "
|
||||
"%3 %4 %5"
|
||||
"%2 %3 "
|
||||
"%4 %5 %6"
|
||||
).arg( m_collection->source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( m_collection->source()->id() ) )
|
||||
.arg( !m_artist ? QString() : QString( "AND artist.id = %1" ).arg( m_artist->id() ) )
|
||||
.arg( !m_album ? QString() : QString( "AND album.id = %1" ).arg( m_album->id() ) )
|
||||
.arg( m_sortOrder > 0 ? QString( "ORDER BY %1" ).arg( m_orderToken ) : QString() )
|
||||
.arg( m_sortDescending ? "DESC" : QString() )
|
||||
|
@@ -17,13 +17,15 @@ Q_OBJECT
|
||||
public:
|
||||
enum SortOrder {
|
||||
None = 0,
|
||||
ModificationTime = 1,
|
||||
AlbumPosition = 2
|
||||
Album = 1,
|
||||
ModificationTime = 2,
|
||||
AlbumPosition = 3
|
||||
};
|
||||
|
||||
explicit DatabaseCommand_AllTracks( const Tomahawk::collection_ptr& collection, QObject* parent = 0 )
|
||||
: DatabaseCommand( parent )
|
||||
, m_collection( collection )
|
||||
, m_artist( 0 )
|
||||
, m_album( 0 )
|
||||
, m_amount( 0 )
|
||||
, m_sortOrder( DatabaseCommand_AllTracks::None )
|
||||
@@ -35,7 +37,9 @@ public:
|
||||
virtual bool doesMutates() const { return false; }
|
||||
virtual QString commandname() const { return "alltracks"; }
|
||||
|
||||
void setArtist( Tomahawk::Artist* artist ) { m_artist = artist; }
|
||||
void setAlbum( Tomahawk::Album* album ) { m_album = album; }
|
||||
|
||||
void setLimit( unsigned int amount ) { m_amount = amount; }
|
||||
void setSortOrder( DatabaseCommand_AllTracks::SortOrder order ) { m_sortOrder = order; }
|
||||
void setSortDescending( bool descending ) { m_sortDescending = descending; }
|
||||
@@ -46,7 +50,10 @@ signals:
|
||||
|
||||
private:
|
||||
Tomahawk::collection_ptr m_collection;
|
||||
|
||||
Tomahawk::Artist* m_artist;
|
||||
Tomahawk::Album* m_album;
|
||||
|
||||
unsigned int m_amount;
|
||||
DatabaseCommand_AllTracks::SortOrder m_sortOrder;
|
||||
bool m_sortDescending;
|
||||
|
@@ -136,7 +136,7 @@ PlaylistManager::show( const Tomahawk::album_ptr& album )
|
||||
PlaylistView* view = new PlaylistView();
|
||||
PlaylistModel* model = new PlaylistModel();
|
||||
view->setModel( model );
|
||||
model->loadAlbum( album );
|
||||
model->appendAlbum( album );
|
||||
|
||||
m_currentInterface = view->proxyModel();
|
||||
m_albumViews.insert( album, view );
|
||||
|
@@ -95,22 +95,11 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist )
|
||||
|
||||
|
||||
void
|
||||
PlaylistModel::loadAlbum( const Tomahawk::album_ptr& album )
|
||||
PlaylistModel::appendAlbum( const Tomahawk::album_ptr& album )
|
||||
{
|
||||
if ( album.isNull() )
|
||||
return;
|
||||
|
||||
if ( rowCount( QModelIndex() ) )
|
||||
{
|
||||
emit beginRemoveRows( QModelIndex(), 0, rowCount( QModelIndex() ) - 1 );
|
||||
delete m_rootItem;
|
||||
emit endRemoveRows();
|
||||
m_rootItem = new PlItem( 0, this );
|
||||
}
|
||||
|
||||
m_playlist.clear();
|
||||
setReadOnly( false );
|
||||
|
||||
connect( album.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ),
|
||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ) );
|
||||
|
||||
@@ -118,6 +107,19 @@ PlaylistModel::loadAlbum( const Tomahawk::album_ptr& album )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistModel::appendArtist( const Tomahawk::artist_ptr& artist )
|
||||
{
|
||||
if ( artist.isNull() )
|
||||
return;
|
||||
|
||||
connect( artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ),
|
||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ) );
|
||||
|
||||
onTracksAdded( artist->tracks(), artist->collection() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistModel::loadHistory( const Tomahawk::source_ptr& source, unsigned int amount )
|
||||
{
|
||||
|
@@ -31,10 +31,12 @@ public:
|
||||
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent );
|
||||
|
||||
void loadPlaylist( const Tomahawk::playlist_ptr& playlist );
|
||||
void loadAlbum( const Tomahawk::album_ptr& album );
|
||||
void loadHistory( const Tomahawk::source_ptr& source, unsigned int amount = 100 );
|
||||
|
||||
void appendTrack( const Tomahawk::query_ptr& query );
|
||||
void appendAlbum( const Tomahawk::album_ptr& album );
|
||||
void appendArtist( const Tomahawk::artist_ptr& artist );
|
||||
|
||||
void insertTrack( unsigned int row, const Tomahawk::query_ptr& query );
|
||||
|
||||
virtual void removeIndex( const QModelIndex& index, bool moreToCome = false );
|
||||
|
Reference in New Issue
Block a user