PageRenderTime 183ms CodeModel.GetById 67ms app.highlight 49ms RepoModel.GetById 65ms app.codeStats 0ms

/src/libtomahawk/context/pages/RelatedArtistsContext.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 107 lines | 65 code | 24 blank | 18 comment | 7 complexity | 6ceb1f6877256e4f1fb6b68fa1c242f3 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5 *
  6 *   Tomahawk is free software: you can redistribute it and/or modify
  7 *   it under the terms of the GNU General Public License as published by
  8 *   the Free Software Foundation, either version 3 of the License, or
  9 *   (at your option) any later version.
 10 *
 11 *   Tomahawk is distributed in the hope that it will be useful,
 12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14 *   GNU General Public License for more details.
 15 *
 16 *   You should have received a copy of the GNU General Public License
 17 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20#include "RelatedArtistsContext.h"
 21
 22#include <QHeaderView>
 23
 24#include "playlist/TreeView.h"
 25#include "playlist/TreeModel.h"
 26#include "Source.h"
 27
 28using namespace Tomahawk;
 29
 30
 31RelatedArtistsContext::RelatedArtistsContext()
 32    : ContextPage()
 33{
 34    m_relatedView = new TreeView();
 35    m_relatedView->setGuid( "RelatedArtistsContext" );
 36    m_relatedView->setUpdatesContextView( false );
 37    m_relatedModel = new TreeModel( m_relatedView );
 38    m_relatedView->proxyModel()->setStyle( PlayableProxyModel::Large );
 39    m_relatedView->setTreeModel( m_relatedModel );
 40    m_relatedView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
 41    m_relatedView->setSortingEnabled( false );
 42    m_relatedView->proxyModel()->sort( -1 );
 43
 44    QPalette pal = m_relatedView->palette();
 45    pal.setColor( QPalette::Window, QColor( 0, 0, 0, 0 ) );
 46    m_relatedView->setPalette( pal );
 47
 48    m_proxy = new QGraphicsProxyWidget();
 49    m_proxy->setWidget( m_relatedView );
 50}
 51
 52
 53RelatedArtistsContext::~RelatedArtistsContext()
 54{
 55}
 56
 57
 58void
 59RelatedArtistsContext::setArtist( const Tomahawk::artist_ptr& artist )
 60{
 61    if ( artist.isNull() )
 62        return;
 63    if ( !m_artist.isNull() && m_artist->name() == artist->name() )
 64        return;
 65
 66    if ( !m_artist.isNull() )
 67    {
 68        disconnect( m_artist.data(), SIGNAL( similarArtistsLoaded() ), this, SLOT( onSimilarArtistsLoaded() ) );
 69    }
 70
 71    m_artist = artist;
 72
 73    connect( m_artist.data(), SIGNAL( similarArtistsLoaded() ), SLOT( onSimilarArtistsLoaded() ) );
 74
 75    m_relatedModel->clear();
 76    onSimilarArtistsLoaded();
 77}
 78
 79
 80void
 81RelatedArtistsContext::setQuery( const Tomahawk::query_ptr& query )
 82{
 83    if ( query.isNull() )
 84        return;
 85
 86    setArtist( Artist::get( query->artist(), false ) );
 87}
 88
 89
 90void
 91RelatedArtistsContext::setAlbum( const Tomahawk::album_ptr& album )
 92{
 93    if ( album.isNull() )
 94        return;
 95
 96    setArtist( album->artist() );
 97}
 98
 99
100void
101RelatedArtistsContext::onSimilarArtistsLoaded()
102{
103    foreach ( const artist_ptr& artist, m_artist->similarArtists() )
104    {
105        m_relatedModel->addArtists( artist );
106    }
107}