mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 15:47:38 +02:00
Move JSPlugin implementation to its own file
This commit is contained in:
@@ -19,9 +19,11 @@
|
|||||||
#include "JSPlugin.h"
|
#include "JSPlugin.h"
|
||||||
|
|
||||||
#include "../utils/Json.h"
|
#include "../utils/Json.h"
|
||||||
|
#include "../utils/Logger.h"
|
||||||
#include "ScriptEngine.h"
|
#include "ScriptEngine.h"
|
||||||
|
|
||||||
#include <QWebFrame>
|
#include <QWebFrame>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
@@ -59,3 +61,42 @@ JSPlugin::serializeQVariantMap( const QVariantMap& map )
|
|||||||
|
|
||||||
return QString( "JSON.parse('%1')" ).arg( JSPlugin::escape( QString::fromUtf8( serialized ) ) );
|
return QString( "JSON.parse('%1')" ).arg( JSPlugin::escape( QString::fromUtf8( serialized ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString
|
||||||
|
JSPlugin::JSPlugin::escape( const QString& source )
|
||||||
|
{
|
||||||
|
QString copy = source;
|
||||||
|
return copy.replace( "\\", "\\\\" ).replace( "'", "\\'" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
JSPlugin::loadScript( const QString& path )
|
||||||
|
{
|
||||||
|
QFile file( path );
|
||||||
|
|
||||||
|
if ( !file.open( QIODevice::ReadOnly ) )
|
||||||
|
{
|
||||||
|
qWarning() << "Failed to read contents of file:" << path << file.errorString();
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QByteArray contents = file.readAll();
|
||||||
|
|
||||||
|
m_engine->setScriptPath( path );
|
||||||
|
m_engine->mainFrame()->evaluateJavaScript( contents );
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
JSPlugin::loadScripts( const QStringList& paths )
|
||||||
|
{
|
||||||
|
foreach ( const QString& path, paths )
|
||||||
|
{
|
||||||
|
loadScript( path );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -960,37 +960,6 @@ JSResolver::resolverCollections()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
JSPlugin::loadScript( const QString& path )
|
|
||||||
{
|
|
||||||
QFile file( path );
|
|
||||||
|
|
||||||
if ( !file.open( QIODevice::ReadOnly ) )
|
|
||||||
{
|
|
||||||
qWarning() << "Failed to read contents of file:" << path << file.errorString();
|
|
||||||
Q_ASSERT(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QByteArray contents = file.readAll();
|
|
||||||
|
|
||||||
m_engine->setScriptPath( path );
|
|
||||||
m_engine->mainFrame()->evaluateJavaScript( contents );
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
JSPlugin::loadScripts( const QStringList& paths )
|
|
||||||
{
|
|
||||||
foreach ( const QString& path, paths )
|
|
||||||
{
|
|
||||||
loadScript( path );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
QVariant
|
||||||
JSResolver::callOnResolver( const QString& scriptSource )
|
JSResolver::callOnResolver( const QString& scriptSource )
|
||||||
{
|
{
|
||||||
@@ -1008,11 +977,3 @@ JSResolver::callOnResolver( const QString& scriptSource )
|
|||||||
"}"
|
"}"
|
||||||
).arg( propertyName ).arg( scriptSource ) );
|
).arg( propertyName ).arg( scriptSource ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
|
||||||
JSPlugin::JSPlugin::escape( const QString& source )
|
|
||||||
{
|
|
||||||
QString copy = source;
|
|
||||||
return copy.replace( "\\", "\\\\" ).replace( "'", "\\'" );
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user