1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 14:46:33 +02:00

Address simple issues raised in PR

This commit is contained in:
Dominik Schmidt
2014-12-05 03:22:59 +01:00
parent 8ecb67178b
commit 3d4cfa0161
8 changed files with 20 additions and 21 deletions

View File

@@ -594,7 +594,7 @@ Tomahawk.base64Encode = function(b) { return window.btoa(b); };
Tomahawk.PluginManager = { Tomahawk.PluginManager = {
objects: {}, objects: {},
identifyObject: function (object) { identifyObject: function (object) {
if( object.id === undefined ) { if( !object.hasOwnProperty('id') ) {
object.id = Tomahawk.uuid(); object.id = Tomahawk.uuid();
} }
@@ -612,7 +612,7 @@ Tomahawk.PluginManager = {
requestId: requestId, requestId: requestId,
data: result data: result
}); });
},function (error) { }, function (error) {
Tomahawk.reportScriptJobResults({error: error}); Tomahawk.reportScriptJobResults({error: error});
}); });
} }

View File

@@ -120,7 +120,8 @@ JSPlugin::startJob( ScriptJob* scriptJob )
.arg( scriptJob->methodName() ) .arg( scriptJob->methodName() )
.arg( serializeQVariantMap( scriptJob->arguments() ) ); .arg( serializeQVariantMap( scriptJob->arguments() ) );
tLog() << Q_FUNC_INFO << eval; // Remove when new scripting api turned out to work reliably
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << eval;
evaluateJavaScript( eval ); evaluateJavaScript( eval );
} }

View File

@@ -48,18 +48,18 @@ public:
const QString name() const; const QString name() const;
/** /**
* Evaluate JavaScript on the WebKit thread * Evaluate JavaScript on the WebKit thread
*/ */
Q_INVOKABLE void evaluateJavaScript( const QString& scriptSource ); Q_INVOKABLE void evaluateJavaScript( const QString& scriptSource );
/** /**
* This method must be called from the WebKit thread * This method must be called from the WebKit thread
*/ */
QVariant evaluateJavaScriptWithResult( const QString& scriptSource ); QVariant evaluateJavaScriptWithResult( const QString& scriptSource );
/** /**
* Escape \ and ' in strings so they are safe to use in JavaScript * Escape \ and ' in strings so they are safe to use in JavaScript
*/ */
static QString escape( const QString& source ); static QString escape( const QString& source );

View File

