From 5cdc8e40c6fb55c76ce7fbe6cb7f209a148e8634 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 26 Apr 2013 09:09:49 +0200 Subject: [PATCH] * Only update playlist when a result-hint has been changed. --- src/libtomahawk/Playlist.cpp | 49 +++++++++++++++++++++++++++++++++--- src/libtomahawk/Playlist.h | 10 +++++++- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/Playlist.cpp b/src/libtomahawk/Playlist.cpp index 735b8f448..121fd1d55 100644 --- a/src/libtomahawk/Playlist.cpp +++ b/src/libtomahawk/Playlist.cpp @@ -64,7 +64,7 @@ PlaylistEntry::setQueryVariant( const QVariant& v ) QString album = m.value( "album" ).toString(); QString track = m.value( "track" ).toString(); - m_query = Tomahawk::Query::get( artist, track, album ); + setQuery( Tomahawk::Query::get( artist, track, album ) ); } @@ -79,6 +79,8 @@ void PlaylistEntry::setQuery( const Tomahawk::query_ptr& q ) { m_query = q; + + connect( q.data(), SIGNAL( resolvingFinished( bool ) ), SLOT( onQueryResolved( bool ) ) ); } @@ -103,6 +105,48 @@ PlaylistEntry::setLastSource( source_ptr s ) } +void +PlaylistEntry::onQueryResolved( bool hasResults ) +{ + if ( !hasResults ) + return; + + if ( resultHint().isEmpty() ) + setResultHint( hintFromQuery() ); +} + + +void +PlaylistEntry::setResultHint( const QString& s ) +{ + if ( m_resulthint == s ) + return; + + m_resulthint = s; + emit resultChanged(); +} + + +QString +PlaylistEntry::hintFromQuery() const +{ + QString resultHint, foundResult; + if ( !m_query->results().isEmpty() ) + foundResult = m_query->results().first()->url(); + else if ( !m_query->resultHint().isEmpty() ) + foundResult = m_query->resultHint(); + + if ( foundResult.startsWith( "file://" ) || + foundResult.startsWith( "servent://" ) || // Save resulthints for local files and peers automatically + ( TomahawkUtils::whitelistedHttpResultHint( foundResult ) && m_query->saveHTTPResultHint() ) ) + { + resultHint = foundResult; + } + + return resultHint; +} + + Playlist::Playlist( const source_ptr& author ) : m_source( author ) , m_lastmodified( 0 ) @@ -533,8 +577,7 @@ Playlist::setRevision( const QString& rev, foreach( const plentry_ptr& entry, m_entries ) { - connect( entry->query().data(), SIGNAL( resultsChanged() ), - SLOT( onResultsChanged() ), Qt::UniqueConnection ); + connect( entry.data(), SIGNAL( resultChanged() ), SLOT( onResultsChanged() ), Qt::UniqueConnection ); } setBusy( false ); diff --git a/src/libtomahawk/Playlist.h b/src/libtomahawk/Playlist.h index a1e4574b8..043a6dbff 100644 --- a/src/libtomahawk/Playlist.h +++ b/src/libtomahawk/Playlist.h @@ -76,7 +76,7 @@ public: void setAnnotation( const QString& s ) { m_annotation = s; } QString resultHint() const { return m_resulthint; } - void setResultHint( const QString& s ) { m_resulthint= s; } + void setResultHint( const QString& s ); unsigned int duration() const { return m_duration; } void setDuration( unsigned int i ) { m_duration = i; } @@ -87,7 +87,15 @@ public: source_ptr lastSource() const; void setLastSource( source_ptr s ); +signals: + void resultChanged(); + +private slots: + void onQueryResolved( bool hasResults ); + private: + QString hintFromQuery() const; + QString m_guid; Tomahawk::query_ptr m_query; QString m_annotation;