diff --git a/src/libtomahawk/database/databasecommand_logplayback.cpp b/src/libtomahawk/database/databasecommand_logplayback.cpp index 9254ea979..6443b2216 100644 --- a/src/libtomahawk/database/databasecommand_logplayback.cpp +++ b/src/libtomahawk/database/databasecommand_logplayback.cpp @@ -44,7 +44,8 @@ DatabaseCommand_LogPlayback::postCommitHook() connect( this, SIGNAL( trackPlayed( Tomahawk::query_ptr ) ), source().data(), SLOT( onPlaybackFinished( Tomahawk::query_ptr ) ), Qt::QueuedConnection ); - Tomahawk::query_ptr q = Tomahawk::Query::get( m_artist, m_track, QString(), uuid() ); + // do not auto resolve this track + Tomahawk::query_ptr q = Tomahawk::Query::get( m_artist, m_track, QString() ); if ( m_action == Finished ) { diff --git a/src/libtomahawk/playlist/playlistmodel.cpp b/src/libtomahawk/playlist/playlistmodel.cpp index 8e4d24ae6..2ab23bf51 100644 --- a/src/libtomahawk/playlist/playlistmodel.cpp +++ b/src/libtomahawk/playlist/playlistmodel.cpp @@ -396,12 +396,16 @@ PlaylistModel::playlistEntries() const } +void +PlaylistModel::remove( unsigned int row, bool moreToCome ) +{ + removeIndex( index( row, 0, QModelIndex() ), moreToCome ); +} + + void PlaylistModel::removeIndex( const QModelIndex& index, bool moreToCome ) { - if ( isReadOnly() ) - return; - TrackModel::removeIndex( index ); if ( !moreToCome && !m_playlist.isNull() ) diff --git a/src/libtomahawk/playlist/playlistmodel.h b/src/libtomahawk/playlist/playlistmodel.h index e69bf59e1..bc743a18a 100644 --- a/src/libtomahawk/playlist/playlistmodel.h +++ b/src/libtomahawk/playlist/playlistmodel.h @@ -62,6 +62,7 @@ public: void insert( unsigned int row, const Tomahawk::query_ptr& query ); + void remove( unsigned int row, bool moreToCome = false ); virtual void removeIndex( const QModelIndex& index, bool moreToCome = false ); signals: diff --git a/src/libtomahawk/playlist/trackmodel.cpp b/src/libtomahawk/playlist/trackmodel.cpp index eceadd401..e3fd2083a 100644 --- a/src/libtomahawk/playlist/trackmodel.cpp +++ b/src/libtomahawk/playlist/trackmodel.cpp @@ -26,6 +26,7 @@ #include "utils/tomahawkutils.h" #include "album.h" +#include "pipeline.h" using namespace Tomahawk; @@ -370,3 +371,16 @@ TrackModel::onPlaybackStopped() oldEntry->setIsPlaying( false ); } } + + +void +TrackModel::ensureResolved() +{ + for( int i = 0; i < rowCount( QModelIndex() ); i++ ) + { + query_ptr query = itemFromIndex( index( i, 0, QModelIndex() ) )->query(); + + if ( !query->numResults() ) + Pipeline::instance()->resolve( query ); + } +} diff --git a/src/libtomahawk/playlist/trackmodel.h b/src/libtomahawk/playlist/trackmodel.h index d9cec03d8..b3a5e0c24 100644 --- a/src/libtomahawk/playlist/trackmodel.h +++ b/src/libtomahawk/playlist/trackmodel.h @@ -76,6 +76,8 @@ public: virtual PlaylistInterface::RepeatMode repeatMode() const { return PlaylistInterface::NoRepeat; } virtual bool shuffled() const { return false; } + virtual void ensureResolved(); + virtual void append( const Tomahawk::query_ptr& query ) = 0; PlItem* itemFromIndex( const QModelIndex& index ) const; diff --git a/src/libtomahawk/widgets/welcomewidget.cpp b/src/libtomahawk/widgets/welcomewidget.cpp index cc4460895..d7ad62938 100644 --- a/src/libtomahawk/widgets/welcomewidget.cpp +++ b/src/libtomahawk/widgets/welcomewidget.cpp @@ -31,7 +31,9 @@ #include -#define FILTER_TIMEOUT 280 +#define HISTORY_TRACK_ITEMS 50 +#define HISTORY_PLAYLIST_ITEMS 10 +#define HISTORY_RESOLVING_TIMEOUT 2500 WelcomeWidget::WelcomeWidget( QWidget* parent ) @@ -46,7 +48,10 @@ WelcomeWidget::WelcomeWidget( QWidget* parent ) m_tracksModel = new PlaylistModel( ui->tracksView ); ui->tracksView->setModel( m_tracksModel ); - m_tracksModel->loadHistory( Tomahawk::source_ptr() ); + m_tracksModel->loadHistory( Tomahawk::source_ptr(), HISTORY_TRACK_ITEMS ); + + m_timer = new QTimer( this ); + connect( m_timer, SIGNAL( timeout() ), SLOT( checkQueries() ) ); connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) ); @@ -96,10 +101,25 @@ WelcomeWidget::onSourceAdded( const Tomahawk::source_ptr& source ) } +void +WelcomeWidget::checkQueries() +{ + m_timer->stop(); + m_tracksModel->ensureResolved(); +} + + void WelcomeWidget::onPlaybackFinished( const Tomahawk::query_ptr& query ) { m_tracksModel->insert( 0, query ); + + if ( m_tracksModel->trackCount() > HISTORY_TRACK_ITEMS ) + m_tracksModel->remove( HISTORY_TRACK_ITEMS ); + + if ( m_timer->isActive() ) + m_timer->stop(); + m_timer->start( HISTORY_RESOLVING_TIMEOUT ); } diff --git a/src/libtomahawk/widgets/welcomewidget.h b/src/libtomahawk/widgets/welcomewidget.h index 9ec4e249c..036e3d5ca 100644 --- a/src/libtomahawk/widgets/welcomewidget.h +++ b/src/libtomahawk/widgets/welcomewidget.h @@ -124,10 +124,13 @@ private slots: void onPlaylistActivated( QListWidgetItem* item ); void onPlaybackFinished( const Tomahawk::query_ptr& query ); + void checkQueries(); + private: Ui::WelcomeWidget *ui; PlaylistModel* m_tracksModel; + QTimer* m_timer; }; #endif // WELCOMEWIDGET_H