File indexing completed on 2024-04-28 15:29:21

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org>
0004     SPDX-FileCopyrightText: David Faure <faure@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef __kparts_liveconnectextension_h__
0010 #define __kparts_liveconnectextension_h__
0011 
0012 #include <kparts/kparts_export.h>
0013 
0014 #include <QObject>
0015 #include <QPair>
0016 #include <QStringList>
0017 
0018 #include <memory>
0019 
0020 template<typename T>
0021 class QList;
0022 class QString;
0023 
0024 namespace KParts
0025 {
0026 class ReadOnlyPart;
0027 class LiveConnectExtensionPrivate;
0028 
0029 /**
0030  * @class LiveConnectExtension liveconnectextension.h <KParts/LiveConnectExtension>
0031  *
0032  * @short An extension class for LiveConnect, i.e. a call from JavaScript
0033  * from a HTML page which embeds this part.
0034  * A part can have an object hierarchy by using objid as a reference
0035  * to an object.
0036  */
0037 class KPARTS_EXPORT LiveConnectExtension : public QObject
0038 {
0039     Q_OBJECT
0040 public:
0041     enum Type {
0042         TypeVoid = 0,
0043         TypeBool,
0044         TypeFunction,
0045         TypeNumber,
0046         TypeObject,
0047         TypeString,
0048     };
0049     typedef QList<QPair<Type, QString>> ArgList;
0050 
0051     LiveConnectExtension(KParts::ReadOnlyPart *parent);
0052 
0053     ~LiveConnectExtension() override;
0054     /**
0055      * get a field value from objid, return true on success
0056      */
0057     virtual bool get(const unsigned long objid, const QString &field, Type &type, unsigned long &retobjid, QString &value);
0058     /**
0059      * put a field value in objid, return true on success
0060      */
0061     virtual bool put(const unsigned long objid, const QString &field, const QString &value);
0062     /**
0063      * calls a function of objid, return true on success
0064      */
0065     virtual bool call(const unsigned long objid, const QString &func, const QStringList &args, Type &type, unsigned long &retobjid, QString &value);
0066     /**
0067      * notifies the part that there is no reference anymore to objid
0068      */
0069     virtual void unregister(const unsigned long objid);
0070 
0071     static LiveConnectExtension *childObject(QObject *obj);
0072 Q_SIGNALS:
0073     /**
0074      * notify a event from the part of object objid
0075      */
0076     void partEvent(const unsigned long objid, const QString &event, const KParts::LiveConnectExtension::ArgList &args);
0077 
0078 private:
0079     std::unique_ptr<LiveConnectExtensionPrivate> const d;
0080 };
0081 
0082 }
0083 
0084 #endif