mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 15:47:38 +02:00
* Added Artist::albums( ... ) for convenience. Removes a lot of DRY code.
This commit is contained in:
@@ -412,6 +412,8 @@ TomahawkApp::registerMetaTypes()
|
||||
|
||||
qRegisterMetaType<GeneratorMode>("GeneratorMode");
|
||||
qRegisterMetaType<Tomahawk::GeneratorMode>("Tomahawk::GeneratorMode");
|
||||
qRegisterMetaType<ModelMode>("Tomahawk::ModelMode");
|
||||
qRegisterMetaType<Tomahawk::ModelMode>("Tomahawk::ModelMode");
|
||||
|
||||
// Extra definition for namespaced-versions of signals/slots required
|
||||
qRegisterMetaType< Tomahawk::source_ptr >("Tomahawk::source_ptr");
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include "database/Database.h"
|
||||
#include "database/DatabaseImpl.h"
|
||||
#include "Query.h"
|
||||
#include "database/DatabaseCommand_AllAlbums.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
@@ -32,6 +33,8 @@ using namespace Tomahawk;
|
||||
|
||||
Artist::~Artist()
|
||||
{
|
||||
m_ownRef.clear();
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
delete m_cover;
|
||||
#endif
|
||||
@@ -65,6 +68,8 @@ Artist::get( unsigned int id, const QString& name )
|
||||
}
|
||||
|
||||
artist_ptr a = artist_ptr( new Artist( id, name ), &QObject::deleteLater );
|
||||
a->setWeakRef( a.toWeakRef() );
|
||||
|
||||
if ( id > 0 )
|
||||
s_artists.insert( id, a );
|
||||
|
||||
@@ -78,6 +83,7 @@ Artist::Artist( unsigned int id, const QString& name )
|
||||
, m_name( name )
|
||||
, m_infoLoaded( false )
|
||||
, m_infoLoading( false )
|
||||
, m_infoJobs( 0 )
|
||||
#ifndef ENABLE_HEADLESS
|
||||
, m_cover( 0 )
|
||||
#endif
|
||||
@@ -92,10 +98,160 @@ Artist::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
|
||||
Tomahawk::ArtistPlaylistInterface* api = dynamic_cast< Tomahawk::ArtistPlaylistInterface* >( playlistInterface().data() );
|
||||
if ( api )
|
||||
api->addQueries( 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
|
||||
QPixmap
|
||||
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(),
|
||||
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(),
|
||||
SIGNAL( finished( QString ) ),
|
||||
SLOT( infoSystemFinished( QString ) ) );
|
||||
SLOT( infoSystemFinished( QString ) ), Qt::UniqueConnection );
|
||||
|
||||
m_infoJobs++;
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||
|
||||
m_infoLoading = true;
|
||||
@@ -132,6 +289,7 @@ Artist::cover( const QSize& size, bool forceLoad ) const
|
||||
{
|
||||
m_cover = new QPixmap();
|
||||
m_cover->loadFromData( m_coverBuffer );
|
||||
m_coverBuffer.clear();
|
||||
}
|
||||
|
||||
if ( m_cover && !m_cover->isNull() && !size.isEmpty() )
|
||||
@@ -155,47 +313,6 @@ Artist::cover( const QSize& size, bool forceLoad ) const
|
||||
#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
|
||||
Artist::playlistInterface()
|
||||
{
|
||||
|
@@ -49,20 +49,29 @@ public:
|
||||
unsigned int id() const { return m_id; }
|
||||
QString name() const { return m_name; }
|
||||
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
|
||||
QPixmap cover( const QSize& size, bool forceLoad = true ) const;
|
||||
#endif
|
||||
bool infoLoaded() const { return m_infoLoaded; }
|
||||
|
||||
Tomahawk::playlistinterface_ptr playlistInterface();
|
||||
|
||||
QWeakPointer< Tomahawk::Artist > weakRef() { return m_ownRef; }
|
||||
void setWeakRef( QWeakPointer< Tomahawk::Artist > weakRef ) { m_ownRef = weakRef; }
|
||||
|
||||
signals:
|
||||
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks );
|
||||
void albumsAdded( const QList<Tomahawk::album_ptr>& albums, Tomahawk::ModelMode mode );
|
||||
|
||||
void updated();
|
||||
void coverChanged();
|
||||
|
||||
private slots:
|
||||
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 infoSystemFinished( QString target );
|
||||
@@ -73,17 +82,25 @@ private:
|
||||
unsigned int m_id;
|
||||
QString m_name;
|
||||
QString m_sortname;
|
||||
QByteArray m_coverBuffer;
|
||||
|
||||
bool m_infoLoaded;
|
||||
mutable bool m_infoLoading;
|
||||
QHash<Tomahawk::ModelMode, bool> m_albumsLoaded;
|
||||
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
|
||||
mutable QPixmap* m_cover;
|
||||
mutable QHash< int, QPixmap > m_coverCache;
|
||||
#endif
|
||||
|
||||
Tomahawk::playlistinterface_ptr m_playlistInterface;
|
||||
|
||||
QWeakPointer< Tomahawk::Artist > m_ownRef;
|
||||
};
|
||||
|
||||
} // ns
|
||||
|
@@ -61,15 +61,17 @@ namespace Tomahawk
|
||||
typedef QString QID; //query id
|
||||
typedef QString RID; //result id
|
||||
|
||||
enum GeneratorMode {
|
||||
enum GeneratorMode
|
||||
{
|
||||
OnDemand = 0,
|
||||
Static
|
||||
};
|
||||
|
||||
enum ModelMode
|
||||
{
|
||||
DatabaseMode = 0,
|
||||
InfoSystemMode
|
||||
Mixed = 0,
|
||||
DatabaseMode,
|
||||
InfoSystemMode,
|
||||
};
|
||||
|
||||
class ExternalResolver;
|
||||
|
@@ -47,6 +47,8 @@ public:
|
||||
virtual bool doesMutates() const { return false; }
|
||||
virtual QString commandname() const { return "allalbums"; }
|
||||
|
||||
Tomahawk::collection_ptr collection() const { return m_collection; }
|
||||
|
||||
void execForCollection( DatabaseImpl* );
|
||||
void execForArtist( DatabaseImpl* );
|
||||
|
||||
|
@@ -172,12 +172,12 @@ TreeModel::fetchMore( const QModelIndex& parent )
|
||||
parentItem->fetchingMore = true;
|
||||
if ( !parentItem->artist().isNull() )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Loading Artist:" << parentItem->artist()->name();
|
||||
addAlbums( parentItem->artist(), parent );
|
||||
tDebug() << Q_FUNC_INFO << "Loading Artist:" << parentItem->artist()->name();
|
||||
fetchAlbums( parentItem->artist() );
|
||||
}
|
||||
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 );
|
||||
}
|
||||
else
|
||||
@@ -601,35 +601,57 @@ TreeModel::addArtists( const artist_ptr& artist )
|
||||
|
||||
|
||||
void
|
||||
TreeModel::addAlbums( const artist_ptr& artist, const QModelIndex& parent, bool autoRefetch )
|
||||
TreeModel::fetchAlbums( const artist_ptr& artist )
|
||||
{
|
||||
emit loadingStarted();
|
||||
|
||||
if ( m_mode == DatabaseMode )
|
||||
{
|
||||
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( m_collection, artist );
|
||||
cmd->setData( parent.row() );
|
||||
connect( artist.data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ),
|
||||
SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ) );
|
||||
|
||||
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
|
||||
SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, QVariant ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
const QModelIndex parent = indexFromArtist( artist );
|
||||
addAlbums( parent, artist->albums( m_mode, m_collection ) );
|
||||
}
|
||||
else if ( m_mode == InfoSystemMode )
|
||||
{
|
||||
Tomahawk::InfoSystem::InfoStringHash artistInfo;
|
||||
artistInfo["artist"] = artist->name();
|
||||
|
||||
Tomahawk::InfoSystem::InfoRequestData requestData;
|
||||
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 );
|
||||
|
||||
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 );
|
||||
}
|
||||
else
|
||||
Q_ASSERT( false );
|
||||
|
||||
|
||||
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 )
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
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
|
||||
TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
|
||||
{
|
||||
@@ -867,43 +851,6 @@ TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QV
|
||||
|
||||
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:
|
||||
{
|
||||
m_receivedInfoData.append( requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >() );
|
||||
|
@@ -96,8 +96,8 @@ public:
|
||||
void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order );
|
||||
|
||||
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 fetchAlbums( const Tomahawk::artist_ptr& artist );
|
||||
|
||||
void getCover( const QModelIndex& index );
|
||||
|
||||
@@ -130,6 +130,8 @@ public slots:
|
||||
virtual void setRepeatMode( Tomahawk::PlaylistInterface::RepeatMode /*mode*/ ) {}
|
||||
virtual void setShuffled( bool /*shuffled*/ ) {}
|
||||
|
||||
void addAlbums( const QModelIndex& parent, const QList<Tomahawk::album_ptr>& albums );
|
||||
|
||||
signals:
|
||||
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
||||
void shuffleModeChanged( bool enabled );
|
||||
@@ -146,8 +148,7 @@ protected:
|
||||
|
||||
private slots:
|
||||
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, const QVariant& variant );
|
||||
void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, Tomahawk::ModelMode mode );
|
||||
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QModelIndex& index );
|
||||
void onTracksFound( const QList<Tomahawk::query_ptr>& tracks, const QVariant& variant );
|
||||
|
||||
|
@@ -85,10 +85,6 @@ AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, ModelMode st
|
||||
connect( m_tracksModel, SIGNAL( loadingStarted() ), SLOT( onLoadingStarted() ) );
|
||||
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 );
|
||||
}
|
||||
|
||||
@@ -217,28 +213,15 @@ AlbumInfoWidget::loadAlbums( bool autoRefetch )
|
||||
{
|
||||
m_albumsModel->clear();
|
||||
|
||||
if ( !m_buttonAlbums->isChecked() )
|
||||
{
|
||||
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums();
|
||||
cmd->setArtist( m_album->artist() );
|
||||
|
||||
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
|
||||
connect( m_album->artist().data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ),
|
||||
SLOT( gotAlbums( QList<Tomahawk::album_ptr> ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Tomahawk::InfoSystem::InfoStringHash artistInfo;
|
||||
artistInfo["artist"] = m_album->artist()->name();
|
||||
ModelMode mode = m_buttonAlbums->isChecked() ? InfoSystemMode : DatabaseMode;
|
||||
gotAlbums( m_album->artist()->albums( mode ) );
|
||||
|
||||
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 );
|
||||
}
|
||||
/* tDebug() << "Auto refetching";
|
||||
m_buttonAlbums->setChecked( false );
|
||||
onAlbumsModeToggle();*/
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
AlbumInfoWidget::changeEvent( QEvent* e )
|
||||
{
|
||||
|
@@ -98,8 +98,6 @@ private slots:
|
||||
void gotAlbums( const QList<Tomahawk::album_ptr>& albums );
|
||||
void onAlbumCoverUpdated();
|
||||
|
||||
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
|
||||
void onModeToggle();
|
||||
void onAlbumsModeToggle();
|
||||
|
||||
|
@@ -132,7 +132,7 @@ void
|
||||
ArtistInfoWidget::onModeToggle()
|
||||
{
|
||||
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_title = artist->name();
|
||||
m_albumsModel->addAlbums( artist, QModelIndex(), true );
|
||||
|
||||
m_albumsModel->fetchAlbums( artist );
|
||||
|
||||
Tomahawk::InfoSystem::InfoStringHash artistInfo;
|
||||
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
|
||||
ArtistInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
|
||||
{
|
||||
|
@@ -96,6 +96,8 @@ private slots:
|
||||
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
void onArtistImageUpdated();
|
||||
|
||||
void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, Tomahawk::ModelMode mode );
|
||||
|
||||
void onModeToggle();
|
||||
void onLoadingStarted();
|
||||
void onLoadingFinished();
|
||||
|
Reference in New Issue
Block a user