1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-18 03:41:27 +02:00

Add Tomahawk object to resolver scope, currently offers a readFile method

This commit is contained in:
Dominik Schmidt
2011-06-24 08:12:43 +02:00
parent 4abb52d198
commit 903617fd50
2 changed files with 39 additions and 0 deletions

View File

@@ -24,6 +24,30 @@
#include "sourcelist.h"
#include "utils/tomahawkutils.h"
QtScriptResolverHelper::QtScriptResolverHelper( const QString& scriptPath, QObject* parent ): QObject(parent)
{
m_scriptPath = scriptPath;
}
QString
QtScriptResolverHelper::readFile( const QString& fileName )
{
QString path = QFileInfo( m_scriptPath ).absolutePath();
// remove directories
QString cleanedFileName = QFileInfo( fileName ).fileName();
QString absoluteFilePath = path.append( "/" ).append( cleanedFileName );
QFile file( absoluteFilePath );
if( !file.exists() )
{
return QString();
}
file.open( QIODevice::ReadOnly );
return file.readAll();
}
QtScriptResolver::QtScriptResolver( const QString& scriptPath )
: Tomahawk::ExternalResolver( scriptPath )
@@ -43,6 +67,7 @@ QtScriptResolver::QtScriptResolver( const QString& scriptPath )
m_engine->mainFrame()->setHtml( "<html><body></body></html>" );
m_engine->mainFrame()->evaluateJavaScript( scriptFile.readAll() );
m_engine->mainFrame()->addToJavaScriptWindowObject( "Tomahawk", new QtScriptResolverHelper( scriptPath, this ) );
scriptFile.close();
QVariantMap m = m_engine->mainFrame()->evaluateJavaScript( "getSettings();" ).toMap();

View File

@@ -33,6 +33,20 @@
class QtScriptResolver;
class QtScriptResolverHelper : public QObject
{
Q_OBJECT
public:
QtScriptResolverHelper(const QString& scriptPath, QObject* parent );
public slots:
QString readFile(const QString& fileName);
private:
QString m_scriptPath;
};
class ScriptEngine : public QWebPage
{
Q_OBJECT