~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/context/pages/RelatedArtistsContext.cpp

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
28
using namespace Tomahawk;
 
29
 
 
30
 
 
31
RelatedArtistsContext::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
 
 
53
RelatedArtistsContext::~RelatedArtistsContext()
 
54
{
 
55
}
 
56
 
 
57
 
 
58
void
 
59
RelatedArtistsContext::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
 
 
80
void
 
81
RelatedArtistsContext::setQuery( const Tomahawk::query_ptr& query )
 
82
{
 
83
    if ( query.isNull() )
 
84
        return;
 
85
 
 
86
    setArtist( Artist::get( query->artist(), false ) );
 
87
}
 
88
 
 
89
 
 
90
void
 
91
RelatedArtistsContext::setAlbum( const Tomahawk::album_ptr& album )
 
92
{
 
93
    if ( album.isNull() )
 
94
        return;
 
95
 
 
96
    setArtist( album->artist() );
 
97
}
 
98
 
 
99
 
 
100
void
 
101
RelatedArtistsContext::onSimilarArtistsLoaded()
 
102
{
 
103
    foreach ( const artist_ptr& artist, m_artist->similarArtists() )
 
104
    {
 
105
        m_relatedModel->addArtists( artist );
 
106
    }
 
107
}