1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-14 13:01:53 +02:00

* Fixed TWK-556: Auto switch to super collection mode if we don't have any 'offical' information available.

This commit is contained in:
Christian Muehlhaeuser 2011-11-28 08:16:43 +01:00
parent a8b655fef8
commit c850fa3520
6 changed files with 106 additions and 47 deletions

View File

@ -75,6 +75,15 @@ TreeModel::clear()
}
void
TreeModel::setMode( ModelMode mode )
{
clear();
m_mode = mode;
emit modeChanged( mode );
}
Tomahawk::collection_ptr
TreeModel::collection() const
{
@ -613,7 +622,7 @@ TreeModel::addAlbums( const artist_ptr& artist, const QModelIndex& parent )
cmd->setData( parent.row() );
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
SLOT( onAlbumsAdded( QList<Tomahawk::album_ptr>, QVariant ) ) );
SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, QVariant ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
@ -635,7 +644,7 @@ TreeModel::addAlbums( const artist_ptr& artist, const QModelIndex& parent )
void
TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent )
TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent, bool autoRefetch )
{
emit loadingStarted();
@ -650,7 +659,7 @@ TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent )
cmd->setData( QVariant( rows ) );
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
SLOT( onTracksAdded( QList<Tomahawk::query_ptr>, QVariant ) ) );
SLOT( onTracksFound( QList<Tomahawk::query_ptr>, QVariant ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
@ -660,10 +669,11 @@ TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent )
artistInfo["artist"] = album->artist()->name();
artistInfo["album"] = album->name();
m_receivedInfoData.remove( artistInfo );
m_receivedInfoData.removeAll( artistInfo );
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = m_infoId;
requestData.customData["rows"] = QVariant( rows );
requestData.customData["refetch"] = QVariant( autoRefetch );
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
requestData.type = Tomahawk::InfoSystem::InfoAlbumSongs;
requestData.timeoutMillis = 0;
@ -777,13 +787,12 @@ TreeModel::onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists )
void
TreeModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QVariant& data )
TreeModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QModelIndex& parent )
{
emit loadingFinished();
if ( !albums.count() )
return;
QModelIndex parent = index( data.toInt(), 0, QModelIndex() );
TreeModelItem* parentItem = itemFromIndex( parent );
QPair< int, int > crows;
@ -808,16 +817,12 @@ TreeModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QVaria
void
TreeModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QVariant& data )
TreeModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QModelIndex& parent )
{
emit loadingFinished();
if ( !tracks.count() )
return;
QList< QVariant > rows = data.toList();
tDebug() << "Adding to:" << rows;
QModelIndex parent = index( rows.first().toUInt(), 0, index( rows.at( 1 ).toUInt(), 0, QModelIndex() ) );
TreeModelItem* parentItem = itemFromIndex( parent );
QPair< int, int > crows;
@ -844,6 +849,24 @@ TreeModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QVaria
}
void
TreeModel::onTracksFound( const QList<Tomahawk::query_ptr>& tracks, const QVariant& variant )
{
QList< QVariant > rows = variant.toList();
QModelIndex idx = index( rows.first().toUInt(), 0, index( rows.at( 1 ).toUInt(), 0, QModelIndex() ) );
onTracksAdded( tracks, idx );
}
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 )
{
@ -897,38 +920,59 @@ TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QV
Tomahawk::album_ptr album = Tomahawk::Album::get( artist, albumName, false );
al << album;
}
onAlbumsAdded( al, requestData.customData[ "row" ] );
QModelIndex idx = index( requestData.customData[ "row" ].toInt(), 0, QModelIndex() );
onAlbumsAdded( al, idx );
break;
}
case Tomahawk::InfoSystem::InfoAlbumSongs:
{
if ( m_receivedInfoData.contains( requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >() ) )
break;
emit loadingFinished();
m_receivedInfoData.append( requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >() );
QVariantMap returnedData = output.value< QVariantMap >();
if ( returnedData.isEmpty() )
break;
m_receivedInfoData.insert( requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >() );
QStringList tracks = returnedData[ "tracks" ].toStringList();
QList<query_ptr> ql;
Tomahawk::InfoSystem::InfoStringHash inputInfo;
inputInfo = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >();
unsigned int trackNo = 1;
foreach ( const QString& trackName, tracks )
if ( !returnedData.isEmpty() )
{
query_ptr query = Query::get( inputInfo[ "artist" ], trackName, inputInfo[ "album" ], uuid() );
query->setAlbumPos( trackNo++ );
ql << query;
emit loadingFinished();
QList< QVariant > rows = requestData.customData[ "rows" ].toList();
QModelIndex idx = index( rows.first().toUInt(), 0, index( rows.at( 1 ).toUInt(), 0, QModelIndex() ) );
if ( rowCount( idx ) )
return;
Tomahawk::InfoSystem::InfoStringHash inputInfo;
inputInfo = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >();
QStringList tracks = returnedData[ "tracks" ].toStringList();
QList<query_ptr> ql;
unsigned int trackNo = 1;
foreach ( const QString& trackName, tracks )
{
query_ptr query = Query::get( inputInfo[ "artist" ], trackName, inputInfo[ "album" ], uuid() );
query->setAlbumPos( trackNo++ );
ql << query;
}
onTracksAdded( ql, idx );
}
else if ( m_receivedInfoData.count() == 2 /* FIXME */ )
{
if ( requestData.customData[ "refetch" ].toInt() > 0 )
{
setMode( DatabaseMode );
Tomahawk::InfoSystem::InfoStringHash inputInfo;
inputInfo = requestData.input.value< InfoSystem::InfoStringHash >();
artist_ptr artist = Artist::get( inputInfo[ "artist" ], false );
album_ptr album = Album::get( artist, inputInfo[ "album" ], false );
addTracks( album, QModelIndex() );
}
else
emit loadingFinished();
}
onTracksAdded( ql, requestData.customData[ "rows" ] );
break;
}

