/src/libtomahawk/jobview/PipelineStatusItem.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 109 lines · 64 code · 25 blank · 20 comment · 4 complexity · d6ae37e71e9d484056ef023f4f13a893 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  4. * Christian Muehlhaeuser <muesli@tomahawk-player.org>
  5. * Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  6. *
  7. * Tomahawk is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Tomahawk is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "PipelineStatusItem.h"
  21. #include "utils/TomahawkUtilsGui.h"
  22. #include "JobStatusModel.h"
  23. #include "JobStatusView.h"
  24. #include "Pipeline.h"
  25. #include "Source.h"
  26. #include "Track.h"
  27. PipelineStatusItem::PipelineStatusItem( const Tomahawk::query_ptr& q )
  28. : JobStatusItem()
  29. {
  30. connect( Tomahawk::Pipeline::instance(), SIGNAL( resolving( Tomahawk::query_ptr ) ), this, SLOT( resolving( Tomahawk::query_ptr ) ) );
  31. connect( Tomahawk::Pipeline::instance(), SIGNAL( idle() ), this, SLOT( idle() ) );
  32. if ( !q.isNull() )
  33. resolving( q );
  34. }
  35. PipelineStatusItem::~PipelineStatusItem()
  36. {
  37. }
  38. QString
  39. PipelineStatusItem::rightColumnText() const
  40. {
  41. return QString( "%1" ).arg( Tomahawk::Pipeline::instance()->activeQueryCount() + Tomahawk::Pipeline::instance()->pendingQueryCount() );
  42. }
  43. QString
  44. PipelineStatusItem::mainText() const
  45. {
  46. return m_latestQuery;
  47. }
  48. void
  49. PipelineStatusItem::idle()
  50. {
  51. if ( !Tomahawk::Pipeline::instance()->activeQueryCount() )
  52. emit finished();
  53. }
  54. QPixmap
  55. PipelineStatusItem::icon() const
  56. {
  57. return TomahawkUtils::defaultPixmap( TomahawkUtils::Search );
  58. }
  59. void
  60. PipelineStatusItem::resolving( const Tomahawk::query_ptr& query )
  61. {
  62. if ( query->isFullTextQuery() )
  63. m_latestQuery = query->fullTextQuery();
  64. else
  65. m_latestQuery = QString( "%1 - %2" ).arg( query->queryTrack()->artist() ).arg( query->queryTrack()->track() );
  66. Q_ASSERT( !m_latestQuery.isEmpty() );
  67. emit statusChanged();
  68. }
  69. PipelineStatusManager::PipelineStatusManager( QObject* parent )
  70. : QObject( parent )
  71. {
  72. connect( Tomahawk::Pipeline::instance(), SIGNAL( resolving( Tomahawk::query_ptr ) ), this, SLOT( resolving( Tomahawk::query_ptr ) ) );
  73. }
  74. void
  75. PipelineStatusManager::resolving( const Tomahawk::query_ptr& p )
  76. {
  77. Q_UNUSED( p );
  78. if ( m_curItem.isNull() )
  79. {
  80. // No current query item and we're resolving something, so show it
  81. m_curItem = QPointer< PipelineStatusItem >( new PipelineStatusItem( p ) );
  82. JobStatusView::instance()->model()->addJob( m_curItem.data() );
  83. }
  84. }