1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-09 07:36:48 +02:00

* Added Artist::albums( ... ) for convenience. Removes a lot of DRY code.

This commit is contained in:
Christian Muehlhaeuser
2012-04-24 08:06:52 +02:00
parent 99e09b3b8d
commit 93ad670828
11 changed files with 259 additions and 243 deletions

View File

@@ -410,8 +410,10 @@ TomahawkApp::registerMetaTypes()
qRegisterMetaType< QMap< QString, QMap< unsigned int, unsigned int > > >("QMap< QString, QMap< unsigned int, unsigned int > >"); qRegisterMetaType< QMap< QString, QMap< unsigned int, unsigned int > > >("QMap< QString, QMap< unsigned int, unsigned int > >");
qRegisterMetaType< PairList >("PairList"); qRegisterMetaType< PairList >("PairList");
qRegisterMetaType< GeneratorMode>("GeneratorMode"); qRegisterMetaType<GeneratorMode>("GeneratorMode");
qRegisterMetaType<Tomahawk::GeneratorMode>("Tomahawk::GeneratorMode"); qRegisterMetaType<Tomahawk::GeneratorMode>("Tomahawk::GeneratorMode");
qRegisterMetaType<ModelMode>("Tomahawk::ModelMode");
qRegisterMetaType<Tomahawk::ModelMode>("Tomahawk::ModelMode");
// Extra definition for namespaced-versions of signals/slots required // Extra definition for namespaced-versions of signals/slots required
qRegisterMetaType< Tomahawk::source_ptr >("Tomahawk::source_ptr"); qRegisterMetaType< Tomahawk::source_ptr >("Tomahawk::source_ptr");

View File

