add support for finding a file path from the current context and cleanups around the addons code now that this works reliably
svn path=/trunk/KDE/kdebase/runtime/; revision=1171716
This commit is contained in:
parent
3ada6f78e9
commit
f13c8b249c
@ -45,7 +45,7 @@
|
|||||||
#include "javascriptaddonpackagestructure.h"
|
#include "javascriptaddonpackagestructure.h"
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(ScriptEnv*)
|
Q_DECLARE_METATYPE(ScriptEnv*)
|
||||||
Q_DECLARE_METATYPE(Plasma::Package)
|
|
||||||
ScriptEnv::ScriptEnv(QObject *parent, QScriptEngine *engine)
|
ScriptEnv::ScriptEnv(QObject *parent, QScriptEngine *engine)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
m_allowedUrls(NoUrls),
|
m_allowedUrls(NoUrls),
|
||||||
@ -453,7 +453,7 @@ QScriptValue ScriptEnv::loadAddon(QScriptContext *context, QScriptEngine *engine
|
|||||||
QScriptValue::ReadOnly |
|
QScriptValue::ReadOnly |
|
||||||
QScriptValue::Undeletable |
|
QScriptValue::Undeletable |
|
||||||
QScriptValue::SkipInEnumeration);
|
QScriptValue::SkipInEnumeration);
|
||||||
kDebug() << "context is" << innerContext;
|
//kDebug() << "context is" << innerContext;
|
||||||
engine->evaluate(code, file.fileName());
|
engine->evaluate(code, file.fileName());
|
||||||
engine->popContext();
|
engine->popContext();
|
||||||
|
|
||||||
@ -465,35 +465,17 @@ QScriptValue ScriptEnv::loadAddon(QScriptContext *context, QScriptEngine *engine
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
QScriptValue ScriptEnv::addonFilePath(QScriptContext *context, QScriptEngine *engine)
|
|
||||||
{
|
|
||||||
const QString &path = context->thisObject().property("__plasma_addon_filepath").toString();
|
|
||||||
return path + context->argument(0).toString();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
QScriptValue ScriptEnv::registerAddon(QScriptContext *context, QScriptEngine *engine)
|
QScriptValue ScriptEnv::registerAddon(QScriptContext *context, QScriptEngine *engine)
|
||||||
{
|
{
|
||||||
if (context->argumentCount() > 0) {
|
if (context->argumentCount() > 0) {
|
||||||
QScriptValue func = context->argument(0);
|
QScriptValue func = context->argument(0);
|
||||||
if (func.isFunction()) {
|
if (func.isFunction()) {
|
||||||
/*
|
|
||||||
QScriptValue v = func.prototype();
|
|
||||||
v.setProperty("addonFilePath", engine->newFunction(ScriptEnv::addonFilePath));
|
|
||||||
func.setPrototype(v);
|
|
||||||
func.setProperty("test", "bar");
|
|
||||||
*/
|
|
||||||
QScriptValue obj = func.construct();
|
QScriptValue obj = func.construct();
|
||||||
obj.setProperty("__plasma_package",
|
obj.setProperty("__plasma_package",
|
||||||
context->parentContext()->activationObject().property("__plasma_package"),
|
context->parentContext()->activationObject().property("__plasma_package"),
|
||||||
QScriptValue::ReadOnly|
|
QScriptValue::ReadOnly|
|
||||||
QScriptValue::Undeletable |
|
QScriptValue::Undeletable |
|
||||||
QScriptValue::SkipInEnumeration);
|
QScriptValue::SkipInEnumeration);
|
||||||
/*
|
|
||||||
obj.setProperty("test", "bar");
|
|
||||||
obj.setProperty("addonFilePath", engine->newFunction(ScriptEnv::addonFilePath));
|
|
||||||
*/
|
|
||||||
|
|
||||||
ScriptEnv *env = ScriptEnv::findScriptEnv(engine);
|
ScriptEnv *env = ScriptEnv::findScriptEnv(engine);
|
||||||
if (env) {
|
if (env) {
|
||||||
@ -507,6 +489,27 @@ QScriptValue ScriptEnv::registerAddon(QScriptContext *context, QScriptEngine *en
|
|||||||
return engine->undefinedValue();
|
return engine->undefinedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ScriptEnv::filePathFromScriptContext(const char *type, const QString &file) const
|
||||||
|
{
|
||||||
|
//kDebug() << type << file;
|
||||||
|
QScriptContext *c = m_engine->currentContext();
|
||||||
|
while (c) {
|
||||||
|
QScriptValue v = c->activationObject().property("__plasma_package");
|
||||||
|
//kDebug() << "variant in parent context?" << v.isVariant();
|
||||||
|
if (v.isVariant()) {
|
||||||
|
const QString path = v.toVariant().value<Plasma::Package>().filePath(type, file);
|
||||||
|
if (!path.isEmpty()) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c = c->parentContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
//kDebug() << "fail";
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
QScriptValue ScriptEnv::addEventListener(QScriptContext *context, QScriptEngine *engine)
|
QScriptValue ScriptEnv::addEventListener(QScriptContext *context, QScriptEngine *engine)
|
||||||
{
|
{
|
||||||
if (context->argumentCount() < 2) {
|
if (context->argumentCount() < 2) {
|
||||||
|
@ -67,6 +67,8 @@ public:
|
|||||||
bool callEventListeners(const QString &event, const QScriptValueList &args = QScriptValueList());
|
bool callEventListeners(const QString &event, const QScriptValueList &args = QScriptValueList());
|
||||||
bool hasEventListeners(const QString &event) const;
|
bool hasEventListeners(const QString &event) const;
|
||||||
|
|
||||||
|
QString filePathFromScriptContext(const char *type, const QString &file) const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void reportError(ScriptEnv *engine, bool fatal);
|
void reportError(ScriptEnv *engine, bool fatal);
|
||||||
|
|
||||||
@ -87,7 +89,6 @@ private:
|
|||||||
static QScriptValue removeEventListener(QScriptContext *context, QScriptEngine *engine);
|
static QScriptValue removeEventListener(QScriptContext *context, QScriptEngine *engine);
|
||||||
static QScriptValue hasExtension(QScriptContext *context, QScriptEngine *engine);
|
static QScriptValue hasExtension(QScriptContext *context, QScriptEngine *engine);
|
||||||
static QScriptValue throwNonFatalError(const QString &msg, QScriptContext *context, QScriptEngine *engine);
|
static QScriptValue throwNonFatalError(const QString &msg, QScriptContext *context, QScriptEngine *engine);
|
||||||
//static QScriptValue addonFilePath(QScriptContext *context, QScriptEngine *engine);
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void signalException();
|
void signalException();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user