1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 05:37:29 +02: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() Album::~Album()
{ {
m_ownRef.clear();
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
delete m_cover; delete m_cover;
#endif #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 ); album_ptr a = album_ptr( new Album( id, name, artist ), &QObject::deleteLater );
a->setWeakRef( a.toWeakRef() );
if ( id > 0 ) if ( id > 0 )
s_albums.insert( id, a ); s_albums.insert( id, a );
@@ -87,13 +91,9 @@ Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr&
void 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() ); emit tracksAdded( playlistInterface( mode, collection )->tracks(), mode, collection );
if ( api )
api->addQueries( tracks );
emit tracksAdded( tracks );
} }
@@ -206,12 +206,25 @@ Album::infoSystemFinished( const QString& target )
Tomahawk::playlistinterface_ptr 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 #endif
bool infoLoaded() const { return m_infoLoaded; } 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: 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 updated();
void coverChanged(); void coverChanged();
private slots: 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 infoSystemInfo( const Tomahawk::InfoSystem::InfoRequestData& requestData, const QVariant& output );
void infoSystemFinished( const QString& target ); void infoSystemFinished( const QString& target );
@@ -75,6 +79,7 @@ private:
QString m_name; QString m_name;
artist_ptr m_artist; artist_ptr m_artist;
QByteArray m_coverBuffer; QByteArray m_coverBuffer;
bool m_infoLoaded; bool m_infoLoaded;
mutable bool m_infoLoading; mutable bool m_infoLoading;
mutable QString m_uuid; mutable QString m_uuid;
@@ -84,9 +89,13 @@ private:
mutable QHash< int, QPixmap > m_coverCache; mutable QHash< int, QPixmap > m_coverCache;
#endif #endif
Tomahawk::playlistinterface_ptr m_playlistInterface; QHash< Tomahawk::ModelMode, QHash< Tomahawk::collection_ptr, Tomahawk::playlistinterface_ptr > > m_playlistInterface;
QWeakPointer< Tomahawk::Album > m_ownRef;
}; };
} // ns } // ns
Q_DECLARE_METATYPE( Tomahawk::album_ptr )
#endif #endif