summaryrefslogtreecommitdiffstats
path: root/kjsembed/plugins
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /kjsembed/plugins
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kjsembed/plugins')
-rw-r--r--kjsembed/plugins/Makefile.am38
-rw-r--r--kjsembed/plugins/customobject_plugin.cpp183
-rw-r--r--kjsembed/plugins/customobject_plugin.desktop5
-rw-r--r--kjsembed/plugins/customobject_plugin.h68
-rw-r--r--kjsembed/plugins/customqobject_plugin.cpp96
-rw-r--r--kjsembed/plugins/customqobject_plugin.desktop5
-rw-r--r--kjsembed/plugins/customqobject_plugin.h68
-rw-r--r--kjsembed/plugins/imagefx_plugin.cpp858
-rw-r--r--kjsembed/plugins/imagefx_plugin.desktop5
-rw-r--r--kjsembed/plugins/imagefx_plugin.h130
-rw-r--r--kjsembed/plugins/kfileitem_plugin.desktop5
-rw-r--r--kjsembed/plugins/kfileitemloader.cpp223
-rw-r--r--kjsembed/plugins/kfileitemloader.h69
-rw-r--r--kjsembed/plugins/qprocess_plugin.cpp144
-rw-r--r--kjsembed/plugins/qprocess_plugin.desktop5
-rw-r--r--kjsembed/plugins/qprocess_plugin.h86
16 files changed, 1988 insertions, 0 deletions
diff --git a/kjsembed/plugins/Makefile.am b/kjsembed/plugins/Makefile.am
new file mode 100644
index 00000000..f3071bb2
--- /dev/null
+++ b/kjsembed/plugins/Makefile.am
@@ -0,0 +1,38 @@
+INCLUDES= -I$(srcdir)/.. -I$(srcdir)/../.. $(all_includes)
+KDE_CXXFLAGS = -DQT_NO_ASCII_CAST -DQT_CLEAN_NAMESPACE
+
+kde_module_LTLIBRARIES = libcustomobjectplugin.la libcustomqobjectplugin.la \
+ libimagefxplugin.la libqprocessplugin.la libfileitemplugin.la
+METASOURCES = AUTO
+
+# the Plugin's source, library search path, and link libraries
+libcustomobjectplugin_la_SOURCES = customobject_plugin.cpp
+libcustomobjectplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries)
+libcustomobjectplugin_la_LIBADD = $(LIB_QT) $(LIB_KPARTS) $(LIB_KDECORE) $(LIB_KFILE) ../libkjsembed.la
+
+# the Plugin's source, library search path, and link libraries
+libcustomqobjectplugin_la_SOURCES = customqobject_plugin.cpp
+libcustomqobjectplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries)
+libcustomqobjectplugin_la_LIBADD = $(LIB_QT) $(LIB_KPARTS) $(LIB_KDECORE) $(LIB_KFILE) ../libkjsembed.la
+
+# the Plugin's source, library search path, and link libraries
+libimagefxplugin_la_SOURCES = imagefx_plugin.cpp
+libimagefxplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries)
+libimagefxplugin_la_LIBADD = $(LIB_QT) $(LIB_KPARTS) $(LIB_KDECORE) $(LIB_KFILE) ../libkjsembed.la
+
+# the Plugin's source, library search path, and link libraries
+libqprocessplugin_la_SOURCES = qprocess_plugin.cpp
+libqprocessplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries)
+libqprocessplugin_la_LIBADD = $(LIB_QT) $(LIB_KPARTS) $(LIB_KDECORE) $(LIB_KFILE) ../libkjsembed.la
+
+# the Plugin's source, library search path, and link libraries
+libfileitemplugin_la_SOURCES = kfileitemloader.cpp
+libfileitemplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
+libfileitemplugin_la_LIBADD = $(LIB_KPARTS) $(LIB_KFILE) ../libkjsembed.la
+
+
+# this is where the desktop file will go
+plugindesktopdir = $(kde_servicesdir)
+plugindesktop_DATA = customobject_plugin.desktop customqobject_plugin.desktop imagefx_plugin.desktop\
+ qprocess_plugin.desktop kfileitem_plugin.desktop
+
diff --git a/kjsembed/plugins/customobject_plugin.cpp b/kjsembed/plugins/customobject_plugin.cpp
new file mode 100644
index 00000000..7c188cba
--- /dev/null
+++ b/kjsembed/plugins/customobject_plugin.cpp
@@ -0,0 +1,183 @@
+// -*- c++ -*-
+
+/*
+ * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <kdebug.h>
+#include <kjsembed/jsopaqueproxy.h>
+#include <kjsembed/jsbinding.h>
+#include <kjsembed/jsfactory.h>
+#include <kjsembed/jsfactory_imp.h>
+#include <kjsembed/kjsembedpart.h>
+#include <kjsembed/customobject_imp.h>
+#include <qvariant.h>
+#include <qbrush.h>
+
+#include "customobject_plugin.h"
+
+namespace KJSEmbed {
+namespace Bindings {
+
+class MyCustomObject
+{
+ public:
+ enum Mode { On, Off };
+ Mode mode;
+ QString thing;
+};
+
+MyCustomObjectLoader::MyCustomObjectLoader( QObject *parent, const char *name, const QStringList &args ) :
+ JSBindingPlugin(parent, name, args)
+{
+}
+
+KJS::Object MyCustomObjectLoader::createBinding(KJSEmbedPart */*jspart*/, KJS::ExecState *exec, const KJS::List &/*args*/) const
+{
+ kdDebug() << "Loading a custom object" << endl;
+ MyCustomObject *obj = new MyCustomObject();
+ JSOpaqueProxy *prx = new JSOpaqueProxy( (void *) obj, "MyCustomObject" );
+
+ KJS::Object proxyObj(prx);
+ MyCustomObjectImp::addBindings( exec, proxyObj );
+ return proxyObj;
+}
+
+MyCustomObjectImp::MyCustomObjectImp( KJS::ExecState *exec, int id )
+ : JSProxyImp(exec), mid(id)
+{
+}
+
+MyCustomObjectImp::~MyCustomObjectImp()
+{
+}
+
+void MyCustomObjectImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) {
+
+ kdDebug() << "MyCustomObjectImp::addBindings()" << endl;
+ JSOpaqueProxy *op = JSProxy::toOpaqueProxy( object.imp() );
+ if ( !op ) {
+ kdWarning() << "MyCustomObjectImp::addBindings() failed, not a JSOpaqueProxy" << endl;
+ return;
+ }
+
+ if ( op->typeName() != "MyCustomObject" ) {
+ kdWarning() << "MyCustomObjectImp::addBindings() failed, type is " << op->typeName() << endl;
+ return;
+ }
+
+ JSProxy::MethodTable methods[] = {
+ { Methodmode, "mode"},
+ { MethodsetMode, "setMode"},
+ { Methodthing, "thing"},
+ { MethodsetThing, "setThing"},
+ { 0, 0 }
+ };
+
+ int idx = 0;
+ do {
+ MyCustomObjectImp *meth = new MyCustomObjectImp( exec, methods[idx].id );
+ object.put( exec , methods[idx].name, KJS::Object(meth) );
+ ++idx;
+ } while( methods[idx].id );
+
+ //
+ // Define the enum constants
+ //
+ struct EnumValue {
+ const char *id;
+ int val;
+ };
+
+ EnumValue enums[] = {
+ // MyCustomObject::mode
+ { "On", 0 },
+ { "Off", 1 },
+ { 0, 0 }
+ };
+
+ int enumidx = 0;
+ do {
+ object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly );
+ ++enumidx;
+ } while( enums[enumidx].id );
+}
+
+KJS::Value MyCustomObjectImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) {
+
+ kdDebug() << "MyCustomObjectImp::call() " << mid << endl;
+ JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() );
+ if ( !op ) {
+ kdWarning() << "MyCustomObjectImp::call() failed, not a JSOpaqueProxy" << endl;
+ return KJS::Value();
+ }
+
+ if ( op->typeName() != "MyCustomObject" ) {
+ kdWarning() << "MyCustomObjectImp::call() failed, type is " << op->typeName() << endl;
+ return KJS::Value();
+ }
+
+ MyCustomObject *obj = op->toNative<MyCustomObject>();
+
+ KJS::Value retValue = KJS::Value();
+ switch ( mid ) {
+ case Methodthing:
+ {
+ retValue = KJS::String(obj->thing);
+ break;
+ }
+ case MethodsetThing:
+ {
+ obj->thing = extractString(exec, args, 0);
+ break;
+ }
+ case Methodmode:
+ {
+ retValue = KJS::Number( (int)obj->mode );
+ break;
+ }
+ case MethodsetMode:
+ {
+ obj->mode = (MyCustomObject::Mode) extractInt(exec, args, 0);
+ break;
+ }
+ default:
+ kdWarning() << "MyCustomObject has no method " << mid << endl;
+ break;
+ }
+
+ op->setValue((void*) obj, "MyCustomObject");
+ return retValue;
+}
+
+
+int MyCustomObjectImp::extractInt( KJS::ExecState *exec, const KJS::List &args, int idx)
+{
+ return (args.size() > idx) ? args[idx].toInteger(exec) : 0;
+}
+QString MyCustomObjectImp::extractString(KJS::ExecState *exec, const KJS::List &args, int idx)
+{
+ return (args.size() > idx) ? args[idx].toString(exec).qstring() : QString::null;
+}
+
+} // namespace KJSEmbed::Bindings
+} // namespace KJSEmbed
+
+#include <kgenericfactory.h>
+typedef KGenericFactory<KJSEmbed::Bindings::MyCustomObjectLoader> MyCustomObjectLoaderFactory;
+K_EXPORT_COMPONENT_FACTORY( libcustomobjectplugin, MyCustomObjectLoaderFactory( "MyCustomObjectLoader" ) )
diff --git a/kjsembed/plugins/customobject_plugin.desktop b/kjsembed/plugins/customobject_plugin.desktop
new file mode 100644
index 00000000..129e8639
--- /dev/null
+++ b/kjsembed/plugins/customobject_plugin.desktop
@@ -0,0 +1,5 @@
+[Desktop Entry]
+Name=MyCustomObject
+ServiceTypes=JSBindingPlugin/Binding
+Type=Service
+X-KDE-Library=libcustomobjectplugin
diff --git a/kjsembed/plugins/customobject_plugin.h b/kjsembed/plugins/customobject_plugin.h
new file mode 100644
index 00000000..2cea3415
--- /dev/null
+++ b/kjsembed/plugins/customobject_plugin.h
@@ -0,0 +1,68 @@
+// -*- c++ -*-
+
+/*
+ * Copyright (C) 2003, Richard J. Moore <rich@kde.org>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KJSEMBED_CUSTOMOBJECT_PLUGIN_H
+#define KJSEMBED_CUSTOMOBJECT_PLUGIN_H
+
+#include <kjsembed/jsbindingplugin.h>
+#include <kjsembed/jsproxy_imp.h>
+
+namespace KJSEmbed {
+namespace Bindings {
+
+class KJSEMBED_EXPORT MyCustomObjectLoader : public JSBindingPlugin
+{
+public:
+ MyCustomObjectLoader( QObject *parent, const char *name, const QStringList &args );
+ KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const;
+};
+
+
+class MyCustomObjectImp : public JSProxyImp {
+
+ /** Identifiers for the methods provided by this class. */
+ enum MethodId { Methodmode, MethodsetMode, Methodthing, MethodsetThing };
+
+public:
+ MyCustomObjectImp( KJS::ExecState *exec, int id );
+ virtual ~MyCustomObjectImp();
+
+ static void addBindings( KJS::ExecState *exec, KJS::Object &object );
+
+ /** Returns true iff this object implements the call function. */
+ virtual bool implementsCall() const {
+ return true;
+ }
+
+ /** Invokes the call function. */
+ virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args );
+
+
+private:
+ int extractInt( KJS::ExecState *exec, const KJS::List &args, int idx);
+ QString extractString(KJS::ExecState *exec, const KJS::List &args, int idx);
+ int mid;
+};
+
+} // namespace
+} // namespace
+
+#endif // KJSEMBED_IMAGE_IMP_H
diff --git a/kjsembed/plugins/customqobject_plugin.cpp b/kjsembed/plugins/customqobject_plugin.cpp
new file mode 100644
index 00000000..f8c45a60
--- /dev/null
+++ b/kjsembed/plugins/customqobject_plugin.cpp
@@ -0,0 +1,96 @@
+// -*- c++ -*-
+
+/*
+ * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <kdebug.h>
+#include <kjsembed/jsobjectproxy.h>
+#include <kjsembed/jsbinding.h>
+#include <kjsembed/kjsembedpart.h>
+#include <kjsembed/customobject_imp.h>
+#include <qvariant.h>
+
+
+#include "customqobject_plugin.h"
+
+namespace KJSEmbed {
+namespace Bindings {
+
+MyCustomQObjectLoader::MyCustomQObjectLoader( QObject *parent, const char *name, const QStringList &args ) :
+ JSBindingPlugin(parent, name, args)
+{
+}
+
+KJS::Object MyCustomQObjectLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const
+{
+ kdDebug() << "Loading a custom object" << endl;
+
+ QObject *parent = 0L;
+ JSObjectProxy *proxy = JSProxy::toObjectProxy( args[0].imp() );
+ if ( proxy )
+ parent = proxy->object();
+ MyCustomQObjectImp *imp = new MyCustomQObjectImp(parent, "MyCustomQObject" );
+ JSObjectProxy *prx = new JSObjectProxy( jspart, imp );
+
+ KJS::Object proxyObj( prx );
+ prx->addBindings( exec, proxyObj );
+ CustomObjectImp::addBindings( exec, proxyObj );
+ return proxyObj;
+}
+
+MyCustomQObjectImp::MyCustomQObjectImp(QObject *parent, const char *name )
+ : QObject(parent, name)
+{
+ kdDebug() << "New MyCustomQObjectImp " << endl;
+}
+
+MyCustomQObjectImp::~MyCustomQObjectImp()
+{
+}
+
+MyCustomQObjectImp::Mode MyCustomQObjectImp::mode() const
+{
+ kdDebug() << "mode() " << endl;
+ return m_mode;
+}
+void MyCustomQObjectImp::setMode( Mode md)
+{
+ kdDebug() << "setMode() " << endl;
+ m_mode = md;
+}
+QString MyCustomQObjectImp::thing() const
+{
+ kdDebug() << "thing()" << endl;
+ return m_thing;
+}
+void MyCustomQObjectImp::setThing( const QString &t)
+{
+ kdDebug() << "setThing() " << t << endl;
+ m_thing = t;
+}
+} // namespace KJSEmbed::Bindings
+} // namespace KJSEmbed
+
+
+#include <kgenericfactory.h>
+typedef KGenericFactory<KJSEmbed::Bindings::MyCustomQObjectLoader> MyCustomQObjectLoaderFactory;
+K_EXPORT_COMPONENT_FACTORY( libcustomqobjectplugin, MyCustomQObjectLoaderFactory( "MyCustomQObjectLoader" ) )
+
+
+#include "customqobject_plugin.moc"
diff --git a/kjsembed/plugins/customqobject_plugin.desktop b/kjsembed/plugins/customqobject_plugin.desktop
new file mode 100644
index 00000000..6be09b1b
--- /dev/null
+++ b/kjsembed/plugins/customqobject_plugin.desktop
@@ -0,0 +1,5 @@
+[Desktop Entry]
+Name=MyCustomQObject
+ServiceTypes=JSBindingPlugin/Binding
+Type=Service
+X-KDE-Library=libcustomqobjectplugin
diff --git a/kjsembed/plugins/customqobject_plugin.h b/kjsembed/plugins/customqobject_plugin.h
new file mode 100644
index 00000000..bd419b59
--- /dev/null
+++ b/kjsembed/plugins/customqobject_plugin.h
@@ -0,0 +1,68 @@
+// -*- c++ -*-
+
+/*
+ * Copyright (C) 2003, Richard J. Moore <rich@kde.org>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KJSEMBED_CUSTOMQOBJECT_PLUGIN_H
+#define KJSEMBED_CUSTOMQOBJECT_PLUGIN_H
+
+#include <kjsembed/jsbindingplugin.h>
+#include <kjsembed/jsproxy_imp.h>
+#include <qobject.h>
+
+namespace KJSEmbed {
+namespace Bindings {
+
+class MyCustomQObjectLoader : public JSBindingPlugin
+{
+public:
+ MyCustomQObjectLoader( QObject *parent, const char *name, const QStringList &args );
+ virtual ~MyCustomQObjectLoader(){;}
+ KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const;
+};
+
+
+class MyCustomQObjectImp : public QObject {
+
+Q_OBJECT
+
+ /** Identifiers for the methods provided by this class. */
+ enum Mode { On, Off };
+ Q_PROPERTY(Mode mode READ mode WRITE setMode)
+ Q_PROPERTY(QString thing READ thing WRITE setThing)
+ Q_ENUMS(Mode)
+public:
+ MyCustomQObjectImp( QObject *parent, const char *name);
+ virtual ~MyCustomQObjectImp();
+
+public slots:
+ Mode mode() const;
+ void setMode( Mode md);
+ QString thing() const;
+ void setThing( const QString &t);
+private:
+ Mode m_mode;
+ QString m_thing;
+
+};
+
+} // namespace
+} // namespace
+
+#endif // KJSEMBED_IMAGE_IMP_H
diff --git a/kjsembed/plugins/imagefx_plugin.cpp b/kjsembed/plugins/imagefx_plugin.cpp
new file mode 100644
index 00000000..903c7655
--- /dev/null
+++ b/kjsembed/plugins/imagefx_plugin.cpp
@@ -0,0 +1,858 @@
+// -*- c++ -*-
+
+/*
+ * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <kdebug.h>
+#include <kglobal.h>
+#include <kjsembed/jsopaqueproxy.h>
+#include <kjsembed/jsbinding.h>
+#include <kjsembed/jsfactory.h>
+#include <kjsembed/jsfactory_imp.h>
+#include <kjsembed/kjsembedpart.h>
+#include <kjsembed/customobject_imp.h>
+#include <qvariant.h>
+#include <qbrush.h>
+
+#include "imagefx_plugin.h"
+
+namespace KJSEmbed {
+namespace Bindings {
+
+
+ImageFXLoader::ImageFXLoader( QObject *parent, const char *name, const QStringList &args ) :
+ JSBindingPlugin(parent, name, args)
+{
+}
+
+KJS::Object ImageFXLoader::createBinding(KJSEmbedPart */*jspart*/, KJS::ExecState *exec, const KJS::List &/*args*/) const
+{
+ kdDebug() << "Loading a ImageFX object" << endl;
+ JSOpaqueProxy *prx = new JSOpaqueProxy( (int*)0, "ImageFX" );
+
+ KJS::Object proxyObj(prx);
+ ImageFX::addBindings( exec, proxyObj );
+ return proxyObj;
+}
+
+ImageFX::ImageFX( KJS::ExecState *exec, int id )
+ : JSProxyImp(exec), mid(id)
+{
+}
+
+ImageFX::~ImageFX()
+{
+}
+
+void ImageFX::addBindings( KJS::ExecState *exec, KJS::Object &object ) {
+
+ kdDebug() << "ImageFX::addBindings()" << endl;
+ JSOpaqueProxy *op = JSProxy::toOpaqueProxy( object.imp() );
+ if ( !op ) {
+ kdWarning() << "ImageFX::addBindings() failed, not a JSOpaqueProxy" << endl;
+ return;
+ }
+
+ if ( op->typeName() != "ImageFX" ) {
+ kdWarning() << "ImageFX::addBindings() failed, type is " << op->typeName() << endl;
+ return;
+ }
+
+ JSProxy::MethodTable methods[] = {
+ { Methodgradient, "gradient" },
+ { MethodunbalancedGradient, "unbalancedGradient" },
+ { MethodblendColor, "blendColor" },
+ { MethodblendImage, "blendImage" },
+ { MethodcomputeDestinationRect, "computeDestinationRect" },
+ { MethodchannelIntensity, "channelIntensity" },
+ { Methodfade, "fade" },
+ { Methodflatten, "flatten" },
+ { Methodhash, "hash" },
+ { Methodintensity, "intensity" },
+ { Methodmodulate, "modulate" },
+ { MethodtoGray, "toGray" },
+ { Methoddesaturate, "desaturate" },
+ { Methoddither, "dither" },
+ { MethodselectedImage, "selectedImage" },
+ { MethodcontrastHSV, "contrastHSV" },
+ { Methodnormalize, "normalize" },
+ { Methodequalize, "equalize" },
+ { Methodthreshold, "threshold" },
+ { Methodsolarize, "solarize" },
+ { Methodemboss, "emboss" },
+ { Methoddespeckle, "despeckle" },
+ { Methodcharcoal, "charcoal" },
+ { Methodcharcoal2, "charcoal2" },
+ { Methodrotate, "rotate" },
+ { Methodsample, "sample" },
+ { MethodaddNoise, "addNoise" },
+ { Methodblur, "blur" },
+ { Methodedge, "edge" },
+ { Methodimplode, "implode" },
+ { MethodoilPaintConvolve, "oilPaintConvolve" },
+ { MethodoilPaint, "MethodoilPaint" },
+ { Methodsharpen, "sharpen" },
+ { Methodsharpen2, "sharpen2" },
+ { Methodspread, "spread" },
+ { Methodshade, "shade" },
+ { Methodswirl, "swirl" },
+ { Methodwave, "wave" },
+ { Methodcontrast, "contrast" },
+ { MethodbumpMap, "bumpmap" },
+ { 0, 0 }
+ };
+
+ int idx = 0;
+ do {
+ ImageFX *meth = new ImageFX( exec, methods[idx].id );
+ object.put( exec , methods[idx].name, KJS::Object(meth) );
+ ++idx;
+ } while( methods[idx].id );
+
+ //
+ // Define the enum constants
+ //
+ struct EnumValue {
+ const char *id;
+ int val;
+ };
+
+ EnumValue enums[] = {
+ // GradiantType
+ { "VerticalGradient", 0 },
+ { "HorizontalGradient", 1 },
+ { "DiagonalGradient", 2 },
+ { "CrossDiagonalGradient", 3 },
+ { "PyramidGradient", 4 },
+ { "RectangleGradient", 5 },
+ { "PipeCrossGradient", 6 },
+ { "EllipticGradient", 7 },
+ // RGBComponent
+ { "Red", 0 },
+ { "Green", 1 },
+ { "Blue", 2 },
+ { "Gray", 3 },
+ { "All", 4 },
+ // Lighting
+ { "NorthLite", 0 },
+ { "NWLite", 1 },
+ { "WestLite", 2 },
+ { "SWLite", 3 },
+ { "SouthLite", 4 },
+ { "SELite", 5 },
+ { "EastLite", 6 },
+ { "NELite", 7 },
+ // ModulationType
+ { "Intensity", 0 },
+ { "Saturation", 1 },
+ { "HueShift", 2 },
+ { "Contrast", 3 },
+ // NoiseType
+ { "UniformNoise", 0 },
+ { "GaussianNoise", 1 },
+ { "MultiplicativeGaussianNoise", 2 },
+ { "ImpulseNoise", 3 },
+ { "LaplacianNoise", 4 },
+ { "PoissonNoise", 5 },
+ // RotateDirection
+ { "Rotate90", 0 },
+ { "Rotate180", 1 },
+ { "Rotate270", 2 },
+ // BumpmapType
+ { "Linear", 0},
+ { "Spherical", 1},
+ { "Sinuosidal", 2},
+ { 0, 0 }
+ };
+
+ int enumidx = 0;
+ do {
+ object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly );
+ ++enumidx;
+ } while( enums[enumidx].id );
+}
+
+KJS::Value ImageFX::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) {
+
+ kdDebug() << "ImageFX::call() " << mid << endl;
+ JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() );
+ if ( !op ) {
+ kdWarning() << "ImageFX::call() failed, not a JSOpaqueProxy" << endl;
+ return KJS::Value();
+ }
+
+ if ( op->typeName() != "ImageFX" ) {
+ kdWarning() << "ImageFX::call() failed, type is " << op->typeName() << endl;
+ return KJS::Value();
+ }
+
+
+ KJS::Value retValue = KJS::Value();
+ switch ( mid ) {
+ case Methodgradient: {
+ QSize size = extractQSize(exec, args, 0);
+ QColor ca = extractQColor(exec, args, 1);
+ QColor cb = extractQColor(exec, args, 2);
+ int type = extractInt( exec, args, 3);
+ int ncols = extractInt( exec, args, 4);
+ QImage img = KImageEffect::gradient(size, ca, cb, (KImageEffect::GradientType)type, ncols);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case MethodunbalancedGradient: {
+ QSize size = extractQSize(exec, args, 0);
+ QColor ca = extractQColor(exec, args, 1);
+ QColor cb = extractQColor(exec, args, 2);
+ int type = extractInt( exec, args, 3);
+ int xfactor = extractInt( exec, args, 4);
+ int yfactor = extractInt( exec, args, 5);
+ int ncols = extractInt( exec, args, 6);
+ QImage img = KImageEffect::unbalancedGradient(size, ca, cb, (KImageEffect::GradientType)type, xfactor, yfactor, ncols);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case MethodblendColor: {
+ QColor clr = extractQColor(exec, args, 0);
+ QImage dst = extractQImage(exec, args, 1);
+ float opacity = (float)extractDouble(exec, args, 2);
+ QImage img = KImageEffect::blend(clr, dst, opacity);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case MethodblendImage: {
+ QImage src = extractQImage(exec, args, 0);
+ QImage dst = extractQImage(exec, args, 1);
+ float opacity = (float)extractDouble(exec, args, 2);
+ QImage img = KImageEffect::blend(src, dst, opacity);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case MethodcomputeDestinationRect: {
+ QSize lowerSize = extractQSize(exec, args, 0);
+ int disposition = extractInt(exec, args, 1);
+ QImage upper = extractQImage(exec, args, 2);
+ QRect rect = KImageEffect::computeDestinationRect(lowerSize, (KImageEffect::Disposition) disposition, upper);
+ retValue = convertToValue(exec, rect);
+ break;
+ }
+ case MethodchannelIntensity: {
+ QImage image = extractQImage(exec, args, 0);
+ float percent = (float)extractDouble(exec, args, 1);
+ int channel = extractInt(exec, args, 2);
+ QImage img = KImageEffect::channelIntensity(image, percent, (KImageEffect::RGBComponent)channel);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodfade: {
+ QImage image = extractQImage(exec, args, 0);
+ float val = (float)extractDouble(exec, args, 1);
+ QColor color = extractQColor(exec, args, 2);
+ QImage img = KImageEffect::fade(image, val, color);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodflatten: {
+ QImage image = extractQImage(exec, args, 0);
+ QColor ca = extractQColor(exec, args, 1);
+ QColor cb = extractQColor(exec, args, 2);
+ int ncols = extractInt(exec, args, 3);
+ QImage img = KImageEffect::flatten(image, ca, cb, ncols);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodhash: {
+
+ QImage image = extractQImage(exec, args, 0);
+ int lite = extractInt(exec, args, 1);
+ int spacing = extractInt(exec, args, 2);
+ QImage img = KImageEffect::hash(image, (KImageEffect::Lighting)lite, spacing);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodintensity: {
+
+ QImage image = extractQImage(exec, args, 0);
+ float percent = (float)extractDouble(exec, args, 1);
+ QImage img = KImageEffect::intensity(image, percent);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodmodulate: {
+ QImage image = extractQImage(exec, args, 0);
+ QImage modImage = extractQImage(exec, args, 0);
+ bool reverse = extractBool(exec, args, 1);
+ int type = extractInt(exec, args, 2);
+ int factor = extractInt(exec, args, 3);
+ int channel = extractInt(exec, args, 4);
+ QImage img = KImageEffect::modulate(image, modImage, reverse, (KImageEffect::ModulationType)type, factor, (KImageEffect::RGBComponent)channel);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+
+ case MethodtoGray: {
+ QImage image = extractQImage(exec, args, 0);
+ bool fast = extractBool(exec, args, 1);
+ QImage img = KImageEffect::toGray(image, fast);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methoddesaturate: {
+ QImage image = extractQImage(exec, args, 0);
+ float desat = (float)extractDouble(exec, args, 1);
+ QImage img = KImageEffect::desaturate(image, desat);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methoddither: {
+
+ //dither( palette, size)
+ break;
+ }
+ case MethodselectedImage: {
+
+ QImage image = extractQImage(exec, args, 0);
+ QColor col = extractQColor(exec, args, 1);
+ QImage img = KImageEffect::selectedImage(image, col);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case MethodcontrastHSV: {
+ QImage image = extractQImage(exec, args, 0);
+ bool sharpen = extractBool(exec, args, 1);
+ KImageEffect::contrastHSV(image, sharpen);
+ retValue = convertToValue(exec, image);
+ break;
+ }
+ case Methodnormalize: {
+ QImage image = extractQImage(exec, args, 0);
+ KImageEffect::normalize(image);
+ retValue = convertToValue(exec, image);
+ break;
+ }
+ case Methodequalize: {
+ QImage image = extractQImage(exec, args, 0);
+ KImageEffect::equalize(image);
+ retValue = convertToValue(exec, image);
+ break;
+ }
+ case Methodthreshold: {
+ QImage image = extractQImage(exec, args, 0);
+ uint value = extractUInt(exec, args, 1);
+ KImageEffect::threshold(image, value);
+ retValue = convertToValue(exec, image);
+ break;
+ }
+ case Methodsolarize: {
+ QImage image = extractQImage(exec, args, 0);
+ double factor = extractDouble(exec, args, 1);
+ KImageEffect::solarize(image, factor);
+ retValue = convertToValue(exec, image);
+ break;
+ }
+ case Methodemboss: {
+ QImage image = extractQImage(exec, args, 0);
+ double radius = extractDouble(exec, args, 1);
+ double sigma = extractDouble(exec, args, 2);
+ QImage img = KImageEffect::emboss(image, radius, sigma);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methoddespeckle: {
+ QImage image = extractQImage(exec, args, 0);
+ QImage img = KImageEffect::despeckle(image);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodcharcoal: {
+ QImage image = extractQImage(exec, args, 0);
+ double factor = extractDouble(exec, args, 1);
+ QImage img = KImageEffect::charcoal( image, factor);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodcharcoal2: {
+ QImage image = extractQImage(exec, args, 0);
+ double radius = extractDouble(exec, args, 1);
+ double sigma = extractDouble(exec, args, 2);
+ QImage img = KImageEffect::charcoal(image, radius, sigma);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodrotate: {
+ QImage image = extractQImage(exec, args, 0);
+ int r = extractInt(exec, args, 1);
+ QImage img = KImageEffect::rotate(image, (KImageEffect::RotateDirection) r);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodsample: {
+ QImage image = extractQImage(exec, args, 0);
+ int width = extractInt(exec, args, 1);
+ int height = extractInt(exec, args, 2);
+ QImage img = KImageEffect::sample(image, width, height);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case MethodaddNoise: {
+ QImage image = extractQImage(exec, args, 0);
+ int type = extractInt(exec, args, 1);
+ QImage img = KImageEffect::addNoise(image, (KImageEffect::NoiseType) type);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodblur: {
+ QImage image = extractQImage(exec, args, 0);
+ double radius = extractDouble(exec, args, 1);
+ double sigma = extractDouble(exec, args, 2);
+ QImage img = KImageEffect::blur(image, radius, sigma);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodedge: {
+ QImage image = extractQImage(exec, args, 0);
+ double radius = extractDouble(exec, args, 1);
+ QImage img = KImageEffect::edge(image, radius);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodimplode: {
+ QImage image = extractQImage(exec, args, 0);
+ double factor = extractDouble(exec, args, 1);
+ uint background = extractUInt(exec, args, 2);
+ QImage img = KImageEffect::implode(image, factor, background);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case MethodoilPaintConvolve: {
+ QImage image = extractQImage(exec, args, 0);
+ double radius = extractDouble(exec, args, 1);
+ QImage img = KImageEffect::oilPaintConvolve(image, radius);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case MethodoilPaint: {
+ QImage image = extractQImage(exec, args, 0);
+ int radius = extractInt(exec, args, 1);
+ QImage img = KImageEffect::oilPaint(image, radius);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+
+
+ case Methodsharpen: {
+ QImage image = extractQImage(exec, args, 0);
+ double factor = extractDouble(exec, args, 1);
+ QImage img = KImageEffect::sharpen(image, factor);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodsharpen2: {
+ QImage image = extractQImage(exec, args, 0);
+ double radius = extractDouble(exec, args, 1);
+ double sigma = extractDouble(exec, args, 2);
+ QImage img = KImageEffect::sharpen(image, radius, sigma);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodspread: {
+ QImage image = extractQImage(exec, args, 0);
+ uint amount = extractUInt(exec, args, 1);
+ QImage img = KImageEffect::spread(image, amount);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodshade: {
+ QImage image = extractQImage(exec, args, 0);
+ bool color_shading = extractBool(exec, args, 1);
+ double azimuth = extractDouble(exec, args, 2);
+ double elevation = extractDouble(exec, args, 3);
+ QImage img = KImageEffect::shade(image, color_shading, azimuth, elevation);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodswirl: {
+ QImage image = extractQImage(exec, args, 0);
+ double degrees = extractDouble(exec, args, 1);
+ uint background = extractUInt(exec, args, 2);
+ QImage img = KImageEffect::swirl(image, degrees, background);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodwave: {
+ QImage image = extractQImage(exec, args, 0);
+ double amplitude = extractDouble(exec, args, 1);
+ double frequency = extractDouble(exec, args, 2);
+ uint background = extractUInt(exec, args, 3);
+ QImage img = KImageEffect::wave(image, amplitude, frequency, background);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case Methodcontrast: {
+ QImage image = extractQImage(exec, args, 0);
+ int c = extractInt(exec, args, 1);
+ QImage img = KImageEffect::contrast(image, c);
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ case MethodbumpMap: {
+ QImage mask = extractQImage(exec, args, 0);
+ QImage img = bumpmap(img,
+ mask,
+ extractDouble(exec, args, 1),
+ extractDouble(exec, args, 2),
+ extractInt(exec, args, 3),
+ extractInt(exec, args, 4),
+ extractInt(exec, args, 5),
+ extractInt(exec, args, 6),
+ extractInt(exec, args, 7),
+ extractBool(exec, args, 8),
+ extractBool(exec, args, 9),
+ (BumpmapType) extractInt(exec, args, 10),
+ extractBool(exec, args, 11));
+
+ retValue = convertToValue(exec, img);
+ break;
+ }
+ default:
+ kdWarning() << "ImageFX has no method " << mid << endl;
+ break;
+ }
+
+ return retValue;
+}
+
+/***********************************************************************
+ * Here's a pretty fast bumpmap implementation.
+ * NOTE: remind me to move it to KImageEffects after 3.2.
+ */
+#define DegreesToRadians(x) ((x)*M_PI/180.0)
+#define MOD(x, y) ((x) < 0 ? ((y) - 1 - ((y) - 1 - (x)) % (y)) : (x) % (y))
+
+/**
+ * NOTE: kclamp needs to be moved to kglobals.h along kmin and kmax
+ */
+#define KCLAMP(x,low,high) kClamp(x,low,high)
+template<class T>
+inline const T& kClamp( const T& x, const T& low, const T& high )
+{
+ if ( x < low )
+ return low;
+ else if ( x > high )
+ return high;
+ else
+ return x;
+}
+
+static inline unsigned int intensityValue( unsigned int color ) {
+ return (unsigned int)( (0.299*qRed( color ) +
+ 0.587*qGreen( color ) +
+ 0.1140000000000001*qBlue( color ) ) );
+}
+
+struct BumpmapParams {
+ BumpmapParams( double bm_azimuth, double bm_elevation,
+ int bm_depth, BumpmapType bm_type,
+ bool invert ) {
+ /* Convert to radians */
+ double azimuth = DegreesToRadians( bm_azimuth );
+ double elevation = DegreesToRadians( bm_elevation );
+
+ /* Calculate the light vector */
+ lx = (int)( cos(azimuth) * cos(elevation) * 255.0 );
+ ly = (int)( sin(azimuth) * cos(elevation) * 255.0 );
+ int lz = (int)( sin(elevation) * 255.0 );
+
+ /* Calculate constant Z component of surface normal */
+ int nz = (6 * 255) / bm_depth;
+ nz2 = nz * nz;
+ nzlz = nz * lz;
+
+ /* Optimize for vertical normals */
+ background = lz;
+
+ /* Calculate darkness compensation factor */
+ compensation = sin(elevation);
+
+ /* Create look-up table for map type */
+ for (int i = 0; i < 256; i++)
+ {
+ double n = 0;
+ switch (bm_type)
+ {
+ case Spherical:
+ n = i / 255.0 - 1.0;
+ lut[i] = (int) (255.0 * sqrt(1.0 - n * n) + 0.5);
+ break;
+
+ case Sinuosidal:
+ n = i / 255.0;
+ lut[i] = (int) (255.0 * (sin((-M_PI / 2.0) + M_PI * n) + 1.0) /
+ 2.0 + 0.5);
+ break;
+
+ case Linear:
+ default:
+ lut[i] = i;
+ }
+
+ if (invert)
+ lut[i] = 255 - lut[i];
+ }
+ }
+ int lx, ly;
+ int nz2, nzlz;
+ int background;
+ double compensation;
+ uchar lut[256];
+};
+
+
+static void bumpmap_convert_row( uint *row,
+ int width,
+ int bpp,
+ int has_alpha,
+ uchar *lut,
+ int waterlevel )
+{
+ uint *p;
+
+ p = row;
+
+ has_alpha = has_alpha ? 1 : 0;
+
+ if (bpp >= 3)
+ for (; width; width--)
+ {
+ if (has_alpha) {
+ unsigned int idx = (unsigned int)(intensityValue( *row ) + 0.5);
+ *p++ = lut[(unsigned int) ( waterlevel +
+ ( ( idx -
+ waterlevel) * qBlue( *row )) / 255.0 )];
+ } else {
+ unsigned int idx = (unsigned int)(intensityValue( *row ) + 0.5);
+ *p++ = lut[idx];
+ }
+
+ ++row;
+ }
+}
+
+static void bumpmap_row( uint *src,
+ uint *dest,
+ int width,
+ int bpp,
+ int has_alpha,
+ uint *bm_row1,
+ uint *bm_row2,
+ uint *bm_row3,
+ int bm_width,
+ int bm_xofs,
+ bool tiled,
+ bool row_in_bumpmap,
+ int ambient,
+ bool compensate,
+ BumpmapParams *params )
+{
+ int xofs1, xofs2, xofs3;
+ int shade;
+ int ndotl;
+ int nx, ny;
+ int x;
+ int pbpp;
+ int tmp;
+
+ if (has_alpha)
+ pbpp = bpp - 1;
+ else
+ pbpp = bpp;
+
+ tmp = bm_xofs;
+ xofs2 = MOD(tmp, bm_width);
+
+ for (x = 0; x < width; x++)
+ {
+ /* Calculate surface normal from bump map */
+
+ if (tiled || (row_in_bumpmap &&
+ x >= - tmp && x < - tmp + bm_width)) {
+ if (tiled) {
+ xofs1 = MOD(xofs2 - 1, bm_width);
+ xofs3 = MOD(xofs2 + 1, bm_width);
+ } else {
+ xofs1 = KCLAMP(xofs2 - 1, 0, bm_width - 1);
+ xofs3 = KCLAMP(xofs2 + 1, 0, bm_width - 1);
+ }
+ nx = (bm_row1[xofs1] + bm_row2[xofs1] + bm_row3[xofs1] -
+ bm_row1[xofs3] - bm_row2[xofs3] - bm_row3[xofs3]);
+ ny = (bm_row3[xofs1] + bm_row3[xofs2] + bm_row3[xofs3] -
+ bm_row1[xofs1] - bm_row1[xofs2] - bm_row1[xofs3]);
+ } else {
+ nx = ny = 0;
+ }
+
+ /* Shade */
+
+ if ((nx == 0) && (ny == 0))
+ shade = params->background;
+ else {
+ ndotl = nx * params->lx + ny * params->ly + params->nzlz;
+
+ if (ndotl < 0)
+ shade = (int)( params->compensation * ambient );
+ else {
+ shade = (int)( ndotl / sqrt(nx * nx + ny * ny + params->nz2) );
+
+ shade = (int)( shade + KMAX(0.0, (255 * params->compensation - shade)) *
+ ambient / 255 );
+ }
+ }
+
+ /* Paint */
+
+ /**
+ * NOTE: if we want to work with non-32bit images the alpha handling would
+ * also change
+ */
+ if (compensate) {
+ int red = (int)((qRed( *src ) * shade) / (params->compensation * 255));
+ int green = (int)((qGreen( *src ) * shade) / (params->compensation * 255));
+ int blue = (int)((qBlue( *src ) * shade) / (params->compensation * 255));
+ int alpha = (int)((qAlpha( *src ) * shade) / (params->compensation * 255));
+ ++src;
+ *dest++ = qRgba( red, green, blue, alpha );
+ } else {
+ int red = qRed( *src ) * shade / 255;
+ int green = qGreen( *src ) * shade / 255;
+ int blue = qBlue( *src ) * shade / 255;
+ int alpha = qAlpha( *src ) * shade / 255;
+ ++src;
+ *dest++ = qRgba( red, green, blue, alpha );
+ }
+
+ /* Next pixel */
+
+ if (++xofs2 == bm_width)
+ xofs2 = 0;
+ }
+}
+
+/**
+ * A bumpmapping algorithm.
+ *
+ * @param img the image you want bumpmap
+ * @param map the map used
+ * @param azimuth azimuth
+ * @param elevation elevation
+ * @param depth depth (not the depth of the image, but of the map)
+ * @param xofs X offset
+ * @param yofs Y offset
+ * @param waterlevel level that full transparency should represent
+ * @param ambient ambient lighting factor
+ * @param compensate compensate for darkening
+ * @param invert invert bumpmap
+ * @param type type of the bumpmap
+ *
+ * @return The destination image (dst) containing the result.
+ * @author Zack Rusin <zack@kde.org>
+ */
+QImage ImageFX::bumpmap(QImage &img, QImage &map, double azimuth, double elevation,
+ int depth, int xofs, int yofs, int waterlevel,
+ int ambient, bool compensate, bool invert,
+ BumpmapType type, bool tiled)
+{
+ QImage dst;
+
+ if ( img.depth() != 32 || img.depth() != 32 ) {
+ qWarning( "Bump-mapping effect works only with 32 bit images");
+ return dst;
+ }
+
+ dst.create( img.width(), img.height(), img.depth() );
+ int bm_width = map.width();
+ int bm_height = map.height();
+ int bm_bpp = map.depth();
+ int bm_has_alpha = map.hasAlphaBuffer();
+
+ int yofs1, yofs2, yofs3;
+
+ if ( tiled ) {
+ yofs2 = MOD( yofs, bm_height );
+ yofs1 = MOD( yofs2 - 1, bm_height);
+ yofs3 = MOD( yofs2 + 1, bm_height);
+ } else {
+ yofs1 = 0;
+ yofs2 = 0;
+ yofs3 = KCLAMP( yofs2+1, 0, bm_height - 1 );
+ }
+
+ BumpmapParams params( azimuth, elevation, depth, type, invert );
+
+ uint* bm_row1 = (unsigned int*)map.scanLine( yofs1 );
+ uint* bm_row2 = (unsigned int*)map.scanLine( yofs2 );
+ uint* bm_row3 = (unsigned int*)map.scanLine( yofs3 );
+
+ bumpmap_convert_row( bm_row1, bm_width, bm_bpp, bm_has_alpha, params.lut, waterlevel );
+ bumpmap_convert_row( bm_row2, bm_width, bm_bpp, bm_has_alpha, params.lut, waterlevel );
+ bumpmap_convert_row( bm_row3, bm_width, bm_bpp, bm_has_alpha, params.lut, waterlevel );
+
+ for (int y = 0; y < img.height(); ++y)
+ {
+ int row_in_bumpmap = (y >= - yofs && y < - yofs + bm_height);
+
+ uint* src_row = (unsigned int*)img.scanLine( y );
+ uint* dest_row = (unsigned int*)dst.scanLine( y );
+
+ bumpmap_row( src_row, dest_row, img.width(), img.depth(), img.hasAlphaBuffer(),
+ bm_row1, bm_row2, bm_row3, bm_width, xofs,
+ tiled,
+ row_in_bumpmap, ambient, compensate,
+ &params );
+
+ /* Next line */
+
+ if (tiled || row_in_bumpmap)
+ {
+ uint* bm_tmprow = bm_row1;
+ bm_row1 = bm_row2;
+ bm_row2 = bm_row3;
+ bm_row3 = bm_tmprow;
+
+ if (++yofs2 == bm_height)
+ yofs2 = 0;
+
+ if (tiled)
+ yofs3 = MOD(yofs2 + 1, bm_height);
+ else
+ yofs3 = KCLAMP(yofs2 + 1, 0, bm_height - 1);
+
+ bm_row3 = (unsigned int*)map.scanLine( yofs3 );
+ bumpmap_convert_row( bm_row3, bm_width, bm_bpp, bm_has_alpha,
+ params.lut, waterlevel );
+ }
+ }
+ return dst;
+}
+
+
+} // namespace KJSEmbed::Bindings
+} // namespace KJSEmbed
+
+#include <kgenericfactory.h>
+typedef KGenericFactory<KJSEmbed::Bindings::ImageFXLoader> ImageFXLoaderFactory;
+K_EXPORT_COMPONENT_FACTORY( libimagefxplugin, ImageFXLoaderFactory( "ImageFXLoader" ) )
diff --git a/kjsembed/plugins/imagefx_plugin.desktop b/kjsembed/plugins/imagefx_plugin.desktop
new file mode 100644
index 00000000..36921e3b
--- /dev/null
+++ b/kjsembed/plugins/imagefx_plugin.desktop
@@ -0,0 +1,5 @@
+[Desktop Entry]
+Name=ImageFX
+ServiceTypes=JSBindingPlugin/Binding
+Type=Service
+X-KDE-Library=libimagefxplugin
diff --git a/kjsembed/plugins/imagefx_plugin.h b/kjsembed/plugins/imagefx_plugin.h
new file mode 100644
index 00000000..7acfed44
--- /dev/null
+++ b/kjsembed/plugins/imagefx_plugin.h
@@ -0,0 +1,130 @@
+// -*- c++ -*-
+
+/*
+ * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KJSEMBED_IMAGEFX_PLUGIN_H
+#define KJSEMBED_IMAGEFX_PLUGIN_H
+
+#include <kjsembed/jsbindingplugin.h>
+#include <kjsembed/jsproxy_imp.h>
+#include <kimageeffect.h>
+
+#include <qimage.h>
+
+namespace KJSEmbed {
+namespace Bindings {
+
+class ImageFXLoader : public JSBindingPlugin
+{
+public:
+ ImageFXLoader( QObject *parent, const char *name, const QStringList &args );
+ KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const;
+};
+enum BumpmapType {
+Linear,
+Spherical,
+Sinuosidal
+};
+
+class ImageFX : JSProxyImp
+{
+
+ /** Identifiers for the methods provided by this class. */
+ enum MethodId {
+ // Image effects
+ Methodgradient,
+ MethodunbalancedGradient, MethodblendColor,MethodblendImage,
+ MethodcomputeDestinationRect, MethodchannelIntensity, Methodfade,
+ Methodflatten, Methodhash, Methodintensity, Methodmodulate, MethodtoGray,
+ Methoddesaturate, Methoddither, MethodselectedImage, MethodcontrastHSV,
+ Methodnormalize, Methodequalize, Methodthreshold, Methodsolarize,
+ Methodemboss, Methoddespeckle, Methodcharcoal, Methodcharcoal2,
+ Methodrotate, Methodsample, MethodaddNoise, Methodblur, Methodedge,
+ Methodimplode, MethodoilPaintConvolve, MethodoilPaint, Methodsharpen,
+ Methodsharpen2, Methodspread, Methodshade, Methodswirl, Methodwave,
+ Methodcontrast, MethodbumpMap
+ };
+
+ public:
+ ImageFX( KJS::ExecState *exec, int id );
+ virtual ~ImageFX();
+
+ static void addBindings( KJS::ExecState *exec, KJS::Object &object );
+
+ /** Returns true iff this object implements the call function. */
+ virtual bool implementsCall() const { return true; }
+
+ /** Invokes the call function. */
+ virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args );
+
+ private:
+ // Image effects
+ void gradient(const QSize &size, const QColor &ca, const QColor &cb, KImageEffect::GradientType type, int ncols);
+ void unbalancedGradient(const QSize &size, const QColor &ca,const QColor &cb, KImageEffect::GradientType type, int xfactor,int yfactor, int ncols);
+ void blendColor(const QColor& clr, float opacity);
+ void blendImage(QImage& blendImage, float opacity);
+ QRect computeDestinationRect(const QSize &lowerSize,KImageEffect::Disposition disposition);
+
+ void channelIntensity(float percent,KImageEffect::RGBComponent channel);
+ void fade(float val, const QColor &color);
+ void flatten(const QColor &ca,const QColor &cb, int ncols);
+ void hash(KImageEffect::Lighting lite,uint spacing);
+ void intensity(float percent);
+ void modulate(QImage &modImage, bool reverse,KImageEffect::ModulationType type, int factor, KImageEffect::RGBComponent channel);
+ void toGray(bool fast);
+ void desaturate(float desat);
+ void contrast(int c);
+ void dither(const QColor *palette, int size);
+ void selectedImage( const QColor &col );
+ void contrastHSV( bool sharpen);
+ void normalize();
+ void equalize();
+ void threshold( uint value);
+ void solarize( double factor);
+ void emboss(double radius, double sigma);
+ //void emboss();
+ void despeckle();
+ void charcoal(double radius, double sigma);
+ void charcoal(double factor);
+ void rotate(KImageEffect::RotateDirection r);
+ void sample(int w, int h);
+ void addNoise(KImageEffect::NoiseType type);
+ void blur(double radius, double sigma);
+ void edge(double radius);
+ void implode(double factor, uint background );
+ void oilPaintConvolve(double radius);
+ void oilPaint(int radius);
+ void sharpen(double radius, double sigma);
+ void sharpen(double factor);
+ void spread(uint amount);
+ void shade(bool color_shading, double azimuth,double elevation);
+ void swirl(double degrees, uint background);
+ void wave(double amplitude, double frequency,uint background);
+
+ QImage bumpmap(QImage &img, QImage &map, double azimuth=135.0, double elevation=45.0, int depth=3, int xofs=0, int yofs=0, int waterlevel=0, int ambient=0, bool compensate=false, bool invert=false, BumpmapType type=Linear, bool tiled=false);
+
+ int mid;
+};
+
+
+} // namespace
+} // namespace
+
+#endif // KJSEMBED_IMAGEFX_PLUGIN_H
diff --git a/kjsembed/plugins/kfileitem_plugin.desktop b/kjsembed/plugins/kfileitem_plugin.desktop
new file mode 100644
index 00000000..2cdab9aa
--- /dev/null
+++ b/kjsembed/plugins/kfileitem_plugin.desktop
@@ -0,0 +1,5 @@
+[Desktop Entry]
+Name=KFileItem
+ServiceTypes=JSBindingPlugin/Binding
+Type=Service
+X-KDE-Library=libfileitemplugin
diff --git a/kjsembed/plugins/kfileitemloader.cpp b/kjsembed/plugins/kfileitemloader.cpp
new file mode 100644
index 00000000..0972e20a
--- /dev/null
+++ b/kjsembed/plugins/kfileitemloader.cpp
@@ -0,0 +1,223 @@
+/***************************************************************************
+ * Copyright (C) 2004 by ian reinhart geiser *
+ * geiseri@kde.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, 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 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 "kfileitemloader.h"
+
+#include <kjsembed/jsopaqueproxy.h>
+#include <kjsembed/jsbinding.h>
+#include <kjsembed/jsfactory.h>
+#include <kjsembed/jsfactory_imp.h>
+#include <kjsembed/kjsembedpart.h>
+
+#include <kfileitem.h>
+#include <kdebug.h>
+
+namespace KJSEmbed {
+namespace Bindings {
+
+KFileItemLoader::KFileItemLoader(QObject *parent, const char *name, const QStringList &args)
+ : JSBindingPlugin(parent, name, args)
+{
+}
+
+
+KFileItemLoader::~KFileItemLoader()
+{
+}
+
+KJS::Object KFileItemLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const
+{
+ kdDebug() << "Loading a KFileItem object" << endl;
+ JSOpaqueProxy *prx = new JSOpaqueProxy( (void *) 0, "KFileItem" );
+
+ KJS::Object proxyObj(prx);
+ KFileItemImp::addBindings( exec, proxyObj );
+ return proxyObj;
+}
+
+} // Bindings
+} // KJSEmbed
+
+KJSEmbed::Bindings::KFileItemImp::KFileItemImp( KJS::ExecState * exec, int id )
+: JSProxyImp(exec), mid(id)
+{
+
+}
+
+KJSEmbed::Bindings::KFileItemImp::~ KFileItemImp( )
+{
+
+}
+
+void KJSEmbed::Bindings::KFileItemImp::addBindings( KJS::ExecState * exec, KJS::Object & object )
+{
+
+ JSOpaqueProxy *op = JSProxy::toOpaqueProxy( object.imp() );
+ if ( !op )
+ {
+ kdWarning() << "KFileItemImp::addBindings() failed, not a JSOpaqueProxy" << endl;
+ return;
+ }
+
+ if ( op->typeName() != "KFileItem" )
+ {
+ kdWarning() << "KFileItemImp::addBindings() failed, type is " << op->typeName() <<
+ endl;
+ return;
+ }
+
+ JSProxy::MethodTable methods[] = {
+ { Methodrefresh, "refresh"},
+ { MethodrefreshMimeType, "refreshMimeType"},
+ { Methodurl, "url"},
+ { MethodsetUrl, "setUrl"},
+ { MethodsetName, "setName"},
+ { MethodpermissionsString, "permissionsString"},
+ { Methoduser, "user"},
+ { Methodgroup, "group"},
+ { MethodisLink, "isLink"},
+ { MethodisDir, "isDir"},
+ { MethodisFile, "isFile"},
+ { MethodisReadable, "isReadable"},
+ { MethodlinkDest, "linkDest"},
+ { MethodtimeString, "timeString"},
+ { MethodisLocalFile, "isLocalFile"},
+ { Methodtext, "text"},
+ { Methodname, "name"},
+ { MethodmimeType, "mimeType"},
+ { MethodisMimeTypeKnown, "isMimeTypeKnown"},
+ { MethodmimeComment, "mimeComment"},
+ { MethodiconName, "iconName"},
+ { Methodpixmap, "pixmap"},
+ { Methodoverlays, "overlays"},
+ { MethodgetStatusBarInfo, "getStatusBarInfo"},
+ { MethodgetToolTipText, "getToolTipText"},
+ { Methodrun, "run"},
+ { 0, 0 }
+ };
+
+ int idx = 0;
+ do {
+ KFileItemImp *meth = new KFileItemImp( exec, methods[idx].id );
+ object.put( exec , methods[idx].name, KJS::Object(meth) );
+ ++idx;
+ } while( methods[idx].id );
+
+}
+
+KJS::Value KJSEmbed::Bindings::KFileItemImp::call( KJS::ExecState * exec, KJS::Object & self, const KJS::List & args )
+{
+ kdDebug() << "KFileItemImp::call() " << mid << endl;
+ JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() );
+ if ( !op ) {
+ kdWarning() << "KFileItemImp::call() failed, not a JSOpaqueProxy" << endl;
+ return KJS::Value();
+ }
+
+ if ( op->typeName() != "KFileItem" ) {
+ kdWarning() << "KFileItemImp::call() failed, type is " << op->typeName() << endl;
+ return KJS::Value();
+ }
+
+ KFileItem *obj = op->toNative<KFileItem >();
+
+ KJS::Value retValue = KJS::Value();
+ switch ( mid ) {
+ case Methodrefresh:
+ obj->refresh();
+ break;
+ case MethodrefreshMimeType:
+ obj->refreshMimeType();
+ break;
+ case Methodurl:
+ {
+ QString url = obj->url().url();
+ retValue = KJS::String(url);
+ break;
+ }
+ case MethodsetUrl:
+ {
+ QString url = extractQString(exec, args, 0);
+ obj->setURL(url);
+ break;
+ }
+ case MethodsetName:
+ case MethodpermissionsString:
+ case Methoduser:
+ case Methodgroup:
+ case MethodisLink:
+ case MethodisDir:
+ case MethodisFile:
+ case MethodisReadable:
+ case MethodlinkDest:
+ case MethodtimeString:
+ case MethodisLocalFile:
+ case Methodtext:
+ {
+ retValue = convertToValue(exec, obj->text() );
+ break;
+ }
+ case Methodname:
+ case MethodmimeType:
+ case MethodisMimeTypeKnown:
+ case MethodmimeComment:
+ case MethodiconName:
+ {
+ retValue = convertToValue( exec, obj->iconName() );
+ break;
+ }
+ case Methodpixmap:
+ {
+ int size = extractInt(exec, args, 0);
+ int state = extractInt(exec, args, 1);
+ retValue = convertToValue(exec, obj->pixmap(size, state));
+ break;
+ }
+ case Methodoverlays:
+ {
+ retValue = convertToValue(exec, obj->overlays());
+ break;
+ }
+ case MethodgetStatusBarInfo:
+ {
+ retValue = KJS::String( obj->getStatusBarInfo() );
+ break;
+ }
+ case MethodgetToolTipText:
+ {
+ int maxcount = extractInt(exec, args, 0);
+ retValue = KJS::String(obj->getToolTipText(maxcount));
+ break;
+ }
+ case Methodrun:
+ obj->run();
+ break;
+ default:
+ kdWarning() << "KFileItemImp has no method " << mid << endl;
+ break;
+ }
+
+ op->setValue((void*) obj, "KFileItem");
+ return retValue;
+
+}
+
+#include <kgenericfactory.h>
+typedef KGenericFactory<KJSEmbed::Bindings::KFileItemLoader> KFileItemLoaderFactory;
+K_EXPORT_COMPONENT_FACTORY( libfileitemplugin, KFileItemLoaderFactory( "KFileItemLoader" ) )
diff --git a/kjsembed/plugins/kfileitemloader.h b/kjsembed/plugins/kfileitemloader.h
new file mode 100644
index 00000000..bca77dc5
--- /dev/null
+++ b/kjsembed/plugins/kfileitemloader.h
@@ -0,0 +1,69 @@
+/***************************************************************************
+ * Copyright (C) 2004 by ian reinhart geiser *
+ * geiseri@kde.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, 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 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 KFILEITEMLOADER_H
+#define KFILEITEMLOADER_H
+
+#include <kjsembed/jsbindingplugin.h>
+#include <kjsembed/jsproxy_imp.h>
+
+/**
+Loader for the KFileItem wrapper. This is automaticly invoked from the jsfactory.
+
+@author ian reinhart geiser
+*/
+namespace KJSEmbed {
+namespace Bindings {
+
+class KFileItemLoader : public JSBindingPlugin
+{
+public:
+ KFileItemLoader(QObject *parent, const char *name, const QStringList &args);
+
+ ~KFileItemLoader();
+
+ KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const;
+};
+
+class KFileItemImp : public JSProxyImp
+{
+ /** Identifiers for the methods provided by this class. */
+ enum MethodId { Methodrefresh, MethodrefreshMimeType, Methodurl, MethodsetUrl, MethodsetName, MethodpermissionsString, Methoduser, Methodgroup, MethodisLink, MethodisDir, MethodisFile, MethodisReadable, MethodlinkDest, MethodtimeString, MethodisLocalFile, Methodtext, Methodname, MethodmimeType, MethodisMimeTypeKnown, MethodmimeComment, MethodiconName, Methodpixmap, Methodoverlays, MethodgetStatusBarInfo, MethodgetToolTipText, Methodrun};
+public:
+ KFileItemImp( KJS::ExecState *exec, int id );
+ virtual ~KFileItemImp();
+
+ static void addBindings( KJS::ExecState *exec, KJS::Object &object );
+
+ /** Returns true iff this object implements the call function. */
+ virtual bool implementsCall() const
+ {
+ return true;
+ }
+
+ /** Invokes the call function. */
+ virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args );
+private:
+ int mid;
+};
+
+} // Bindings
+} // KJSEmbed
+
+#endif
diff --git a/kjsembed/plugins/qprocess_plugin.cpp b/kjsembed/plugins/qprocess_plugin.cpp
new file mode 100644
index 00000000..497022e1
--- /dev/null
+++ b/kjsembed/plugins/qprocess_plugin.cpp
@@ -0,0 +1,144 @@
+// -*- c++ -*-
+
+/*
+ * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <kdebug.h>
+#include <kjsembed/jsobjectproxy.h>
+#include <kjsembed/jsbinding.h>
+#include <kjsembed/kjsembedpart.h>
+#include <kjsembed/customobject_imp.h>
+#include <qvariant.h>
+
+
+#include "qprocess_plugin.h"
+
+namespace KJSEmbed {
+namespace Bindings {
+
+ProcessLoader::ProcessLoader( QObject *parent, const char *name, const QStringList &args ) :
+ JSBindingPlugin(parent, name, args)
+{
+}
+
+KJS::Object ProcessLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const
+{
+ kdDebug() << "Loading a process object" << endl;
+
+ QObject *parent = 0L;
+ JSObjectProxy *proxy = JSProxy::toObjectProxy( args[0].imp() );
+ if ( proxy )
+ parent = proxy->object();
+ ProcessImp *imp = new ProcessImp(parent, "Process" );
+ JSObjectProxy *prx = new JSObjectProxy( jspart, imp );
+
+ KJS::Object proxyObj( prx );
+ prx->addBindings( exec, proxyObj );
+ CustomObjectImp::addBindings( exec, proxyObj );
+ return proxyObj;
+}
+
+ProcessImp::ProcessImp(QObject *parent, const char *name )
+ : QProcess(parent, name)
+{
+ kdDebug() << "New ProcessImp " << endl;
+}
+
+ProcessImp::~ProcessImp()
+{
+}
+
+QStringList ProcessImp::arguments() const
+{
+ return QProcess::arguments();
+}
+void ProcessImp::setArguments( const QStringList args)
+{
+ QProcess::setArguments( args );
+}
+
+ProcessImp::Communication ProcessImp::communication() const
+{
+ return (ProcessImp::Communication)QProcess::communication();
+}
+void ProcessImp::setCommunication( Communication comm)
+{
+ QProcess::setCommunication( comm );
+}
+
+bool ProcessImp::canReadLineStdout() const
+{
+ return QProcess::canReadLineStdout();
+}
+bool ProcessImp::canReadLineStderr() const
+{
+ return QProcess::canReadLineStderr();
+}
+bool ProcessImp::isRunning() const
+{
+ return QProcess::isRunning();
+}
+bool ProcessImp::normalExit() const
+{
+ return QProcess::normalExit();
+}
+int ProcessImp::exitStatus() const
+{
+ return QProcess::exitStatus();
+}
+
+bool ProcessImp::start()
+{
+ return QProcess::start( );
+}
+
+QString ProcessImp::readLineStdout ()
+{
+ return QProcess::readLineStdout();
+}
+
+QString ProcessImp::readLineStderr ()
+{
+ return QProcess::readLineStderr();
+}
+
+QDir ProcessImp::workingDirectory () const
+{
+ return QProcess::workingDirectory();
+}
+
+void ProcessImp::setWorkingDirectory ( const QDir & dir )
+{
+ QProcess::setWorkingDirectory( dir );
+}
+
+void ProcessImp::addArgument ( const QString & arg )
+{
+ QProcess::addArgument( arg );
+}
+
+} // namespace KJSEmbed::Bindings
+} // namespace KJSEmbed
+
+
+#include <kgenericfactory.h>
+typedef KGenericFactory<KJSEmbed::Bindings::ProcessLoader> ProcessLoaderFactory;
+K_EXPORT_COMPONENT_FACTORY( libqprocessplugin, ProcessLoaderFactory( "ProcessLoader" ) )
+
+#include "qprocess_plugin.moc"
diff --git a/kjsembed/plugins/qprocess_plugin.desktop b/kjsembed/plugins/qprocess_plugin.desktop
new file mode 100644
index 00000000..91d18c99
--- /dev/null
+++ b/kjsembed/plugins/qprocess_plugin.desktop
@@ -0,0 +1,5 @@
+[Desktop Entry]
+Name=Process
+ServiceTypes=JSBindingPlugin/Binding
+Type=Service
+X-KDE-Library=libqprocessplugin
diff --git a/kjsembed/plugins/qprocess_plugin.h b/kjsembed/plugins/qprocess_plugin.h
new file mode 100644
index 00000000..8b0608a5
--- /dev/null
+++ b/kjsembed/plugins/qprocess_plugin.h
@@ -0,0 +1,86 @@
+// -*- c++ -*-
+
+/*
+ * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KJSEMBED_QPROCESS_PLUGIN_H
+#define KJSEMBED_QPROCESS_PLUGIN_H
+
+#include <kjsembed/jsbindingplugin.h>
+#include <kjsembed/jsproxy_imp.h>
+#include <qprocess.h>
+#include <qdir.h>
+
+namespace KJSEmbed {
+namespace Bindings {
+
+class ProcessLoader : public JSBindingPlugin
+{
+public:
+ ProcessLoader( QObject *parent, const char *name, const QStringList &args );
+ virtual ~ProcessLoader(){;}
+ KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const;
+};
+
+
+class ProcessImp : public QProcess {
+
+Q_OBJECT
+
+ /** Identifiers for the methods provided by this class. */
+ enum Communication { Stdin = 0x01, Stdout = 0x02, Stderr = 0x04, DupStderr = 0x08 };
+
+ Q_PROPERTY(QStringList arguments READ arguments WRITE setArguments )
+ Q_PROPERTY(Communication communication READ communication WRITE setCommunication)
+ Q_PROPERTY(bool canReadLineStdout READ canReadLineStdout )
+ Q_PROPERTY(bool canReadLineStderr READ canReadLineStderr )
+ Q_PROPERTY(bool isRunning READ isRunning )
+ Q_PROPERTY(bool normalExit READ normalExit )
+ Q_PROPERTY(int exitStatus READ exitStatus )
+ Q_ENUMS(Communication)
+
+public:
+ ProcessImp( QObject *parent = 0, const char *name = 0);
+ virtual ~ProcessImp();
+
+ QStringList arguments() const;
+ void setArguments( const QStringList args);
+
+ Communication communication() const;
+ void setCommunication( Communication comm);
+
+ bool canReadLineStdout() const;
+ bool canReadLineStderr() const;
+ bool isRunning() const;
+ bool normalExit() const;
+ int exitStatus() const;
+
+public slots:
+ bool start();
+ virtual QString readLineStdout ();
+ virtual QString readLineStderr ();
+ QDir workingDirectory () const;
+ void setWorkingDirectory ( const QDir & dir );
+ void addArgument ( const QString & arg );
+};
+
+} // namespace
+} // namespace
+
+#endif // KJSEMBED_QPROCESS_PLUGIN_H