From 385e8d507afe73e7dab9d3f78adee81edb51e438 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Fri, 19 Mar 2010 18:07:53 +0000 Subject: [PATCH] add the script locating code as statics to the ScriptEngine class svn path=/trunk/KDE/kdebase/workspace/; revision=1105277 --- scriptengine.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ scriptengine.h | 3 +++ 2 files changed, 73 insertions(+) diff --git a/scriptengine.cpp b/scriptengine.cpp index f187c6495..31a54c478 100644 --- a/scriptengine.cpp +++ b/scriptengine.cpp @@ -20,9 +20,11 @@ #include "scriptengine.h" #include +#include #include #include +#include #include #include @@ -249,5 +251,73 @@ void ScriptEngine::exception(const QScriptValue &value) emit printError(value.toVariant().toString()); } +QStringList ScriptEngine::pendingUpdateScripts() +{ + const QString appName = KGlobal::activeComponent().aboutData()->appName(); + QStringList scripts = KGlobal::dirs()->findAllResources("data", appName + "/updates/*.js"); + QStringList scriptPaths; + + if (scripts.isEmpty()) { + //kDebug() << "no update scripts"; + return scriptPaths; + } + + KConfigGroup cg(KGlobal::config(), "Updates"); + QStringList performed = cg.readEntry("performed", QStringList()); + const QString localDir = KGlobal::dirs()->localkdedir(); + const QString localXdgDir = KGlobal::dirs()->localxdgdatadir(); + + foreach (const QString &script, scripts) { + if (performed.contains(script)) { + continue; + } + + if (script.startsWith(localDir) || script.startsWith(localXdgDir)) { + kDebug() << "skipping user local script: " << script; + continue; + } + + scriptPaths.append(script); + performed.append(script); + } + + cg.writeEntry("performed", performed); + KGlobal::config()->sync(); + return scriptPaths; +} + +QStringList ScriptEngine::defaultLayoutScripts() +{ + const QString appName = KGlobal::activeComponent().aboutData()->appName(); + QStringList scripts = KGlobal::dirs()->findAllResources("data", appName + "/init/*.js"); + QStringList scriptPaths; + + if (scripts.isEmpty()) { + //kDebug() << "no javascript based layouts"; + return scriptPaths; + } + + const QString localDir = KGlobal::dirs()->localkdedir(); + const QString localXdgDir = KGlobal::dirs()->localxdgdatadir(); + + QSet scriptNames; + foreach (const QString &script, scripts) { + if (script.startsWith(localDir) || script.startsWith(localXdgDir)) { + kDebug() << "skipping user local script: " << script; + kDebug() << "skipping user local script: " << script; + continue; + } + + QFileInfo f(script); + QString filename = f.fileName(); + if (!scriptNames.contains(filename)) { + scriptNames.insert(filename); + scriptPaths.append(script); + } + } + + return scriptPaths; +} + #include "scriptengine.moc" diff --git a/scriptengine.h b/scriptengine.h index 5a714e6db..96a5092cb 100644 --- a/scriptengine.h +++ b/scriptengine.h @@ -42,6 +42,9 @@ public: ScriptEngine(Plasma::Corona *corona, QObject *parent = 0); ~ScriptEngine(); + static QStringList pendingUpdateScripts(); + static QStringList defaultLayoutScripts(); + void evaluateScript(const QString &script); static bool isPanel(const Plasma::Containment *c); QScriptValue wrap(Plasma::Applet *w, QScriptEngine *engine);