1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-25 02:09:48 +01:00

* Directly query artist / albums objects for their data.

This commit is contained in:
Christian Muehlhaeuser 2012-05-18 12:09:58 +02:00
parent bf3e2ccb01
commit fe58726b69
2 changed files with 41 additions and 41 deletions

View File

@ -29,6 +29,7 @@
#include "database/DatabaseCommand_AllAlbums.h"
#include "database/DatabaseCommand_AllTracks.h"
#include "database/Database.h"
#include "AlbumPlaylistInterface.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
@ -55,6 +56,9 @@ TreeModel::TreeModel( QObject* parent )
TreeModel::~TreeModel()
{
tDebug() << Q_FUNC_INFO;
delete m_rootItem;
}
@ -619,11 +623,15 @@ TreeModel::onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, ModelMode mo
if ( m_mode != mode )
return;
const artist_ptr artist = qobject_cast< Artist* >( sender() )->weakRef().toStrongRef();
disconnect( artist.data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ),
this, SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ) );
Artist* artist = qobject_cast< Artist* >( sender() );
if ( !artist )
return;
const QModelIndex parent = indexFromArtist( artist );
const artist_ptr artistp = artist->weakRef().toStrongRef();
disconnect( artist, SIGNAL( albumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ),
this, SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ) );
const QModelIndex parent = indexFromArtist( artistp );
addAlbums( parent, albums );
}
@ -663,40 +671,10 @@ TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent, bool au
{
emit loadingStarted();
QList< QVariant > rows;
rows << parent.row();
rows << parent.parent().row();
connect( album.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
SLOT( onTracksFound( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ) );
if ( m_mode == DatabaseMode )
{
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_collection );
cmd->setAlbum( album );
cmd->setData( QVariant( rows ) );
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
SLOT( onTracksFound( QList<Tomahawk::query_ptr>, QVariant ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
else if ( m_mode == InfoSystemMode )
{
Tomahawk::InfoSystem::InfoStringHash artistInfo;
artistInfo["artist"] = album->artist()->name();
artistInfo["album"] = album->name();
m_receivedInfoData.removeAll( artistInfo );
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = m_infoId;
requestData.customData["rows"] = rows;
requestData.customData["refetch"] = autoRefetch;
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
requestData.type = Tomahawk::InfoSystem::InfoAlbumSongs;
requestData.timeoutMillis = 0;
requestData.allSources = true;
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
}
else
Q_ASSERT( false );
onTracksAdded( album->tracks( m_mode, m_collection ), parent );
}
@ -835,11 +813,14 @@ TreeModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QModel
void
TreeModel::onTracksFound( const QList<Tomahawk::query_ptr>& tracks, const QVariant& variant )
TreeModel::onTracksFound( const QList<Tomahawk::query_ptr>& tracks, Tomahawk::ModelMode mode, Tomahawk::collection_ptr collection )
{
QList< QVariant > rows = variant.toList();
QModelIndex idx = index( rows.first().toUInt(), 0, index( rows.at( 1 ).toUInt(), 0, QModelIndex() ) );
if ( mode != m_mode || collection != m_collection )
return;
Album* album = qobject_cast<Album*>( sender() );
QModelIndex idx = indexFromAlbum( album->weakRef().toStrongRef() );
onTracksAdded( tracks, idx );
}
@ -977,3 +958,21 @@ TreeModel::indexFromArtist( const Tomahawk::artist_ptr& artist ) const
return QModelIndex();
}
QModelIndex
TreeModel::indexFromAlbum( const Tomahawk::album_ptr& album ) const
{
QModelIndex artistIdx = indexFromArtist( album->artist() );
for ( int i = 0; i < rowCount( artistIdx ); i++ )
{
QModelIndex idx = index( i, 0, artistIdx );
TreeModelItem* item = itemFromIndex( idx );
if ( item && item->album() == album )
{
return idx;
}
}
return QModelIndex();
}

View File

@ -112,6 +112,7 @@ public:
virtual void setIcon( const QPixmap& pixmap ) { m_icon = pixmap; }
QModelIndex indexFromArtist( const Tomahawk::artist_ptr& artist ) const;
QModelIndex indexFromAlbum( const Tomahawk::album_ptr& album ) const;
TreeModelItem* itemFromIndex( const QModelIndex& index ) const
{
if ( index.isValid() )
@ -150,7 +151,7 @@ private slots:
void onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists );
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 );
void onTracksFound( const QList<Tomahawk::query_ptr>& tracks, Tomahawk::ModelMode mode, Tomahawk::collection_ptr collection );
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );