allow including other files in contents/code/ into the Plasmoid. huzzah.

svn path=/trunk/KDE/kdebase/runtime/; revision=1048899
This commit is contained in:
Aaron J. Seigo 2009-11-14 05:19:19 +00:00
parent 847fb93cc4
commit 09f29dc6b4
4 changed files with 34 additions and 17 deletions

View File

@ -316,4 +316,14 @@ int AppletInterface::apiVersion() const
return offers.first()->property("X-KDE-PluginInfo-Version", QVariant::Int).toInt();
}
bool AppletInterface::include(const QString &script)
{
const QString path = package()->filePath("scripts", script);
if (path.isEmpty()) {
return false;
}
return m_appletScriptEngine->include(path);
}
#include "appletinterface.moc"

View File

@ -184,7 +184,6 @@ enum QtScrollBarPolicy {
Q_INVOKABLE void setFailedToLaunch(bool failed, const QString &reason = QString());
Q_INVOKABLE bool isBusy() const;
Q_INVOKABLE void setBusy(bool busy);
Q_INVOKABLE BackgroundHints backgroundHints() const;
@ -219,6 +218,8 @@ enum QtScrollBarPolicy {
Q_INVOKABLE QString file(const QString &fileType);
Q_INVOKABLE QString file(const QString &fileType, const QString &filePath);
Q_INVOKABLE bool include(const QString &script);
Plasma::DataEngine *dataEngine(const QString &name);
const Plasma::Package *package() const;

View File

@ -343,6 +343,26 @@ void SimpleJavaScriptApplet::constraintsEvent(Plasma::Constraints constraints)
}
}
bool SimpleJavaScriptApplet::include(const QString &path)
{
QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
kWarning() << i18n("Unable to load script file: %1", path);
return false;
}
QString script = file.readAll();
//kDebug() << "Script says" << script;
m_engine->evaluate(script);
if (m_engine->hasUncaughtException()) {
reportError(m_engine, true);
return false;
}
return true;
}
void SimpleJavaScriptApplet::populateAnimationsHash()
{
if (s_animationDefs.isEmpty()) {
@ -369,22 +389,7 @@ bool SimpleJavaScriptApplet::init()
kDebug() << "ScriptName:" << applet()->name();
kDebug() << "ScriptCategory:" << applet()->category();
QFile file(mainScript());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
kWarning() << "Unable to load script file";
return false;
}
QString script = file.readAll();
//kDebug() << "Script says" << script;
m_engine->evaluate(script);
if (m_engine->hasUncaughtException()) {
reportError(m_engine, true);
return false;
}
return true;
return include(mainScript());
}
bool SimpleJavaScriptApplet::importExtensions()

View File

@ -46,6 +46,7 @@ public:
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect);
QList<QAction*> contextualActions();
void constraintsEvent(Plasma::Constraints constraints);
bool include(const QString &path);
Q_INVOKABLE QString findDataResource( const QString &filename );
Q_INVOKABLE void debug( const QString &msg );