mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-27 07:44:34 +02:00
Add async api for returning results in a qtscriptresolver
This commit is contained in:
@@ -35,10 +35,11 @@
|
||||
#define RESOLVER_LEGACY_CODE2 "var resolver = Tomahawk.resolver.instance ? Tomahawk.resolver.instance : window;"
|
||||
|
||||
|
||||
QtScriptResolverHelper::QtScriptResolverHelper( const QString& scriptPath, QObject* parent )
|
||||
QtScriptResolverHelper::QtScriptResolverHelper( const QString& scriptPath, QtScriptResolver* parent )
|
||||
: QObject( parent )
|
||||
{
|
||||
m_scriptPath = scriptPath;
|
||||
m_resolver = parent;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +103,18 @@ QtScriptResolverHelper::log( const QString& message )
|
||||
|
||||
|
||||
void
|
||||
QtScriptResolverHelper::setResolverConfig( QVariantMap config )
|
||||
QtScriptResolverHelper::addTrackResults( const QVariantMap& results )
|
||||
{
|
||||
QList< Tomahawk::result_ptr > tracks = m_resolver->parseResultVariantList( results.value("results").toList() );
|
||||
|
||||
QString qid = results.value("qid").toString();
|
||||
|
||||
Tomahawk::Pipeline::instance()->reportResults( qid, tracks );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
QtScriptResolverHelper::setResolverConfig( const QVariantMap& config )
|
||||
{
|
||||
m_resolverConfig = config;
|
||||
}
|
||||
@@ -245,6 +257,14 @@ QtScriptResolver::resolve( const Tomahawk::query_ptr& query )
|
||||
}
|
||||
|
||||
QVariantMap m = m_engine->mainFrame()->evaluateJavaScript( eval ).toMap();
|
||||
|
||||
if( m.isEmpty() )
|
||||
{
|
||||
// if the resolver doesn't return anything, async api is used
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
qDebug() << "JavaScript Result:" << m;
|
||||
|
||||
const QString qid = query->id();
|
||||
@@ -265,11 +285,6 @@ QtScriptResolver::parseResultVariantList( const QVariantList& reslist )
|
||||
{
|
||||
QVariantMap m = rv.toMap();
|
||||
|
||||
qDebug() << "artist: " << m.value("artist").toString();
|
||||
qDebug() << "track: " << m.value( "track" ).toString();
|
||||
|
||||
//Q_ASSERT(false);
|
||||
|
||||
Tomahawk::result_ptr rp( new Tomahawk::Result() );
|
||||
Tomahawk::artist_ptr ap = Tomahawk::Artist::get( m.value( "artist" ).toString(), true );
|
||||
rp->setArtist( ap );
|
||||
|
@@ -38,8 +38,8 @@ class QtScriptResolverHelper : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtScriptResolverHelper( const QString& scriptPath, QObject* parent );
|
||||
void setResolverConfig( QVariantMap config );
|
||||
QtScriptResolverHelper( const QString& scriptPath, QtScriptResolver* parent );
|
||||
void setResolverConfig( const QVariantMap& config );
|
||||
|
||||
public slots:
|
||||
QByteArray readRaw( const QString& fileName );
|
||||
@@ -52,9 +52,12 @@ public slots:
|
||||
void log( const QString& message );
|
||||
bool fakeEnv() { return false; }
|
||||
|
||||
void addTrackResults( const QVariantMap& results );
|
||||
|
||||
private:
|
||||
QString m_scriptPath;
|
||||
QVariantMap m_resolverConfig;
|
||||
QtScriptResolver* m_resolver;
|
||||
};
|
||||
|
||||
class ScriptEngine : public QWebPage
|
||||
@@ -97,6 +100,8 @@ class QtScriptResolver : public Tomahawk::ExternalResolver
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class QtScriptResolverHelper;
|
||||
|
||||
public:
|
||||
explicit QtScriptResolver( const QString& scriptPath );
|
||||
virtual ~QtScriptResolver();
|
||||
|
Reference in New Issue
Block a user