mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
Move JSPlugin and ScriptPlugin to their own headers
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#include "JSInfoPlugin_p.h"
|
#include "JSInfoPlugin_p.h"
|
||||||
|
|
||||||
#include "JSResolver.h"
|
#include "JSPlugin.h"
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
|
|
||||||
#include "../utils/Logger.h"
|
#include "../utils/Logger.h"
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include "JSInfoSystemHelper_p.h"
|
#include "JSInfoSystemHelper_p.h"
|
||||||
#include "JSInfoPlugin.h"
|
#include "JSInfoPlugin.h"
|
||||||
|
|
||||||
|
#include "JSPlugin.h"
|
||||||
#include "../utils/Logger.h"
|
#include "../utils/Logger.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
@@ -16,15 +16,22 @@
|
|||||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "JSResolver.h"
|
#include "JSPlugin.h"
|
||||||
|
|
||||||
#include "../utils/Json.h"
|
#include "../utils/Json.h"
|
||||||
|
#include "ScriptEngine.h"
|
||||||
|
|
||||||
#include <QWebFrame>
|
#include <QWebFrame>
|
||||||
|
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
JSPlugin::JSPlugin()
|
||||||
|
: m_engine( new ScriptEngine( this ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
JSPlugin::addToJavaScriptWindowObject( const QString& name, QObject* object )
|
JSPlugin::addToJavaScriptWindowObject( const QString& name, QObject* object )
|
||||||
{
|
{
|
||||||
|
80
src/libtomahawk/resolvers/JSPlugin.h
Normal file
80
src/libtomahawk/resolvers/JSPlugin.h
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Dominik Schmidt <domme@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TOMAHAWK_JSPLUGIN_H
|
||||||
|
#define TOMAHAWK_JSPLUGIN_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "ScriptPlugin.h"
|
||||||
|
|
||||||
|
#include <QVariantMap>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
//TODO: pimple
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
//TODO: pimple
|
||||||
|
class ScriptEngine;
|
||||||
|
|
||||||
|
class DLLEXPORT JSPlugin : public QObject, public ScriptPlugin
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
JSPlugin();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluate JavaScript on the WebKit thread
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE void evaluateJavaScript( const QString& scriptSource );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method must be called from the WebKit thread
|
||||||
|
*/
|
||||||
|
QVariant evaluateJavaScriptWithResult( const QString& scriptSource );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape \ and ' in strings so they are safe to use in JavaScript
|
||||||
|
*/
|
||||||
|
static QString escape( const QString& source );
|
||||||
|
|
||||||
|
|
||||||
|
void loadScript( const QString& path );
|
||||||
|
void loadScripts( const QStringList& paths );
|
||||||
|
void addToJavaScriptWindowObject( const QString& name, QObject* object );
|
||||||
|
|
||||||
|
static QString serializeQVariantMap(const QVariantMap& map);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* Wrap the pure evaluateJavaScript call in here, while the threadings guards are in public methods
|
||||||
|
*/
|
||||||
|
QVariant evaluateJavaScriptInternal( const QString& scriptSource );
|
||||||
|
|
||||||
|
std::unique_ptr<ScriptEngine> m_engine;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TOMAHAWK_SCRIPTJOB_H
|
||||||
|
|
@@ -43,6 +43,7 @@
|
|||||||
#include "TomahawkVersion.h"
|
#include "TomahawkVersion.h"
|
||||||
#include "Track.h"
|
#include "Track.h"
|
||||||
#include "JSInfoPlugin.h"
|
#include "JSInfoPlugin.h"
|
||||||
|
#include "JSPlugin.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
@@ -42,54 +42,6 @@ class ScriptJob;
|
|||||||
class ScriptObject;
|
class ScriptObject;
|
||||||
class ScriptPlugin;
|
class ScriptPlugin;
|
||||||
|
|
||||||
class DLLEXPORT ScriptPlugin
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~ScriptPlugin() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class DLLEXPORT JSPlugin : public QObject, public ScriptPlugin
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
JSPlugin()
|
|
||||||
: m_engine( new ScriptEngine( this ) )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Evaluate JavaScript on the WebKit thread
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void evaluateJavaScript( const QString& scriptSource );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method must be called from the WebKit thread
|
|
||||||
*/
|
|
||||||
QVariant evaluateJavaScriptWithResult( const QString& scriptSource );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Escape \ and ' in strings so they are safe to use in JavaScript
|
|
||||||
*/
|
|
||||||
static QString escape( const QString& source );
|
|
||||||
|
|
||||||
|
|
||||||
void loadScript( const QString& path );
|
|
||||||
void loadScripts( const QStringList& paths );
|
|
||||||
void addToJavaScriptWindowObject( const QString& name, QObject* object );
|
|
||||||
|
|
||||||
static QString serializeQVariantMap(const QVariantMap& map);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* Wrap the pure evaluateJavaScript call in here, while the threadings guards are in public methods
|
|
||||||
*/
|
|
||||||
QVariant evaluateJavaScriptInternal( const QString& scriptSource );
|
|
||||||
|
|
||||||
std::unique_ptr<ScriptEngine> m_engine;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class DLLEXPORT JSResolver : public Tomahawk::ExternalResolverGui
|
class DLLEXPORT JSResolver : public Tomahawk::ExternalResolverGui
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
#include "Result.h"
|
#include "Result.h"
|
||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
#include "UrlHandler.h"
|
#include "UrlHandler.h"
|
||||||
|
#include "JSPlugin.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
38
src/libtomahawk/resolvers/ScriptPlugin.h
Normal file
38
src/libtomahawk/resolvers/ScriptPlugin.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Leo Franchi <lfranchi@kde.org>
|
||||||
|
* Copyright (C) 2014 Dominik Schmidt <domme@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef TOMAHAWK_SCRIPTPLUGIN_H
|
||||||
|
#define TOMAHAWK_SCRIPTPLUGIN_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "../DllMacro.h"
|
||||||
|
|
||||||
|
namespace Tomahawk {
|
||||||
|
|
||||||
|
class DLLEXPORT ScriptPlugin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~ScriptPlugin() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // ns: Tomahawk
|
||||||
|
|
||||||
|
#endif // TOMAHAWK_SCRIPTPLUGIN_H
|
Reference in New Issue
Block a user