diff --git a/src/libtomahawk/playlist/artistview.cpp b/src/libtomahawk/playlist/artistview.cpp index 61851b692..59ce86097 100644 --- a/src/libtomahawk/playlist/artistview.cpp +++ b/src/libtomahawk/playlist/artistview.cpp @@ -158,7 +158,7 @@ ArtistView::onItemActivated( const QModelIndex& index ) if ( !item->artist().isNull() ) ViewManager::instance()->show( item->artist() ); else if ( !item->album().isNull() ) - ViewManager::instance()->show( item->album() ); + ViewManager::instance()->show( item->album(), m_model->mode() ); else if ( !item->result().isNull() && item->result()->isOnline() ) { m_model->setCurrentItem( item->index ); diff --git a/src/libtomahawk/playlist/treemodel.cpp b/src/libtomahawk/playlist/treemodel.cpp index 154548d7f..56afbc2e2 100644 --- a/src/libtomahawk/playlist/treemodel.cpp +++ b/src/libtomahawk/playlist/treemodel.cpp @@ -38,7 +38,7 @@ TreeModel::TreeModel( QObject* parent ) , m_rootItem( new TreeModelItem( 0, this ) ) , m_infoId( uuid() ) , m_columnStyle( AllColumns ) - , m_mode( Database ) + , m_mode( DatabaseMode ) { setIcon( QPixmap( RESPATH "images/music-icon.png" ) ); @@ -576,7 +576,7 @@ TreeModel::addAlbums( const artist_ptr& artist, const QModelIndex& parent ) { emit loadingStarted(); - if ( m_mode == Database ) + if ( m_mode == DatabaseMode ) { DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( m_collection, artist ); cmd->setData( parent.row() ); @@ -586,7 +586,7 @@ TreeModel::addAlbums( const artist_ptr& artist, const QModelIndex& parent ) Database::instance()->enqueue( QSharedPointer( cmd ) ); } - else if ( m_mode == InfoSystem ) + else if ( m_mode == InfoSystemMode ) { Tomahawk::InfoSystem::InfoStringHash artistInfo; artistInfo["artist"] = artist->name(); @@ -612,7 +612,7 @@ TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent ) rows << parent.row(); rows << parent.parent().row(); - if ( m_mode == Database ) + if ( m_mode == DatabaseMode ) { DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_collection ); cmd->setAlbum( album.data() ); @@ -623,7 +623,7 @@ TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent ) Database::instance()->enqueue( QSharedPointer( cmd ) ); } - else if ( m_mode == InfoSystem ) + else if ( m_mode == InfoSystemMode ) { Tomahawk::InfoSystem::InfoStringHash artistInfo; artistInfo["artist"] = album->artist()->name(); @@ -850,14 +850,14 @@ TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QV { if ( m_receivedInfoData.contains( requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >() ) ) break; - + QVariantMap returnedData = output.value< QVariantMap >(); if ( returnedData.isEmpty() ) break; - + m_receivedInfoData.insert( requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >() ); - + QStringList tracks = returnedData[ "tracks" ].toStringList(); QList ql; diff --git a/src/libtomahawk/playlist/treemodel.h b/src/libtomahawk/playlist/treemodel.h index 0c22511cc..3973b396f 100644 --- a/src/libtomahawk/playlist/treemodel.h +++ b/src/libtomahawk/playlist/treemodel.h @@ -33,6 +33,7 @@ #include "infosystem/infosystem.h" #include "dllmacro.h" +#include "typedefs.h" class QMetaData; @@ -55,9 +56,6 @@ public: enum ColumnStyle { AllColumns = 0, TrackOnly }; - enum ModelMode - { Database = 0, InfoSystem }; - explicit TreeModel( QObject* parent = 0 ); virtual ~TreeModel(); @@ -73,8 +71,8 @@ public: virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const; virtual int columnCount( const QModelIndex& parent = QModelIndex() ) const; - virtual ModelMode mode() const { return m_mode; } - virtual void setMode( ModelMode mode ) { m_mode = mode; } + virtual Tomahawk::ModelMode mode() const { return m_mode; } + virtual void setMode( Tomahawk::ModelMode mode ) { m_mode = mode; } virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const; virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const; @@ -165,7 +163,7 @@ private: QString m_description; QPixmap m_icon; ColumnStyle m_columnStyle; - ModelMode m_mode; + Tomahawk::ModelMode m_mode; QList m_artistsFilter; diff --git a/src/libtomahawk/playlist/treeproxymodel.cpp b/src/libtomahawk/playlist/treeproxymodel.cpp index c6c7f99cf..5530d9aae 100644 --- a/src/libtomahawk/playlist/treeproxymodel.cpp +++ b/src/libtomahawk/playlist/treeproxymodel.cpp @@ -195,7 +195,7 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent TreeModelItem* pi = sourceModel()->itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) ); Q_ASSERT( pi ); - if ( m_model->mode() == TreeModel::Database && !pi->result().isNull() ) + if ( m_model->mode() == Tomahawk::DatabaseMode && !pi->result().isNull() ) { QList< Tomahawk::result_ptr > rl = m_cache.values( sourceParent ); foreach ( const Tomahawk::result_ptr& result, rl ) diff --git a/src/libtomahawk/typedefs.h b/src/libtomahawk/typedefs.h index b3b98232e..b972009ba 100644 --- a/src/libtomahawk/typedefs.h +++ b/src/libtomahawk/typedefs.h @@ -63,6 +63,12 @@ namespace Tomahawk Static }; + enum ModelMode + { + DatabaseMode = 0, + InfoSystemMode + }; + }; // ns typedef int AudioErrorCode; diff --git a/src/libtomahawk/viewmanager.cpp b/src/libtomahawk/viewmanager.cpp index 8f022890c..b7cd72b08 100644 --- a/src/libtomahawk/viewmanager.cpp +++ b/src/libtomahawk/viewmanager.cpp @@ -217,12 +217,12 @@ ViewManager::show( const Tomahawk::artist_ptr& artist ) Tomahawk::ViewPage* -ViewManager::show( const Tomahawk::album_ptr& album ) +ViewManager::show( const Tomahawk::album_ptr& album, Tomahawk::ModelMode initialMode ) { AlbumInfoWidget* swidget; if ( !m_albumViews.contains( album ) || m_albumViews.value( album ).isNull() ) { - swidget = new AlbumInfoWidget( album ); + swidget = new AlbumInfoWidget( album, initialMode ); m_albumViews.insert( album, swidget ); } else diff --git a/src/libtomahawk/viewmanager.h b/src/libtomahawk/viewmanager.h index 38820b63b..3c2bed9a6 100644 --- a/src/libtomahawk/viewmanager.h +++ b/src/libtomahawk/viewmanager.h @@ -139,7 +139,7 @@ public slots: Tomahawk::ViewPage* show( const Tomahawk::playlist_ptr& playlist ); Tomahawk::ViewPage* show( const Tomahawk::dynplaylist_ptr& playlist ); Tomahawk::ViewPage* show( const Tomahawk::artist_ptr& artist ); - Tomahawk::ViewPage* show( const Tomahawk::album_ptr& album ); + Tomahawk::ViewPage* show( const Tomahawk::album_ptr& album, Tomahawk::ModelMode withInitialMode = Tomahawk::InfoSystemMode ); Tomahawk::ViewPage* show( const Tomahawk::collection_ptr& collection ); Tomahawk::ViewPage* show( const Tomahawk::source_ptr& source ); diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp index 3b5877a96..2f0f8415a 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp @@ -39,7 +39,7 @@ static QString s_aiInfoIdentifier = QString( "AlbumInfoWidget" ); using namespace Tomahawk; -AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, QWidget* parent ) +AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, ModelMode startingMode, QWidget* parent ) : QWidget( parent ) , ui( new Ui::AlbumInfoWidget ) { @@ -58,16 +58,19 @@ 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 ); + m_tracksModel->setMode( startingMode ); 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 Super Collection Tracks" ) ); m_button->setCheckable( true ); - m_button->setChecked( true ); + m_button->setChecked( m_tracksModel->mode() == InfoSystemMode ); + if ( m_button->isChecked() ) + m_button->setText( tr( "Click to show Super Collection Tracks" ) ); + else + m_button->setText( tr( "Click to show Official Tracks" ) ); connect( m_button, SIGNAL( clicked() ), SLOT( onModeToggle() ) ); connect( m_tracksModel, SIGNAL( loadingStarted() ), SLOT( onLoadingStarted() ) ); @@ -94,11 +97,18 @@ AlbumInfoWidget::playlistInterface() const return ui->tracksView->playlistInterface(); } +void +AlbumInfoWidget::setMode( ModelMode mode ) +{ + if ( m_tracksModel->mode() != mode ) + onModeToggle(); +} + void AlbumInfoWidget::onModeToggle() { - m_tracksModel->setMode( m_button->isChecked() ? TreeModel::InfoSystem : TreeModel::Database ); + m_tracksModel->setMode( m_button->isChecked() ? InfoSystemMode : DatabaseMode ); m_tracksModel->clear(); m_tracksModel->addTracks( m_album, QModelIndex() ); diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h index 8fe7c286c..9542ab679 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h @@ -35,6 +35,7 @@ #include "infosystem/infosystem.h" #include "dllmacro.h" +#include "typedefs.h" class AlbumModel; class TreeModel; @@ -50,7 +51,7 @@ class DLLEXPORT AlbumInfoWidget : public QWidget, public Tomahawk::ViewPage Q_OBJECT public: - AlbumInfoWidget( const Tomahawk::album_ptr& album, QWidget* parent = 0 ); + AlbumInfoWidget( const Tomahawk::album_ptr& album, Tomahawk::ModelMode startingMode = Tomahawk::InfoSystemMode, QWidget* parent = 0 ); ~AlbumInfoWidget(); virtual QWidget* widget() { return this; } @@ -63,6 +64,8 @@ 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; } diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp index 8f24ae62d..3ead1a03c 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp @@ -21,7 +21,6 @@ #include "ui_ArtistInfoWidget.h" #include "audio/audioengine.h" -#include "viewmanager.h" #include "playlist/treemodel.h" #include "playlist/playlistmodel.h" #include "playlist/treeproxymodel.h" @@ -63,7 +62,7 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget* TomahawkUtils::unmarginLayout( ui->albumHeader->layout() ); m_albumsModel = new TreeModel( ui->albums ); - m_albumsModel->setMode( TreeModel::InfoSystem ); + m_albumsModel->setMode( InfoSystemMode ); ui->albums->setTreeModel( m_albumsModel ); m_relatedModel = new TreeModel( ui->relatedArtists ); @@ -111,7 +110,7 @@ ArtistInfoWidget::playlistInterface() const void ArtistInfoWidget::onModeToggle() { - m_albumsModel->setMode( m_button->isChecked() ? TreeModel::InfoSystem : TreeModel::Database ); + m_albumsModel->setMode( m_button->isChecked() ? InfoSystemMode : DatabaseMode ); m_albumsModel->clear(); m_albumsModel->addAlbums( m_artist, QModelIndex() );