[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/plasma/scripting
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2010-05-13 0:47:25
Message-ID: 20100513004725.0D863AC8B5 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1126035 by aseigo:

hook up AppletScript to the JS anims


 M  +43 -0     appletscript.cpp  
 M  +9 -0      appletscript.h  


--- trunk/KDE/kdelibs/plasma/scripting/appletscript.cpp #1126034:1126035
@@ -19,8 +19,11 @@
 
 #include "scripting/appletscript.h"
 
+#include "kconfig.h"
 #include "kconfigdialog.h"
 
+#include "animations/animationscriptengine_p.h"
+#include "animator.h"
 #include "applet.h"
 #include "package.h"
 #include "private/applet_p.h"
@@ -178,6 +181,46 @@
     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()
 {
 }
--- trunk/KDE/kdelibs/plasma/scripting/appletscript.h #1126034:1126035
@@ -38,6 +38,7 @@
 namespace Plasma
 {
 
+class Animation;
 class AppletScriptPrivate;
 class Extender;
 
@@ -225,6 +226,14 @@
      */
     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:
     friend class Applet;
     friend class PopupApplet;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic