/src/libtomahawk/playlist/QueueView.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 110 lines · 73 code · 20 blank · 17 comment · 5 complexity · 1d77524931f506bcb8bafa6194d9bce5 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. *
  5. * Tomahawk is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Tomahawk is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "QueueView.h"
  19. #include "playlist/TrackView.h"
  20. #include "playlist/ContextView.h"
  21. #include "playlist/PlaylistModel.h"
  22. #include "playlist/QueueProxyModel.h"
  23. #include "playlist/TrackItemDelegate.h"
  24. #include "utils/Logger.h"
  25. #include "Pipeline.h"
  26. #include "Source.h"
  27. #include "SourceList.h"
  28. #include "TomahawkSettings.h"
  29. #include "utils/TomahawkUtilsGui.h"
  30. using namespace Tomahawk;
  31. QueueView::QueueView( QWidget* parent )
  32. : PlaylistViewPage( parent )
  33. {
  34. view()->setCaption( tr( "Queue Details" ) );
  35. view()->trackView()->setProxyModel( new QueueProxyModel( view()->trackView() ) );
  36. view()->trackView()->proxyModel()->setStyle( PlayableProxyModel::SingleColumn );
  37. view()->trackView()->setHeaderHidden( true );
  38. view()->trackView()->setUniformRowHeights( false );
  39. PlaylistModel* queueModel = new PlaylistModel( view()->trackView() );
  40. queueModel->setAcceptPlayableQueriesOnly( true );
  41. queueModel->setReadOnly( false );
  42. queueModel->setTitle( tr( "Queue" ) );
  43. setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::Queue ) );
  44. view()->trackView()->setPlayableModel( queueModel );
  45. view()->setEmptyTip( tr( "The queue is currently empty. Drop something to enqueue it!" ) );
  46. TrackItemDelegate* delegate = new TrackItemDelegate( TrackItemDelegate::LovedTracks, view()->trackView(), view()->trackView()->proxyModel() );
  47. view()->trackView()->setPlaylistItemDelegate( delegate );
  48. if ( Pipeline::instance()->isRunning() && SourceList::instance()->isReady() )
  49. {
  50. restoreState();
  51. }
  52. else
  53. {
  54. connect( SourceList::instance(), SIGNAL( ready() ), SLOT( restoreState() ) );
  55. connect( Pipeline::instance(), SIGNAL( running() ), SLOT( restoreState() ) );
  56. }
  57. }
  58. QueueView::~QueueView()
  59. {
  60. tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
  61. saveState();
  62. }
  63. void
  64. QueueView::restoreState()
  65. {
  66. if ( !Pipeline::instance()->isRunning() || !SourceList::instance()->isReady() )
  67. return;
  68. QVariantList vl = TomahawkSettings::instance()->queueState().toList();
  69. QList< query_ptr > ql;
  70. foreach ( const QVariant& v, vl )
  71. {
  72. QVariantMap map = v.toMap();
  73. query_ptr q = Query::get( map["artist"].toString(), map["track"].toString(), map["album"].toString() );
  74. ql << q;
  75. }
  76. if ( !ql.isEmpty() )
  77. {
  78. view()->trackView()->model()->appendQueries( ql );
  79. }
  80. }
  81. void
  82. QueueView::saveState()
  83. {
  84. QVariantList vl;
  85. foreach ( const query_ptr& query, view()->trackView()->model()->queries() )
  86. {
  87. vl << query->toVariant();
  88. }
  89. TomahawkSettings::instance()->setQueueState( vl );
  90. }