mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-18 23:09:42 +01:00
Working query-stores-its-own-pointer behavior
This commit is contained in:
parent
4d7945291e
commit
14fd0424a1
@ -36,10 +36,6 @@
|
||||
|
||||
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 )
|
||||
{
|
||||
@ -47,11 +43,11 @@ 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 );
|
||||
q->setWeakRef( q.toWeakRef() );
|
||||
|
||||
if ( autoResolve )
|
||||
Pipeline::instance()->resolve( q );
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
@ -59,10 +55,13 @@ Query::get( const QString& artist, const QString& track, const QString& album, c
|
||||
query_ptr
|
||||
Query::get( const QString& query, const QID& qid )
|
||||
{
|
||||
|
||||
query_ptr q = query_ptr( new Query( query, qid ) );
|
||||
q->setWeakRef( q.toWeakRef() );
|
||||
|
||||
if ( !qid.isEmpty() )
|
||||
Pipeline::instance()->resolve( q );
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
@ -102,14 +101,7 @@ Query::Query( const QString& query, const QID& qid )
|
||||
|
||||
Query::~Query()
|
||||
{
|
||||
QMutexLocker lock( &s_mutex );
|
||||
if ( !id().isEmpty() )
|
||||
{
|
||||
if ( s_queries.contains( id() ) )
|
||||
{
|
||||
s_queries.remove( id() );
|
||||
}
|
||||
}
|
||||
m_ownRef.clear();
|
||||
}
|
||||
|
||||
|
||||
@ -206,9 +198,9 @@ Query::refreshResults()
|
||||
if ( m_resolveFinished )
|
||||
{
|
||||
m_resolveFinished = false;
|
||||
QMutexLocker lock( &s_mutex );
|
||||
if ( s_queries.contains( id() ) && !s_queries[ id() ].isNull() )
|
||||
Pipeline::instance()->resolve( s_queries.value( id() ) );
|
||||
query_ptr q = m_ownRef.toStrongRef();
|
||||
if ( q )
|
||||
Pipeline::instance()->resolve( q );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,9 +51,6 @@ public:
|
||||
static query_ptr get( const QString& artist, const QString& track, const QString& album, const QID& qid = QString(), bool autoResolve = true );
|
||||
static query_ptr get( const QString& query, const QID& qid );
|
||||
|
||||
explicit Query( const QString& artist, const QString& track, const QString& album, const QID& qid, bool autoResolve );
|
||||
explicit Query( const QString& query, const QID& qid );
|
||||
|
||||
virtual ~Query();
|
||||
|
||||
/// returns list of all results so far
|
||||
@ -105,6 +102,9 @@ public:
|
||||
void setResolveFinished( bool resolved ) { m_resolveFinished = resolved; }
|
||||
void setPlayedBy( const Tomahawk::source_ptr& source, unsigned int playtime );
|
||||
|
||||
QWeakPointer< Tomahawk::Query > weakRef() { return m_ownRef; }
|
||||
void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef ) { m_ownRef = weakRef; }
|
||||
|
||||
signals:
|
||||
void resultsAdded( const QList<Tomahawk::result_ptr>& );
|
||||
void resultsRemoved( const Tomahawk::result_ptr& );
|
||||
@ -137,6 +137,8 @@ private slots:
|
||||
|
||||
private:
|
||||
Query();
|
||||
explicit Query( const QString& artist, const QString& track, const QString& album, const QID& qid, bool autoResolve );
|
||||
explicit Query( const QString& query, const QID& qid );
|
||||
|
||||
void init();
|
||||
|
||||
@ -172,6 +174,8 @@ private:
|
||||
QList< QWeakPointer< Tomahawk::Resolver > > m_resolvers;
|
||||
|
||||
mutable QMutex m_mutex;
|
||||
|
||||
QWeakPointer< Tomahawk::Query > m_ownRef;
|
||||
};
|
||||
|
||||
}; //ns
|
||||
|
Loading…
x
Reference in New Issue
Block a user