View File

@ -72,7 +72,7 @@ public:
virtual int columnCount( const QModelIndex& parent = QModelIndex() ) const;
virtual Tomahawk::ModelMode mode() const { return m_mode; }
virtual void setMode( Tomahawk::ModelMode mode ) { m_mode = mode; }
virtual void setMode( Tomahawk::ModelMode mode );
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
@ -95,7 +95,7 @@ public:
void addArtists( const Tomahawk::artist_ptr& artist );
void addAlbums( const Tomahawk::artist_ptr& artist, const QModelIndex& parent );
void addTracks( const Tomahawk::album_ptr& album, const QModelIndex& parent );
void addTracks( const Tomahawk::album_ptr& album, const QModelIndex& parent, bool autoRefetch = false );
void getCover( const QModelIndex& index );
@ -132,6 +132,7 @@ signals:
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );
void modeChanged( Tomahawk::ModelMode mode );
void itemCountChanged( unsigned int items );
void loadingStarted();
@ -143,8 +144,10 @@ protected:
private slots:
void onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists );
void onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QVariant& data );
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QVariant& data );
void onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QModelIndex& index );
void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, const QVariant& variant );
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QModelIndex& index );
void onTracksFound( const QList<Tomahawk::query_ptr>& tracks, const QVariant& variant );
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
void infoSystemFinished( QString target );
@ -172,7 +175,7 @@ private:
Tomahawk::collection_ptr m_collection;
QHash<qlonglong, QPersistentModelIndex> m_coverHash;
QSet<Tomahawk::InfoSystem::InfoStringHash> m_receivedInfoData;
QList<Tomahawk::InfoSystem::InfoStringHash> m_receivedInfoData;
};
#endif // ALBUMMODEL_H

View File

