mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 23:39:42 +01:00
Move JSPlugin implementation to its own file
This commit is contained in:
parent
0a0cbd15ae
commit
81fdc368a2
@ -19,9 +19,11 @@
|
||||
#include "JSPlugin.h"
|
||||
|
||||
#include "../utils/Json.h"
|
||||
#include "../utils/Logger.h"
|
||||
#include "ScriptEngine.h"
|
||||
|
||||
#include <QWebFrame>
|
||||
#include <QFile>
|
||||
|
||||
|
||||
using namespace Tomahawk;
|
||||
@ -59,3 +61,42 @@ JSPlugin::serializeQVariantMap( const QVariantMap& map )
|
||||
|
||||
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
|
||||
JSResolver::callOnResolver( const QString& scriptSource )
|
||||
{
|
||||
@ -1008,11 +977,3 @@ JSResolver::callOnResolver( const QString& scriptSource )
|
||||
"}"
|
||||
).arg( propertyName ).arg( scriptSource ) );
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
JSPlugin::JSPlugin::escape( const QString& source )
|
||||
{
|
||||
QString copy = source;
|
||||
return copy.replace( "\\", "\\\\" ).replace( "'", "\\'" );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user