use the centralized global object methods from ScriptEnv in SimpleJavaScriptApplet; gets rid of a handful of code and makes it more consistent
svn path=/trunk/KDE/kdebase/runtime/; revision=1171438
This commit is contained in:
parent
6a9b6a302c
commit
bf35cc9176
@ -81,6 +81,7 @@ void ScriptEnv::addMainObjectProperties(QScriptValue &value)
|
||||
value.setProperty("loadAddon", m_engine->newFunction(ScriptEnv::loadAddon));
|
||||
value.setProperty("addEventListener", m_engine->newFunction(ScriptEnv::addEventListener));
|
||||
value.setProperty("removeEventListener", m_engine->newFunction(ScriptEnv::removeEventListener));
|
||||
value.setProperty("hasExtension", m_engine->newFunction(ScriptEnv::hasExtension));
|
||||
}
|
||||
|
||||
QScriptEngine *ScriptEnv::engine() const
|
||||
@ -519,6 +520,20 @@ QScriptValue ScriptEnv::removeEventListener(QScriptContext *context, QScriptEngi
|
||||
return env->removeEventListener(context->argument(0).toString(), context->argument(1));
|
||||
}
|
||||
|
||||
QScriptValue ScriptEnv::hasExtension(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(engine);
|
||||
if (!env) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return env->m_extensions.contains(context->argument(0).toString().toLower());
|
||||
}
|
||||
|
||||
QScriptValue ScriptEnv::callFunction(QScriptValue &func, const QScriptValueList &args, const QScriptValue &activator)
|
||||
{
|
||||
if (!func.isFunction()) {
|
||||
|
@ -85,6 +85,7 @@ private:
|
||||
static QScriptValue registerAddon(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue addEventListener(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue removeEventListener(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue hasExtension(QScriptContext *context, QScriptEngine *engine);
|
||||
//static QScriptValue addonFilePath(QScriptContext *context, QScriptEngine *engine);
|
||||
|
||||
private Q_SLOTS:
|
||||
|
@ -341,11 +341,6 @@ bool AppletInterface::include(const QString &script)
|
||||
return m_appletScriptEngine->include(path);
|
||||
}
|
||||
|
||||
bool AppletInterface::hasExtension(const QString &extension) const
|
||||
{
|
||||
return m_appletScriptEngine->loadedExtensions().contains(extension.toLower());
|
||||
}
|
||||
|
||||
void AppletInterface::debug(const QString &msg)
|
||||
{
|
||||
kDebug() << msg;
|
||||
@ -372,16 +367,6 @@ Plasma::Extender *AppletInterface::extender() const
|
||||
return m_appletScriptEngine->extender();
|
||||
}
|
||||
|
||||
void AppletInterface::addEventListener(const QString &event, const QScriptValue &func)
|
||||
{
|
||||
m_appletScriptEngine->addEventListener(event, func);
|
||||
}
|
||||
|
||||
void AppletInterface::removeEventListener(const QString &event, const QScriptValue &func)
|
||||
{
|
||||
m_appletScriptEngine->removeEventListener(event, func);
|
||||
}
|
||||
|
||||
void AppletInterface::gc()
|
||||
{
|
||||
QTimer::singleShot(0, m_appletScriptEngine, SLOT(collectGarbage()));
|
||||
|
@ -269,16 +269,12 @@ enum IntervalAlignment {
|
||||
Q_INVOKABLE QString file(const QString &fileType, const QString &filePath);
|
||||
|
||||
Q_INVOKABLE bool include(const QString &script);
|
||||
Q_INVOKABLE bool hasExtension(const QString &extension) const;
|
||||
|
||||
Q_INVOKABLE void debug(const QString &msg);
|
||||
Q_INVOKABLE QObject *findChild(const QString &name) const;
|
||||
|
||||
Q_INVOKABLE Plasma::Extender *extender() const;
|
||||
|
||||
Q_INVOKABLE void addEventListener(const QString &event, const QScriptValue &func);
|
||||
Q_INVOKABLE void removeEventListener(const QString &event, const QScriptValue &func);
|
||||
|
||||
Plasma::DataEngine *dataEngine(const QString &name);
|
||||
|
||||
const Plasma::Package *package() const;
|
||||
|
@ -253,22 +253,6 @@ void SimpleJavaScriptApplet::callPlasmoidFunction(const QString &functionName, c
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::addEventListener(const QString &event, const QScriptValue &func)
|
||||
{
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (env) {
|
||||
env->addEventListener(event, func);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::removeEventListener(const QString &event, const QScriptValue &func)
|
||||
{
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
if (env) {
|
||||
env->removeEventListener(event, func);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::constraintsEvent(Plasma::Constraints constraints)
|
||||
{
|
||||
ScriptEnv *env = ScriptEnv::findScriptEnv(m_engine);
|
||||
@ -537,6 +521,7 @@ void SimpleJavaScriptApplet::setupObjects()
|
||||
const bool isPopupApplet = qobject_cast<Plasma::PopupApplet *>(applet());
|
||||
m_interface = isPopupApplet ? new PopupAppletInterface(this) : new AppletInterface(this);
|
||||
m_self = m_engine->newQObject(m_interface);
|
||||
m_env->addMainObjectProperties(m_self);
|
||||
m_self.setScope(global);
|
||||
global.setProperty("plasmoid", m_self);
|
||||
|
||||
@ -596,11 +581,6 @@ void SimpleJavaScriptApplet::setupObjects()
|
||||
installWidgets(m_engine);
|
||||
}
|
||||
|
||||
QSet<QString> SimpleJavaScriptApplet::loadedExtensions() const
|
||||
{
|
||||
return m_env->loadedExtensions();
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::dataEngine(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 1) {
|
||||
|
@ -55,8 +55,6 @@ public:
|
||||
bool include(const QString &path);
|
||||
QSet<QString> loadedExtensions() const;
|
||||
QScriptValue variantToScriptValue(QVariant var);
|
||||
void addEventListener(const QString &event, const QScriptValue &func);
|
||||
void removeEventListener(const QString &event, const QScriptValue &func);
|
||||
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user