• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KParts

scriptableextension.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2010 Maksim Orlovich <maksim@kde.org>
00003    Copyright (C) 2002 Koos Vriezen <koos.vriezen@gmail.com>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef kparts_scriptableextension_h
00022 #define kparts_scriptableextension_h
00023 
00024 #include <QtGlobal>
00025 #include <QObject>
00026 #include <QVariant>
00027 #include <kparts/part.h>
00028 
00029 namespace KParts {
00030 
00031 class  ScriptableExtension;
00032 struct ScriptableExtensionPrivate;
00033 class  LiveConnectExtension;
00034 
00044 class KPARTS_EXPORT ScriptableExtension: public QObject
00045 {
00046     Q_OBJECT
00047 public:
00060 
00061     struct Null {};
00062 
00064     struct Undefined {};
00065 
00068     struct Exception {
00072         QString message;
00073 
00074         Exception() {}
00075         Exception(const QString& msg): message(msg) {}
00076     };
00077 
00091     struct Object {
00092         ScriptableExtension* owner;
00093         quint64              objId;
00094 
00095         Object(): owner(0), objId(0) {}
00096         Object(ScriptableExtension* o, quint64 id): owner(o), objId(id) {}
00097         bool operator==(const Object& other) const { return owner == other.owner && objId == other.objId; }
00098     };
00099 
00104     struct FunctionRef {
00105         Object   base;
00106         QString  field;
00107 
00108         FunctionRef() {}
00109         FunctionRef(const Object& b, const QString&f): base(b), field(f) {}
00110         bool operator==(const FunctionRef& other) const { return base == other.base && field == other.field; }
00111     };
00112 
00114 
00115 
00117 
00118 protected:
00119     ScriptableExtension(QObject* parent);
00120 public:
00121     virtual ~ScriptableExtension();
00122 
00127     static ScriptableExtension* childObject(QObject* obj);
00128 
00134     static ScriptableExtension* adapterFromLiveConnect(QObject* parentObj,
00135                                                        LiveConnectExtension* oldApi);
00136 
00138 
00139 
00141 
00142 
00148     void setHost(ScriptableExtension* host);
00149 
00154     ScriptableExtension* host() const;
00155 
00161     virtual QVariant rootObject();
00162 
00172     QVariant enclosingObject();
00174 
00190 
00191 
00192     typedef QList<QVariant> ArgList;
00193 
00197     virtual QVariant callAsFunction(ScriptableExtension* callerPrincipal, quint64 objId, const ArgList& args);
00198 
00202     virtual QVariant callFunctionReference(ScriptableExtension* callerPrincipal, quint64 objId,
00203                                            const QString& f, const ArgList& args);
00204 
00209     virtual QVariant callAsConstructor(ScriptableExtension* callerPrincipal, quint64 objId, const ArgList& args);
00210 
00215     virtual bool hasProperty(ScriptableExtension* callerPrincipal, quint64 objId, const QString& propName);
00216 
00220     virtual QVariant get(ScriptableExtension* callerPrincipal, quint64 objId, const QString& propName);
00221 
00226     virtual bool put(ScriptableExtension* callerPrincipal, quint64 objId, const QString& propName, const QVariant& value);
00227 
00232     virtual bool removeProperty(ScriptableExtension* callerPrincipal, quint64 objId, const QString& propName);
00233 
00238     virtual bool enumerateProperties(ScriptableExtension* callerPrincipal, quint64 objId, QStringList* result);
00239 
00244     virtual bool setException(ScriptableExtension* callerPrincipal, const QString& message);
00245 
00246 
00247     enum ScriptLanguage {
00248         ECMAScript, 
00249         EnumLimit = 0xFFFF
00250     };
00251     
00257     virtual QVariant evaluateScript(ScriptableExtension* callerPrincipal,
00258                                     quint64 contextObjectId,
00259                                     const QString& code,
00260                                     ScriptLanguage language = ECMAScript);
00261 
00264     virtual bool isScriptLanguageSupported(ScriptLanguage lang) const;
00265 
00269     virtual void acquire(quint64 objid);
00270 
00277     static QVariant acquireValue(const QVariant& v);
00278 
00282     virtual void release(quint64 objid);
00283 
00290     static QVariant releaseValue(const QVariant& v);
00291 
00293 private:
00299     virtual QVariant encloserForKid(KParts::ScriptableExtension* kid);
00300 
00301     ScriptableExtensionPrivate* const d;
00302 };
00303 
00304 KPARTS_EXPORT unsigned int qHash(const KParts::ScriptableExtension::Object& o);
00305 
00306 KPARTS_EXPORT unsigned int qHash(const KParts::ScriptableExtension::FunctionRef& f);
00307 
00308 } // namespace KParts
00309 
00310 Q_DECLARE_METATYPE(KParts::ScriptableExtension::Null)
00311 Q_DECLARE_METATYPE(KParts::ScriptableExtension::Undefined)
00312 Q_DECLARE_METATYPE(KParts::ScriptableExtension::Exception)
00313 Q_DECLARE_METATYPE(KParts::ScriptableExtension::Object)
00314 Q_DECLARE_METATYPE(KParts::ScriptableExtension::FunctionRef)
00315 
00316 #endif
00317 
00318 // kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;

KParts

Skip menu "KParts"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal