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

List:       kde-commits
Subject:    KDE/kdebase/workspace/libs/plasmagenericshell/scripting
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2010-11-18 1:16:58
Message-ID: 20101118011658.4C6E7AC8A0 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1198260 by aseigo:

* move more properties into AppInterface
* add 'bool multihead'


 M  +42 -9     appinterface.cpp  
 M  +17 -2     appinterface.h  
 M  +25 -41    scriptengine.cpp  
 M  +3 -4      scriptengine.h  


--- trunk/KDE/kdebase/workspace/libs/plasmagenericshell/scripting/appinterface.cpp \
#1198259:1198260 @@ -22,30 +22,33 @@
 #include <QEventLoop>
 #include <QTimer>
 
+#include <KGlobalSettings>
+
 #include <Plasma/Containment>
 #include <Plasma/Corona>
 #include <Plasma/DataEngineManager>
+#include <Plasma/Theme>
 
 #include "scriptengine.h"
 
 namespace WorkspaceScripting
 {
 
-AppInterface::AppInterface(Plasma::Corona *corona, QObject *parent)
-    : QObject(parent),
-      m_corona(corona)
+AppInterface::AppInterface(ScriptEngine *env)
+    : QObject(env),
+      m_env(env)
 {
 
 }
 
 int AppInterface::screenCount() const
 {
-    return m_corona->numScreens();
+    return m_env->corona()->numScreens();
 }
 
 QRectF AppInterface::screenGeometry(int screen) const
 {
-    return m_corona->screenGeometry(screen);
+    return m_env->corona()->screenGeometry(screen);
 }
 
 QList<int> AppInterface::activityIds() const
@@ -54,7 +57,7 @@
     //       however QScript deals with QList<uint> very, very poory
     QList<int> containments;
 
-    foreach (Plasma::Containment *c, m_corona->containments()) {
+    foreach (Plasma::Containment *c, m_env->corona()->containments()) {
         if (!ScriptEngine::isPanel(c)) {
             containments.append(c->id());
         }
@@ -69,7 +72,7 @@
     //       however QScript deals with QList<uint> very, very poory
     QList<int> panels;
 
-    foreach (Plasma::Containment *c, m_corona->containments()) {
+    foreach (Plasma::Containment *c, m_env->corona()->containments()) {
         //kDebug() << "checking" << (QObject*)c << isPanel(c);
         if (ScriptEngine::isPanel(c)) {
             panels.append(c->id());
@@ -79,14 +82,44 @@
     return panels;
 }
 
+QString AppInterface::applicationVersion() const
+{
+    return KGlobal::mainComponent().aboutData()->version();
+}
+
+QString AppInterface::platformVersion() const
+{
+    return KDE::versionString();
+}
+
+int AppInterface::scriptingVersion() const
+{
+    return PLASMA_DESKTOP_SCRIPTING_VERSION;
+}
+
+QString AppInterface::theme() const
+{
+    return Plasma::Theme::defaultTheme()->themeName();
+}
+
+void AppInterface::setTheme(const QString &name)
+{
+    Plasma::Theme::defaultTheme()->setThemeName(name);
+}
+
+bool AppInterface::multihead() const
+{
+    return KGlobalSettings::isMultiHead();
+}
+
 void AppInterface::lockCorona(bool locked)
 {
-    m_corona->setImmutability(locked ? Plasma::UserImmutable : Plasma::Mutable);
+    m_env->corona()->setImmutability(locked ? Plasma::UserImmutable : \
Plasma::Mutable);  }
 
 bool AppInterface::coronaLocked() const
 {
-    return m_corona->immutability() != Plasma::Mutable;
+    return m_env->corona()->immutability() != Plasma::Mutable;
 }
 
 void AppInterface::sleep(int ms)
--- trunk/KDE/kdebase/workspace/libs/plasmagenericshell/scripting/appinterface.h \
#1198259:1198260 @@ -35,6 +35,8 @@
 namespace WorkspaceScripting
 {
 
+class ScriptEngine;
+
 class PLASMAGENERICSHELL_EXPORT AppInterface : public QObject
 {
     Q_OBJECT
@@ -46,9 +48,14 @@
     Q_PROPERTY(QStringList knownPanelTypes READ knownPanelTypes)
     Q_PROPERTY(QStringList knownActivityTypes READ knownActivityTypes)
     Q_PROPERTY(QStringList knownWidgetTypes READ knownWidgetTypes)
+    Q_PROPERTY(QString theme READ theme WRITE setTheme)
+    Q_PROPERTY(QString applicationVersion READ applicationVersion)
+    Q_PROPERTY(QString platformVersion READ platformVersion)
+    Q_PROPERTY(int scriptingVersion READ scriptingVersion)
+    Q_PROPERTY(bool multihead READ multihead)
 
 public:
-    AppInterface(Plasma::Corona *corona, QObject *parent = 0);
+    AppInterface(ScriptEngine *env);
 
     bool hasBattery() const;
     int screenCount() const;
@@ -60,6 +67,14 @@
     QStringList knownPanelTypes() const;
     QStringList knownContainmentTypes(const QString &type) const;
 
+    QString applicationVersion() const;
+    QString platformVersion() const;
+    int scriptingVersion() const;
+
+    QString theme() const;
+    void setTheme(const QString &name);
+
+    bool multihead() const;
     bool coronaLocked() const;
 
 public Q_SLOTS:
@@ -71,7 +86,7 @@
     void print(const QString &string);
 
 private:
-    Plasma::Corona *m_corona;
+    ScriptEngine *m_env;
 };
 
 }
--- trunk/KDE/kdebase/workspace/libs/plasmagenericshell/scripting/scriptengine.cpp \
#1198259:1198260 @@ -33,7 +33,6 @@
 #include <Plasma/Containment>
 #include <Plasma/Corona>
 #include <Plasma/Package>
-#include <Plasma/Theme>
 
 #include "appinterface.h"
 #include "containment.h"
@@ -50,7 +49,7 @@
       m_corona(corona)
 {
     Q_ASSERT(m_corona);
-    AppInterface *interface = new AppInterface(corona, this);
+    AppInterface *interface = new AppInterface(this);
     connect(interface, SIGNAL(print(QString)), this, SIGNAL(print(QString)));
     m_scriptSelf = newQObject(interface, QScriptEngine::QtOwnership,
                               QScriptEngine::ExcludeSuperClassProperties | \
QScriptEngine::ExcludeSuperClassMethods); @@ -62,18 +61,6 @@
 {
 }
 
-QScriptValue ScriptEngine::theme(QScriptContext *context, QScriptEngine *engine)
-{
-    Q_UNUSED(engine)
-
-    if (context->argumentCount() > 0) {
-        const QString newTheme = context->argument(0).toString();
-        Plasma::Theme::defaultTheme()->setThemeName(newTheme);
-    }
-
-    return Plasma::Theme::defaultTheme()->themeName();
-}
-
 QScriptValue ScriptEngine::activityById(QScriptContext *context, QScriptEngine \
*engine)  {
     if (context->argumentCount() == 0) {
@@ -207,25 +194,6 @@
     return engine->undefinedValue();
 }
 
-QScriptValue ScriptEngine::activities(QScriptContext *context, QScriptEngine \
                *engine)
-{
-    Q_UNUSED(context)
-
-    QScriptValue containments = engine->newArray();
-    ScriptEngine *env = envFor(engine);
-    int count = 0;
-
-    foreach (Plasma::Containment *c, env->m_corona->containments()) {
-        if (!isPanel(c)) {
-            containments.setProperty(count, env->wrap(c));
-            ++count;
-        }
-    }
-
-    containments.setProperty("length", count);
-    return containments;
-}
-
 QScriptValue ScriptEngine::panels(QScriptContext *context, QScriptEngine *engine)
 {
     Q_UNUSED(context)
@@ -348,14 +316,6 @@
     m_scriptSelf.setProperty("panels", newFunction(ScriptEngine::panels));
     m_scriptSelf.setProperty("fileExists", newFunction(ScriptEngine::fileExists));
     m_scriptSelf.setProperty("loadTemplate", \
                newFunction(ScriptEngine::loadTemplate));
-    m_scriptSelf.setProperty("applicationVersion", \
                KGlobal::mainComponent().aboutData()->version(),
-                             QScriptValue::PropertyGetter | QScriptValue::ReadOnly | \
                QScriptValue::Undeletable);
-    m_scriptSelf.setProperty("scriptingVersion", \
                newVariant(PLASMA_DESKTOP_SCRIPTING_VERSION),
-                             QScriptValue::PropertyGetter | QScriptValue::ReadOnly | \
                QScriptValue::Undeletable);
-    m_scriptSelf.setProperty("platformVersion", KDE::versionString(),
-                             QScriptValue::PropertyGetter | QScriptValue::ReadOnly | \
                QScriptValue::Undeletable);
-    m_scriptSelf.setProperty("theme", newFunction(ScriptEngine::theme),
-                             QScriptValue::PropertyGetter | \
QScriptValue::PropertySetter | QScriptValue::Undeletable);  
     setGlobalObject(m_scriptSelf);
 }
@@ -370,6 +330,30 @@
            c->containmentType() == Plasma::Containment::CustomPanelContainment;
 }
 
+QScriptValue ScriptEngine::activities(QScriptContext *context, QScriptEngine \
*engine) +{
+    Q_UNUSED(context)
+
+    QScriptValue containments = engine->newArray();
+    ScriptEngine *env = envFor(engine);
+    int count = 0;
+
+    foreach (Plasma::Containment *c, env->corona()->containments()) {
+        if (!isPanel(c)) {
+            containments.setProperty(count, env->wrap(c));
+            ++count;
+        }
+    }
+
+    containments.setProperty("length", count);
+    return containments;
+}
+
+Plasma::Corona *ScriptEngine::corona() const
+{
+    return m_corona;
+}
+
 bool ScriptEngine::evaluateScript(const QString &script, const QString &path)
 {
     //kDebug() << "evaluating" << m_editor->toPlainText();
--- trunk/KDE/kdebase/workspace/libs/plasmagenericshell/scripting/scriptengine.h \
#1198259:1198260 @@ -48,12 +48,13 @@
     static QStringList pendingUpdateScripts();
     static QStringList defaultLayoutScripts();
 
+    Plasma::Corona *corona() const;
     bool evaluateScript(const QString &script, const QString &path = QString());
-    static bool isPanel(const Plasma::Containment *c);
     QScriptValue wrap(Plasma::Applet *w);
     virtual QScriptValue wrap(Plasma::Containment *c);
     QScriptValue wrap(Containment *c);
 
+    static bool isPanel(const Plasma::Containment *c);
     static ScriptEngine *envFor(QScriptEngine *engine);
 
 Q_SIGNALS:
@@ -75,7 +76,6 @@
     static QScriptValue panels(QScriptContext *context, QScriptEngine *engine);
     static QScriptValue fileExists(QScriptContext *context, QScriptEngine *engine);
     static QScriptValue loadTemplate(QScriptContext *context, QScriptEngine \
                *engine);
-    static QScriptValue theme(QScriptContext *context, QScriptEngine *engine);
 
     // helpers
     static QScriptValue createContainment(const QString &type, const QString \
&defautPlugin, @@ -87,10 +87,9 @@
 private:
     Plasma::Corona *m_corona;
     QScriptValue m_scriptSelf;
-
-    static const int PLASMA_DESKTOP_SCRIPTING_VERSION = 3;
 };
 
+static const int PLASMA_DESKTOP_SCRIPTING_VERSION = 3;
 }
 
 #endif


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

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