1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

* Fixed re-resolving after sources / resolvers go offline.

This commit is contained in:
Christian Muehlhaeuser
2011-09-27 19:54:37 +02:00
parent 26a7d37298
commit b4a8e32f44
3 changed files with 51 additions and 32 deletions

View File

@@ -36,6 +36,9 @@
using namespace Tomahawk; using namespace Tomahawk;
static QHash< QString, QWeakPointer< Query > > s_queries;
static QMutex s_mutex;
query_ptr query_ptr
Query::get( const QString& artist, const QString& track, const QString& album, const QID& qid, bool autoResolve ) Query::get( const QString& artist, const QString& track, const QString& album, const QID& qid, bool autoResolve )
@@ -44,6 +47,8 @@ Query::get( const QString& artist, const QString& track, const QString& album, c
autoResolve = false; autoResolve = false;
query_ptr q = query_ptr( new Query( artist, track, album, qid, autoResolve ) ); query_ptr q = query_ptr( new Query( artist, track, album, qid, autoResolve ) );
QMutexLocker lock( &s_mutex );
s_queries.insert( q->id(), q );
if ( autoResolve ) if ( autoResolve )
Pipeline::instance()->resolve( q ); Pipeline::instance()->resolve( q );
@@ -97,7 +102,16 @@ Query::Query( const QString& query, const QID& qid )
Query::~Query() Query::~Query()
{ {
qDebug() << Q_FUNC_INFO << toString(); tDebug() << Q_FUNC_INFO << toString();
if ( !id().isEmpty() )
{
QMutexLocker lock( &s_mutex );
if ( s_queries.contains( id() ) )
{
s_queries.remove( id() );
}
}
} }
@@ -166,8 +180,10 @@ Query::addResults( const QList< Tomahawk::result_ptr >& newresults )
void void
Query::refreshResults() Query::refreshResults()
{ {
setResolveFinished( false ); tDebug() << "Re-resolving query:" << toString() << s_queries.contains( id() );
Pipeline::instance()->resolve( id() );
m_resolveFinished = false;
Pipeline::instance()->resolve( s_queries.value( id() ) );
} }
@@ -215,7 +231,7 @@ Query::onResolvingFinished()
void void
Query::onResolverAdded() Query::onResolverAdded()
{ {
if ( !solved() ) if ( m_resolveFinished && !solved() )
{ {
refreshResults(); refreshResults();
} }
@@ -225,7 +241,7 @@ Query::onResolverAdded()
void void
Query::onResolverRemoved() Query::onResolverRemoved()
{ {
if ( !solved() ) if ( m_resolveFinished && !solved() )
{ {
refreshResults(); refreshResults();
} }
@@ -323,49 +339,46 @@ Query::clearResults()
void void
Query::checkResults() Query::checkResults()
{ {
bool becameSolved = false; bool playable = false;
bool becameUnsolved = true; bool solved = false;
{ {
QMutexLocker lock( &m_mutex ); QMutexLocker lock( &m_mutex );
m_playable = false;
// hook up signals, and check solved status // hook up signals, and check solved status
foreach( const result_ptr& rp, m_results ) foreach( const result_ptr& rp, m_results )
{ {
if ( rp->score() > 0.0 && rp->collection().isNull() ) if ( rp->score() > 0.0 && rp->collection().isNull() )
{ {
m_playable = true; playable = true;
} }
if ( !rp->collection().isNull() && rp->collection()->source()->isOnline() ) else if ( !rp->collection().isNull() && rp->collection()->source()->isOnline() )
{ {
m_playable = true; playable = true;
}
if ( rp->score() > 0.99 ) if ( rp->score() > 0.99 )
{ {
becameUnsolved = false; solved = true;
}
}
}
if ( !m_solved ) if ( m_playable && !playable )
{ {
m_solved = true;
becameSolved = true;
}
}
}
}
}
if ( m_solved && becameUnsolved )
{
m_solved = false;
m_resolveFinished = false;
emit solvedStateChanged( false );
refreshResults(); refreshResults();
} }
if ( becameSolved ) if ( m_playable != playable )
emit solvedStateChanged( true ); {
m_playable = playable;
emit playableStateChanged( m_playable );
}
if ( m_solved != solved )
{
m_solved = solved;
emit solvedStateChanged( m_solved );
}
} }

View File

@@ -108,6 +108,7 @@ signals:
void resultsChanged(); void resultsChanged();
void solvedStateChanged( bool state ); void solvedStateChanged( bool state );
void playableStateChanged( bool state );
void resolvingFinished( bool hasResults ); void resolvingFinished( bool hasResults );
public slots: public slots:

View File

@@ -31,13 +31,13 @@
using namespace Tomahawk; using namespace Tomahawk;
static QHash< QString, QWeakPointer< Result > > s_results;
static QMutex s_mutex;
Tomahawk::result_ptr Tomahawk::result_ptr
Result::get( const QString& url ) Result::get( const QString& url )
{ {
static QHash< QString, result_ptr > s_results;
static QMutex s_mutex;
QMutexLocker lock( &s_mutex ); QMutexLocker lock( &s_mutex );
if ( s_results.contains( url ) ) if ( s_results.contains( url ) )
{ {
@@ -68,6 +68,11 @@ Result::Result( const QString& url )
Result::~Result() Result::~Result()
{ {
QMutexLocker lock( &s_mutex );
if ( s_results.contains( m_url ) )
{
s_results.remove( m_url );
}
} }