From 85b3a83144f3e127709b77ec7f328048b22305b1 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 23 Dec 2012 10:06:58 +0100 Subject: [PATCH] * PlayableModel now emits signals for its queries so we don't have to store them everywhere. --- src/libtomahawk/playlist/PlayableModel.cpp | 23 +++++++++++++++++++ src/libtomahawk/playlist/PlayableModel.h | 7 ++++-- .../playlist/PlayableProxyModel.cpp | 9 ++++++++ src/libtomahawk/playlist/PlayableProxyModel.h | 2 ++ src/libtomahawk/playlist/TrackView.cpp | 2 -- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index 76f4d2016..c76be9731 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -62,6 +62,7 @@ PlayableModel::createIndex( int row, int column, PlayableItem* item ) const if ( item->query() ) { connect( item->query().data(), SIGNAL( playableStateChanged( bool ) ), SLOT( onQueryBecamePlayable( bool ) ), Qt::UniqueConnection ); + connect( item->query().data(), SIGNAL( resolvingFinished( bool ) ), SLOT( onQueryResolved( bool ) ), Qt::UniqueConnection ); } return QAbstractItemModel::createIndex( row, column, item ); @@ -884,6 +885,28 @@ PlayableModel::onQueryBecamePlayable( bool playable ) } +void +PlayableModel::onQueryResolved( bool hasResults ) +{ + Q_UNUSED( hasResults ); + + Tomahawk::Query* q = qobject_cast< Query* >( sender() ); + if ( !q ) + { + // Track has been removed from the playlist by now + return; + } + + Tomahawk::query_ptr query = q->weakRef().toStrongRef(); + PlayableItem* item = itemFromQuery( query ); + + if ( item ) + { + emit indexResolved( item->index ); + } +} + + PlayableItem* PlayableModel::itemFromQuery( const Tomahawk::query_ptr& query ) const { diff --git a/src/libtomahawk/playlist/PlayableModel.h b/src/libtomahawk/playlist/PlayableModel.h index 56b5836b3..8b0b69647 100644 --- a/src/libtomahawk/playlist/PlayableModel.h +++ b/src/libtomahawk/playlist/PlayableModel.h @@ -120,9 +120,10 @@ signals: void loadingStarted(); void loadingFinished(); + void indexResolved( const QModelIndex& index ); void indexPlayable( const QModelIndex& index ); - void changed(); + void changed(); void currentIndexChanged(); public slots: @@ -158,8 +159,10 @@ protected: private slots: void onDataChanged(); - void onQueryBecamePlayable( bool playable ); + void onQueryBecamePlayable( bool playable ); + void onQueryResolved( bool hasResults ); + void onPlaybackStarted( const Tomahawk::result_ptr& result ); void onPlaybackStopped(); diff --git a/src/libtomahawk/playlist/PlayableProxyModel.cpp b/src/libtomahawk/playlist/PlayableProxyModel.cpp index 842b9c800..2fe157d36 100644 --- a/src/libtomahawk/playlist/PlayableProxyModel.cpp +++ b/src/libtomahawk/playlist/PlayableProxyModel.cpp @@ -108,6 +108,7 @@ PlayableProxyModel::setSourcePlayableModel( PlayableModel* sourceModel ) disconnect( m_model, SIGNAL( loadingFinished() ), this, SIGNAL( loadingFinished() ) ); disconnect( m_model, SIGNAL( itemCountChanged( unsigned int ) ), this, SIGNAL( itemCountChanged( unsigned int ) ) ); disconnect( m_model, SIGNAL( indexPlayable( QModelIndex ) ), this, SLOT( onIndexPlayable( QModelIndex ) ) ); + disconnect( m_model, SIGNAL( indexResolved( QModelIndex ) ), this, SLOT( onIndexResolved( QModelIndex ) ) ); disconnect( m_model, SIGNAL( currentIndexChanged() ), this, SIGNAL( currentIndexChanged() ) ); } @@ -119,6 +120,7 @@ PlayableProxyModel::setSourcePlayableModel( PlayableModel* sourceModel ) connect( m_model, SIGNAL( loadingFinished() ), SIGNAL( loadingFinished() ) ); connect( m_model, SIGNAL( itemCountChanged( unsigned int ) ), SIGNAL( itemCountChanged( unsigned int ) ) ); connect( m_model, SIGNAL( indexPlayable( QModelIndex ) ), SLOT( onIndexPlayable( QModelIndex ) ) ); + connect( m_model, SIGNAL( indexResolved( QModelIndex ) ), SLOT( onIndexResolved( QModelIndex ) ) ); connect( m_model, SIGNAL( currentIndexChanged() ), SIGNAL( currentIndexChanged() ) ); } @@ -643,3 +645,10 @@ PlayableProxyModel::onIndexPlayable( const QModelIndex& index ) { emit indexPlayable( mapFromSource( index ) ); } + + +void +PlayableProxyModel::onIndexResolved( const QModelIndex& index ) +{ + emit indexResolved( mapFromSource( index ) ); +} diff --git a/src/libtomahawk/playlist/PlayableProxyModel.h b/src/libtomahawk/playlist/PlayableProxyModel.h index 3db7f125a..cec45783e 100644 --- a/src/libtomahawk/playlist/PlayableProxyModel.h +++ b/src/libtomahawk/playlist/PlayableProxyModel.h @@ -94,6 +94,7 @@ signals: void loadingFinished(); void indexPlayable( const QModelIndex& index ); + void indexResolved( const QModelIndex& index ); void currentIndexChanged(); void itemCountChanged( unsigned int items ); @@ -106,6 +107,7 @@ protected: private slots: void onIndexPlayable( const QModelIndex& index ); + void onIndexResolved( const QModelIndex& index ); private: virtual bool lessThan( int column, const Tomahawk::query_ptr& left, const Tomahawk::query_ptr& right ) const; diff --git a/src/libtomahawk/playlist/TrackView.cpp b/src/libtomahawk/playlist/TrackView.cpp index 2a82c8d85..d4c68c50f 100644 --- a/src/libtomahawk/playlist/TrackView.cpp +++ b/src/libtomahawk/playlist/TrackView.cpp @@ -426,8 +426,6 @@ TrackView::resizeEvent( QResizeEvent* event ) { m_header->resizeSection( 0, event->size().width() ); } - - }