/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. #include "TopTracksContext.h"
  20. #include "playlist/PlaylistModel.h"
  21. #include "playlist/PlaylistView.h"
  22. #include "Source.h"
  23. using namespace Tomahawk;
  24. TopTracksContext::TopTracksContext()
  25. : ContextPage()
  26. {
  27. m_topHitsView = new PlaylistView();
  28. m_topHitsView->setGuid( "TopTracksContext" );
  29. m_topHitsView->setUpdatesContextView( false );
  30. m_topHitsModel = new PlaylistModel( m_topHitsView );
  31. m_topHitsView->proxyModel()->setStyle( PlayableProxyModel::Short );
  32. m_topHitsView->setPlaylistModel( m_topHitsModel );
  33. m_topHitsView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
  34. QPalette pal = m_topHitsView->palette();
  35. pal.setColor( QPalette::Window, QColor( 0, 0, 0, 0 ) );
  36. m_topHitsView->setPalette( pal );
  37. m_proxy = new QGraphicsProxyWidget();
  38. m_proxy->setWidget( m_topHitsView );
  39. }
  40. TopTracksContext::~TopTracksContext()
  41. {
  42. }
  43. void
  44. TopTracksContext::setArtist( const Tomahawk::artist_ptr& artist )
  45. {
  46. if ( artist.isNull() )
  47. return;
  48. if ( !m_artist.isNull() && m_artist->name() == artist->name() )
  49. return;
  50. if ( !m_artist.isNull() )
  51. {
  52. disconnect( m_artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
  53. this, SLOT( onTracksFound( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode ) ) );
  54. }
  55. m_artist = artist;
  56. connect( m_artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
  57. SLOT( onTracksFound( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode ) ) );
  58. m_topHitsModel->clear();
  59. onTracksFound( m_artist->tracks(), Mixed );
  60. }
  61. void
  62. TopTracksContext::setAlbum( const Tomahawk::album_ptr& album )
  63. {
  64. if ( album.isNull() )
  65. return;
  66. setArtist( album->artist() );
  67. }
  68. void
  69. TopTracksContext::setQuery( const Tomahawk::query_ptr& query )
  70. {
  71. if ( query.isNull() )
  72. return;
  73. setArtist( Artist::get( query->artist(), false ) );
  74. }
  75. void
  76. TopTracksContext::onTracksFound( const QList<Tomahawk::query_ptr>& queries, ModelMode mode )
  77. {
  78. Q_UNUSED( mode );
  79. m_topHitsModel->appendQueries( queries );
  80. }