use filePathFromScriptContext
svn path=/trunk/KDE/kdebase/runtime/; revision=1171720
This commit is contained in:
parent
f13c8b249c
commit
33c240ffa4
@ -35,7 +35,6 @@
|
|||||||
#include <Plasma/Package>
|
#include <Plasma/Package>
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(AppletInterface*)
|
Q_DECLARE_METATYPE(AppletInterface*)
|
||||||
Q_DECLARE_METATYPE(Plasma::Package)
|
|
||||||
|
|
||||||
AppletInterface::AppletInterface(SimpleJavaScriptApplet *parent)
|
AppletInterface::AppletInterface(SimpleJavaScriptApplet *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
@ -141,7 +140,7 @@ void AppletInterface::setActiveConfig(const QString &name)
|
|||||||
Plasma::ConfigLoader *loader = m_configs.value(name, 0);
|
Plasma::ConfigLoader *loader = m_configs.value(name, 0);
|
||||||
|
|
||||||
if (!loader) {
|
if (!loader) {
|
||||||
QString path = file("config", name + ".xml");
|
QString path = m_appletScriptEngine->filePath("config", name + ".xml");
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -196,31 +195,12 @@ QScriptValue AppletInterface::readConfig(const QString &entry) const
|
|||||||
|
|
||||||
QString AppletInterface::file(const QString &fileType)
|
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)
|
QString AppletInterface::file(const QString &fileType, const QString &filePath)
|
||||||
{
|
{
|
||||||
return file(fileType, filePath, context());
|
return m_appletScriptEngine->filePath(fileType, filePath);
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QAction*> AppletInterface::contextualActions() const
|
QList<QAction*> AppletInterface::contextualActions() const
|
||||||
@ -348,23 +328,7 @@ int AppletInterface::apiVersion() const
|
|||||||
|
|
||||||
bool AppletInterface::include(const QString &script)
|
bool AppletInterface::include(const QString &script)
|
||||||
{
|
{
|
||||||
QString path;
|
const QString path = m_appletScriptEngine->filePath("scripts", script);
|
||||||
/*
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSizePolicy>
|
#include <QSizePolicy>
|
||||||
#include <QScriptValue>
|
#include <QScriptValue>
|
||||||
#include <QScriptable>
|
|
||||||
|
|
||||||
#include <Plasma/Applet>
|
#include <Plasma/Applet>
|
||||||
#include <Plasma/PopupApplet>
|
#include <Plasma/PopupApplet>
|
||||||
@ -46,7 +45,7 @@ namespace Plasma
|
|||||||
class Extender;
|
class Extender;
|
||||||
} // namespace Plasa
|
} // namespace Plasa
|
||||||
|
|
||||||
class AppletInterface : public QObject, QScriptable
|
class AppletInterface : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_ENUMS(FormFactor)
|
Q_ENUMS(FormFactor)
|
||||||
@ -268,7 +267,6 @@ enum IntervalAlignment {
|
|||||||
|
|
||||||
Q_INVOKABLE QString file(const QString &fileType);
|
Q_INVOKABLE QString file(const QString &fileType);
|
||||||
Q_INVOKABLE QString file(const QString &fileType, const QString &filePath);
|
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);
|
Q_INVOKABLE bool include(const QString &script);
|
||||||
|
|
||||||
|
@ -705,9 +705,9 @@ QString SimpleJavaScriptApplet::findSvg(QScriptContext *context, QScriptEngine *
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString path = interface->file("images", file + ".svg", context);
|
QString path = interface->file("images", file + ".svg");
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
path = interface->file("images", file + ".svgz", context);
|
path = interface->file("images", file + ".svgz");
|
||||||
|
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
return file;
|
return file;
|
||||||
@ -856,6 +856,16 @@ void SimpleJavaScriptApplet::collectGarbage()
|
|||||||
m_engine->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.
|
* Workaround the fact that QtScripts handling of variants seems a bit broken.
|
||||||
*/
|
*/
|
||||||
|
@ -54,6 +54,7 @@ public:
|
|||||||
bool include(const QString &path);
|
bool include(const QString &path);
|
||||||
QSet<QString> loadedExtensions() const;
|
QSet<QString> loadedExtensions() const;
|
||||||
QScriptValue variantToScriptValue(QVariant var);
|
QScriptValue variantToScriptValue(QVariant var);
|
||||||
|
QString filePath(const QString &type, const QString &file) const;
|
||||||
|
|
||||||
bool eventFilter(QObject *watched, QEvent *event);
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user