@@ -24,6 +24,7 @@
#include "database/Database.h" #include "database/Database.h"
#include "database/DatabaseImpl.h" #include "database/DatabaseImpl.h"
#include "Query.h" #include "Query.h"
#include "database/DatabaseCommand_AllAlbums.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@@ -32,6 +33,8 @@ using namespace Tomahawk;
Artist::~Artist() Artist::~Artist()
{ {
m_ownRef.clear();
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
delete m_cover; delete m_cover;
#endif #endif
@@ -65,6 +68,8 @@ Artist::get( unsigned int id, const QString& name )
} }
artist_ptr a = artist_ptr( new Artist( id, name ), &QObject::deleteLater ); artist_ptr a = artist_ptr( new Artist( id, name ), &QObject::deleteLater );
a->setWeakRef( a.toWeakRef() );
if ( id > 0 ) if ( id > 0 )
s_artists.insert( id, a ); s_artists.insert( id, a );
@@ -78,6 +83,7 @@ Artist::Artist( unsigned int id, const QString& name )
, m_name( name ) , m_name( name )
, m_infoLoaded( false ) , m_infoLoaded( false )
, m_infoLoading( false ) , m_infoLoading( false )
, m_infoJobs( 0 )
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
, m_cover( 0 ) , m_cover( 0 )
#endif #endif
@@ -92,10 +98,160 @@ Artist::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
Tomahawk::ArtistPlaylistInterface* api = dynamic_cast< Tomahawk::ArtistPlaylistInterface* >( playlistInterface().data() ); Tomahawk::ArtistPlaylistInterface* api = dynamic_cast< Tomahawk::ArtistPlaylistInterface* >( playlistInterface().data() );
if ( api ) if ( api )
api->addQueries( tracks ); api->addQueries( tracks );
emit tracksAdded( tracks ); emit tracksAdded( tracks );
} }
QList<album_ptr>
Artist::albums( ModelMode mode, const Tomahawk::collection_ptr& collection ) const
{
artist_ptr artist = m_ownRef.toStrongRef();
bool dbLoaded = m_albumsLoaded.value( DatabaseMode );
const bool infoLoaded = m_albumsLoaded.value( InfoSystemMode );
if ( !collection.isNull() )
dbLoaded = false;
m_uuid = uuid();
tDebug() << Q_FUNC_INFO << mode;
if ( ( mode == DatabaseMode || mode == Mixed ) && !dbLoaded )
{
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection, artist );
cmd->setData( QVariant( collection.isNull() ) );
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, QVariant ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
if ( ( mode == InfoSystemMode || mode == Mixed ) && !infoLoaded )
{
Tomahawk::InfoSystem::InfoStringHash artistInfo;
artistInfo["artist"] = name();
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = m_uuid;
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
requestData.type = Tomahawk::InfoSystem::InfoArtistReleases;
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection );
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( finished( QString ) ),
SLOT( infoSystemFinished( QString ) ), Qt::UniqueConnection );
m_infoJobs++;
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
}
if ( !collection.isNull() )
return QList<album_ptr>();
switch ( mode )
{
case DatabaseMode:
return m_databaseAlbums;
case InfoSystemMode:
return m_officialAlbums;
default:
return m_databaseAlbums + m_officialAlbums;
}
}
void
Artist::onAlbumsFound( const QList< album_ptr >& albums, const QVariant& data )
{
if ( data.toBool() )
{
m_databaseAlbums << albums;
m_albumsLoaded.insert( DatabaseMode, true );
}
emit albumsAdded( albums, DatabaseMode );
}
void
Artist::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
{
if ( requestData.caller != m_uuid )
return;
switch ( requestData.type )
{
case Tomahawk::InfoSystem::InfoArtistReleases:
{
QVariantMap returnedData = output.value< QVariantMap >();
QStringList albumNames = returnedData[ "albums" ].toStringList();
Tomahawk::InfoSystem::InfoStringHash inputInfo;
inputInfo = requestData.input.value< InfoSystem::InfoStringHash >();
QList< album_ptr > albums;
foreach ( const QString& albumName, albumNames )
{
tDebug() << Q_FUNC_INFO << albumName;
Tomahawk::album_ptr album = Tomahawk::Album::get( m_ownRef.toStrongRef(), albumName, false );
m_officialAlbums << album;
albums << album;
}
m_albumsLoaded.insert( InfoSystemMode, true );
if ( m_officialAlbums.count() )
emit albumsAdded( albums, InfoSystemMode );
break;
}
case Tomahawk::InfoSystem::InfoArtistImages:
{
if ( !output.isNull() && output.isValid() )
{
QVariantMap returnedData = output.value< QVariantMap >();
const QByteArray ba = returnedData["imgbytes"].toByteArray();
if ( ba.length() )
{
m_coverBuffer = ba;
m_infoLoaded = true;
emit coverChanged();
}
}
break;
}
default:
Q_ASSERT( false );
}
}
void
Artist::infoSystemFinished( QString target )
{
Q_UNUSED( target );
if ( target != m_uuid )
return;
if ( --m_infoJobs == 0 )
{
disconnect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
this, SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
disconnect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ),
this, SLOT( infoSystemFinished( QString ) ) );
}
emit updated();
}
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
QPixmap QPixmap
Artist::cover( const QSize& size, bool forceLoad ) const Artist::cover( const QSize& size, bool forceLoad ) const
@@ -117,12 +273,13 @@ Artist::cover( const QSize& size, bool forceLoad ) const
connect( Tomahawk::InfoSystem::InfoSystem::instance(), connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) ); SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection );
connect( Tomahawk::InfoSystem::InfoSystem::instance(), connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( finished( QString ) ), SIGNAL( finished( QString ) ),
SLOT( infoSystemFinished( QString ) ) ); SLOT( infoSystemFinished( QString ) ), Qt::UniqueConnection );
m_infoJobs++;
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
m_infoLoading = true; m_infoLoading = true;
@@ -132,6 +289,7 @@ Artist::cover( const QSize& size, bool forceLoad ) const
{ {
m_cover = new QPixmap(); m_cover = new QPixmap();
m_cover->loadFromData( m_coverBuffer ); m_cover->loadFromData( m_coverBuffer );
m_coverBuffer.clear();
} }
if ( m_cover && !m_cover->isNull() && !size.isEmpty() ) if ( m_cover && !m_cover->isNull() && !size.isEmpty() )
@@ -155,47 +313,6 @@ Artist::cover( const QSize& size, bool forceLoad ) const
#endif #endif
void
Artist::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
{
if ( requestData.caller != m_uuid ||
requestData.type != Tomahawk::InfoSystem::InfoArtistImages )
{
return;
}
if ( !output.isNull() && output.isValid() )
{
QVariantMap returnedData = output.value< QVariantMap >();
const QByteArray ba = returnedData["imgbytes"].toByteArray();
if ( ba.length() )
{
m_coverBuffer = ba;
emit coverChanged();
}
}
}
void
Artist::infoSystemFinished( QString target )
{
Q_UNUSED( target );
if ( target != m_uuid )
return;
disconnect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
this, SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
disconnect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ),
this, SLOT( infoSystemFinished( QString ) ) );
m_infoLoaded = true;
emit updated();
}
Tomahawk::playlistinterface_ptr Tomahawk::playlistinterface_ptr
Artist::playlistInterface() Artist::playlistInterface()
{ {

View File

@@ -49,20 +49,29 @@ public:
unsigned int id() const { return m_id; } unsigned int id() const { return m_id; }
QString name() const { return m_name; } QString name() const { return m_name; }
QString sortname() const { return m_sortname; } QString sortname() const { return m_sortname; }
bool infoLoaded() const { return m_infoLoaded; }
QList<Tomahawk::album_ptr> albums( ModelMode mode = Mixed, const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr() ) const;
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
QPixmap cover( const QSize& size, bool forceLoad = true ) const; QPixmap cover( const QSize& size, bool forceLoad = true ) const;
#endif #endif
bool infoLoaded() const { return m_infoLoaded; }
Tomahawk::playlistinterface_ptr playlistInterface(); Tomahawk::playlistinterface_ptr playlistInterface();
QWeakPointer< Tomahawk::Artist > weakRef() { return m_ownRef; }
void setWeakRef( QWeakPointer< Tomahawk::Artist > weakRef ) { m_ownRef = weakRef; }
signals: signals:
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks ); void tracksAdded( const QList<Tomahawk::query_ptr>& tracks );
void albumsAdded( const QList<Tomahawk::album_ptr>& albums, Tomahawk::ModelMode mode );
void updated(); void updated();
void coverChanged(); void coverChanged();
private slots: private slots:
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks ); void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks );
void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, const QVariant& data );
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
void infoSystemFinished( QString target ); void infoSystemFinished( QString target );
@@ -73,17 +82,25 @@ private:
unsigned int m_id; unsigned int m_id;
QString m_name; QString m_name;
QString m_sortname; QString m_sortname;
QByteArray m_coverBuffer;
bool m_infoLoaded; bool m_infoLoaded;
mutable bool m_infoLoading; mutable bool m_infoLoading;
QHash<Tomahawk::ModelMode, bool> m_albumsLoaded;
mutable QString m_uuid; mutable QString m_uuid;
mutable int m_infoJobs;
QList<Tomahawk::album_ptr> m_databaseAlbums;
QList<Tomahawk::album_ptr> m_officialAlbums;
mutable QByteArray m_coverBuffer;
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
mutable QPixmap* m_cover; mutable QPixmap* m_cover;
mutable QHash< int, QPixmap > m_coverCache; mutable QHash< int, QPixmap > m_coverCache;
#endif #endif
Tomahawk::playlistinterface_ptr m_playlistInterface; Tomahawk::playlistinterface_ptr m_playlistInterface;
QWeakPointer< Tomahawk::Artist > m_ownRef;
}; };
} // ns } // ns

