From 41b3ebf4e4c6bb34e74eb4992da1c9ad45829e31 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 7 Dec 2011 07:19:30 +0100 Subject: [PATCH] * Auto-switch to super collection mode when no official info is available on artist & album pages. --- .../infoplugins/generic/musicbrainzPlugin.cpp | 1 + src/libtomahawk/playlist/albumview.cpp | 5 +- src/libtomahawk/playlist/treemodel.cpp | 17 ++- src/libtomahawk/playlist/treemodel.h | 2 +- src/libtomahawk/playlistinterface.cpp | 2 +- src/libtomahawk/playlistinterface.h | 2 +- .../widgets/infowidgets/AlbumInfoWidget.cpp | 108 +++++++++++++++--- .../widgets/infowidgets/AlbumInfoWidget.h | 6 + .../widgets/infowidgets/ArtistInfoWidget.cpp | 24 ++-- .../widgets/infowidgets/ArtistInfoWidget.h | 2 + 10 files changed, 142 insertions(+), 27 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.cpp index 12f96599e..94b0983a2 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.cpp @@ -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; } diff --git a/src/libtomahawk/playlist/albumview.cpp b/src/libtomahawk/playlist/albumview.cpp index beca0ff9f..d553b88bc 100644 --- a/src/libtomahawk/playlist/albumview.cpp +++ b/src/libtomahawk/playlist/albumview.cpp @@ -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 ); diff --git a/src/libtomahawk/playlist/treemodel.cpp b/src/libtomahawk/playlist/treemodel.cpp index cada2b10f..d34e69821 100644 --- a/src/libtomahawk/playlist/treemodel.cpp +++ b/src/libtomahawk/playlist/treemodel.cpp @@ -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; } diff --git a/src/libtomahawk/playlist/treemodel.h b/src/libtomahawk/playlist/treemodel.h index ee2f0708e..ecdd4946c 100644 --- a/src/libtomahawk/playlist/treemodel.h +++ b/src/libtomahawk/playlist/treemodel.h @@ -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 ); diff --git a/src/libtomahawk/playlistinterface.cpp b/src/libtomahawk/playlistinterface.cpp index 4a441ab4f..7724329f2 100644 --- a/src/libtomahawk/playlistinterface.cpp +++ b/src/libtomahawk/playlistinterface.cpp @@ -22,7 +22,7 @@ using namespace Tomahawk; -PlaylistInterface::PlaylistInterface (QObject *parent ) +PlaylistInterface::PlaylistInterface ( QObject *parent ) : m_object( parent ) { qRegisterMetaType( "Tomahawk::PlaylistInterface::RepeatMode" ); diff --git a/src/libtomahawk/playlistinterface.h b/src/libtomahawk/playlistinterface.h index 5aa3fd46e..c6017f197 100644 --- a/src/libtomahawk/playlistinterface.h +++ b/src/libtomahawk/playlistinterface.h @@ -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() { diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp index 75a4a2650..cad3c9785 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp @@ -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, QVariant ) ), - SLOT( gotAlbums( QList ) ) ); - - Database::instance()->enqueue( QSharedPointer( 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, QVariant ) ), + SLOT( gotAlbums( QList ) ) ); + + Database::instance()->enqueue( QSharedPointer( 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& albums ) { @@ -218,7 +259,7 @@ AlbumInfoWidget::gotAlbums( const QList& 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 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: diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h index 4f7f9b161..9c849ec0a 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h @@ -92,12 +92,15 @@ protected: void changeEvent( QEvent* e ); private slots: + void loadAlbums( bool autoRefetch = false ); void gotAlbums( const QList& 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 diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp index 979e8c15a..1dae0f1a7 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp @@ -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(); diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h index 754578bef..72e5fb815 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h @@ -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 );