From 736c381bbe2b88f27dc51f0dd68dd436d05340a1 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Wed, 28 Apr 2010 17:51:46 +0000 Subject: [PATCH] * 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 --- animations/animationscriptengine.cpp | 35 +++++++++++++++++++++++++++- animations/animationscriptengine_p.h | 4 +++- animator.cpp | 26 +++------------------ 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/animations/animationscriptengine.cpp b/animations/animationscriptengine.cpp index f36ccba6b..91d02ced8 100644 --- a/animations/animationscriptengine.cpp +++ b/animations/animationscriptengine.cpp @@ -1,5 +1,6 @@ /* - * Copyright (C) 2010 Adenilson Cavalcanti + * Copyright 2010 Aaron Seigo + * Copyright 2010 Adenilson Cavalcanti * * 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 +#include + +#include + 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 diff --git a/animations/animationscriptengine_p.h b/animations/animationscriptengine_p.h index e17c1bb89..2234e587b 100644 --- a/animations/animationscriptengine_p.h +++ b/animations/animationscriptengine_p.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2010 Adenilson Cavalcanti + * Copyright 2010 Aaron Seigo + * Copyright 2010 Adenilson Cavalcanti * * 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); } diff --git a/animator.cpp b/animator.cpp index fd760412c..52170c1bf 100644 --- a/animator.cpp +++ b/animator.cpp @@ -18,10 +18,7 @@ #include "animator.h" #include "private/animator_p.h" -#include -#include - -#include +#include #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; } }