aboutsummaryrefslogtreecommitdiffstats
path: root/src/webchannel
diff options
context:
space:
mode:
Diffstat (limited to 'src/webchannel')
-rw-r--r--src/webchannel/CMakeLists.txt48
-rw-r--r--src/webchannel/doc/qtwebchannel.qdocconf4
-rw-r--r--src/webchannel/qqmlwebchannel.cpp247
-rw-r--r--src/webchannel/qqmlwebchannel.h59
-rw-r--r--src/webchannel/qqmlwebchannelattached.cpp39
-rw-r--r--src/webchannel/qqmlwebchannelattached_p.h46
-rw-r--r--src/webchannel/qwebchannel_p.h2
-rw-r--r--src/webchannel/signalhandler_p.h1
8 files changed, 13 insertions, 433 deletions
diff --git a/src/webchannel/CMakeLists.txt b/src/webchannel/CMakeLists.txt
index 9354973..fd5c08b 100644
--- a/src/webchannel/CMakeLists.txt
+++ b/src/webchannel/CMakeLists.txt
@@ -1,13 +1,8 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from webchannel.pro.
-
-#####################################################################
-## WebChannel Module:
-#####################################################################
-
qt_internal_add_module(WebChannel
+ GENERATE_CPP_EXPORTS
SOURCES
qmetaobjectpublisher.cpp qmetaobjectpublisher_p.h
qwebchannel.cpp qwebchannel.h qwebchannel_p.h
@@ -16,49 +11,26 @@ qt_internal_add_module(WebChannel
qwebchannelglobal.h
LIBRARIES
Qt::CorePrivate
- PUBLIC_LIBRARIES
- Qt::Core
- PRIVATE_MODULE_INTERFACE
- Qt::CorePrivate
- GENERATE_CPP_EXPORTS
)
-# Resources:
-set_source_files_properties("../../examples/webchannel/shared/qwebchannel.js"
- PROPERTIES QT_RESOURCE_ALIAS "qwebchannel.js"
-)
-set(resources_resource_files
- "../../examples/webchannel/shared/qwebchannel.js"
+set(resource_file "../../examples/webchannel/shared/qwebchannel.js")
+set_source_files_properties(${resource_file} PROPERTIES
+ QT_RESOURCE_ALIAS "qwebchannel.js"
)
-set_source_files_properties(${resources_resource_files} PROPERTIES QT_SKIP_QUICKCOMPILER 1)
-
qt_internal_add_resource(WebChannel "resources"
PREFIX
"/qtwebchannel/"
FILES
- ${resources_resource_files}
+ ${resource_file}
)
+if(TARGET Qt::Qml)
+ qt_internal_extend_target(WebChannel PUBLIC_LIBRARIES Qt::Qml)
+else()
+ qt_internal_extend_target(WebChannel DEFINES QT_NO_JSVALUE)
+endif()
-#### Keys ignored in scope 1:.:.:webchannel.pro:<TRUE>:
-# OTHER_FILES = "qwebchannel.js"
-
-## Scopes:
-#####################################################################
-
-qt_internal_extend_target(WebChannel CONDITION TARGET Qt::Qml
- SOURCES
- qqmlwebchannel.cpp qqmlwebchannel.h
- qqmlwebchannelattached.cpp qqmlwebchannelattached_p.h
- PUBLIC_LIBRARIES
- Qt::Qml
-)
-
-qt_internal_extend_target(WebChannel CONDITION NOT TARGET Qt::Qml
- DEFINES
- QT_NO_JSVALUE
-)
qt_internal_add_docs(WebChannel
doc/qtwebchannel.qdocconf
)
diff --git a/src/webchannel/doc/qtwebchannel.qdocconf b/src/webchannel/doc/qtwebchannel.qdocconf
index 766e73f..b77d5f3 100644
--- a/src/webchannel/doc/qtwebchannel.qdocconf
+++ b/src/webchannel/doc/qtwebchannel.qdocconf
@@ -40,10 +40,10 @@ tagfile = ../../../doc/qtwebchannel/
depends += qtcore qtquick qtqml qtdoc qtwebengine qtwebsockets qmake qtcmake
headerdirs += .. \
- ../../imports
+ ../../webchannelquick
sourcedirs += .. \
- ../../imports
+ ../../webchannelquick
imagedirs += images
diff --git a/src/webchannel/qqmlwebchannel.cpp b/src/webchannel/qqmlwebchannel.cpp
deleted file mode 100644
index c8f8bd8..0000000
--- a/src/webchannel/qqmlwebchannel.cpp
+++ /dev/null
@@ -1,247 +0,0 @@
-// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-
-#include "qqmlwebchannel.h"
-
-#include "qwebchannel_p.h"
-#include "qmetaobjectpublisher_p.h"
-#include "qwebchannelabstracttransport.h"
-
-#include <QtQml/QQmlContext>
-
-#include "qqmlwebchannelattached_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype WebChannel
- \instantiates QQmlWebChannel
-
- \inqmlmodule QtWebChannel
- \ingroup webchannel-qml
- \brief QML interface to QWebChannel.
- \since 5.4
-
- The WebChannel provides a mechanism to transparently access QObject or QML objects from HTML
- clients. All properties, signals and public slots can be used from the HTML clients.
-
- \sa QWebChannel, {Qt WebChannel JavaScript API}{JavaScript API}
-*/
-
-/*!
- \qmlproperty QQmlListProperty<QObject> WebChannel::transports
- A list of transport objects, which implement QWebChannelAbstractTransport. The transports
- are used to talk to the remote clients.
-
- \sa connectTo(), disconnectFrom()
-*/
-
-/*!
- \qmlproperty QQmlListProperty<QObject> WebChannel::registeredObjects
-
- \brief A list of objects which should be accessible to remote clients.
-
- The objects must have the attached \l id property set to an identifier, under which the
- object is then known on the HTML side.
-
- Once registered, all signals and property changes are automatically propagated to the clients.
- Public invokable methods, including slots, are also accessible to the clients.
-
- If one needs to register objects which are not available when the component is created, use the
- imperative registerObjects method.
-
- \sa registerObjects(), id
-*/
-
-class QQmlWebChannelPrivate : public QWebChannelPrivate
-{
- Q_DECLARE_PUBLIC(QQmlWebChannel)
-public:
- QList<QObject *> registeredObjects;
-
- void _q_objectIdChanged(const QString &newId);
-};
-
-/*!
- \internal
-
- Update the name of the sender object, when its attached WebChannel.id property changed.
- This is required, since during startup the property is empty and only gets set later on.
-*/
-void QQmlWebChannelPrivate::_q_objectIdChanged(const QString &newId)
-{
- Q_Q(QQmlWebChannel);
- const QQmlWebChannelAttached *const attached = qobject_cast<QQmlWebChannelAttached*>(q->sender());
- Q_ASSERT(attached);
- Q_ASSERT(attached->parent());
- Q_ASSERT(registeredObjects.contains(attached->parent()));
-
- QObject *const object = attached->parent();
- const QString &oldId = publisher->registeredObjectIds.value(object);
-
- if (!oldId.isEmpty()) {
- q->deregisterObject(object);
- }
-
- q->registerObject(newId, object);
-}
-
-QQmlWebChannel::QQmlWebChannel(QObject *parent)
- : QWebChannel(*(new QQmlWebChannelPrivate), parent)
-{
-}
-
-QQmlWebChannel::~QQmlWebChannel()
-{
-
-}
-
-/*!
- \qmlmethod void WebChannel::registerObjects(QVariantMap objects)
- Registers the specified \a objects to make them accessible to HTML clients.
- The key of the map is used as an identifier for the object on the client side.
-
- Once registered, all signals and property changes are automatically propagated to the clients.
- Public invokable methods, including slots, are also accessible to the clients.
-
- This imperative API can be used to register objects on the fly. For static objects, the declarative
- registeredObjects property should be preferred.
-
- \sa registeredObjects
-*/
-void QQmlWebChannel::registerObjects(const QVariantMap &objects)
-{
- Q_D(QQmlWebChannel);
- QMap<QString, QVariant>::const_iterator it = objects.constBegin();
- for (; it != objects.constEnd(); ++it) {
- QObject *object = it.value().value<QObject*>();
- if (!object) {
- qWarning("Invalid QObject given to register under name %s", qPrintable(it.key()));
- continue;
- }
- d->publisher->registerObject(it.key(), object);
- }
-}
-
-QQmlWebChannelAttached *QQmlWebChannel::qmlAttachedProperties(QObject *obj)
-{
- return new QQmlWebChannelAttached(obj);
-}
-
-/*!
- \qmlmethod void WebChannel::connectTo(QWebChannelAbstractTransport transport)
-
- \brief Connects to the \a transport, which represents a communication
- channel to a single client.
-
- The transport object must be an implementation of QWebChannelAbstractTransport.
-
- \sa transports, disconnectFrom()
-*/
-void QQmlWebChannel::connectTo(QObject *transport)
-{
- if (QWebChannelAbstractTransport *realTransport = qobject_cast<QWebChannelAbstractTransport*>(transport)) {
- QWebChannel::connectTo(realTransport);
- } else {
- qWarning() << "Cannot connect to transport" << transport << " - it is not a QWebChannelAbstractTransport.";
- }
-}
-
-/*!
- \qmlmethod void WebChannel::disconnectFrom(QWebChannelAbstractTransport transport)
-
- \brief Disconnects the \a transport from this WebChannel.
-
- The client will not be able to communicate with the WebChannel anymore, nor will it receive any
- signals or property updates.
-
- \sa connectTo()
-*/
-void QQmlWebChannel::disconnectFrom(QObject *transport)
-{
- if (QWebChannelAbstractTransport *realTransport = qobject_cast<QWebChannelAbstractTransport*>(transport)) {
- QWebChannel::disconnectFrom(realTransport);
- } else {
- qWarning() << "Cannot disconnect from transport" << transport << " - it is not a QWebChannelAbstractTransport.";
- }
-}
-
-QQmlListProperty<QObject> QQmlWebChannel::registeredObjects()
-{
- return QQmlListProperty<QObject>(this, nullptr, registeredObjects_append,
- registeredObjects_count, registeredObjects_at,
- registeredObjects_clear);
-}
-
-void QQmlWebChannel::registeredObjects_append(QQmlListProperty<QObject> *prop, QObject *object)
-{
- const QQmlWebChannelAttached *const attached = qobject_cast<QQmlWebChannelAttached*>(
- qmlAttachedPropertiesObject<QQmlWebChannel>(object, false /* don't create */));
- if (!attached) {
- const QQmlContext *const context = qmlContext(object);
- qWarning() << "Cannot register object" << context->nameForObject(object) << '(' << object << ") without attached WebChannel.id property. Did you forget to set it?";
- return;
- }
- QQmlWebChannel *channel = static_cast<QQmlWebChannel*>(prop->object);
- if (!attached->id().isEmpty()) {
- // TODO: warning in such cases?
- channel->registerObject(attached->id(), object);
- }
- channel->d_func()->registeredObjects.append(object);
- connect(attached, SIGNAL(idChanged(QString)), channel, SLOT(_q_objectIdChanged(QString)));
-}
-
-qsizetype QQmlWebChannel::registeredObjects_count(QQmlListProperty<QObject> *prop)
-{
- return static_cast<QQmlWebChannel*>(prop->object)->d_func()->registeredObjects.size();
-}
-
-QObject *QQmlWebChannel::registeredObjects_at(QQmlListProperty<QObject> *prop, qsizetype index)
-{
- return static_cast<QQmlWebChannel*>(prop->object)->d_func()->registeredObjects.at(index);
-}
-
-void QQmlWebChannel::registeredObjects_clear(QQmlListProperty<QObject> *prop)
-{
- QQmlWebChannel *channel = static_cast<QQmlWebChannel*>(prop->object);
- foreach (QObject *object, channel->d_func()->registeredObjects) {
- channel->deregisterObject(object);
- }
- return channel->d_func()->registeredObjects.clear();
-}
-
-QQmlListProperty<QObject> QQmlWebChannel::transports()
-{
- return QQmlListProperty<QObject>(this, nullptr, transports_append, transports_count,
- transports_at, transports_clear);
-}
-
-void QQmlWebChannel::transports_append(QQmlListProperty<QObject> *prop, QObject *transport)
-{
- QQmlWebChannel *channel = static_cast<QQmlWebChannel*>(prop->object);
- channel->connectTo(transport);
-}
-
-qsizetype QQmlWebChannel::transports_count(QQmlListProperty<QObject> *prop)
-{
- return static_cast<QQmlWebChannel*>(prop->object)->d_func()->transports.size();
-}
-
-QObject *QQmlWebChannel::transports_at(QQmlListProperty<QObject> *prop, qsizetype index)
-{
- QQmlWebChannel *channel = static_cast<QQmlWebChannel*>(prop->object);
- return channel->d_func()->transports.at(index);
-}
-
-void QQmlWebChannel::transports_clear(QQmlListProperty<QObject> *prop)
-{
- QWebChannel *channel = static_cast<QWebChannel*>(prop->object);
- foreach (QWebChannelAbstractTransport *transport, channel->d_func()->transports) {
- channel->disconnectFrom(transport);
- }
- Q_ASSERT(channel->d_func()->transports.isEmpty());
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qqmlwebchannel.cpp"
diff --git a/src/webchannel/qqmlwebchannel.h b/src/webchannel/qqmlwebchannel.h
deleted file mode 100644
index f57a510..0000000
--- a/src/webchannel/qqmlwebchannel.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-
-#ifndef QQMLWEBCHANNEL_H
-#define QQMLWEBCHANNEL_H
-
-#include <QtWebChannel/QWebChannel>
-#include <QtWebChannel/qwebchannelglobal.h>
-
-#include <QtQml/qqml.h>
-#include <QtQml/QQmlListProperty>
-
-QT_BEGIN_NAMESPACE
-
-class QQmlWebChannelPrivate;
-class QQmlWebChannelAttached;
-class Q_WEBCHANNEL_EXPORT QQmlWebChannel : public QWebChannel
-{
- Q_OBJECT
- Q_DISABLE_COPY(QQmlWebChannel)
-
- Q_PROPERTY( QQmlListProperty<QObject> transports READ transports )
- Q_PROPERTY( QQmlListProperty<QObject> registeredObjects READ registeredObjects )
-
-public:
- explicit QQmlWebChannel(QObject *parent = nullptr);
- virtual ~QQmlWebChannel();
-
- Q_INVOKABLE void registerObjects(const QVariantMap &objects);
- QQmlListProperty<QObject> registeredObjects();
-
- QQmlListProperty<QObject> transports();
-
- static QQmlWebChannelAttached *qmlAttachedProperties(QObject *obj);
-
- Q_INVOKABLE void connectTo(QObject *transport);
- Q_INVOKABLE void disconnectFrom(QObject *transport);
-
-private:
- Q_DECLARE_PRIVATE(QQmlWebChannel)
- Q_PRIVATE_SLOT(d_func(), void _q_objectIdChanged(const QString &newId))
-
- static void registeredObjects_append(QQmlListProperty<QObject> *prop, QObject *item);
- static qsizetype registeredObjects_count(QQmlListProperty<QObject> *prop);
- static QObject *registeredObjects_at(QQmlListProperty<QObject> *prop, qsizetype index);
- static void registeredObjects_clear(QQmlListProperty<QObject> *prop);
-
- static void transports_append(QQmlListProperty<QObject> *prop, QObject *item);
- static qsizetype transports_count(QQmlListProperty<QObject> *prop);
- static QObject *transports_at(QQmlListProperty<QObject> *prop, qsizetype index);
- static void transports_clear(QQmlListProperty<QObject> *prop);
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE( QQmlWebChannel )
-QML_DECLARE_TYPEINFO( QQmlWebChannel, QML_HAS_ATTACHED_PROPERTIES )
-
-#endif // QQMLWEBCHANNEL_H
diff --git a/src/webchannel/qqmlwebchannelattached.cpp b/src/webchannel/qqmlwebchannelattached.cpp
deleted file mode 100644
index 5019590..0000000
--- a/src/webchannel/qqmlwebchannelattached.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-
-#include "qqmlwebchannelattached_p.h"
-
-QT_USE_NAMESPACE
-
-QQmlWebChannelAttached::QQmlWebChannelAttached(QObject *parent)
- : QObject(parent)
-{
-
-}
-
-QQmlWebChannelAttached::~QQmlWebChannelAttached()
-{
-
-}
-
-/*!
- \qmlattachedproperty QString WebChannel::id
-
- \brief The identifier under which an object, registered to a WebChannel, is known to remote clients.
-
- This property must be set for every object that should be published over the WebChannel.
- While no restrictions are enforced on the format of the id, it is usually a good idea to
- choose a string that is also a valid JavaScript identifier.
-*/
-QString QQmlWebChannelAttached::id() const
-{
- return m_id;
-}
-
-void QQmlWebChannelAttached::setId(const QString &id)
-{
- if (id != m_id) {
- m_id = id;
- emit idChanged(id);
- }
-}
diff --git a/src/webchannel/qqmlwebchannelattached_p.h b/src/webchannel/qqmlwebchannelattached_p.h
deleted file mode 100644
index c4c70fd..0000000
--- a/src/webchannel/qqmlwebchannelattached_p.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-
-#ifndef QQMLWEBCHANNELATTACHED_H
-#define QQMLWEBCHANNELATTACHED_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QObject>
-
-#include "qwebchannelglobal.h"
-#include "private/qglobal_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class Q_WEBCHANNEL_EXPORT QQmlWebChannelAttached : public QObject
-{
- Q_OBJECT
-
- Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged FINAL )
-public:
- explicit QQmlWebChannelAttached(QObject *parent = 0);
- virtual ~QQmlWebChannelAttached();
-
- QString id() const;
- void setId(const QString &id);
-
-Q_SIGNALS:
- void idChanged(const QString &id);
-
-private:
- QString m_id;
-};
-
-QT_END_NAMESPACE
-
-#endif // QQMLWEBCHANNELATTACHED_H
diff --git a/src/webchannel/qwebchannel_p.h b/src/webchannel/qwebchannel_p.h
index 7aad0ab..71cf4a7 100644
--- a/src/webchannel/qwebchannel_p.h
+++ b/src/webchannel/qwebchannel_p.h
@@ -17,7 +17,7 @@
#include "qwebchannelglobal.h"
-#include <private/qobject_p.h>
+#include <QtCore/private/qobject_p.h>
#include <QList>
QT_BEGIN_NAMESPACE
diff --git a/src/webchannel/signalhandler_p.h b/src/webchannel/signalhandler_p.h
index 3431f1b..022762a 100644
--- a/src/webchannel/signalhandler_p.h
+++ b/src/webchannel/signalhandler_p.h
@@ -21,7 +21,6 @@
#include <QMetaMethod>
#include <QDebug>
#include <QThread>
-#include <private/qglobal_p.h>
QT_BEGIN_NAMESPACE