/src/libtomahawk/playlist/playlistview.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 162 lines · 111 code · 33 blank · 18 comment · 16 complexity · de6f86c3dc9e219626115acd244c18ad 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 "PlaylistView.h"
  20. #include <QKeyEvent>
  21. #include "ViewManager.h"
  22. #include "utils/Logger.h"
  23. #include "PlaylistUpdaterInterface.h"
  24. #include "Source.h"
  25. using namespace Tomahawk;
  26. PlaylistView::PlaylistView( QWidget* parent )
  27. : TrackView( parent )
  28. , m_model( 0 )
  29. {
  30. connect( contextMenu(), SIGNAL( triggered( int ) ), SLOT( onMenuTriggered( int ) ) );
  31. }
  32. PlaylistView::~PlaylistView()
  33. {
  34. qDebug() << Q_FUNC_INFO;
  35. }
  36. void
  37. PlaylistView::setModel( QAbstractItemModel* model )
  38. {
  39. Q_UNUSED( model );
  40. qDebug() << "Explicitly use setPlaylistModel instead";
  41. Q_ASSERT( false );
  42. }
  43. void
  44. PlaylistView::setPlaylistModel( PlaylistModel* model )
  45. {
  46. m_model = model;
  47. TrackView::setPlayableModel( m_model );
  48. setColumnHidden( PlayableModel::Age, true ); // Hide age column per default
  49. setColumnHidden( PlayableModel::Filesize, true ); // Hide filesize column per default
  50. setColumnHidden( PlayableModel::Composer, true ); // Hide composer column per default
  51. connect( m_model, SIGNAL( playlistDeleted() ), SLOT( onDeleted() ) );
  52. connect( m_model, SIGNAL( playlistChanged() ), SLOT( onChanged() ) );
  53. emit modelChanged();
  54. }
  55. void
  56. PlaylistView::keyPressEvent( QKeyEvent* event )
  57. {
  58. TrackView::keyPressEvent( event );
  59. }
  60. bool
  61. PlaylistView::eventFilter( QObject* obj, QEvent* event )
  62. {
  63. if ( event->type() == QEvent::DragEnter )
  64. {
  65. QDragEnterEvent* e = static_cast<QDragEnterEvent*>(event);
  66. dragEnterEvent( e );
  67. return true;
  68. }
  69. if ( event->type() == QEvent::DragMove )
  70. {
  71. QDragMoveEvent* e = static_cast<QDragMoveEvent*>(event);
  72. dragMoveEvent( e );
  73. return true;
  74. }
  75. if ( event->type() == QEvent::DragLeave )
  76. {
  77. QDragLeaveEvent* e = static_cast<QDragLeaveEvent*>(event);
  78. dragLeaveEvent( e );
  79. return true;
  80. }
  81. if ( event->type() == QEvent::Drop )
  82. {
  83. QDropEvent* e = static_cast<QDropEvent*>(event);
  84. dropEvent( e );
  85. return true;
  86. }
  87. return QObject::eventFilter( obj, event );
  88. }
  89. QList<PlaylistUpdaterInterface*>
  90. PlaylistView::updaters() const
  91. {
  92. if ( !m_model->playlist().isNull() )
  93. return m_model->playlist()->updaters();
  94. return QList<PlaylistUpdaterInterface*>();
  95. }
  96. void
  97. PlaylistView::onDeleted()
  98. {
  99. emit destroyed( widget() );
  100. }
  101. void
  102. PlaylistView::onChanged()
  103. {
  104. if ( m_model )
  105. {
  106. if ( m_model->isReadOnly() )
  107. setEmptyTip( tr( "This playlist is currently empty." ) );
  108. else
  109. setEmptyTip( tr( "This playlist is currently empty. Add some tracks to it and enjoy the music!" ) );
  110. m_model->finishLoading();
  111. setGuid( proxyModel()->guid() );
  112. if ( !m_model->playlist().isNull() && ViewManager::instance()->currentPage() == this )
  113. emit nameChanged( m_model->playlist()->title() );
  114. }
  115. }
  116. bool
  117. PlaylistView::isTemporaryPage() const
  118. {
  119. return ( m_model && m_model->isTemporary() );
  120. }
  121. void
  122. PlaylistView::onMenuTriggered( int action )
  123. {
  124. switch ( action )
  125. {
  126. default:
  127. break;
  128. }
  129. }