diff --git a/scriptengines/javascript/simplebindings/qscriptbookkeeping.cpp b/scriptengines/javascript/simplebindings/qscriptbookkeeping.cpp index dac42d249..3c3a97b40 100644 --- a/scriptengines/javascript/simplebindings/qscriptbookkeeping.cpp +++ b/scriptengines/javascript/simplebindings/qscriptbookkeeping.cpp @@ -20,23 +20,17 @@ #include #include -#include -#include - #include #include #include #include -#include "dataengine.h" #include "variant.h" //Q_DECLARE_METATYPE(SimpleJavaScriptApplet*) Q_DECLARE_METATYPE(QGraphicsWidget*) Q_DECLARE_METATYPE(QGraphicsLayout*) -Q_DECLARE_METATYPE(KConfigGroup) - Q_DECLARE_METATYPE(Plasma::Animation*) Q_DECLARE_METATYPE(Plasma::Applet*) Q_DECLARE_METATYPE(Plasma::Extender*) @@ -76,85 +70,16 @@ void controlsFromScriptValue(const QScriptValue& obj, Plasma::VideoWidget::Contr } } -Q_DECLARE_METATYPE(KJob *) -typedef KJob* KJobPtr; -QScriptValue qScriptValueFromKJob(QScriptEngine *engine, const KJobPtr &job) -{ - return engine->newQObject(const_cast(job), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); -} - -void qKJobFromQScriptValue(const QScriptValue &scriptValue, KJobPtr &job) -{ - QObject *obj = scriptValue.toQObject(); - job = static_cast(obj); -} - -Q_DECLARE_METATYPE(KIO::Job *) -typedef KIO::Job* KioJobPtr; -QScriptValue qScriptValueFromKIOJob(QScriptEngine *engine, const KioJobPtr &job) -{ - return engine->newQObject(const_cast(job), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); -} - -void qKIOJobFromQScriptValue(const QScriptValue &scriptValue, KioJobPtr &job) -{ - QObject *obj = scriptValue.toQObject(); - job = static_cast(obj); -} - -QScriptValue qScriptValueFromKConfigGroup(QScriptEngine *engine, const KConfigGroup &config) -{ - QScriptValue obj = engine->newObject(); - - if (!config.isValid()) { - return obj; - } - - QMap entryMap = config.entryMap(); - QMap::const_iterator it = entryMap.constBegin(); - QMap::const_iterator begin = it; - QMap::const_iterator end = entryMap.constEnd(); - - //setting the group name - obj.setProperty("__name", QScriptValue(engine, config.name())); - - //setting the key/value pairs - for (it = begin; it != end; ++it) { - //kDebug() << "setting" << it.key() << "to" << it.value(); - QString prop = it.key(); - prop.replace(' ', '_'); - obj.setProperty(prop, variantToScriptValue(engine, it.value())); - } - - return obj; -} - -void kConfigGroupFromScriptValue(const QScriptValue& obj, KConfigGroup &config) -{ - KConfigSkeleton *skel = new KConfigSkeleton(); - config = KConfigGroup(skel->config(), obj.property("__name").toString()); - - QScriptValueIterator it(obj); - - while (it.hasNext()) { - it.next(); - //kDebug() << it.name() << "is" << it.value().toString(); - if (it.name() != "__name") { - config.writeEntry(it.name(), it.value().toString()); - } - } -} - typedef Plasma::Animation* AnimationPtr; QScriptValue qScriptValueFromAnimation(QScriptEngine *engine, const AnimationPtr &anim) { - return engine->newQObject(const_cast(anim), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); + return engine->newQObject(const_cast(anim), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); } void abstractAnimationFromQScriptValue(const QScriptValue &scriptValue, AnimationPtr &anim) { QObject *obj = scriptValue.toQObject(); - anim = static_cast(obj); + anim = static_cast(obj); } typedef QGraphicsWidget * QGraphicsWidgetPtr; @@ -210,14 +135,11 @@ void registerSimpleAppletMetaTypes(QScriptEngine *engine) qScriptRegisterMetaType(engine, qScriptValueFromQGraphicsWidget, graphicsWidgetFromQScriptValue); qScriptRegisterMetaType(engine, qScriptValueFromSvg, svgFromQScriptValue); - qScriptRegisterMetaType(engine, qScriptValueFromKConfigGroup, kConfigGroupFromScriptValue, QScriptValue()); - qScriptRegisterMetaType(engine, qScriptValueFromKJob, qKJobFromQScriptValue); - qScriptRegisterMetaType(engine, qScriptValueFromKIOJob, qKIOJobFromQScriptValue); - qScriptRegisterMetaType(engine, qScriptValueFromAnimation, abstractAnimationFromQScriptValue); qScriptRegisterMetaType(engine, qScriptValueFromExtender, extenderFromQScriptValue); qScriptRegisterMetaType(engine, qScriptValueFromControls, controlsFromScriptValue, QScriptValue()); qScriptRegisterMetaType(engine, qScriptValueFromMouseButton, mouseButtonFromScriptValue); - registerDataEngineMetaTypes(engine); } +#include "simplebindings/qscriptnonguibookkeeping.cpp" + diff --git a/scriptengines/javascript/simplebindings/qscriptnonguibookkeeping.cpp b/scriptengines/javascript/simplebindings/qscriptnonguibookkeeping.cpp new file mode 100644 index 000000000..712c3bd0b --- /dev/null +++ b/scriptengines/javascript/simplebindings/qscriptnonguibookkeeping.cpp @@ -0,0 +1,109 @@ +/* + * Copyright 2007-2008 Richard J. Moore + * Copyright 2009 Aaron J. Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 + +#include +#include +#include + +#include "dataengine.h" +#include "variant.h" + +Q_DECLARE_METATYPE(KConfigGroup) +Q_DECLARE_METATYPE(KJob *) + +typedef KJob* KJobPtr; +QScriptValue qScriptValueFromKJob(QScriptEngine *engine, const KJobPtr &job) +{ + return engine->newQObject(const_cast(job), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); +} + +void qKJobFromQScriptValue(const QScriptValue &scriptValue, KJobPtr &job) +{ + QObject *obj = scriptValue.toQObject(); + job = static_cast(obj); +} + +Q_DECLARE_METATYPE(KIO::Job *) +typedef KIO::Job* KioJobPtr; +QScriptValue qScriptValueFromKIOJob(QScriptEngine *engine, const KioJobPtr &job) +{ + return engine->newQObject(const_cast(job), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject); +} + +void qKIOJobFromQScriptValue(const QScriptValue &scriptValue, KioJobPtr &job) +{ + QObject *obj = scriptValue.toQObject(); + job = static_cast(obj); +} + +QScriptValue qScriptValueFromKConfigGroup(QScriptEngine *engine, const KConfigGroup &config) +{ + QScriptValue obj = engine->newObject(); + + if (!config.isValid()) { + return obj; + } + + QMap entryMap = config.entryMap(); + QMap::const_iterator it = entryMap.constBegin(); + QMap::const_iterator begin = it; + QMap::const_iterator end = entryMap.constEnd(); + + //setting the group name + obj.setProperty("__file", QScriptValue(engine, config.config()->name())); + obj.setProperty("__name", QScriptValue(engine, config.name())); + + //setting the key/value pairs + for (it = begin; it != end; ++it) { + //kDebug() << "setting" << it.key() << "to" << it.value(); + QString prop = it.key(); + prop.replace(' ', '_'); + obj.setProperty(prop, variantToScriptValue(engine, it.value())); + } + + return obj; +} + +void kConfigGroupFromScriptValue(const QScriptValue& obj, KConfigGroup &config) +{ + config = KConfigGroup(KSharedConfig::openConfig(obj.property("__file").toString()), obj.property("__name").toString()); + + QScriptValueIterator it(obj); + + while (it.hasNext()) { + it.next(); + //kDebug() << it.name() << "is" << it.value().toString(); + if (it.name() != "__name") { + config.writeEntry(it.name(), it.value().toString()); + } + } +} + +using namespace Plasma; + +void registerNonGuiMetaTypes(QScriptEngine *engine) +{ + qScriptRegisterMetaType(engine, qScriptValueFromKConfigGroup, kConfigGroupFromScriptValue, QScriptValue()); + qScriptRegisterMetaType(engine, qScriptValueFromKJob, qKJobFromQScriptValue); + qScriptRegisterMetaType(engine, qScriptValueFromKIOJob, qKIOJobFromQScriptValue); + registerDataEngineMetaTypes(engine); +} +