View File

@@ -61,15 +61,17 @@ namespace Tomahawk
typedef QString QID; //query id typedef QString QID; //query id
typedef QString RID; //result id typedef QString RID; //result id
enum GeneratorMode { enum GeneratorMode
{
OnDemand = 0, OnDemand = 0,
Static Static
}; };
enum ModelMode enum ModelMode
{ {
DatabaseMode = 0, Mixed = 0,
InfoSystemMode DatabaseMode,
InfoSystemMode,
}; };
class ExternalResolver; class ExternalResolver;

View File

@@ -47,6 +47,8 @@ public:
virtual bool doesMutates() const { return false; } virtual bool doesMutates() const { return false; }
virtual QString commandname() const { return "allalbums"; } virtual QString commandname() const { return "allalbums"; }
Tomahawk::collection_ptr collection() const { return m_collection; }
void execForCollection( DatabaseImpl* ); void execForCollection( DatabaseImpl* );
void execForArtist( DatabaseImpl* ); void execForArtist( DatabaseImpl* );

View File

@@ -172,12 +172,12 @@ TreeModel::fetchMore( const QModelIndex& parent )
parentItem->fetchingMore = true; parentItem->fetchingMore = true;
if ( !parentItem->artist().isNull() ) if ( !parentItem->artist().isNull() )
{ {
qDebug() << Q_FUNC_INFO << "Loading Artist:" << parentItem->artist()->name(); tDebug() << Q_FUNC_INFO << "Loading Artist:" << parentItem->artist()->name();
addAlbums( parentItem->artist(), parent ); fetchAlbums( parentItem->artist() );
} }
else if ( !parentItem->album().isNull() ) else if ( !parentItem->album().isNull() )
{ {
qDebug() << Q_FUNC_INFO << "Loading Album:" << parentItem->album()->name(); tDebug() << Q_FUNC_INFO << "Loading Album:" << parentItem->album()->name();
addTracks( parentItem->album(), parent ); addTracks( parentItem->album(), parent );
} }
else else
@@ -601,35 +601,57 @@ TreeModel::addArtists( const artist_ptr& artist )
void void
TreeModel::addAlbums( const artist_ptr& artist, const QModelIndex& parent, bool autoRefetch ) TreeModel::fetchAlbums( const artist_ptr& artist )
{ {
emit loadingStarted(); emit loadingStarted();
if ( m_mode == DatabaseMode ) connect( artist.data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ),
SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ) );
const QModelIndex parent = indexFromArtist( artist );
addAlbums( parent, artist->albums( m_mode, m_collection ) );
}
void
TreeModel::onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, ModelMode mode )
{
if ( m_mode != mode )
return;
const artist_ptr artist = qobject_cast< Artist* >( sender() )->weakRef().toStrongRef();
const QModelIndex parent = indexFromArtist( artist );
addAlbums( parent, albums );
}
void
TreeModel::addAlbums( const QModelIndex& parent, const QList<Tomahawk::album_ptr>& albums )
{
emit loadingFinished();
if ( !albums.count() )
return;
TreeModelItem* parentItem = itemFromIndex( parent );
QPair< int, int > crows;
const int c = rowCount( parent );
crows.first = c;
crows.second = c + albums.count() - 1;
emit beginInsertRows( parent, crows.first, crows.second );
TreeModelItem* albumitem = 0;
foreach( const album_ptr& album, albums )
{ {
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( m_collection, artist ); albumitem = new TreeModelItem( album, parentItem );
cmd->setData( parent.row() ); albumitem->index = createIndex( parentItem->children.count() - 1, 0, albumitem );
connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ), getCover( albumitem->index );
SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, QVariant ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
} }
else if ( m_mode == InfoSystemMode )
{
Tomahawk::InfoSystem::InfoStringHash artistInfo;
artistInfo["artist"] = artist->name();
Tomahawk::InfoSystem::InfoRequestData requestData; emit endInsertRows();
requestData.caller = m_infoId;
requestData.customData["row"] = parent.row();
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
requestData.customData["refetch"] = autoRefetch;
requestData.type = Tomahawk::InfoSystem::InfoArtistReleases;
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
}
else
Q_ASSERT( false );
} }
@@ -776,36 +798,6 @@ TreeModel::onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists )
} }
void
TreeModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QModelIndex& parent )
{
emit loadingFinished();
if ( !albums.count() )
return;
TreeModelItem* parentItem = itemFromIndex( parent );
QPair< int, int > crows;
int c = rowCount( parent );
crows.first = c;
crows.second = c + albums.count() - 1;
emit beginInsertRows( parent, crows.first, crows.second );
TreeModelItem* albumitem = 0;
foreach( const album_ptr& album, albums )
{
albumitem = new TreeModelItem( album, parentItem );
albumitem->index = createIndex( parentItem->children.count() - 1, 0, albumitem );
connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
getCover( albumitem->index );
}
emit endInsertRows();
}
void void
TreeModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QModelIndex& parent ) TreeModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QModelIndex& parent )
{ {
@@ -849,14 +841,6 @@ TreeModel::onTracksFound( const QList<Tomahawk::query_ptr>& tracks, const QVaria
} }
void
TreeModel::onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, const QVariant& variant )
{
QModelIndex idx = index( variant.toInt(), 0, QModelIndex() );
onAlbumsAdded( albums, idx );
}
void void
TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
{ {
@@ -867,43 +851,6 @@ TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QV
switch ( requestData.type ) switch ( requestData.type )
{ {
case Tomahawk::InfoSystem::InfoArtistReleases:
{
QVariantMap returnedData = output.value< QVariantMap >();
QStringList albums = returnedData[ "albums" ].toStringList();
QList<album_ptr> al;
Tomahawk::InfoSystem::InfoStringHash inputInfo;
inputInfo = requestData.input.value< InfoSystem::InfoStringHash >();
artist_ptr artist = Artist::get( inputInfo[ "artist" ], false );
if ( artist.isNull() )
return;
foreach ( const QString& albumName, albums )
{
Tomahawk::album_ptr album = Tomahawk::Album::get( artist, albumName, false );
al << album;
}
QModelIndex idx = index( requestData.customData[ "row" ].toInt(), 0, QModelIndex() );
if ( requestData.customData[ "refetch" ].toBool() && !al.count() )
{
setMode( DatabaseMode );
Tomahawk::InfoSystem::InfoStringHash inputInfo;
inputInfo = requestData.input.value< InfoSystem::InfoStringHash >();
artist_ptr artist = Artist::get( inputInfo[ "artist" ], false );
addAlbums( artist, idx );
}
else
onAlbumsAdded( al, idx );
break;
}
case Tomahawk::InfoSystem::InfoAlbumSongs: case Tomahawk::InfoSystem::InfoAlbumSongs:
{ {
m_receivedInfoData.append( requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >() ); m_receivedInfoData.append( requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >() );

View File

@@ -96,8 +96,8 @@ public:
void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order ); void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order );
void addArtists( const Tomahawk::artist_ptr& artist ); void addArtists( const Tomahawk::artist_ptr& artist );
void addAlbums( const Tomahawk::artist_ptr& artist, const QModelIndex& parent, bool autoRefetch = false );
void addTracks( const Tomahawk::album_ptr& album, const QModelIndex& parent, bool autoRefetch = false ); void addTracks( const Tomahawk::album_ptr& album, const QModelIndex& parent, bool autoRefetch = false );
void fetchAlbums( const Tomahawk::artist_ptr& artist );
void getCover( const QModelIndex& index ); void getCover( const QModelIndex& index );
@@ -130,6 +130,8 @@ public slots:
virtual void setRepeatMode( Tomahawk::PlaylistInterface::RepeatMode /*mode*/ ) {} virtual void setRepeatMode( Tomahawk::PlaylistInterface::RepeatMode /*mode*/ ) {}
virtual void setShuffled( bool /*shuffled*/ ) {} virtual void setShuffled( bool /*shuffled*/ ) {}
void addAlbums( const QModelIndex& parent, const QList<Tomahawk::album_ptr>& albums );
signals: signals:
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled ); void shuffleModeChanged( bool enabled );
@@ -146,8 +148,7 @@ protected:
private slots: private slots:
void onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists ); void onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists );
void onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QModelIndex& index ); void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, Tomahawk::ModelMode mode );
void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, const QVariant& variant );
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QModelIndex& index ); void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QModelIndex& index );
void onTracksFound( const QList<Tomahawk::query_ptr>& tracks, const QVariant& variant ); void onTracksFound( const QList<Tomahawk::query_ptr>& tracks, const QVariant& variant );