@@ -65,7 +65,7 @@ JSResolver::JSResolver( const QString& accountId, const QString& scriptPath, con
tLog() << Q_FUNC_INFO << "Loading JS resolver:" << scriptPath; tLog() << Q_FUNC_INFO << "Loading JS resolver:" << scriptPath;
d->name = QFileInfo( filePath() ).baseName(); d->name = QFileInfo( filePath() ).baseName();
d->scriptPlugin = new JSPlugin( d->name ); d->scriptPlugin.reset( new JSPlugin( d->name ) );
// set the icon, if we launch properly we'll get the icon the resolver reports // set the icon, if we launch properly we'll get the icon the resolver reports
d->icon = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultResolver, TomahawkUtils::Original, QSize( 128, 128 ) ); d->icon = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultResolver, TomahawkUtils::Original, QSize( 128, 128 ) );
@@ -87,8 +87,6 @@ JSResolver::~JSResolver()
Q_D( JSResolver ); Q_D( JSResolver );
if ( !d->stopped ) if ( !d->stopped )
stop(); stop();
delete d->scriptPlugin;
} }
@@ -233,8 +231,10 @@ JSResolver::init()
// tomahawk-infosystem.js // tomahawk-infosystem.js
{ {
// TODO: be smarter about this, only instantiate this if the resolver supports infoplugins
// add c++ part of tomahawk infosystem bindings as Tomahawk.InfoSystem // add c++ part of tomahawk infosystem bindings as Tomahawk.InfoSystem
d->infoSystemHelper = new JSInfoSystemHelper( d->scriptPlugin ); d->infoSystemHelper = new JSInfoSystemHelper( d->scriptPlugin.get() );
d->scriptPlugin->addToJavaScriptWindowObject( "_TomahawkInfoSystem", d->infoSystemHelper ); d->scriptPlugin->addToJavaScriptWindowObject( "_TomahawkInfoSystem", d->infoSystemHelper );
d->scriptPlugin->evaluateJavaScript( "Tomahawk.InfoSystem = _TomahawkInfoSystem;" ); d->scriptPlugin->evaluateJavaScript( "Tomahawk.InfoSystem = _TomahawkInfoSystem;" );
@@ -967,8 +967,6 @@ JSResolver::callOnResolver( const QString& scriptSource )
QString propertyName = scriptSource.split('(').first(); QString propertyName = scriptSource.split('(').first();
tLog() << "JAVASCRIPT: run: " << scriptSource;
return d->scriptPlugin->evaluateJavaScriptWithResult( QString( return d->scriptPlugin->evaluateJavaScriptWithResult( QString(
"if(Tomahawk.resolver.instance['_adapter_%1']) {" "if(Tomahawk.resolver.instance['_adapter_%1']) {"
" Tomahawk.resolver.instance._adapter_%2;" " Tomahawk.resolver.instance._adapter_%2;"

View File

@@ -27,8 +27,6 @@
#include "ExternalResolverGui.h" #include "ExternalResolverGui.h"
#include "Typedefs.h" #include "Typedefs.h"
#include <memory> // unique_ptr
#include "ScriptEngine.h" // hack, also should be renamed to JSEngine #include "ScriptEngine.h" // hack, also should be renamed to JSEngine
namespace Tomahawk namespace Tomahawk

View File

@@ -28,6 +28,8 @@
#include "JSInfoSystemHelper.h" #include "JSInfoSystemHelper.h"
#include "database/fuzzyindex/FuzzyIndex.h" #include "database/fuzzyindex/FuzzyIndex.h"
#include <memory> // unique_ptr
namespace Tomahawk namespace Tomahawk
{ {
@@ -42,7 +44,6 @@ public:
, stopped( true ) , stopped( true )
, error( Tomahawk::ExternalResolver::NoError ) , error( Tomahawk::ExternalResolver::NoError )
, resolverHelper( new JSResolverHelper( scriptPath, q ) ) , resolverHelper( new JSResolverHelper( scriptPath, q ) )
// TODO: be smarter about this, only instantiate this if the resolver supports infoplugins
, infoSystemHelper( nullptr ) , infoSystemHelper( nullptr )
, requiredScriptPaths( additionalScriptPaths ) , requiredScriptPaths( additionalScriptPaths )
{ {
@@ -68,7 +69,7 @@ private:
QList< QVariant > dataWidgets; QList< QVariant > dataWidgets;
QStringList requiredScriptPaths; QStringList requiredScriptPaths;
JSPlugin* scriptPlugin; std::unique_ptr<JSPlugin> scriptPlugin;
}; };
} // ns: Tomahawk } // ns: Tomahawk

View File

@@ -26,7 +26,6 @@ namespace Tomahawk
class ScriptLinkGeneratorPluginPrivate class ScriptLinkGeneratorPluginPrivate
{ {
friend class ScriptLinkGeneratorPlugin;
public: public:
ScriptLinkGeneratorPluginPrivate( ScriptLinkGeneratorPlugin* q, ScriptObject* scriptObject ) ScriptLinkGeneratorPluginPrivate( ScriptLinkGeneratorPlugin* q, ScriptObject* scriptObject )
: q_ptr ( q ) : q_ptr ( q )

View File

@@ -31,7 +31,9 @@ using namespace Tomahawk;
static QString static QString
requestIdGenerator() requestIdGenerator()
{ {
return uuid(); static int requestCounter = 0;
return QString::number( ++requestCounter );
} }