PageRenderTime 153ms CodeModel.GetById 61ms app.highlight 9ms RepoModel.GetById 81ms app.codeStats 0ms

/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
 21#include "PipelineStatusItem.h"
 22
 23#include "utils/TomahawkUtilsGui.h"
 24
 25#include "JobStatusModel.h"
 26#include "JobStatusView.h"
 27#include "Pipeline.h"
 28#include "Source.h"
 29#include "Track.h"
 30
 31
 32PipelineStatusItem::PipelineStatusItem( const Tomahawk::query_ptr& q )
 33    : JobStatusItem()
 34{
 35    connect( Tomahawk::Pipeline::instance(), SIGNAL( resolving( Tomahawk::query_ptr ) ), this, SLOT( resolving( Tomahawk::query_ptr ) ) );
 36    connect( Tomahawk::Pipeline::instance(), SIGNAL( idle() ), this, SLOT( idle() ) );
 37
 38    if ( !q.isNull() )
 39        resolving( q );
 40}
 41
 42
 43PipelineStatusItem::~PipelineStatusItem()
 44{
 45}
 46
 47
 48QString
 49PipelineStatusItem::rightColumnText() const
 50{
 51    return QString( "%1" ).arg( Tomahawk::Pipeline::instance()->activeQueryCount() + Tomahawk::Pipeline::instance()->pendingQueryCount() );
 52}
 53
 54
 55QString
 56PipelineStatusItem::mainText() const
 57{
 58    return m_latestQuery;
 59}
 60
 61
 62void
 63PipelineStatusItem::idle()
 64{
 65    if ( !Tomahawk::Pipeline::instance()->activeQueryCount() )
 66        emit finished();
 67}
 68
 69
 70QPixmap
 71PipelineStatusItem::icon() const
 72{
 73    return TomahawkUtils::defaultPixmap( TomahawkUtils::Search );
 74}
 75
 76
 77void
 78PipelineStatusItem::resolving( const Tomahawk::query_ptr& query )
 79{
 80    if ( query->isFullTextQuery() )
 81        m_latestQuery = query->fullTextQuery();
 82    else
 83        m_latestQuery = QString( "%1 - %2" ).arg( query->queryTrack()->artist() ).arg( query->queryTrack()->track() );
 84
 85    Q_ASSERT( !m_latestQuery.isEmpty() );
 86
 87    emit statusChanged();
 88}
 89
 90
 91PipelineStatusManager::PipelineStatusManager( QObject* parent )
 92    : QObject( parent )
 93{
 94    connect( Tomahawk::Pipeline::instance(), SIGNAL( resolving( Tomahawk::query_ptr ) ), this, SLOT( resolving( Tomahawk::query_ptr ) ) );
 95}
 96
 97
 98void
 99PipelineStatusManager::resolving( const Tomahawk::query_ptr& p )
100{
101    Q_UNUSED( p );
102
103    if ( m_curItem.isNull() )
104    {
105        // No current query item and we're resolving something, so show it
106        m_curItem = QPointer< PipelineStatusItem >( new PipelineStatusItem( p ) );
107        JobStatusView::instance()->model()->addJob( m_curItem.data() );
108    }
109}