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);