View File

@@ -85,10 +85,6 @@ AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, ModelMode st
connect( m_tracksModel, SIGNAL( loadingStarted() ), SLOT( onLoadingStarted() ) ); connect( m_tracksModel, SIGNAL( loadingStarted() ), SLOT( onLoadingStarted() ) );
connect( m_tracksModel, SIGNAL( loadingFinished() ), SLOT( onLoadingFinished() ) ); connect( m_tracksModel, SIGNAL( loadingFinished() ), SLOT( onLoadingFinished() ) );
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
load( album ); load( album );
} }
@@ -217,28 +213,15 @@ AlbumInfoWidget::loadAlbums( bool autoRefetch )
{ {
m_albumsModel->clear(); m_albumsModel->clear();
if ( !m_buttonAlbums->isChecked() ) connect( m_album->artist().data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ),
{ SLOT( gotAlbums( QList<Tomahawk::album_ptr> ) ) );
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums();
cmd->setArtist( m_album->artist() );
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ), ModelMode mode = m_buttonAlbums->isChecked() ? InfoSystemMode : DatabaseMode;
SLOT( gotAlbums( QList<Tomahawk::album_ptr> ) ) ); gotAlbums( m_album->artist()->albums( mode ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); /* tDebug() << "Auto refetching";
} m_buttonAlbums->setChecked( false );
else onAlbumsModeToggle();*/
{
Tomahawk::InfoSystem::InfoStringHash artistInfo;
artistInfo["artist"] = m_album->artist()->name();
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.customData["refetch"] = autoRefetch;
requestData.caller = m_infoId;
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
requestData.type = Tomahawk::InfoSystem::InfoArtistReleases;
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
}
} }
@@ -264,68 +247,6 @@ AlbumInfoWidget::gotAlbums( const QList<Tomahawk::album_ptr>& albums )
} }
void
AlbumInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
{
if ( requestData.caller != m_infoId )
{
return;
}
InfoSystem::InfoStringHash trackInfo;
trackInfo = requestData.input.value< InfoSystem::InfoStringHash >();
if ( output.canConvert< QVariantMap >() )
{
if ( requestData.type == InfoSystem::InfoArtistReleases && trackInfo["artist"] != m_album->artist()->name() )
{
qDebug() << "Returned info was for:" << trackInfo["artist"] << "- was looking for:" << m_album->artist()->name();
return;
}
}
QVariantMap returnedData = output.value< QVariantMap >();
switch ( requestData.type )
{
case Tomahawk::InfoSystem::InfoArtistReleases:
{
QStringList albums = returnedData[ "albums" ].toStringList();
QList<album_ptr> al;
Tomahawk::InfoSystem::InfoStringHash inputInfo;
inputInfo = requestData.input.value< InfoSystem::InfoStringHash >();
artist_ptr artist = Artist::get( inputInfo[ "artist" ], false );
if ( artist.isNull() )
return;
foreach ( const QString& albumName, albums )
{
Tomahawk::album_ptr album = Tomahawk::Album::get( artist, albumName, false );
al << album;
}
if ( al.count() )
{
tDebug() << "Adding" << al.count() << "albums";
gotAlbums( al );
}
else if ( requestData.customData[ "refetch" ].toBool() )
{
tDebug() << "Auto refetching";
m_buttonAlbums->setChecked( false );
onAlbumsModeToggle();
}
break;
}
default:
return;
}
}
void void
AlbumInfoWidget::changeEvent( QEvent* e ) AlbumInfoWidget::changeEvent( QEvent* e )
{ {

View File

@@ -98,8 +98,6 @@ private slots:
void gotAlbums( const QList<Tomahawk::album_ptr>& albums ); void gotAlbums( const QList<Tomahawk::album_ptr>& albums );
void onAlbumCoverUpdated(); void onAlbumCoverUpdated();
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
void onModeToggle(); void onModeToggle();
void onAlbumsModeToggle(); void onAlbumsModeToggle();

View File

@@ -132,7 +132,7 @@ void
ArtistInfoWidget::onModeToggle() ArtistInfoWidget::onModeToggle()
{ {
m_albumsModel->setMode( m_button->isChecked() ? InfoSystemMode : DatabaseMode ); m_albumsModel->setMode( m_button->isChecked() ? InfoSystemMode : DatabaseMode );
m_albumsModel->addAlbums( m_artist, QModelIndex() ); m_albumsModel->addAlbums( QModelIndex(), m_artist->albums( m_albumsModel->mode() ) );
} }
@@ -192,7 +192,8 @@ ArtistInfoWidget::load( const artist_ptr& artist )
m_artist = artist; m_artist = artist;
m_title = artist->name(); m_title = artist->name();
m_albumsModel->addAlbums( artist, QModelIndex(), true );
m_albumsModel->fetchAlbums( artist );
Tomahawk::InfoSystem::InfoStringHash artistInfo; Tomahawk::InfoSystem::InfoStringHash artistInfo;
artistInfo["artist"] = artist->name(); artistInfo["artist"] = artist->name();
@@ -220,6 +221,12 @@ ArtistInfoWidget::load( const artist_ptr& artist )
} }
void
ArtistInfoWidget::onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, ModelMode mode )
{
}
void void
ArtistInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) ArtistInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
{ {

View File

@@ -96,6 +96,8 @@ private slots:
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
void onArtistImageUpdated(); void onArtistImageUpdated();
void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, Tomahawk::ModelMode mode );
void onModeToggle(); void onModeToggle();
void onLoadingStarted(); void onLoadingStarted();
void onLoadingFinished(); void onLoadingFinished();