mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 19:30:21 +02:00
More API cleanup for QtScriptResolver
This commit is contained in:
@@ -4,6 +4,10 @@ if(window.Tomahawk === undefined)
|
||||
{
|
||||
alert("PHANTOMJS ENVIRONMENT");
|
||||
var Tomahawk = {
|
||||
fakeEnv: function()
|
||||
{
|
||||
return true;
|
||||
},
|
||||
resolverData: function()
|
||||
{
|
||||
return {
|
||||
@@ -12,14 +16,34 @@ if(window.Tomahawk === undefined)
|
||||
return "/home/tomahawk/resolver.js";
|
||||
}
|
||||
};
|
||||
},
|
||||
log: function( message )
|
||||
{
|
||||
console.log( message );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Tomahawk.resolver = {
|
||||
scriptPath: Tomahawk.resolverData().scriptPath
|
||||
};
|
||||
|
||||
Tomahawk.timestamp = function() {
|
||||
return Math.round( new Date()/1000 );
|
||||
}
|
||||
|
||||
Tomahawk.dumpResult = function( result ) {
|
||||
var results = result.results;
|
||||
Tomahawk.log("Dumping " + results.length + " results for query " + result.qid + "...");
|
||||
for(var i=0; i<results.length;i++)
|
||||
{
|
||||
var result = results[i];
|
||||
Tomahawk.log( result.artist + " - " + result.track + " | " + result.url );
|
||||
}
|
||||
|
||||
Tomahawk.log("Done.");
|
||||
}
|
||||
|
||||
// javascript part of Tomahawk-Object API
|
||||
Tomahawk.extend = function(object, members) {
|
||||
@@ -38,6 +62,9 @@ Tomahawk.extend = function(object, members) {
|
||||
|
||||
// Resolver BaseObject, inherit it to implement your own resolver
|
||||
var TomahawkResolver = {
|
||||
init: function()
|
||||
{
|
||||
},
|
||||
scriptPath: function()
|
||||
{
|
||||
return Tomahawk.resolverData().scriptPath;
|
||||
@@ -129,7 +156,11 @@ Tomahawk.valueForSubNode = function(node, tag)
|
||||
if(node === undefined)
|
||||
throw new Error("Tomahawk.valueForSubnode: node is undefined!");
|
||||
|
||||
return node.getElementsByTagName(tag)[0].textContent;
|
||||
var element = node.getElementsByTagName(tag)[0];
|
||||
if( element === undefined )
|
||||
return undefined;
|
||||
|
||||
return element.textContent;
|
||||
};
|
||||
|
||||
|
||||
@@ -267,4 +298,4 @@ Tomahawk.sha256=function(s){
|
||||
s = Utf8Encode(s);
|
||||
return binb2hex(core_sha256(str2binb(s), s.length * chrsz));
|
||||
|
||||
}
|
||||
}
|
@@ -86,6 +86,12 @@ QtScriptResolverHelper::resolverData()
|
||||
}
|
||||
|
||||
|
||||
void QtScriptResolverHelper::log(const QString& message)
|
||||
{
|
||||
qDebug() << m_scriptPath << ":" << message;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
QtScriptResolverHelper::setResolverConfig( QVariantMap config )
|
||||
{
|
||||
@@ -122,11 +128,14 @@ QtScriptResolver::QtScriptResolver( const QString& scriptPath )
|
||||
m_engine->mainFrame()->evaluateJavaScript( jslib.readAll() );
|
||||
jslib.close();
|
||||
|
||||
// execute resolver
|
||||
// add resolver
|
||||
m_engine->setScriptPath( scriptPath );
|
||||
m_engine->mainFrame()->evaluateJavaScript( scriptFile.readAll() );
|
||||
scriptFile.close();
|
||||
|
||||
// init resolver
|
||||
resolverInit();
|
||||
|
||||
|
||||
QVariantMap m = resolverSettings();
|
||||
m_name = m.value( "name" ).toString();
|
||||
@@ -167,7 +176,7 @@ QtScriptResolver::resolve( const Tomahawk::query_ptr& query )
|
||||
|
||||
if ( !query->isFullTextQuery() )
|
||||
{
|
||||
eval = QString( "Tomahawk.resolver.instance.resolve( '%1', '%2', '%3', '%4' );" )
|
||||
eval = QString( "Tomahawk.resolver.instance.resolve( '%1', '%4', '%3', '%4' );" )
|
||||
.arg( query->id().replace( "'", "\\'" ) )
|
||||
.arg( query->artist().replace( "'", "\\'" ) )
|
||||
.arg( query->album().replace( "'", "\\'" ) )
|
||||
@@ -175,11 +184,9 @@ QtScriptResolver::resolve( const Tomahawk::query_ptr& query )
|
||||
}
|
||||
else
|
||||
{
|
||||
eval = QString( "Tomahawk.resolver.instance.resolve( '%1', '%2', '%3', '%4' );" )
|
||||
eval = QString( "Tomahawk.resolver.instance.search( '%1', '%2' );" )
|
||||
.arg( query->id().replace( "'", "\\'" ) )
|
||||
.arg( query->fullTextQuery().replace( "'", "\\'" ) )
|
||||
.arg( QString() )
|
||||
.arg( QString() );
|
||||
.arg( query->fullTextQuery().replace( "'", "\\'" ) );
|
||||
}
|
||||
|
||||
QList< Tomahawk::result_ptr > results;
|
||||
@@ -415,7 +422,7 @@ QtScriptResolver::fillDataInWidgets( const QVariantMap& data )
|
||||
QVariantMap
|
||||
QtScriptResolver::resolverSettings()
|
||||
{
|
||||
return m_engine->mainFrame()->evaluateJavaScript( "Tomahawk.resolver.instance.getSettings();" ).toMap();
|
||||
return m_engine->mainFrame()->evaluateJavaScript( "Tomahawk.resolver.instance.settings;" ).toMap();
|
||||
}
|
||||
|
||||
|
||||
@@ -424,3 +431,11 @@ QtScriptResolver::resolverUserConfig()
|
||||
{
|
||||
return m_engine->mainFrame()->evaluateJavaScript( "Tomahawk.resolver.instance.getUserConfig();" ).toMap();
|
||||
}
|
||||
|
||||
|
||||
QVariantMap
|
||||
QtScriptResolver::resolverInit()
|
||||
{
|
||||
return m_engine->mainFrame()->evaluateJavaScript( "Tomahawk.resolver.instance.init();" ).toMap();
|
||||
}
|
||||
|
||||
|
@@ -49,6 +49,9 @@ public slots:
|
||||
QString compress( const QString& data );
|
||||
QVariantMap resolverData();
|
||||
|
||||
void log( const QString& message);
|
||||
bool fakeEnv() { return false; }
|
||||
|
||||
private:
|
||||
QString m_scriptPath;
|
||||
QVariantMap m_resolverConfig;
|
||||
@@ -124,6 +127,7 @@ private:
|
||||
// encapsulate javascript calls
|
||||
QVariantMap resolverSettings();
|
||||
QVariantMap resolverUserConfig();
|
||||
QVariantMap resolverInit();
|
||||
|
||||
ScriptEngine* m_engine;
|
||||
|
||||
|
Reference in New Issue
Block a user