mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
Move JSPlugin and ScriptPlugin to their own headers
This commit is contained in:
parent
28dad3aef3
commit
0a0cbd15ae
@ -18,7 +18,7 @@
|
||||
|
||||
#include "JSInfoPlugin_p.h"
|
||||
|
||||
#include "JSResolver.h"
|
||||
#include "JSPlugin.h"
|
||||
#include "Typedefs.h"
|
||||
|
||||
#include "../utils/Logger.h"
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "JSInfoSystemHelper_p.h"
|
||||
#include "JSInfoPlugin.h"
|
||||
|
||||
#include "JSPlugin.h"
|
||||
#include "../utils/Logger.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
@ -16,15 +16,22 @@
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "JSResolver.h"
|
||||
#include "JSPlugin.h"
|
||||
|
||||
#include "../utils/Json.h"
|
||||
#include "ScriptEngine.h"
|
||||
|
||||
#include <QWebFrame>
|
||||
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
JSPlugin::JSPlugin()
|
||||
: m_engine( new ScriptEngine( this ) )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
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 "Track.h"
|
||||
#include "JSInfoPlugin.h"
|
||||
#include "JSPlugin.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
|
@ -42,54 +42,6 @@ class ScriptJob;
|
||||
class ScriptObject;
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "Result.h"
|
||||
#include "SourceList.h"
|
||||
#include "UrlHandler.h"
|
||||
#include "JSPlugin.h"
|
||||
|
||||
#include <QFile>
|
||||
#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
|
Loading…
x
Reference in New Issue
Block a user