use the engine access in DeclarativeWidget
now DeclarativeWidget itself steals the scriptengine, so use it instead of having the hack there
This commit is contained in:
parent
2754c01add
commit
2a54c9c416
@ -20,6 +20,8 @@
|
||||
#include "datamodel.h"
|
||||
#include "datasource_p.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
namespace Plasma
|
||||
@ -140,6 +142,11 @@ DataModel::DataModel(QObject* parent)
|
||||
this, SIGNAL(countChanged()));
|
||||
connect(this, SIGNAL(modelReset()),
|
||||
this, SIGNAL(countChanged()));
|
||||
|
||||
m_roleNamesTimer = new QTimer(this);
|
||||
m_roleNamesTimer->setSingleShot(true);
|
||||
connect(m_roleNamesTimer, SIGNAL(timeout()),
|
||||
this, SLOT(syncRoleNames()));
|
||||
}
|
||||
|
||||
DataModel::~DataModel()
|
||||
@ -253,6 +260,13 @@ void DataModel::setItems(const QString &sourceName, const QVariantList &list)
|
||||
setRoleNames(m_roleNames);
|
||||
}
|
||||
|
||||
m_roleNamesTimer->start(0);
|
||||
}
|
||||
|
||||
void DataModel::syncRoleNames()
|
||||
{
|
||||
setRoleNames(m_roleNames);
|
||||
|
||||
//make the declarative view reload everything,
|
||||
//would be nice an incremental update but is not possible
|
||||
emit modelReset();
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include <Plasma/DataEngine>
|
||||
|
||||
class QTimer;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
@ -125,10 +126,12 @@ Q_SIGNALS:
|
||||
private Q_SLOTS:
|
||||
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
|
||||
void removeSource(const QString &sourceName);
|
||||
void syncRoleNames();
|
||||
|
||||
private:
|
||||
DataSource *m_dataSource;
|
||||
QString m_keyRoleFilter;
|
||||
QTimer *m_roleNamesTimer;
|
||||
QMap<QString, QVector<QVariant> > m_items;
|
||||
QHash<int, QByteArray> m_roleNames;
|
||||
QHash<QString, int> m_roleIds;
|
||||
|
@ -127,7 +127,6 @@ set(declarative_appletscript_SRCS
|
||||
plasmoid/appletauthorization.cpp
|
||||
plasmoid/appletinterface.cpp
|
||||
plasmoid/declarativeappletscript.cpp
|
||||
plasmoid/engineaccess.cpp
|
||||
plasmoid/themedsvg.cpp
|
||||
simplebindings/bytearrayclass.cpp
|
||||
simplebindings/bytearrayprototype.cpp
|
||||
|
@ -46,7 +46,6 @@
|
||||
|
||||
#include "plasmoid/declarativeappletscript.h"
|
||||
|
||||
#include "engineaccess.h"
|
||||
#include "plasmoid/appletinterface.h"
|
||||
#include "plasmoid/themedsvg.h"
|
||||
|
||||
@ -123,18 +122,12 @@ bool DeclarativeAppletScript::init()
|
||||
m_interface = new AppletInterface(this);
|
||||
}
|
||||
|
||||
m_engineAccess = new EngineAccess(this);
|
||||
m_declarativeWidget->engine()->rootContext()->setContextProperty("__engineAccess", m_engineAccess);
|
||||
|
||||
connect(applet(), SIGNAL(extenderItemRestored(Plasma::ExtenderItem*)),
|
||||
this, SLOT(extenderItemRestored(Plasma::ExtenderItem*)));
|
||||
connect(applet(), SIGNAL(activate()),
|
||||
this, SLOT(activate()));
|
||||
|
||||
//Glorious hack:steal the engine
|
||||
QDeclarativeExpression *expr = new QDeclarativeExpression(m_declarativeWidget->engine()->rootContext(), m_declarativeWidget->rootObject(), "__engineAccess.setEngine(this)");
|
||||
expr->evaluate();
|
||||
delete expr;
|
||||
setupObjects();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -352,10 +345,19 @@ ScriptEnv *DeclarativeAppletScript::scriptEnv()
|
||||
|
||||
void DeclarativeAppletScript::setupObjects()
|
||||
{
|
||||
QScriptValue global = m_engine->globalObject();
|
||||
m_engine = m_declarativeWidget->scriptEngine();
|
||||
connect(m_engine, SIGNAL(signalHandlerException(const QScriptValue &)),
|
||||
this, SLOT(signalHandlerException(const QScriptValue &)));
|
||||
QScriptValue originalGlobalObject = m_engine->globalObject();
|
||||
|
||||
m_declarativeWidget->engine()->rootContext()->setContextProperty("__engineAccess", 0);
|
||||
m_engineAccess->deleteLater();
|
||||
QScriptValue newGlobalObject = m_engine->newObject();
|
||||
|
||||
m_engine->setGlobalObject(newGlobalObject);
|
||||
|
||||
delete m_env;
|
||||
m_env = new ScriptEnv(this, m_engine);
|
||||
|
||||
QScriptValue global = m_engine->globalObject();
|
||||
|
||||
m_self = m_engine->newQObject(m_interface);
|
||||
m_self.setScope(global);
|
||||
@ -394,6 +396,16 @@ void DeclarativeAppletScript::setupObjects()
|
||||
global.setProperty("Svg", m_engine->newFunction(DeclarativeAppletScript::newPlasmaSvg));
|
||||
global.setProperty("FrameSvg", m_engine->newFunction(DeclarativeAppletScript::newPlasmaFrameSvg));
|
||||
global.setProperty("ExtenderItem", m_engine->newFunction(DeclarativeAppletScript::newPlasmaExtenderItem));
|
||||
|
||||
if (!m_env->importExtensions(description(), m_self, m_auth)) {
|
||||
return;
|
||||
}
|
||||
|
||||
qScriptRegisterSequenceMetaType<KUrl::List>(m_engine);
|
||||
registerNonGuiMetaTypes(m_engine);
|
||||
registerSimpleAppletMetaTypes(m_engine);
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(configChanged()));
|
||||
}
|
||||
|
||||
QScriptValue DeclarativeAppletScript::dataEngine(QScriptContext *context, QScriptEngine *engine)
|
||||
@ -460,67 +472,6 @@ QScriptEngine *DeclarativeAppletScript::engine() const
|
||||
return m_engine;
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::setEngine(QScriptValue &val)
|
||||
{
|
||||
if (val.engine() == m_engine) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_engine = val.engine();
|
||||
connect(m_engine, SIGNAL(signalHandlerException(const QScriptValue &)),
|
||||
this, SLOT(signalHandlerException(const QScriptValue &)));
|
||||
QScriptValue originalGlobalObject = m_engine->globalObject();
|
||||
|
||||
QScriptValue newGlobalObject = m_engine->newObject();
|
||||
|
||||
QString eval = QLatin1String("eval");
|
||||
QString version = QLatin1String("version");
|
||||
|
||||
{
|
||||
QScriptValueIterator iter(originalGlobalObject);
|
||||
QVector<QString> names;
|
||||
QVector<QScriptValue> values;
|
||||
QVector<QScriptValue::PropertyFlags> flags;
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
|
||||
QString name = iter.name();
|
||||
|
||||
if (name == version) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (name != eval) {
|
||||
names.append(name);
|
||||
values.append(iter.value());
|
||||
flags.append(iter.flags() | QScriptValue::Undeletable);
|
||||
}
|
||||
newGlobalObject.setProperty(iter.scriptName(), iter.value());
|
||||
|
||||
// m_illegalNames.insert(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
m_engine->setGlobalObject(newGlobalObject);
|
||||
|
||||
delete m_env;
|
||||
m_env = new ScriptEnv(this, m_engine);
|
||||
//m_env->addMainObjectProperties(newGlobalObject);
|
||||
|
||||
setupObjects();
|
||||
|
||||
if (!m_env->importExtensions(description(), m_self, m_auth)) {
|
||||
return;
|
||||
}
|
||||
|
||||
qScriptRegisterSequenceMetaType<KUrl::List>(m_engine);
|
||||
registerNonGuiMetaTypes(m_engine);
|
||||
registerSimpleAppletMetaTypes(m_engine);
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(configChanged()));
|
||||
}
|
||||
|
||||
void DeclarativeAppletScript::signalHandlerException(const QScriptValue &exception)
|
||||
{
|
||||
kWarning()<<"Exception caught: "<<exception.toVariant();
|
||||
|
@ -47,8 +47,6 @@ public:
|
||||
DeclarativeAppletScript(QObject *parent, const QVariantList &args);
|
||||
~DeclarativeAppletScript();
|
||||
|
||||
void setEngine(QScriptValue &val);
|
||||
|
||||
QString filePath(const QString &type, const QString &file) const;
|
||||
|
||||
void executeAction(const QString &name);
|
||||
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "engineaccess.h"
|
||||
#include "scriptenv.h"
|
||||
|
||||
#include "plasmoid/declarativeappletscript.h"
|
||||
|
||||
EngineAccess::EngineAccess(DeclarativeAppletScript *parent)
|
||||
: QObject(parent),
|
||||
m_appletScriptEngine(parent)
|
||||
{
|
||||
}
|
||||
|
||||
EngineAccess::~EngineAccess()
|
||||
{
|
||||
}
|
||||
|
||||
void EngineAccess::setEngine(QScriptValue val)
|
||||
{
|
||||
m_appletScriptEngine->setEngine(val);
|
||||
}
|
||||
|
||||
#include "engineaccess.moc"
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef ENGINEACCESS_H
|
||||
#define ENGINEACCESS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <QScriptValue>
|
||||
|
||||
class DeclarativeAppletScript;
|
||||
|
||||
class EngineAccess : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
EngineAccess(DeclarativeAppletScript *parent);
|
||||
~EngineAccess();
|
||||
|
||||
Q_INVOKABLE void setEngine(QScriptValue val);
|
||||
|
||||
private:
|
||||
DeclarativeAppletScript *m_appletScriptEngine;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user