1 /*
2     This file is part of the KDE project
3     SPDX-FileCopyrightText: 2010 Maksim Orlovich <maksim@kde.org>
4 
5     SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef kparts_scriptableextension_p_h
9 #define kparts_scriptableextension_p_h
10 
11 #include "liveconnectextension.h"
12 #include "scriptableextension.h"
13 
14 namespace KParts
15 {
16 // LiveConnectExtension -> ScriptableExtension adapter.
17 class ScriptableLiveConnectExtension : public ScriptableExtension
18 {
19     Q_OBJECT
20 public:
21     ScriptableLiveConnectExtension(QObject *parent, LiveConnectExtension *old);
22 
23     QVariant rootObject() override;
24     // enclosingObject: not applicable, plugins wouldn't have children
25 
26     // callAsFunction: we only have function rereferences.
27     QVariant callFunctionReference(ScriptableExtension *callerPrincipal, quint64 objId, const QString &f, const ArgList &args) override;
28 
29     // callAsConstructor: unsupported by LC
30 
31     bool hasProperty(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName) override;
32 
33     QVariant get(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName) override;
34 
35     bool put(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName, const QVariant &value) override;
36 
37     // removeProperty: unsupported by LC
38     // enumerateProperties: unsupported by LC
39     // setException: unsupported by LC
40     // evaluateScript: unsupported by LC, though we have to
41     //                 route LC evaluation requests to our parent
42     //                 as appropriate
43 
44     void acquire(quint64 objid) override;
45     void release(quint64 objid) override;
46 
47 private:
48     // LC uses 0-1 refcounting, we use arbitrary, so we need to call
49     // unregister when done.
50     QHash<quint64, int> refCounts;
51     LiveConnectExtension *wrapee;
52 
53     // also registers when needed
54     QVariant fromLC(const QString &name, LiveConnectExtension::Type type, unsigned long objId, const QString &value);
55 
56     QString toLC(const QVariant &in, bool *ok);
57 public Q_SLOTS:
58     void liveConnectEvent(const unsigned long, const QString &, const KParts::LiveConnectExtension::ArgList &);
59 };
60 
61 } // namespace KParts
62 
63 #endif
64