PageRenderTime 113ms CodeModel.GetById 61ms app.highlight 10ms RepoModel.GetById 40ms app.codeStats 0ms

/src/libtomahawk/context/pages/TopTracksContext.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 106 lines | 62 code | 26 blank | 18 comment | 7 complexity | bb48167117fffda35e8e86396d6a5e95 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 "TopTracksContext.h"
 21
 22#include "playlist/PlaylistModel.h"
 23#include "playlist/PlaylistView.h"
 24#include "Source.h"
 25
 26using namespace Tomahawk;
 27
 28
 29TopTracksContext::TopTracksContext()
 30    : ContextPage()
 31{
 32    m_topHitsView = new PlaylistView();
 33    m_topHitsView->setGuid( "TopTracksContext" );
 34    m_topHitsView->setUpdatesContextView( false );
 35    m_topHitsModel = new PlaylistModel( m_topHitsView );
 36    m_topHitsView->proxyModel()->setStyle( PlayableProxyModel::Short );
 37    m_topHitsView->setPlaylistModel( m_topHitsModel );
 38    m_topHitsView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
 39
 40    QPalette pal = m_topHitsView->palette();
 41    pal.setColor( QPalette::Window, QColor( 0, 0, 0, 0 ) );
 42    m_topHitsView->setPalette( pal );
 43
 44    m_proxy = new QGraphicsProxyWidget();
 45    m_proxy->setWidget( m_topHitsView );
 46}
 47
 48
 49TopTracksContext::~TopTracksContext()
 50{
 51}
 52
 53
 54void
 55TopTracksContext::setArtist( const Tomahawk::artist_ptr& artist )
 56{
 57    if ( artist.isNull() )
 58        return;
 59    if ( !m_artist.isNull() && m_artist->name() == artist->name() )
 60        return;
 61
 62    if ( !m_artist.isNull() )
 63    {
 64        disconnect( m_artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
 65                    this,              SLOT( onTracksFound( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode ) ) );
 66    }
 67
 68    m_artist = artist;
 69
 70    connect( m_artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
 71                                SLOT( onTracksFound( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode ) ) );
 72
 73    m_topHitsModel->clear();
 74    onTracksFound( m_artist->tracks(), Mixed );
 75}
 76
 77
 78void
 79TopTracksContext::setAlbum( const Tomahawk::album_ptr& album )
 80{
 81    if ( album.isNull() )
 82        return;
 83
 84    setArtist( album->artist() );
 85}
 86
 87
 88void
 89TopTracksContext::setQuery( const Tomahawk::query_ptr& query )
 90{
 91    if ( query.isNull() )
 92        return;
 93
 94    setArtist( Artist::get( query->artist(), false ) );
 95}
 96
 97
 98void
 99TopTracksContext::onTracksFound( const QList<Tomahawk::query_ptr>& queries, ModelMode mode )
100{
101    Q_UNUSED( mode );
102
103    m_topHitsModel->appendQueries( queries );
104}
105
106