1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +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 Tomahawk::collection_ptr
TreeModel::collection() const TreeModel::collection() const
{ {
@@ -613,7 +622,7 @@ TreeModel::addAlbums( const artist_ptr& artist, const QModelIndex& parent )
cmd->setData( parent.row() ); cmd->setData( parent.row() );
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ), 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 ) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
} }
@@ -635,7 +644,7 @@ TreeModel::addAlbums( const artist_ptr& artist, const QModelIndex& parent )
void void
TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent ) TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent, bool autoRefetch )
{ {
emit loadingStarted(); emit loadingStarted();
@@ -650,7 +659,7 @@ TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent )
cmd->setData( QVariant( rows ) ); cmd->setData( QVariant( rows ) );
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ), 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 ) ); 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["artist"] = album->artist()->name();
artistInfo["album"] = album->name(); artistInfo["album"] = album->name();
m_receivedInfoData.remove( artistInfo ); m_receivedInfoData.removeAll( artistInfo );
Tomahawk::InfoSystem::InfoRequestData requestData; Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = m_infoId; requestData.caller = m_infoId;
requestData.customData["rows"] = QVariant( rows ); requestData.customData["rows"] = QVariant( rows );
requestData.customData["refetch"] = QVariant( autoRefetch );
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo ); requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
requestData.type = Tomahawk::InfoSystem::InfoAlbumSongs; requestData.type = Tomahawk::InfoSystem::InfoAlbumSongs;
requestData.timeoutMillis = 0; requestData.timeoutMillis = 0;
@@ -777,13 +787,12 @@ TreeModel::onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists )
void 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(); emit loadingFinished();
if ( !albums.count() ) if ( !albums.count() )
return; return;
QModelIndex parent = index( data.toInt(), 0, QModelIndex() );
TreeModelItem* parentItem = itemFromIndex( parent ); TreeModelItem* parentItem = itemFromIndex( parent );
QPair< int, int > crows; QPair< int, int > crows;
@@ -808,16 +817,12 @@ TreeModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QVaria
void 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(); emit loadingFinished();
if ( !tracks.count() ) if ( !tracks.count() )
return; 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 ); TreeModelItem* parentItem = itemFromIndex( parent );
QPair< int, int > crows; 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 void
TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) 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 ); Tomahawk::album_ptr album = Tomahawk::Album::get( artist, albumName, false );
al << album; al << album;
} }
onAlbumsAdded( al, requestData.customData[ "row" ] );
QModelIndex idx = index( requestData.customData[ "row" ].toInt(), 0, QModelIndex() );
onAlbumsAdded( al, idx );
break; break;
} }
case Tomahawk::InfoSystem::InfoAlbumSongs: case Tomahawk::InfoSystem::InfoAlbumSongs:
{ {
if ( m_receivedInfoData.contains( requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >() ) ) m_receivedInfoData.append( requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >() );
break;
emit loadingFinished();
QVariantMap returnedData = output.value< QVariantMap >(); QVariantMap returnedData = output.value< QVariantMap >();
if ( returnedData.isEmpty() ) 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 )
{ {
query_ptr query = Query::get( inputInfo[ "artist" ], trackName, inputInfo[ "album" ], uuid() ); emit loadingFinished();
query->setAlbumPos( trackNo++ );
ql << query; 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; break;
} }

View File

@@ -72,7 +72,7 @@ public:
virtual int columnCount( const QModelIndex& parent = QModelIndex() ) const; virtual int columnCount( const QModelIndex& parent = QModelIndex() ) const;
virtual Tomahawk::ModelMode mode() const { return m_mode; } 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 data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) 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 addArtists( const Tomahawk::artist_ptr& artist );
void addAlbums( const Tomahawk::artist_ptr& artist, const QModelIndex& parent ); 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 ); void getCover( const QModelIndex& index );
@@ -132,6 +132,7 @@ signals:
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled ); void shuffleModeChanged( bool enabled );
void modeChanged( Tomahawk::ModelMode mode );
void itemCountChanged( unsigned int items ); void itemCountChanged( unsigned int items );
void loadingStarted(); void loadingStarted();
@@ -143,8 +144,10 @@ protected:
private slots: private slots:
void onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists ); void onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists );
void onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QVariant& data ); void onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QModelIndex& index );
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const QVariant& data ); 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 infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
void infoSystemFinished( QString target ); void infoSystemFinished( QString target );
@@ -172,7 +175,7 @@ private:
Tomahawk::collection_ptr m_collection; Tomahawk::collection_ptr m_collection;
QHash<qlonglong, QPersistentModelIndex> m_coverHash; QHash<qlonglong, QPersistentModelIndex> m_coverHash;
QSet<Tomahawk::InfoSystem::InfoStringHash> m_receivedInfoData; QList<Tomahawk::InfoSystem::InfoStringHash> m_receivedInfoData;
}; };
#endif // ALBUMMODEL_H #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 ); QList< Tomahawk::result_ptr > rl = m_cache.values( sourceParent );
foreach ( const Tomahawk::result_ptr& cachedResult, rl ) foreach ( const Tomahawk::result_ptr& cachedResult, rl )
{ {
if ( cachedResult.isNull() )
continue;
if ( cachedResult->track() == item->result()->track() && if ( cachedResult->track() == item->result()->track() &&
( cachedResult->albumpos() == item->result()->albumpos() || cachedResult->albumpos() == 0 ) ) ( 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" ) ); m_button->setText( tr( "Click to show Official Tracks" ) );
connect( m_button, SIGNAL( clicked() ), SLOT( onModeToggle() ) ); 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( loadingStarted() ), SLOT( onLoadingStarted() ) );
connect( m_tracksModel, SIGNAL( loadingFinished() ), SLOT( onLoadingFinished() ) ); connect( m_tracksModel, SIGNAL( loadingFinished() ), SLOT( onLoadingFinished() ) );
@@ -91,17 +92,26 @@ AlbumInfoWidget::~AlbumInfoWidget()
delete ui; delete ui;
} }
PlaylistInterface* PlaylistInterface*
AlbumInfoWidget::playlistInterface() const AlbumInfoWidget::playlistInterface() const
{ {
return ui->tracksView->playlistInterface(); return ui->tracksView->playlistInterface();
} }
void void
AlbumInfoWidget::setMode( ModelMode mode ) AlbumInfoWidget::setMode( ModelMode mode )
{ {
m_button->setChecked( mode == InfoSystemMode );
if ( m_tracksModel->mode() != mode ) if ( m_tracksModel->mode() != mode )
onModeToggle(); 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() AlbumInfoWidget::onModeToggle()
{ {
m_tracksModel->setMode( m_button->isChecked() ? InfoSystemMode : DatabaseMode ); m_tracksModel->setMode( m_button->isChecked() ? InfoSystemMode : DatabaseMode );
m_tracksModel->clear();
m_tracksModel->addTracks( m_album, QModelIndex() ); 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(); m_button->show();
} }
bool bool
AlbumInfoWidget::isBeingPlayed() const AlbumInfoWidget::isBeingPlayed() const
{ {
@@ -146,6 +151,7 @@ AlbumInfoWidget::isBeingPlayed() const
return false; return false;
} }
artist_ptr AlbumInfoWidget::descriptionArtist() const artist_ptr AlbumInfoWidget::descriptionArtist() const
{ {
if ( !m_album.isNull() && !m_album->artist().isNull() ) if ( !m_album.isNull() && !m_album->artist().isNull() )
@@ -154,6 +160,7 @@ artist_ptr AlbumInfoWidget::descriptionArtist() const
return artist_ptr(); return artist_ptr();
} }
ViewPage::DescriptionType ViewPage::DescriptionType
AlbumInfoWidget::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() ) ); 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(); DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums();
cmd->setArtist( album->artist() ); cmd->setArtist( album->artist() );

View File

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

View File

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