/src/sourcetree/items/genericpageitems.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 115 lines · 72 code · 25 blank · 18 comment · 8 complexity · 3bad1a8ed22c9c1810c11213bf56838b MD5 · raw file

  1. /*
  2. * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "GenericPageItems.h"
  19. #include "utils/TomahawkUtils.h"
  20. #include "utils/Logger.h"
  21. #include "ViewManager.h"
  22. #include "audio/AudioEngine.h"
  23. using namespace Tomahawk;
  24. /// Generic page item
  25. GenericPageItem::GenericPageItem( SourcesModel* model, SourceTreeItem* parent, const QString& text, const QIcon& icon, boost::function< ViewPage* () > show, boost::function< ViewPage* () > get )
  26. : SourceTreeItem( model, parent, SourcesModel::GenericPage )
  27. , m_icon( icon )
  28. , m_text( text )
  29. , m_sortValue( 0 )
  30. , m_show( show )
  31. , m_get( get )
  32. {
  33. if( ViewPage* p = m_get() )
  34. model->linkSourceItemToPage( this, p );
  35. }
  36. GenericPageItem::~GenericPageItem()
  37. {
  38. }
  39. void
  40. GenericPageItem::activate()
  41. {
  42. ViewPage* p = m_show();
  43. model()->linkSourceItemToPage( this, p );
  44. }
  45. QString
  46. GenericPageItem::text() const
  47. {
  48. return m_text;
  49. }
  50. QIcon
  51. GenericPageItem::icon() const
  52. {
  53. return m_icon;
  54. }
  55. bool
  56. GenericPageItem::willAcceptDrag(const QMimeData* data) const
  57. {
  58. Q_UNUSED( data );
  59. return false;
  60. }
  61. void
  62. GenericPageItem::setText( const QString &text )
  63. {
  64. m_text = text;
  65. emit updated();
  66. }
  67. bool
  68. GenericPageItem::isBeingPlayed() const
  69. {
  70. if ( m_get() )
  71. {
  72. if ( m_get()->isBeingPlayed() )
  73. return true;
  74. if ( !m_get()->playlistInterface().isNull() && m_get()->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() )
  75. return true;
  76. if ( !m_get()->playlistInterface().isNull() && m_get()->playlistInterface()->hasChildInterface( AudioEngine::instance()->currentTrackPlaylist() ) )
  77. return true;
  78. }
  79. return false;
  80. }
  81. int
  82. GenericPageItem::peerSortValue() const
  83. {
  84. return m_sortValue;
  85. }
  86. void
  87. GenericPageItem::setSortValue(int value)
  88. {
  89. m_sortValue = value;
  90. }