1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-21 13:21:52 +02:00

Add a transfer item to jobsview

Add files

work

add file
This commit is contained in:
Leo Franchi
2011-09-17 16:22:12 -04:00
parent b6c1d06165
commit 70c1cc8829
15 changed files with 286 additions and 202 deletions

BIN
data/images/downloading.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
data/images/headphones.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
data/images/uploading.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -116,5 +116,8 @@
<file>data/images/drop-song.png</file>
<file>data/images/drop-album.png</file>
<file>data/images/spotify-logo.jpg</file>
<file>data/images/uploading.png</file>
<file>data/images/downloading.png</file>
<file>data/images/headphones.png</file>
</qresource>
</RCC>

View File

@@ -65,7 +65,6 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
# breakpad/BreakPad.cpp
transferview.cpp
tomahawktrayicon.cpp
audiocontrols.cpp
settingsdialog.cpp
@@ -114,7 +113,6 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui}
sourcetree/items/genericpageitems.h
sourcetree/items/temporarypageitem.h
transferview.h
tomahawktrayicon.h
audiocontrols.h
settingsdialog.h

View File

@@ -219,6 +219,7 @@ set( libSources
jobview/JobStatusModel.cpp
jobview/JobStatusDelegate.cpp
jobview/PipelineStatusItem.cpp
jobview/TransferStatusItem.cpp
thirdparty/kdsingleapplicationguard/kdsingleapplicationguard.cpp
thirdparty/kdsingleapplicationguard/kdsharedmemorylocker.cpp
@@ -431,6 +432,7 @@ set( libHeaders
jobview/JobStatusDelegate.h
jobview/JobStatusItem.h
jobview/PipelineStatusItem.h
jobview/TransferStatusItem.h
thirdparty/kdsingleapplicationguard/kdsingleapplicationguard.h
thirdparty/Qocoa/qsearchfield.h

View File

@@ -0,0 +1,55 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "DatabaseCommand_Latched.h"
DatabaseCommand_Latched::DatabaseCommand_Latched(QObject* parent): DatabaseCommandLoggable(parent)
{
}
DatabaseCommand_Latched::DatabaseCommand_Latched(const Tomahawk::source_ptr& s, QObject* parent): DatabaseCommandLoggable(parent)
{
}
bool DatabaseCommand_Latched::doesMutates() const
{
return DatabaseCommand::doesMutates();
}
void DatabaseCommand_Latched::exec(DatabaseImpl* )
{
DatabaseCommand::exec();
}
void DatabaseCommand_Latched::postCommitHook()
{
DatabaseCommand::postCommitHook();
}
bool DatabaseCommand_Latched::singletonCmd() const
{
return DatabaseCommand::singletonCmd();
}
bool DatabaseCommand_Latched::localOnly() const
{
return DatabaseCommand::localOnly();
}

View File

@@ -1,6 +1,6 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,40 +16,30 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRANSFERVIEW_H
#define TRANSFERVIEW_H
#ifndef DATABASECOMMAND_LATCHED_H
#define DATABASECOMMAND_LATCHED_H
#include <QTreeWidget>
#include "database/databasecommandloggable.h"
#include "typedefs.h"
#include "widgets/animatedsplitter.h"
class DatabaseImpl;
class StreamConnection;
class TransferView : public AnimatedWidget
class DatabaseCommand_Latched : public DatabaseCommandLoggable
{
Q_OBJECT
public:
explicit TransferView( AnimatedSplitter* parent );
virtual ~TransferView()
{
}
QSize sizeHint() const;
signals:
private slots:
void streamRegistered( StreamConnection* sc );
void streamFinished( StreamConnection* sc );
void onTransferUpdate();
private:
QHash< StreamConnection*, QPersistentModelIndex > m_index;
QTreeWidget* m_tree;
AnimatedSplitter* m_parent;
enum LatchAction {
LatchedOn = 0,
LatchedOff
};
#endif // TRANSFERVIEW_H
explicit DatabaseCommand_Latched( QObject* parent = 0 );
explicit DatabaseCommand_Latched( const Tomahawk::source_ptr& s, QObject* parent = 0 );
virtual bool doesMutates() const { return true; }
virtual void exec( DatabaseImpl* );
virtual void postCommitHook();
virtual bool singletonCmd() const;
virtual bool localOnly() const;
};
#endif // DATABASECOMMAND_LATCHED_H

View File

@@ -18,9 +18,11 @@
#include "JobStatusDelegate.h"
#include "JobStatusModel.h"
#include "utils/logger.h"
#include <QPainter>
#include <QApplication>
#include "JobStatusModel.h"
#define ROW_HEIGHT 20
#define PADDING 2
@@ -43,12 +45,12 @@ JobStatusDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
initStyleOption( &opt, index );
QFontMetrics fm( opt.font );
opt.state &= ~QStyle::State_MouseOver;
QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget );
// painter->drawLine( opt.rect.topLeft(), opt.rect.topRight() );
painter->setRenderHint( QPainter::Antialiasing );
painter->drawLine( opt.rect.topLeft(), opt.rect.topRight() );
const QRect iconRect( PADDING, PADDING + opt.rect.y(), ROW_HEIGHT - 2*PADDING, ROW_HEIGHT - 2*PADDING );
QPixmap p = index.data( Qt::DecorationRole ).value< QPixmap >();
p = p.scaled( iconRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
@@ -66,7 +68,7 @@ JobStatusDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
rightEdge = rRect.left();
}
const int mainW = rightEdge - iconRect.right();
const int mainW = rightEdge - PADDING - iconRect.right();
QString mainText = index.data( Qt::DisplayRole ).toString();
mainText = fm.elidedText( mainText, Qt::ElideRight, mainW );
painter->drawText( QRect( iconRect.right() + 2*PADDING, PADDING + opt.rect.y(), mainW, opt.rect.height() - 2*PADDING ), Qt::AlignLeft | Qt::AlignVCenter, mainText );

View File

@@ -112,30 +112,33 @@ JobStatusModel::itemFinished()
JobStatusItem* item = qobject_cast< JobStatusItem* >( sender() );
Q_ASSERT( item );
// tDebug() << "Got item finished:" << item->type() << item->mainText() << item;
// foreach( JobStatusItem* item, m_items )
// {
// qDebug() << "ITEM #:" << item;
// }
// foreach( const QString& str, m_collapseCount.keys() )
// {
// tDebug() << "\t" << str;
// foreach( JobStatusItem* chain, m_collapseCount[ str ] )
// qDebug() << "\t\t" << chain;
// }
tDebug() << "Got item finished:" << item->type() << item->mainText() << item;
if ( !m_items.contains( item ) && !m_collapseCount.contains( item->type() ) )
return;
foreach( JobStatusItem* item, m_items )
{
qDebug() << "ITEM #:" << item;
}
foreach( const QString& str, m_collapseCount.keys() )
{
tDebug() << "\t" << str;
foreach( JobStatusItem* chain, m_collapseCount[ str ] )
qDebug() << "\t\t" << chain;
}
if ( m_collapseCount.contains( item->type() ) )
{
const int indexOf = m_items.indexOf( m_collapseCount[ item->type() ].first() );
// tDebug() << "index in main list of collapsed irst item:" << indexOf;
tDebug() << "index in main list of collapsed irst item:" << indexOf;
if ( m_collapseCount[ item->type() ].first() == item &&
m_items.contains( m_collapseCount[ item->type() ].first() ) && m_collapseCount[ item->type() ].size() > 1 )
{
// the placeholder we use that links m_items and m_collapsecount is done, so choose another one
m_items.replace( m_items.indexOf( m_collapseCount[ item->type() ].first() ), m_collapseCount[ item->type() ][ 1 ] );
// qDebug() << "Replaced" << m_collapseCount[ item->type() ].first() << "with:" << m_collapseCount[ item->type() ][ 1 ] << m_items;
qDebug() << "Replaced" << m_collapseCount[ item->type() ].first() << "with:" << m_collapseCount[ item->type() ][ 1 ] << m_items;
}
m_collapseCount[ item->type() ].removeAll( item );
// tDebug() << "New collapse count list:" << m_collapseCount[ item->type() ];
tDebug() << "New collapse count list:" << m_collapseCount[ item->type() ];
if ( m_collapseCount[ item->type() ].isEmpty() )
m_collapseCount.remove( item->type() );
else
@@ -149,6 +152,9 @@ JobStatusModel::itemFinished()
// Remove row completely
const int idx = m_items.indexOf( item );
tDebug() << "Got index of item:" << idx;
Q_ASSERT( idx >= 0 );
beginRemoveRows( QModelIndex(), idx, idx );
m_items.removeAll( item );
endRemoveRows();

View File

@@ -31,6 +31,7 @@
#include <QVBoxLayout>
#include <QListView>
#include <QAbstractItemModel>
#include "TransferStatusItem.h"
using namespace Tomahawk;
@@ -73,6 +74,7 @@ JobStatusView::JobStatusView( AnimatedSplitter* parent )
hideWidget();
new PipelineStatusManager( this );
new TransferStatusManager( this );
}
void

View File

@@ -0,0 +1,113 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TransferStatusItem.h"
#include "JobStatusView.h"
#include "JobStatusModel.h"
#include "network/streamconnection.h"
#include "network/servent.h"
#include "utils/tomahawkutils.h"
#include "result.h"
#include "source.h"
#include "artist.h"
TransferStatusItem::TransferStatusItem( TransferStatusManager* p, StreamConnection* sc )
: m_parent( p )
, m_stream( QWeakPointer< StreamConnection >( sc ) )
{
if ( m_stream.data()->type() == StreamConnection::RECEIVING )
m_type = "receive";
else
m_type = "send";
connect( m_stream.data(), SIGNAL( updated() ), SLOT( onTransferUpdate() ) );
connect( Servent::instance(), SIGNAL( streamFinished( StreamConnection* ) ), SLOT( streamFinished( StreamConnection* ) ) );
}
TransferStatusItem::~TransferStatusItem()
{
}
QString
TransferStatusItem::mainText() const
{
if ( m_stream.isNull() )
return QString();
if ( m_stream.data()->source().isNull() && !m_stream.data()->track().isNull() )
return QString( "%1" ).arg( QString( "%1 - %2" ).arg( m_stream.data()->track()->artist()->name() ).arg( m_stream.data()->track()->track() ) );
else if ( !m_stream.data()->source().isNull() && !m_stream.data()->track().isNull() )
return QString( "%1 %2 %3" ).arg( QString( "%1 - %2" ).arg( m_stream.data()->track()->artist()->name() ).arg( m_stream.data()->track()->track() ) )
.arg( m_stream.data()->type() == StreamConnection::RECEIVING ? tr( "from" ) : tr( "to" ) )
.arg( m_stream.data()->source()->friendlyName() );
else
return QString();
}
QString
TransferStatusItem::rightColumnText() const
{
if ( m_stream.isNull() )
return QString();
return QString( "%1 kb/s" ).arg( m_stream.data()->transferRate() / 1024 );
}
void
TransferStatusItem::streamFinished( StreamConnection* sc )
{
if ( m_stream.data() == sc )
emit finished();
}
QPixmap
TransferStatusItem::icon() const
{
if ( m_stream.isNull() )
return QPixmap();
if ( m_stream.data()->type() == StreamConnection::SENDING )
return m_parent->rxPixmap();
else
return m_parent->txPixmap();
}
void
TransferStatusItem::onTransferUpdate()
{
emit statusChanged();
}
TransferStatusManager::TransferStatusManager( QObject* parent )
: QObject( parent )
{
m_rxPixmap.load( RESPATH "images/uploading.png" );
m_txPixmap.load( RESPATH "images/downloading.png" );
connect( Servent::instance(), SIGNAL( streamStarted( StreamConnection* ) ), SLOT( streamRegistered( StreamConnection* ) ) );
}
void
TransferStatusManager::streamRegistered( StreamConnection* sc )
{
JobStatusView::instance()->model()->addJob( new TransferStatusItem( this, sc ) );
}

View File

@@ -0,0 +1,65 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRANSFERSTATUSITEM_H
#define TRANSFERSTATUSITEM_H
#include "JobStatusItem.h"
class StreamConnection;
class TransferStatusManager : public QObject
{
Q_OBJECT
public:
explicit TransferStatusManager( QObject* parent = 0 );
virtual ~TransferStatusManager() {}
QPixmap rxPixmap() const { return m_rxPixmap; }
QPixmap txPixmap() const { return m_txPixmap; }
private slots:
void streamRegistered( StreamConnection* sc );
private:
QPixmap m_rxPixmap, m_txPixmap;
};
class TransferStatusItem : public JobStatusItem
{
Q_OBJECT
public:
explicit TransferStatusItem( TransferStatusManager* p, StreamConnection* );
virtual ~TransferStatusItem();
virtual QString rightColumnText() const;
virtual QString mainText() const;
virtual QPixmap icon() const;
virtual QString type() const { return m_type; }
private slots:
void streamFinished( StreamConnection* sc );
void onTransferUpdate();
private:
TransferStatusManager* m_parent;
QString m_type, m_main, m_right;
QWeakPointer< StreamConnection > m_stream;
};
#endif // TRANSFERSTATUSITEM_H

View File

@@ -58,7 +58,6 @@
#include "tomahawksettings.h"
#include "sourcelist.h"
#include "jobview/JobStatusView.h"
#include "transferview.h"
#include "tomahawktrayicon.h"
#include "scanmanager.h"
#include "tomahawkapp.h"
@@ -205,7 +204,6 @@ TomahawkWindow::setupSideBar()
connect( m_searchWidget, SIGNAL( returnPressed() ), this, SLOT( onFilterEdited() ) );
m_sourcetree = new SourceTreeView();
TransferView* transferView = new TransferView( m_sidebar );
JobStatusView* jobsView = new JobStatusView( m_sidebar );
m_jobsModel = new JobStatusModel( jobsView );
jobsView->setModel( m_jobsModel );
@@ -219,7 +217,6 @@ TomahawkWindow::setupSideBar()
m_sidebar->addWidget( m_searchWidget );
m_sidebar->addWidget( m_sourcetree );
m_sidebar->addWidget( transferView );
m_sidebar->addWidget( jobsView );
m_sidebar->addWidget( m_queueView );

View File

@@ -1,149 +0,0 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "transferview.h"
#include <QHeaderView>
#include <QVBoxLayout>
#include "artist.h"
#include "source.h"
#include "network/streamconnection.h"
#include "network/servent.h"
#include "utils/logger.h"
TransferView::TransferView( AnimatedSplitter* parent )
: AnimatedWidget( parent )
, m_parent( parent )
{
setHiddenSize( QSize( 0, 0 ) );
setLayout( new QVBoxLayout() );
m_tree = new QTreeWidget( this );
layout()->setMargin( 0 );
layout()->addWidget( m_tree );
connect( Servent::instance(), SIGNAL( streamStarted( StreamConnection* ) ), SLOT( streamRegistered( StreamConnection* ) ) );
connect( Servent::instance(), SIGNAL( streamFinished( StreamConnection* ) ), SLOT( streamFinished( StreamConnection* ) ) );
QStringList headers;
headers << tr( "Peer" ) << tr( "Rate" ) << tr( "Track" );
m_tree->setHeaderLabels( headers );
m_tree->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
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 );
m_tree->header()->setStretchLastSection( true );
m_tree->setRootIsDecorated( false );
m_tree->setFrameShape( QFrame::NoFrame );
m_tree->setAttribute( Qt::WA_MacShowFocusRect, 0 );
#ifndef Q_WS_WIN
QFont f = font();
f.setPointSize( f.pointSize() - 1 );
setFont( f );
#endif
#ifdef Q_WS_MAC
f.setPointSize( f.pointSize() - 2 );
setFont( f );
#endif
}
void
TransferView::streamRegistered( StreamConnection* sc )
{
qDebug() << Q_FUNC_INFO;
connect( sc, SIGNAL( updated() ), SLOT( onTransferUpdate() ) );
}
void
TransferView::streamFinished( StreamConnection* sc )
{
if ( !m_index.contains( sc ) )
return;
QPersistentModelIndex i = m_index.take( sc );
delete m_tree->invisibleRootItem()->takeChild( i.row() );
if ( m_tree->invisibleRootItem()->childCount() > 0 )
emit showWidget();
else
emit hideWidget();
}
void
TransferView::onTransferUpdate()
{
StreamConnection* sc = (StreamConnection*)sender();
// qDebug() << Q_FUNC_INFO << sc->track().isNull() << sc->source().isNull();
if ( sc->track().isNull() || sc->source().isNull() )
return;
QTreeWidgetItem* ti = 0;
if ( m_index.contains( sc ) )
{
QPersistentModelIndex i = m_index.value( sc );
ti = m_tree->invisibleRootItem()->child( i.row() );
}
else
{
ti = new QTreeWidgetItem( m_tree );
m_index.insert( sc, QPersistentModelIndex( m_tree->model()->index( m_tree->invisibleRootItem()->childCount() - 1, 0 ) ) );
emit showWidget();
}
if ( !ti )
return;
ti->setText( 0, sc->source()->friendlyName() );
ti->setText( 1, QString( "%1 kb/s" ).arg( sc->transferRate() / 1024 ) );
ti->setText( 2, QString( "%1 - %2" ).arg( sc->track()->artist()->name() ).arg( sc->track()->track() ) );
if ( isHidden() )
emit showWidget();
}
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 );
}