1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 03:40:16 +02: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_AllAlbums.h"
#include "database/DatabaseCommand_AllTracks.h" #include "database/DatabaseCommand_AllTracks.h"
#include "database/Database.h" #include "database/Database.h"
#include "AlbumPlaylistInterface.h"
#include "utils/TomahawkUtils.h" #include "utils/TomahawkUtils.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@@ -55,6 +56,9 @@ TreeModel::TreeModel( QObject* parent )
TreeModel::~TreeModel() 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 ) if ( m_mode != mode )
return; return;
const artist_ptr artist = qobject_cast< Artist* >( sender() )->weakRef().toStrongRef(); Artist* artist = qobject_cast< Artist* >( sender() );
disconnect( artist.data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ), if ( !artist )
return;
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 ) ) ); this, SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ) );
const QModelIndex parent = indexFromArtist( artist ); const QModelIndex parent = indexFromArtist( artistp );
addAlbums( parent, albums ); addAlbums( parent, albums );
} }
@@ -663,40 +671,10 @@ TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent, bool au
{ {
emit loadingStarted(); emit loadingStarted();
QList< QVariant > rows; connect( album.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
rows << parent.row(); SLOT( onTracksFound( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ) );
rows << parent.parent().row();
if ( m_mode == DatabaseMode ) onTracksAdded( album->tracks( m_mode, m_collection ), parent );
{
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 );
} }
@@ -835,11 +813,14 @@ TreeModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QModel
void 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(); if ( mode != m_mode || collection != m_collection )
QModelIndex idx = index( rows.first().toUInt(), 0, index( rows.at( 1 ).toUInt(), 0, QModelIndex() ) ); return;
Album* album = qobject_cast<Album*>( sender() );
QModelIndex idx = indexFromAlbum( album->weakRef().toStrongRef() );
onTracksAdded( tracks, idx ); onTracksAdded( tracks, idx );
} }
@@ -977,3 +958,21 @@ TreeModel::indexFromArtist( const Tomahawk::artist_ptr& artist ) const
return QModelIndex(); 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; } virtual void setIcon( const QPixmap& pixmap ) { m_icon = pixmap; }
QModelIndex indexFromArtist( const Tomahawk::artist_ptr& artist ) const; QModelIndex indexFromArtist( const Tomahawk::artist_ptr& artist ) const;
QModelIndex indexFromAlbum( const Tomahawk::album_ptr& album ) const;
TreeModelItem* itemFromIndex( const QModelIndex& index ) const TreeModelItem* itemFromIndex( const QModelIndex& index ) const
{ {
if ( index.isValid() ) if ( index.isValid() )
@@ -150,7 +151,7 @@ private slots:
void onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists ); void onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists );
void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, Tomahawk::ModelMode mode ); void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, Tomahawk::ModelMode mode );
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, Tomahawk::ModelMode mode, Tomahawk::collection_ptr collection );
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );