summaryrefslogtreecommitdiff
path: root/src/imports/qmlwebsockets/qqmlwebsocket.h
diff options
context:
space:
mode:
authorKurt Pattyn <pattyn.kurt@gmail.com>2013-11-17 15:20:08 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-25 01:10:23 +0100
commit7c8d645c4759f7290fd31fe439abf0a99aac9161 (patch)
tree4d2630238d010c5e123b6053569e9853e4a954ac /src/imports/qmlwebsockets/qqmlwebsocket.h
parent12a415503ed2579f8d9773a983ef34b1b0817caa (diff)
downloadqtwebsockets-7c8d645c4759f7290fd31fe439abf0a99aac9161.tar.gz
Add QML websockets plugin
Change-Id: I9454cf339f8af5515d3a91667d8c8ded3659d18b Reviewed-by: Milian Wolff <milian.wolff@kdab.com> Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
Diffstat (limited to 'src/imports/qmlwebsockets/qqmlwebsocket.h')
-rw-r--r--src/imports/qmlwebsockets/qqmlwebsocket.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/imports/qmlwebsockets/qqmlwebsocket.h b/src/imports/qmlwebsockets/qqmlwebsocket.h
index 20718c3..47cf6fa 100644
--- a/src/imports/qmlwebsockets/qqmlwebsocket.h
+++ b/src/imports/qmlwebsockets/qqmlwebsocket.h
@@ -44,6 +44,9 @@
#include <QObject>
#include <QQmlParserStatus>
+#include <QtQml>
+#include <QScopedPointer>
+#include <QWebSocket>
class QQmlWebSocket : public QObject, public QQmlParserStatus
{
@@ -51,12 +54,64 @@ class QQmlWebSocket : public QObject, public QQmlParserStatus
Q_DISABLE_COPY(QQmlWebSocket)
Q_INTERFACES(QQmlParserStatus)
+ Q_ENUMS(Status)
+ Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
+ Q_PROPERTY(Status status READ status NOTIFY statusChanged)
+ Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
+ Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
+
public:
explicit QQmlWebSocket(QObject *parent = Q_NULLPTR);
+ virtual ~QQmlWebSocket();
+
+ enum Status
+ {
+ Connecting = 0,
+ Open = 1,
+ Closing = 2,
+ Closed = 3,
+ Error = 4
+ };
+
+ QUrl url() const;
+ void setUrl(const QUrl &url);
+ Status status() const;
+ QString errorString() const;
+
+ void setActive(bool active);
+ bool isActive() const;
+
+public Q_SLOTS:
+ void sendTextMessage(const QString &message);
+
+
+Q_SIGNALS:
+ void textMessageReceived(QString message);
+ void statusChanged(Status status);
+ void activeChanged(bool isActive);
+ void errorStringChanged(QString errorString);
+ void urlChanged();
public:
void classBegin() Q_DECL_OVERRIDE;
void componentComplete() Q_DECL_OVERRIDE;
+
+private Q_SLOTS:
+ void onError(QAbstractSocket::SocketError error);
+ void onStateChanged(QAbstractSocket::SocketState state);
+
+private:
+ QScopedPointer<QWebSocket> m_webSocket;
+ Status m_status;
+ QUrl m_url;
+ bool m_isActive;
+ bool m_componentCompleted;
+ QString m_errorString;
+
+ void setStatus(Status status);
+ void open();
+ void close();
+ void setErrorString(QString errorString = QString());
};
#endif // QQMLWEBSOCKET_H