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

« back to all changes in this revision

Viewing changes to src/libtomahawk/jobview/TransferStatusItem.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
 *
 
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
 
 
19
#include "TransferStatusItem.h"
 
20
 
 
21
#include "JobStatusView.h"
 
22
#include "JobStatusModel.h"
 
23
#include "Result.h"
 
24
#include "Source.h"
 
25
#include "Artist.h"
 
26
#include "network/StreamConnection.h"
 
27
#include "network/Servent.h"
 
28
#include "utils/TomahawkUtilsGui.h"
 
29
 
 
30
 
 
31
TransferStatusItem::TransferStatusItem( TransferStatusManager* p, StreamConnection* sc )
 
32
    : m_parent( p )
 
33
    , m_stream( QWeakPointer< StreamConnection >( sc ) )
 
34
{
 
35
    if ( m_stream.data()->type() == StreamConnection::RECEIVING )
 
36
        m_type = "receive";
 
37
    else
 
38
        m_type = "send";
 
39
 
 
40
    connect( m_stream.data(), SIGNAL( updated() ), SLOT( onTransferUpdate() ) );
 
41
    connect( Servent::instance(), SIGNAL( streamFinished( StreamConnection* ) ), SLOT( streamFinished( StreamConnection* ) ) );
 
42
}
 
43
 
 
44
TransferStatusItem::~TransferStatusItem()
 
45
{
 
46
 
 
47
}
 
48
 
 
49
QString
 
50
TransferStatusItem::mainText() const
 
51
{
 
52
    if ( m_stream.isNull() )
 
53
        return QString();
 
54
 
 
55
    if ( m_stream.data()->source().isNull() && !m_stream.data()->track().isNull() )
 
56
        return QString( "%1" ).arg( QString( "%1 - %2" ).arg( m_stream.data()->track()->artist()->name() ).arg( m_stream.data()->track()->track() ) );
 
57
    else if ( !m_stream.data()->source().isNull() && !m_stream.data()->track().isNull() )
 
58
        return QString( "%1 %2 %3" ).arg( QString( "%1 - %2" ).arg( m_stream.data()->track()->artist()->name() ).arg( m_stream.data()->track()->track() ) )
 
59
                                .arg( m_stream.data()->type() == StreamConnection::RECEIVING ? tr( "from", "streaming artist - track from friend" ) : tr( "to", "streaming artist - track to friend" ) )
 
60
                                .arg( m_stream.data()->source()->friendlyName() );
 
61
    else
 
62
        return QString();
 
63
}
 
64
 
 
65
QString
 
66
TransferStatusItem::rightColumnText() const
 
67
{
 
68
    if ( m_stream.isNull() )
 
69
        return QString();
 
70
 
 
71
    return QString( "%1 kB/s" ).arg( m_stream.data()->transferRate() / 1000 );
 
72
}
 
73
 
 
74
void
 
75
TransferStatusItem::streamFinished( StreamConnection* sc )
 
76
{
 
77
    if ( m_stream.data() == sc )
 
78
        emit finished();
 
79
}
 
80
 
 
81
QPixmap
 
82
TransferStatusItem::icon() const
 
83
{
 
84
    if ( m_stream.isNull() )
 
85
        return QPixmap();
 
86
 
 
87
    if ( m_stream.data()->type() == StreamConnection::SENDING )
 
88
        return m_parent->txPixmap();
 
89
    else
 
90
        return m_parent->rxPixmap();
 
91
}
 
92
 
 
93
 
 
94
void
 
95
TransferStatusItem::onTransferUpdate()
 
96
{
 
97
    emit statusChanged();
 
98
}
 
99
 
 
100
 
 
101
TransferStatusManager::TransferStatusManager( QObject* parent )
 
102
    : QObject( parent )
 
103
{
 
104
    connect( Servent::instance(), SIGNAL( streamStarted( StreamConnection* ) ), SLOT( streamRegistered( StreamConnection* ) ) );
 
105
}
 
106
 
 
107
void
 
108
TransferStatusManager::streamRegistered( StreamConnection* sc )
 
109
{
 
110
    JobStatusView::instance()->model()->addJob( new TransferStatusItem( this, sc ) );
 
111
}
 
112
 
 
113
 
 
114
QPixmap
 
115
TransferStatusManager::rxPixmap() const
 
116
{
 
117
    return TomahawkUtils::defaultPixmap( TomahawkUtils::Downloading, TomahawkUtils::Original, QSize( 128, 128 ) );
 
118
}
 
119
 
 
120
 
 
121
QPixmap
 
122
TransferStatusManager::txPixmap() const
 
123
{
 
124
    return TomahawkUtils::defaultPixmap( TomahawkUtils::Uploading, TomahawkUtils::Original, QSize( 128, 128 ) );
 
125
}