1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01: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;
static QHash< QString, QWeakPointer< Query > > s_queries;
static QMutex s_mutex;
query_ptr
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;
query_ptr q = query_ptr( new Query( artist, track, album, qid, autoResolve ) );
QMutexLocker lock( &s_mutex );
s_queries.insert( q->id(), q );
if ( autoResolve )
Pipeline::instance()->resolve( q );
@ -97,7 +102,16 @@ Query::Query( const QString& query, const QID& qid )
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
Query::refreshResults()
{
setResolveFinished( false );
Pipeline::instance()->resolve( id() );
tDebug() << "Re-resolving query:" << toString() << s_queries.contains( id() );
m_resolveFinished = false;
Pipeline::instance()->resolve( s_queries.value( id() ) );
}
@ -215,7 +231,7 @@ Query::onResolvingFinished()
void
Query::onResolverAdded()
{
if ( !solved() )
if ( m_resolveFinished && !solved() )
{
refreshResults();
}
@ -225,7 +241,7 @@ Query::onResolverAdded()
void
Query::onResolverRemoved()
{
if ( !solved() )
if ( m_resolveFinished && !solved() )
{
refreshResults();
}
@ -323,49 +339,46 @@ Query::clearResults()
void
Query::checkResults()
{
bool becameSolved = false;
bool becameUnsolved = true;
bool playable = false;
bool solved = false;
{
QMutexLocker lock( &m_mutex );
m_playable = false;
// hook up signals, and check solved status
foreach( const result_ptr& rp, m_results )
{
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 )
{
becameUnsolved = false;
if ( !m_solved )
{
m_solved = true;
becameSolved = true;
}
}
if ( rp->score() > 0.99 )
{
solved = true;
}
}
}
if ( m_solved && becameUnsolved )
if ( m_playable && !playable )
{
m_solved = false;
m_resolveFinished = false;
emit solvedStateChanged( false );
refreshResults();
}
if ( becameSolved )
emit solvedStateChanged( true );
if ( m_playable != playable )
{
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 solvedStateChanged( bool state );
void playableStateChanged( bool state );
void resolvingFinished( bool hasResults );
public slots:

View File

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