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