~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/jobview/PipelineStatusItem.cpp

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

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