* move more properties into AppInterface
* add 'bool multihead' svn path=/trunk/KDE/kdebase/workspace/; revision=1198260
This commit is contained in:
parent
e52a934109
commit
61a7ee7247
@ -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 @@ QList<int> AppInterface::activityIds() const
|
||||
// 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 @@ QList<int> AppInterface::panelIds() const
|
||||
// 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 @@ QList<int> AppInterface::panelIds() const
|
||||
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)
|
||||
|
@ -35,6 +35,8 @@ namespace Plasma
|
||||
namespace WorkspaceScripting
|
||||
{
|
||||
|
||||
class ScriptEngine;
|
||||
|
||||
class PLASMAGENERICSHELL_EXPORT AppInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -46,9 +48,14 @@ class PLASMAGENERICSHELL_EXPORT AppInterface : public QObject
|
||||
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 @@ public:
|
||||
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 @@ Q_SIGNALS:
|
||||
void print(const QString &string);
|
||||
|
||||
private:
|
||||
Plasma::Corona *m_corona;
|
||||
ScriptEngine *m_env;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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 @@ ScriptEngine::ScriptEngine(Plasma::Corona *corona, QObject *parent)
|
||||
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 @@ ScriptEngine::~ScriptEngine()
|
||||
{
|
||||
}
|
||||
|
||||
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 @@ QScriptValue ScriptEngine::panelById(QScriptContext *context, QScriptEngine *eng
|
||||
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 @@ void ScriptEngine::setupEngine()
|
||||
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 @@ bool ScriptEngine::isPanel(const Plasma::Containment *c)
|
||||
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();
|
||||
|
@ -48,12 +48,13 @@ public:
|
||||
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 @@ private:
|
||||
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 Q_SLOTS:
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user