@ -210,6 +210,9 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent
QList< Tomahawk::result_ptr > rl = m_cache.values( sourceParent );
foreach ( const Tomahawk::result_ptr& cachedResult, rl )
{
if ( cachedResult.isNull() )
continue;
if ( cachedResult->track() == item->result()->track() &&
( cachedResult->albumpos() == item->result()->albumpos() || cachedResult->albumpos() == 0 ) )
{

View File

@ -73,6 +73,7 @@ AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, ModelMode st
m_button->setText( tr( "Click to show Official Tracks" ) );
connect( m_button, SIGNAL( clicked() ), SLOT( onModeToggle() ) );
connect( m_tracksModel, SIGNAL( modeChanged( Tomahawk::ModelMode ) ), SLOT( setMode( Tomahawk::ModelMode ) ) );
connect( m_tracksModel, SIGNAL( loadingStarted() ), SLOT( onLoadingStarted() ) );
connect( m_tracksModel, SIGNAL( loadingFinished() ), SLOT( onLoadingFinished() ) );
@ -91,17 +92,26 @@ AlbumInfoWidget::~AlbumInfoWidget()
delete ui;
}
PlaylistInterface*
AlbumInfoWidget::playlistInterface() const
{
return ui->tracksView->playlistInterface();
}
void
AlbumInfoWidget::setMode( ModelMode mode )
{
m_button->setChecked( mode == InfoSystemMode );
if ( m_tracksModel->mode() != mode )
onModeToggle();
if ( mode == InfoSystemMode )
m_button->setText( tr( "Click to show Super Collection Tracks" ) );
else
m_button->setText( tr( "Click to show Official Tracks" ) );
}
@ -109,13 +119,7 @@ void
AlbumInfoWidget::onModeToggle()
{
m_tracksModel->setMode( m_button->isChecked() ? InfoSystemMode : DatabaseMode );
m_tracksModel->clear();
m_tracksModel->addTracks( m_album, QModelIndex() );
if ( m_button->isChecked() )
m_button->setText( tr( "Click to show Super Collection Tracks" ) );
else
m_button->setText( tr( "Click to show Official Tracks" ) );
}
@ -134,6 +138,7 @@ AlbumInfoWidget::onLoadingFinished()
m_button->show();
}
bool
AlbumInfoWidget::isBeingPlayed() const
{
@ -146,6 +151,7 @@ AlbumInfoWidget::isBeingPlayed() const
return false;
}
artist_ptr AlbumInfoWidget::descriptionArtist() const
{
if ( !m_album.isNull() && !m_album->artist().isNull() )
@ -154,6 +160,7 @@ artist_ptr AlbumInfoWidget::descriptionArtist() const
return artist_ptr();
}
ViewPage::DescriptionType
AlbumInfoWidget::descriptionType()
{
@ -173,7 +180,7 @@ AlbumInfoWidget::load( const album_ptr& album )
ui->albumsLabel->setText( tr( "Other Albums by %1" ).arg( album->artist()->name() ) );
m_tracksModel->addTracks( album, QModelIndex() );
m_tracksModel->addTracks( album, QModelIndex(), true );
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums();
cmd->setArtist( album->artist() );

View File

@ -64,8 +64,6 @@ public:
virtual QString longDescription() const { return m_longDescription; }
virtual QPixmap pixmap() const { if ( m_pixmap.isNull() ) return Tomahawk::ViewPage::pixmap(); else return m_pixmap; }
void setMode( Tomahawk::ModelMode mode );
virtual bool isTemporaryPage() const { return true; }
virtual bool showStatsBar() const { return false; }
@ -73,6 +71,7 @@ public:
virtual bool isBeingPlayed() const;
public slots:
void setMode( Tomahawk::ModelMode mode );
/** \brief Loads information for a given album.
* \param album The album that you want to load information for.

View File

@ -100,6 +100,7 @@ ArtistInfoWidget::~ArtistInfoWidget()
delete ui;
}
PlaylistInterface*
ArtistInfoWidget::playlistInterface() const
{
@ -136,6 +137,7 @@ ArtistInfoWidget::onLoadingFinished()
m_button->show();
}
bool
ArtistInfoWidget::isBeingPlayed() const
{
@ -151,6 +153,7 @@ ArtistInfoWidget::isBeingPlayed() const
return false;
}
bool
ArtistInfoWidget::jumpToCurrentTrack()
{