1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 17:29:42 +01:00

* ModelMode specific PlaylistInterfaces for Album object.

This commit is contained in:
Christian Muehlhaeuser 2012-05-18 12:12:53 +02:00
parent 4c04feb529
commit 2d34a69e0c
2 changed files with 36 additions and 14 deletions

View File

@ -32,6 +32,8 @@ using namespace Tomahawk;
Album::~Album()
{
m_ownRef.clear();
#ifndef ENABLE_HEADLESS
delete m_cover;
#endif
@ -65,6 +67,8 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar
}
album_ptr a = album_ptr( new Album( id, name, artist ), &QObject::deleteLater );
a->setWeakRef( a.toWeakRef() );
if ( id > 0 )
s_albums.insert( id, a );
@ -87,13 +91,9 @@ Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr&
void
Album::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
Album::onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection )
{
Tomahawk::AlbumPlaylistInterface* api = dynamic_cast< Tomahawk::AlbumPlaylistInterface* >( playlistInterface().data() );
if ( api )
api->addQueries( tracks );
emit tracksAdded( tracks );
emit tracksAdded( playlistInterface( mode, collection )->tracks(), mode, collection );
}
@ -206,12 +206,25 @@ Album::infoSystemFinished( const QString& target )
Tomahawk::playlistinterface_ptr
Album::playlistInterface()
Album::playlistInterface( ModelMode mode, const Tomahawk::collection_ptr& collection )
{
if ( m_playlistInterface.isNull() )
playlistinterface_ptr pli = m_playlistInterface[ mode ][ collection ];
if ( pli.isNull() )
{
m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::AlbumPlaylistInterface( this ) );
pli = Tomahawk::playlistinterface_ptr( new Tomahawk::AlbumPlaylistInterface( this, mode, collection ) );
connect( pli.data(), SIGNAL( tracksLoaded( Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
SLOT( onTracksLoaded( Tomahawk::ModelMode, Tomahawk::collection_ptr ) ) );
m_playlistInterface[ mode ][ collection ] = pli;
}
return m_playlistInterface;
return pli;
}
QList<Tomahawk::query_ptr>
Album::tracks( ModelMode mode, const Tomahawk::collection_ptr& collection )
{
return playlistInterface( mode, collection )->tracks();
}

View File

@ -55,15 +55,19 @@ public:
#endif
bool infoLoaded() const { return m_infoLoaded; }
Tomahawk::playlistinterface_ptr playlistInterface();
QList<Tomahawk::query_ptr> tracks( ModelMode mode = Mixed, const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr() );
Tomahawk::playlistinterface_ptr playlistInterface( ModelMode mode, const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr() );
QWeakPointer< Tomahawk::Album > weakRef() { return m_ownRef; }
void setWeakRef( QWeakPointer< Tomahawk::Album > weakRef ) { m_ownRef = weakRef; }
signals:
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks );
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection );
void updated();
void coverChanged();
private slots:
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks );
void onTracksLoaded(Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection );
void infoSystemInfo( const Tomahawk::InfoSystem::InfoRequestData& requestData, const QVariant& output );
void infoSystemFinished( const QString& target );
@ -75,6 +79,7 @@ private:
QString m_name;
artist_ptr m_artist;
QByteArray m_coverBuffer;
bool m_infoLoaded;
mutable bool m_infoLoading;
mutable QString m_uuid;
@ -84,9 +89,13 @@ private:
mutable QHash< int, QPixmap > m_coverCache;
#endif
Tomahawk::playlistinterface_ptr m_playlistInterface;
QHash< Tomahawk::ModelMode, QHash< Tomahawk::collection_ptr, Tomahawk::playlistinterface_ptr > > m_playlistInterface;
QWeakPointer< Tomahawk::Album > m_ownRef;
};
} // ns
Q_DECLARE_METATYPE( Tomahawk::album_ptr )
#endif