1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
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.
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.
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/>.
19
#include "TransferStatusItem.h"
21
#include "JobStatusView.h"
22
#include "JobStatusModel.h"
26
#include "network/StreamConnection.h"
27
#include "network/Servent.h"
28
#include "utils/TomahawkUtilsGui.h"
31
TransferStatusItem::TransferStatusItem( TransferStatusManager* p, StreamConnection* sc )
33
, m_stream( QWeakPointer< StreamConnection >( sc ) )
35
if ( m_stream.data()->type() == StreamConnection::RECEIVING )
40
connect( m_stream.data(), SIGNAL( updated() ), SLOT( onTransferUpdate() ) );
41
connect( Servent::instance(), SIGNAL( streamFinished( StreamConnection* ) ), SLOT( streamFinished( StreamConnection* ) ) );
44
TransferStatusItem::~TransferStatusItem()
50
TransferStatusItem::mainText() const
52
if ( m_stream.isNull() )
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() );
66
TransferStatusItem::rightColumnText() const
68
if ( m_stream.isNull() )
71
return QString( "%1 kB/s" ).arg( m_stream.data()->transferRate() / 1000 );
75
TransferStatusItem::streamFinished( StreamConnection* sc )
77
if ( m_stream.data() == sc )
82
TransferStatusItem::icon() const
84
if ( m_stream.isNull() )
87
if ( m_stream.data()->type() == StreamConnection::SENDING )
88
return m_parent->txPixmap();
90
return m_parent->rxPixmap();
95
TransferStatusItem::onTransferUpdate()
101
TransferStatusManager::TransferStatusManager( QObject* parent )
104
connect( Servent::instance(), SIGNAL( streamStarted( StreamConnection* ) ), SLOT( streamRegistered( StreamConnection* ) ) );
108
TransferStatusManager::streamRegistered( StreamConnection* sc )
110
JobStatusView::instance()->model()->addJob( new TransferStatusItem( this, sc ) );
115
TransferStatusManager::rxPixmap() const
117
return TomahawkUtils::defaultPixmap( TomahawkUtils::Downloading, TomahawkUtils::Original, QSize( 128, 128 ) );
122
TransferStatusManager::txPixmap() const
124
return TomahawkUtils::defaultPixmap( TomahawkUtils::Uploading, TomahawkUtils::Original, QSize( 128, 128 ) );