From f74e49b99bb299eb53b1bf72464826bcb8ec5c03 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 1 Jun 2012 01:58:21 +0200 Subject: [PATCH] * Show how many items are currently in the queue. --- src/libtomahawk/playlist/QueueProxyModel.cpp | 24 ++++++++++++++++---- src/libtomahawk/playlist/QueueProxyModel.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/libtomahawk/playlist/QueueProxyModel.cpp b/src/libtomahawk/playlist/QueueProxyModel.cpp index 80c1d7dea..e544eb645 100644 --- a/src/libtomahawk/playlist/QueueProxyModel.cpp +++ b/src/libtomahawk/playlist/QueueProxyModel.cpp @@ -19,10 +19,12 @@ #include "QueueProxyModel.h" +#include "audio/AudioEngine.h" #include "playlist/TrackView.h" +#include "PlayableItem.h" #include "ViewManager.h" -#include "utils/Logger.h" #include "Source.h" +#include "utils/Logger.h" using namespace Tomahawk; @@ -30,10 +32,9 @@ using namespace Tomahawk; QueueProxyModel::QueueProxyModel( TrackView* parent ) : PlayableProxyModel( parent ) { - qDebug() << Q_FUNC_INFO; - - connect( parent, SIGNAL( itemActivated( QModelIndex ) ), this, SLOT( onIndexActivated( QModelIndex ) ) ); - connect( playlistInterface().data(), SIGNAL( sourceTrackCountChanged( unsigned int ) ), this, SLOT( onTrackCountChanged( unsigned int ) ) ); + connect( parent, SIGNAL( itemActivated( QModelIndex ) ), SLOT( onIndexActivated( QModelIndex ) ) ); + connect( playlistInterface().data(), SIGNAL( sourceTrackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) ); + connect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), SLOT( onPlaybackStarted( Tomahawk::result_ptr ) ) ); } @@ -42,6 +43,19 @@ QueueProxyModel::~QueueProxyModel() } +void +QueueProxyModel::onPlaybackStarted( const Tomahawk::result_ptr& result ) +{ + for ( int i = 0; i < rowCount(); i++ ) + { + QModelIndex idx = index( i, 0 ); + PlayableItem* item = itemFromIndex( mapToSource( idx ) ); + if ( item && item->query() && item->query()->equals( result->toQuery() ) ) + remove( idx ); + } +} + + void QueueProxyModel::onIndexActivated( const QModelIndex& index ) { diff --git a/src/libtomahawk/playlist/QueueProxyModel.h b/src/libtomahawk/playlist/QueueProxyModel.h index 3ea2f9254..3c39a68dc 100644 --- a/src/libtomahawk/playlist/QueueProxyModel.h +++ b/src/libtomahawk/playlist/QueueProxyModel.h @@ -38,6 +38,7 @@ public: private slots: void onIndexActivated( const QModelIndex& index ); void onTrackCountChanged( unsigned int count ); + void onPlaybackStarted( const Tomahawk::result_ptr& result ); }; #endif // QUEUEPROXYMODEL_H