/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. #include "RelatedArtistsContext.h"
  20. #include <QHeaderView>
  21. #include "playlist/TreeView.h"
  22. #include "playlist/TreeModel.h"
  23. #include "Source.h"
  24. using namespace Tomahawk;
  25. RelatedArtistsContext::RelatedArtistsContext()
  26. : ContextPage()
  27. {
  28. m_relatedView = new TreeView();
  29. m_relatedView->setGuid( "RelatedArtistsContext" );
  30. m_relatedView->setUpdatesContextView( false );
  31. m_relatedModel = new TreeModel( m_relatedView );
  32. m_relatedView->proxyModel()->setStyle( PlayableProxyModel::Large );
  33. m_relatedView->setTreeModel( m_relatedModel );
  34. m_relatedView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
  35. m_relatedView->setSortingEnabled( false );
  36. m_relatedView->proxyModel()->sort( -1 );
  37. QPalette pal = m_relatedView->palette();
  38. pal.setColor( QPalette::Window, QColor( 0, 0, 0, 0 ) );
  39. m_relatedView->setPalette( pal );
  40. m_proxy = new QGraphicsProxyWidget();
  41. m_proxy->setWidget( m_relatedView );
  42. }
  43. RelatedArtistsContext::~RelatedArtistsContext()
  44. {
  45. }
  46. void
  47. RelatedArtistsContext::setArtist( const Tomahawk::artist_ptr& artist )
  48. {
  49. if ( artist.isNull() )
  50. return;
  51. if ( !m_artist.isNull() && m_artist->name() == artist->name() )
  52. return;
  53. if ( !m_artist.isNull() )
  54. {
  55. disconnect( m_artist.data(), SIGNAL( similarArtistsLoaded() ), this, SLOT( onSimilarArtistsLoaded() ) );
  56. }
  57. m_artist = artist;
  58. connect( m_artist.data(), SIGNAL( similarArtistsLoaded() ), SLOT( onSimilarArtistsLoaded() ) );
  59. m_relatedModel->clear();
  60. onSimilarArtistsLoaded();
  61. }
  62. void
  63. RelatedArtistsContext::setQuery( const Tomahawk::query_ptr& query )
  64. {
  65. if ( query.isNull() )
  66. return;
  67. setArtist( Artist::get( query->artist(), false ) );
  68. }
  69. void
  70. RelatedArtistsContext::setAlbum( const Tomahawk::album_ptr& album )
  71. {
  72. if ( album.isNull() )
  73. return;
  74. setArtist( album->artist() );
  75. }
  76. void
  77. RelatedArtistsContext::onSimilarArtistsLoaded()
  78. {
  79. foreach ( const artist_ptr& artist, m_artist->similarArtists() )
  80. {
  81. m_relatedModel->addArtists( artist );
  82. }
  83. }