2010-11-28 12:26:01 +01:00
|
|
|
#include "transferview.h"
|
|
|
|
|
|
|
|
#include <QHeaderView>
|
2010-11-29 05:34:25 +01:00
|
|
|
#include <QVBoxLayout>
|
2010-11-28 12:26:01 +01:00
|
|
|
|
|
|
|
#include "tomahawk/tomahawkapp.h"
|
2010-12-06 20:44:39 -05:00
|
|
|
#include "tomahawk/artist.h"
|
2010-11-28 12:26:01 +01:00
|
|
|
#include "network/filetransferconnection.h"
|
|
|
|
#include "network/servent.h"
|
|
|
|
|
|
|
|
|
2010-11-29 05:34:25 +01:00
|
|
|
TransferView::TransferView( AnimatedSplitter* parent )
|
|
|
|
: AnimatedWidget( parent )
|
|
|
|
, m_parent( parent )
|
2010-11-28 12:26:01 +01:00
|
|
|
{
|
2010-11-29 05:34:25 +01:00
|
|
|
setHiddenSize( QSize( 0, 0 ) );
|
|
|
|
setLayout( new QVBoxLayout() );
|
|
|
|
m_tree = new QTreeWidget( this );
|
|
|
|
|
|
|
|
layout()->setMargin( 0 );
|
|
|
|
layout()->addWidget( m_tree );
|
|
|
|
|
2010-11-28 12:26:01 +01:00
|
|
|
connect( &APP->servent(), SIGNAL( fileTransferStarted( FileTransferConnection* ) ), SLOT( fileTransferRegistered( FileTransferConnection* ) ) );
|
|
|
|
connect( &APP->servent(), SIGNAL( fileTransferFinished( FileTransferConnection* ) ), SLOT( fileTransferFinished( FileTransferConnection* ) ) );
|
|
|
|
|
|
|
|
QStringList headers;
|
|
|
|
headers << tr( "Peer" ) << tr( "Rate" ) << tr( "Track" );
|
2010-11-29 05:34:25 +01:00
|
|
|
m_tree->setHeaderLabels( headers );
|
2010-11-28 12:26:01 +01:00
|
|
|
|
2010-11-29 05:34:25 +01:00
|
|
|
m_tree->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored );
|
|
|
|
m_tree->setColumnCount( 3 );
|
|
|
|
m_tree->setColumnWidth( 0, 80 );
|
|
|
|
m_tree->setColumnWidth( 1, 65 );
|
|
|
|
m_tree->setColumnWidth( 2, 10 );
|
2010-11-28 12:26:01 +01:00
|
|
|
|
2010-11-29 05:34:25 +01:00
|
|
|
m_tree->header()->setStretchLastSection( true );
|
|
|
|
m_tree->setRootIsDecorated( false );
|
2010-11-28 12:26:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TransferView::fileTransferRegistered( FileTransferConnection* ftc )
|
|
|
|
{
|
2010-11-29 07:51:18 +01:00
|
|
|
qDebug() << Q_FUNC_INFO;
|
2010-11-28 12:26:01 +01:00
|
|
|
connect( ftc, SIGNAL( updated() ), SLOT( onTransferUpdate() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TransferView::fileTransferFinished( FileTransferConnection* ftc )
|
|
|
|
{
|
|
|
|
if ( !m_index.contains( ftc ) )
|
|
|
|
return;
|
|
|
|
|
2010-11-29 11:42:50 +01:00
|
|
|
QPersistentModelIndex i = m_index.take( ftc );
|
|
|
|
delete m_tree->invisibleRootItem()->takeChild( i.row() );
|
2010-11-28 12:26:01 +01:00
|
|
|
|
2010-11-29 05:34:25 +01:00
|
|
|
if ( m_tree->invisibleRootItem()->childCount() > 0 )
|
|
|
|
emit showWidget();
|
|
|
|
else
|
|
|
|
emit hideWidget();
|
|
|
|
|
|
|
|
/* if ( m_index.contains( ftc ) )
|
2010-11-28 12:26:01 +01:00
|
|
|
{
|
|
|
|
int i = m_index.value( ftc );
|
2010-11-29 05:34:25 +01:00
|
|
|
m_tree->invisibleRootItem()->child( i )->setText( 1, tr( "Finished" ) );
|
|
|
|
}*/
|
2010-11-28 12:26:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TransferView::onTransferUpdate()
|
|
|
|
{
|
|
|
|
FileTransferConnection* ftc = (FileTransferConnection*)sender();
|
2010-11-29 11:42:50 +01:00
|
|
|
// qDebug() << Q_FUNC_INFO << ftc->track().isNull() << ftc->source().isNull();
|
|
|
|
|
2010-11-28 17:06:13 +01:00
|
|
|
if ( ftc->track().isNull() || ftc->source().isNull() )
|
2010-11-28 12:30:12 +01:00
|
|
|
return;
|
|
|
|
|
2010-11-28 12:26:01 +01:00
|
|
|
QTreeWidgetItem* ti = 0;
|
|
|
|
|
|
|
|
if ( m_index.contains( ftc ) )
|
|
|
|
{
|
2010-11-29 11:42:50 +01:00
|
|
|
QPersistentModelIndex i = m_index.value( ftc );
|
|
|
|
ti = m_tree->invisibleRootItem()->child( i.row() );
|
2010-11-28 12:26:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-29 05:34:25 +01:00
|
|
|
ti = new QTreeWidgetItem( m_tree );
|
2010-11-29 11:42:50 +01:00
|
|
|
m_index.insert( ftc, QPersistentModelIndex( m_tree->model()->index( m_tree->invisibleRootItem()->childCount() - 1, 0 ) ) );
|
2010-11-29 09:17:56 +01:00
|
|
|
emit showWidget();
|
2010-11-28 12:26:01 +01:00
|
|
|
}
|
|
|
|
|
2010-11-29 08:27:51 +01:00
|
|
|
if ( !ti )
|
|
|
|
return;
|
|
|
|
|
2010-11-28 12:26:01 +01:00
|
|
|
ti->setText( 0, ftc->source()->friendlyName() );
|
|
|
|
ti->setText( 1, QString( "%1 kb/s" ).arg( ftc->transferRate() / 1024 ) );
|
|
|
|
ti->setText( 2, QString( "%1 - %2" ).arg( ftc->track()->artist()->name() ).arg( ftc->track()->track() ) );
|
2010-11-29 05:34:25 +01:00
|
|
|
|
2010-11-29 07:51:18 +01:00
|
|
|
if ( isHidden() )
|
|
|
|
emit showWidget();
|
2010-11-29 05:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QSize
|
|
|
|
TransferView::sizeHint() const
|
|
|
|
{
|
|
|
|
unsigned int y = 0;
|
|
|
|
y += m_tree->header()->height();
|
|
|
|
y += m_tree->contentsMargins().top() + m_tree->contentsMargins().bottom();
|
|
|
|
|
|
|
|
if ( m_tree->invisibleRootItem()->childCount() )
|
|
|
|
{
|
|
|
|
unsigned int rowheight = m_tree->sizeHintForRow( 0 );
|
|
|
|
y += rowheight * m_tree->invisibleRootItem()->childCount() + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QSize( 0, y );
|
2010-11-28 12:26:01 +01:00
|
|
|
}
|