1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 15:29:42 +01:00

* Only update playlist when a result-hint has been changed.

This commit is contained in:
Christian Muehlhaeuser 2013-04-26 09:09:49 +02:00
parent 9dbdffd0ef
commit 5cdc8e40c6
2 changed files with 55 additions and 4 deletions

View File

@ -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 );

View File

@ -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;