mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
Register the resolver as scriptObject
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "ScriptEngine.h"
|
||||
#include "ScriptJob.h"
|
||||
#include "ScriptObject.h"
|
||||
#include "JSResolver.h"
|
||||
|
||||
#include <QWebFrame>
|
||||
#include <QFile>
|
||||
@@ -44,6 +45,28 @@ JSAccount::addToJavaScriptWindowObject( const QString& name, QObject* object )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
JSAccount::setResolver( JSResolver* resolver )
|
||||
{
|
||||
m_resolver = resolver;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
JSAccount::scriptPluginFactory( const QString& type, ScriptObject* object )
|
||||
{
|
||||
if ( type == "resolver" )
|
||||
{
|
||||
Q_ASSERT( m_resolver );
|
||||
m_resolver->m_object = object;
|
||||
}
|
||||
else
|
||||
{
|
||||
Tomahawk::ScriptAccount::scriptPluginFactory(type, object);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
JSAccount::serializeQVariantMap( const QVariantMap& map )
|
||||
{
|
||||
|
@@ -34,6 +34,7 @@ namespace Tomahawk
|
||||
{
|
||||
//TODO: pimple
|
||||
class ScriptEngine;
|
||||
class JSResolver;
|
||||
|
||||
class DLLEXPORT JSAccount : public ScriptAccount
|
||||
{
|
||||
@@ -67,6 +68,9 @@ public:
|
||||
void loadScripts( const QStringList& paths );
|
||||
void addToJavaScriptWindowObject( const QString& name, QObject* object );
|
||||
|
||||
void setResolver( JSResolver* resolver );
|
||||
void scriptPluginFactory( const QString& type, ScriptObject* object ) override;
|
||||
|
||||
static QString serializeQVariantMap(const QVariantMap& map);
|
||||
|
||||
private:
|
||||
@@ -77,7 +81,8 @@ private:
|
||||
|
||||
std::unique_ptr<ScriptEngine> m_engine;
|
||||
QString m_name;
|
||||
|
||||
// HACK: the order of initializen is flawed, tbr
|
||||
JSResolver* m_resolver;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -59,6 +59,7 @@ using namespace Tomahawk;
|
||||
|
||||
JSResolver::JSResolver( const QString& accountId, const QString& scriptPath, const QStringList& additionalScriptPaths )
|
||||
: Tomahawk::ExternalResolverGui( scriptPath )
|
||||
, ScriptPlugin( nullptr )
|
||||
, d_ptr( new JSResolverPrivate( this, accountId, scriptPath, additionalScriptPaths ) )
|
||||
{
|
||||
Q_D( JSResolver );
|
||||
@@ -66,6 +67,7 @@ JSResolver::JSResolver( const QString& accountId, const QString& scriptPath, con
|
||||
|
||||
d->name = QFileInfo( filePath() ).baseName();
|
||||
d->scriptAccount.reset( new JSAccount( d->name ) );
|
||||
d->scriptAccount->setResolver( this );
|
||||
|
||||
// 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 ) );
|
||||
|
@@ -23,12 +23,13 @@
|
||||
#define JSRESOLVER_H
|
||||
|
||||
#include "config.h"
|
||||
#include "DllMacro.h"
|
||||
#include "ExternalResolverGui.h"
|
||||
#include "Typedefs.h"
|
||||
|
||||
#include "ScriptPlugin.h"
|
||||
#include "ScriptEngine.h" // hack, also should be renamed to JSEngine
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
@@ -40,11 +41,12 @@ class ScriptJob;
|
||||
class ScriptObject;
|
||||
class ScriptAccount;
|
||||
|
||||
class DLLEXPORT JSResolver : public Tomahawk::ExternalResolverGui
|
||||
class DLLEXPORT JSResolver : public Tomahawk::ExternalResolverGui, public ScriptPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class JSResolverHelper;
|
||||
friend class JSAccount;
|
||||
|
||||
public:
|
||||
explicit JSResolver( const QString& accountId, const QString& scriptPath, const QStringList& additionalScriptPaths = QStringList() );
|
||||
|
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
ScriptObject* scriptObject() const;
|
||||
|
||||
private: // TODO: pimple
|
||||
protected: // TODO: pimple
|
||||
ScriptObject* m_object;
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user