use filePathFromScriptContext

svn path=/trunk/KDE/kdebase/runtime/; revision=1171720
This commit is contained in:
Aaron J. Seigo 2010-09-04 22:51:13 +00:00
parent f13c8b249c
commit 33c240ffa4
4 changed files with 18 additions and 45 deletions

View File

@ -35,7 +35,6 @@
#include <Plasma/Package>
Q_DECLARE_METATYPE(AppletInterface*)
Q_DECLARE_METATYPE(Plasma::Package)
AppletInterface::AppletInterface(SimpleJavaScriptApplet *parent)
: QObject(parent),
@ -141,7 +140,7 @@ void AppletInterface::setActiveConfig(const QString &name)
Plasma::ConfigLoader *loader = m_configs.value(name, 0);
if (!loader) {
QString path = file("config", name + ".xml");
QString path = m_appletScriptEngine->filePath("config", name + ".xml");
if (path.isEmpty()) {
return;
}
@ -196,31 +195,12 @@ QScriptValue AppletInterface::readConfig(const QString &entry) const
QString AppletInterface::file(const QString &fileType)
{
return file(fileType.toLocal8Bit().constData(), QString());
return m_appletScriptEngine->filePath(fileType, QString());
}
QString AppletInterface::file(const QString &fileType, const QString &filePath)
{
return file(fileType, filePath, context());
}
QString AppletInterface::file(const QString &fileType, const QString &filePath, QScriptContext *c)
{
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(fileType.toLocal8Bit().constData(), filePath);
if (!path.isEmpty()) {
return path;
}
}
c = c->parentContext();
}
//kDebug() << "old school attempt";
return m_appletScriptEngine->package()->filePath(fileType.toLocal8Bit().constData(), filePath);
return m_appletScriptEngine->filePath(fileType, filePath);
}
QList<QAction*> AppletInterface::contextualActions() const
@ -348,23 +328,7 @@ int AppletInterface::apiVersion() const
bool AppletInterface::include(const QString &script)
{
QString path;
/*
QScriptContext *c = context();
if (c && c->parentContext()) {
QScriptValue v = c->parentContext()->activationObject().property("__plasma_package");
//kDebug() << "variant in parent context?" << v.isVariant() << t.restart();
if (v.isVariant()) {
Plasma::Package p = v.toVariant().value<Plasma::Package>();
//kDebug() << "path to package is" << p.path();
path = p.filePath("scripts", script);
}
}
*/
if (path.isEmpty()) {
kDebug() << "kicking it old school";
path = file("scripts", script);
}
const QString path = m_appletScriptEngine->filePath("scripts", script);
if (path.isEmpty()) {
return false;

View File

@ -25,7 +25,6 @@
#include <QObject>
#include <QSizePolicy>
#include <QScriptValue>
#include <QScriptable>
#include <Plasma/Applet>
#include <Plasma/PopupApplet>
@ -46,7 +45,7 @@ namespace Plasma
class Extender;
} // namespace Plasa
class AppletInterface : public QObject, QScriptable
class AppletInterface : public QObject
{
Q_OBJECT
Q_ENUMS(FormFactor)
@ -268,7 +267,6 @@ enum IntervalAlignment {
Q_INVOKABLE QString file(const QString &fileType);
Q_INVOKABLE QString file(const QString &fileType, const QString &filePath);
QString file(const QString &fileType, const QString &filePath, QScriptContext *context);
Q_INVOKABLE bool include(const QString &script);

View File

@ -705,9 +705,9 @@ QString SimpleJavaScriptApplet::findSvg(QScriptContext *context, QScriptEngine *
return file;
}
QString path = interface->file("images", file + ".svg", context);
QString path = interface->file("images", file + ".svg");
if (path.isEmpty()) {
path = interface->file("images", file + ".svgz", context);
path = interface->file("images", file + ".svgz");
if (path.isEmpty()) {
return file;
@ -856,6 +856,16 @@ void SimpleJavaScriptApplet::collectGarbage()
m_engine->collectGarbage();
}
QString SimpleJavaScriptApplet::filePath(const QString &type, const QString &file) const
{
const QString path = m_env->filePathFromScriptContext(type.toLocal8Bit().constData(), file);
if (!path.isEmpty()) {
return path;
}
return package()->filePath(type.toLocal8Bit().constData(), file);
}
/*
* Workaround the fact that QtScripts handling of variants seems a bit broken.
*/

View File

@ -54,6 +54,7 @@ public:
bool include(const QString &path);
QSet<QString> loadedExtensions() const;
QScriptValue variantToScriptValue(QVariant var);
QString filePath(const QString &type, const QString &file) const;
bool eventFilter(QObject *watched, QEvent *event);