hook up AppletScript to the JS anims

svn path=/trunk/KDE/kdelibs/; revision=1126035
This commit is contained in:
Aaron J. Seigo 2010-05-13 00:47:24 +00:00
parent eb8e81e27c
commit cb6d3b581a
2 changed files with 52 additions and 0 deletions

View File

@ -19,8 +19,11 @@
#include "scripting/appletscript.h" #include "scripting/appletscript.h"
#include "kconfig.h"
#include "kconfigdialog.h" #include "kconfigdialog.h"
#include "animations/animationscriptengine_p.h"
#include "animator.h"
#include "applet.h" #include "applet.h"
#include "package.h" #include "package.h"
#include "private/applet_p.h" #include "private/applet_p.h"
@ -178,6 +181,46 @@ bool AppletScript::isRegisteredAsDragHandle(QGraphicsItem *item)
return false; return false;
} }
Animation *AppletScript::loadAnimationFromPackage(const QString &name, QObject *parent)
{
if (applet()) {
const QString scopedName = applet()->pluginName() + ":" + name;
if (!AnimationScriptEngine::isAnimationRegistered(scopedName)) {
KConfig conf(applet()->package()->path() + "/metadata.desktop", KConfig::SimpleConfig);
KConfigGroup animConf(&conf, "Animations");
QString file;
foreach (const QString &possibleFile, animConf.keyList()) {
const QStringList anims = animConf.readEntry(possibleFile, QStringList());
if (anims.contains(name)) {
file = possibleFile;
break;
}
}
if (file.isEmpty()) {
return 0;
}
const QString path = applet()->package()->filePath("animations", file);
if (path.isEmpty()) {
kDebug() << "file path was empty for" << file;
return 0;
}
if (!AnimationScriptEngine::loadScript(path, applet()->pluginName() + ':') ||
!AnimationScriptEngine::isAnimationRegistered(scopedName)) {
kDebug() << "script engine loading failed for" << path;
return 0;
}
}
Animation *anim = Animator::create(scopedName, parent ? parent : this);
return anim;
}
return 0;
}
void AppletScript::configChanged() void AppletScript::configChanged()
{ {
} }

View File

@ -38,6 +38,7 @@ class KConfigDialog;
namespace Plasma namespace Plasma
{ {
class Animation;
class AppletScriptPrivate; class AppletScriptPrivate;
class Extender; class Extender;
@ -225,6 +226,14 @@ protected:
*/ */
bool isRegisteredAsDragHandle(QGraphicsItem *item); bool isRegisteredAsDragHandle(QGraphicsItem *item);
/**
* Loads an animation from the applet package
* @arg animation the animation to load
* @return an Animation object on success, a NULL pointer on failure
* @since 4.5
*/
Animation *loadAnimationFromPackage(const QString &name, QObject *parent);
private: private:
friend class Applet; friend class Applet;
friend class PopupApplet; friend class PopupApplet;