add the script locating code as statics to the ScriptEngine class

svn path=/trunk/KDE/kdebase/workspace/; revision=1105277
This commit is contained in:
Aaron J. Seigo 2010-03-19 18:07:53 +00:00 committed by Marco Martin
parent 760dedc101
commit 385e8d507a
2 changed files with 73 additions and 0 deletions

View File

@ -20,9 +20,11 @@
#include "scriptengine.h"
#include <QFile>
#include <QFileInfo>
#include <QScriptValueIterator>
#include <KShell>
#include <KStandardDirs>
#include <Plasma/Applet>
#include <Plasma/Containment>
@ -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<QString> 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"

View File

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