* move script file loading from Animator to AnimationScriptEngine

* don't use camel case includes for kdelibs classes in files which are themselves in kdelibs
* add my copyright to these files since they are approaching 100% code written by me

svn path=/trunk/KDE/kdelibs/; revision=1120250
This commit is contained in:
Aaron J. Seigo 2010-04-28 17:51:46 +00:00
parent 0cf62abb09
commit 736c381bbe
3 changed files with 40 additions and 25 deletions

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2010 Adenilson Cavalcanti <cavalcantii@gmail.com>
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
* Copyright 2010 Adenilson Cavalcanti <cavalcantii@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@ -24,6 +25,11 @@
#include "animationscriptengine_p.h"
#include <QFile>
#include <QTextStream>
#include <kdebug.h>
namespace Plasma
{
@ -78,6 +84,33 @@ QScriptEngine *globalEngine()
return inst;
}
bool loadScript(const QString &path)
{
QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
kError() << "failed to open script file" << path;
return false;
}
QTextStream buffer(&file);
QString tmp(buffer.readAll());
QScriptEngine *engine = AnimationScriptEngine::globalEngine();
QScriptValue def(engine->evaluate(tmp, path));
if (engine->hasUncaughtException()) {
const QScriptValue error = engine->uncaughtException();
QString file = error.property("fileName").toString();
const QString failureMsg = QString("Error in %1 on line %2.\n%3")
.arg(file)
.arg(error.property("lineNumber").toString())
.arg(error.toString());
kError() << failureMsg;
return false;
}
return true;
}
} // namespace AnimationEngine
} // namespace Plasma

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2010 Adenilson Cavalcanti <cavalcantii@gmail.com>
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
* Copyright 2010 Adenilson Cavalcanti <cavalcantii@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@ -37,6 +38,7 @@ void clearAnimations();
bool isAnimationRegistered(const QString &anim);
QScriptEngine* globalEngine();
QScriptValue animation(const QString &anim);
bool loadScript(const QString &path);
}

View File

@ -18,10 +18,7 @@
#include "animator.h"
#include "private/animator_p.h"
#include <QFile>
#include <QTextStream>
#include <KDebug>
#include <kdebug.h>
#include "animations/animation.h"
#include "animations/animationscriptengine_p.h"
@ -162,30 +159,13 @@ Plasma::Animation *Animator::create(const QString &anim, QObject *parent)
return 0;
}
QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
kError() << "failed to open script file" << path;
return 0;
}
QTextStream buffer(&file);
QString tmp(buffer.readAll());
QScriptEngine *engine = AnimationScriptEngine::globalEngine();
QScriptValue def(engine->evaluate(tmp, path));
if (engine->hasUncaughtException()) {
const QScriptValue error = engine->uncaughtException();
QString file = error.property("fileName").toString();
const QString failureMsg = QString("Error in %1 on line %2.\n%3")
.arg(file)
.arg(error.property("lineNumber").toString())
.arg(error.toString());
kError() << failureMsg;
if (!AnimationScriptEngine::loadScript(path)) {
return 0;
}
if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
kError() << "successfully loaded script file" << path << ", but did not get animation object for" << anim;
return false;
}
}