diff --git a/src/libtomahawk/resolvers/JSInfoPlugin.cpp b/src/libtomahawk/resolvers/JSInfoPlugin.cpp index 857033d33..e16010190 100644 --- a/src/libtomahawk/resolvers/JSInfoPlugin.cpp +++ b/src/libtomahawk/resolvers/JSInfoPlugin.cpp @@ -18,7 +18,7 @@ #include "JSInfoPlugin_p.h" -#include "JSResolver.h" +#include "JSPlugin.h" #include "Typedefs.h" #include "../utils/Logger.h" diff --git a/src/libtomahawk/resolvers/JSInfoSystemHelper.cpp b/src/libtomahawk/resolvers/JSInfoSystemHelper.cpp index 0d8b07a40..949c3b811 100644 --- a/src/libtomahawk/resolvers/JSInfoSystemHelper.cpp +++ b/src/libtomahawk/resolvers/JSInfoSystemHelper.cpp @@ -19,6 +19,7 @@ #include "JSInfoSystemHelper_p.h" #include "JSInfoPlugin.h" +#include "JSPlugin.h" #include "../utils/Logger.h" using namespace Tomahawk; diff --git a/src/libtomahawk/resolvers/JSPlugin.cpp b/src/libtomahawk/resolvers/JSPlugin.cpp index 2bcd5ce4b..4affbc10e 100644 --- a/src/libtomahawk/resolvers/JSPlugin.cpp +++ b/src/libtomahawk/resolvers/JSPlugin.cpp @@ -16,15 +16,22 @@ * along with Tomahawk. If not, see . */ -#include "JSResolver.h" +#include "JSPlugin.h" #include "../utils/Json.h" +#include "ScriptEngine.h" #include using namespace Tomahawk; +JSPlugin::JSPlugin() + : m_engine( new ScriptEngine( this ) ) +{ +} + + void JSPlugin::addToJavaScriptWindowObject( const QString& name, QObject* object ) { diff --git a/src/libtomahawk/resolvers/JSPlugin.h b/src/libtomahawk/resolvers/JSPlugin.h new file mode 100644 index 000000000..75d6acb52 --- /dev/null +++ b/src/libtomahawk/resolvers/JSPlugin.h @@ -0,0 +1,80 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, Dominik Schmidt + * + * 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 . + */ + +#ifndef TOMAHAWK_JSPLUGIN_H +#define TOMAHAWK_JSPLUGIN_H + + +#include "ScriptPlugin.h" + +#include +#include + +//TODO: pimple +#include + +#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 m_engine; + +}; + +} + +#endif // TOMAHAWK_SCRIPTJOB_H + diff --git a/src/libtomahawk/resolvers/JSResolver.cpp b/src/libtomahawk/resolvers/JSResolver.cpp index 24a674b36..d22fc291c 100644 --- a/src/libtomahawk/resolvers/JSResolver.cpp +++ b/src/libtomahawk/resolvers/JSResolver.cpp @@ -43,6 +43,7 @@ #include "TomahawkVersion.h" #include "Track.h" #include "JSInfoPlugin.h" +#include "JSPlugin.h" #include #include diff --git a/src/libtomahawk/resolvers/JSResolver.h b/src/libtomahawk/resolvers/JSResolver.h index e668ad859..63dcd8de5 100644 --- a/src/libtomahawk/resolvers/JSResolver.h +++ b/src/libtomahawk/resolvers/JSResolver.h @@ -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 m_engine; - -}; - class DLLEXPORT JSResolver : public Tomahawk::ExternalResolverGui { Q_OBJECT diff --git a/src/libtomahawk/resolvers/JSResolverHelper.cpp b/src/libtomahawk/resolvers/JSResolverHelper.cpp index f325bc85c..def34c60b 100644 --- a/src/libtomahawk/resolvers/JSResolverHelper.cpp +++ b/src/libtomahawk/resolvers/JSResolverHelper.cpp @@ -40,6 +40,7 @@ #include "Result.h" #include "SourceList.h" #include "UrlHandler.h" +#include "JSPlugin.h" #include #include diff --git a/src/libtomahawk/resolvers/ScriptPlugin.h b/src/libtomahawk/resolvers/ScriptPlugin.h new file mode 100644 index 000000000..ed0a89f15 --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptPlugin.h @@ -0,0 +1,38 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright (C) 2011 Leo Franchi + * Copyright (C) 2014 Dominik Schmidt + * + * 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 . + */ + +#pragma once +#ifndef TOMAHAWK_SCRIPTPLUGIN_H +#define TOMAHAWK_SCRIPTPLUGIN_H + +#include + +#include "../DllMacro.h" + +namespace Tomahawk { + +class DLLEXPORT ScriptPlugin +{ +public: + virtual ~ScriptPlugin() {} +}; + +} // ns: Tomahawk + +#endif // TOMAHAWK_SCRIPTPLUGIN_H