From 93ad670828fa5ecee45e31186f7cb4d8857b795b Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 24 Apr 2012 08:06:52 +0200 Subject: [PATCH] * Added Artist::albums( ... ) for convenience. Removes a lot of DRY code. --- src/TomahawkApp.cpp | 4 +- src/libtomahawk/Artist.cpp | 203 ++++++++++++++---- src/libtomahawk/Artist.h | 21 +- src/libtomahawk/Typedefs.h | 8 +- .../database/DatabaseCommand_AllAlbums.h | 2 + src/libtomahawk/playlist/TreeModel.cpp | 147 ++++--------- src/libtomahawk/playlist/TreeModel.h | 7 +- .../widgets/infowidgets/AlbumInfoWidget.cpp | 95 +------- .../widgets/infowidgets/AlbumInfoWidget.h | 2 - .../widgets/infowidgets/ArtistInfoWidget.cpp | 11 +- .../widgets/infowidgets/ArtistInfoWidget.h | 2 + 11 files changed, 259 insertions(+), 243 deletions(-) diff --git a/src/TomahawkApp.cpp b/src/TomahawkApp.cpp index 8529e8b02..e92f2527c 100644 --- a/src/TomahawkApp.cpp +++ b/src/TomahawkApp.cpp @@ -410,8 +410,10 @@ TomahawkApp::registerMetaTypes() qRegisterMetaType< QMap< QString, QMap< unsigned int, unsigned int > > >("QMap< QString, QMap< unsigned int, unsigned int > >"); qRegisterMetaType< PairList >("PairList"); - qRegisterMetaType< GeneratorMode>("GeneratorMode"); + qRegisterMetaType("GeneratorMode"); qRegisterMetaType("Tomahawk::GeneratorMode"); + qRegisterMetaType("Tomahawk::ModelMode"); + qRegisterMetaType("Tomahawk::ModelMode"); // Extra definition for namespaced-versions of signals/slots required qRegisterMetaType< Tomahawk::source_ptr >("Tomahawk::source_ptr"); diff --git a/src/libtomahawk/Artist.cpp b/src/libtomahawk/Artist.cpp index 563dedac9..3bd9bfec0 100644 --- a/src/libtomahawk/Artist.cpp +++ b/src/libtomahawk/Artist.cpp @@ -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& tracks ) Tomahawk::ArtistPlaylistInterface* api = dynamic_cast< Tomahawk::ArtistPlaylistInterface* >( playlistInterface().data() ); if ( api ) api->addQueries( tracks ); + emit tracksAdded( tracks ); } +QList +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, QVariant ) ), + SLOT( onAlbumsFound( QList, QVariant ) ) ); + + Database::instance()->enqueue( QSharedPointer( 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(); + + 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() { diff --git a/src/libtomahawk/Artist.h b/src/libtomahawk/Artist.h index df428846e..8f9459422 100644 --- a/src/libtomahawk/Artist.h +++ b/src/libtomahawk/Artist.h @@ -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 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& tracks ); + void albumsAdded( const QList& albums, Tomahawk::ModelMode mode ); + void updated(); void coverChanged(); private slots: void onTracksAdded( const QList& tracks ); + void onAlbumsFound( const QList& 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 m_albumsLoaded; mutable QString m_uuid; + mutable int m_infoJobs; + QList m_databaseAlbums; + QList 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 diff --git a/src/libtomahawk/Typedefs.h b/src/libtomahawk/Typedefs.h index 1f3ed51cc..cce94d236 100644 --- a/src/libtomahawk/Typedefs.h +++ b/src/libtomahawk/Typedefs.h @@ -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; diff --git a/src/libtomahawk/database/DatabaseCommand_AllAlbums.h b/src/libtomahawk/database/DatabaseCommand_AllAlbums.h index 55a16f79f..d659699d1 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllAlbums.h +++ b/src/libtomahawk/database/DatabaseCommand_AllAlbums.h @@ -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* ); diff --git a/src/libtomahawk/playlist/TreeModel.cpp b/src/libtomahawk/playlist/TreeModel.cpp index 07acb959c..72cb8d61b 100644 --- a/src/libtomahawk/playlist/TreeModel.cpp +++ b/src/libtomahawk/playlist/TreeModel.cpp @@ -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 ) + connect( artist.data(), SIGNAL( albumsAdded( QList, Tomahawk::ModelMode ) ), + SLOT( onAlbumsFound( QList, Tomahawk::ModelMode ) ) ); + + const QModelIndex parent = indexFromArtist( artist ); + addAlbums( parent, artist->albums( m_mode, m_collection ) ); +} + + +void +TreeModel::onAlbumsFound( const QList& 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& 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 ); - cmd->setData( parent.row() ); + albumitem = new TreeModelItem( album, parentItem ); + albumitem->index = createIndex( parentItem->children.count() - 1, 0, albumitem ); + connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); - connect( cmd, SIGNAL( albums( QList, QVariant ) ), - SLOT( onAlbumsFound( QList, QVariant ) ) ); - - Database::instance()->enqueue( QSharedPointer( cmd ) ); + getCover( albumitem->index ); } - 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 ); - } - else - Q_ASSERT( false ); + emit endInsertRows(); } @@ -776,36 +798,6 @@ TreeModel::onArtistsAdded( const QList& artists ) } -void -TreeModel::onAlbumsAdded( const QList& 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& tracks, const QModelIndex& parent ) { @@ -849,14 +841,6 @@ TreeModel::onTracksFound( const QList& tracks, const QVaria } -void -TreeModel::onAlbumsFound( const QList& 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 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 >() ); diff --git a/src/libtomahawk/playlist/TreeModel.h b/src/libtomahawk/playlist/TreeModel.h index 6ed5cd56e..94d3b9a9a 100644 --- a/src/libtomahawk/playlist/TreeModel.h +++ b/src/libtomahawk/playlist/TreeModel.h @@ -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& albums ); + signals: void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); void shuffleModeChanged( bool enabled ); @@ -146,8 +148,7 @@ protected: private slots: void onArtistsAdded( const QList& artists ); - void onAlbumsAdded( const QList& albums, const QModelIndex& index ); - void onAlbumsFound( const QList& albums, const QVariant& variant ); + void onAlbumsFound( const QList& albums, Tomahawk::ModelMode mode ); void onTracksAdded( const QList& tracks, const QModelIndex& index ); void onTracksFound( const QList& tracks, const QVariant& variant ); diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp index e2da944c6..a1f920271 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp @@ -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( m_album->artist().data(), SIGNAL( albumsAdded( QList, Tomahawk::ModelMode ) ), + SLOT( gotAlbums( QList ) ) ); - connect( cmd, SIGNAL( albums( QList, QVariant ) ), - SLOT( gotAlbums( QList ) ) ); - - Database::instance()->enqueue( QSharedPointer( cmd ) ); - } - else - { - 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 ); - } + ModelMode mode = m_buttonAlbums->isChecked() ? InfoSystemMode : DatabaseMode; + gotAlbums( m_album->artist()->albums( mode ) ); + +/* tDebug() << "Auto refetching"; + m_buttonAlbums->setChecked( false ); + onAlbumsModeToggle();*/ } @@ -264,68 +247,6 @@ AlbumInfoWidget::gotAlbums( const QList& 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 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 ) { diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h index 6883e9b16..958748a51 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h @@ -98,8 +98,6 @@ private slots: void gotAlbums( const QList& albums ); void onAlbumCoverUpdated(); - void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); - void onModeToggle(); void onAlbumsModeToggle(); diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp index 9c844f8fd..49728a5f7 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp @@ -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& albums, ModelMode mode ) +{ +} + + void ArtistInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) { diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h index a76b177c4..5469a0c3d 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h @@ -96,6 +96,8 @@ private slots: void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); void onArtistImageUpdated(); + void onAlbumsFound( const QList& albums, Tomahawk::ModelMode mode ); + void onModeToggle(); void onLoadingStarted(); void onLoadingFinished();