From a6c838cd39f4dfca91378810c4cc0a7a7957c547 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 19 Oct 2011 02:06:53 +0200 Subject: [PATCH] * Support official release on album pages. --- src/libtomahawk/CMakeLists.txt | 2 + src/libtomahawk/playlist/treemodel.cpp | 2 + src/libtomahawk/playlist/treeproxymodel.cpp | 10 +++++ src/libtomahawk/playlist/treeproxymodel.h | 2 + .../widgets/infowidgets/AlbumInfoWidget.cpp | 41 +++++++++++++++++++ .../widgets/infowidgets/AlbumInfoWidget.h | 7 ++++ .../widgets/infowidgets/ArtistInfoWidget.cpp | 36 +++++++++++++--- .../widgets/infowidgets/ArtistInfoWidget.h | 5 +++ .../widgets/infowidgets/ArtistInfoWidget.ui | 7 ---- 9 files changed, 100 insertions(+), 12 deletions(-) diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index b80ac4a9b..209c721a7 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -212,6 +212,7 @@ set( libSources widgets/whatshotwidget.cpp widgets/RecentlyPlayedPlaylistsModel.cpp widgets/RecentPlaylistsModel.cpp + widgets/OverlayButton.cpp widgets/overlaywidget.cpp widgets/HeaderLabel.cpp widgets/HeaderWidget.cpp @@ -436,6 +437,7 @@ set( libHeaders widgets/whatshotwidget.h widgets/RecentlyPlayedPlaylistsModel.h widgets/RecentPlaylistsModel.h + widgets/OverlayButton.h widgets/overlaywidget.h widgets/HeaderLabel.h widgets/HeaderWidget.h diff --git a/src/libtomahawk/playlist/treemodel.cpp b/src/libtomahawk/playlist/treemodel.cpp index 28f4543c0..a7e67e4e0 100644 --- a/src/libtomahawk/playlist/treemodel.cpp +++ b/src/libtomahawk/playlist/treemodel.cpp @@ -73,12 +73,14 @@ TreeModel::clear() } } + Tomahawk::collection_ptr TreeModel::collection() const { return m_collection; } + void TreeModel::getCover( const QModelIndex& index ) { diff --git a/src/libtomahawk/playlist/treeproxymodel.cpp b/src/libtomahawk/playlist/treeproxymodel.cpp index 57aa72505..5dc0e0cfa 100644 --- a/src/libtomahawk/playlist/treeproxymodel.cpp +++ b/src/libtomahawk/playlist/treeproxymodel.cpp @@ -64,6 +64,7 @@ TreeProxyModel::setSourceTreeModel( TreeModel* sourceModel ) connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ), SIGNAL( sourceTrackCountChanged( unsigned int ) ) ); connect( m_model, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onRowsInserted( QModelIndex, int, int ) ) ); + connect( m_model, SIGNAL( modelReset() ), SLOT( onModelReset() ) ); } QSortFilterProxyModel::setSourceModel( sourceModel ); @@ -93,6 +94,15 @@ TreeProxyModel::onRowsInserted( const QModelIndex& parent, int /* start */, int } +void +TreeProxyModel::onModelReset() +{ + m_cache.clear(); + m_artistsFilter.clear(); + m_albumsFilter.clear(); +} + + void TreeProxyModel::setFilter( const QString& pattern ) { diff --git a/src/libtomahawk/playlist/treeproxymodel.h b/src/libtomahawk/playlist/treeproxymodel.h index 8b398e23a..d15f3e8a8 100644 --- a/src/libtomahawk/playlist/treeproxymodel.h +++ b/src/libtomahawk/playlist/treeproxymodel.h @@ -92,6 +92,8 @@ private slots: void onFilterArtists( const QList& artists ); void onFilterAlbums( const QList& albums ); + void onModelReset(); + private: void filterFinished(); QString textForItem( TreeModelItem* item ) const; diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp index 2a059d233..4824aaba3 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp @@ -30,6 +30,7 @@ #include "utils/tomahawkutils.h" #include "utils/logger.h" +#include "widgets/OverlayButton.h" #include "widgets/overlaywidget.h" static QString s_aiInfoIdentifier = QString( "AlbumInfoWidget" ); @@ -56,11 +57,21 @@ AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, QWidget* par ui->albumsView->setAlbumModel( m_albumsModel ); m_tracksModel = new TreeModel( ui->tracksView ); + m_tracksModel->setMode( TreeModel::InfoSystem ); ui->tracksView->setTreeModel( m_tracksModel ); ui->tracksView->setRootIsDecorated( false ); m_pixmap = QPixmap( RESPATH "images/no-album-art-placeholder.png" ).scaledToWidth( 48, Qt::SmoothTransformation ); + m_button = new OverlayButton( ui->tracksView ); + m_button->setText( tr( "Click to show All Tracks" ) ); + m_button->setCheckable( true ); + m_button->setChecked( true ); + + connect( m_button, SIGNAL( clicked() ), SLOT( onModeToggle() ) ); + connect( m_tracksModel, SIGNAL( loadingStarted() ), SLOT( onLoadingStarted() ) ); + connect( m_tracksModel, SIGNAL( loadingFinished() ), SLOT( onLoadingFinished() ) ); + connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) ); @@ -77,6 +88,36 @@ AlbumInfoWidget::~AlbumInfoWidget() } +void +AlbumInfoWidget::onModeToggle() +{ + m_tracksModel->setMode( m_button->isChecked() ? TreeModel::InfoSystem : TreeModel::Database ); + m_tracksModel->clear(); + m_tracksModel->addTracks( m_album, QModelIndex() ); + + if ( m_button->isChecked() ) + m_button->setText( tr( "Click to show All Tracks" ) ); + else + m_button->setText( tr( "Click to show Official Tracks" ) ); +} + + +void +AlbumInfoWidget::onLoadingStarted() +{ + m_button->setEnabled( false ); + m_button->hide(); +} + + +void +AlbumInfoWidget::onLoadingFinished() +{ + m_button->setEnabled( true ); + m_button->show(); +} + + void AlbumInfoWidget::load( const album_ptr& album ) { diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h index aa4f1016c..ca1bc8130 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h @@ -38,6 +38,7 @@ class AlbumModel; class TreeModel; +class OverlayButton; namespace Ui { @@ -89,6 +90,10 @@ private slots: void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); void infoSystemFinished( QString target ); + void onModeToggle(); + void onLoadingStarted(); + void onLoadingFinished(); + private: Ui::AlbumInfoWidget *ui; @@ -97,6 +102,8 @@ private: AlbumModel* m_albumsModel; TreeModel* m_tracksModel; + OverlayButton* m_button; + QString m_title; QString m_description; QString m_longDescription; diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp index 73ecc14c0..269ee626d 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp @@ -30,6 +30,7 @@ #include "utils/tomahawkutils.h" #include "utils/logger.h" +#include "widgets/OverlayButton.h" #include "widgets/overlaywidget.h" using namespace Tomahawk; @@ -68,12 +69,16 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget* m_topHitsModel->setStyle( TrackModel::Short ); ui->topHits->setTrackModel( m_topHitsModel ); - ui->albumHeader->setContentsMargins( 0, 0, 4, 0 ); - ui->button->setChecked( true ); - m_pixmap = QPixmap( RESPATH "images/no-album-art-placeholder.png" ).scaledToWidth( 48, Qt::SmoothTransformation ); - connect( ui->button, SIGNAL( clicked() ), SLOT( onModeToggle() ) ); + m_button = new OverlayButton( ui->albums ); + m_button->setText( tr( "Click to show All Releases" ) ); + m_button->setCheckable( true ); + m_button->setChecked( true ); + + connect( m_button, SIGNAL( clicked() ), SLOT( onModeToggle() ) ); + connect( m_albumsModel, SIGNAL( loadingStarted() ), SLOT( onLoadingStarted() ) ); + connect( m_albumsModel, SIGNAL( loadingFinished() ), SLOT( onLoadingFinished() ) ); connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), @@ -94,9 +99,30 @@ ArtistInfoWidget::~ArtistInfoWidget() void ArtistInfoWidget::onModeToggle() { - m_albumsModel->setMode( ui->button->isChecked() ? TreeModel::InfoSystem : TreeModel::Database ); + m_albumsModel->setMode( m_button->isChecked() ? TreeModel::InfoSystem : TreeModel::Database ); m_albumsModel->clear(); m_albumsModel->addAlbums( m_artist, QModelIndex() ); + + if ( m_button->isChecked() ) + m_button->setText( tr( "Click to show All Releases" ) ); + else + m_button->setText( tr( "Click to show Official Releases" ) ); +} + + +void +ArtistInfoWidget::onLoadingStarted() +{ + m_button->setEnabled( false ); + m_button->hide(); +} + + +void +ArtistInfoWidget::onLoadingFinished() +{ + m_button->setEnabled( true ); + m_button->show(); } diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h index cb83fb9e2..1f0a8a1d8 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h @@ -40,6 +40,7 @@ class PlaylistModel; class TreeModel; +class OverlayButton; namespace Ui { @@ -90,6 +91,8 @@ private slots: void infoSystemFinished( QString target ); void onModeToggle(); + void onLoadingStarted(); + void onLoadingFinished(); private: Ui::ArtistInfoWidget *ui; @@ -100,6 +103,8 @@ private: TreeModel* m_albumsModel; PlaylistModel* m_topHitsModel; + OverlayButton* m_button; + QString m_title; QString m_description; QString m_longDescription; diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.ui b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.ui index bc6115712..670acc2b8 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.ui +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.ui @@ -78,13 +78,6 @@ - - - - Official Releases Only - - -