mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 07:36:48 +02:00
* Auto-switch to super collection mode when no official info is available on artist & album pages.
This commit is contained in:
@@ -165,6 +165,7 @@ MusicBrainzPlugin::artistSearchSlot()
|
||||
if ( domNodeList.isEmpty() )
|
||||
{
|
||||
emit info( oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
|
||||
tDebug() << Q_FUNC_INFO << doc.toString();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -235,8 +235,11 @@ AlbumView::resizeEvent( QResizeEvent* event )
|
||||
else
|
||||
setSpacing( newSpacing );
|
||||
|
||||
if ( !m_inited && m_proxyModel->rowCount() )
|
||||
if ( !m_inited )
|
||||
{
|
||||
m_inited = true;
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
QListView::resizeEvent( event );
|
||||
|
@@ -610,7 +610,7 @@ TreeModel::addArtists( const artist_ptr& artist )
|
||||
|
||||
|
||||
void
|
||||
TreeModel::addAlbums( const artist_ptr& artist, const QModelIndex& parent )
|
||||
TreeModel::addAlbums( const artist_ptr& artist, const QModelIndex& parent, bool autoRefetch )
|
||||
{
|
||||
emit loadingStarted();
|
||||
|
||||
@@ -633,6 +633,7 @@ TreeModel::addAlbums( const artist_ptr& artist, const QModelIndex& parent )
|
||||
requestData.caller = m_infoId;
|
||||
requestData.customData["row"] = parent.row();
|
||||
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
|
||||
requestData.customData["refetch"] = QVariant( autoRefetch );
|
||||
requestData.type = Tomahawk::InfoSystem::InfoArtistReleases;
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||
}
|
||||
@@ -920,7 +921,19 @@ TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QV
|
||||
}
|
||||
|
||||
QModelIndex idx = index( requestData.customData[ "row" ].toInt(), 0, QModelIndex() );
|
||||
onAlbumsAdded( al, idx );
|
||||
|
||||
if ( requestData.customData[ "refetch" ].toInt() > 0 && !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;
|
||||
}
|
||||
|
@@ -94,7 +94,7 @@ 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 );
|
||||
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 getCover( const QModelIndex& index );
|
||||
|
@@ -22,7 +22,7 @@
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
PlaylistInterface::PlaylistInterface (QObject *parent )
|
||||
PlaylistInterface::PlaylistInterface ( QObject *parent )
|
||||
: m_object( parent )
|
||||
{
|
||||
qRegisterMetaType<Tomahawk::PlaylistInterface::RepeatMode>( "Tomahawk::PlaylistInterface::RepeatMode" );
|
||||
|
@@ -75,7 +75,7 @@ public:
|
||||
|
||||
static void dontDelete( Tomahawk::PlaylistInterface* obj )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << obj;
|
||||
tDebug() << Q_FUNC_INFO << obj;
|
||||
}
|
||||
virtual Tomahawk::playlistinterface_ptr getSharedPointer()
|
||||
{
|
||||
|
@@ -34,14 +34,13 @@
|
||||
#include "widgets/OverlayButton.h"
|
||||
#include "widgets/overlaywidget.h"
|
||||
|
||||
static QString s_aiInfoIdentifier = QString( "AlbumInfoWidget" );
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, ModelMode startingMode, QWidget* parent )
|
||||
: QWidget( parent )
|
||||
, ui( new Ui::AlbumInfoWidget )
|
||||
, m_infoId( uuid() )
|
||||
{
|
||||
ui->setupUi( this );
|
||||
|
||||
@@ -72,7 +71,14 @@ AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, ModelMode st
|
||||
else
|
||||
m_button->setText( tr( "Click to show Official Tracks" ) );
|
||||
|
||||
m_buttonAlbums = new OverlayButton( ui->albumsView );
|
||||
m_buttonAlbums->setCheckable( true );
|
||||
m_buttonAlbums->setChecked( true );
|
||||
m_buttonAlbums->setText( tr( "Click to show Super Collection Albums" ) );
|
||||
m_buttonAlbums->show();
|
||||
|
||||
connect( m_button, SIGNAL( clicked() ), SLOT( onModeToggle() ) );
|
||||
connect( m_buttonAlbums, SIGNAL( clicked() ), SLOT( onAlbumsModeToggle() ) );
|
||||
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() ) );
|
||||
@@ -123,6 +129,18 @@ AlbumInfoWidget::onModeToggle()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlbumInfoWidget::onAlbumsModeToggle()
|
||||
{
|
||||
if ( m_buttonAlbums->isChecked() )
|
||||
m_buttonAlbums->setText( tr( "Click to show Super Collection Albums" ) );
|
||||
else
|
||||
m_buttonAlbums->setText( tr( "Click to show Official Albums" ) );
|
||||
|
||||
loadAlbums();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlbumInfoWidget::onLoadingStarted()
|
||||
{
|
||||
@@ -181,21 +199,14 @@ AlbumInfoWidget::load( const album_ptr& album )
|
||||
ui->albumsLabel->setText( tr( "Other Albums by %1" ).arg( album->artist()->name() ) );
|
||||
|
||||
m_tracksModel->addTracks( album, QModelIndex(), true );
|
||||
|
||||
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums();
|
||||
cmd->setArtist( album->artist() );
|
||||
|
||||
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
|
||||
SLOT( gotAlbums( QList<Tomahawk::album_ptr> ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
loadAlbums( true );
|
||||
|
||||
Tomahawk::InfoSystem::InfoStringHash trackInfo;
|
||||
trackInfo["artist"] = album->artist()->name();
|
||||
trackInfo["album"] = album->name();
|
||||
|
||||
Tomahawk::InfoSystem::InfoRequestData requestData;
|
||||
requestData.caller = s_aiInfoIdentifier;
|
||||
requestData.caller = m_infoId;
|
||||
requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
|
||||
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
|
||||
requestData.customData = QVariantMap();
|
||||
@@ -204,6 +215,36 @@ AlbumInfoWidget::load( const album_ptr& album )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlbumInfoWidget::loadAlbums( bool autoRefetch )
|
||||
{
|
||||
m_albumsModel->clear();
|
||||
|
||||
if ( !m_buttonAlbums->isChecked() )
|
||||
{
|
||||
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums();
|
||||
cmd->setArtist( m_album->artist() );
|
||||
|
||||
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
|
||||
SLOT( gotAlbums( QList<Tomahawk::album_ptr> ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Tomahawk::InfoSystem::InfoStringHash artistInfo;
|
||||
artistInfo["artist"] = m_album->artist()->name();
|
||||
|
||||
Tomahawk::InfoSystem::InfoRequestData requestData;
|
||||
requestData.customData["refetch"] = QVariant( autoRefetch );
|
||||
requestData.caller = m_infoId;
|
||||
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
|
||||
requestData.type = Tomahawk::InfoSystem::InfoArtistReleases;
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlbumInfoWidget::gotAlbums( const QList<Tomahawk::album_ptr>& albums )
|
||||
{
|
||||
@@ -218,7 +259,7 @@ AlbumInfoWidget::gotAlbums( const QList<Tomahawk::album_ptr>& albums )
|
||||
void
|
||||
AlbumInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
|
||||
{
|
||||
if ( requestData.caller != s_aiInfoIdentifier )
|
||||
if ( requestData.caller != m_infoId )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -228,11 +269,16 @@ AlbumInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDa
|
||||
|
||||
if ( output.canConvert< QVariantMap >() )
|
||||
{
|
||||
if ( trackInfo["album"] != m_album->name() )
|
||||
if ( requestData.type == InfoSystem::InfoAlbumCoverArt && trackInfo["album"] != m_album->name() )
|
||||
{
|
||||
qDebug() << "Returned info was for:" << trackInfo["album"] << "- was looking for:" << m_album->name();
|
||||
return;
|
||||
}
|
||||
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 >();
|
||||
@@ -240,13 +286,47 @@ AlbumInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDa
|
||||
{
|
||||
case Tomahawk::InfoSystem::InfoAlbumCoverArt:
|
||||
{
|
||||
QVariantMap returnedData = output.value< QVariantMap >();
|
||||
const QByteArray ba = returnedData["imgbytes"].toByteArray();
|
||||
if ( ba.length() )
|
||||
{
|
||||
m_pixmap.loadFromData( ba );
|
||||
emit pixmapChanged( m_pixmap );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Tomahawk::InfoSystem::InfoArtistReleases:
|
||||
{
|
||||
QStringList albums = returnedData[ "albums" ].toStringList();
|
||||
QList<album_ptr> 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" ].toInt() > 0 )
|
||||
{
|
||||
tDebug() << "Auto refetching";
|
||||
m_buttonAlbums->setChecked( false );
|
||||
onAlbumsModeToggle();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
|
@@ -92,12 +92,15 @@ protected:
|
||||
void changeEvent( QEvent* e );
|
||||
|
||||
private slots:
|
||||
void loadAlbums( bool autoRefetch = false );
|
||||
void gotAlbums( const QList<Tomahawk::album_ptr>& albums );
|
||||
|
||||
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
void infoSystemFinished( QString target );
|
||||
|
||||
void onModeToggle();
|
||||
void onAlbumsModeToggle();
|
||||
|
||||
void onLoadingStarted();
|
||||
void onLoadingFinished();
|
||||
|
||||
@@ -110,11 +113,14 @@ private:
|
||||
TreeModel* m_tracksModel;
|
||||
|
||||
OverlayButton* m_button;
|
||||
OverlayButton* m_buttonAlbums;
|
||||
|
||||
QString m_title;
|
||||
QString m_description;
|
||||
QString m_longDescription;
|
||||
QPixmap m_pixmap;
|
||||
|
||||
QString m_infoId;
|
||||
};
|
||||
|
||||
#endif // ALBUMINFOWIDGET_H
|
||||
|
@@ -81,6 +81,7 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
|
||||
m_button->setChecked( true );
|
||||
|
||||
connect( m_button, SIGNAL( clicked() ), SLOT( onModeToggle() ) );
|
||||
connect( m_albumsModel, SIGNAL( modeChanged( Tomahawk::ModelMode ) ), SLOT( setMode( Tomahawk::ModelMode ) ) );
|
||||
connect( m_albumsModel, SIGNAL( loadingStarted() ), SLOT( onLoadingStarted() ) );
|
||||
connect( m_albumsModel, SIGNAL( loadingFinished() ), SLOT( onLoadingFinished() ) );
|
||||
|
||||
@@ -108,17 +109,26 @@ ArtistInfoWidget::playlistInterface() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ArtistInfoWidget::setMode( ModelMode mode )
|
||||
{
|
||||
m_button->setChecked( mode == InfoSystemMode );
|
||||
|
||||
if ( m_albumsModel->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" ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ArtistInfoWidget::onModeToggle()
|
||||
{
|
||||
m_albumsModel->setMode( m_button->isChecked() ? InfoSystemMode : DatabaseMode );
|
||||
m_albumsModel->clear();
|
||||
m_albumsModel->addAlbums( m_artist, QModelIndex() );
|
||||
|
||||
if ( m_button->isChecked() )
|
||||
m_button->setText( tr( "Click to show Super Collection Albums" ) );
|
||||
else
|
||||
m_button->setText( tr( "Click to show Official Releases" ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +185,7 @@ ArtistInfoWidget::load( const artist_ptr& artist )
|
||||
{
|
||||
m_artist = artist;
|
||||
m_title = artist->name();
|
||||
m_albumsModel->addAlbums( artist, QModelIndex() );
|
||||
m_albumsModel->addAlbums( artist, QModelIndex(), true );
|
||||
|
||||
Tomahawk::InfoSystem::InfoStringHash artistInfo;
|
||||
artistInfo["artist"] = artist->name();
|
||||
|
@@ -90,6 +90,8 @@ protected:
|
||||
void changeEvent( QEvent* e );
|
||||
|
||||
private slots:
|
||||
void setMode( Tomahawk::ModelMode mode );
|
||||
|
||||
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
void infoSystemFinished( QString target );
|
||||
|
||||
|
Reference in New Issue
Block a user